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.object.config;
005:
006: import junit.framework.TestCase;
007:
008: /**
009: * This class testing the following "designed" behavior
010: * 1. App name, config path and distributed events supports wildcards (heading and tailing only though)
011: * 2. Bean name, excluded field name has to match exactly
012: *
013: */
014: public class StandardDSOSpringConfigHelperTest extends TestCase {
015: private StandardDSOSpringConfigHelper config = null;
016:
017: public void setUp() {
018: config = new StandardDSOSpringConfigHelper();
019: }
020:
021: /*
022: * Test method for 'com.tc.object.config.StandardDSOSpringConfigHelper.isMatching(String, String)'
023: */
024: public void testIsMatching() {
025: assertTrue(config.isMatching("*", null));
026: assertTrue(config.isMatching("*", ""));
027: assertTrue(config.isMatching("*", "a"));
028: assertTrue(config.isMatching("*", "aaaa"));
029:
030: assertTrue(config.isMatching("*a", "a"));
031: assertTrue(config.isMatching("*a", "ba"));
032: assertTrue(config.isMatching("*aaa", "baaa"));
033: assertTrue(config.isMatching("*aaa", "baaaa")); // ends with
034: assertFalse(config.isMatching("*a", "b"));
035: assertFalse(config.isMatching("*a", null));
036: assertFalse(config.isMatching("*aaa", "baa"));
037:
038: assertTrue(config.isMatching("a*", "a"));
039: assertTrue(config.isMatching("a*", "ab"));
040: assertTrue(config.isMatching("a*", "aab"));
041: assertTrue(config.isMatching("aa*", "aab"));
042: assertTrue(config.isMatching("aa*", "aaab"));
043: assertFalse(config.isMatching("a*", null));
044: assertFalse(config.isMatching("a*", "b"));
045: assertFalse(config.isMatching("aaa*", "aab"));
046:
047: assertTrue(config.isMatching("**", ""));
048: assertTrue(config.isMatching("*a*", "a"));
049: assertTrue(config.isMatching("*a*", "aaa"));
050: assertTrue(config.isMatching("*a*", "bab"));
051: assertTrue(config.isMatching("*a*", "ba"));
052: assertTrue(config.isMatching("*a*", "ab"));
053: assertTrue(config.isMatching("*a*", "baaab"));
054: assertTrue(config.isMatching("*a*", "aaab"));
055: assertTrue(config.isMatching("*a*", "baaa"));
056: assertFalse(config.isMatching("*a*", ""));
057: assertFalse(config.isMatching("**", null));
058:
059: assertTrue(config.isMatching("", ""));
060: assertTrue(config.isMatching("aa", "aa"));
061: assertFalse(config.isMatching("aa", "aaa"));
062: assertFalse(config.isMatching("", "aa"));
063: }
064:
065: public void testMatchingConfig() throws Exception {
066: config.addConfigPattern("exact");
067: config.addConfigPattern("*Tail");
068: config.addConfigPattern("Head*");
069: config.addConfigPattern("*Wherever*");
070:
071: assertTrue(config.isMatchingConfig("exact"));
072: assertTrue(config.isMatchingConfig("Blah.And_Tail"));
073: assertTrue(config.isMatchingConfig("Head.And_Blah"));
074: assertTrue(config.isMatchingConfig("Blah.WhereverAnd_Blah"));
075: assertTrue(config.isMatchingConfig("Tail"));
076: assertTrue(config.isMatchingConfig("Head"));
077: assertTrue(config.isMatchingConfig("itisWherever"));
078: assertTrue(config.isMatchingConfig("Whereveritgoes"));
079: assertTrue(config.isMatchingConfig("Wherever"));
080:
081: assertFalse(config.isMatchingConfig("notexact"));
082: assertFalse(config.isMatchingConfig("withTailandmore"));
083: assertFalse(config.isMatchingConfig("notHead"));
084: assertFalse(config
085: .isMatchingConfig("WHereverhastobecasesensitive"));
086: }
087:
088: public void testDistributedEvents() throws Exception {
089: config.addDistributedEvent("exact");
090: config.addDistributedEvent("*Tail");
091: config.addDistributedEvent("Head*");
092: config.addDistributedEvent("*Wherever*");
093:
094: assertTrue(config.isDistributedEvent("exact"));
095: assertTrue(config.isDistributedEvent("Blah.And_Tail"));
096: assertTrue(config.isDistributedEvent("Head.And_Blah"));
097: assertTrue(config.isDistributedEvent("Blah.WhereverAnd_Blah"));
098: assertTrue(config.isDistributedEvent("Tail"));
099: assertTrue(config.isDistributedEvent("Head"));
100: assertTrue(config.isDistributedEvent("itisWherever"));
101: assertTrue(config.isDistributedEvent("Whereveritgoes"));
102: assertTrue(config.isDistributedEvent("Wherever"));
103:
104: assertFalse(config.isDistributedEvent("notexact"));
105: assertFalse(config.isDistributedEvent("withTailandmore"));
106: assertFalse(config.isDistributedEvent("notHead"));
107: assertFalse(config
108: .isDistributedEvent("WHereverhastobecasesensitive"));
109: }
110:
111: public void testDistributedBean() throws Exception {
112: config.addBean("exact");
113: config.addBean("*");
114:
115: assertTrue(config.isDistributedBean("exact"));
116: assertFalse(config.isDistributedBean("wildcardshouldnotwork"));
117: }
118:
119: public void testApplicationPattern() throws Exception {
120: config.addApplicationNamePattern("exact");
121: config.addApplicationNamePattern("*Tail");
122: config.addApplicationNamePattern("Head*");
123: config.addApplicationNamePattern("*Wherever*");
124:
125: assertTrue(config.isMatchingApplication("exact"));
126: assertTrue(config.isMatchingApplication("Blah.And_Tail"));
127: assertTrue(config.isMatchingApplication("Head.And_Blah"));
128: assertTrue(config
129: .isMatchingApplication("Blah.WhereverAnd_Blah"));
130: assertTrue(config.isMatchingApplication("Tail"));
131: assertTrue(config.isMatchingApplication("Head"));
132: assertTrue(config.isMatchingApplication("itisWherever"));
133: assertTrue(config.isMatchingApplication("Whereveritgoes"));
134: assertTrue(config.isMatchingApplication("Wherever"));
135:
136: assertFalse(config.isMatchingApplication("notexact"));
137: assertFalse(config.isMatchingApplication("withTailandmore"));
138: assertFalse(config.isMatchingApplication("notHead"));
139: assertFalse(config
140: .isMatchingApplication("WHereverhastobecasesensitive"));
141: }
142:
143: public void testExludeField() throws Exception {
144: config.addBean("existingBean");
145: config.excludeField("existingBean", "exact");
146: config.excludeField("existingBean", "*");
147: config.excludeField("newBean", "exact");
148: config.excludeField("newBean", "*");
149:
150: assertFalse(config.isDistributedField("newBean", "exact"));
151: assertFalse(config.isDistributedField("existingBean", "exact"));
152:
153: assertTrue(config.isDistributedField("newBean",
154: "wildcardshouldnotwork"));
155: assertTrue(config.isDistributedField("existigBean",
156: "wildcardshouldnotwork"));
157: assertTrue(config.isDistributedField("beanNameNotMatch",
158: "exact"));
159: assertTrue(config.isDistributedField("beanNameNotMatch",
160: "wildcardshouldnotwork"));
161: }
162: }
|