1 package org
.argeo
.slc
.unit
.test
.tree
;
3 import static junit
.framework
.Assert
.assertEquals
;
4 import static junit
.framework
.Assert
.assertNotNull
;
5 import static junit
.framework
.Assert
.assertNull
;
6 import static junit
.framework
.Assert
.fail
;
8 import org
.argeo
.slc
.core
.structure
.SimpleSElement
;
9 import org
.argeo
.slc
.core
.structure
.tree
.TreeSPath
;
10 import org
.argeo
.slc
.core
.test
.SimpleResultPart
;
11 import org
.argeo
.slc
.core
.test
.TestResultPart
;
12 import org
.argeo
.slc
.core
.test
.tree
.PartSubList
;
13 import org
.argeo
.slc
.core
.test
.tree
.TreeTestResult
;
15 /** Utilities for unit tests. */
16 public class UnitTestTreeUtil
{
17 public static void assertTreeTestResult(TreeTestResult expected
,
18 TreeTestResult reached
) {
19 assertEquals(expected
.getTestResultId(), reached
.getTestResultId());
20 assertEquals(expected
.getCloseDate(), reached
.getCloseDate());
22 assertEquals(expected
.getResultParts().size(), reached
.getResultParts()
24 for (TreeSPath path
: expected
.getResultParts().keySet()) {
25 PartSubList lstExpected
= expected
.getResultParts().get(path
);
26 PartSubList lstReached
= expected
.getResultParts().get(path
);
27 if (lstReached
== null) {
28 fail("No result for path " + path
);
31 assertPartSubList(lstExpected
, lstReached
);
34 assertEquals(expected
.getElements().size(), reached
.getElements()
36 for (TreeSPath path
: expected
.getElements().keySet()) {
37 // String nameExpected = expected.getElements().get(path);
38 // String nameReached = expected.getElements().get(path);
39 SimpleSElement elemExpected
= (SimpleSElement
) expected
40 .getElements().get(path
);
41 SimpleSElement elemReached
= (SimpleSElement
) expected
42 .getElements().get(path
);
43 assertNotNull(elemReached
);
44 assertElements(elemExpected
, elemReached
);
49 public static void assertElements(SimpleSElement expected
,
50 SimpleSElement reached
) {
51 assertEquals(expected
.getLabel(), reached
.getLabel());
52 assertEquals(expected
.getTags().size(), reached
.getTags().size());
53 for (String tagName
: expected
.getTags().keySet()) {
54 String expectedTagValue
= expected
.getTags().get(tagName
);
55 String reachedTagValue
= reached
.getTags().get(tagName
);
56 assertNotNull(reachedTagValue
);
57 assertEquals(expectedTagValue
, reachedTagValue
);
61 public static void assertPartSubList(PartSubList lstExpected
,
62 PartSubList lstReached
) {
63 if (lstExpected
.getSlcExecutionUuid() == null) {
64 assertNull(lstReached
.getSlcExecutionUuid());
66 assertEquals(lstExpected
.getSlcExecutionUuid(), lstReached
67 .getSlcExecutionUuid());
70 if (lstExpected
.getSlcExecutionStepUuid() == null) {
71 assertNull(lstReached
.getSlcExecutionStepUuid());
73 assertEquals(lstExpected
.getSlcExecutionStepUuid(), lstReached
74 .getSlcExecutionStepUuid());
77 assertEquals(lstExpected
.getParts().size(), lstReached
.getParts()
79 for (int i
= 0; i
< lstExpected
.getParts().size(); i
++) {
80 assertPart(lstExpected
.getParts().get(i
), lstReached
.getParts()
86 * Assert one part of a tree test result.
88 * @deprecated use {@link #assertPart(TestResultPart, TestResultPart)}
91 public static void assertPart(TreeTestResult testResult
, String pathStr
,
92 int index
, Integer status
, String message
) {
93 TreeSPath path
= TreeSPath
.parseToCreatePath(pathStr
);
94 PartSubList list
= testResult
.getResultParts().get(path
);
96 fail("No result for path " + path
);
99 if (index
>= list
.getParts().size()) {
100 fail("Not enough parts.");
102 SimpleResultPart part
= (SimpleResultPart
) list
.getParts().get(index
);
103 assertPart(part
, status
, message
, null);
106 public static void assertPart(TestResultPart expected
,
107 TestResultPart reached
) {
108 assertPart(reached
, expected
.getStatus(), expected
.getMessage(),
109 expected
.getException());
112 /** Assert one part of a tree test result. */
113 private static void assertPart(TestResultPart part
, Integer status
,
114 String message
, Exception exception
) {
115 assertEquals(status
, part
.getStatus());
116 assertEquals(message
, part
.getMessage());
117 if (exception
== null) {
118 assertNull(part
.getException());
120 assertEquals(exception
, part
.getException());
124 /** Makes sure this is a singleton */
125 private UnitTestTreeUtil() {