KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > config > StandardDSOSpringConfigHelperTest


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.object.config;
5
6 import junit.framework.TestCase;
7
8 /**
9  * This class testing the following "designed" behavior
10  * 1. App name, config path and distributed events supports wildcards (heading and tailing only though)
11  * 2. Bean name, excluded field name has to match exactly
12  *
13  */

14 public class StandardDSOSpringConfigHelperTest extends TestCase {
15   private StandardDSOSpringConfigHelper config = null;
16   
17   public void setUp() {
18     config = new StandardDSOSpringConfigHelper();
19   }
20   
21   /*
22    * Test method for 'com.tc.object.config.StandardDSOSpringConfigHelper.isMatching(String, String)'
23    */

24   public void testIsMatching() {
25     assertTrue(config.isMatching("*", null));
26     assertTrue(config.isMatching("*", ""));
27     assertTrue(config.isMatching("*", "a"));
28     assertTrue(config.isMatching("*", "aaaa"));
29
30     assertTrue(config.isMatching("*a", "a"));
31     assertTrue(config.isMatching("*a", "ba"));
32     assertTrue(config.isMatching("*aaa", "baaa"));
33     assertTrue(config.isMatching("*aaa", "baaaa")); // ends with
34
assertFalse(config.isMatching("*a", "b"));
35     assertFalse(config.isMatching("*a", null));
36     assertFalse(config.isMatching("*aaa", "baa"));
37
38     assertTrue(config.isMatching("a*", "a"));
39     assertTrue(config.isMatching("a*", "ab"));
40     assertTrue(config.isMatching("a*", "aab"));
41     assertTrue(config.isMatching("aa*", "aab"));
42     assertTrue(config.isMatching("aa*", "aaab"));
43     assertFalse(config.isMatching("a*", null));
44     assertFalse(config.isMatching("a*", "b"));
45     assertFalse(config.isMatching("aaa*", "aab"));
46
47     assertTrue(config.isMatching("**", ""));
48     assertTrue(config.isMatching("*a*", "a"));
49     assertTrue(config.isMatching("*a*", "aaa"));
50     assertTrue(config.isMatching("*a*", "bab"));
51     assertTrue(config.isMatching("*a*", "ba"));
52     assertTrue(config.isMatching("*a*", "ab"));
53     assertTrue(config.isMatching("*a*", "baaab"));
54     assertTrue(config.isMatching("*a*", "aaab"));
55     assertTrue(config.isMatching("*a*", "baaa"));
56     assertFalse(config.isMatching("*a*", ""));
57     assertFalse(config.isMatching("**", null));
58
59     assertTrue(config.isMatching("", ""));
60     assertTrue(config.isMatching("aa", "aa"));
61     assertFalse(config.isMatching("aa", "aaa"));
62     assertFalse(config.isMatching("", "aa"));
63   }
64   
65   public void testMatchingConfig() throws Exception JavaDoc {
66     config.addConfigPattern("exact");
67     config.addConfigPattern("*Tail");
68     config.addConfigPattern("Head*");
69     config.addConfigPattern("*Wherever*");
70     
71     assertTrue(config.isMatchingConfig("exact"));
72     assertTrue(config.isMatchingConfig("Blah.And_Tail"));
73     assertTrue(config.isMatchingConfig("Head.And_Blah"));
74     assertTrue(config.isMatchingConfig("Blah.WhereverAnd_Blah"));
75     assertTrue(config.isMatchingConfig("Tail"));
76     assertTrue(config.isMatchingConfig("Head"));
77     assertTrue(config.isMatchingConfig("itisWherever"));
78     assertTrue(config.isMatchingConfig("Whereveritgoes"));
79     assertTrue(config.isMatchingConfig("Wherever"));
80     
81     assertFalse(config.isMatchingConfig("notexact"));
82     assertFalse(config.isMatchingConfig("withTailandmore"));
83     assertFalse(config.isMatchingConfig("notHead"));
84     assertFalse(config.isMatchingConfig("WHereverhastobecasesensitive"));
85   }
86   
87   public void testDistributedEvents() throws Exception JavaDoc {
88     config.addDistributedEvent("exact");
89     config.addDistributedEvent("*Tail");
90     config.addDistributedEvent("Head*");
91     config.addDistributedEvent("*Wherever*");
92     
93     assertTrue(config.isDistributedEvent("exact"));
94     assertTrue(config.isDistributedEvent("Blah.And_Tail"));
95     assertTrue(config.isDistributedEvent("Head.And_Blah"));
96     assertTrue(config.isDistributedEvent("Blah.WhereverAnd_Blah"));
97     assertTrue(config.isDistributedEvent("Tail"));
98     assertTrue(config.isDistributedEvent("Head"));
99     assertTrue(config.isDistributedEvent("itisWherever"));
100     assertTrue(config.isDistributedEvent("Whereveritgoes"));
101     assertTrue(config.isDistributedEvent("Wherever"));
102     
103     assertFalse(config.isDistributedEvent("notexact"));
104     assertFalse(config.isDistributedEvent("withTailandmore"));
105     assertFalse(config.isDistributedEvent("notHead"));
106     assertFalse(config.isDistributedEvent("WHereverhastobecasesensitive"));
107   }
108   
109   public void testDistributedBean() throws Exception JavaDoc {
110     config.addBean("exact");
111     config.addBean("*");
112     
113     assertTrue(config.isDistributedBean("exact"));
114     assertFalse(config.isDistributedBean("wildcardshouldnotwork"));
115   }
116   
117   public void testApplicationPattern() throws Exception JavaDoc {
118     config.addApplicationNamePattern("exact");
119     config.addApplicationNamePattern("*Tail");
120     config.addApplicationNamePattern("Head*");
121     config.addApplicationNamePattern("*Wherever*");
122     
123     assertTrue(config.isMatchingApplication("exact"));
124     assertTrue(config.isMatchingApplication("Blah.And_Tail"));
125     assertTrue(config.isMatchingApplication("Head.And_Blah"));
126     assertTrue(config.isMatchingApplication("Blah.WhereverAnd_Blah"));
127     assertTrue(config.isMatchingApplication("Tail"));
128     assertTrue(config.isMatchingApplication("Head"));
129     assertTrue(config.isMatchingApplication("itisWherever"));
130     assertTrue(config.isMatchingApplication("Whereveritgoes"));
131     assertTrue(config.isMatchingApplication("Wherever"));
132     
133     assertFalse(config.isMatchingApplication("notexact"));
134     assertFalse(config.isMatchingApplication("withTailandmore"));
135     assertFalse(config.isMatchingApplication("notHead"));
136     assertFalse(config.isMatchingApplication("WHereverhastobecasesensitive"));
137   }
138   
139   public void testExludeField() throws Exception JavaDoc {
140     config.addBean("existingBean");
141     config.excludeField("existingBean", "exact");
142     config.excludeField("existingBean", "*");
143     config.excludeField("newBean", "exact");
144     config.excludeField("newBean", "*");
145
146     assertFalse(config.isDistributedField("newBean", "exact"));
147     assertFalse(config.isDistributedField("existingBean", "exact"));
148     
149     
150     assertTrue(config.isDistributedField("newBean", "wildcardshouldnotwork"));
151     assertTrue(config.isDistributedField("existigBean", "wildcardshouldnotwork"));
152     assertTrue(config.isDistributedField("beanNameNotMatch", "exact"));
153     assertTrue(config.isDistributedField("beanNameNotMatch", "wildcardshouldnotwork"));
154   }
155 }
156
Popular Tags