From 42aa6ffce6a95107cd10f908e5f9c695d902d571 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Sat, 28 Jun 2008 10:09:35 +0000 Subject: [PATCH] Improve web services git-svn-id: https://svn.argeo.org/slc/trunk@1305 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../process/FileSlcExecutionNotifier.java | 5 +- .../slc/core/structure/DefaultSRegistry.java | 63 ------------------- .../slc/core/structure/StructureRegistry.java | 2 +- .../core/structure/tree/TreeSRegistry.java | 25 +++----- .../slc/core/test/tree/TreeTestResult.java | 8 ++- .../tree/TreeTestResultCollectionDao.java | 1 - .../msg/process/SlcExecutionStepsRequest.java | 8 +++ .../tree/CreateTreeTestResultRequest.java | 2 +- .../slc/msg/test/tree/ResultPartRequest.java | 4 +- .../argeo/slc/runtime/SlcExecutionOutput.java | 2 +- .../org/argeo/slc/spring/SpringUtils.java | 2 - .../slc/unit/AbstractSpringTestCase.java | 7 +-- .../test/tree/TreeTestResultTestUtils.java | 14 +++-- 13 files changed, 42 insertions(+), 101 deletions(-) delete mode 100644 org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/DefaultSRegistry.java diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/process/FileSlcExecutionNotifier.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/process/FileSlcExecutionNotifier.java index e1fb3e361..0b9f682b0 100644 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/process/FileSlcExecutionNotifier.java +++ b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/process/FileSlcExecutionNotifier.java @@ -10,12 +10,9 @@ import java.util.Map; import javax.xml.transform.stream.StreamResult; -import org.springframework.oxm.Marshaller; - import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.LogFactory; - import org.argeo.slc.core.SlcException; +import org.springframework.oxm.Marshaller; public class FileSlcExecutionNotifier implements SlcExecutionNotifier { private final static SimpleDateFormat sdf = new SimpleDateFormat( diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/DefaultSRegistry.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/DefaultSRegistry.java deleted file mode 100644 index 44b4a7a98..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/DefaultSRegistry.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.argeo.slc.core.structure; - -import java.util.List; -import java.util.Vector; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** Default implementation of a StructureRegistry. */ -public class DefaultSRegistry implements StructureRegistry { - private static Log log = LogFactory.getLog(DefaultSRegistry.class); - - private List elements = new Vector(); - private List paths = new Vector(); - private String mode = StructureRegistry.ALL; - - private List activePaths; - - public List listElements() { - return new Vector(elements); - } - - public List listPaths() { - return new Vector(paths); - } - - public void register(StructurePath path, StructureElement element) { - StructureElement treeSElement = element; - elements.add(treeSElement); - paths.add(path); - - if (log.isTraceEnabled()) - log.trace("Registered " + path + " (label: '" - + treeSElement.getLabel() + "', position: " - + elements.size() + ")"); - } - - public StructureElement getElement(StructurePath path) { - int index = paths.indexOf(path); - if (index >= 0) { - return elements.get(index); - } else {// not found - return null; - } - } - - public String getMode() { - return mode; - } - - public void setMode(String mode) { - this.mode = mode; - } - - public List getActivePaths() { - return activePaths; - } - - public void setActivePaths(List activePaths) { - this.activePaths = activePaths; - } - -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/StructureRegistry.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/StructureRegistry.java index eac04b2bb..e90916408 100644 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/StructureRegistry.java +++ b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/StructureRegistry.java @@ -9,7 +9,7 @@ public interface StructureRegistry

