1 22 package org.jboss.test.jmx.compliance.objectname; 23 import javax.management.ObjectName ; 24 25 import junit.framework.Test; 26 import junit.framework.TestCase; 27 import junit.framework.TestSuite; 28 29 34 public class QuoteSUITE 35 extends TestSuite 36 { 37 private static final String EMPTY = ""; 38 private static final String WHITESPACE = " "; 39 private static final String DOMAIN = "domain"; 40 private static final String LETTER = "A"; 41 private static final String QUOTE = "\""; 42 private static final String ESCAPE = "\\"; 43 private static final String ASTERISK = "*"; 44 private static final String QUESTION = "?"; 45 private static final String NL = "\n"; 46 private static final String NEWLINE = ESCAPE + "n"; 47 private static final String COLON = ":"; 48 private static final String COMMA = ","; 49 private static final String EQUALS = "="; 50 private static final String KEY = "type"; 51 private static final String VALUE = "user"; 52 private static final String JMI = "JMImplementation"; 53 private static final String TYPE = "type"; 54 private static final String DELEGATE = "MBeanServerDelegate"; 55 56 public static void main(String [] args) 57 { 58 junit.textui.TestRunner.run(suite()); 59 } 60 61 public static Test suite() 62 { 63 TestSuite suite = new TestSuite("All Quote Tests"); 64 65 suite.addTest(new QuoteTEST(QUOTE, ESCAPE + QUOTE)); 67 suite.addTest(new QuoteTEST(ESCAPE, ESCAPE + ESCAPE)); 68 suite.addTest(new QuoteTEST(QUESTION, ESCAPE + QUESTION)); 69 suite.addTest(new QuoteTEST(ASTERISK, ESCAPE + ASTERISK)); 70 suite.addTest(new QuoteTEST(NL, NEWLINE)); 71 72 suite.addTest(new QuoteTEST(COLON, COLON)); 74 suite.addTest(new QuoteTEST(COMMA, COMMA)); 75 suite.addTest(new QuoteTEST(EQUALS, EQUALS)); 76 77 suite.addTest(new QuoteTEST(EMPTY, EMPTY)); 79 suite.addTest(new QuoteTEST(WHITESPACE, WHITESPACE)); 80 suite.addTest(new QuoteTEST(LETTER, LETTER)); 81 82 suite.addTest(new QuoteTEST(ASTERISK + COLON + KEY + EQUALS + VALUE + COMMA + ASTERISK, 84 ESCAPE + ASTERISK + COLON + KEY + EQUALS + VALUE + COMMA + ESCAPE + ASTERISK)); 85 86 suite.addTest(new QuoteTEST(JMI + COLON + TYPE + EQUALS + DELEGATE, 88 JMI + COLON + TYPE + EQUALS + DELEGATE)); 89 90 suite.addTest(new QuoteTEST(ASTERISK + COLON + ASTERISK, 92 ESCAPE + ASTERISK + COLON + ESCAPE + ASTERISK)); 93 94 suite.addTest(new UnquoteTEST(ESCAPE + QUOTE, QUOTE)); 96 suite.addTest(new UnquoteTEST(ESCAPE + ESCAPE, ESCAPE)); 97 suite.addTest(new UnquoteTEST(ESCAPE + QUESTION, QUESTION)); 98 suite.addTest(new UnquoteTEST(ESCAPE + ASTERISK, ASTERISK)); 99 100 suite.addTest(new UnquoteTEST(COLON, COLON)); 102 suite.addTest(new UnquoteTEST(COMMA, COMMA)); 103 suite.addTest(new UnquoteTEST(EQUALS, EQUALS)); 104 105 suite.addTest(new UnquoteTEST(EMPTY, EMPTY)); 107 suite.addTest(new UnquoteTEST(WHITESPACE, WHITESPACE)); 108 suite.addTest(new UnquoteTEST(LETTER, LETTER)); 109 110 suite.addTest(new UnquoteTEST(ESCAPE + ASTERISK + COLON + KEY + EQUALS + VALUE + COMMA + ESCAPE + ASTERISK, 112 ASTERISK + COLON + KEY + EQUALS + VALUE + COMMA + ASTERISK)); 113 114 suite.addTest(new UnquoteTEST(JMI + COLON + TYPE + EQUALS + DELEGATE, 116 JMI + COLON + TYPE + EQUALS + DELEGATE)); 117 118 suite.addTest(new UnquoteTEST(ESCAPE + ASTERISK + COLON + ESCAPE + ASTERISK, 120 ASTERISK + COLON + ASTERISK)); 121 122 suite.addTest(new UnquoteFailuresTEST(EMPTY)); 124 suite.addTest(new UnquoteFailuresTEST(LETTER + QUOTE + LETTER + QUOTE)); 125 suite.addTest(new UnquoteFailuresTEST(QUOTE + LETTER + QUOTE + LETTER)); 126 127 suite.addTest(new UnquoteFailuresTEST(QUOTE + LETTER)); 129 130 suite.addTest(new UnquoteFailuresTEST(QUOTE + QUOTE + QUOTE)); 132 suite.addTest(new UnquoteFailuresTEST(QUOTE + ESCAPE + QUOTE)); 133 suite.addTest(new UnquoteFailuresTEST(QUOTE + QUESTION + QUOTE)); 134 suite.addTest(new UnquoteFailuresTEST(QUOTE + ASTERISK + QUOTE)); 135 136 return suite; 137 } 138 139 public static class QuoteTEST 140 extends TestCase 141 { 142 private String original; 143 private String expectedResult; 144 145 public QuoteTEST(String original, String expectedResult) 146 { 147 super("testQuote"); 148 this.original = original; 149 this.expectedResult = QUOTE + expectedResult + QUOTE; 150 } 151 152 public void testQuote() 153 throws Exception 154 { 155 String quoted = ObjectName.quote(original); 156 assertTrue("The quoted string for " + original + " should be " + 157 expectedResult + " but got " + quoted, expectedResult.equals(quoted)); 158 159 String quoteUnquote = ObjectName.unquote(quoted); 160 assertTrue("quote/unquote should produce the original string " + 161 original + " but got " + quoteUnquote, 162 original.equals(quoteUnquote)); 163 164 new ObjectName (DOMAIN, KEY, quoted); 165 } 166 } 167 168 public static class UnquoteTEST 169 extends TestCase 170 { 171 private String original; 172 private String expectedResult; 173 174 public UnquoteTEST(String original, String expectedResult) 175 { 176 super("testUnquote"); 177 this.original = QUOTE + original + QUOTE; 178 this.expectedResult = expectedResult; 179 } 180 181 public void testUnquote() 182 throws Exception 183 { 184 String unquoted = ObjectName.unquote(original); 185 assertTrue("The unquoted string for " + original + " should be " + 186 expectedResult + " but got " + unquoted, expectedResult.equals(unquoted)); 187 } 188 } 189 190 public static class UnquoteFailuresTEST 191 extends TestCase 192 { 193 private String test; 194 195 public UnquoteFailuresTEST(String test) 196 { 197 super("testUnquoteFailures"); 198 this.test = test; 199 } 200 201 public void testUnquoteFailures() 202 throws Exception 203 { 204 boolean caught = false; 205 try 206 { 207 ObjectName.unquote(test); 208 } 209 catch (Exception e) 210 { 211 caught = true; 212 } 213 assertTrue("The value " + test + " should fail in unquote", caught); 214 } 215 } 216 } | Popular Tags |