01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21: package db4ounit.extensions.tests;
22:
23: import com.db4o.foundation.io.*;
24:
25: import db4ounit.*;
26: import db4ounit.extensions.*;
27: import db4ounit.extensions.fixtures.*;
28: import db4ounit.extensions.util.*;
29: import db4ounit.tests.*;
30:
31: public class AllTests implements TestCase {
32: private final class ExcludingInMemoryFixture extends Db4oInMemory {
33: public ExcludingInMemoryFixture(ConfigurationSource source) {
34: super (source);
35: }
36:
37: public boolean accept(Class clazz) {
38: return !OptOutFromTestFixture.class.isAssignableFrom(clazz);
39: }
40: }
41:
42: public static void main(String[] args) {
43: new TestRunner(AllTests.class).run();
44: }
45:
46: public void testSingleTestWithDifferentFixtures() {
47: ConfigurationSource configSource = new IndependentConfigurationSource();
48: assertSimpleDb4o(new Db4oInMemory(configSource));
49: assertSimpleDb4o(new Db4oSolo(configSource));
50: }
51:
52: public void testMultipleTestsSingleFixture() {
53: MultipleDb4oTestCase.resetConfigureCalls();
54: FrameworkTestCase.runTestAndExpect(new Db4oTestSuiteBuilder(
55: new Db4oInMemory(new IndependentConfigurationSource()),
56: MultipleDb4oTestCase.class).build(), 2, false);
57: Assert.areEqual(2, MultipleDb4oTestCase.configureCalls());
58: }
59:
60: public void testSelectiveFixture() {
61: Db4oFixture fixture = new ExcludingInMemoryFixture(
62: new IndependentConfigurationSource());
63: TestSuite suite = new Db4oTestSuiteBuilder(fixture,
64: new Class[] { AcceptedTestCase.class,
65: NotAcceptedTestCase.class }).build();
66: Assert.areEqual(1, suite.getTests().length);
67: FrameworkTestCase.runTestAndExpect(suite, 0);
68: }
69:
70: private void assertSimpleDb4o(Db4oFixture fixture) {
71: TestSuite suite = new Db4oTestSuiteBuilder(fixture,
72: SimpleDb4oTestCase.class).build();
73: SimpleDb4oTestCase subject = getTestSubject(suite);
74: subject.expectedFixture(fixture);
75: FrameworkTestCase.runTestAndExpect(suite, 0);
76: Assert.isTrue(subject.everythingCalled());
77: }
78:
79: private SimpleDb4oTestCase getTestSubject(TestSuite suite) {
80: return ((SimpleDb4oTestCase) ((TestMethod) suite.getTests()[0])
81: .getSubject());
82: }
83:
84: public void testInterfaceIsAvailable() {
85: Assert.isTrue(Db4oTestCase.class
86: .isAssignableFrom(AbstractDb4oTestCase.class));
87: }
88:
89: public void testDeleteDir() throws Exception {
90: File4.mkdirs("a/b/c");
91: Assert.isTrue(File4.exists("a"));
92: IOUtil.deleteDir("a");
93: Assert.isFalse(File4.exists("a"));
94: }
95: }
|