KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > util > test > PropertyPatternUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.util.test;
23
24 import java.io.File JavaDoc;
25
26 import org.jboss.util.StringPropertyReplacer;
27 import org.jboss.test.JBossTestCase;
28
29 /**
30  * Unit tests for the custom JBoss property editors
31  *
32  * @see org.jboss.util.StringPropertyReplacer
33  * @author <a HREF="Adrian.Brock@HappeningTimes.com">Adrian.Brock</a>
34  * @version $Revision: 37406 $
35  */

36 public class PropertyPatternUnitTestCase extends JBossTestCase
37 {
38    static final String JavaDoc simpleKey = "org.jboss.test.util.test.Simple";
39    static final String JavaDoc simple = "AProperty";
40    static final String JavaDoc anotherKey = "org.jboss.test.util.test.Another";
41    static final String JavaDoc another = "BProperty";
42    static final String JavaDoc doesNotExist = "org.jboss.test.util.test.DoesNotExist";
43    static final String JavaDoc before = "Before";
44    static final String JavaDoc between = "Between";
45    static final String JavaDoc after = "After";
46    static final String JavaDoc fileSeparatorKey = "/";
47    static final String JavaDoc pathSeparatorKey = ":";
48
49    String JavaDoc longWithNoProperties = new String JavaDoc("\n"+
50 " BLOB_TYPE=OBJECT_BLOB\n"+
51 " INSERT_TX = INSERT INTO JMS_TRANSACTIONS (TXID) values(?)\n"+
52 " INSERT_MESSAGE = INSERT INTO JMS_MESSAGES (MESSAGEID, DESTINATION, MESSAGEBLOB, TXID, TXOP) VALUES(?,?,?,?,?)\n"+
53 " SELECT_ALL_UNCOMMITED_TXS = SELECT TXID FROM JMS_TRANSACTIONS\n"+
54 " SELECT_MAX_TX = SELECT MAX(TXID) FROM JMS_MESSAGES\n"+
55 " SELECT_MESSAGES_IN_DEST = SELECT MESSAGEID, MESSAGEBLOB FROM JMS_MESSAGES WHERE DESTINATION=?\n"+
56 " SELECT_MESSAGE = SELECT MESSAGEID, MESSAGEBLOB FROM JMS_MESSAGES WHERE MESSAGEID=? AND DESTINATION=?\n"+
57 " MARK_MESSAGE = UPDATE JMS_MESSAGES SET TXID=?, TXOP=? WHERE MESSAGEID=? AND DESTINATION=?\n"+
58 " UPDATE_MESSAGE = UPDATE JMS_MESSAGES SET MESSAGEBLOB=? WHERE MESSAGEID=? AND DESTINATION=?\n"+
59 " UPDATE_MARKED_MESSAGES = UPDATE JMS_MESSAGES SET TXID=?, TXOP=? WHERE TXOP=?\n"+
60 " UPDATE_MARKED_MESSAGES_WITH_TX = UPDATE JMS_MESSAGES SET TXID=?, TXOP=? WHERE TXOP=? AND TXID=?\n"+
61 " DELETE_MARKED_MESSAGES_WITH_TX = DELETE FROM JMS_MESSAGES WHERE TXID IS NOT NULL AND TXOP=?\n"+
62 " DELETE_TX = DELETE FROM JMS_TRANSACTIONS WHERE TXID = ?\n"+
63 " DELETE_MARKED_MESSAGES = DELETE FROM JMS_MESSAGES WHERE TXID=? AND TXOP=?\n"+
64 " DELETE_MESSAGE = DELETE FROM JMS_MESSAGES WHERE MESSAGEID=? AND DESTINATION=?\n"+
65 " CREATE_MESSAGE_TABLE = CREATE TABLE JMS_MESSAGES ( MESSAGEID INTEGER NOT NULL, \\\n"+
66 " DESTINATION VARCHAR(255) NOT NULL, TXID INTEGER, TXOP CHAR(1), \\\n"+
67 " MESSAGEBLOB OBJECT, PRIMARY KEY (MESSAGEID, DESTINATION) )\n"+
68 " CREATE_TX_TABLE = CREATE TABLE JMS_TRANSACTIONS ( TXID INTEGER )\n");
69
70    static
71    {
72       System.setProperty(simpleKey, simple);
73       System.setProperty(anotherKey, another);
74    }
75
76    public PropertyPatternUnitTestCase(String JavaDoc name)
77    {
78       super(name);
79    }
80
81    public void testEmptyPattern()
82       throws Exception JavaDoc
83    {
84       assertEquals("Empty pattern", "",
85          StringPropertyReplacer.replaceProperties(""));
86    }
87
88    public void testNoPattern()
89       throws Exception JavaDoc
90    {
91       assertEquals("No pattern", "xxx",
92          StringPropertyReplacer.replaceProperties("xxx"));
93    }
94
95    public void testNoProperty()
96       throws Exception JavaDoc
97    {
98       assertEquals("No pattern", "${xxx}",
99          StringPropertyReplacer.replaceProperties("${xxx}"));
100    }
101
102    public void testNoPropertyWithDefault()
103       throws Exception JavaDoc
104    {
105       assertEquals("No pattern", "xxx-default",
106          StringPropertyReplacer.replaceProperties("${xxx:xxx-default}"));
107    }
108
109    public void testPropertyWithDefault()
110       throws Exception JavaDoc
111    {
112       assertEquals("Simple pattern", simple,
113          StringPropertyReplacer.replaceProperties("${"+simpleKey+":simpleDefault}"));
114    }
115
116    public void testSimpleProperty()
117       throws Exception JavaDoc
118    {
119       assertEquals("Simple pattern", simple,
120          StringPropertyReplacer.replaceProperties("${"+simpleKey+"}"));
121    }
122    
123    public void testFileSeparatorProperty()
124       throws Exception JavaDoc
125    {
126       assertEquals("File Separator", before + File.separator + after,
127          StringPropertyReplacer.replaceProperties(before + "${" + fileSeparatorKey + "}" + after));
128    }
129
130    public void testPathSeparatorProperty()
131       throws Exception JavaDoc
132    {
133       assertEquals("Path Separator", before + File.pathSeparator + after,
134          StringPropertyReplacer.replaceProperties(before + "${" + pathSeparatorKey + "}" + after));
135    }
136
137    public void testStringBeforeProperty()
138       throws Exception JavaDoc
139    {
140       assertEquals("String before pattern", before + simple,
141          StringPropertyReplacer.replaceProperties(before + "${"+simpleKey+"}"));
142    }
143
144    public void testStringAfterProperty()
145       throws Exception JavaDoc
146    {
147       assertEquals("String after pattern", simple + after,
148          StringPropertyReplacer.replaceProperties("${"+simpleKey+"}" + after));
149    }
150
151    public void testStringBeforeAfterProperty()
152       throws Exception JavaDoc
153    {
154       assertEquals("String before and after pattern", before + simple + after,
155          StringPropertyReplacer.replaceProperties(before + "${"+simpleKey+"}" + after));
156    }
157
158    public void testStringBeforeBetweenProperty()
159       throws Exception JavaDoc
160    {
161       assertEquals("String before and between pattern", before + simple + between + another,
162          StringPropertyReplacer.replaceProperties(before + "${"+simpleKey+"}" + between + "${" + anotherKey + "}"));
163    }
164
165    public void testStringAfterBetweenProperty()
166       throws Exception JavaDoc
167    {
168       assertEquals("String after and between pattern", simple + between + another + after,
169          StringPropertyReplacer.replaceProperties("${"+simpleKey+"}" + between + "${" + anotherKey + "}" + after));
170    }
171
172    public void testStringBeforeAfterBetweenProperty()
173       throws Exception JavaDoc
174    {
175       assertEquals("String before, after and between pattern", before + simple + between + another + after,
176          StringPropertyReplacer.replaceProperties(before + "${"+simpleKey+"}" + between + "${" + anotherKey + "}" + after));
177    }
178
179    public void testDollarBeforeProperty()
180       throws Exception JavaDoc
181    {
182       assertEquals("Dollar before pattern", "$" + simple,
183          StringPropertyReplacer.replaceProperties("$${"+simpleKey+"}"));
184    }
185
186    public void testSpaceBetweenDollarAndProperty()
187       throws Exception JavaDoc
188    {
189       assertEquals("Dollar before pattern", "$ {"+simpleKey+"}",
190          StringPropertyReplacer.replaceProperties("$ {"+simpleKey+"}"));
191    }
192
193    public void testPropertyDoesNotExist()
194       throws Exception JavaDoc
195    {
196       assertEquals("Property does not exist", "${"+doesNotExist+"}",
197          StringPropertyReplacer.replaceProperties("${"+doesNotExist+"}"));
198    }
199
200    public void testPathologicalProperties()
201       throws Exception JavaDoc
202    {
203       assertEquals("$", StringPropertyReplacer.replaceProperties("$"));
204       assertEquals("{", StringPropertyReplacer.replaceProperties("{"));
205       assertEquals("}", StringPropertyReplacer.replaceProperties("}"));
206       assertEquals("${", StringPropertyReplacer.replaceProperties("${"));
207       assertEquals("$}", StringPropertyReplacer.replaceProperties("$}"));
208       assertEquals("{$", StringPropertyReplacer.replaceProperties("{$"));
209       assertEquals("{}", StringPropertyReplacer.replaceProperties("{}"));
210       assertEquals("{{", StringPropertyReplacer.replaceProperties("{{"));
211       assertEquals("}$", StringPropertyReplacer.replaceProperties("}$"));
212       assertEquals("}{", StringPropertyReplacer.replaceProperties("}{"));
213       assertEquals("}}", StringPropertyReplacer.replaceProperties("}}"));
214       assertEquals("}}", StringPropertyReplacer.replaceProperties("}}"));
215       assertEquals("${}", StringPropertyReplacer.replaceProperties("${}"));
216       assertEquals("$}{", StringPropertyReplacer.replaceProperties("$}{"));
217       assertEquals("}${", StringPropertyReplacer.replaceProperties("}${"));
218       assertEquals("}{$", StringPropertyReplacer.replaceProperties("}{$"));
219       assertEquals("{$}", StringPropertyReplacer.replaceProperties("{$}"));
220       assertEquals("{}$", StringPropertyReplacer.replaceProperties("{}$"));
221    }
222
223    public void testLongWithNoProperties()
224       throws Exception JavaDoc
225    {
226       long start = System.currentTimeMillis();
227       assertEquals("No properties in long string", longWithNoProperties,
228          StringPropertyReplacer.replaceProperties(longWithNoProperties));
229       long end = System.currentTimeMillis();
230       assertTrue("Shouldn't take very long", end - start < 1000);
231    }
232
233    /**
234     * Override the testServerFound since these test don't need the JBoss server
235     */

236    public void testServerFound()
237    {
238    }
239
240 }
241
242
Popular Tags