]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/BasicTestDefinition.java
Finalize JMS serialization
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / test / BasicTestDefinition.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.core.test;
18
19 import org.argeo.slc.SlcException;
20 import org.argeo.slc.core.structure.tree.TreeSRelatedHelper;
21 import org.argeo.slc.core.test.context.ContextUtils;
22 import org.argeo.slc.test.IncompatibleTestDataException;
23 import org.argeo.slc.test.TestData;
24 import org.argeo.slc.test.TestDefinition;
25 import org.argeo.slc.test.TestResult;
26 import org.argeo.slc.test.TestRun;
27 import org.argeo.slc.test.TestStatus;
28 import org.argeo.slc.test.context.ContextAware;
29
30 /** Understands basic test data and context aware test data. */
31 public class BasicTestDefinition extends TreeSRelatedHelper implements
32 TestDefinition {
33
34 public void execute(TestRun testRun) {
35 if (testRun.<TestData> getTestData() instanceof BasicTestData) {
36 BasicTestData testData = testRun.getTestData();
37 TestResult result = testRun.getTestResult();
38
39 if (result == null)
40 throw new SlcException("No test result defined.");
41
42 try {
43 if (testData.getExpected().equals(testData.getReached())) {
44 result.addResultPart(new SimpleResultPart(
45 TestStatus.PASSED, "Reached and expected equals"));
46 } else {
47 result.addResultPart(new SimpleResultPart(
48 TestStatus.FAILED, "Expected "
49 + testData.getExpected() + " but reached "
50 + testData.getReached()));
51 }
52 } catch (Exception e) {
53 result.addResultPart(new SimpleResultPart(TestStatus.ERROR,
54 "Could not compare", e));
55 }
56 } else if (testRun.<TestData> getTestData() instanceof ContextAware) {
57 TestData testData = testRun.getTestData();
58 ContextUtils.compareReachedExpected((ContextAware) testData,
59 testRun.getTestResult(), this);
60 } else {
61 throw new IncompatibleTestDataException(testRun);
62 }
63 }
64 }