summaryrefslogtreecommitdiffstats
path: root/sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/ConsistencyTestTemplate.java
blob: d37686a4bf6a0dc208cc38aeefa904e9aa31f823 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 *  
 *  $Rev$  $Date$
 */
package test.sdo21.tests;

// static imports simply allow you to call assertTrue rather than
// Assert.assertTrue
import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

import test.sdo21.tests.TestData.StandardDynamicFactory;
import test.sdo21.tests.TestData.StandardXSDFactory;
import test.sdo21.tests.TestData.TestDataFactory;
import test.sdo21.tests.api.CTSConsistencyBase;

import commonj.sdo.DataObject;

/**
 * Example test class to be used as a template for SDO test cases which apply
 * the same set of tests to a number of data sets of the same shape, but backed
 * by metadata created in different ways, e.g. from and xsd, using the dynamic API,
 * or, in the case of vendor specific tests, using statically generated classes.
 * 
 * This class extends {@link CTSConsistencyBase}
 * which requires a concrete derived class to provide a factory which will be used to
 * populate a DataObject called testSDO.  The concrete test can be written to conform
 * to the expected shape of test data created by the factory it chooses to instantiate <br>
 * <br>
 * The test case can be run using Junit within eclipse, from normal command line
 * junit, or within a WebSphere build environment by adding an target such as
 * sampleTestTarget that is contained within the build.xml file of the
 * WAS.soa.sdo.cts component. <br>
 * <br>
 * Once a test case has been completed and reviewed it can be added into the
 * appropiate CTS Suite.<br>
 * <br>
 * Tests class must only use methods that are defined
 * within the current SDO Specification. If utility methods are required they
 * should be added to {@link test.sdo21.framework.TestHelper}. <br>
 * <br>
 * Please Document the overall intention of the test case and provide detailed
 * javadoc for each test method. Please create modular test methods rather than
 * single large test methods. Please use provide links back to the Main class under test
 * and to the page in the specification as demonstrated below<br>
 * <br>
 * Resources:
 * <UL>
 * <LI><a href="http://www.junit.org/">Junit Foundation</a>
 * </UL>
 * 
 * @see DataObject
 * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=45">2.1 spec section 3.11</a>
 */
public abstract class ConsistencyTestTemplate extends CTSConsistencyBase {

    public ConsistencyTestTemplate() {
    } 
    

    /**
     * A concrete class which provides a factory that creates appropriate metadata for the
     * test case using the SDO dynamic API.  This can be referenced as a class to be tested
     * from within a junit suite declaration. Additional derived classes creating alternative
     * factories may be supplied ellsewhere and referenced by other junit suite declarations,
     * for example, in a vendor specific extension that uses statically generated classes.
     */
    public static class DynamicMetadata extends ConsistencyTestTemplate {
      public DynamicMetadata() {
        
      }
      public TestDataFactory createTestDataFactory() {
  
        return new StandardDynamicFactory();
      }
    }

    /**
     * A concrete class which provides a factory that creates appropriate metadata for the
     * test case using an XML schema.  This can be referenced as a class to be tested
     * from within a junit suite declaration. Additional derived classes creating alternative
     * factories may be supplied ellsewhere and referenced by other junit suite declarations,
     * for example, in a vendor specific extension that uses statically generated classes.
     */
    public static class XSDMetadata extends ConsistencyTestTemplate {
      
      public XSDMetadata() {
      }
      
      public TestDataFactory createTestDataFactory() {
  
        return new StandardXSDFactory();
      }
    }
    
    
    @Before
    public void setUp () throws Exception {
      super.setUp();
    }
    
    @After
    public void tearDown() throws Exception {
      super.tearDown();
    }
    /**
     * Example test method. Please provide good description of the test case in
     * javadoc including the intention, reference to the specification, etc.
     */
    @Test
    public void myTestMethod() {

        String expected = new String("bla bla bla");
        String actual = new String("bla bla bla");
        assertEquals("Your Message", expected, actual);
    }

    /**
     * Sometimes you want to temporarily disable a test. Methods annotated with
     * {@link org.junit.Test} that are also annotated with <code>@Ignore</code> will not be executed as tests. Native JUnit 4 test
     *         runners should report the number of ignored tests along with the
     *         number of tests that ran and the number of tests that failed.
     *         <code>@Ignore</code> takes an optional default parameter if you want to record
     *         why a test is being ignored:<br>
     */
    @Test
    @Ignore("Function Foo is not clearly defined within the SDO 2.1 specification and is currently being defined as a part of the x.x specification.")
    public void exampleIngoredTestCase() {
        // test method here
    }

    /**
     * Sometimes you may not have the resources to implement a test case. If is
     * very very valuable to create method signatures in the appropiate classes
     * for test cases that are currently not covered. In cases such as these
     * please define and checkin method signatures with the following ignore
     * message. <br>
     * <br>
     * In this case you should ensure that the class that contains the test
     * method is added to a testSuite such as
     * {@link test.sdo21.UnderReviewSuite} so that it will
     * be completed, or open a defect/JIRA to complete the test case.
     */
    @Test
    @Ignore("This test method requires implementation")
    public void exampleUnimplementedTestCase() {
    }

    /**
     * When writing tests, it is common to find that several tests need similar
     * objects created before they can run. Annotating a
     * <code>public void</code> method with <code>@Before</code> causes that method to be run before the
     *         {@link org.junit.Test} method. The <code>@Before</code> methods of superclasses will be run before those of the
     *         current class. There is also an <code>@After</code> annotation
     */
    @Before
    public void testCaseInit() {
        // initMethod
    }

    /**
     * Sometimes several tests need to share computationally expensive setup
     * (like logging into a database). While this can compromise the
     * independence of tests, sometimes it is a necessary optimization.
     * Annotating a <code>public static void</code> no-arg method with
     * <code>@BeforeClass</code> causes it to be run once before any of the test
     *              methods in the class. The <code>@BeforeClass</code> methods of superclasses will be run before those the
     *              current class.
     */
    @BeforeClass
    public static void init() {
        // init
    }
}