View Javadoc
1   /*
2    * Copyright 2002-2016 the original author or authors
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 com.github.springtestdbunit.annotation;
18  
19  import java.lang.annotation.Documented;
20  import java.lang.annotation.ElementType;
21  import java.lang.annotation.Inherited;
22  import java.lang.annotation.Repeatable;
23  import java.lang.annotation.Retention;
24  import java.lang.annotation.RetentionPolicy;
25  import java.lang.annotation.Target;
26  
27  import org.dbunit.dataset.IDataSet;
28  import org.dbunit.dataset.filter.IColumnFilter;
29  
30  import com.github.springtestdbunit.DbUnitTestExecutionListener;
31  import com.github.springtestdbunit.assertion.DatabaseAssertionMode;
32  import com.github.springtestdbunit.dataset.DataSetModifier;
33  
34  /**
35   * Test annotation that can be used to assert that a database is in given state after tests have run.
36   *
37   * @see DbUnitTestExecutionListener
38   *
39   * @author Phillip Webb
40   * @author Mario Zagar
41   */
42  @Documented
43  @Inherited
44  @Retention(RetentionPolicy.RUNTIME)
45  @Target({ ElementType.TYPE, ElementType.METHOD })
46  @Repeatable(ExpectedDatabases.class)
47  public @interface ExpectedDatabase {
48  
49  	/**
50  	 * The name of the connection that should be used when verifying data. Can refer to a connection specified in
51  	 * {@link DbUnitConfiguration @DbUnitConfiguration} or left blank to use the default connection.
52  	 * @return the connection
53  	 */
54  	String connection() default "";
55  
56  	/**
57  	 * Provides the location of the dataset that will be used to test the database.
58  	 * @return The dataset locations
59  	 * @see DbUnitConfiguration#dataSetLoader()
60  	 */
61  	String value() default "";
62  
63  	/**
64  	 * Database assertion mode to use. Default is {@link DatabaseAssertionMode#DEFAULT}.
65  	 * @return Database assertion mode to use
66  	 */
67  	DatabaseAssertionMode assertionMode() default DatabaseAssertionMode.DEFAULT;
68  
69  	/**
70  	 * Optional table name that can be used to limit the comparison to a specific table.
71  	 * @return the table name
72  	 */
73  	String table() default "";
74  
75  	/**
76  	 * Optional SQL to retrieve the actual subset of the table rows from the database. NOTE: a {@link #table() table
77  	 * name} must also be specified when using a query.
78  	 * @return the SQL Query
79  	 */
80  	String query() default "";
81  
82  	/**
83  	 * If this expectation overrides any others that have been defined at a higher level. Defaults to {@code true}
84  	 * @return if this annotation overrides any others
85  	 */
86  	boolean override() default true;
87  
88  	/**
89  	 * A set of {@link DataSetModifier} that will be applied to the {@link IDataSet} before it is used. Can refer to a
90  	 * static or inner class of the test.
91  	 * @return the modifiers to apply
92  	 */
93  	Class<? extends DataSetModifier>[] modifiers() default {};
94  
95  	/**
96  	 * A set of {@link org.dbunit.dataset.filter.IColumnFilter} that will be applied to column comparison when using
97  	 * non-strict {@link DatabaseAssertionMode}.
98  	 * <p>
99  	 * Specify this when you want to use DTD with your expected dataset XML file but want to exclude some columns from
100 	 * comparison.
101 	 * @return column filters to apply
102 	 */
103 	Class<? extends IColumnFilter>[] columnFilters() default {};
104 }