001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.config.schema.repository;
005:
006: import com.tc.config.schema.MockApplication;
007: import com.tc.config.schema.validate.MockConfigurationValidator;
008: import com.tc.test.TCTestCase;
009: import com.terracottatech.config.Application;
010:
011: /**
012: * Unit test for {@link StandardApplicationsRepository}.
013: */
014: public class StandardApplicationsRepositoryTest extends TCTestCase {
015:
016: private StandardApplicationsRepository repository;
017: private MockConfigurationValidator validator1;
018: private MockConfigurationValidator validator2;
019:
020: public void setUp() throws Exception {
021: this .repository = new StandardApplicationsRepository();
022:
023: this .validator1 = new MockConfigurationValidator();
024: this .validator2 = new MockConfigurationValidator();
025: }
026:
027: public void testAll() throws Exception {
028: try {
029: this .repository.repositoryFor(null);
030: fail("Didn't get NPE on no application name");
031: } catch (NullPointerException npe) {
032: // ok
033: }
034:
035: try {
036: this .repository.repositoryFor("");
037: fail("Didn't get IAE on empty application name");
038: } catch (IllegalArgumentException iae) {
039: // ok
040: }
041:
042: try {
043: this .repository.repositoryFor(" ");
044: fail("Didn't get IAE on blank application name");
045: } catch (IllegalArgumentException iae) {
046: // ok
047: }
048:
049: assertEqualsUnordered(new String[0], this .repository
050: .applicationNames());
051:
052: MutableBeanRepository one = this .repository
053: .repositoryFor("one");
054:
055: assertEqualsUnordered(new String[] { "one" }, this .repository
056: .applicationNames());
057:
058: this .repository.addRepositoryValidator(this .validator1);
059:
060: MutableBeanRepository two = this .repository
061: .repositoryFor("two");
062: assertSame(two, this .repository.repositoryFor("two"));
063: assertNotSame(one, two);
064:
065: assertSame(one, this .repository.repositoryFor("one"));
066: assertSame(two, this .repository.repositoryFor("two"));
067: assertSame(one, this .repository.repositoryFor("one"));
068: assertSame(two, this .repository.repositoryFor("two"));
069:
070: assertEqualsUnordered(new String[] { "one", "two" },
071: this .repository.applicationNames());
072:
073: this .repository.addRepositoryValidator(this .validator2);
074:
075: MutableBeanRepository three = this .repository
076: .repositoryFor("three");
077:
078: assertEqualsUnordered(new String[] { "one", "two", "three" },
079: this .repository.applicationNames());
080: assertNotSame(one, three);
081: assertNotSame(two, three);
082:
083: assertSame(three, this .repository.repositoryFor("three"));
084:
085: Application oneBean = new MockApplication();
086: Application twoBean = new MockApplication();
087: Application threeBean = new MockApplication();
088:
089: one.setBean(oneBean, "foobar");
090:
091: assertEquals(0, this .validator1.getNumValidates());
092: assertEquals(0, this .validator2.getNumValidates());
093:
094: two.setBean(twoBean, "foobaz");
095:
096: assertEquals(1, this .validator1.getNumValidates());
097: assertSame(twoBean, this .validator1.getLastBean());
098: assertEquals(0, this .validator2.getNumValidates());
099:
100: this .validator1.reset();
101:
102: three.setBean(threeBean, "foobonk");
103:
104: assertEquals(1, this .validator1.getNumValidates());
105: assertSame(threeBean, this .validator1.getLastBean());
106: assertEquals(1, this.validator2.getNumValidates());
107: assertSame(threeBean, this.validator2.getLastBean());
108:
109: this.validator1.reset();
110: }
111:
112: }
|