{ /** All mode: everything is executed regardless of the active paths. */ public static String ALL = "ALL"; /** Active mode: only the active paths are executed. */ - public static String ACTIVE = "STATUS_ACTIVE"; + public static String ACTIVE = "ACTIVE"; /** Adds an element to the registry. */ public void register(P path, StructureElement element); diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/tree/TreeSRegistry.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/tree/TreeSRegistry.java index 7337367dc..36c85728f 100644 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/tree/TreeSRegistry.java +++ b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/tree/TreeSRegistry.java @@ -12,11 +12,8 @@ import org.argeo.slc.core.structure.StructureRegistry; /** Tree based implementation of a structure registry. */ public class TreeSRegistry implements StructureRegistry { - public final static String STATUS_ACTIVE = "STATUS_ACTIVE"; - /** For ORM */ private Long tid; - private String status; private Map elements = new TreeMap(); private String mode = StructureRegistry.ALL; @@ -36,6 +33,16 @@ public class TreeSRegistry implements StructureRegistry { } public void register(TreeSPath path, StructureElement element) { + if (path == null) + throw new UnsupportedException("Cannot register under a null path."); + if (element == null) + throw new UnsupportedException( + "Cannot register null element for path " + path); + if (element.getLabel() == null) + throw new UnsupportedException( + "Cannot register an element with null label for path " + + path); + final SimpleSElement simpleSElement; if (element instanceof SimpleSElement) { simpleSElement = (SimpleSElement) element; @@ -43,11 +50,7 @@ public class TreeSRegistry implements StructureRegistry { simpleSElement = new SimpleSElement(element.getLabel()); } - if (path == null) - throw new UnsupportedException("Path cannot be null."); - elements.put(path, simpleSElement); - } public String getMode() { @@ -66,14 +69,6 @@ public class TreeSRegistry implements StructureRegistry { this.activePaths = activePaths; } - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - /** Gets the elements. */ public Map getElements() { return elements; diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java index f34561a9e..ecd6cad52 100644 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java +++ b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java @@ -9,7 +9,6 @@ import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.argeo.slc.core.SlcException; import org.argeo.slc.core.structure.SimpleSElement; import org.argeo.slc.core.structure.StructureAware; @@ -100,7 +99,7 @@ public class TreeTestResult implements TestResult, StructureAware, } } - currentPath = (TreeSPath) path; + currentPath = path; } /** Gets the current path. */ @@ -168,6 +167,11 @@ public class TreeTestResult implements TestResult, StructureAware, public SortedMap getRelatedElements( TreeSPath path) { + if (path == null) + throw new SlcException( + "Cannot retrieve element for a null path in result #" + + uuid); + SortedMap relatedElements = new TreeMap(); List hierarchy = path.getHierarchyAsList(); for (TreeSPath currPath : elements.keySet()) { diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/dao/test/tree/TreeTestResultCollectionDao.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/dao/test/tree/TreeTestResultCollectionDao.java index f43689df9..730c9d988 100644 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/dao/test/tree/TreeTestResultCollectionDao.java +++ b/org.argeo.slc.core/src/main/java/org/argeo/slc/dao/test/tree/TreeTestResultCollectionDao.java @@ -2,7 +2,6 @@ package org.argeo.slc.dao.test.tree; import java.util.SortedSet; -import org.argeo.slc.core.test.tree.TreeTestResult; import org.argeo.slc.core.test.tree.TreeTestResultCollection; public interface TreeTestResultCollectionDao { diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/msg/process/SlcExecutionStepsRequest.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/msg/process/SlcExecutionStepsRequest.java index 9c564aaae..7da2b43f5 100644 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/msg/process/SlcExecutionStepsRequest.java +++ b/org.argeo.slc.core/src/main/java/org/argeo/slc/msg/process/SlcExecutionStepsRequest.java @@ -19,6 +19,14 @@ public class SlcExecutionStepsRequest { this.steps = steps; } + public SlcExecutionStepsRequest(String slcExecutionUuid, + SlcExecutionStep step) { + this.slcExecutionUuid = slcExecutionUuid; + List steps = new Vector(); + steps.add(step); + this.steps = steps; + } + public String getSlcExecutionUuid() { return slcExecutionUuid; } diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/msg/test/tree/CreateTreeTestResultRequest.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/msg/test/tree/CreateTreeTestResultRequest.java index 281f44d9c..e11ef0407 100644 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/msg/test/tree/CreateTreeTestResultRequest.java +++ b/org.argeo.slc.core/src/main/java/org/argeo/slc/msg/test/tree/CreateTreeTestResultRequest.java @@ -20,7 +20,7 @@ public class CreateTreeTestResultRequest { public void setTreeTestResult(TreeTestResult treeTestResult) { this.treeTestResult = treeTestResult; } - + @Override public String toString() { return getClass().getSimpleName() + "#" + treeTestResult.getUuid(); diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/msg/test/tree/ResultPartRequest.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/msg/test/tree/ResultPartRequest.java index 04aa41462..7e3750ea9 100644 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/msg/test/tree/ResultPartRequest.java +++ b/org.argeo.slc.core/src/main/java/org/argeo/slc/msg/test/tree/ResultPartRequest.java @@ -25,8 +25,8 @@ public class ResultPartRequest { SimpleResultPart resultPart) { resultUuid = ttr.getUuid(); this.resultPart = resultPart; - this.path = path; - relatedElements = ttr.getRelatedElements(path); + this.path = (path != null ? path : ttr.getCurrentPath()); + relatedElements = ttr.getRelatedElements(this.path); if (ttr.getCurrentTestRun() != null) testRunDescriptor = new TestRunDescriptor(ttr.getCurrentTestRun()); } diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/runtime/SlcExecutionOutput.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/runtime/SlcExecutionOutput.java index c6353942d..7db938399 100644 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/runtime/SlcExecutionOutput.java +++ b/org.argeo.slc.core/src/main/java/org/argeo/slc/runtime/SlcExecutionOutput.java @@ -1,6 +1,6 @@ package org.argeo.slc.runtime; public interface SlcExecutionOutput { - /** Called after the execution, before the resources are freed.*/ + /** Called after the execution, before the resources are freed. */ public void postExecution(T executionContext); } diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/spring/SpringUtils.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/spring/SpringUtils.java index 7e01f3235..2b7569f88 100644 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/spring/SpringUtils.java +++ b/org.argeo.slc.core/src/main/java/org/argeo/slc/spring/SpringUtils.java @@ -2,13 +2,11 @@ package org.argeo.slc.spring; import java.io.IOException; import java.net.URI; -import java.net.URL; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.slc.core.SlcException; -import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.core.io.DefaultResourceLoader; diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/unit/AbstractSpringTestCase.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/unit/AbstractSpringTestCase.java index 625564fa7..a37c4a7ce 100644 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/unit/AbstractSpringTestCase.java +++ b/org.argeo.slc.core/src/main/java/org/argeo/slc/unit/AbstractSpringTestCase.java @@ -2,15 +2,12 @@ package org.argeo.slc.unit; import junit.framework.TestCase; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.argeo.slc.core.SlcException; import org.argeo.slc.spring.SpringUtils; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; /** Helper for tests using a Spring application co,text. */ public abstract class AbstractSpringTestCase extends TestCase { diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/unit/test/tree/TreeTestResultTestUtils.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/unit/test/tree/TreeTestResultTestUtils.java index a9a2d8e1e..92e66bb02 100644 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/unit/test/tree/TreeTestResultTestUtils.java +++ b/org.argeo.slc.core/src/main/java/org/argeo/slc/unit/test/tree/TreeTestResultTestUtils.java @@ -33,6 +33,16 @@ public abstract class TreeTestResultTestUtils { SlcExecutionStep step = new SlcExecutionStep("JUnit step"); slcExecution.getSteps().add(step); + TreeTestResult ttr = createMinimalConsistentTreeTestResult(slcExecution); + + ttr.addResultPart(createSimpleResultPartPassed()); + ttr.addResultPart(createSimpleResultPartFailed()); + ttr.addResultPart(createSimpleResultPartError()); + return ttr; + } + + public static TreeTestResult createMinimalConsistentTreeTestResult( + SlcExecution slcExecution) { SimpleTestRun testRun = new SimpleTestRun(); testRun.setUuid(UUID.randomUUID().toString()); @@ -71,10 +81,6 @@ public abstract class TreeTestResultTestUtils { }); testRun.notifySlcExecution(slcExecution); - - ttr.addResultPart(createSimpleResultPartPassed()); - ttr.addResultPart(createSimpleResultPartFailed()); - ttr.addResultPart(createSimpleResultPartError()); return ttr; } -- 2.39.2