This project has retired. For details please refer to its
Attic page.
AbstractCmisTestGroup xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.tck.impl;
20
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.Map;
24
25 import org.apache.chemistry.opencmis.tck.CmisTest;
26 import org.apache.chemistry.opencmis.tck.CmisTestGroup;
27 import org.apache.chemistry.opencmis.tck.CmisTestProgressMonitor;
28 import org.junit.Test;
29
30
31
32
33 public abstract class AbstractCmisTestGroup implements CmisTestGroup {
34
35 private Map<String, String> parameters;
36 private String name;
37 private String description;
38 private final List<CmisTest> tests = new ArrayList<CmisTest>();
39 private boolean isEnabled = true;
40 private CmisTestProgressMonitor progressMonitor;
41
42 public void init(Map<String, String> parameters) throws Exception {
43 this.parameters = parameters;
44 }
45
46 protected Map<String, String> getParameters() {
47 return parameters;
48 }
49
50 public String getName() {
51 return name;
52 }
53
54 public void setName(String name) {
55 this.name = name;
56 }
57
58 public String getDescription() {
59 return description;
60 }
61
62 public void setDescription(String description) {
63 this.description = description;
64 }
65
66 public List<CmisTest> getTests() {
67 return tests;
68 }
69
70 public void addTest(CmisTest test) throws Exception {
71 if (test != null) {
72 tests.add(test);
73 if (test instanceof AbstractCmisTest) {
74 ((AbstractCmisTest) test).setGroup(this);
75 }
76 test.init(parameters);
77 }
78 }
79
80 public void setProgressMonitor(CmisTestProgressMonitor progressMonitor) {
81 this.progressMonitor = progressMonitor;
82 }
83
84 protected CmisTestProgressMonitor getProgressMonitor() {
85 return this.progressMonitor;
86 }
87
88 public void run() throws Exception {
89 if (progressMonitor != null) {
90 progressMonitor.startGroup(this);
91 }
92
93 try {
94 preRun();
95 for (CmisTest test : tests) {
96 if (test == null || !test.isEnabled()) {
97 continue;
98 }
99
100 try {
101 if (progressMonitor != null) {
102 progressMonitor.startTest(test);
103 }
104
105 preTest(test);
106
107 long start = System.currentTimeMillis();
108
109 test.run();
110
111 long end = System.currentTimeMillis();
112 if (test instanceof AbstractCmisTest) {
113 ((AbstractCmisTest) test).setTime(end - start);
114 }
115 } catch (Exception e) {
116 if (!(e instanceof FatalTestException)) {
117 throw e;
118 }
119 } finally {
120 postTest(test);
121
122 if (progressMonitor != null) {
123 progressMonitor.endTest(test);
124 }
125 }
126 }
127 } finally {
128 postRun();
129 }
130
131 if (progressMonitor != null) {
132 progressMonitor.endGroup(this);
133 }
134 }
135
136 @Test
137 public void junit() {
138 JUnitHelper.run(this);
139 }
140
141 protected void preRun() {
142 }
143
144 protected void postRun() {
145 }
146
147 protected void preTest(CmisTest test) {
148 }
149
150 protected void postTest(CmisTest test) {
151 }
152
153 public boolean isEnabled() {
154 return isEnabled;
155 }
156
157 public void setEnabled(boolean enabled) {
158 this.isEnabled = enabled;
159 }
160 }