]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/BasicTestDefinition.java
Make default execution ressources temp dir dependent of the JVM OS user, in order...
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / test / BasicTestDefinition.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
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 package org.argeo.slc.core.test;
17
18 import org.argeo.slc.SlcException;
19 import org.argeo.slc.core.structure.tree.TreeSRelatedHelper;
20 import org.argeo.slc.core.test.context.ContextUtils;
21 import org.argeo.slc.test.IncompatibleTestDataException;
22 import org.argeo.slc.test.TestData;
23 import org.argeo.slc.test.TestDefinition;
24 import org.argeo.slc.test.TestResult;
25 import org.argeo.slc.test.TestRun;
26 import org.argeo.slc.test.TestStatus;
27 import org.argeo.slc.test.context.ContextAware;
28
29 /** Understands basic test data and context aware test data. */
30 public class BasicTestDefinition extends TreeSRelatedHelper implements
31 TestDefinition {
32
33 public void execute(TestRun testRun) {
34 if (testRun.<TestData> getTestData() instanceof BasicTestData) {
35 BasicTestData testData = testRun.getTestData();
36 TestResult result = testRun.getTestResult();
37
38 if (result == null)
39 throw new SlcException("No test result defined.");
40
41 try {
42 if (testData.getExpected().equals(testData.getReached())) {
43 result.addResultPart(new SimpleResultPart(
44 TestStatus.PASSED, "Reached and expected equals"));
45 } else {
46 result.addResultPart(new SimpleResultPart(
47 TestStatus.FAILED, "Expected "
48 + testData.getExpected() + " but reached "
49 + testData.getReached()));
50 }
51 } catch (Exception e) {
52 result.addResultPart(new SimpleResultPart(TestStatus.ERROR,
53 "Could not compare", e));
54 }
55 } else if (testRun.<TestData> getTestData() instanceof ContextAware) {
56 TestData testData = testRun.getTestData();
57 ContextUtils.compareReachedExpected((ContextAware) testData,
58 testRun.getTestResult(), this);
59 } else {
60 throw new IncompatibleTestDataException(testRun);
61 }
62 }
63 }