01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.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.opensource.org/licenses/ecl1.php
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.kuali.test.suite;
17:
18: import junit.framework.TestCase;
19: import junit.framework.TestSuite;
20:
21: import org.kuali.test.ConfigureContext;
22: import org.kuali.test.fixtures.UserNameFixture;
23:
24: /**
25: * The suite of all test classes with the {@link org.kuali.test.ConfigureContext} annotation. IDEs or Ant can run this as JUnit
26: * tests.
27: */
28: public class ContextConfiguredSuite {
29:
30: public static TestSuiteBuilder.ClassCriteria CLASS_CRITERIA = new TestSuiteBuilder.ClassCriteria() {
31: public boolean includes(Class<? extends TestCase> testClass) {
32: return testClass
33: .isAnnotationPresent(ConfigureContext.class);
34: }
35: };
36:
37: public static TestSuite suite() throws Exception {
38: return TestSuiteBuilder.build(CLASS_CRITERIA,
39: TestSuiteBuilder.NULL_CRITERIA);
40: }
41:
42: /**
43: * The suite of all test classes without the {@link org.kuali.test.ConfigureContext} annotation. IDEs or Ant can run this nested
44: * class as JUnit tests.
45: */
46: public static class Not {
47: public static TestSuite suite() throws Exception {
48: return TestSuiteBuilder.build(
49: new TestSuiteBuilder.NegatingClassCriteria(
50: CLASS_CRITERIA),
51: TestSuiteBuilder.NULL_CRITERIA);
52: }
53: }
54:
55: /**
56: * The suite of all test classes with the {@link org.kuali.test.ConfigureContext} annotation with a {@code session} element
57: * other than {@code NO_SESSION}. IDEs or Ant can run this nested class as JUnit tests.
58: */
59: public static class WithSession {
60: public static TestSuite suite() throws Exception {
61: TestSuiteBuilder.ClassCriteria classCriteria = new TestSuiteBuilder.ClassCriteria() {
62: public boolean includes(
63: Class<? extends TestCase> testClass) {
64: ConfigureContext annotation = testClass
65: .getAnnotation(ConfigureContext.class);
66: return annotation != null
67: && annotation.session() != UserNameFixture.NO_SESSION;
68: }
69: };
70: return TestSuiteBuilder.build(classCriteria,
71: TestSuiteBuilder.NULL_CRITERIA);
72: }
73: }
74:
75: /**
76: * The suite of all test classes with the {@link org.kuali.test.ConfigureContext} annotation with a {@code session} element of
77: * {@code NO_SESSION} (the default). IDEs or Ant can run this nested class as JUnit tests.
78: */
79: public static class WithoutSession {
80: public static TestSuite suite() throws Exception {
81: TestSuiteBuilder.ClassCriteria classCriteria = new TestSuiteBuilder.ClassCriteria() {
82: public boolean includes(
83: Class<? extends TestCase> testClass) {
84: ConfigureContext annotation = testClass
85: .getAnnotation(ConfigureContext.class);
86: return annotation != null
87: && annotation.session() == UserNameFixture.NO_SESSION;
88: }
89: };
90: return TestSuiteBuilder.build(classCriteria,
91: TestSuiteBuilder.NULL_CRITERIA);
92: }
93: }
94: }
|