KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > config > schema > repository > StandardApplicationsRepositoryTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.config.schema.repository;
5
6 import com.tc.config.schema.MockApplication;
7 import com.tc.config.schema.validate.MockConfigurationValidator;
8 import com.tc.test.TCTestCase;
9 import com.terracottatech.config.Application;
10
11 /**
12  * Unit test for {@link StandardApplicationsRepository}.
13  */

14 public class StandardApplicationsRepositoryTest extends TCTestCase {
15
16   private StandardApplicationsRepository repository;
17   private MockConfigurationValidator validator1;
18   private MockConfigurationValidator validator2;
19
20   public void setUp() throws Exception JavaDoc {
21     this.repository = new StandardApplicationsRepository();
22
23     this.validator1 = new MockConfigurationValidator();
24     this.validator2 = new MockConfigurationValidator();
25   }
26
27   public void testAll() throws Exception JavaDoc {
28     try {
29       this.repository.repositoryFor(null);
30       fail("Didn't get NPE on no application name");
31     } catch (NullPointerException JavaDoc npe) {
32       // ok
33
}
34
35     try {
36       this.repository.repositoryFor("");
37       fail("Didn't get IAE on empty application name");
38     } catch (IllegalArgumentException JavaDoc iae) {
39       // ok
40
}
41
42     try {
43       this.repository.repositoryFor(" ");
44       fail("Didn't get IAE on blank application name");
45     } catch (IllegalArgumentException JavaDoc iae) {
46       // ok
47
}
48
49     assertEqualsUnordered(new String JavaDoc[0], this.repository.applicationNames());
50
51     MutableBeanRepository one = this.repository.repositoryFor("one");
52
53     assertEqualsUnordered(new String JavaDoc[] { "one" }, this.repository.applicationNames());
54
55     this.repository.addRepositoryValidator(this.validator1);
56
57     MutableBeanRepository two = this.repository.repositoryFor("two");
58     assertSame(two, this.repository.repositoryFor("two"));
59     assertNotSame(one, two);
60
61     assertSame(one, this.repository.repositoryFor("one"));
62     assertSame(two, this.repository.repositoryFor("two"));
63     assertSame(one, this.repository.repositoryFor("one"));
64     assertSame(two, this.repository.repositoryFor("two"));
65
66     assertEqualsUnordered(new String JavaDoc[] { "one", "two" }, this.repository.applicationNames());
67
68     this.repository.addRepositoryValidator(this.validator2);
69
70     MutableBeanRepository three = this.repository.repositoryFor("three");
71
72     assertEqualsUnordered(new String JavaDoc[] { "one", "two", "three" }, this.repository.applicationNames());
73     assertNotSame(one, three);
74     assertNotSame(two, three);
75
76     assertSame(three, this.repository.repositoryFor("three"));
77
78     Application oneBean = new MockApplication();
79     Application twoBean = new MockApplication();
80     Application threeBean = new MockApplication();
81
82     one.setBean(oneBean, "foobar");
83
84     assertEquals(0, this.validator1.getNumValidates());
85     assertEquals(0, this.validator2.getNumValidates());
86
87     two.setBean(twoBean, "foobaz");
88
89     assertEquals(1, this.validator1.getNumValidates());
90     assertSame(twoBean, this.validator1.getLastBean());
91     assertEquals(0, this.validator2.getNumValidates());
92
93     this.validator1.reset();
94
95     three.setBean(threeBean, "foobonk");
96
97     assertEquals(1, this.validator1.getNumValidates());
98     assertSame(threeBean, this.validator1.getLastBean());
99     assertEquals(1, this.validator2.getNumValidates());
100     assertSame(threeBean, this.validator2.getLastBean());
101
102     this.validator1.reset();
103   }
104
105 }
106
Popular Tags