01: /*
02: * Copyright 2006-2007, Unitils.org
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.unitils.dbunit.annotation;
17:
18: import static java.lang.annotation.ElementType.METHOD;
19: import static java.lang.annotation.ElementType.TYPE;
20: import static java.lang.annotation.RetentionPolicy.RUNTIME;
21:
22: import java.lang.annotation.Inherited;
23: import java.lang.annotation.Retention;
24: import java.lang.annotation.Target;
25:
26: import org.unitils.dbunit.datasetfactory.DataSetFactory;
27:
28: /**
29: * Annotation indicating that after having executed a test method, the contents of the unit test database should be
30: * equal to the contents of a data set.
31: * <p/>
32: * If a class is annotated, the content of the unit test database will be compared with a dataset after the execution
33: * of each of the test methods in the class. A data set file name can explicitly be specified. If no such file name is
34: * specified, the default 'classname'.'testmethod'-result.xml will be tried, if no such file, an exception will be
35: * thrown. Filenames that start with '/' are treated absolute. Filenames that do not start with '/', are relative to
36: * the current class.
37: * <p/>
38: * A test method can also be annotated with ExpectedDataSet in which case you specify the dataset that needs to be used
39: * for this test method. Again, a file name can explicitly be specified or if not specified, the default will
40: * be used: 'classname'.'methodname'-result.xml. Example:
41: * <p/>
42: * Examples:
43: * <p/>
44: * <pre><code>
45: * ' @ExpectedDataSet
46: * public class MyTestClass extends UnitilsJUnit3 {
47: * '
48: * public void testMethod1(){
49: * }
50: * '
51: * ' @ExpectedDataSet("aCustomFileName.xml")
52: * public void testMethod2(){
53: * }
54: * }
55: * </code></pre>
56: * Will check the resulting contents of the unit test database using a data set file named MyTestClass.testMethod1-result.xml
57: * in the same directory as the class for testMethod1 and aCustomFileName.xml for testMethod2.
58: * <p/>
59: * <pre><code>
60: * public class MyTestClass extends UnitilsJUnit3 {
61: * '
62: * public void testMethod1(){
63: * }
64: * '
65: * ' @ExpectedDataSet
66: * public void testMethod2(){
67: * }
68: * }
69: * </code></pre>
70: * Will not perform any dataset check for testMethod1 (there is no class level expected data set). And will use a data set
71: * file named MyTestClass.testMethod2-result.xml for testMethod2.
72: *
73: * @author Filip Neven
74: * @author Tim Ducheyne
75: */
76: @Target({TYPE,METHOD})
77: @Retention(RUNTIME)
78: @Inherited
79: public @interface ExpectedDataSet {
80:
81: /**
82: * The file name of the data set. If left empty, the default filename will be
83: * used: 'classname'.'methodname'-result.xml. If that file also does not exist, an exception is thrown.
84: *
85: * @return the fileName, empty for default
86: */
87: String[] value() default {};
88:
89: Class<? extends DataSetFactory> factory() default DataSetFactory.class;
90:
91: }
|