interface="org.argeo.slc.execution.ExecutionModulesManager" />\r
\r
<!-- SERVICES -->\r
- <!-- Deprecated -->\r
- <service ref="resultListener"\r
- interface="org.argeo.slc.core.test.tree.TreeTestResultListener" />\r
- <service ref="resultListener" interface="org.argeo.slc.test.TestResultListener" />\r
<service ref="attachmentUploader" interface="org.argeo.slc.core.attachment.AttachmentUploader" />\r
\r
<service interface="org.argeo.slc.execution.ExecutionModulesListener"\r
<property name="repository" ref="repository" />\r
</bean>\r
\r
- <bean id="resultListener" class="org.argeo.slc.jcr.execution.JcrResultListener">\r
- <property name="session" ref="session" />\r
- </bean>\r
-\r
<bean id="attachmentUploader" class="org.argeo.slc.jcr.execution.JcrAttachmentUploader">\r
<property name="session" ref="session" />\r
</bean>\r
<instructions>
<Import-Package>
*,
- org.argeo.slc.core.test.tree
</Import-Package>
</instructions>
</configuration>
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.slc.SlcException;
-import org.argeo.slc.core.structure.tree.TreeSPath;
-import org.argeo.slc.core.structure.tree.TreeSRegistry;
import org.argeo.slc.execution.ExecutionFlow;
import org.argeo.slc.execution.ExecutionSpec;
import org.argeo.slc.execution.ExecutionSpecAttribute;
-import org.argeo.slc.structure.StructureAware;
-import org.argeo.slc.structure.StructureRegistry;
-import org.springframework.aop.scope.ScopedObject;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.validation.MapBindingResult;
private List<Runnable> executables = new ArrayList<Runnable>();
private String path;
- private StructureRegistry<TreeSPath> registry = new TreeSRegistry();
private Boolean failOnError = true;
runnable.run();
}
- @SuppressWarnings(value = { "unchecked" })
public void afterPropertiesSet() throws Exception {
if (path == null) {
if (name.charAt(0) == '/') {
if (path != null) {
for (Runnable executable : executables) {
- if (executable instanceof StructureAware
- && !(executable instanceof ScopedObject)) {
- ((StructureAware<TreeSPath>) executable).notifyCurrentPath(
- registry, new TreeSPath(path));
- } else if (executable instanceof DefaultExecutionFlow) {
+ if (executable instanceof DefaultExecutionFlow) {
// so we don't need to have DefaultExecutionFlow
// implementing StructureAware
// FIXME: probably has side effects
this.path = path;
}
- public void setRegistry(StructureRegistry<TreeSPath> registry) {
- this.registry = registry;
- }
-
public Boolean getFailOnError() {
return failOnError;
}
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.core.execution.tasks;\r
-\r
-import java.lang.reflect.Method;\r
-import java.util.UUID;\r
-\r
-import org.argeo.slc.SlcException;\r
-import org.argeo.slc.deploy.DeployedSystem;\r
-import org.argeo.slc.deploy.DeployedSystemManager;\r
-import org.argeo.slc.process.SlcExecution;\r
-import org.argeo.slc.process.SlcExecutionRelated;\r
-import org.argeo.slc.process.SlcExecutionStep;\r
-import org.argeo.slc.structure.StructureRegistry;\r
-\r
-/** Use {@link MethodCall} instead. */\r
-@Deprecated\r
-public class SlcManager implements Runnable, SlcExecutionRelated {\r
- private String uuid;\r
- private String slcExecutionUuid;\r
- private String slcExecutionStepUuid;\r
-\r
- private String action;\r
- private DeployedSystemManager<DeployedSystem> manager;\r
-\r
- public final void run() {\r
- uuid = UUID.randomUUID().toString();\r
- executeActions(StructureRegistry.ALL);\r
- }\r
-\r
- protected void executeActions(String mode) {\r
- try {\r
- Class<?>[] argClasses = null;\r
- Method method = manager.getClass().getMethod(action, argClasses);\r
- Object[] argObjects = null;\r
- method.invoke(manager, argObjects);\r
- } catch (Exception e) {\r
- throw new SlcException("Cannot execute action " + action\r
- + " for manager " + manager, e);\r
- }\r
- }\r
-\r
- public void setAction(String action) {\r
- this.action = action;\r
- }\r
-\r
- public void setManager(DeployedSystemManager<DeployedSystem> manager) {\r
- this.manager = manager;\r
- }\r
-\r
- public String getUuid() {\r
- return uuid;\r
- }\r
-\r
- public void setUuid(String uuid) {\r
- this.uuid = uuid;\r
- }\r
-\r
- public String getSlcExecutionUuid() {\r
- return slcExecutionUuid;\r
- }\r
-\r
- public void setSlcExecutionUuid(String slcExecutionUuid) {\r
- this.slcExecutionUuid = slcExecutionUuid;\r
- }\r
-\r
- public String getSlcExecutionStepUuid() {\r
- return slcExecutionStepUuid;\r
- }\r
-\r
- public void setSlcExecutionStepUuid(String slcExecutionStepUuid) {\r
- this.slcExecutionStepUuid = slcExecutionStepUuid;\r
- }\r
-\r
- public void notifySlcExecution(SlcExecution slcExecution) {\r
- if (slcExecution != null) {\r
- slcExecutionUuid = slcExecution.getUuid();\r
- SlcExecutionStep step = slcExecution.currentStep();\r
- if (step != null) {\r
- slcExecutionStepUuid = step.getUuid();\r
- }\r
- }\r
- }\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.core.structure;\r
-\r
-import java.io.Serializable;\r
-import java.util.Map;\r
-import java.util.TreeMap;\r
-\r
-import org.argeo.slc.core.structure.tree.TreeSPath;\r
-import org.argeo.slc.structure.StructureElement;\r
-\r
-/**\r
- * Basic implementation of <code>StructureElement</code>.\r
- * \r
- * @see TreeSPath\r
- */\r
-public class SimpleSElement implements StructureElement, Serializable {\r
- private static final long serialVersionUID = -7012193125005818900L;\r
- /** For ORM */\r
- private Long tid;\r
- private String label;\r
- private Map<String, String> tags = new TreeMap<String, String>();\r
-\r
- /** For ORM */\r
- public SimpleSElement() {\r
- }\r
-\r
- /** Constructor */\r
- public SimpleSElement(String label) {\r
- this.label = label;\r
- }\r
-\r
- /** Constructor */\r
- public SimpleSElement(String label, String defaultLabel) {\r
- this(label != null ? label : defaultLabel);\r
- }\r
-\r
- /** Constructor */\r
- public SimpleSElement(SimpleSElement sElement) {\r
- setLabel(sElement.getLabel());\r
- setTags(new TreeMap<String, String>(sElement.getTags()));\r
- }\r
-\r
- public String getLabel() {\r
- return label;\r
- }\r
-\r
- /** Sets the label. */\r
- public void setLabel(String label) {\r
- this.label = label;\r
- }\r
-\r
- public Long getTid() {\r
- return tid;\r
- }\r
-\r
- void setTid(Long tid) {\r
- this.tid = tid;\r
- }\r
-\r
- public Map<String, String> getTags() {\r
- return tags;\r
- }\r
-\r
- public void setTags(Map<String, String> tags) {\r
- this.tags = tags;\r
- }\r
-\r
- @Override\r
- public SimpleSElement clone() {\r
- return new SimpleSElement(this);\r
- }\r
-\r
-}\r
+++ /dev/null
-<html>\r
-<head></head>\r
-<body>\r
-SLC Structure framework allowing to uniquely reference actions.\r
-</body>\r
-</html>
\ No newline at end of file
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.core.structure.tree;\r
-\r
-import java.io.Serializable;\r
-import java.util.List;\r
-import java.util.StringTokenizer;\r
-import java.util.Vector;\r
-\r
-import org.argeo.slc.SlcException;\r
-import org.argeo.slc.structure.StructurePath;\r
-import org.argeo.slc.structure.StructureRegistry;\r
-\r
-/**\r
- * Path for tree based <code>StructureRegistry</code> implementations.\r
- */\r
-public class TreeSPath implements StructurePath, Comparable<StructurePath>,\r
- Serializable {\r
- private static final long serialVersionUID = -110121029180848183L;\r
-\r
- /** Default character to use a separator: /. */\r
- private static Character DEFAULT_SEPARATOR = '/';\r
-\r
- private Character separator = DEFAULT_SEPARATOR;\r
-\r
- private String asUniqueString;\r
-\r
- /** For ORM */\r
- private Long tid;\r
-\r
- public TreeSPath() {\r
-\r
- }\r
-\r
- public TreeSPath(String asUniqueString) {\r
- this.asUniqueString = checkAndFormatPath(asUniqueString);\r
- }\r
-\r
- public String getAsUniqueString() {\r
- return asUniqueString;\r
- }\r
-\r
- /**\r
- * Sets all the required data from a string. <b>ATTENTION</b>: the path is\r
- * not checked for performance reason. This method should be used only by\r
- * ORM/OXM frameworks. Use constructor to create immutable tree structure\r
- * paths.\r
- */\r
- public void setAsUniqueString(String str) {\r
- this.asUniqueString = str;\r
- }\r
-\r
- /** The separator actually used by this path. */\r
- public Character getSeparator() {\r
- return separator;\r
- }\r
-\r
- /** Gets the parent path. */\r
- public TreeSPath getParent() {\r
- int lastSep = getAsUniqueString().lastIndexOf(separator);\r
- if (lastSep < 1) {\r
- return null;\r
- }\r
- String parentUniqueString = getAsUniqueString().substring(0, lastSep);\r
- return new TreeSPath(parentUniqueString);\r
- }\r
-\r
- /** Gets the name part of the path. */\r
- public String getName() {\r
- int lastSep = getAsUniqueString().lastIndexOf(separator);\r
- return getAsUniqueString().substring(lastSep + 1);\r
- }\r
-\r
- /** Create a path without parent. */\r
- public static TreeSPath createRootPath(String name) {\r
- if (name.indexOf(DEFAULT_SEPARATOR) >= 0) {\r
- throw new SlcException("Name cannot contain " + DEFAULT_SEPARATOR);\r
- }\r
- return new TreeSPath('/' + name);\r
- }\r
-\r
- /** Create a child . */\r
- public TreeSPath createChild(String name) {\r
- if (name.indexOf(separator) > -1) {\r
- throw new SlcException("Tree path name '" + name\r
- + "' contains separator character " + separator);\r
- }\r
- return new TreeSPath(getAsUniqueString() + '/' + name);\r
- }\r
-\r
- /**\r
- * Parses a string to a path.\r
- * \r
- * @deprecated use constructor instead\r
- */\r
- public static TreeSPath parseToCreatePath(String path) {\r
- return parseToCreatePath(path, DEFAULT_SEPARATOR);\r
- }\r
-\r
- protected String checkAndFormatPath(String str) {\r
- if (str.length() < 2) {\r
- throw new SlcException("Path " + str + " is not short");\r
- }\r
- if (str.charAt(0) != separator) {\r
- throw new SlcException("Path " + str + " have to start with "\r
- + separator);\r
- }\r
-\r
- StringBuffer buf = new StringBuffer(str.length() + 5);\r
- StringTokenizer st = new StringTokenizer(str, separator.toString());\r
- while (st.hasMoreTokens()) {\r
- buf.append(separator).append(st.nextToken());\r
- }\r
- return buf.toString();\r
- }\r
-\r
- /**\r
- * Parses a string to a path.\r
- * \r
- * @deprecated use constructor instead\r
- */\r
- public static TreeSPath parseToCreatePath(String path, Character separator) {\r
- return new TreeSPath(path);\r
- }\r
-\r
- /** Lists the children from a registry. */\r
- public List<TreeSPath> listChildren(StructureRegistry<TreeSPath> registry) {\r
- return listChildrenPaths(registry, this);\r
- }\r
-\r
- /** Lists the children from a given path from a registry. */\r
- public static List<TreeSPath> listChildrenPaths(\r
- StructureRegistry<TreeSPath> registry, TreeSPath path) {\r
- List<TreeSPath> paths = new Vector<TreeSPath>();\r
- List<TreeSPath> allPaths = registry.listPaths();\r
- for (TreeSPath pathT : allPaths) {\r
- if (pathT.getParent() != null && pathT.getParent().equals(path)) {\r
- paths.add(pathT);\r
- }\r
- }\r
- return paths;\r
- }\r
-\r
- /** Gets the root tree path of this path. */\r
- public TreeSPath getRoot() {\r
- TreeSPath root = this;\r
- while (root.getParent() != null) {\r
- root = root.getParent();\r
- }\r
- return root;\r
- }\r
-\r
- /** Depth of this path. */\r
- public Integer getDepth() {\r
- return depthImpl(this);\r
- }\r
-\r
- protected int depthImpl(TreeSPath path) {\r
- if (path.getParent() == null) {\r
- return 1;\r
- } else {\r
- return depthImpl(path.getParent()) + 1;\r
- }\r
- }\r
-\r
- public List<TreeSPath> getHierarchyAsList() {\r
- List<TreeSPath> lst = new Vector<TreeSPath>();\r
- addParentToList(lst, this);\r
- lst.add(this);\r
- return lst;\r
- }\r
-\r
- protected void addParentToList(List<TreeSPath> lst, TreeSPath current) {\r
- TreeSPath parent = current.getParent();\r
- if (parent != null) {\r
- addParentToList(lst, parent);\r
- lst.add(parent);\r
- }\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return getAsUniqueString();\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (obj instanceof StructurePath) {\r
- StructurePath path = (StructurePath) obj;\r
- return getAsUniqueString().equals(path.getAsUniqueString());\r
- }\r
- return false;\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- return getAsUniqueString().hashCode();\r
- }\r
-\r
- public int compareTo(StructurePath o) {\r
- return getAsUniqueString().compareTo(o.getAsUniqueString());\r
- }\r
-\r
- public Long getTid() {\r
- return tid;\r
- }\r
-\r
- void setTid(Long tid) {\r
- this.tid = tid;\r
- }\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.core.structure.tree;\r
-\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.TreeMap;\r
-import java.util.Vector;\r
-\r
-import org.argeo.slc.UnsupportedException;\r
-import org.argeo.slc.core.structure.SimpleSElement;\r
-import org.argeo.slc.structure.StructureElement;\r
-import org.argeo.slc.structure.StructureRegistry;\r
-\r
-/** Tree based implementation of a structure registry. */\r
-public class TreeSRegistry implements StructureRegistry<TreeSPath> {\r
- /** For ORM */\r
- private Long tid;\r
- private Map<TreeSPath, SimpleSElement> elements = new TreeMap<TreeSPath, SimpleSElement>();\r
-\r
- private String mode = StructureRegistry.ALL;\r
-\r
- private List<TreeSPath> activePaths;\r
-\r
- @SuppressWarnings("unchecked")\r
- public <T extends StructureElement> T getElement(TreeSPath path) {\r
- return (T) elements.get(path);\r
- }\r
-\r
- public List<StructureElement> listElements() {\r
- return new Vector<StructureElement>(elements.values());\r
- }\r
-\r
- public List<TreeSPath> listPaths() {\r
- return new Vector<TreeSPath>(elements.keySet());\r
- }\r
-\r
- public void register(TreeSPath path, StructureElement element) {\r
- if (path == null)\r
- throw new UnsupportedException("Cannot register under a null path.");\r
- if (element == null)\r
- throw new UnsupportedException(\r
- "Cannot register null element for path " + path);\r
- if (element.getLabel() == null)\r
- throw new UnsupportedException(\r
- "Cannot register an element with null label for path "\r
- + path);\r
-\r
- final SimpleSElement simpleSElement;\r
- if (element instanceof SimpleSElement) {\r
- simpleSElement = (SimpleSElement) element;\r
- } else {\r
- simpleSElement = new SimpleSElement(element.getLabel());\r
- }\r
-\r
- elements.put(path, simpleSElement);\r
- }\r
-\r
- public String getMode() {\r
- return mode;\r
- }\r
-\r
- public void setMode(String mode) {\r
- this.mode = mode;\r
- }\r
-\r
- public List<TreeSPath> getActivePaths() {\r
- return activePaths;\r
- }\r
-\r
- public void setActivePaths(List<TreeSPath> activePaths) {\r
- this.activePaths = activePaths;\r
- }\r
-\r
- /** Gets the elements. */\r
- public Map<TreeSPath, SimpleSElement> getElements() {\r
- return elements;\r
- }\r
-\r
- /** Sets the elements (for ORM). */\r
- public void setElements(Map<TreeSPath, SimpleSElement> elements) {\r
- this.elements = elements;\r
- }\r
-\r
- Long getTid() {\r
- return tid;\r
- }\r
-\r
- void setTid(Long tid) {\r
- this.tid = tid;\r
- }\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.core.structure.tree;\r
-\r
-import org.argeo.slc.structure.StructureAware;\r
-import org.argeo.slc.structure.StructureElement;\r
-import org.argeo.slc.structure.StructureRegistry;\r
-\r
-public interface TreeSRelated extends StructureAware<TreeSPath> {\r
- public TreeSPath getBasePath();\r
-\r
- public StructureRegistry<TreeSPath> getRegistry();\r
-\r
- public StructureElement getStructureElement(String key);\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.core.structure.tree;\r
-\r
-import org.argeo.slc.core.structure.SimpleSElement;\r
-import org.argeo.slc.structure.StructureAware;\r
-import org.argeo.slc.structure.StructureElement;\r
-import org.argeo.slc.structure.StructureRegistry;\r
-\r
-/**\r
- * Provides default implementations of some methods of <code>TreeSRelated</code>\r
- * .\r
- */\r
-public abstract class TreeSRelatedHelper implements TreeSRelated {\r
- private TreeSPath basePath;\r
- private StructureRegistry<TreeSPath> registry;\r
-\r
- // private ThreadLocal<TreeSPath> basePath = new ThreadLocal<TreeSPath>();\r
- // private ThreadLocal<StructureRegistry<TreeSPath>> registry = new\r
- // ThreadLocal<StructureRegistry<TreeSPath>>();\r
-\r
- public TreeSPath getBasePath() {\r
- return basePath;\r
- }\r
-\r
- public StructureRegistry<TreeSPath> getRegistry() {\r
- return registry;\r
- }\r
-\r
- public void notifyCurrentPath(StructureRegistry<TreeSPath> registry,\r
- TreeSPath path) {\r
- this.basePath = path;\r
- this.registry = registry;\r
- }\r
-\r
- public StructureElement getStructureElement(String key) {\r
- return new SimpleSElement(key);\r
- }\r
-\r
- /**\r
- * Checks wether the object is {@link StructureAware} and forward path and\r
- * registry. null safe for both arguments.\r
- */\r
- @SuppressWarnings(value = { "unchecked" })\r
- protected void forwardPath(Object obj, String childName) {\r
- if (obj == null)\r
- return;\r
-\r
- if (obj instanceof StructureAware && basePath != null) {\r
- TreeSPath path;\r
- if (childName != null)\r
- path = basePath.createChild(childName);\r
- else\r
- path = basePath;\r
-\r
- ((StructureAware<TreeSPath>) obj).notifyCurrentPath(registry, path);\r
- }\r
- }\r
-\r
-}\r
+++ /dev/null
-<html>\r
-<head></head>\r
-<body>\r
-Tree-based implementation of the SLC structure framework.\r
-</body>\r
-</html>
\ No newline at end of file
package org.argeo.slc.core.test;\r
\r
import org.argeo.slc.SlcException;\r
-import org.argeo.slc.core.structure.tree.TreeSRelatedHelper;\r
import org.argeo.slc.core.test.context.ContextUtils;\r
import org.argeo.slc.test.IncompatibleTestDataException;\r
import org.argeo.slc.test.TestData;\r
import org.argeo.slc.test.context.ContextAware;\r
\r
/** Understands basic test data and context aware test data. */\r
-public class BasicTestDefinition extends TreeSRelatedHelper implements\r
- TestDefinition {\r
+public class BasicTestDefinition implements TestDefinition {\r
\r
public void execute(TestRun testRun) {\r
if (testRun.<TestData> getTestData() instanceof BasicTestData) {\r
} else if (testRun.<TestData> getTestData() instanceof ContextAware) {\r
TestData testData = testRun.getTestData();\r
ContextUtils.compareReachedExpected((ContextAware) testData,\r
- testRun.getTestResult(), this);\r
+ testRun.getTestResult());\r
} else {\r
throw new IncompatibleTestDataException(testRun);\r
}\r
return attributes;\r
}\r
\r
+ public void setAttributes(Map<String, String> attributes) {\r
+ this.attributes = attributes;\r
+ }\r
+\r
}\r
\r
import java.util.UUID;\r
\r
-import org.argeo.slc.core.structure.tree.TreeSPath;\r
import org.argeo.slc.deploy.DeployedSystem;\r
-import org.argeo.slc.process.SlcExecution;\r
-import org.argeo.slc.process.SlcExecutionRelated;\r
-import org.argeo.slc.process.SlcExecutionStep;\r
-import org.argeo.slc.structure.StructureAware;\r
-import org.argeo.slc.structure.StructureRegistry;\r
import org.argeo.slc.test.ExecutableTestRun;\r
import org.argeo.slc.test.TestData;\r
import org.argeo.slc.test.TestDefinition;\r
* A basic bean implementation of a <code>WritableTestRun</code>, holding\r
* references to the various parts of a test run.\r
*/\r
-@SuppressWarnings("deprecation")\r
-public class SimpleTestRun implements WritableTestRun, ExecutableTestRun,\r
- SlcExecutionRelated, StructureAware<TreeSPath> {\r
+public class SimpleTestRun implements WritableTestRun, ExecutableTestRun {\r
private String uuid;\r
\r
private String slcExecutionUuid;\r
private String slcExecutionStepUuid;\r
\r
- private TreeSPath path;\r
- private StructureRegistry<TreeSPath> registry;\r
-\r
private DeployedSystem deployedSystem;\r
private TestData testData;\r
private TestDefinition testDefinition;\r
private TestResult testResult;\r
\r
/** Executes the underlying test definition. */\r
- @SuppressWarnings("unchecked")\r
public void run() {\r
uuid = UUID.randomUUID().toString();\r
if (testResult != null)\r
testResult.notifyTestRun(this);\r
\r
- // Structure\r
- if (testResult != null && path != null\r
- && testResult instanceof StructureAware)\r
- ((StructureAware<TreeSPath>) testResult).notifyCurrentPath(\r
- registry, path);\r
-\r
- if (path != null && testDefinition instanceof StructureAware)\r
- ((StructureAware<TreeSPath>) testDefinition).notifyCurrentPath(\r
- registry, path);\r
-\r
testDefinition.execute(this);\r
}\r
\r
public void setSlcExecutionStepUuid(String slcExecutionStepUuid) {\r
this.slcExecutionStepUuid = slcExecutionStepUuid;\r
}\r
-\r
- @Deprecated\r
- public void notifySlcExecution(SlcExecution slcExecution) {\r
- if (slcExecution != null) {\r
- slcExecutionUuid = slcExecution.getUuid();\r
- SlcExecutionStep step = slcExecution.currentStep();\r
- if (step != null) {\r
- slcExecutionStepUuid = step.getUuid();\r
- }\r
- }\r
- }\r
-\r
- public void notifyCurrentPath(StructureRegistry<TreeSPath> registry,\r
- TreeSPath path) {\r
- this.registry = registry;\r
- this.path = path;\r
- }\r
-\r
}\r
\r
import org.apache.commons.logging.Log;\r
import org.apache.commons.logging.LogFactory;\r
-\r
-import org.argeo.slc.core.structure.tree.TreeSPath;\r
-import org.argeo.slc.core.structure.tree.TreeSRelated;\r
import org.argeo.slc.core.test.SimpleResultPart;\r
-import org.argeo.slc.structure.StructureAware;\r
-import org.argeo.slc.structure.StructureElement;\r
-import org.argeo.slc.structure.StructureRegistry;\r
import org.argeo.slc.test.TestResult;\r
import org.argeo.slc.test.TestStatus;\r
import org.argeo.slc.test.context.ContextAware;\r
private final static Log log = LogFactory.getLog(ContextUtils.class);\r
\r
public static void compareReachedExpected(ContextAware contextAware,\r
- TestResult testResult, TreeSRelated treeSRelated) {\r
+ TestResult testResult) {\r
for (String key : contextAware.getExpectedValues().keySet()) {\r
\r
// Compare expected values with reached ones\r
continue;\r
}\r
\r
- // Register in structure\r
- registerInStructure(testResult, treeSRelated, key);\r
-\r
if (contextAware.getValues().containsKey(key)) {\r
Object reachedValue = contextAware.getValues().get(key);\r
\r
TestStatus.FAILED, "No value reached for key '" + key\r
+ "'"));\r
}\r
- resetStructure(testResult, treeSRelated);\r
- }\r
- }\r
-\r
- @SuppressWarnings("unchecked")\r
- private static void registerInStructure(TestResult testResult,\r
- TreeSRelated treeSRelated, String key) {\r
- if (treeSRelated != null) {\r
- if (treeSRelated.getBasePath() != null) {\r
- TreeSPath path = treeSRelated.getBasePath().createChild(key);\r
- StructureRegistry<TreeSPath> registry = treeSRelated\r
- .getRegistry();\r
- final StructureElement element = treeSRelated\r
- .getStructureElement(key);\r
- registry.register(path, element);\r
- if (testResult instanceof StructureAware)\r
- ((StructureAware<TreeSPath>) testResult).notifyCurrentPath(\r
- registry, path);\r
-\r
- if (log.isDebugEnabled())\r
- log.debug("Checking key " + key + " for path " + path);\r
- }\r
- }\r
- }\r
-\r
- @SuppressWarnings("unchecked")\r
- private static void resetStructure(TestResult testResult,\r
- TreeSRelated treeSRelated) {\r
- if (treeSRelated != null) {\r
- if (treeSRelated.getBasePath() != null) {\r
- if (testResult instanceof StructureAware) {\r
- ((StructureAware<TreeSPath>) testResult).notifyCurrentPath(\r
- treeSRelated.getRegistry(), treeSRelated\r
- .getBasePath());\r
- }\r
- }\r
}\r
}\r
\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.core.test.tree;\r
-\r
-import java.util.List;\r
-import java.util.Vector;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.slc.core.structure.SimpleSElement;\r
-import org.argeo.slc.core.structure.tree.TreeSPath;\r
-import org.argeo.slc.structure.StructureAware;\r
-import org.argeo.slc.structure.StructureElement;\r
-import org.argeo.slc.structure.StructureElementProvider;\r
-import org.argeo.slc.structure.StructureRegistry;\r
-import org.argeo.slc.test.TestDefinition;\r
-import org.argeo.slc.test.TestResult;\r
-import org.argeo.slc.test.TestRun;\r
-\r
-/**\r
- * Collection of test definitions propagating tree structure information to its\r
- * children.\r
- */\r
-public class CompositeTreeTestDefinition implements TestDefinition,\r
- StructureAware<TreeSPath> {\r
- private Log log = LogFactory.getLog(CompositeTreeTestDefinition.class);\r
-\r
- private List<TestDefinition> tasks = null;\r
- private List<TreeSPath> taskPaths = null;\r
- private TreeSPath path;\r
- private StructureRegistry<TreeSPath> registry;\r
-\r
- @SuppressWarnings({ "unchecked", "rawtypes" })\r
- public void execute(TestRun testRun) {\r
- if (log.isTraceEnabled())\r
- log.trace("Execute sequence of test definitions...");\r
-\r
- int i = 0;\r
- for (TestDefinition task : tasks) {\r
- TestResult result = testRun.getTestResult();\r
- if (result instanceof StructureAware) {\r
- ((StructureAware) result).notifyCurrentPath(registry,\r
- taskPaths.get(i));\r
- }\r
-\r
- task.execute(testRun);\r
-\r
- // Reset current path in case it has been changed\r
- if (result instanceof StructureAware) {\r
- ((StructureAware) result).notifyCurrentPath(registry, path);\r
- }\r
- i++;\r
- }\r
- }\r
-\r
- /** Sets the list of children test definitions */\r
- public void setTasks(List<TestDefinition> tasks) {\r
- this.tasks = tasks;\r
- if (tasks != null) {\r
- taskPaths = new Vector<TreeSPath>();\r
- }\r
- }\r
-\r
- @SuppressWarnings("unchecked")\r
- public void notifyCurrentPath(StructureRegistry<TreeSPath> registry,\r
- TreeSPath path) {\r
- this.path = path;\r
- this.registry = registry;\r
-\r
- // clear task paths\r
- taskPaths.clear();\r
-\r
- Integer count = 0;\r
- for (TestDefinition task : tasks) {\r
- final StructureElement element;\r
- if (task instanceof StructureElementProvider) {\r
- element = ((StructureElementProvider) task)\r
- .createStructureElement();\r
- } else {\r
- element = new SimpleSElement("[no desc]");\r
- }\r
- TreeSPath taskPath = this.path.createChild(count.toString());\r
- registry.register(taskPath, element);\r
- taskPaths.add(taskPath);\r
- if (task instanceof StructureAware) {\r
- ((StructureAware<TreeSPath>) task).notifyCurrentPath(registry,\r
- taskPath);\r
- }\r
- count++;\r
- }\r
- }\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.core.test.tree;\r
-\r
-import java.io.Serializable;\r
-import java.util.List;\r
-import java.util.Vector;\r
-\r
-import org.argeo.slc.test.TestResultPart;\r
-import org.argeo.slc.test.TestStatus;\r
-\r
-/**\r
- * List of <code>TestResultPart</code>. It can be used to build complex\r
- * <code>TestResult</code> affording the possibility to a\r
- * <code>TestDefinition</code> to add a list of result part under the same\r
- * <code>StructurePath</code>.\r
- * \r
- * @see TreeTestResult\r
- */\r
-public class PartSubList implements Serializable {\r
- private static final long serialVersionUID = -5308754827565759844L;\r
-\r
- /** For ORM */\r
- private Long tid;\r
-\r
- private List<TestResultPart> parts = new Vector<TestResultPart>();\r
-\r
- /** Gets the result parts. */\r
- public List<TestResultPart> getParts() {\r
- return parts;\r
- }\r
-\r
- /** Sets the result parts. */\r
- public void setParts(List<TestResultPart> parts) {\r
- this.parts = parts;\r
- }\r
-\r
- Long getTid() {\r
- return tid;\r
- }\r
-\r
- void setTid(Long tid) {\r
- this.tid = tid;\r
- }\r
-\r
- public Boolean getIsPassed() {\r
- for (TestResultPart part : parts) {\r
- if (part.getStatus() != TestStatus.PASSED) {\r
- return false;\r
- }\r
- }\r
- return true;\r
- }\r
-}\r
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.core.test.tree;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-
-import org.argeo.slc.core.attachment.SimpleAttachment;
-
-public class ResultAttributes implements Serializable {
- private static final long serialVersionUID = 1L;
-
- private String uuid = null;
- private Date closeDate = null;
- private Map<String, String> attributes = new Hashtable<String, String>();
- private List<SimpleAttachment> attachments = new ArrayList<SimpleAttachment>();
-
- public ResultAttributes() {
- super();
- }
-
- public ResultAttributes(TreeTestResult ttr) {
- super();
- this.uuid = ttr.getUuid();
- this.attributes = ttr.getAttributes();
- this.closeDate = ttr.getCloseDate();
- this.attachments = ttr.getAttachments();
- }
-
- public String getUuid() {
- return uuid;
- }
-
- public void setUuid(String uuid) {
- this.uuid = uuid;
- }
-
- public Map<String, String> getAttributes() {
- return attributes;
- }
-
- public void setAttributes(Map<String, String> attributes) {
- this.attributes = attributes;
- }
-
- public Date getCloseDate() {
- return closeDate;
- }
-
- public void setCloseDate(Date closeDate) {
- this.closeDate = closeDate;
- }
-
- public List<SimpleAttachment> getAttachments() {
- return attachments;
- }
-
- public void setAttachments(List<SimpleAttachment> attachments) {
- this.attachments = attachments;
- }
-
-}
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.core.test.tree;\r
-\r
-import java.io.Serializable;\r
-import java.util.ArrayList;\r
-import java.util.Date;\r
-import java.util.List;\r
-import java.util.SortedMap;\r
-import java.util.TreeMap;\r
-import java.util.UUID;\r
-import java.util.Vector;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.slc.SlcException;\r
-import org.argeo.slc.core.attachment.Attachment;\r
-import org.argeo.slc.core.attachment.AttachmentsEnabled;\r
-import org.argeo.slc.core.attachment.SimpleAttachment;\r
-import org.argeo.slc.core.structure.tree.TreeSPath;\r
-import org.argeo.slc.structure.StructureAware;\r
-import org.argeo.slc.structure.StructureElement;\r
-import org.argeo.slc.structure.StructureRegistry;\r
-import org.argeo.slc.test.TestResult;\r
-import org.argeo.slc.test.TestResultListener;\r
-import org.argeo.slc.test.TestResultPart;\r
-import org.argeo.slc.test.TestRun;\r
-import org.argeo.slc.test.TestRunAware;\r
-\r
-/**\r
- * Complex implementation of a test result compatible with a tree based\r
- * structure.\r
- */\r
-public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,\r
- Comparable<TreeTestResult>, AttachmentsEnabled, Serializable {\r
-\r
- private static final long serialVersionUID = 1L;\r
- private final static Log log = LogFactory.getLog(TreeTestResult.class);\r
-\r
- // Persistence data\r
- private String uuid = UUID.randomUUID().toString();\r
- private Date closeDate;\r
-\r
- private SortedMap<TreeSPath, PartSubList> resultParts = new TreeMap<TreeSPath, PartSubList>();\r
- private SortedMap<TreeSPath, StructureElement> elements = new TreeMap<TreeSPath, StructureElement>();\r
- private List<SimpleAttachment> attachments = new ArrayList<SimpleAttachment>();\r
-\r
- // Headers. Used to accelerate request on a specific test result.\r
- private SortedMap<String, String> attributes = new TreeMap<String, String>();\r
-\r
- // Runtime Data\r
- private TreeSPath currentPath;\r
- private transient TestRun currentTestRun;\r
- private Boolean warnIfAlreadyClosed = true;\r
- private Boolean strictChecks = false;\r
- // TODO is it really necessary closeDate == null ?\r
- private Boolean isClosed = false;\r
-\r
- private Boolean cache = true;\r
-\r
- private transient List<TestResultListener<TreeTestResult>> listeners = new Vector<TestResultListener<TreeTestResult>>();\r
-\r
- /** Sets the list of listeners. */\r
- public void setListeners(List<TestResultListener<TreeTestResult>> listeners) {\r
- this.listeners = listeners;\r
- }\r
-\r
- public void addResultPart(TestResultPart part) {\r
- if (isClosed)\r
- notifyIssue(\r
- "Trying to add result parts to an already closed result,"\r
- + " consider changing the scope of this test result:"\r
- + " you are referencing the same stored data with each new call.",\r
- null);\r
-\r
- if (currentPath == null)\r
- throw new SlcException("No current path set.");\r
-\r
- if (cache) {\r
- PartSubList subList = resultParts.get(currentPath);\r
- if (subList == null) {\r
- subList = new PartSubList();\r
- resultParts.put(currentPath, subList);\r
- }\r
- subList.getParts().add(part);\r
- }\r
-\r
- if (part instanceof TestRunAware && currentTestRun != null) {\r
- ((TestRunAware) part).notifyTestRun(currentTestRun);\r
- }\r
-\r
- // notify listeners\r
- synchronized (listeners) {\r
- for (TestResultListener<TreeTestResult> listener : listeners) {\r
- listener.resultPartAdded(this, part);\r
- }\r
- }\r
- }\r
-\r
- protected void notifyIssue(String msg, Exception e) {\r
- if (strictChecks)\r
- throw new SlcException(msg, e);\r
- else\r
- log.error(msg, e);\r
- }\r
-\r
- public void notifyCurrentPath(StructureRegistry<TreeSPath> registry,\r
- TreeSPath path) {\r
- if (!cache)\r
- return;\r
-\r
- if (registry != null) {\r
- for (TreeSPath p : path.getHierarchyAsList()) {\r
- if (!elements.containsKey(p)) {\r
- StructureElement elem = registry.getElement(p);\r
- if (elem != null) {\r
- elements.put(p, elem);\r
- }\r
- } else {\r
- if (log.isTraceEnabled())\r
- log.trace("An element is already registered for path "\r
- + p + " and was not updated");\r
- }\r
-\r
- }\r
- }\r
-\r
- currentPath = path;\r
- }\r
-\r
- /** Gets the current path. */\r
- public TreeSPath getCurrentPath() {\r
- return currentPath;\r
- }\r
-\r
- /** Gets all the results structured as a map of <code>PartSubList<code>s. */\r
- public SortedMap<TreeSPath, PartSubList> getResultParts() {\r
- return resultParts;\r
- }\r
-\r
- /**\r
- * Used by ORM systems. Changed to public in order to enable jcr persistence\r
- */\r
- public void setResultParts(SortedMap<TreeSPath, PartSubList> resultParts) {\r
- this.resultParts = resultParts;\r
- }\r
-\r
- public void close() {\r
- if (resultParts.size() == 0) {\r
- if (log.isTraceEnabled())\r
- log.trace("Test Result #" + getUuid()\r
- + " contains no results, no need to close it.");\r
- return;\r
- }\r
-\r
- if (isClosed) {\r
- if (warnIfAlreadyClosed)\r
- log.warn("Test Result #" + getUuid()\r
- + " already closed. Doing nothing.");\r
- return;\r
- }\r
-\r
- closeDate = new Date();\r
-\r
- synchronized (listeners) {\r
- for (TestResultListener<TreeTestResult> listener : listeners) {\r
- listener.close(this);\r
- }\r
- }\r
- isClosed = true;\r
-\r
- if (log.isTraceEnabled())\r
- log.trace("Test Result " + getUuid() + " closed.");\r
- }\r
-\r
- public Date getCloseDate() {\r
- return closeDate;\r
- }\r
-\r
- /** Sets the close date (for ORM) */\r
- public void setCloseDate(Date closeDate) {\r
- this.closeDate = closeDate;\r
- }\r
-\r
- public void notifyTestRun(TestRun testRun) {\r
- currentTestRun = testRun;\r
- }\r
-\r
- public SortedMap<TreeSPath, StructureElement> getElements() {\r
- return elements;\r
- }\r
-\r
- public void setElements(SortedMap<TreeSPath, StructureElement> pathNames) {\r
- this.elements = pathNames;\r
- }\r
-\r
- public String getUuid() {\r
- return uuid;\r
- }\r
-\r
- public void setUuid(String uuid) {\r
- this.uuid = uuid;\r
- }\r
-\r
- public SortedMap<TreeSPath, StructureElement> getRelatedElements(\r
- TreeSPath path) {\r
- if (path == null)\r
- throw new SlcException(\r
- "Cannot retrieve element for a null path in result #"\r
- + uuid);\r
-\r
- SortedMap<TreeSPath, StructureElement> relatedElements = new TreeMap<TreeSPath, StructureElement>();\r
- List<TreeSPath> hierarchy = path.getHierarchyAsList();\r
- for (TreeSPath currPath : elements.keySet()) {\r
- if (hierarchy.contains(currPath)) {\r
- relatedElements.put(currPath, elements.get(currPath));\r
- }\r
- }\r
- return relatedElements;\r
- }\r
-\r
- public TestRun getCurrentTestRun() {\r
- return currentTestRun;\r
- }\r
-\r
- public int compareTo(TreeTestResult ttr2) {\r
- TreeTestResult ttr1 = this;\r
- if (ttr1.getCloseDate() != null && ttr2.getCloseDate() != null) {\r
- if (ttr1.getCloseDate().equals(ttr2.getCloseDate()))\r
- return compareUuid(ttr1, ttr2);\r
- else\r
- return -ttr1.getCloseDate().compareTo(ttr2.getCloseDate());\r
- } else if (ttr1.getCloseDate() != null && ttr2.getCloseDate() == null) {\r
- return 1;\r
- } else if (ttr1.getCloseDate() == null && ttr2.getCloseDate() != null) {\r
- return -1;\r
- } else {\r
- return compareUuid(ttr1, ttr2);\r
- }\r
- }\r
-\r
- protected int compareUuid(TestResult ttr1, TestResult ttr2) {\r
- if (ttr1.getUuid() == null || ttr2.getUuid() == null)\r
- throw new SlcException(\r
- "Cannot compare tree test result with null uuid");\r
- else {\r
- if (ttr1.getUuid().equals(ttr2.getUuid()))\r
- return 0;\r
- return ttr1.getUuid().compareTo(ttr2.getUuid());\r
- }\r
- }\r
-\r
- public boolean equals(Object obj) {\r
- if (obj instanceof TestResult)\r
- return compareUuid(this, ((TestResult) obj)) == 0;\r
- else\r
- return false;\r
- }\r
-\r
- public int hashCode() {\r
- if (uuid != null)\r
- return uuid.hashCode();\r
- else\r
- return super.hashCode();\r
- }\r
-\r
- public SortedMap<String, String> getAttributes() {\r
- return attributes;\r
- }\r
-\r
- public void setAttributes(SortedMap<String, String> attributes) {\r
- this.attributes = attributes;\r
- }\r
-\r
- public void setWarnIfAlreadyClosed(Boolean warnIfAlreadyClosed) {\r
- this.warnIfAlreadyClosed = warnIfAlreadyClosed;\r
- }\r
-\r
- public List<SimpleAttachment> getAttachments() {\r
- return attachments;\r
- }\r
-\r
- public void setAttachments(List<SimpleAttachment> attachments) {\r
- this.attachments = attachments;\r
- }\r
-\r
- public void addAttachment(Attachment attachment) {\r
- attachments.add((SimpleAttachment) attachment);\r
- synchronized (listeners) {\r
- for (TestResultListener<TreeTestResult> listener : listeners) {\r
- if (listener instanceof TreeTestResultListener)\r
- ((TreeTestResultListener) listener).addAttachment(this,\r
- attachment);\r
- }\r
- }\r
- }\r
-\r
- public void setStrictChecks(Boolean strictChecks) {\r
- this.strictChecks = strictChecks;\r
- }\r
-\r
- /**\r
- * Whether information should be stored in thsi object or simply forwarded\r
- * to teh listeners.\r
- */\r
- public void setCache(Boolean cache) {\r
- this.cache = cache;\r
- }\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.core.test.tree;\r
-\r
-import java.util.SortedSet;\r
-import java.util.TreeSet;\r
-\r
-public class TreeTestResultCollection implements\r
- Comparable<TreeTestResultCollection> {\r
- private String id;\r
- private SortedSet<TreeTestResult> results = new TreeSet<TreeTestResult>();\r
-\r
- public TreeTestResultCollection() {\r
- }\r
-\r
- public TreeTestResultCollection(String id) {\r
- this.id = id;\r
- }\r
-\r
- public String getId() {\r
- return id;\r
- }\r
-\r
- public void setId(String id) {\r
- this.id = id;\r
- }\r
-\r
- public SortedSet<TreeTestResult> getResults() {\r
- return results;\r
- }\r
-\r
- public void setResults(SortedSet<TreeTestResult> results) {\r
- this.results = results;\r
- }\r
-\r
- public int compareTo(TreeTestResultCollection o) {\r
- return getId().compareTo(o.getId());\r
- }\r
-\r
- @Override\r
- public boolean equals(Object o) {\r
- if (o instanceof TreeTestResultCollection) {\r
- return getId().equals(((TreeTestResultCollection) o).getId());\r
- }\r
- return false;\r
- }\r
-}\r
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.core.test.tree;
-
-import org.argeo.slc.core.attachment.Attachment;
-import org.argeo.slc.test.TestResultListener;
-
-public interface TreeTestResultListener extends
- TestResultListener<TreeTestResult> {
- public void addAttachment(TreeTestResult testResult,
- Attachment attachment);
-}
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.core.test.tree;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.slc.core.attachment.Attachment;\r
-import org.argeo.slc.test.TestResultPart;\r
-import org.argeo.slc.test.TestStatus;\r
-\r
-/**\r
- * Listener logging tree-based test results to the underlying logging system.\r
- * \r
- * @see TreeTestResult\r
- * \r
- */\r
-public class TreeTestResultLogger implements TreeTestResultListener {\r
-\r
- private static Log log = LogFactory.getLog(TreeTestResultLogger.class);\r
-\r
- private Boolean logExceptionMessages = false;\r
-\r
- public void resultPartAdded(TreeTestResult testResult,\r
- TestResultPart testResultPart) {\r
- String msg = testResultPart + " - " + testResult.getUuid() + ":"\r
- + testResult.getCurrentPath();\r
- if (testResultPart.getStatus().equals(TestStatus.PASSED)) {\r
- log.info(msg);\r
- } else if (testResultPart.getStatus().equals(TestStatus.FAILED)) {\r
- log.warn(msg);\r
- } else if (testResultPart.getStatus().equals(TestStatus.ERROR)) {\r
- if (logExceptionMessages)\r
- msg = msg + "\n" + testResultPart.getExceptionMessage();\r
-\r
- log.error(msg);\r
-\r
- if (!logExceptionMessages || log.isDebugEnabled())\r
- log.debug(testResultPart.getExceptionMessage());\r
-\r
- } else {\r
- log.error("Unknow test status: " + msg);\r
- }\r
- }\r
-\r
- public void close(TreeTestResult testResult) {\r
- log.info("Test result " + testResult.getUuid() + " closed.");\r
- }\r
-\r
- public void setLogExceptionMessages(Boolean logExceptionMessages) {\r
- this.logExceptionMessages = logExceptionMessages;\r
- }\r
-\r
- public void addAttachment(TreeTestResult treeTestResult,\r
- Attachment attachment) {\r
- if (log.isDebugEnabled())\r
- log.debug("Attachment " + attachment + " added to "\r
- + treeTestResult.getUuid());\r
- }\r
-\r
-}\r
+++ /dev/null
-<html>\r
-<head></head>\r
-<body>\r
-Extension of SLC Test integrating tree-based structure.\r
-</body>\r
-</html>
\ No newline at end of file
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.dao.test.tree;\r
-\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.SortedSet;\r
-\r
-import org.argeo.slc.core.test.tree.ResultAttributes;\r
-import org.argeo.slc.core.test.tree.TreeTestResult;\r
-import org.argeo.slc.core.test.tree.TreeTestResultCollection;\r
-\r
-/** Collections DAO */\r
-public interface TreeTestResultCollectionDao {\r
- public void create(TreeTestResultCollection ttrCollection);\r
-\r
- public void update(TreeTestResultCollection ttrCollection);\r
-\r
- public void delete(TreeTestResultCollection ttrCollection);\r
-\r
- public TreeTestResultCollection getTestResultCollection(String id);\r
-\r
- /** Lists all collections */\r
- public SortedSet<TreeTestResultCollection> listCollections();\r
-\r
- /**\r
- * Lists only result ids and attributes of the results belonging to these\r
- * collection, or all results if id is null.\r
- */\r
- public List<ResultAttributes> listResultAttributes(String collectionId);\r
-\r
- /** Lists results filtering based on the arguments. */\r
- public List<TreeTestResult> listResults(String collectionId,\r
- Map<String, String> attributes);\r
-\r
- /** Adds a result to a collection. */\r
- public void addResultToCollection(TreeTestResultCollection ttrc,\r
- String resultUuid);\r
-\r
- /** Removes a result from a collection. */\r
- public void removeResultFromCollection(TreeTestResultCollection ttrc,\r
- String resultUuid);\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.dao.test.tree;\r
-\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.SortedMap;\r
-\r
-import org.argeo.slc.core.attachment.SimpleAttachment;\r
-import org.argeo.slc.core.structure.tree.TreeSPath;\r
-import org.argeo.slc.core.test.SimpleResultPart;\r
-import org.argeo.slc.core.test.tree.TreeTestResult;\r
-import org.argeo.slc.dao.test.TestResultDao;\r
-import org.argeo.slc.structure.StructureElement;\r
-\r
-/**\r
- * Adds DAO features specific to tree test result.\r
- * \r
- * @see TreeTestResult\r
- */\r
-@Deprecated\r
-public interface TreeTestResultDao extends TestResultDao<TreeTestResult> {\r
- /** Lists results containing this path */\r
- public List<TreeTestResult> listResults(TreeSPath path);\r
-\r
- /** Adds a result part related to this path */\r
- public void addResultPart(String testResultId, TreeSPath path,\r
- SimpleResultPart resultPart,\r
- Map<TreeSPath, StructureElement> relatedElements);\r
-\r
- /** Update attributes */\r
- public void updateAttributes(String testResultId,\r
- SortedMap<String, String> attributes);\r
-\r
- public void addAttachment(String testResultId, SimpleAttachment attachment);\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.dao.test.tree;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-\r
-import org.argeo.slc.core.test.tree.TreeTestResult;\r
-import org.argeo.slc.test.TestResultListener;\r
-import org.argeo.slc.test.TestResultPart;\r
-\r
-/**\r
- * Listener persisting tree-based results.\r
- * \r
- * @see TreeTestResult\r
- */\r
-@Deprecated\r
-public class TreeTestResultPersister implements\r
- TestResultListener<TreeTestResult> {\r
- private static Log log = LogFactory.getLog(TreeTestResultPersister.class);\r
-\r
- private TreeTestResultDao testResultDao;\r
-\r
- public void resultPartAdded(TreeTestResult testResult,\r
- TestResultPart testResultPart) {\r
- try {\r
- TreeTestResult persistedResult = testResultDao\r
- .getTestResult(testResult.getUuid());\r
-\r
- if (persistedResult == null) {\r
- testResultDao.create(testResult);\r
- } else {\r
- testResultDao.update(testResult);\r
- }\r
- } catch (Exception e) {\r
- log.error("Could not persist result part " + testResultPart\r
- + " for result " + testResult.getUuid());\r
- }\r
- }\r
-\r
- public void close(TreeTestResult testResult) {\r
- TreeTestResult persistedResult = (TreeTestResult) testResultDao\r
- .getTestResult(testResult.getUuid());\r
-\r
- if (persistedResult != null) {\r
- persistedResult.setCloseDate(testResult.getCloseDate());\r
- testResultDao.update(persistedResult);\r
- }\r
- if (log.isDebugEnabled())\r
- log.debug("Closed result persister for result "\r
- + testResult.getUuid());\r
- }\r
-\r
- /** Sets the DAO to use in order to persist the results. */\r
- public void setTestResultDao(TreeTestResultDao testResultDao) {\r
- this.testResultDao = testResultDao;\r
- }\r
-}\r
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.msg;
-
-import java.io.PrintWriter;
-import java.io.Serializable;
-import java.io.StringWriter;
-
-import org.apache.commons.io.IOUtils;
-import org.argeo.slc.SlcException;
-
-/** Answer to an execution of a remote service which performed changes. */
-public class ExecutionAnswer implements Serializable {
- private static final long serialVersionUID = -3268867743181316160L;
- public final static String OK = "OK";
- public final static String ERROR = "ERROR";
-
- private String status = OK;
- private String message = "";
-
- /** Canonical constructor */
- public ExecutionAnswer(String status, String message) {
- setStatus(status);
- if (message == null)
- throw new SlcException("Message cannot be null");
- this.message = message;
- }
-
- /** Empty constructor */
- public ExecutionAnswer() {
- }
-
- public String getStatus() {
- return status;
- }
-
- public void setStatus(String status) {
- if (status == null || (!status.equals(OK) && !status.equals(ERROR)))
- throw new SlcException("Bad status format: " + status);
- this.status = status;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
-
- public Boolean isOk() {
- return status.equals(OK);
- }
-
- public Boolean isError() {
- return status.equals(ERROR);
- }
-
- public static ExecutionAnswer error(String message) {
- return new ExecutionAnswer(ERROR, message);
- }
-
- public static ExecutionAnswer error(Throwable e) {
- StringWriter writer = new StringWriter();
- try {
- e.printStackTrace(new PrintWriter(writer));
- return new ExecutionAnswer(ERROR, writer.toString());
- } finally {
- IOUtils.closeQuietly(writer);
- }
- }
-
- public static ExecutionAnswer ok(String message) {
- return new ExecutionAnswer(OK, message);
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.msg;
-
-public class MsgConstants {
-
- public final static String PROPERTY_SLC_AGENT_ID = "slc_agentId";
- public final static String PROPERTY_SLC_EXECUTION_ID = "slc_executionId";
- public final static String PROPERTY_SLC_EXECUTION_STATUS = "slc_executionStatus";
-
- /** Force singleton */
- private MsgConstants() {
-
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.msg;
-
-public interface MsgHandler {
- public Object handleMsg(Object msg);
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.msg;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-public class ObjectList implements Serializable{
- private static final long serialVersionUID = -7200599279369084551L;
- private List<Serializable> objects = new ArrayList<Serializable>();
-
- public ObjectList() {
- }
-
- public ObjectList(Collection<? extends Serializable> objects) {
- this.objects.addAll(objects);
- }
-
- @SuppressWarnings(value = { "unchecked" })
- public <T extends Serializable> void fill(List<T> objects) {
- for (Serializable o : this.objects){
- objects.add((T) o);
- }
- }
-
- public List<Serializable> getObjects() {
- return objects;
- }
-
- public void setObjects(List<Serializable> objects) {
- this.objects = objects;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.msg;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-public class ReferenceList implements Serializable{
- private static final long serialVersionUID = -6852393203700925723L;
- private List<String> references = new ArrayList<String>();
-
- public ReferenceList() {
- }
-
- public ReferenceList(List<String> references) {
- this.references = references;
- }
-
- public List<String> getReferences() {
- return references;
- }
-
- public void setReferences(List<String> refs) {
- this.references = refs;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.msg.build;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.argeo.slc.BasicNameVersion;
-
-/** Describes a distribution of modules. */
-public class ModularDistributionDescriptor extends BasicNameVersion implements
- Serializable {
- private static final long serialVersionUID = 6076494586594591185L;
- /** key is type, value the URL */
- private Map<String, String> modulesDescriptors = new HashMap<String, String>();
-
- public Map<String, String> getModulesDescriptors() {
- return modulesDescriptors;
- }
-
- public void setModulesDescriptors(Map<String, String> urls) {
- this.modulesDescriptors = urls;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.msg.event;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-
-public class SlcEvent implements Serializable {
- private static final long serialVersionUID = 1566174832839931036L;
- public final static String EVENT_TYPE = "slc_eventType";
- public final static String EVENT_FILTER = "slc_eventFilter";
-
- private Map<String, String> headers = new HashMap<String, String>();
-
- public SlcEvent() {
- }
-
- public SlcEvent(String eventType) {
- headers.put(EVENT_TYPE, eventType);
- }
-
- public Map<String, String> getHeaders() {
- return headers;
- }
-
- public void setHeaders(Map<String, String> headers) {
- this.headers = headers;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.msg.event;
-
-import java.util.List;
-
-public interface SlcEventListener {
- /**
- * Blocks until an event is received or timeout is reached
- *
- * @return the event received or null if timeout was reached before
- * receiving one
- */
- public SlcEvent listen(String subscriberId,
- List<SlcEventListenerDescriptor> descriptors, Long timeout);
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.msg.event;
-
-import java.io.Serializable;
-
-public class SlcEventListenerDescriptor implements Serializable {
- static final long serialVersionUID = 1l;
-
- private final String eventType;
- private final String filter;
-
- public SlcEventListenerDescriptor(String eventType, String filter) {
- super();
- this.eventType = eventType;
- this.filter = filter;
- }
-
- public String getEventType() {
- return eventType;
- }
-
- public String getFilter() {
- return filter;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof SlcEventListenerDescriptor) {
- SlcEventListenerDescriptor eventListenerDescriptor = (SlcEventListenerDescriptor) obj;
- return eventListenerDescriptor.getEventType()
- .equals(getEventType());
- }
- return false;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.msg.event;
-
-import java.util.List;
-
-public interface SlcEventListenerRegister {
- public void addEventListenerDescriptor(
- SlcEventListenerDescriptor eventListenerDescriptor);
-
- public void removeEventListenerDescriptor(
- SlcEventListenerDescriptor eventListenerDescriptor);
-
- public List<SlcEventListenerDescriptor> getDescriptorsCopy();
-
- public String getId();
-
- // public SlcEvent listen(SlcEventListener eventListener, Long timeout);
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.msg.event;
-
-public interface SlcEventPublisher {
- public void publish(SlcEvent event);
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.msg.process;
-
-import java.io.Serializable;
-
-import org.argeo.slc.process.SlcExecution;
-
-@Deprecated
-public class SlcExecutionRequest implements Serializable {
- private static final long serialVersionUID = 4448081961875614441L;
- private SlcExecution slcExecution;
-
- public SlcExecutionRequest() {
- }
-
- public SlcExecutionRequest(SlcExecution slcExecution) {
- this.slcExecution = slcExecution;
- }
-
- public SlcExecution getSlcExecution() {
- return slcExecution;
- }
-
- public void setSlcExecution(SlcExecution slcExecution) {
- this.slcExecution = slcExecution;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "#" + slcExecution.getUuid();
- }
-}
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.msg.process;\r
-\r
-import java.io.Serializable;\r
-\r
-@Deprecated\r
-public class SlcExecutionStatusRequest implements Serializable {\r
- private static final long serialVersionUID = -6495004680978575999L;\r
- private String slcExecutionUuid;\r
- private String newStatus;\r
-\r
- public SlcExecutionStatusRequest() {\r
- }\r
-\r
- public SlcExecutionStatusRequest(String slcExecutionUuid, String newStatus) {\r
- this.slcExecutionUuid = slcExecutionUuid;\r
- this.newStatus = newStatus;\r
- }\r
-\r
- public String getSlcExecutionUuid() {\r
- return slcExecutionUuid;\r
- }\r
-\r
- public void setSlcExecutionUuid(String slcExecutionUuid) {\r
- this.slcExecutionUuid = slcExecutionUuid;\r
- }\r
-\r
- public String getNewStatus() {\r
- return newStatus;\r
- }\r
-\r
- public void setNewStatus(String newStatus) {\r
- this.newStatus = newStatus;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return getClass().getSimpleName() + "#" + slcExecutionUuid;\r
- }\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.msg.process;\r
-\r
-import java.io.Serializable;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.argeo.slc.execution.ExecutionStep;\r
-import org.argeo.slc.process.SlcExecutionStep;\r
-\r
-@Deprecated\r
-public class SlcExecutionStepsRequest implements Serializable {\r
- private static final long serialVersionUID = 6243880315234605390L;\r
- private String slcExecutionUuid;\r
- private List<SlcExecutionStep> steps = new ArrayList<SlcExecutionStep>();\r
-\r
- public SlcExecutionStepsRequest() {\r
-\r
- }\r
-\r
- public SlcExecutionStepsRequest(String slcExecutionUuid,\r
- List<ExecutionStep> steps) {\r
- this.slcExecutionUuid = slcExecutionUuid;\r
- for (ExecutionStep step : steps) {\r
- this.steps.add((SlcExecutionStep) step);\r
- }\r
- }\r
-\r
- public SlcExecutionStepsRequest(String slcExecutionUuid, ExecutionStep step) {\r
- this.slcExecutionUuid = slcExecutionUuid;\r
- List<SlcExecutionStep> steps = new ArrayList<SlcExecutionStep>();\r
- steps.add((SlcExecutionStep) step);\r
- this.steps = steps;\r
- }\r
-\r
- public String getSlcExecutionUuid() {\r
- return slcExecutionUuid;\r
- }\r
-\r
- public void setSlcExecutionUuid(String slcExecutionUuid) {\r
- this.slcExecutionUuid = slcExecutionUuid;\r
- }\r
-\r
- public List<SlcExecutionStep> getSteps() {\r
- return steps;\r
- }\r
-\r
- public void setSteps(List<SlcExecutionStep> step) {\r
- this.steps = step;\r
- }\r
-\r
- public void addStep(SlcExecutionStep step) {\r
- steps.add(step);\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return getClass().getSimpleName() + "#" + slcExecutionUuid + " "\r
- + steps;\r
- }\r
-}\r
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.msg.test.tree;
-
-import java.io.Serializable;
-
-import org.argeo.slc.core.attachment.SimpleAttachment;
-
-public class AddTreeTestResultAttachmentRequest implements Serializable {
- private static final long serialVersionUID = -3193110972587429882L;
- private String resultUuid;
- private SimpleAttachment attachment;
-
- public String getResultUuid() {
- return resultUuid;
- }
-
- public void setResultUuid(String resultUuid) {
- this.resultUuid = resultUuid;
- }
-
- public SimpleAttachment getAttachment() {
- return attachment;
- }
-
- public void setAttachment(SimpleAttachment attachment) {
- this.attachment = attachment;
- }
-
-}
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.msg.test.tree;\r
-\r
-import java.io.Serializable;\r
-import java.util.Date;\r
-\r
-import org.argeo.slc.core.test.tree.TreeTestResult;\r
-\r
-public class CloseTreeTestResultRequest implements Serializable {\r
- private static final long serialVersionUID = 7384136025920047977L;\r
- private String resultUuid;\r
- private Date closeDate;\r
-\r
- public CloseTreeTestResultRequest() {\r
-\r
- }\r
-\r
- public CloseTreeTestResultRequest(String resultUuid, Date closeDate) {\r
- this.resultUuid = resultUuid;\r
- this.closeDate = closeDate;\r
- }\r
-\r
- public CloseTreeTestResultRequest(TreeTestResult ttr) {\r
- this.resultUuid = ttr.getUuid();\r
- this.closeDate = ttr.getCloseDate();\r
- }\r
-\r
- public String getResultUuid() {\r
- return resultUuid;\r
- }\r
-\r
- public void setResultUuid(String id) {\r
- this.resultUuid = id;\r
- }\r
-\r
- public Date getCloseDate() {\r
- return closeDate;\r
- }\r
-\r
- public void setCloseDate(Date closeDate) {\r
- this.closeDate = closeDate;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return getClass().getSimpleName() + "#" + resultUuid;\r
- }\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.msg.test.tree;\r
-\r
-import java.io.Serializable;\r
-\r
-import org.argeo.slc.core.test.tree.TreeTestResult;\r
-import org.argeo.slc.test.TestRunDescriptor;\r
-\r
-public class CreateTreeTestResultRequest implements Serializable {\r
- private static final long serialVersionUID = 7443906609434527687L;\r
- private TreeTestResult treeTestResult;\r
- private TestRunDescriptor testRunDescriptor;\r
-\r
- public CreateTreeTestResultRequest() {\r
-\r
- }\r
-\r
- public CreateTreeTestResultRequest(TreeTestResult treeTestResult) {\r
- this.treeTestResult = treeTestResult;\r
- if (treeTestResult.getCurrentTestRun() != null)\r
- testRunDescriptor = new TestRunDescriptor(treeTestResult\r
- .getCurrentTestRun());\r
- }\r
-\r
- public TreeTestResult getTreeTestResult() {\r
- return treeTestResult;\r
- }\r
-\r
- public void setTreeTestResult(TreeTestResult treeTestResult) {\r
- this.treeTestResult = treeTestResult;\r
- }\r
-\r
- public TestRunDescriptor getTestRunDescriptor() {\r
- return testRunDescriptor;\r
- }\r
-\r
- public void setTestRunDescriptor(TestRunDescriptor testRunDescriptor) {\r
- this.testRunDescriptor = testRunDescriptor;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return getClass().getSimpleName() + "#" + treeTestResult.getUuid();\r
- }\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.msg.test.tree;\r
-\r
-import java.io.Serializable;\r
-import java.util.Map;\r
-import java.util.SortedMap;\r
-\r
-import org.argeo.slc.SlcException;\r
-import org.argeo.slc.core.structure.tree.TreeSPath;\r
-import org.argeo.slc.core.test.SimpleResultPart;\r
-import org.argeo.slc.core.test.tree.PartSubList;\r
-import org.argeo.slc.core.test.tree.TreeTestResult;\r
-import org.argeo.slc.structure.StructureElement;\r
-import org.argeo.slc.test.TestRunDescriptor;\r
-\r
-public class ResultPartRequest implements Serializable {\r
- private static final long serialVersionUID = -6430135988577074226L;\r
- private String resultUuid;\r
- private SimpleResultPart resultPart;\r
- private TreeSPath path;\r
- private Map<TreeSPath, StructureElement> relatedElements;\r
- private TestRunDescriptor testRunDescriptor;\r
- private Map<String, String> attributes;\r
-\r
- public ResultPartRequest() {\r
-\r
- }\r
-\r
- public ResultPartRequest(TreeTestResult ttr, TreeSPath path,\r
- SimpleResultPart resultPart) {\r
- resultUuid = ttr.getUuid();\r
- this.resultPart = resultPart;\r
- this.path = (path != null ? path : ttr.getCurrentPath());\r
- relatedElements = ttr.getRelatedElements(this.path);\r
- if (ttr.getCurrentTestRun() != null)\r
- testRunDescriptor = new TestRunDescriptor(ttr.getCurrentTestRun());\r
- attributes = ttr.getAttributes();\r
- }\r
-\r
- public ResultPartRequest(TreeTestResult ttr) {\r
- resultUuid = ttr.getUuid();\r
- this.path = ttr.getCurrentPath();\r
-\r
- PartSubList lst = ttr.getResultParts().get(path);\r
- if (lst.getParts().size() < 1) {\r
- throw new SlcException("Cannot find part for path " + path\r
- + " in result " + resultUuid);\r
- }\r
-\r
- this.resultPart = (SimpleResultPart) lst.getParts().get(\r
- lst.getParts().size() - 1);\r
- relatedElements = ttr.getRelatedElements(path);\r
- if (ttr.getCurrentTestRun() != null)\r
- testRunDescriptor = new TestRunDescriptor(ttr.getCurrentTestRun());\r
- }\r
-\r
- public String getResultUuid() {\r
- return resultUuid;\r
- }\r
-\r
- public void setResultUuid(String resultUuid) {\r
- this.resultUuid = resultUuid;\r
- }\r
-\r
- public SimpleResultPart getResultPart() {\r
- return resultPart;\r
- }\r
-\r
- public void setResultPart(SimpleResultPart resultPart) {\r
- this.resultPart = resultPart;\r
- }\r
-\r
- public TreeSPath getPath() {\r
- return path;\r
- }\r
-\r
- public void setPath(TreeSPath path) {\r
- this.path = path;\r
- }\r
-\r
- public TestRunDescriptor getTestRunDescriptor() {\r
- return testRunDescriptor;\r
- }\r
-\r
- public void setTestRunDescriptor(TestRunDescriptor testRunDescriptor) {\r
- this.testRunDescriptor = testRunDescriptor;\r
- }\r
-\r
- public Map<TreeSPath, StructureElement> getRelatedElements() {\r
- return relatedElements;\r
- }\r
-\r
- public void setRelatedElements(\r
- Map<TreeSPath, StructureElement> relatedElements) {\r
- this.relatedElements = relatedElements;\r
- }\r
-\r
- public Map<String, String> getAttributes() {\r
- return attributes;\r
- }\r
-\r
- public void setAttributes(SortedMap<String, String> attributes) {\r
- this.attributes = attributes;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return getClass().getSimpleName() + "#" + resultUuid + " " + path;\r
- }\r
-}\r
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
default-lazy-init="true">
- <bean id="slcDefault.test.resultLogger"
- class="org.argeo.slc.core.test.tree.TreeTestResultLogger">
- </bean>
-
<bean name="slcDefault.test.testRun"
class="org.argeo.slc.core.test.SimpleTestRun"
scope="prototype">
factory-method="randomUUID" scope="prototype">
</bean>
- <bean id="slcDefault.test.basicTreeTestResult"
- class="org.argeo.slc.core.test.tree.TreeTestResult"
- abstract="true" destroy-method="close">
- <property name="uuid">
- <bean factory-bean="slcDefault.test.uuid"
- factory-method="toString">
- </bean>
- </property>
- <property name="listeners">
- <list>
- <ref bean="slcDefault.test.resultLogger" />
- </list>
- </property>
- </bean>
-
<bean id="slcDefault.test.basicSimpleTestResult"
class="org.argeo.slc.core.test.SimpleTestResult"
abstract="true">
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Copyright (C) 2007-2012 Mathieu Baudier
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
- default-lazy-init="true">
-
- <description>Deprecated</description>
-
- <bean id="slcDefault.test.resultLogger" class="org.argeo.slc.core.test.tree.TreeTestResultLogger">
- </bean>
-
- <bean name="slcDefault.test.testRun" class="org.argeo.slc.core.test.SimpleTestRun"
- scope="prototype">
- </bean>
-
- <bean name="slcDefault.test.uuid" class="java.util.UUID"
- factory-method="randomUUID" scope="prototype">
- </bean>
-
- <bean id="slcDefault.test.basicTreeTestResult" class="org.argeo.slc.core.test.tree.TreeTestResult"
- abstract="true" destroy-method="close">
- <property name="uuid">
- <bean factory-bean="slcDefault.test.uuid" factory-method="toString">
- </bean>
- </property>
- <property name="listeners">
- <list>
- <ref bean="slcDefault.test.resultLogger" />
- </list>
- </property>
- </bean>
-
- <bean id="slcDefault.test.basicSimpleTestResult" class="org.argeo.slc.core.test.SimpleTestResult"
- abstract="true">
- <property name="uuid">
- <bean factory-bean="slcDefault.test.uuid" factory-method="toString">
- </bean>
- </property>
- </bean>
-
-</beans>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>\r
-<xsl:stylesheet version="1.0"\r
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"\r
- xmlns:slc="http://argeo.org/projects/slc/schemas"\r
- exclude-result-prefixes="slc">\r
-\r
- <xsl:output method="html" omit-xml-declaration="yes" />\r
- <xsl:param name="confDir" select="unkown_confDir"/>\r
- \r
-\r
- <xsl:template match="/">\r
- <html>\r
- <head>\r
- <title>Result</title>\r
- </head>\r
- <body style="font-family: sans-serif">\r
- <h1>\r
- Result\r
- <xsl:value-of select="slc:tree-test-result/@uuid" />\r
- </h1>\r
- <p>Conf dir: <xsl:value-of select="$confDir"/></p>\r
- <xsl:for-each\r
- select="slc:tree-test-result/slc:result-parts/slc:result-part">\r
- <h2>\r
- <xsl:value-of select="@path" />\r
- </h2>\r
- <table>\r
- <xsl:for-each\r
- select="slc:part-sub-list/slc:parts/slc:simple-result-part">\r
- <tr>\r
- <xsl:choose>\r
- <xsl:when\r
- test="slc:status = 'PASSED' ">\r
- <td style="color:green">\r
- <xsl:value-of\r
- select="slc:message" />\r
- </td>\r
- </xsl:when>\r
- <xsl:otherwise>\r
- <td style="color:red">\r
- <xsl:value-of\r
- select="slc:message" />\r
- </td>\r
- </xsl:otherwise>\r
- </xsl:choose>\r
- </tr>\r
- </xsl:for-each>\r
- </table>\r
- </xsl:for-each>\r
- </body>\r
- </html>\r
- </xsl:template>\r
-</xsl:stylesheet>
\ No newline at end of file
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.core.structure.tree;\r
-\r
-import junit.framework.TestCase;\r
-\r
-public class TreeSPathTest extends TestCase {\r
-\r
- public void testNew() {\r
- TreeSPath path = new TreeSPath("/test");\r
- assertEquals("test", path.getName());\r
- assertNull(path.getParent());\r
-\r
- path = new TreeSPath("/root/subdir");\r
- assertEquals("subdir", path.getName());\r
- assertEquals(new TreeSPath("/root"), path.getParent());\r
- }\r
-\r
- public void testEquals() {\r
- TreeSPath path1 = new TreeSPath("/test");\r
- TreeSPath path2 = new TreeSPath("/test");\r
- assertEquals(path1, path2);\r
-\r
- path1 = new TreeSPath("/test/subdir/anotherdir");\r
- path2 = new TreeSPath("/test/subdir/anotherdir");\r
- assertEquals(path1, path2);\r
-\r
- path1 = new TreeSPath("/test/subdir/anotherd");\r
- path2 = new TreeSPath("/test/subdir/anotherdir");\r
- assertNotSame(path1, path2);\r
-\r
- path1 = new TreeSPath("/test/subdir");\r
- path2 = new TreeSPath("/test/subdir/anotherdir");\r
- assertNotSame(path1, path2);\r
-\r
- path1 = new TreeSPath("/test/subd/anotherdir");\r
- path2 = new TreeSPath("/test/subdir/anotherdir");\r
- assertNotSame(path1, path2);\r
- }\r
-\r
- public void testCheckFormat() {\r
- try {\r
- new TreeSPath("hello");\r
- fail("Bad format should be rejected");\r
- } catch (Exception e) {\r
- // exception expected\r
- }\r
-\r
- try {\r
- new TreeSPath("/");\r
- fail("Bad format should be rejected");\r
- } catch (Exception e) {\r
- // exception expected\r
- }\r
-\r
- assertEquals(new TreeSPath("/test"), new TreeSPath("/test/"));\r
- assertEquals(new TreeSPath("/test/dir"), new TreeSPath(\r
- "//test///dir////"));\r
- }\r
-}\r
public void testComplexContext() {\r
SimpleTestResult testResult = new SimpleTestResult();\r
ContextUtils.compareReachedExpected(\r
- (ContextAware) getBean("context.c1"), testResult, null);\r
+ (ContextAware) getBean("context.c1"), testResult);\r
ContextUtils.compareReachedExpected(\r
- (ContextAware) getBean("context.c2"), testResult, null);\r
+ (ContextAware) getBean("context.c2"), testResult);\r
ContextUtils.compareReachedExpected(\r
- (ContextAware) getBean("context.c3"), testResult, null);\r
+ (ContextAware) getBean("context.c3"), testResult);\r
\r
List<TestResultPart> parts = testResult.getParts();\r
assertEquals(6, parts.size());\r
<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Copyright (C) 2007-2012 Mathieu Baudier
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
+<!-- Copyright (C) 2007-2012 Mathieu Baudier Licensed under the Apache License,
+ Version 2.0 (the "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software distributed
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
+ OR CONDITIONS OF ANY KIND, either express or implied. See the License for
+ the specific language governing permissions and limitations under the License. -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<import resource="classpath:org/argeo/slc/core/execution/spring.xml" />
-
- <import
- resource="classpath:/org/argeo/slc/core/test/spring/applicationContext.xml" />
+ <import resource="classpath:/org/argeo/slc/core/test/spring.xml" />
</beans>
\ No newline at end of file
<!-- </bean>-->\r
<!-- </property>-->\r
<property name="testResult">\r
- <bean parent="slcDefault.test.basicTreeTestResult" scope="execution">\r
+ <bean parent="slcDefault.test.basicSimpleTestResult" scope="execution">\r
<property name="attributes">\r
<map>\r
<entry key="displayWithControl" value="@{displayWithControl}" />\r
log.warn(msg);
}
- // Check paths
- if (!previousRequest.getPath().equals(request.getPath())) {
- String msg = "New request is not consistent with previous path. previousPath="
- + previousRequest.getPath()
- + ", newPath="
- + request.getPath() + "\n";
- skippedLog.append(msg);
- log.warn(msg);
- }
-
if (previousAnswer.getStatus() != DetachedAnswer.ERROR) {
// if no error occurred in the replayedSession,
// skip the step
private String uuid;
private Properties properties = new Properties();
private String ref;
- private String path = "";
private Object cachedObject = null;
this.ref = stepRef;
}
- /** A path identifying the request within its source context. */
- public String getPath() {
- return path;
- }
-
- public void setPath(String path) {
- this.path = path;
- }
-
/** The unique identifier of this request. */
public String getUuid() {
return uuid;
buf.append(ref);
buf.append(" #").append(uuid);
buf.append(" cachedObject=").append((cachedObject != null));
- buf.append(" path=").append(path);
buf.append(" properties=").append(properties);
return buf.toString();
}
.setRef(root.getElementsByTagNameNS(
SLC_DETACHED_NAMESPACE_URI, "ref").item(0)
.getTextContent());
- request.setPath(root.getElementsByTagNameNS(
- SLC_DETACHED_NAMESPACE_URI, "path").item(0)
- .getTextContent());
Element propertiesElement = (Element) root.getElementsByTagNameNS(
SLC_DETACHED_NAMESPACE_URI, "properties").item(0);
NodeList propElements = propertiesElement.getElementsByTagNameNS(
"uuid").item(0).getTextContent());
request.setRef(node.getElementsByTagNameNS(SLC_DETACHED_NAMESPACE_URI,
"ref").item(0).getTextContent());
- request.setPath(node.getElementsByTagNameNS(SLC_DETACHED_NAMESPACE_URI,
- "path").item(0).getTextContent());
Element propertiesElement = (Element) node.getElementsByTagNameNS(
SLC_DETACHED_NAMESPACE_URI, "properties").item(0);
NodeList propElements = propertiesElement.getElementsByTagNameNS(
DetachedRequest req) {
log.debug(" uuid=" + req.getUuid());
log.debug(" ref=" + req.getRef());
- log.debug(" path=" + req.getPath());
log.debug(" properties=" + req.getProperties());
DetachedAnswer answer = new DetachedAnswer(req, "Mirror");
// Counters to avoid naming files with same prefix
private long lastSentTime = 0;
private int counter = 0;
-
- private DetachedXmlConverter xmlConverter = null;
-
+
+ private DetachedXmlConverter xmlConverter = null;
+
private long receiveAnswerTimeout = 10000l;
-
- private boolean active = true;
+
+ private boolean active = true;
public synchronized DetachedRequest receiveRequest() throws Exception {
DetachedRequest request = (DetachedRequest) receiveFile(requestsDir,
if (request != null)
if (log.isTraceEnabled())
log.trace("Received detached request #" + request.getUuid()
- + " for ref '" + request.getRef() + "', path="
- + request.getPath());
+ + " for ref '" + request.getRef());
return request;
}
sendFile(requestsDir, request);
if (log.isTraceEnabled())
log.trace("Sent detached request #" + request.getUuid()
- + " for ref '" + request.getRef() + "', path="
- + request.getPath());
+ + " for ref '" + request.getRef());
}
protected synchronized void sendFile(File dir, DetachedCommunication detCom)
// Create file path
StringBuffer filePath = new StringBuffer(dir.getPath());
- filePath.append(File.separatorChar).append(sdf.format(nowDate)).append(
- '-');
+ filePath.append(File.separatorChar).append(sdf.format(nowDate))
+ .append('-');
filePath.append(mf.format(new Object[] { new Long(counter) })).append(
'-');
filePath.append(detCom.getUuid()).append(ext);
FileUtils.moveFileToDirectory(file, processedDir, false);
return detCom;
}
-
+
public synchronized void stop() {
log.debug("Stopping Detached Driver");
active = false;
notifyAll();
- }
-
+ }
+
private synchronized boolean isActive() {
return active;
}
import org.apache.commons.cli.ParseException;
import org.apache.commons.io.IOUtils;
import org.argeo.slc.SlcException;
-import org.argeo.slc.server.client.impl.SlcServerHttpClientImpl;
@SuppressWarnings("static-access")
public class SlcMain {
// "classpath:org/argeo/slc/cli/spring-agent-default.xml";
private final static Option typeOpt = OptionBuilder.withLongOpt("mode")
- .withArgName("mode").hasArg().withDescription(
- "Execution type, one of: " + listTypeValues()).create('t');
+ .withArgName("mode").hasArg()
+ .withDescription("Execution type, one of: " + listTypeValues())
+ .create('t');
- private final static Option propertyOpt = OptionBuilder.withLongOpt(
- "property").withArgName("prop1=val1,prop2=val2").hasArgs()
- .withValueSeparator(',').withDescription(
- "use value for given property").create('p');
+ private final static Option propertyOpt = OptionBuilder
+ .withLongOpt("property").withArgName("prop1=val1,prop2=val2")
+ .hasArgs().withValueSeparator(',')
+ .withDescription("use value for given property").create('p');
- private final static Option propertiesOpt = OptionBuilder.withLongOpt(
- "properties").withArgName("properties file").hasArgs()
- .withValueSeparator(',').withDescription(
- "load properties from file (-p has priority)").create('P');
+ private final static Option propertiesOpt = OptionBuilder
+ .withLongOpt("properties").withArgName("properties file").hasArgs()
+ .withValueSeparator(',')
+ .withDescription("load properties from file (-p has priority)")
+ .create('P');
private final static Option moduleOpt = OptionBuilder.withLongOpt("module")
.withArgName("module").hasArg().withDescription("Execution module")
.withArgName("flows").hasArg().withDescription("Flows to execute")
.create('f');
- private final static Option runtimeOpt = OptionBuilder.withLongOpt(
- "runtime").withArgName("runtime").hasArg().withDescription(
- "Runtime URL").create('r');
+ private final static Option runtimeOpt = OptionBuilder
+ .withLongOpt("runtime").withArgName("runtime").hasArg()
+ .withDescription("Runtime URL").create('r');
private final static Options options;
// Agent
else if (type.equals(Type.agent)) {
}
- // Server
- else if (type.equals(Type.server)) {
- SlcServerHttpClientImpl slcServerHttpClient = new SlcServerHttpClientImpl();
- slcServerHttpClient.setBaseUrl(urlStr);
- }
}
public static void printUsage() {
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.server.client;
-
-import java.util.Map;
-
-import org.argeo.slc.Condition;
-
-/** Abstraction of the access to HTTP services . */
-public interface HttpServicesClient {
- /** Call service, failing if it is not available. */
- public <T> T callService(String path, Map<String, String> parameters);
-
- /**
- * Call service, waiting and retrying until the timeout is reached if it is
- * not immediately available.
- *
- * @param path
- * service path
- * @param condition
- * if not null, a condition to be applied on received object,
- * keep trying if it returns false.
- * @param timeout
- * timeout after which an exception is thrown
- */
- public <T> T callServiceSafe(String path, Map<String, String> parameters,
- Condition<T> condition, Long timeout);
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.server.client;
-
-import java.util.List;
-import java.util.Map;
-
-import org.argeo.slc.execution.ExecutionModuleDescriptor;
-import org.argeo.slc.msg.ExecutionAnswer;
-import org.argeo.slc.msg.event.SlcEvent;
-import org.argeo.slc.process.RealizedFlow;
-import org.argeo.slc.process.SlcExecution;
-import org.argeo.slc.runtime.SlcAgentDescriptor;
-import org.argeo.slc.server.HttpServices;
-
-/** Abstraction of the access to HTTP services of an SLC Server. */
-public interface SlcServerHttpClient extends HttpServicesClient,HttpServices {
- /** Wait for the provided SlcExecution to be finished. */
- public void waitForSlcExecutionFinished(SlcExecution slcExecution,
- Long timeout);
-
- /** Block until one of the registered event is finished. */
- public SlcEvent pollEvent(Long timeout);
-
- /** Register an event type. */
- public ExecutionAnswer addEventListener(String eventType, String eventFilter);
-
- /** Unregister an event type. */
- public ExecutionAnswer removeEventListener(String eventType,
- String eventFilter);
-
- /** Wait for one agent to be available. */
- public SlcAgentDescriptor waitForOneAgent();
-
- /** Wait for the http server to be ready. */
- public void waitForServerToBeReady();
-
- /** Start an execution flow on the given agent. */
- public SlcExecution startFlow(String agentId, RealizedFlow realizedFlow);
-
- /** Assume one agent and one version per module. */
- public SlcExecution startFlowDefault(String moduleName, String flowName,
- Map<String, Object> args);
-
- /** List execution modules descriptors. */
- public List<ExecutionModuleDescriptor> listModuleDescriptors(String agentId);
-
- /** Retrieve a single execution module descriptor. */
- public ExecutionModuleDescriptor getModuleDescriptor(String agentId,
- String moduleName, String version);
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.server.client.impl;
-
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.Reader;
-import java.io.Writer;
-import java.net.Authenticator;
-import java.net.HttpURLConnection;
-import java.net.PasswordAuthentication;
-import java.net.URL;
-import java.net.URLEncoder;
-import java.util.Map;
-
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.Condition;
-import org.argeo.slc.SlcException;
-import org.argeo.slc.server.client.HttpServicesClient;
-import org.springframework.oxm.Marshaller;
-import org.springframework.oxm.Unmarshaller;
-import org.springframework.util.Assert;
-
-public abstract class AbstractHttpServicesClient implements HttpServicesClient {
- private final static Log log = LogFactory
- .getLog(AbstractHttpServicesClient.class);
-
- private String user;
- private String password;
-
- private Unmarshaller unmarshaller;
- private Marshaller marshaller;
- private String baseUrl;
- private String encoding = "UTF-8";
-
- private Long retryPeriod = 1000l;
- private Long defaultTimeout = 30 * 1000l;
-
- public void init() {
- if (user != null && password != null)
- Authenticator.setDefault(new Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(user, password
- .toCharArray());
- }
- });
- }
-
- @SuppressWarnings(value = { "unchecked" })
- public <T> T callService(String path, Map<String, String> parameters) {
- return (T) callService(path, parameters, null);
- }
-
- @SuppressWarnings(value = { "unchecked" })
- public <T> T callService(String path, Map<String, String> parameters,
- Object body) {
- try {
- return (T) callServiceLowLevel(path, parameters, body);
- } catch (Exception e) {
- throw new SlcException("Cannot call service " + path + " on "
- + baseUrl, e);
- }
- }
-
- @SuppressWarnings(value = { "unchecked" })
- public <T> T callServiceSafe(String path, Map<String, String> parameters,
- Condition<T> condition, Long timeout) {
-
- long begin = System.currentTimeMillis();
- try {
- Object obj = null;
- while (System.currentTimeMillis() - begin < timeout(timeout)) {
- try {
- obj = callServiceLowLevel(path, parameters, null);
- } catch (IOException e) {
- if (log.isTraceEnabled())
- log.trace("Exception when calling service " + path
- + " on " + baseUrl, e);
- }
-
- if (obj != null) {
- if (condition == null)
- break;
- else {
- if (condition.check((T) obj))
- break;
- }
- }
- // wait a bit
- try {
- Thread.sleep(retryPeriod);
- } catch (InterruptedException e) {
- // silent
- }
- }
-
- if (obj == null)
- throw new SlcException(
- "Service "
- + path
- + " on "
- + baseUrl
- + " did not return an answer after calling it safely for "
- + timeout(timeout) + " ms.");
- return (T) obj;
- } catch (Exception e) {
- throw new SlcException(
- "Unexpected exception when safely calling service " + path
- + " on " + baseUrl, e);
- }
- }
-
- protected Object callServiceLowLevel(String path,
- Map<String, String> parameters, Object body) throws IOException {
-
- Assert.notNull(baseUrl, "base url");
- HttpURLConnection connection = null;
- Writer writer = null;
- Reader reader = null;
- try {
- URL url = createUrl(path, parameters);
- connection = (HttpURLConnection) url.openConnection();
-
- if (body != null) {
- connection.setRequestMethod("POST");
- connection.setDoOutput(true);
- connection.setDoInput(true);
- connection.setUseCaches(false);
- connection.setAllowUserInteraction(false);
- connection.setRequestProperty("Content-type",
- "text/xml; charset=" + encoding);
- }
-
- // Establish the connection
- connection.connect();
-
- if (body != null) {
- writer = new OutputStreamWriter(connection.getOutputStream(),
- encoding);
- StreamResult result = new StreamResult(writer);
- marshaller.marshal(body, result);
- writer.flush();
- IOUtils.closeQuietly(writer);
- }
-
- // Read answer
- reader = new InputStreamReader(connection.getInputStream(),
- encoding);
- Source source = new StreamSource(reader);
- Object obj = unmarshaller.unmarshal(source);
- return obj;
- } finally {
- IOUtils.closeQuietly(reader);
- IOUtils.closeQuietly(writer);
- if (connection != null) {
- connection.disconnect();
- }
- }
- }
-
- protected URL createUrl(String service, Map<String, String> parameters) {
- // URL encoded with UTF-8, as recommended by W3C
- final String urlEncoding = "UTF-8";
-
- StringBuffer buf = new StringBuffer(baseUrl + service);
- try {
- if (parameters != null && parameters.size() != 0) {
- buf.append('?');
- boolean first = true;
- for (String key : parameters.keySet()) {
- String value = parameters.get(key);
- if (value != null) {
- if (first)
- first = false;
- else
- buf.append('&');
- String keyEncoded = URLEncoder.encode(key, urlEncoding);
- String valueEncoded = URLEncoder.encode(value,
- urlEncoding);
- buf.append(keyEncoded).append('=').append(valueEncoded);
- }
- }
- }
-
- return new URL(buf.toString());
- } catch (Exception e) {
- throw new SlcException("Cannot create URL: " + buf, e);
- }
- }
-
- public Long timeout(Long timeout) {
- if (timeout == null)
- timeout = getDefaultTimeout();
- return timeout;
- }
-
- public void setUnmarshaller(Unmarshaller unmarshaller) {
- this.unmarshaller = unmarshaller;
- }
-
- public void setBaseUrl(String baseUrl) {
- this.baseUrl = baseUrl;
- }
-
- public Long getRetryPeriod() {
- return retryPeriod;
- }
-
- /** Retry period in ms when accessing service safely. Default is 1000 ms. */
- public void setRetryPeriod(Long retryPeriod) {
- this.retryPeriod = retryPeriod;
- }
-
- public void setMarshaller(Marshaller marshaller) {
- this.marshaller = marshaller;
- }
-
- /** Default is UTF-8. */
- public void setEncoding(String encoding) {
- this.encoding = encoding;
- }
-
- /** Default is 30s */
- public void setDefaultTimeout(Long defaultTimeout) {
- this.defaultTimeout = defaultTimeout;
- }
-
- public Long getDefaultTimeout() {
- return defaultTimeout;
- }
-
- public void setUser(String user) {
- this.user = user;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.server.client.impl;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.Condition;
-import org.argeo.slc.SlcException;
-import org.argeo.slc.execution.ExecutionFlowDescriptor;
-import org.argeo.slc.execution.ExecutionModuleDescriptor;
-import org.argeo.slc.msg.ExecutionAnswer;
-import org.argeo.slc.msg.MsgConstants;
-import org.argeo.slc.msg.ObjectList;
-import org.argeo.slc.msg.event.SlcEvent;
-import org.argeo.slc.process.RealizedFlow;
-import org.argeo.slc.process.SlcExecution;
-import org.argeo.slc.runtime.SlcAgentDescriptor;
-import org.argeo.slc.server.client.SlcServerHttpClient;
-
-public class SlcServerHttpClientImpl extends AbstractHttpServicesClient
- implements SlcServerHttpClient {
-
- protected final static String PARAM_AGENT_ID = "agentId";
-
- private final static Log log = LogFactory
- .getLog(SlcServerHttpClientImpl.class);
-
- private Long serverReadyTimeout = 120 * 1000l;
-
- public void waitForSlcExecutionFinished(SlcExecution slcExecution,
- Long timeout) {
- if (slcExecution.getStatus().equals(SlcExecution.COMPLETED))
- return;
-
- long begin = System.currentTimeMillis();
- while (System.currentTimeMillis() - begin < timeout(timeout)) {
- SlcEvent event = pollEvent(timeout);
- String slcExecutionId = event.getHeaders().get(
- MsgConstants.PROPERTY_SLC_EXECUTION_ID);
- String status = event.getHeaders().get(
- MsgConstants.PROPERTY_SLC_EXECUTION_STATUS);
- if (slcExecutionId.equals(slcExecution.getUuid())
- && status.equals(SlcExecution.COMPLETED)) {
- return;
- }
- }
- throw new SlcException("SLC Execution not completed after timeout "
- + timeout(timeout) + " elapsed.");
- }
-
- public SlcEvent pollEvent(Long timeout) {
- long begin = System.currentTimeMillis();
- while (System.currentTimeMillis() - begin < timeout(timeout)) {
- Object obj = callService(POLL_EVENT, null);
- if (obj instanceof ExecutionAnswer) {
- ExecutionAnswer answer = (ExecutionAnswer) obj;
- if (answer.isError())
- throw new SlcException(
- "Unexpected exception when polling event: "
- + answer.getMessage());
- } else {
- return (SlcEvent) obj;
- }
- }
- throw new SlcException("No event received after timeout "
- + timeout(timeout) + " elapsed.");
- }
-
- public ExecutionAnswer addEventListener(String eventType, String eventFilter) {
- Map<String, String> parameters = new HashMap<String, String>();
- parameters.put(SlcEvent.EVENT_TYPE, eventType);
- parameters.put(SlcEvent.EVENT_FILTER, eventFilter);
- return callService(ADD_EVENT_LISTENER, parameters);
- }
-
- public ExecutionAnswer removeEventListener(String eventType,
- String eventFilter) {
- Map<String, String> parameters = new HashMap<String, String>();
- parameters.put(SlcEvent.EVENT_TYPE, eventType);
- parameters.put(SlcEvent.EVENT_FILTER, eventFilter);
- return callService(REMOVE_EVENT_LISTENER, parameters);
- }
-
- public SlcExecution startFlow(String agentId, RealizedFlow realizedFlow) {
- SlcExecution slcExecution = new SlcExecution();
- slcExecution.setUuid(UUID.randomUUID().toString());
-
- slcExecution.getRealizedFlows().add(realizedFlow);
-
- Map<String, String> parameters = new HashMap<String, String>();
- parameters.put(MsgConstants.PROPERTY_SLC_AGENT_ID, agentId);
- ExecutionAnswer answer = callService(NEW_SLC_EXECUTION, parameters,
- slcExecution);
- if (!answer.isOk())
- throw new SlcException("Could not start flow on agent " + agentId
- + ": " + answer.getMessage());
- return slcExecution;
- }
-
- public SlcExecution startFlowDefault(String moduleName, String flowName,
- Map<String, Object> args) {
- SlcAgentDescriptor agentDescriptor = waitForOneAgent();
- List<ExecutionModuleDescriptor> lst = listModuleDescriptors(agentDescriptor
- .getUuid());
- ExecutionModuleDescriptor moduleDescMinimal = findModule(lst,
- moduleName);
- if (moduleDescMinimal == null)
- throw new SlcException("Cannot find module " + moduleName);
- String moduleVersion = moduleDescMinimal.getVersion();
-
- ExecutionModuleDescriptor moduleDesc = getModuleDescriptor(
- agentDescriptor.getUuid(), moduleName, moduleVersion);
-
- RealizedFlow realizedFlow = new RealizedFlow();
- realizedFlow.setModuleName(moduleName);
- realizedFlow.setModuleVersion(moduleDesc.getVersion());
-
- ExecutionFlowDescriptor flowDescriptor = findFlow(moduleDesc, flowName);
- if (args != null) {
- for (String key : args.keySet()) {
- if (flowDescriptor.getValues().containsKey(key)) {
- flowDescriptor.getValues().put(key, args.get(key));
- }
- }
- }
- realizedFlow.setFlowDescriptor(flowDescriptor);
-
- return startFlow(agentDescriptor.getUuid(), realizedFlow);
-
- // FIXME: polling not working when called from test: no unique
- // session is created on server side
- // SlcExecution slcExecutionFinished = null;
- // try {
- // addEventListener(
- // EventPublisherAspect.EVT_UPDATE_SLC_EXECUTION_STATUS, null);
- // SlcExecution slcExecution = startFlow(agentDescriptor.getUuid(),
- // realizedFlow);
- //
- // waitForSlcExecutionFinished(slcExecution, null);
- //
- // ObjectList ol = callService(LIST_SLC_EXECUTIONS, null);
- // for (Serializable sr : ol.getObjects()) {
- // SlcExecution se = (SlcExecution) sr;
- // if (se.getUuid().equals(slcExecution.getUuid())) {
- // slcExecutionFinished = se;
- // break;
- // }
- // }
- //
- // } finally {
- // removeEventListener(
- // EventPublisherAspect.EVT_UPDATE_SLC_EXECUTION_STATUS, null);
- // }
- //
- // if (slcExecutionFinished == null)
- // throw new SlcException("No finished SLC Execution.");
- // return slcExecutionFinished;
- }
-
- public static ExecutionModuleDescriptor findModule(
- List<ExecutionModuleDescriptor> lst, String moduleName) {
- ExecutionModuleDescriptor moduleDesc = null;
- for (ExecutionModuleDescriptor desc : lst) {
- if (desc.getName().equals(moduleName)) {
- if (moduleDesc != null)
- throw new SlcException(
- "There is more than one module named " + moduleName
- + " (versions: " + moduleDesc + " and "
- + desc.getVersion() + ")");
- moduleDesc = desc;
- }
- }
- return moduleDesc;
- }
-
- public static ExecutionFlowDescriptor findFlow(
- ExecutionModuleDescriptor moduleDesc, String flowName) {
- ExecutionFlowDescriptor flowDesc = null;
- for (ExecutionFlowDescriptor desc : moduleDesc.getExecutionFlows()) {
- if (desc.getName().equals(flowName)) {
- flowDesc = desc;
- }
- }
- return flowDesc;
- }
-
- public List<ExecutionModuleDescriptor> listModuleDescriptors(String agentId) {
- Map<String, String> parameters = new HashMap<String, String>();
- parameters.put(PARAM_AGENT_ID, agentId);
-
- List<ExecutionModuleDescriptor> moduleDescriptors = new ArrayList<ExecutionModuleDescriptor>();
- ObjectList ol = callService(LIST_MODULE_DESCRIPTORS, parameters);
- ol.fill(moduleDescriptors);
- return moduleDescriptors;
- }
-
- public ExecutionModuleDescriptor getModuleDescriptor(String agentId,
- String moduleName, String version) {
- Map<String, String> parameters = new HashMap<String, String>();
- parameters.put(PARAM_AGENT_ID, agentId);
- parameters.put("moduleName", moduleName);
- parameters.put("version", version);
- ExecutionModuleDescriptor moduleDescriptor = callService(
- GET_MODULE_DESCRIPTOR, parameters);
- return moduleDescriptor;
- }
-
- public SlcAgentDescriptor waitForOneAgent() {
- ObjectList objectList = callServiceSafe(LIST_AGENTS, null,
- new Condition<ObjectList>() {
- public Boolean check(ObjectList obj) {
- int size = obj.getObjects().size();
- if (log.isTraceEnabled())
- log.trace("Object list size: " + size);
- return size == 1;
- }
- }, null);
- return (SlcAgentDescriptor) objectList.getObjects().get(0);
- }
-
- public void waitForServerToBeReady() {
- ExecutionAnswer answer = callServiceSafe(IS_SERVER_READY, null, null,
- serverReadyTimeout);
- if (!answer.isOk())
- throw new SlcException("Server is not ready: " + answer);
- }
-
- /**
- * Timeout in ms after which the client will stop waiting for the server to
- * be ready and throw an exception. Default is 120s.
- */
- public void setServerReadyTimeout(Long serverReadyTimeout) {
- this.serverReadyTimeout = serverReadyTimeout;
- }
-
-}
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.slc.SlcException;
-import org.argeo.slc.core.structure.tree.TreeSRelatedHelper;
import org.argeo.slc.core.test.SimpleResultPart;
import org.argeo.slc.core.test.context.ContextUtils;
import org.argeo.slc.core.test.context.DefaultContextTestData;
import org.springframework.beans.factory.config.BeanReference;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-public class DetachedTestDefinition extends TreeSRelatedHelper implements
- TestDefinition, BeanNameAware, BeanFactoryAware, InitializingBean {
+public class DetachedTestDefinition implements TestDefinition, BeanNameAware,
+ BeanFactoryAware, InitializingBean {
private final static Log log = LogFactory
.getLog(DetachedTestDefinition.class);
// Execute
DetachedRequest request = new DetachedRequest();
- request.setPath(getBasePath().toString());
request.setUuid(UUID.randomUUID().toString());
request.setRef(stepBeanNameT);
} catch (Exception e) {
throw new SlcException("Could not receive answer #"
+ request.getUuid() + " for step " + stepBeanNameT, e);
- }
-
+ }
+
if (answer.getStatus() == DetachedAnswer.ERROR)
throw new SlcException("Error when executing step "
+ answer.getUuid() + ": " + answer.getLog());
outputParameters.get(key));
}
-
if (testData != null) {
- ContextUtils.compareReachedExpected(testData, testRun
- .getTestResult(), this);
+ ContextUtils.compareReachedExpected(testData,
+ testRun.getTestResult());
} else {
- ((TestResult)testRun.getTestResult()).addResultPart(
- new SimpleResultPart(TestStatus.PASSED, "Step "
- + stepBeanNameT + " executed successfully"));
+ ((TestResult) testRun.getTestResult())
+ .addResultPart(new SimpleResultPart(TestStatus.PASSED,
+ "Step " + stepBeanNameT + " executed successfully"));
}
}
ns-prefix="&slc-detached-namespace-prefix;" />
<field name="uuid" />
<field name="ref" />
- <field name="path" />
<field name="properties" collection="map">
<bind-xml name="prop" location="properties">
<class name="org.exolab.castor.mapping.MapItem">
public static DetachedRequest createTestRequest() {
DetachedRequest request = new DetachedRequest();
request.setUuid("12345");
- request.setPath("/root/test");
request.setRef("testRef");
Properties properties = new Properties();
properties.setProperty("key1", "value1");
public static void assertDetachedRequest(DetachedRequest expected,
DetachedRequest reached) {
assertEquals(expected.getUuid(), reached.getUuid());
- assertEquals(expected.getPath(), reached.getPath());
assertEquals(expected.getRef(), reached.getRef());
Properties expectedProps = expected.getProperties();
Properties reachedProps = reached.getProperties();
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.dao;
-
-import java.util.List;
-
-import org.argeo.slc.runtime.SlcAgentDescriptor;
-
-@SuppressWarnings("deprecation")
-public interface SlcAgentDescriptorDao extends
- org.argeo.slc.dao.runtime.SlcAgentDescriptorDao {
- public void create(SlcAgentDescriptor slcAgentDescriptor);
-
- public void delete(SlcAgentDescriptor slcAgentDescriptor);
-
- public void delete(String agentId);
-
- public List<SlcAgentDescriptor> listSlcAgentDescriptors();
-
- public SlcAgentDescriptor getAgentDescriptor(String agentId);
-}
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.dao;\r
-\r
-import java.util.List;\r
-\r
-import org.argeo.slc.process.SlcExecution;\r
-import org.argeo.slc.process.SlcExecutionStep;\r
-\r
-@SuppressWarnings("deprecation")\r
-public interface SlcExecutionDao extends\r
- org.argeo.slc.dao.process.SlcExecutionDao {\r
- public void create(SlcExecution slcExecution);\r
-\r
- public void update(SlcExecution slcExecution);\r
-\r
- public SlcExecution getSlcExecution(String uuid);\r
-\r
- public List<SlcExecution> listSlcExecutions();\r
-\r
- public void addSteps(String slcExecutionId,\r
- List<SlcExecutionStep> additionalSteps);\r
-\r
- public List<SlcExecutionStep> tailSteps(final String slcExecutionId,\r
- final Integer nbrOfSteps);\r
-\r
- public List<SlcExecutionStep> tailSteps(final String slcExecutionId,\r
- final String slcExecutionStepId);\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.dao;\r
-\r
-import java.util.Date;\r
-import java.util.List;\r
-\r
-import org.argeo.slc.test.TestResult;\r
-\r
-/**\r
- * The dao for <code>TestResult</code>.\r
- * \r
- * @see TestResult\r
- */\r
-@SuppressWarnings("deprecation")\r
-public interface TestResultDao<T extends TestResult> extends\r
- org.argeo.slc.dao.test.TestResultDao<T> {\r
- /** Gets a test result based on its id. */\r
- public T getTestResult(String uuid);\r
-\r
- /** Persists a new test result. */\r
- public void create(TestResult testResult);\r
-\r
- /** Updates an already persisted test result. */\r
- public void update(TestResult testResult);\r
-\r
- /** Lists all test results. */\r
- public List<T> listTestResults();\r
-\r
- public void close(String id, Date closeDate);\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.dao;\r
-\r
-import org.argeo.slc.test.TestRunDescriptor;\r
-\r
-@SuppressWarnings("deprecation")\r
-public interface TestRunDescriptorDao extends\r
- org.argeo.slc.dao.test.TestRunDescriptorDao {\r
- public TestRunDescriptor getTestRunDescriptor(String id);\r
-\r
- public void saveOrUpdate(TestRunDescriptor testRunDescriptor);\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.dao.process;\r
-\r
-import java.util.List;\r
-\r
-import org.argeo.slc.process.SlcExecution;\r
-import org.argeo.slc.process.SlcExecutionStep;\r
-\r
-/**\r
- * @deprecated will be removed in SLC 2.x, use\r
- * {@link org.argeo.slc.dao.SlcExecutionDao}\r
- */\r
-public interface SlcExecutionDao {\r
- public void create(SlcExecution slcExecution);\r
-\r
- public void update(SlcExecution slcExecution);\r
-\r
- public SlcExecution getSlcExecution(String uuid);\r
-\r
- public List<SlcExecution> listSlcExecutions();\r
-\r
- public void addSteps(String slcExecutionId,\r
- List<SlcExecutionStep> additionalSteps);\r
-\r
- public List<SlcExecutionStep> tailSteps(final String slcExecutionId,\r
- final Integer nbrOfSteps);\r
-\r
- public List<SlcExecutionStep> tailSteps(final String slcExecutionId,\r
- final String slcExecutionStepId);\r
-}\r
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.dao.runtime;
-
-import java.util.List;
-
-import org.argeo.slc.runtime.SlcAgentDescriptor;
-
-/**
- * @deprecated will be removed in SLC 2.0, use
- * {@link org.argeo.slc.dao.SlcAgentDescriptorDao} instead.
- */
-public interface SlcAgentDescriptorDao {
- public void create(SlcAgentDescriptor slcAgentDescriptor);
-
- public void delete(SlcAgentDescriptor slcAgentDescriptor);
-
- public void delete(String agentId);
-
- public List<SlcAgentDescriptor> listSlcAgentDescriptors();
-
- public SlcAgentDescriptor getAgentDescriptor(String agentId);
-}
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.dao.test;\r
-\r
-import java.util.Date;\r
-import java.util.List;\r
-\r
-import org.argeo.slc.test.TestResult;\r
-\r
-/**\r
- * @deprecated will be removed in SLC 2.0, use\r
- * {@link org.argeo.slc.dao.TestResultDao} instead. The dao for\r
- * <code>TestResult</code>.\r
- * \r
- * @see TestResult\r
- */\r
-public interface TestResultDao<T extends TestResult> {\r
- /** Gets a test result based on its id. */\r
- public T getTestResult(String uuid);\r
-\r
- /** Persists a new test result. */\r
- public void create(TestResult testResult);\r
-\r
- /** Updates an already persisted test result. */\r
- public void update(TestResult testResult);\r
-\r
- /** Lists all test results. */\r
- public List<T> listTestResults();\r
-\r
- public void close(String id, Date closeDate);\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.dao.test;\r
-\r
-import org.argeo.slc.dao.TestResultDao;\r
-import org.argeo.slc.test.TestRunDescriptor;\r
-\r
-/** @deprecated will be removed in SLC 2.0, use {@link TestResultDao} instead. */\r
-public interface TestRunDescriptorDao {\r
- public TestRunDescriptor getTestRunDescriptor(String id);\r
-\r
- public void saveOrUpdate(TestRunDescriptor testRunDescriptor);\r
-}\r
+++ /dev/null
-<html>\r
-<head></head>\r
-<body>\r
-Data Access Objects for SLC Test.\r
-</body>\r
-</html>
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.server;
-
-public interface HttpServices {
- public final static String LIST_AGENTS = "listAgents.service";
- public final static String IS_SERVER_READY = "isServerReady.service";
- public final static String NEW_SLC_EXECUTION = "newSlcExecution.service";
- public final static String LIST_SLC_EXECUTIONS = "listSlcExecutions.service";
- public final static String GET_MODULE_DESCRIPTOR = "getExecutionDescriptor.service";
- public final static String LIST_MODULE_DESCRIPTORS = "listModulesDescriptors.service";
- public final static String LIST_RESULTS = "listResults.service";
- public final static String ADD_EVENT_LISTENER = "addEventListener.service";
- public final static String REMOVE_EVENT_LISTENER = "removeEventListener.service";
- public final static String POLL_EVENT = "pollEvent.service";
-
-}
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.structure;\r
-\r
-/**\r
- * Wrapper for an element, which is able to propagate registration to\r
- * sub-elements.\r
- */\r
-public interface StructureAware<T extends StructurePath> {\r
- /** Called <b>after</b> registration. */\r
- public void notifyCurrentPath(StructureRegistry<T> registry, T path);\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.structure;\r
-\r
-import java.util.Map;\r
-\r
-/**\r
- * Atomic element holding metadata such as description about the element which\r
- * registered.\r
- */\r
-public interface StructureElement {\r
- /** Label of this element. */\r
- public String getLabel();\r
- \r
- /** tags attached to this element*/\r
- public Map<String, String> getTags();\r
-\r
- \r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.structure;\r
-\r
-public interface StructureElementProvider {\r
- public StructureElement createStructureElement();\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.structure;\r
-\r
-/**\r
- * Path allowing to uniquely identify a <code>StructureElement</code> within a\r
- * registry.\r
- * \r
- * @see StructureElement\r
- * @see StructurePath\r
- */\r
-public interface StructurePath {\r
- /**\r
- * Unique representation as a string. Most implementation will also provide\r
- * a mean to interpret this string.\r
- */\r
- public String getAsUniqueString();\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.structure;\r
-\r
-import java.util.List;\r
-\r
-/** Registry where the whole structure is stored. */\r
-public interface StructureRegistry<P extends StructurePath> {\r
- /** Read mode: the structure is only read. */\r
- public static String READ = "READ";\r
- /** All mode: everything is executed regardless of the active paths. */\r
- public static String ALL = "ALL";\r
- /** Active mode: only the active paths are executed. */\r
- public static String ACTIVE = "ACTIVE";\r
-\r
- /** Adds an element to the registry. */\r
- public void register(P path, StructureElement element);\r
-\r
- /** Lists <b>all</b> registered elements. */\r
- public List<StructureElement> listElements();\r
-\r
- /** Lists <b>all</b> registered elements. */\r
- public List<P> listPaths();\r
-\r
- /** Gets a element based on its path. */\r
- public <T extends StructureElement> T getElement(P path);\r
-\r
- /**\r
- * Set the interpreter mode: read, all or active.\r
- * \r
- * @see #READ\r
- * @see #ALL\r
- * @see #STATUS_ACTIVE\r
- */\r
- public void setMode(String mode);\r
-\r
- /**\r
- * Gets the current interpreter mode.\r
- * \r
- * @see #READ\r
- * @see #ALL\r
- * @see #STATUS_ACTIVE\r
- */\r
- public String getMode();\r
-\r
- /**\r
- * Gets the list of active paths, which will be run if executed in\r
- * <code>STATUS_ACTIVE</code> mode.\r
- */\r
- public List<P> getActivePaths();\r
-\r
- /**\r
- * Sets the list of active path, which will be run if executed in\r
- * <code>STATUS_ACTIVE</code> mode.\r
- */\r
- public void setActivePaths(List<P> activePaths);\r
-}\r
+++ /dev/null
-<html>\r
-<head></head>\r
-<body>\r
-SLC Structure framework allowing to uniquely reference actions.\r
-</body>\r
-</html>
\ No newline at end of file
\r
/** The actual run of a test */\r
@SuppressWarnings("deprecation")\r
-public interface TestRun extends SlcExecutionAware {\r
+public interface TestRun {\r
/** Gets UUID */\r
public String getUuid();\r
\r
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.argeo.slc</groupId>
<Export-Package>
org.argeo.slc.jcr.*
</Export-Package>
- <Import-Package>org.springframework.context,javax.jcr.nodetype,*</Import-Package>
+ <Import-Package>
+ org.springframework.context,
+ javax.jcr.nodetype,
+ org.springframework.beans.factory,
+ *
+ </Import-Package>
</instructions>
</configuration>
</plugin>
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.jcr.dao;\r
-\r
-import java.util.Calendar;\r
-import java.util.Date;\r
-import java.util.GregorianCalendar;\r
-\r
-import javax.jcr.NamespaceRegistry;\r
-import javax.jcr.RepositoryException;\r
-import javax.jcr.Session;\r
-import javax.jcr.query.Query;\r
-\r
-import org.argeo.ArgeoException;\r
-import org.argeo.jcr.JcrUtils;\r
-import org.argeo.jcr.NodeMapper;\r
-import org.argeo.jcr.NodeMapperProvider;\r
-import org.argeo.slc.runtime.SlcAgentDescriptor;\r
-import org.argeo.slc.test.TestResult;\r
-import org.argeo.slc.test.TestRunDescriptor;\r
-\r
-public abstract class AbstractSlcJcrDao {\r
-\r
- private Session session;\r
-\r
- // protected Workspace workspace;\r
- // protected QueryManager queryManager;\r
- protected NodeMapper nodeMapper;\r
-\r
- // We inject the nodeMapperProvider that define a default node mapper as an\r
- // entry point of the NodeMapper\r
- private NodeMapperProvider nodeMapperProvider;\r
-\r
- public void init() {\r
- nodeMapper = getNodeMapperProvider().findNodeMapper(null);\r
- // JcrUtils.registerNamespaceSafely(session, "slc",\r
- // "http://www.argeo.org/slc/0.12");\r
-\r
- }\r
-\r
- public void setSession(Session session) {\r
- this.session = session;\r
- }\r
-\r
- protected Session getSession() {\r
- return session;\r
- }\r
-\r
- // IoC\r
- public void setNodeMapperProvider(NodeMapperProvider nodeMapperProvider) {\r
- this.nodeMapperProvider = nodeMapperProvider;\r
- }\r
-\r
- // TODO : define a strategy to define basePathes\r
- protected String basePath(TestResult testResult) {\r
- Calendar cal = new GregorianCalendar();\r
- cal.setTime(new Date());\r
- return "/slc/testresults/" + JcrUtils.dateAsPath(cal) + "testresult";\r
- }\r
-\r
- protected String basePath(SlcAgentDescriptor slcAgentDescriptor) {\r
- return "/slc/agents/"\r
- + JcrUtils.hostAsPath(slcAgentDescriptor.getHost()) + "/agent";\r
- }\r
-\r
- protected String basePath(TestRunDescriptor testRunDescriptor) {\r
- return "/slc/testruns/" + testRunDescriptor.getSlcExecutionUuid()\r
- + "/testrun";\r
- }\r
-\r
- protected NodeMapperProvider getNodeMapperProvider() {\r
- return this.nodeMapperProvider;\r
- }\r
-\r
- protected Query createQuery(String query, String type) {\r
- try {\r
- return getSession().getWorkspace().getQueryManager().createQuery(\r
- query, type);\r
- } catch (RepositoryException e) {\r
- throw new ArgeoException("Cannot create query " + query, e);\r
- }\r
- }\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.jcr.dao;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import javax.jcr.Node;\r
-import javax.jcr.NodeIterator;\r
-import javax.jcr.RepositoryException;\r
-import javax.jcr.query.Query;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.jcr.JcrUtils;\r
-import org.argeo.slc.SlcException;\r
-import org.argeo.slc.dao.runtime.SlcAgentDescriptorDao;\r
-import org.argeo.slc.runtime.SlcAgentDescriptor;\r
-\r
-public class SlcAgentDescriptorDaoJcr extends AbstractSlcJcrDao implements\r
- SlcAgentDescriptorDao {\r
- private final static Log log = LogFactory\r
- .getLog(SlcAgentDescriptorDaoJcr.class);\r
-\r
- public void create(SlcAgentDescriptor slcAgentDescriptor) {\r
- try {\r
- nodeMapper.save(getSession(), basePath(slcAgentDescriptor),\r
- slcAgentDescriptor);\r
- getSession().save();\r
- } catch (RepositoryException e) {\r
- throw new SlcException("Cannot import " + slcAgentDescriptor, e);\r
- }\r
- }\r
-\r
- public SlcAgentDescriptor getAgentDescriptor(String agentId) {\r
- // TODO: optimize query\r
- String queryString = "//agent[@uuid='" + agentId + "']";\r
- Query query = createQuery(queryString, Query.XPATH);\r
- Node node = JcrUtils.querySingleNode(query);\r
- if (node == null)\r
- return null;\r
- return (SlcAgentDescriptor) nodeMapper.load(node);\r
- }\r
-\r
- public void delete(SlcAgentDescriptor slcAgentDescriptor) {\r
- try {\r
- String queryString = "//agent[@uuid='"\r
- + slcAgentDescriptor.getUuid() + "']";\r
- Query query = createQuery(queryString, Query.XPATH);\r
- Node node = JcrUtils.querySingleNode(query);\r
- if (node != null) {\r
- node.remove();\r
- getSession().save();\r
- } else\r
- log.warn("No node found for agent descriptor: "\r
- + slcAgentDescriptor);\r
- } catch (RepositoryException e) {\r
- throw new SlcException("Cannot delete " + slcAgentDescriptor, e);\r
- }\r
-\r
- }\r
-\r
- public void delete(String agentId) {\r
- try {\r
- // TODO: optimize query\r
- String queryString = "//agent[@uuid='" + agentId + "']";\r
- Query query = createQuery(queryString, Query.XPATH);\r
- Node node = JcrUtils.querySingleNode(query);\r
- if (node != null)\r
- node.remove();\r
- } catch (RepositoryException e) {\r
- throw new SlcException("Cannot find AgentDescriptor" + agentId, e);\r
- }\r
-\r
- }\r
-\r
- public List<SlcAgentDescriptor> listSlcAgentDescriptors() {\r
- try {\r
- String queryString = "//agent";\r
- Query query = createQuery(queryString, Query.XPATH);\r
-\r
- List<SlcAgentDescriptor> listSad = new ArrayList<SlcAgentDescriptor>();\r
-\r
- NodeIterator ni = query.execute().getNodes();\r
- while (ni.hasNext()) {\r
- Node curNode = (Node) ni.next();\r
- // JcrUtils.debug(curNode);\r
- listSad.add((SlcAgentDescriptor) nodeMapper.load(curNode));\r
- }\r
-\r
- return listSad;\r
- } catch (Exception e) {\r
- throw new SlcException("Cannot load AgentDescriptorList", e);\r
- }\r
- }\r
-\r
-}\r
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.jcr.dao;
-
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.List;
-
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.query.Query;
-import javax.jcr.query.QueryResult;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.jcr.JcrUtils;
-import org.argeo.slc.SlcException;
-import org.argeo.slc.dao.process.SlcExecutionDao;
-import org.argeo.slc.process.SlcExecution;
-import org.argeo.slc.process.SlcExecutionStep;
-
-public class SlcExecutionDaoJcr extends AbstractSlcJcrDao implements
- SlcExecutionDao {
- private final static Log log = LogFactory.getLog(SlcExecutionDaoJcr.class);
-
- public void addSteps(String slcExecutionId,
- List<SlcExecutionStep> additionalSteps) {
- // TODO: optimize, do one single query
- SlcExecution slcExecution = getSlcExecution(slcExecutionId);
- slcExecution.getSteps().addAll(additionalSteps);
- update(slcExecution);
-
- }
-
- public void create(SlcExecution slcExecution) {
- try {
- nodeMapper.save(getSession(), basePath(slcExecution), slcExecution);
- getSession().save();
- } catch (RepositoryException e) {
- throw new SlcException("Cannot create slcExecution" + slcExecution,
- e);
- }
- }
-
- protected String basePath(SlcExecution slcExecution) {
- Calendar cal = new GregorianCalendar();
- cal.setTime(new Date());
- // cal.setTime(slcExecution.getStartDate());
- String host = slcExecution.getHost();
- if (host == null)
- host = "UNKOWNHOST";
- return "/slc/processes/" + JcrUtils.hostAsPath(host) + '/'
- + JcrUtils.dateAsPath(cal) + "process";
- }
-
- public SlcExecution getSlcExecution(String uuid) {
- // TODO: optimize query
- String queryString = "//process[@uuid='" + uuid + "']";
- Query query = createQuery(queryString, Query.XPATH);
- Node node = JcrUtils.querySingleNode(query);
- if (node == null)
- return null;
- return (SlcExecution) nodeMapper.load(node);
- }
-
- public List<SlcExecution> listSlcExecutions() {
- List<SlcExecution> res = new ArrayList<SlcExecution>();
- // TODO: optimize query
- String queryString = "//process";
- try {
- Query query = createQuery(queryString, Query.XPATH);
- QueryResult qr = query.execute();
- NodeIterator iterator = qr.getNodes();
- while (iterator.hasNext()) {
- Node node = iterator.nextNode();
- SlcExecution slcExecution = (SlcExecution) nodeMapper
- .load(node);
- res.add(slcExecution);
- }
- return res;
- } catch (RepositoryException e) {
- throw new SlcException("Cannot list SLC executions", e);
- }
- }
-
- public void merge(SlcExecution slcExecution) {
- throw new UnsupportedOperationException();
- }
-
- public void update(SlcExecution slcExecution) {
- // TODO: optimize query
- String queryString = "//process[@uuid='" + slcExecution.getUuid()
- + "']";
- try {
- Query query = createQuery(queryString, Query.XPATH);
- Node node = JcrUtils.querySingleNode(query);
- nodeMapper.update(node, slcExecution);
- getSession().save();
- } catch (RepositoryException e) {
- throw new SlcException("Cannot update " + slcExecution, e);
- }
- }
-
- public List<SlcExecutionStep> tailSteps(String slcExecutionId,
- Integer nbrOfSteps) {
- log.error("Method not implemented, returning an empty list.");
- return new ArrayList<SlcExecutionStep>();
- }
-
- public List<SlcExecutionStep> tailSteps(String slcExecutionId,
- String slcExecutionStepId) {
- log.error("Method not implemented, returning an empty list.");
- return new ArrayList<SlcExecutionStep>();
- }
-
-}
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.jcr.dao;\r
-\r
-import javax.jcr.Node;\r
-import javax.jcr.RepositoryException;\r
-\r
-import org.argeo.ArgeoException;\r
-import org.argeo.jcr.NodeMapper;\r
-import org.argeo.jcr.NodeMapperProvider;\r
-\r
-public class SlcNodeMapperProvider implements NodeMapperProvider {\r
-// private final static Log log = LogFactory\r
-// .getLog(SlcNodeMapperProvider.class);\r
-\r
- private NodeMapper defaultNodeMapper;\r
- private NodeMapper treeTestResultNodeMapper;\r
-\r
- public void init() {\r
- defaultNodeMapper.setNodeMapperProvider(this);\r
- treeTestResultNodeMapper.setNodeMapperProvider(this);\r
- }\r
-\r
- public NodeMapper findNodeMapper(Node node) {\r
- try {\r
- // useful to initialize recursivity\r
- if (node == null)\r
- return defaultNodeMapper;\r
-\r
- if ("testresult".equals(node.getName()))\r
- return treeTestResultNodeMapper;\r
- else\r
- return defaultNodeMapper;\r
-\r
- } catch (RepositoryException re) {\r
- throw new ArgeoException("Cannot find NodeMapper for node " + node,\r
- re);\r
- }\r
- }\r
-\r
- public void setTreeTestResultNodeMapper(NodeMapper treeTestResultNodeMapper) {\r
- this.treeTestResultNodeMapper = treeTestResultNodeMapper;\r
- }\r
-\r
- public void setDefaultNodeMapper(NodeMapper defaultNodeMapper) {\r
- this.defaultNodeMapper = defaultNodeMapper;\r
- }\r
-\r
-}\r
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.jcr.dao;
-
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.jcr.query.Query;
-
-import org.argeo.jcr.JcrUtils;
-import org.argeo.slc.SlcException;
-import org.argeo.slc.dao.test.TestRunDescriptorDao;
-import org.argeo.slc.test.TestRunDescriptor;
-
-public class TestRunDescriptorDaoJcr extends AbstractSlcJcrDao implements
- TestRunDescriptorDao {
-
- public TestRunDescriptor getTestRunDescriptor(String id) {
- // TODO: optimize query
- String queryString = "//testrun[@testRunUuid='" + id + "']";
- Query query = createQuery(queryString, Query.XPATH);
- Node node = JcrUtils.querySingleNode(query);
- if (node == null)
- return null;
- return (TestRunDescriptor) nodeMapper.load(node);
- }
-
- public void saveOrUpdate(TestRunDescriptor testRunDescriptor) {
- try {
- nodeMapper.save(getSession(), basePath(testRunDescriptor),
- testRunDescriptor);
- getSession().save();
- } catch (RepositoryException e) {
- throw new SlcException("Cannot import " + testRunDescriptor, e);
- }
- }
-
-}
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.jcr.dao;\r
-\r
-import java.util.ArrayList;\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.SortedSet;\r
-import java.util.TreeSet;\r
-\r
-import javax.jcr.Node;\r
-import javax.jcr.NodeIterator;\r
-import javax.jcr.RepositoryException;\r
-import javax.jcr.query.Query;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.jcr.JcrUtils;\r
-import org.argeo.slc.SlcException;\r
-import org.argeo.slc.core.test.tree.ResultAttributes;\r
-import org.argeo.slc.core.test.tree.TreeTestResult;\r
-import org.argeo.slc.core.test.tree.TreeTestResultCollection;\r
-import org.argeo.slc.dao.test.tree.TreeTestResultCollectionDao;\r
-\r
-/** JCR implementation of collections DAO. */\r
-public class TreeTestResultCollectionDaoJcr extends AbstractSlcJcrDao implements\r
- TreeTestResultCollectionDao {\r
-\r
- // FIXME : we handle testResultCollection by adding a property called\r
- // "TestResultCollectionId "\r
- final private String ttrColProp = "collectionId";\r
-\r
- private final static Log log = LogFactory\r
- .getLog(TreeTestResultCollectionDaoJcr.class);\r
-\r
- public void create(TreeTestResultCollection ttrCollection) {\r
- try {\r
- Node curNode;\r
- String colId = ttrCollection.getId();\r
- for (TreeTestResult ttr : ttrCollection.getResults()) {\r
- curNode = nodeMapper.save(getSession(), basePath(ttr), ttr);\r
- curNode.setProperty(ttrColProp, colId);\r
- }\r
- getSession().save();\r
- } catch (RepositoryException e) {\r
- throw new SlcException("Cannot create TreeTestResultCollection "\r
- + ttrCollection, e);\r
- }\r
- }\r
-\r
- public TreeTestResultCollection getTestResultCollection(String id) {\r
- TreeTestResultCollection res = new TreeTestResultCollection();\r
- res.setId(id);\r
- NodeIterator ni = resultNodesInCollection(id);\r
- while (ni.hasNext()) {\r
- res.getResults().add(\r
- (TreeTestResult) nodeMapper.load(ni.nextNode()));\r
- }\r
- return res;\r
- }\r
-\r
- /**\r
- * \r
- * FIXME : validate what this method must really do ? what happen if one of\r
- * the TreeTestResult of the collection is not found in the jcr repository?\r
- * Now we create ttr that are not found and update existing ones.\r
- * FurtherMore if a TreeTestResult is persisted as member the collection but\r
- * is not in the object passed, it is removed.\r
- */\r
- public void update(TreeTestResultCollection ttrCollection) {\r
- try {\r
- log.debug("Update ");\r
- String colId = ttrCollection.getId();\r
- // We add or update existing ones\r
- for (TreeTestResult ttr : ttrCollection.getResults()) {\r
- String queryString = "//testresult[@uuid='" + ttr.getUuid()\r
- + "']";\r
- Node curNode = singleNode(queryString, Query.XPATH);\r
- if (curNode == null) {\r
- curNode = nodeMapper.save(getSession(), basePath(ttr), ttr);\r
- log.debug("New Node added");\r
- } else {\r
- nodeMapper.update(curNode, ttr);\r
- log.debug("Node updated");\r
- }\r
- log\r
- .debug("-----------------------------------------------------------------");\r
- curNode.setProperty(ttrColProp, colId);\r
- JcrUtils.debug(curNode.getSession().getRootNode());\r
- }\r
- // We remove those who are not part of the collection anymore\r
- String queryString = "//*[@" + ttrColProp + "='" + colId + "']";\r
- Query query = createQuery(queryString, Query.XPATH);\r
- log.debug("Query :" + queryString);\r
- NodeIterator ni = query.execute().getNodes();\r
- int i = 0;\r
- while (ni.hasNext()) {\r
- log.debug("Node " + (++i));\r
- Node curNode = ni.nextNode();\r
- String uuid = curNode.getProperty("uuid").getString();\r
- boolean isPartOfTheSet = false;\r
- for (TreeTestResult ttr : ttrCollection.getResults()) {\r
- if (uuid.equals(ttr.getUuid())) {\r
- isPartOfTheSet = true;\r
- log.debug("Node " + i + " found");\r
- break;\r
- }\r
- }\r
- if (!isPartOfTheSet) {\r
- log.debug("Node " + i + " not found. trying to remove");\r
- curNode.getProperty(ttrColProp).remove();\r
- }\r
- }\r
- getSession().save();\r
- } catch (RepositoryException e) {\r
- throw new SlcException("Cannot update TreeTestResultCollection "\r
- + ttrCollection, e);\r
- }\r
- }\r
-\r
- public void delete(TreeTestResultCollection ttrCollection) {\r
- try {\r
- // FIXME: should not delete sub nodes\r
- Node curNode;\r
- String colId = ttrCollection.getId();\r
- NodeIterator ni = resultNodesInCollection(colId);\r
- while (ni.hasNext()) {\r
- curNode = ni.nextNode();\r
- curNode.remove();\r
- }\r
- getSession().save();\r
- } catch (Exception e) {\r
- throw new SlcException("Cannot delete TreeTestResultCollection "\r
- + ttrCollection, e);\r
- }\r
- }\r
-\r
- public SortedSet<TreeTestResultCollection> listCollections() {\r
- // FIXME: optimize\r
- Map<String, TreeTestResultCollection> lst = new HashMap<String, TreeTestResultCollection>();\r
- NodeIterator nodeIterator = query("//testresult");\r
- while (nodeIterator.hasNext()) {\r
- Node node = nodeIterator.nextNode();\r
- String colId = property(node, ttrColProp);\r
- if (colId != null) {\r
- if (!lst.containsKey(colId))\r
- lst.put(colId, new TreeTestResultCollection(colId));\r
- TreeTestResultCollection ttrc = lst.get(colId);\r
- ttrc.getResults().add((TreeTestResult) nodeMapper.load(node));\r
- }\r
- }\r
- return new TreeSet<TreeTestResultCollection>(lst.values());\r
- }\r
-\r
- public void addResultToCollection(final TreeTestResultCollection ttrc,\r
- final String resultUuid) {\r
- try {\r
- String queryString;\r
- Node curNode;\r
- String colId = ttrc.getId();\r
- queryString = "//testresult[@uuid='" + resultUuid + "']";\r
- curNode = singleNode(queryString, Query.XPATH);\r
- if (curNode == null) {\r
- throw new SlcException("Cannot find test result #" + resultUuid);\r
- } else\r
- curNode.setProperty(ttrColProp, colId);\r
- getSession().save();\r
- } catch (Exception e) {\r
- throw new SlcException("Cannot add TreeTestResult of Id "\r
- + resultUuid + " to collection " + ttrc, e);\r
- }\r
-\r
- }\r
-\r
- public void removeResultFromCollection(final TreeTestResultCollection ttrc,\r
- final String resultUuid) {\r
- try {\r
- String queryString;\r
- Node curNode;\r
- queryString = "//testresult[@uuid='" + resultUuid + "' and "\r
- + ttrColProp + "='" + ttrc.getId() + "']";\r
- Query query = createQuery(queryString, Query.XPATH);\r
- curNode = JcrUtils.querySingleNode(query);\r
- if (curNode == null) {\r
- throw new SlcException("Cannot find test result #" + resultUuid);\r
- } else {\r
- curNode.getProperty(ttrColProp).remove();\r
- }\r
- getSession().save();\r
- } catch (RepositoryException e) {\r
- throw new SlcException("Cannot remove TreeTestResult of Id "\r
- + resultUuid + " from collection " + ttrc, e);\r
- }\r
- }\r
-\r
- // FIXME specify and implement this method\r
- public List<ResultAttributes> listResultAttributes(String collectionId) {\r
- // FIXME: optimize\r
- List<ResultAttributes> list = new ArrayList<ResultAttributes>();\r
- if (collectionId == null) {\r
- List<TreeTestResult> results = asTreeTestResultList(resultNodes(\r
- null, null));\r
-\r
- for (TreeTestResult ttr : results) {\r
- list.add(new ResultAttributes(ttr));\r
- }\r
- } else {\r
- NodeIterator nodeIterator = resultNodesInCollection(collectionId);\r
- while (nodeIterator.hasNext()) {\r
- list.add(new ResultAttributes((TreeTestResult) nodeMapper\r
- .load(nodeIterator.nextNode())));\r
- }\r
- }\r
-\r
- return list;\r
- }\r
-\r
- public List<TreeTestResult> listResults(String collectionId,\r
- Map<String, String> attributes) {\r
- List<TreeTestResult> list;\r
-\r
- if (collectionId == null) {\r
- if (attributes == null || attributes.size() == 0)\r
- list = asTreeTestResultList(resultNodes(null, null));\r
- else if (attributes.size() == 1) {\r
- Map.Entry<String, String> entry = attributes.entrySet()\r
- .iterator().next();\r
- list = asTreeTestResultList(resultNodes(entry.getKey(), entry\r
- .getValue()));\r
- } else {\r
- throw new SlcException(\r
- "Multiple attributes filter are currently not supported.");\r
- }\r
- } else {\r
- if (attributes == null || attributes.size() == 0)\r
- list = asTreeTestResultList(resultNodesInCollection(collectionId));\r
- else if (attributes.size() == 1) {\r
- Map.Entry<String, String> entry = attributes.entrySet()\r
- .iterator().next();\r
- list = asTreeTestResultList(resultNodesInCollection(\r
- collectionId, entry.getKey(), entry.getValue()));\r
- } else {\r
- throw new SlcException(\r
- "Multiple attributes filter are currently not supported.");\r
- }\r
- }\r
- return list;\r
- }\r
-\r
- // UTILITIES\r
-\r
- protected NodeIterator resultNodesInCollection(String collectionId,\r
- String attributeKey, String attributeValue) {\r
- String queryString = "//testresult[@" + ttrColProp + "='"\r
- + collectionId + "' and @" + attributeKey + "='"\r
- + attributeValue + "']";\r
- return query(queryString);\r
- }\r
-\r
- protected NodeIterator resultNodesInCollection(String collectionId) {\r
- String queryString = "//testresult[@" + ttrColProp + "='"\r
- + collectionId + "']";\r
- return query(queryString);\r
- }\r
-\r
- protected NodeIterator resultNodes(String attributeKey,\r
- String attributeValue) {\r
- String queryString;\r
- if (attributeKey != null)\r
- queryString = "//testresult[@" + attributeKey + "='"\r
- + attributeValue + "']";\r
- else\r
- queryString = "//testresult";\r
- return query(queryString);\r
- }\r
-\r
- protected List<TreeTestResult> asTreeTestResultList(\r
- NodeIterator nodeIterator) {\r
- List<TreeTestResult> lst = new ArrayList<TreeTestResult>();\r
- while (nodeIterator.hasNext()) {\r
- lst.add((TreeTestResult) nodeMapper.load(nodeIterator.nextNode()));\r
- }\r
- return lst;\r
- }\r
-\r
- private NodeIterator query(String query) {\r
- try {\r
- if (log.isDebugEnabled())\r
- log.debug("Retrieve nodes from query: " + query);\r
- Query q = createQuery(query, Query.XPATH);\r
- return q.execute().getNodes();\r
- } catch (RepositoryException e) {\r
- throw new SlcException("Cannot load nodes from query: " + query);\r
- }\r
- }\r
-\r
- private String property(Node node, String key) {\r
- try {\r
- return node.getProperty(key).getString();\r
- } catch (RepositoryException e) {\r
- log.warn("Cannot retrieve property " + key + " of node " + node, e);\r
- return null;\r
- }\r
- }\r
-\r
- private Node singleNode(String query, String queryType) {\r
- Query q = createQuery(query, queryType);\r
- return JcrUtils.querySingleNode(q);\r
- }\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.jcr.dao;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Calendar;\r
-import java.util.Date;\r
-import java.util.GregorianCalendar;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.SortedMap;\r
-\r
-import javax.jcr.Node;\r
-import javax.jcr.NodeIterator;\r
-import javax.jcr.RepositoryException;\r
-import javax.jcr.Session;\r
-import javax.jcr.query.Query;\r
-import javax.jcr.query.QueryManager;\r
-import javax.jcr.query.QueryResult;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.jcr.JcrUtils;\r
-import org.argeo.slc.SlcException;\r
-import org.argeo.slc.core.attachment.SimpleAttachment;\r
-import org.argeo.slc.core.structure.tree.TreeSPath;\r
-import org.argeo.slc.core.test.SimpleResultPart;\r
-import org.argeo.slc.core.test.tree.TreeTestResult;\r
-import org.argeo.slc.dao.test.tree.TreeTestResultDao;\r
-import org.argeo.slc.structure.StructureElement;\r
-import org.argeo.slc.test.TestResult;\r
-\r
-/**\r
- * The JCR implementation for tree-based result of the test result dao.\r
- * \r
- * @see TreeTestResult\r
- */\r
-\r
-public class TreeTestResultDaoJcr extends AbstractSlcJcrDao implements\r
- TreeTestResultDao {\r
-\r
- private final static Log log = LogFactory\r
- .getLog(TreeTestResultDaoJcr.class);\r
-\r
- public synchronized void create(TestResult testResult) {\r
- try {\r
- nodeMapper.save(getSession(), basePath(testResult), testResult);\r
- getSession().save();\r
- } catch (Exception e) {\r
- throw new SlcException("Cannot create testResult " + testResult, e);\r
- }\r
- }\r
-\r
- public synchronized void update(TestResult testResult) {\r
- try {\r
- nodeMapper.save(getSession(), basePath(testResult), testResult);\r
- getSession().save();\r
- } catch (Exception e) {\r
- throw new SlcException("Cannot update testResult" + testResult, e);\r
- }\r
- }\r
-\r
- public TreeTestResult getTestResult(String uuid) {\r
- String queryString = "//testresult[@uuid='" + uuid + "']";\r
- Query query = createQuery(queryString, Query.XPATH);\r
- Node node = JcrUtils.querySingleNode(query);\r
- if (node == null)\r
- return null;\r
- return (TreeTestResult) nodeMapper.load(node);\r
-\r
- }\r
-\r
- public List<TreeTestResult> listTestResults() {\r
- try {\r
- // TODO: optimize query\r
- String queryString = "//testresult";\r
- Query query = createQuery(queryString, Query.XPATH);\r
- QueryResult queryResult = query.execute();\r
- NodeIterator nodeIterator = queryResult.getNodes();\r
- if (nodeIterator.hasNext()) {\r
- List<TreeTestResult> list = new ArrayList<TreeTestResult>();\r
- nodes: while (nodeIterator.hasNext()) {\r
- Node curNode = (Node) nodeIterator.next();\r
-\r
- // TODO improve architecture and get rid of this hack\r
- if ("slc".equals(curNode.getParent().getName()))\r
- continue nodes;\r
-\r
- list.add((TreeTestResult) nodeMapper.load(curNode));\r
- }\r
- return list;\r
- } else\r
- return null;\r
-\r
- } catch (RepositoryException e) {\r
- throw new SlcException("Cannot load list of TestResult ", e);\r
- }\r
- }\r
-\r
- public List<TreeTestResult> listResults(TreeSPath path) {\r
- try {\r
- // TODO: optimize query\r
- String queryString = "//testresult" + path.getAsUniqueString();\r
- Query query = createQuery(queryString, Query.XPATH);\r
- QueryResult queryResult = query.execute();\r
- NodeIterator nodeIterator = queryResult.getNodes();\r
- if (nodeIterator.hasNext()) {\r
- List<TreeTestResult> list = new ArrayList<TreeTestResult>();\r
- while (nodeIterator.hasNext()) {\r
- list.add((TreeTestResult) nodeMapper\r
- .load((Node) nodeIterator.next()));\r
- }\r
- return list;\r
- } else\r
- return null;\r
-\r
- } catch (RepositoryException e) {\r
- throw new SlcException("Cannot load list of TestResult ", e);\r
- }\r
- }\r
-\r
- public synchronized void close(final String testResultId,\r
- final Date closeDate) {\r
- try {\r
- // TODO: optimize query\r
- String queryString = "//testresult[@uuid='" + testResultId + "']";\r
- Query query = createQuery(queryString, Query.XPATH);\r
- Node resNode = JcrUtils.querySingleNode(query);\r
- Calendar cal = new GregorianCalendar();\r
- cal.setTime(closeDate);\r
- if (resNode != null)\r
- resNode.setProperty("closeDate", cal);\r
- else if (log.isDebugEnabled())\r
- log.debug("Cannot close because a node for test result # "\r
- + testResultId + " was not found");\r
- getSession().save();\r
- } catch (RepositoryException e) {\r
- throw new SlcException("Cannot close TestResult " + testResultId, e);\r
- }\r
-\r
- }\r
-\r
- /**\r
- * Add a SimpleResultPart to the TreeTestResult of ID testResultId at\r
- * treeSPath path\r
- * \r
- * May also add some relatedElements\r
- * \r
- */\r
- // TODO do we load objects, do treatment and persist them or do we work\r
- // directly in JCR\r
- public synchronized void addResultPart(final String testResultId,\r
- final TreeSPath path, final SimpleResultPart resultPart,\r
- final Map<TreeSPath, StructureElement> relatedElements) {\r
-\r
- try {\r
- // TODO: optimize query\r
- String queryString = "//testresult[@uuid='" + testResultId + "']";\r
- Query query = createQuery(queryString, Query.XPATH);\r
- Node resNode = JcrUtils.querySingleNode(query);\r
-\r
- Node curNode;\r
- String usedPath = path.getAsUniqueString().substring(1)\r
- + "/partsublist";\r
-\r
- if (resNode.hasNode(usedPath))\r
- curNode = resNode.getNode(usedPath);\r
- else {\r
-\r
- // TODO Factorize that\r
- Node tmpNode = resNode;\r
- String[] pathes = usedPath.split("/");\r
- for (int i = 0; i < pathes.length; i++) {\r
- if (tmpNode.hasNode(pathes[i]))\r
- tmpNode = tmpNode.getNode(pathes[i]);\r
- else\r
- tmpNode = tmpNode.addNode(pathes[i]);\r
- }\r
- curNode = tmpNode;\r
- }\r
-\r
- nodeMapper.update(curNode.addNode("resultPart"), resultPart);\r
-\r
- if (relatedElements != null) {\r
- for (TreeSPath key : relatedElements.keySet()) {\r
- String relPath = key.getAsUniqueString().substring(1);\r
-\r
- // check if already exists.\r
- if (!resNode.hasNode(relPath)) {\r
-\r
- // TODO Factorize that\r
- Node tmpNode = resNode;\r
- String[] pathes = usedPath.split("/");\r
- for (int i = 0; i < pathes.length; i++) {\r
- if (tmpNode.hasNode(pathes[i]))\r
- tmpNode = tmpNode.getNode(pathes[i]);\r
- else\r
- tmpNode = tmpNode.addNode(pathes[i]);\r
- }\r
- curNode = tmpNode;\r
- } else\r
- curNode = resNode.getNode(relPath);\r
-\r
- curNode.setProperty("label", relatedElements.get(key)\r
- .getLabel());\r
- // We add the tags\r
- Map<String, String> tags = relatedElements.get(key)\r
- .getTags();\r
-\r
- for (String tag : tags.keySet()) {\r
- NodeIterator tagIt = curNode.getNodes("tag");\r
- Node tagNode = null;\r
- while (tagIt.hasNext()) {\r
- Node n = tagIt.nextNode();\r
- if (n.getProperty("name").getString().equals(tag)) {\r
- tagNode = n;\r
- }\r
- }\r
-\r
- if (tagNode == null) {\r
- tagNode = curNode.addNode("tag");\r
- tagNode.setProperty("name", tag);\r
- }\r
-\r
- tagNode.setProperty("value", tags.get(tag));\r
-\r
- // remove forbidden characters\r
- // String cleanTag =\r
- // JcrUtils.removeForbiddenCharacters(tag);\r
- // if (!cleanTag.equals(tag))\r
- // log.warn("Tag '" + tag + "' persisted as '" +\r
- // cleanTag\r
- // + "'");\r
- // childNode.setProperty(cleanTag, tags.get(tag));\r
- }\r
- // for (String tag : tags.keySet()) {\r
- // String cleanTag = JcrUtils\r
- // .removeForbiddenCharacters(tag);\r
- // if (!cleanTag.equals(tag))\r
- // log.warn("Tag '" + tag + "' persisted as '"\r
- // + cleanTag + "'");\r
- // curNode.setProperty(cleanTag, tags.get(tag));\r
- // }\r
-\r
- // We set the class in order to be able to retrieve\r
- curNode.setProperty("class", StructureElement.class\r
- .getName());\r
- }\r
- }\r
- getSession().save();\r
-\r
- } catch (RepositoryException e) {\r
- throw new SlcException("Cannot add resultPart", e);\r
- }\r
- }\r
-\r
- public synchronized void addAttachment(final String testResultId,\r
- final SimpleAttachment attachment) {\r
-\r
- try {\r
- // TODO: optimize query\r
- // Might not be OK.\r
- // Do we have a notion of "currentNode" when we call JCRUtils one\r
- // more time.\r
-\r
- // Check if attachment already exists\r
- String queryString = "//testresult[@uuid='" + testResultId + "']";\r
- Query query = createQuery(queryString, Query.XPATH);\r
- Node resNode = JcrUtils.querySingleNode(query);\r
-\r
- queryString = ".//*[@uuid='" + attachment.getUuid() + "']";\r
- query = createQuery(queryString, Query.XPATH);\r
- Node atNode = JcrUtils.querySingleNode(query);\r
-\r
- if (atNode != null) {\r
- if (log.isDebugEnabled())\r
- log.debug("Attachement already There ");\r
- } else {\r
- if (resNode.hasNode("attachments"))\r
- atNode = resNode.getNode("attachments");\r
- else {\r
- atNode = resNode.addNode("attachments");\r
- }\r
- Node attachNode;\r
- attachNode = atNode.addNode(attachment.getName());\r
- attachNode.setProperty("uuid", attachment.getUuid());\r
- attachNode.setProperty("contentType", attachment\r
- .getContentType());\r
- getSession().save();\r
- }\r
-\r
- } catch (RepositoryException e) {\r
- throw new SlcException("Cannot Add Attachment to " + testResultId,\r
- e);\r
- }\r
- }\r
-\r
- protected TreeTestResult getTreeTestResult(Session session,\r
- String testResultId) {\r
- try {\r
- String queryString = "//testresult[@uuid='" + testResultId + "']";\r
- QueryManager qm = session.getWorkspace().getQueryManager();\r
- Query query = qm.createQuery(queryString, Query.XPATH);\r
- Node node = JcrUtils.querySingleNode(query);\r
- if (node == null)\r
- return null;\r
- return (TreeTestResult) nodeMapper.load(node);\r
-\r
- } catch (RepositoryException e) {\r
- throw new SlcException("Cannot load TestResult with ID "\r
- + testResultId + " For Session " + session, e);\r
- }\r
- }\r
-\r
- public synchronized void updateAttributes(final String testResultId,\r
- final SortedMap<String, String> attributes) {\r
- try {\r
- String queryString = "//testresult[@uuid='" + testResultId + "']";\r
- Query query = createQuery(queryString, Query.XPATH);\r
- Node node = JcrUtils.querySingleNode(query);\r
-\r
- for (String key : attributes.keySet()) {\r
- node.setProperty(key, attributes.get(key));\r
- }\r
- getSession().save();\r
- } catch (RepositoryException e) {\r
- throw new SlcException(\r
- "Cannot update Attributes on TestResult with ID "\r
- + testResultId, e);\r
- }\r
- }\r
-\r
-}\r
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.jcr.dao;
-
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.List;
-import java.util.Map;
-import java.util.SortedMap;
-import java.util.TreeMap;
-import java.util.Vector;
-
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.Property;
-import javax.jcr.PropertyIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.query.Query;
-import javax.jcr.query.QueryManager;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.jcr.spring.BeanNodeMapper;
-import org.argeo.slc.core.attachment.SimpleAttachment;
-import org.argeo.slc.core.structure.SimpleSElement;
-import org.argeo.slc.core.structure.tree.TreeSPath;
-import org.argeo.slc.core.test.tree.PartSubList;
-import org.argeo.slc.core.test.tree.TreeTestResult;
-import org.argeo.slc.structure.StructureElement;
-import org.argeo.slc.test.TestResultPart;
-import org.springframework.beans.BeanWrapper;
-
-public class TreeTestResultNodeMapper extends BeanNodeMapper {
- private final static Log log = LogFactory
- .getLog(TreeTestResultNodeMapper.class);
-
- /**
- * Transforms a TreeTestResult to the specified jcr Node in order to persist
- * it.
- *
- * @param beanWrapper
- * @param node
- * @throws RepositoryException
- */
- protected void beanToNode(BeanWrapper beanWrapper, Node node)
- throws RepositoryException {
-
- if (log.isTraceEnabled())
- log.debug("Map TreeTestResult to node " + node.getPath());
-
- // We know we are mapping a TreeTestResult so we cast it
- TreeTestResult ttr = (TreeTestResult) beanWrapper.getWrappedInstance();
-
- // First we persist the class
- node.setProperty(getClassProperty(), ttr.getClass().getName());
-
- // Then we persist String uuid, Date closeDate
- node.setProperty("uuid", ttr.getUuid());
- if (ttr.getCloseDate() != null) {
- Calendar cal = new GregorianCalendar();
- cal.setTime(ttr.getCloseDate());
- node.setProperty("closeDate", cal);
- }
-
- Node childNode;
-
- // Elements & resultParts are merged, we use treeSPath to build the tree
- // Element label is stored as a property of the vertice
- // ResultParts are stored as childNode named resultpart[xx].
-
- SortedMap<TreeSPath, StructureElement> elements = ttr.getElements();
-
- for (TreeSPath key : elements.keySet()) {
- String relPath = key.getAsUniqueString();
- // We remove the first separator
- relPath = relPath.substring(1);
-
- // check if already exists.
- if (!node.hasNode(relPath)) {
- // TODO Factorize that
- Node tmpNode = node;
- String[] pathes = relPath.split("/");
- for (int i = 0; i < pathes.length; i++) {
- if (tmpNode.hasNode(pathes[i]))
- tmpNode = tmpNode.getNode(pathes[i]);
- else
- tmpNode = tmpNode.addNode(pathes[i]);
- }
- childNode = tmpNode;
- } else
- childNode = node.getNode(relPath);
-
- childNode.setProperty("label", elements.get(key).getLabel());
- // We add the tags
- Map<String, String> tags = elements.get(key).getTags();
- for (String tag : tags.keySet()) {
- NodeIterator tagIt = childNode.getNodes("tag");
- Node tagNode = null;
- while (tagIt.hasNext()) {
- Node n = tagIt.nextNode();
- if (n.getProperty("name").getString().equals(tag)) {
- tagNode = n;
- }
- }
-
- if (tagNode == null) {
- tagNode = childNode.addNode("tag");
- tagNode.setProperty("name", tag);
- }
-
- tagNode.setProperty("value", tags.get(tag));
-
- // remove forbidden characters
- // String cleanTag = JcrUtils.removeForbiddenCharacters(tag);
- // if (!cleanTag.equals(tag))
- // log.warn("Tag '" + tag + "' persisted as '" + cleanTag
- // + "'");
- // childNode.setProperty(cleanTag, tags.get(tag));
- }
-
- // We set the class in order to be able to retrieve
- childNode.setProperty(getClassProperty(), StructureElement.class
- .getName());
- }
-
- SortedMap<TreeSPath, PartSubList> resultParts = ttr.getResultParts();
-
- for (TreeSPath key : resultParts.keySet()) {
- String relPath = key.getAsUniqueString();
-
- // we get rid of the '/' that begins every TreeSPath Unique string
- // and add the partsublist level
- relPath = relPath.substring(1) + "/partsublist";
-
- // check if already exists.
- if (!node.hasNode(relPath)) {
- // TODO Factorize that
- Node tmpNode = node;
- String[] pathes = relPath.split("/");
- for (int i = 0; i < pathes.length; i++) {
- if (tmpNode.hasNode(pathes[i]))
- tmpNode = tmpNode.getNode(pathes[i]);
- else
- tmpNode = tmpNode.addNode(pathes[i]);
- }
- childNode = tmpNode;
- //log.debug("Node created " + childNode.getPath());
- } else {
- childNode = node.getNode(relPath);
- //log.debug("Node already existing " + childNode.getPath());
- }
-
- List<TestResultPart> list = resultParts.get(key).getParts();
-
- Node listNode;
- int i;
- for (i = 0; i < list.size(); i++) {
- // TestResultPart trp = list.get(i);
- // FIXME : ResultParts are systematicaly added.
- // There no check to see if already exists.
- listNode = childNode.addNode("resultpart");
- update(listNode, list.get(i));
- }
- }
-
- // TODO : store files in the graph
- // As for now, we only store on a vertice called after the name value of
- // the SimpleAttachment Object
- // and uuid & contentType as property
-
- List<SimpleAttachment> attachments = ttr.getAttachments();
- if (attachments.size() != 0) {
- if (node.hasNode("attachments"))
- childNode = node.getNode("attachments");
- else {
- if (getPrimaryNodeType() != null)
- childNode = node.addNode("attachments",
- getPrimaryNodeType());
- else
- childNode = node.addNode("attachments");
- }
- Node attachNode;
- for (int i = 0; i < attachments.size(); i++) {
- attachNode = childNode.addNode(attachments.get(i).getName());
- attachNode.setProperty("uuid", attachments.get(i).getUuid());
- attachNode.setProperty("contentType", attachments.get(i)
- .getContentType());
- }
- }
-
- // attributes are stored as properties of the testResult node
- for (String key : ttr.getAttributes().keySet()) {
- String mapValue = ttr.getAttributes().get(key);
- node.setProperty(key, mapValue);
- }
-
- }
-
- /**
- * Transforms a node into a TreeTestResult Instance
- */
- @SuppressWarnings("unchecked")
- protected Object nodeToBean(Node node) throws RepositoryException {
- // method variables
- String uuid;
- String clssName = node.getProperty(getClassProperty()).getString();
- QueryManager qm = node.getSession().getWorkspace().getQueryManager();
- Query query;
-
- if (log.isTraceEnabled())
- log.debug("Map node " + node.getPath() + " to bean " + clssName);
-
- // It's a very specific implementation,
- // We don't need to use a bean wrapper.
- TreeTestResult ttr = new TreeTestResult();
-
- // RESULTPART PARAMETERS
- uuid = node.getProperty("uuid").getString();
- ttr.setUuid(uuid);
-
- if (node.hasProperty("closeDate")) {
- ttr.setCloseDate((node.getProperty("closeDate").getDate())
- .getTime());
- }
-
- // ATTRIBUTES
- SortedMap attributes = new TreeMap<String, String>();
- PropertyIterator propIt = node.getProperties();
- props: while (propIt.hasNext()) {
- Property prop = propIt.nextProperty();
-
- // TODO Define a rule to generalize it (Namespace ??)
- // Get rid of specific case. mainly uuid
- if ("uuid".equals(prop.getName())
- || prop.getName().equals(getClassProperty())
- || prop.getName().startsWith("jcr")) {
- continue props;
- }
-
- // else it's an attribute, we retrieve it
- attributes.put(prop.getName(), prop.getString());
- }
- ttr.setAttributes(attributes);
-
- // ATTACHMENTS
- NodeIterator ni;
- if (node.hasNode("attachments")) {
- List<SimpleAttachment> attachments = new ArrayList<SimpleAttachment>();
-
- ni = node.getNode("attachments").getNodes();
- while (ni.hasNext()) {
- Node curNode = ni.nextNode();
- attachments.add(new SimpleAttachment(curNode
- .getProperty("uuid").getString(), curNode.getName(),
- curNode.getProperty("contentType").getString()));
- }
- ttr.setAttachments(attachments);
- }
-
- // STRUCTURED ELEMENTS
-
- String basePath = node.getPath();
- SortedMap<TreeSPath, PartSubList> resultParts = new TreeMap<TreeSPath, PartSubList>();
- SortedMap<TreeSPath, StructureElement> elements = new TreeMap<TreeSPath, StructureElement>();
-
- // We have to add the uuid of the current node to be sure that we are in
- // its sub tree
- String queryString = "//testresult[@uuid='" + uuid + "']";
-
- // Business part of the current query
- queryString = queryString + "//*[@" + getClassProperty() + "='"
- + StructureElement.class.getName() + "']";
-
- query = qm.createQuery(queryString, Query.XPATH);
- ni = query.execute().getNodes();
-
- while (ni.hasNext()) {
- Node curNode = ni.nextNode();
- String curPath = curNode.getPath().substring(basePath.length());
- TreeSPath tsp = new TreeSPath();
-
- // We must add the "/" at the begining of the jcr path to have a
- // TreeSPath string
- tsp.setAsUniqueString(tsp.getSeparator() + curPath);
-
- SimpleSElement se = new SimpleSElement();
- se.setLabel(curNode.getProperty("label").getString());
-
- Map<String, String> tagMap = new TreeMap<String, String>();
- NodeIterator tagIt = node.getNodes("tag");
- while (tagIt.hasNext()) {
- Node tagNode = tagIt.nextNode();
- tagMap.put(tagNode.getProperty("name").getString(), tagNode
- .getProperty("value").getString());
-
- }
- // PropertyIterator tagIt = curNode.getProperties();
- // tags: while (tagIt.hasNext()) {
- // Property prop = tagIt.nextProperty();
- // //log.debug("Handling property named : " + prop.getName());
- //
- // // TODO Define a rule to generalize it
- // // Specific case. mainly uuid
- // if ("uuid".equals(prop.getName())
- // || prop.getName().equals(getClassProperty())
- // || prop.getName().startsWith("jcr")) {
- // continue tags;
- // }
- //
- // // else it's an attribute, we retrieve it
- // tagMap.put(prop.getName(), prop.getString());
- // }
-
- se.setTags(tagMap);
- elements.put(tsp, se);
- }
- //log.debug("We added " + elements.size() + " elements");
-
- ttr.setElements(elements);
-
- // RESULTPARTS
-
- // We have to had the uuid of the current node to be sure that we are in
- // its sub tree
- queryString = "//testresult[@uuid='" + uuid + "']";
-
- // Business part of the current query
- queryString = queryString + "//partsublist";
- query = qm.createQuery(queryString, Query.XPATH);
- ni = query.execute().getNodes();
- while (ni.hasNext()) {
- Node curNode = ni.nextNode();
- String curPath = curNode.getParent().getPath().substring(
- basePath.length());
-
- TreeSPath tsp = new TreeSPath();
- // We must add the "/" at the begining of the jcr path to have a
- // TreeSPath string
- tsp.setAsUniqueString(tsp.getSeparator() + curPath);
-
- NodeIterator ni2 = curNode.getNodes("resultpart");
- List<TestResultPart> parts = new Vector<TestResultPart>();
- while (ni2.hasNext()) {
- parts.add((TestResultPart) load(ni2.nextNode()));
- }
- PartSubList psl = new PartSubList();
- psl.setParts(parts);
- resultParts.put(tsp, psl);
- }
-
- ttr.setResultParts(resultParts);
-
- return ttr;
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.jcr.execution;
-
-import java.util.Collections;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.Property;
-import javax.jcr.PropertyIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.query.Query;
-import javax.jcr.query.QueryManager;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.jcr.JcrUtils;
-import org.argeo.slc.SlcException;
-import org.argeo.slc.core.attachment.Attachment;
-import org.argeo.slc.core.structure.SimpleSElement;
-import org.argeo.slc.core.structure.tree.TreeSPath;
-import org.argeo.slc.core.test.SimpleResultPart;
-import org.argeo.slc.core.test.tree.PartSubList;
-import org.argeo.slc.core.test.tree.TreeTestResult;
-import org.argeo.slc.core.test.tree.TreeTestResultListener;
-import org.argeo.slc.jcr.SlcJcrUtils;
-import org.argeo.slc.jcr.SlcNames;
-import org.argeo.slc.jcr.SlcTypes;
-import org.argeo.slc.test.TestResultPart;
-import org.argeo.slc.test.TestStatus;
-
-/**
- * Persists results in JCR by listening to {@link TreeTestResult}. This is to
- * facilitate transition from legacy approaches and should not be used in new
- * implementations.
- */
-public class JcrResultListener implements TreeTestResultListener, SlcNames {
- private final static Log log = LogFactory.getLog(JcrResultListener.class);
-
- private Session session;
-
- /** Caches the mapping between SLC uuids and internal JCR identifiers */
- private Map<String, String> uuidToIdentifier = Collections
- .synchronizedMap(new HashMap<String, String>());
-
- public void resultPartAdded(TreeTestResult testResult,
- TestResultPart testResultPart) {
- try {
- String uuid = testResult.getUuid();
- Node resultNode = getResultNode(uuid);
- if (resultNode == null) {
- resultNode = createResultNode(testResult);
- // session.save();
- }
- String partParentPath;
- TreeSPath currentPath = testResult.getCurrentPath();
- if (currentPath != null) {
- String subPath = currentPath.getAsUniqueString();
- partParentPath = resultNode.getPath() + subPath;
- } else {
- partParentPath = resultNode.getPath();
- // TODO create some depth?
- }
-
- Node partParentNode;
- if (session.itemExists(partParentPath)) {
- partParentNode = session.getNode(partParentPath);
- } else {
- partParentNode = JcrUtils.mkdirs(session, partParentPath);
- // session.save();
- }
- // create part node
- SimpleSElement element = null;
- if (testResult.getElements().containsKey(currentPath)) {
- element = (SimpleSElement) testResult.getElements().get(
- currentPath);
- }
-
- String elementLabel = element != null && element.getLabel() != null
- && !element.getLabel().trim().equals("") ? element
- .getLabel() : null;
- String partNodeName = elementLabel != null ? JcrUtils
- .replaceInvalidChars(elementLabel, '_') : Long
- .toString(System.currentTimeMillis());
-
- Node resultPartNode = partParentNode.addNode(partNodeName,
- SlcTypes.SLC_CHECK);
- resultPartNode.setProperty(SLC_SUCCESS,
- testResultPart.getStatus() == TestStatus.PASSED);
- if (elementLabel != null)
- resultPartNode.setProperty(Property.JCR_TITLE, elementLabel);
- if (testResultPart.getMessage() != null)
- resultPartNode.setProperty(SLC_MESSAGE,
- testResultPart.getMessage());
- if (testResultPart.getExceptionMessage() != null)
- resultPartNode.setProperty(SLC_ERROR_MESSAGE,
- testResultPart.getExceptionMessage());
- // JcrUtils.debug(resultPartNode);
-
- JcrUtils.updateLastModified(resultNode);
-
- if (element != null) {
- element = (SimpleSElement) testResult.getElements().get(
- currentPath);
- if (log.isTraceEnabled())
- log.trace(" Path= " + currentPath + ", part="
- + testResultPart.getMessage());
- for (Map.Entry<String, String> tag : element.getTags()
- .entrySet()) {
- String tagNodeName = JcrUtils.replaceInvalidChars(
- tag.getKey(), '_');
- // log.debug("key=" + tag.getKey() + ", tagNodeName="
- // + tagNodeName);
- Node tagNode = resultPartNode.addNode(tagNodeName,
- SlcTypes.SLC_PROPERTY);
- tagNode.setProperty(SLC_NAME, tag.getKey());
- tagNode.setProperty(SLC_VALUE, tag.getValue());
- }
- }
-
- session.save();
- } catch (RepositoryException e) {
- JcrUtils.discardQuietly(session);
- log.error("Cannot add result part " + testResultPart + " to "
- + testResult, e);
- // throw new SlcException("Cannot add result part " + testResultPart
- // + " to " + testResult, e);
- }
-
- }
-
- /** @return null if does not exist */
- protected Node getResultNode(String uuid) throws RepositoryException {
- Node resultNode;
- if (uuidToIdentifier.containsKey(uuid)) {
- return session.getNodeByIdentifier(uuidToIdentifier.get(uuid));
- } else {
- Query q = session
- .getWorkspace()
- .getQueryManager()
- .createQuery(
- "select * from [slc:result] where [slc:uuid]='"
- + uuid + "'", Query.JCR_SQL2);
- resultNode = JcrUtils.querySingleNode(q);
- if (resultNode != null)
- uuidToIdentifier.put(uuid, resultNode.getIdentifier());
- }
- return resultNode;
- }
-
- protected Node createResultNode(TreeTestResult testResult)
- throws RepositoryException {
- String uuid = testResult.getUuid();
- String path = SlcJcrUtils.createResultPath(session, uuid);
- Node resultNode = JcrUtils.mkdirs(session, path, SlcTypes.SLC_TEST_RESULT);
- resultNode.setProperty(SLC_UUID, uuid);
- for (Map.Entry<String, String> entry : testResult.getAttributes()
- .entrySet()) {
- resultNode.setProperty(entry.getKey(), entry.getValue());
- }
-
- uuidToIdentifier.put(uuid, resultNode.getIdentifier());
- return resultNode;
- }
-
- public void close(TreeTestResult testResult) {
- try {
- String uuid = testResult.getUuid();
- Node resultNode = getResultNode(uuid);
- if (resultNode == null)
- resultNode = createResultNode(testResult);
- JcrUtils.updateLastModified(resultNode);
- GregorianCalendar closeDate = new GregorianCalendar();
- closeDate.setTime(testResult.getCloseDate());
- resultNode.setProperty(SLC_COMPLETED, closeDate);
-
- uuidToIdentifier.remove(uuid);
- session.save();
-
- if (log.isDebugEnabled())
- log.debug("Closed test result " + uuid);
- } catch (RepositoryException e) {
- JcrUtils.discardQuietly(session);
- log.error("Cannot close result " + testResult, e);
- // throw new SlcException("Cannot close result " + testResult, e);
- }
-
- }
-
- public void addAttachment(TreeTestResult testResult, Attachment attachment) {
-
- }
-
- public void setSession(Session session) {
- this.session = session;
- }
-
- /**
- * Creates and populates a {@link TreeTestResult} from the related result
- * node. Meant to simplify migration of legacy applications. This is no
- * stable API.
- */
- public static TreeTestResult nodeToTreeTestResult(Node resultNode) {
- try {
- String resultPath = resultNode.getPath();
- TreeTestResult ttr = new TreeTestResult();
- // base properties
- ttr.setUuid(resultNode.getProperty(SLC_UUID).getString());
- if (resultNode.hasProperty(SLC_COMPLETED))
- ttr.setCloseDate(resultNode.getProperty(SLC_COMPLETED)
- .getDate().getTime());
- // attributes
- for (PropertyIterator pit = resultNode.getProperties(); pit
- .hasNext();) {
- Property p = pit.nextProperty();
- if (p.getName().indexOf(':') < 0) {
- ttr.getAttributes().put(p.getName(), p.getString());
- }
- }
-
- QueryManager qm = resultNode.getSession().getWorkspace()
- .getQueryManager();
- String statement = "SELECT * FROM [" + SlcTypes.SLC_CHECK
- + "] WHERE ISDESCENDANTNODE(['" + resultPath + "'])";
- NodeIterator nit = qm.createQuery(statement, Query.JCR_SQL2)
- .execute().getNodes();
- while (nit.hasNext()) {
- Node checkNode = nit.nextNode();
- String relPath = checkNode.getPath().substring(
- resultPath.length());
- TreeSPath tsp = new TreeSPath(relPath);
-
- // result part
- SimpleResultPart srp = new SimpleResultPart();
- if (checkNode.getProperty(SLC_SUCCESS).getBoolean())
- srp.setStatus(TestStatus.PASSED);
- else if (checkNode.hasProperty(SLC_ERROR_MESSAGE))
- srp.setStatus(TestStatus.ERROR);
- else
- srp.setStatus(TestStatus.FAILED);
- if (checkNode.hasProperty(SLC_MESSAGE))
- srp.setMessage(checkNode.getProperty(SLC_MESSAGE)
- .getString());
- if (!ttr.getResultParts().containsKey(tsp))
- ttr.getResultParts().put(tsp, new PartSubList());
- ttr.getResultParts().get(tsp).getParts().add(srp);
-
- // element
- SimpleSElement elem = new SimpleSElement();
- if (checkNode.hasProperty(Property.JCR_TITLE))
- elem.setLabel(checkNode.getProperty(Property.JCR_TITLE)
- .getString());
- else
- elem.setLabel("");// some legacy code expect it to be set
- for (NodeIterator tagIt = checkNode.getNodes(); tagIt.hasNext();) {
- Node tagNode = tagIt.nextNode();
- elem.getTags().put(
- tagNode.getProperty(SLC_NAME).getString(),
- tagNode.getProperty(SLC_VALUE).getString());
- }
- ttr.getElements().put(tsp, elem);
- }
- return ttr;
- } catch (RepositoryException e) {
- throw new SlcException("Cannot generate tree test result from "
- + resultNode, e);
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.jcr.dao;
-
-import java.io.ByteArrayOutputStream;
-import java.net.InetAddress;
-import java.util.UUID;
-
-import javax.jcr.Session;
-
-import org.argeo.slc.dao.runtime.SlcAgentDescriptorDao;
-import org.argeo.slc.runtime.SlcAgentDescriptor;
-import org.argeo.slc.unit.AbstractSpringTestCase;
-
-public class SlcAgentDescriptorDaoJcrTest extends AbstractSpringTestCase {
- // private final static Log log = LogFactory
- // .getLog(SlcAgentDescriptorDaoJcrTest.class);
-
- private SlcAgentDescriptorDao slcAgentDescriptorDao;
- private String host = "localhost";
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- slcAgentDescriptorDao = getBean(SlcAgentDescriptorDao.class);
- }
-
- public void testZero() throws Exception {
- SlcAgentDescriptor slcAgentDescriptor0 = new SlcAgentDescriptor();
- slcAgentDescriptor0.setHost(host);
- slcAgentDescriptor0.setUuid(UUID.randomUUID().toString());
- }
-
- public void testExportXml() throws Exception {
- SlcAgentDescriptor slcAgentDescriptor0 = new SlcAgentDescriptor();
- slcAgentDescriptor0.setHost(host);
-
- String agentID = UUID.randomUUID().toString();
- slcAgentDescriptor0.setUuid(agentID);
- slcAgentDescriptorDao.create(slcAgentDescriptor0);
-
- Session session = getBean(Session.class);
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- session.exportDocumentView("/slc", out, true, false);
- log.debug("\n\n"+new String(out.toByteArray())+"\n\n");
-
- }
-
- public void testCreate() throws Exception {
- SlcAgentDescriptor slcAgentDescriptor0 = new SlcAgentDescriptor();
- slcAgentDescriptor0.setHost(host);
-
- String agentID = UUID.randomUUID().toString();
- slcAgentDescriptor0.setUuid(agentID);
- slcAgentDescriptorDao.create(slcAgentDescriptor0);
-
- // JcrUtils.debug(session.getRootNode());
-
- SlcAgentDescriptor slcAgentDescriptor1 = slcAgentDescriptorDao
- .getAgentDescriptor(agentID);
- // log.debug("expected agentID :"+agentID+
- // " . Retrieved one : "+slcAgentDescriptor1.getUuid());
- // TODO : compare retrieved AgentDescriptor with expected one.
- assertEquals(agentID, slcAgentDescriptor1.getUuid());
-
- slcAgentDescriptorDao.delete(agentID);
-
- }
-
- public void testList() throws Exception {
- SlcAgentDescriptor slcAgentDescriptor0 = new SlcAgentDescriptor();
- SlcAgentDescriptor slcAgentDescriptor1 = new SlcAgentDescriptor();
- SlcAgentDescriptor slcAgentDescriptor2 = new SlcAgentDescriptor();
-
- slcAgentDescriptor0.setHost(host);
- slcAgentDescriptor1.setHost(host);
- slcAgentDescriptor2.setHost(host);
-
- String agentID = UUID.randomUUID().toString();
- String agentID1 = UUID.randomUUID().toString();
- String agentID2 = UUID.randomUUID().toString();
-
- slcAgentDescriptor0.setUuid(agentID);
- slcAgentDescriptor1.setUuid(agentID1);
- slcAgentDescriptor2.setUuid(agentID2);
-
- slcAgentDescriptorDao.create(slcAgentDescriptor0);
- slcAgentDescriptorDao.create(slcAgentDescriptor1);
- slcAgentDescriptorDao.create(slcAgentDescriptor2);
-
- // List<SlcAgentDescriptor> list =
- // slcAgentDescriptorDao.listSlcAgentDescriptors();
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.jcr.dao;
-
-import java.net.InetAddress;
-
-import javax.jcr.Session;
-
-import org.argeo.jcr.JcrUtils;
-import org.argeo.slc.dao.process.SlcExecutionDao;
-import org.argeo.slc.process.SlcExecution;
-import org.argeo.slc.process.SlcExecutionStep;
-import org.argeo.slc.unit.AbstractSpringTestCase;
-import org.argeo.slc.unit.process.SlcExecutionTestUtils;
-
-public class SlcExecutionDaoJcrTest extends AbstractSpringTestCase {
- private SlcExecutionDao slcExecutionDao;
- private Session session;
- private String host;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- slcExecutionDao = getBean(SlcExecutionDao.class);
- session = getBean(Session.class);
- host = "localhost";
- }
-
- public void testCreate() throws Exception {
- SlcExecution slcExecution0 = SlcExecutionTestUtils
- .createSimpleSlcExecution();
- slcExecution0.setHost(host);
- slcExecutionDao.create(slcExecution0);
-
- SlcExecution slcExecution = SlcExecutionTestUtils
- .createSlcExecutionWithRealizedFlows();
- slcExecution.setHost(host);
- String uuid = slcExecution.getUuid();
- slcExecutionDao.create(slcExecution);
-
- JcrUtils.debug(session.getRootNode());
-
- SlcExecution slcExecutionPersist = slcExecutionDao
- .getSlcExecution(uuid);
- SlcExecutionTestUtils.assertSlcExecution(slcExecution,
- slcExecutionPersist);
- }
-
- public void testUpdate() throws Exception {
- SlcExecution slcExecution0 = SlcExecutionTestUtils
- .createSimpleSlcExecution();
- slcExecution0.setHost(host);
- slcExecutionDao.create(slcExecution0);
- String uuid = slcExecution0.getUuid();
-
- SlcExecution slcExecution = SlcExecutionTestUtils
- .createSlcExecutionWithRealizedFlows();
- slcExecution.setUuid(uuid);
- slcExecution.setHost(host);
- slcExecution.getSteps().add(new SlcExecutionStep("My log"));
- slcExecutionDao.update(slcExecution);
-
- JcrUtils.debug(session.getRootNode());
-
- SlcExecution slcExecutionPersist = slcExecutionDao
- .getSlcExecution(uuid);
- SlcExecutionTestUtils.assertSlcExecution(slcExecution,
- slcExecutionPersist);
- }
-
- // // FIXME
- // protected void tearDown() {
- // try {
- // super.tearDown();
- // } catch (Exception e) {
- // log.debug("pbs Remain while closing jcr test env.");
- // log.debug("Exc Name : " + e.getClass().getName());
- // }
- // }
-}
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.jcr.dao;\r
-\r
-import java.util.Date;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.jcr.JcrUtils;\r
-import org.argeo.slc.core.test.tree.TreeTestResult;\r
-import org.argeo.slc.core.test.tree.TreeTestResultCollection;\r
-import org.argeo.slc.dao.test.tree.TreeTestResultCollectionDao;\r
-import org.argeo.slc.dao.test.tree.TreeTestResultDao;\r
-import org.argeo.slc.unit.AbstractSpringTestCase;\r
-import org.argeo.slc.unit.test.tree.TreeTestResultTestUtils;\r
-import org.argeo.slc.unit.test.tree.UnitTestTreeUtil;\r
-\r
-public class TreeTestResultCollectionDaoJcrTest extends AbstractSpringTestCase {\r
- private final static Log log = LogFactory\r
- .getLog(TreeTestResultCollectionDaoJcrTest.class);\r
-\r
- private TreeTestResultCollectionDao ttrcDao;\r
- private TreeTestResultDao ttrDao;\r
-\r
- @Override\r
- protected void setUp() throws Exception {\r
- super.setUp();\r
- ttrDao = getBean(TreeTestResultDao.class);\r
- ttrcDao = getBean(TreeTestResultCollectionDao.class);\r
- log.debug("Context Initialized");\r
- }\r
-\r
- @SuppressWarnings("restriction")\r
- public void testScenario() {\r
- String ttrcName = "testCollection";\r
-\r
- TreeTestResult ttr1 = TreeTestResultTestUtils\r
- .createCompleteTreeTestResult();\r
- ttrDao.create(ttr1);\r
-\r
- TreeTestResultCollection ttrc = new TreeTestResultCollection(ttrcName);\r
- ttrcDao.create(ttrc);\r
- ttrc.getResults().add(ttr1);\r
- ttrcDao.update(ttrc);\r
-\r
- final TreeTestResult ttr2 = TreeTestResultTestUtils\r
- .createCompleteTreeTestResult();\r
- ttrDao.create(ttr2);\r
-\r
- ttrc.getResults().add(ttr2);\r
- ttrcDao.update(ttrc);\r
-\r
- ttrc.getResults().remove(ttr1);\r
- ttrcDao.update(ttrc);\r
-\r
- final TreeTestResultCollection ttrcPersist = ttrcDao\r
- .getTestResultCollection(ttrcName);\r
-\r
- assertEquals(1, ttrcPersist.getResults().size());\r
- TreeTestResult ttrFin = ttrcPersist.getResults().iterator().next();\r
- UnitTestTreeUtil.assertTreeTestResult(ttr2, ttrFin);\r
- \r
- }\r
-\r
- @SuppressWarnings("restriction")\r
- public void testResultsWithSameCloseDate() {\r
- String ttrcName = "testCollectionWithSameCloseDate";\r
-\r
- Date closeDate = new Date();\r
-\r
- // TTR1\r
- TreeTestResult ttr1 = TreeTestResultTestUtils\r
- .createCompleteTreeTestResult();\r
- ttr1.setCloseDate(closeDate);\r
- ttrDao.create(ttr1);\r
-\r
- // TTR2\r
- TreeTestResult ttr2 = TreeTestResultTestUtils\r
- .createCompleteTreeTestResult();\r
- ttr2.setCloseDate(closeDate);\r
- ttrDao.create(ttr2);\r
-\r
- // TTRC\r
- TreeTestResultCollection ttrc = new TreeTestResultCollection(ttrcName);\r
- ttrc.getResults().add(ttr1);\r
- ttrc.getResults().add(ttr2);\r
- ttrcDao.create(ttrc);\r
-\r
- final TreeTestResultCollection ttrcPersist = ttrcDao\r
- .getTestResultCollection(ttrcName);\r
- assertEquals(2, ttrcPersist.getResults().size());\r
- }\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.jcr.dao;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.slc.core.test.tree.TreeTestResult;\r
-import org.argeo.slc.dao.test.tree.TreeTestResultDao;\r
-import org.argeo.slc.unit.AbstractSpringTestCase;\r
-import org.argeo.slc.unit.test.tree.TreeTestResultTestUtils;\r
-import org.argeo.slc.unit.test.tree.UnitTestTreeUtil;\r
-\r
-public class TreeTestResultDaoJcrSimpleTest extends AbstractSpringTestCase {\r
- private final static Log log = LogFactory\r
- .getLog(TreeTestResultDaoJcrSimpleTest.class);\r
-\r
- private TreeTestResultDao ttrDao;\r
-\r
- @Override\r
- protected void setUp() throws Exception {\r
- super.setUp();\r
- ttrDao = getBean(TreeTestResultDao.class);\r
- log.debug("Context Initialized");\r
- }\r
-\r
- @SuppressWarnings("restriction")\r
- public void testCreate() {\r
- TreeTestResult ttr = TreeTestResultTestUtils\r
- .createComplexeTreeTestResult();\r
- ttrDao.create(ttr);\r
- TreeTestResult ttrPersisted = ttrDao.getTestResult(ttr.getUuid());\r
- compareTestResult(ttr, ttrPersisted);\r
- UnitTestTreeUtil.assertTreeTestResult(ttr, ttrPersisted);\r
-\r
- }\r
-\r
- @SuppressWarnings("restriction")\r
- public void testCreate2() {\r
- TreeTestResult ttr = TreeTestResultTestUtils\r
- .createComplexeTreeTestResult();\r
- ttrDao.create(ttr);\r
- TreeTestResult ttrPersisted = ttrDao.getTestResult(ttr.getUuid());\r
- compareTestResult(ttr, ttrPersisted);\r
- UnitTestTreeUtil.assertTreeTestResult(ttr, ttrPersisted);\r
-\r
- }\r
-\r
- public static void compareTestResult(final TreeTestResult t1,\r
- final TreeTestResult t2) {\r
-\r
- assertEquals(t1.getUuid(), t2.getUuid());\r
- assertEquals(t1.getCloseDate(), t2.getCloseDate());\r
- assertEquals(t1.getAttachments().size(), t2.getAttachments().size());\r
- assertEquals(t1.getAttributes().size(), t2.getAttributes().size());\r
- assertEquals(t1.getElements().size(), t2.getElements().size());\r
- // resultParts\r
- assertEquals(t1.getResultParts().size(), t2.getResultParts().size());\r
-\r
- // TODO Add more check.\r
- }\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.jcr.dao;\r
-\r
-import java.io.ByteArrayOutputStream;\r
-import java.util.SortedMap;\r
-import java.util.TreeMap;\r
-import java.util.UUID;\r
-\r
-import javax.jcr.Session;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.slc.core.attachment.SimpleAttachment;\r
-import org.argeo.slc.core.structure.tree.TreeSPath;\r
-import org.argeo.slc.core.test.SimpleResultPart;\r
-import org.argeo.slc.core.test.tree.TreeTestResult;\r
-import org.argeo.slc.dao.test.tree.TreeTestResultDao;\r
-import org.argeo.slc.unit.AbstractSpringTestCase;\r
-import org.argeo.slc.unit.test.tree.TreeTestResultTestUtils;\r
-import org.argeo.slc.unit.test.tree.UnitTestTreeUtil;\r
-\r
-public class TreeTestResultDaoJcrTest extends AbstractSpringTestCase {\r
- private final static Log log = LogFactory\r
- .getLog(TreeTestResultDaoJcrTest.class);\r
-\r
- private TreeTestResultDao ttrDao;\r
-\r
- @Override\r
- protected void setUp() throws Exception {\r
- super.setUp();\r
- ttrDao = getBean(TreeTestResultDao.class);\r
- log.debug("Context Initialized");\r
- }\r
-\r
- public void testExportXml() throws Exception {\r
- TreeTestResult ttr = TreeTestResultTestUtils\r
- .createComplexeTreeTestResult();\r
- ttrDao.create(ttr);\r
-\r
- Session session = getBean(Session.class);\r
- ByteArrayOutputStream out = new ByteArrayOutputStream();\r
- session.exportDocumentView("/slc", out, true, false);\r
- log.debug("\n\n"+new String(out.toByteArray())+"\n\n");\r
- }\r
-\r
- public void testCreate() {\r
- TreeTestResult ttr = TreeTestResultTestUtils\r
- .createComplexeTreeTestResult();\r
- ttrDao.create(ttr);\r
- TreeTestResult ttrPersisted = ttrDao.getTestResult(ttr.getUuid());\r
- compareTestResult(ttr, ttrPersisted);\r
- UnitTestTreeUtil.assertTreeTestResult(ttr, ttrPersisted);\r
- }\r
-\r
- public void testUpdate() {\r
- TreeTestResult ttr = TreeTestResultTestUtils\r
- .createCompleteTreeTestResult();\r
- ttrDao.create(ttr);\r
- SimpleAttachment sa = new SimpleAttachment(\r
- UUID.randomUUID().toString(), "A new Attachment", "UTF8");\r
- // test if we can attach a new doc\r
- ttrDao.addAttachment(ttr.getUuid(), sa);\r
-\r
- // test if an existing doc is not added 2 times.\r
- TreeTestResult ttr2 = ttrDao.getTestResult(ttr.getUuid());\r
- ttrDao.addAttachment(ttr.getUuid(), sa);\r
- TreeTestResult ttr3 = ttrDao.getTestResult(ttr.getUuid());\r
- assertEquals(ttr3.getAttachments().size(), ttr2.getAttachments().size());\r
-\r
- // Test Add ResultPart\r
- // Initializing context\r
- SimpleResultPart resultPart = TreeTestResultTestUtils\r
- .createSimpleResultPartFailed();\r
- TreeSPath path = new TreeSPath("/test1");\r
- ttrDao.addResultPart(ttr.getUuid(), path, resultPart, null);\r
-\r
- // TestAdd Attribute\r
- SortedMap<String, String> newAtt = new TreeMap<String, String>();\r
- newAtt.put("NewTestCase", "NonSortedView");\r
- newAtt.put("NewTestCaseType", "csvdiff");\r
- ttrDao.updateAttributes(ttr.getUuid(), newAtt);\r
-\r
- ttr2 = ttrDao.getTestResult(ttr.getUuid());\r
- assertEquals(ttr.getAttributes().size() + 2, ttr2.getAttributes()\r
- .size());\r
- assertEquals("csvdiff", ttr2.getAttributes().get("NewTestCaseType"));\r
-\r
- // Test update existing Attribute\r
- ttrDao.updateAttributes(ttr.getUuid(), newAtt);\r
- assertEquals(ttr.getAttributes().size() + 2, ttr2.getAttributes()\r
- .size());\r
-\r
- }\r
-\r
- public void testResultPartOnly() {\r
-\r
- TreeTestResult ttr = TreeTestResultTestUtils\r
- .createComplexeTreeTestResult();\r
-\r
- SimpleResultPart resultPart = TreeTestResultTestUtils\r
- .createSimpleResultPartPassed();\r
- ttr.addResultPart(resultPart);\r
- ttrDao.create(ttr);\r
- TreeTestResult ttr2;\r
- ttr2 = ttrDao.getTestResult(ttr.getUuid());\r
- assertEquals(ttr.getResultParts().size(), ttr2.getResultParts().size());\r
- }\r
-\r
- public static void compareTestResult(final TreeTestResult t1,\r
- final TreeTestResult t2) {\r
-\r
- assertEquals(t1.getUuid(), t2.getUuid());\r
- assertEquals(t1.getCloseDate(), t2.getCloseDate());\r
- assertEquals(t1.getAttachments().size(), t2.getAttachments().size());\r
- assertEquals(t1.getAttributes().size(), t2.getAttributes().size());\r
- assertEquals(t1.getElements().size(), t2.getElements().size());\r
- // resultParts\r
- assertEquals(t1.getResultParts().size(), t2.getResultParts().size());\r
-\r
- // TODO Add more check.\r
- }\r
-\r
-}\r
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.server.unit;
-
-import org.argeo.slc.msg.ExecutionAnswer;
-import org.argeo.slc.server.client.SlcServerHttpClient;
-import org.argeo.slc.unit.AbstractSpringTestCase;
-
-public abstract class AbstractHttpClientTestCase extends AbstractSpringTestCase {
- private SlcServerHttpClient httpClient = null;
-
- protected void setUp() throws Exception {
- super.setUp();
- httpClient = createHttpClient();
- httpClient.waitForServerToBeReady();
- }
-
- protected SlcServerHttpClient createHttpClient() {
- SlcServerHttpClient httpClient = getBean(SlcServerHttpClient.class);
- return httpClient;
- }
-
- protected SlcServerHttpClient getHttpClient() {
- return httpClient;
- }
-
- protected void assertAnswerOk(ExecutionAnswer answer) {
- if (!answer.isOk()) {
- fail("Server execution answer is not ok: " + answer.getMessage());
- }
- }
-}
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.unit.test.tree;\r
-\r
-import java.util.UUID;\r
-\r
-\r
-import org.argeo.slc.build.Distribution;\r
-import org.argeo.slc.core.attachment.SimpleAttachment;\r
-import org.argeo.slc.core.structure.SimpleSElement;\r
-import org.argeo.slc.core.structure.tree.TreeSPath;\r
-import org.argeo.slc.core.structure.tree.TreeSRegistry;\r
-import org.argeo.slc.core.test.SimpleResultPart;\r
-import org.argeo.slc.core.test.SimpleTestRun;\r
-import org.argeo.slc.core.test.tree.PartSubList;\r
-import org.argeo.slc.core.test.tree.TreeTestResult;\r
-import org.argeo.slc.deploy.DeployedSystem;\r
-import org.argeo.slc.deploy.DeploymentData;\r
-import org.argeo.slc.deploy.TargetData;\r
-import org.argeo.slc.msg.test.tree.ResultPartRequest;\r
-import org.argeo.slc.process.SlcExecution;\r
-import org.argeo.slc.process.SlcExecutionStep;\r
-import org.argeo.slc.test.TestStatus;\r
-import org.argeo.slc.unit.process.SlcExecutionTestUtils;\r
-\r
-public abstract class TreeTestResultTestUtils {\r
-\r
- public static TreeTestResult createSimpleTreeTestResult() {\r
- TreeTestResult treeTestResult = new TreeTestResult();\r
- treeTestResult.setUuid(UUID.randomUUID().toString());\r
- return treeTestResult;\r
- }\r
-\r
- public static TreeTestResult createCompleteTreeTestResult() {\r
- SlcExecution slcExecution = SlcExecutionTestUtils\r
- .createSimpleSlcExecution();\r
- SlcExecutionStep step = new SlcExecutionStep("JUnit step");\r
- slcExecution.getSteps().add(step);\r
-\r
- TreeTestResult ttr = createMinimalConsistentTreeTestResult(slcExecution);\r
-\r
- ttr.addResultPart(createSimpleResultPartPassed());\r
- ttr.addResultPart(createSimpleResultPartFailed());\r
- ttr.addResultPart(createSimpleResultPartError());\r
- return ttr;\r
- }\r
-\r
- public static TreeTestResult createComplexeTreeTestResult() {\r
- SlcExecution slcExecution = SlcExecutionTestUtils\r
- .createSimpleSlcExecution();\r
- SlcExecutionStep step = new SlcExecutionStep("JUnit step");\r
- slcExecution.getSteps().add(step);\r
-\r
- TreeTestResult ttr = createMinimalConsistentTreeTestResult(slcExecution);\r
-\r
- ttr.addResultPart(createSimpleResultPartPassed());\r
- ttr.addResultPart(createSimpleResultPartFailed());\r
- //ttr.addResultPart(createSimpleResultPartError());\r
- \r
- SimpleAttachment sa = new SimpleAttachment(UUID.randomUUID().toString(),"AnAttachment","UTF8");\r
- SimpleAttachment sa2 = new SimpleAttachment(UUID.randomUUID().toString(),"AnOtherAttachment","UTF8");\r
- ttr.addAttachment(sa);\r
- ttr.addAttachment(sa2);\r
- return ttr;\r
- }\r
-\r
- public static TreeTestResult createMinimalConsistentTreeTestResult(\r
- SlcExecution slcExecution) {\r
- SimpleTestRun testRun = new SimpleTestRun();\r
- testRun.setUuid(UUID.randomUUID().toString());\r
-\r
- // Doesn't work in hibernate with such a path.\r
- //String pathStr = "/fileDiff/testcases/issue";\r
- String pathStr = "/test";\r
- TreeSPath path = new TreeSPath(pathStr);\r
-\r
- TreeSRegistry registry = new TreeSRegistry();\r
- SimpleSElement elem = new SimpleSElement("Unit Test");\r
- elem.getTags().put("myTag", "myTagValue");\r
- registry.register(path, elem);\r
-\r
- TreeTestResult ttr = createSimpleTreeTestResult();\r
- ttr.getAttributes().put("testCase", "UNIT");\r
-\r
- // Simulate test run\r
- ttr.notifyCurrentPath(registry, path);\r
- ttr.notifyTestRun(testRun);\r
- testRun.setTestResult(ttr);\r
- testRun.setDeployedSystem(new DeployedSystem() {\r
- private String uuid = UUID.randomUUID().toString();\r
-\r
- public String getDeployedSystemId() {\r
- return uuid;\r
- }\r
-\r
- public Distribution getDistribution() {\r
- return null;\r
- }\r
-\r
- public DeploymentData getDeploymentData() {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
-\r
- public TargetData getTargetData() {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
-\r
- });\r
- testRun.notifySlcExecution(slcExecution);\r
- return ttr;\r
- }\r
-\r
- public static SimpleResultPart createSimpleResultPartPassed() {\r
- SimpleResultPart partPassed = new SimpleResultPart();\r
- String msgPassed = "message\nnew line";\r
- partPassed.setStatus(TestStatus.PASSED);\r
- partPassed.setMessage(msgPassed);\r
- return partPassed;\r
- }\r
-\r
- public static SimpleResultPart createSimpleResultPartFailed() {\r
- SimpleResultPart partFailed = new SimpleResultPart();\r
- String msgFailed = "too bad";\r
- partFailed.setStatus(TestStatus.FAILED);\r
- partFailed.setMessage(msgFailed);\r
- return partFailed;\r
- }\r
-\r
- public static SimpleResultPart createSimpleResultPartError() {\r
- SimpleResultPart partFailed = new SimpleResultPart();\r
- String msgFailed = "crashed\nanother line";\r
- partFailed.setStatus(TestStatus.ERROR);\r
- partFailed.setMessage(msgFailed);\r
- partFailed.setException(new Exception("Test Exception"));\r
- return partFailed;\r
- }\r
-\r
- public static ResultPartRequest createSimpleResultPartRequest(\r
- TreeTestResult ttr) {\r
- TreeSPath path = ttr.getCurrentPath();\r
- PartSubList lst = ttr.getResultParts().get(path);\r
- SimpleResultPart part = (SimpleResultPart) lst.getParts().get(2);\r
-\r
- ResultPartRequest req = new ResultPartRequest(ttr, path, part);\r
- req.setPath(ttr.getCurrentPath());\r
-\r
- return req;\r
- }\r
-\r
- private TreeTestResultTestUtils() {\r
-\r
- }\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.unit.test.tree;\r
-\r
-import static junit.framework.Assert.assertEquals;\r
-import static junit.framework.Assert.assertNotNull;\r
-import static junit.framework.Assert.assertNull;\r
-import static junit.framework.Assert.fail;\r
-import static org.argeo.slc.unit.UnitUtils.assertDateSec;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.slc.core.structure.SimpleSElement;\r
-import org.argeo.slc.core.structure.tree.TreeSPath;\r
-import org.argeo.slc.core.test.SimpleResultPart;\r
-import org.argeo.slc.core.test.tree.PartSubList;\r
-import org.argeo.slc.core.test.tree.TreeTestResult;\r
-import org.argeo.slc.test.TestResultPart;\r
-\r
-/** Utilities for unit tests. */\r
-public class UnitTestTreeUtil {\r
- private final static Log log = LogFactory.getLog(UnitTestTreeUtil.class);\r
-\r
- public static void assertTreeTestResult(TreeTestResult expected,\r
- TreeTestResult reached) {\r
- assertEquals(expected.getUuid(), reached.getUuid());\r
- assertDateSec(expected.getCloseDate(), reached.getCloseDate());\r
-\r
- // Attributes\r
- //assertEquals(expected.getAttributes().size(), reached.getAttributes()\r
- // .size());\r
- for (String key : expected.getAttributes().keySet()) {\r
- String expectedValue = expected.getAttributes().get(key);\r
- String reachedValue = reached.getAttributes().get(key);\r
- assertNotNull(reachedValue);\r
- assertEquals(expectedValue, reachedValue);\r
- }\r
-\r
- // Result parts\r
- assertEquals(expected.getResultParts().size(), reached.getResultParts()\r
- .size());\r
- for (TreeSPath path : expected.getResultParts().keySet()) {\r
- PartSubList lstExpected = expected.getResultParts().get(path);\r
- PartSubList lstReached = expected.getResultParts().get(path);\r
- if (lstReached == null) {\r
- fail("No result for path " + path);\r
- return;\r
- }\r
- assertPartSubList(lstExpected, lstReached);\r
- }\r
-\r
- // Elements\r
- assertEquals(expected.getElements().size(), reached.getElements()\r
- .size());\r
- for (TreeSPath path : expected.getElements().keySet()) {\r
- // String nameExpected = expected.getElements().get(path);\r
- // String nameReached = expected.getElements().get(path);\r
- SimpleSElement elemExpected = (SimpleSElement) expected\r
- .getElements().get(path);\r
- SimpleSElement elemReached = (SimpleSElement) expected\r
- .getElements().get(path);\r
- assertNotNull(elemReached);\r
- assertElements(elemExpected, elemReached);\r
- }\r
-\r
- }\r
-\r
- public static void assertElements(SimpleSElement expected,\r
- SimpleSElement reached) {\r
- assertEquals(expected.getLabel(), reached.getLabel());\r
- assertEquals(expected.getTags().size(), reached.getTags().size());\r
- for (String tagName : expected.getTags().keySet()) {\r
- String expectedTagValue = expected.getTags().get(tagName);\r
- String reachedTagValue = reached.getTags().get(tagName);\r
- assertNotNull(reachedTagValue);\r
- assertEquals(expectedTagValue, reachedTagValue);\r
- }\r
- }\r
-\r
- public static void assertPartSubList(PartSubList lstExpected,\r
- PartSubList lstReached) {\r
- assertEquals(lstExpected.getParts().size(), lstReached.getParts()\r
- .size());\r
- for (int i = 0; i < lstExpected.getParts().size(); i++) {\r
- assertPart(lstExpected.getParts().get(i), lstReached.getParts()\r
- .get(i));\r
- }\r
- }\r
-\r
- /** Asserts one part of a tree test result */\r
- public static void assertPart(TreeTestResult testResult, String pathStr,\r
- int index, Integer status, String message) {\r
- TreeSPath path = new TreeSPath(pathStr);\r
- PartSubList list = testResult.getResultParts().get(path);\r
- if (list == null) {\r
- fail("No result for path " + path);\r
- return;\r
- }\r
- if (index >= list.getParts().size()) {\r
- fail("Not enough parts.");\r
- }\r
- SimpleResultPart part = (SimpleResultPart) list.getParts().get(index);\r
- assertPart(part, status, message, null, part.getTestRunUuid(), true);\r
- }\r
-\r
- public static void assertPart(TestResultPart expected,\r
- TestResultPart reached) {\r
- String expectedTestRunUuid = null;\r
- if (expected instanceof SimpleResultPart) {\r
- expectedTestRunUuid = ((SimpleResultPart) expected)\r
- .getTestRunUuid();\r
- }\r
-\r
- assertPart(reached, expected.getStatus(), expected.getMessage(),\r
- expected.getExceptionMessage(), expectedTestRunUuid, false);\r
- }\r
-\r
- /** Assert one part of a tree test result. */\r
- private static void assertPart(TestResultPart part, Integer status,\r
- String message, String exceptionDescription,\r
- String expectedTestRunUuid, boolean skipExceptionMessage) {\r
- assertEquals(status, part.getStatus());\r
-\r
- if (message != null) {\r
- if (log.isTraceEnabled()) {\r
- log.trace("Expected message:" + message);\r
- log.trace("Reached message:" + part.getMessage());\r
- }\r
- assertEquals(message, part.getMessage());\r
- }\r
-\r
- if (!skipExceptionMessage) {\r
- if (exceptionDescription == null) {\r
- assertNull(part.getExceptionMessage());\r
- } else {\r
- if (log.isTraceEnabled()) {\r
- log.trace("Expected exception message:"\r
- + exceptionDescription);\r
- log.trace("Reached exception message:"\r
- + part.getExceptionMessage());\r
- }\r
-\r
- assertEquals(exceptionDescription, part.getExceptionMessage());\r
- }\r
- }\r
-\r
- if (expectedTestRunUuid != null) {\r
- SimpleResultPart reachedPart = (SimpleResultPart) part;\r
- assertNotNull(reachedPart.getTestRunUuid());\r
- assertEquals(expectedTestRunUuid, reachedPart.getTestRunUuid());\r
- } else {\r
- if (part instanceof SimpleResultPart) {\r
- assertNull(((SimpleResultPart) part).getTestRunUuid());\r
- }\r
-\r
- }\r
-\r
- }\r
-\r
- public static void describeTreeTestResult(TreeTestResult ttr) {\r
- log.info("TreeTestResult #" + ttr.getUuid());\r
- log.info(" Close date: " + ttr.getCloseDate());\r
- log.info(" Attributes:");\r
- for (String key : ttr.getAttributes().keySet())\r
- log.info(" " + key + "=" + ttr.getAttributes().get(key));\r
-\r
- log.info(" Result parts: (size=" + ttr.getResultParts().size() + ")");\r
- for (TreeSPath path : ttr.getResultParts().keySet()) {\r
- log.info(" Path: " + path);\r
- PartSubList lst = ttr.getResultParts().get(path);\r
- for (TestResultPart part : lst.getParts())\r
- log.info(" " + part);\r
- }\r
-\r
- log.info(" Elements: (size=" + ttr.getElements().size() + ")");\r
- for (TreeSPath path : ttr.getElements().keySet()) {\r
- SimpleSElement elem = (SimpleSElement) ttr.getElements().get(path);\r
- log.info(" Path: " + path + ", Element: " + elem.getLabel());\r
- for (String tag : elem.getTags().keySet())\r
- log.info(" " + tag + "=" + elem.getTags().get(tag));\r
- }\r
-\r
- }\r
-\r
- /** Makes sure this is a singleton */\r
- private UnitTestTreeUtil() {\r
-\r
- }\r
-}\r