2 * Copyright (C) 2007-2012 Mathieu Baudier
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.slc
.core
.test
;
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
;
29 /** Understands basic test data and context aware test data. */
30 public class BasicTestDefinition
extends TreeSRelatedHelper
implements
33 public void execute(TestRun testRun
) {
34 if (testRun
.<TestData
> getTestData() instanceof BasicTestData
) {
35 BasicTestData testData
= testRun
.getTestData();
36 TestResult result
= testRun
.getTestResult();
39 throw new SlcException("No test result defined.");
42 if (testData
.getExpected().equals(testData
.getReached())) {
43 result
.addResultPart(new SimpleResultPart(
44 TestStatus
.PASSED
, "Reached and expected equals"));
46 result
.addResultPart(new SimpleResultPart(
47 TestStatus
.FAILED
, "Expected "
48 + testData
.getExpected() + " but reached "
49 + testData
.getReached()));
51 } catch (Exception e
) {
52 result
.addResultPart(new SimpleResultPart(TestStatus
.ERROR
,
53 "Could not compare", e
));
55 } else if (testRun
.<TestData
> getTestData() instanceof ContextAware
) {
56 TestData testData
= testRun
.getTestData();
57 ContextUtils
.compareReachedExpected((ContextAware
) testData
,
58 testRun
.getTestResult(), this);
60 throw new IncompatibleTestDataException(testRun
);