1 22 package org.jboss.test.util.test; 23 24 import java.io.File ; 25 26 import org.jboss.util.StringPropertyReplacer; 27 import org.jboss.test.JBossTestCase; 28 29 36 public class PropertyPatternUnitTestCase extends JBossTestCase 37 { 38 static final String simpleKey = "org.jboss.test.util.test.Simple"; 39 static final String simple = "AProperty"; 40 static final String anotherKey = "org.jboss.test.util.test.Another"; 41 static final String another = "BProperty"; 42 static final String doesNotExist = "org.jboss.test.util.test.DoesNotExist"; 43 static final String before = "Before"; 44 static final String between = "Between"; 45 static final String after = "After"; 46 static final String fileSeparatorKey = "/"; 47 static final String pathSeparatorKey = ":"; 48 49 String longWithNoProperties = new String ("\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 name) 77 { 78 super(name); 79 } 80 81 public void testEmptyPattern() 82 throws Exception 83 { 84 assertEquals("Empty pattern", "", 85 StringPropertyReplacer.replaceProperties("")); 86 } 87 88 public void testNoPattern() 89 throws Exception 90 { 91 assertEquals("No pattern", "xxx", 92 StringPropertyReplacer.replaceProperties("xxx")); 93 } 94 95 public void testNoProperty() 96 throws Exception 97 { 98 assertEquals("No pattern", "${xxx}", 99 StringPropertyReplacer.replaceProperties("${xxx}")); 100 } 101 102 public void testNoPropertyWithDefault() 103 throws Exception 104 { 105 assertEquals("No pattern", "xxx-default", 106 StringPropertyReplacer.replaceProperties("${xxx:xxx-default}")); 107 } 108 109 public void testPropertyWithDefault() 110 throws Exception 111 { 112 assertEquals("Simple pattern", simple, 113 StringPropertyReplacer.replaceProperties("${"+simpleKey+":simpleDefault}")); 114 } 115 116 public void testSimpleProperty() 117 throws Exception 118 { 119 assertEquals("Simple pattern", simple, 120 StringPropertyReplacer.replaceProperties("${"+simpleKey+"}")); 121 } 122 123 public void testFileSeparatorProperty() 124 throws Exception 125 { 126 assertEquals("File Separator", before + File.separator + after, 127 StringPropertyReplacer.replaceProperties(before + "${" + fileSeparatorKey + "}" + after)); 128 } 129 130 public void testPathSeparatorProperty() 131 throws Exception 132 { 133 assertEquals("Path Separator", before + File.pathSeparator + after, 134 StringPropertyReplacer.replaceProperties(before + "${" + pathSeparatorKey + "}" + after)); 135 } 136 137 public void testStringBeforeProperty() 138 throws Exception 139 { 140 assertEquals("String before pattern", before + simple, 141 StringPropertyReplacer.replaceProperties(before + "${"+simpleKey+"}")); 142 } 143 144 public void testStringAfterProperty() 145 throws Exception 146 { 147 assertEquals("String after pattern", simple + after, 148 StringPropertyReplacer.replaceProperties("${"+simpleKey+"}" + after)); 149 } 150 151 public void testStringBeforeAfterProperty() 152 throws Exception 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 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 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 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 181 { 182 assertEquals("Dollar before pattern", "$" + simple, 183 StringPropertyReplacer.replaceProperties("$${"+simpleKey+"}")); 184 } 185 186 public void testSpaceBetweenDollarAndProperty() 187 throws Exception 188 { 189 assertEquals("Dollar before pattern", "$ {"+simpleKey+"}", 190 StringPropertyReplacer.replaceProperties("$ {"+simpleKey+"}")); 191 } 192 193 public void testPropertyDoesNotExist() 194 throws Exception 195 { 196 assertEquals("Property does not exist", "${"+doesNotExist+"}", 197 StringPropertyReplacer.replaceProperties("${"+doesNotExist+"}")); 198 } 199 200 public void testPathologicalProperties() 201 throws Exception 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 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 236 public void testServerFound() 237 { 238 } 239 240 } 241 242 | Popular Tags |