0001: /*
0002: * Licensed to the Apache Software Foundation (ASF) under one or more
0003: * contributor license agreements. See the NOTICE file distributed with
0004: * this work for additional information regarding copyright ownership.
0005: * The ASF licenses this file to You under the Apache License, Version 2.0
0006: * (the "License"); you may not use this file except in compliance with
0007: * the License. You may obtain a copy of the License at
0008: *
0009: * http://www.apache.org/licenses/LICENSE-2.0
0010: *
0011: * Unless required by applicable law or agreed to in writing, software
0012: * distributed under the License is distributed on an "AS IS" BASIS,
0013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014: * See the License for the specific language governing permissions and
0015: * limitations under the License.
0016: */
0017: package org.apache.harmony.jndi.tests.javax.naming;
0018:
0019: import java.io.ByteArrayInputStream;
0020: import java.io.ByteArrayOutputStream;
0021: import java.io.ObjectInputStream;
0022: import java.io.ObjectOutputStream;
0023: import java.util.Enumeration;
0024: import java.util.Properties;
0025:
0026: import javax.naming.CompositeName;
0027: import javax.naming.CompoundName;
0028: import javax.naming.InvalidNameException;
0029: import javax.naming.Name;
0030:
0031: import junit.framework.AssertionFailedError;
0032: import junit.framework.TestCase;
0033:
0034: import org.apache.harmony.jndi.tests.javax.naming.util.Log;
0035:
0036: public class CompoundNameTest extends TestCase {
0037:
0038: private Properties props2;
0039:
0040: static Log log = new Log(CompoundNameTest.class);
0041:
0042: private final Properties props = new Properties();
0043:
0044: @Override
0045: protected void setUp() throws Exception {
0046: super .setUp();
0047: props.clear();
0048: props.put("jndi.syntax.direction", "left_to_right");
0049: props.put("jndi.syntax.separator", "/");
0050: props.put("jndi.syntax.escape", "\\");
0051: props.put("jndi.syntax.beginquote", "<");
0052: props.put("jndi.syntax.endquote", ">");
0053: props.put("jndi.syntax.beginquote2", "'");
0054: props.put("jndi.syntax.endquote2", "'");
0055: props.put("jndi.syntax.ignorecase", "false");
0056: props.put("jndi.syntax.trimblanks", "false");
0057: props.put("jndi.syntax.separator.ava", ",");
0058: props.put("jndi.syntax.separator.typeval", "=");
0059: props2 = (Properties) props.clone();
0060: }
0061:
0062: public void testConstructor_Simple() throws InvalidNameException {
0063: log.setMethod("testConstructor_Simple()");
0064: CompoundName name;
0065:
0066: name = new CompoundName("", props);
0067: assertNameEmpty(name);
0068: name = new CompoundName("/", props);
0069: assertNameEquals(name, "");
0070: name = new CompoundName("//", props);
0071: assertNameEquals(name, "", "");
0072: name = new CompoundName("///", props);
0073: assertNameEquals(name, "", "", "");
0074: name = new CompoundName("a", props);
0075: assertNameEquals(name, "a");
0076: name = new CompoundName("a/b", props);
0077:
0078: assertNameEquals(name, "a", "b");
0079: name = new CompoundName("a/b", props);
0080: assertNameEquals(name, "a", "b");
0081: }
0082:
0083: public void testConstructor_Null_String()
0084: throws InvalidNameException {
0085: log.setMethod("testConstructor_Null_String()");
0086:
0087: try {
0088: new CompoundName((String) null, props);
0089: fail("should be null pointer exception");
0090: } catch (NullPointerException e) {
0091: }
0092: }
0093:
0094: public void testConstructor_Null_Props()
0095: throws InvalidNameException {
0096: log.setMethod("testConstructor_Null_Props()");
0097:
0098: try {
0099: new CompoundName("abc", null);
0100: fail("should be null pointer exception");
0101: } catch (NullPointerException e) {
0102: }
0103: }
0104:
0105: public void testConstructor_WithProps_nothing()
0106: throws InvalidNameException {
0107: log.setMethod("testConstructor_WithProps_nothing()");
0108: CompoundName name;
0109: props.clear();
0110:
0111: name = new CompoundName("a/b/c", props);
0112: assertNameEquals(name, "a/b/c");
0113: }
0114:
0115: public void testConstructor_WithProps_D_NotFlat()
0116: throws InvalidNameException {
0117: log.setMethod("testConstructor_WithProps_D_NotFlat()");
0118: props.clear();
0119: props.put("jndi.syntax.direction", "left_to_right");
0120:
0121: try {
0122: new CompoundName("a/b/c", props);
0123: fail("has direction but no separator, should throw IllegalArgumentException");
0124: } catch (IllegalArgumentException e) {
0125: }
0126: }
0127:
0128: public void testConstructor_WithProps_D_Flat()
0129: throws InvalidNameException {
0130: log.setMethod("testConstructor_WithProps_D_Flat()");
0131: CompoundName name;
0132: props.clear();
0133: props.put("jndi.syntax.direction", "flat");
0134:
0135: name = new CompoundName("a/b/c", props);
0136: assertNameEquals(name, "a/b/c");
0137: }
0138:
0139: public void testConstructor_WithProps_DS()
0140: throws InvalidNameException {
0141: log.setMethod("testConstructor_WithProps_DS()");
0142: CompoundName name;
0143: props.clear();
0144: props.put("jndi.syntax.direction", "left_to_right");
0145: props.put("jndi.syntax.separator", "/");
0146:
0147: name = new CompoundName("a\\/b/c", props);
0148: assertNameEquals(name, "a\\", "b", "c");
0149:
0150: name = new CompoundName("'a/a'/b/c", props);
0151: assertNameEquals(name, "'a", "a'", "b", "c");
0152:
0153: name = new CompoundName("\"a/a\"/b/c", props);
0154: assertNameEquals(name, "\"a", "a\"", "b", "c");
0155:
0156: name = new CompoundName("<a/a>/b/c", props);
0157: assertNameEquals(name, "<a", "a>", "b", "c");
0158:
0159: name = new CompoundName("a/b/c", props);
0160: assertFalse(name.equals(new CompoundName("A/B/C", props)));
0161: assertFalse(name.equals(new CompoundName(" a / b / c ", props)));
0162: }
0163:
0164: public void testConstructor_WithProps_DS2()
0165: throws InvalidNameException {
0166: log.setMethod("testConstructor_WithProps_DS2()");
0167: props.clear();
0168: props.put("jndi.syntax.direction", "left_to_right");
0169: props.put("jndi.syntax.separator2", "/");
0170: try {
0171: new CompoundName("a/b/c", props);
0172: fail("IllegalArgumentException expected");
0173: } catch (IllegalArgumentException e) {
0174: }
0175: }
0176:
0177: public void testConstructor_WithProps_DSS2()
0178: throws InvalidNameException {
0179: log.setMethod("testConstructor_WithProps_DSS2()");
0180: CompoundName name;
0181: props.clear();
0182: props.put("jndi.syntax.direction", "left_to_right");
0183: props.put("jndi.syntax.separator", "/");
0184: props.put("jndi.syntax.separator2", ":");
0185: name = new CompoundName("a:b/c:d", props);
0186: assertNameEquals(name, "a", "b", "c", "d");
0187: assertEquals("a/b/c/d", name.toString());
0188: }
0189:
0190: public void testConstructor_WithProps_DSS2E()
0191: throws InvalidNameException {
0192: log.setMethod("testConstructor_WithProps_DSS2E()");
0193: CompoundName name;
0194: props.clear();
0195: props.put("jndi.syntax.direction", "left_to_right");
0196: props.put("jndi.syntax.separator", "/");
0197: props.put("jndi.syntax.separator2", ":");
0198: props.put("jndi.syntax.escape", "\\");
0199:
0200: name = new CompoundName("a\\:b\\/c:d", props);
0201: assertNameEquals(name, "a:b/c", "d");
0202: assertEquals("a\\:b\\/c/d", name.toString());
0203: }
0204:
0205: public void testConstructor_WithProps_DSE()
0206: throws InvalidNameException {
0207: log.setMethod("testConstructor_WithProps_DSE()");
0208: CompoundName name;
0209: props.clear();
0210: props.put("jndi.syntax.direction", "left_to_right");
0211: props.put("jndi.syntax.separator", "/");
0212: props.put("jndi.syntax.escape", "\\");
0213:
0214: name = new CompoundName("a\\/a/b/c", props);
0215: assertNameEquals(name, "a/a", "b", "c");
0216:
0217: name = new CompoundName("a\\/a/\\b/c", props);
0218: assertNameEquals(name, "a/a", "\\b", "c");
0219:
0220: name = new CompoundName("\\'a/b/c", props);
0221: assertNameEquals(name, "\\'a", "b", "c");
0222: }
0223:
0224: public void testConstructor_WithProps_DSEQ_Bq()
0225: throws InvalidNameException {
0226: log.setMethod("testConstructor_WithProps_DSEQ_Bq()");
0227: CompoundName name;
0228: props.clear();
0229: props.put("jndi.syntax.direction", "left_to_right");
0230: props.put("jndi.syntax.separator", "/");
0231: props.put("jndi.syntax.escape", "\\");
0232: props.put("jndi.syntax.beginquote", "'");
0233:
0234: name = new CompoundName("'a/a'/b/c", props);
0235: assertNameEquals(name, "a/a", "b", "c");
0236:
0237: name = new CompoundName("a'a/a'a/b/c", props);
0238: assertNameEquals(name, "a'a", "a'a", "b", "c");
0239:
0240: name = new CompoundName("\\'a/b/c", props);
0241: assertNameEquals(name, "'a", "b", "c");
0242:
0243: assertInvalidName("'a/a'a/b/c", props);
0244: }
0245:
0246: public void testConstructor_WithProps_DSEQ_BqEq()
0247: throws InvalidNameException {
0248: log.setMethod("testConstructor_WithProps_DSEQ_BqEq()");
0249: CompoundName name;
0250: props.clear();
0251: props.put("jndi.syntax.direction", "left_to_right");
0252: props.put("jndi.syntax.separator", "/");
0253: props.put("jndi.syntax.escape", "\\");
0254: props.put("jndi.syntax.beginquote", "<");
0255: props.put("jndi.syntax.endquote", ">");
0256:
0257: name = new CompoundName("<a/a>/b/c", props);
0258: assertNameEquals(name, "a/a", "b", "c");
0259:
0260: name = new CompoundName("a<a/a>a/b/c", props);
0261: assertNameEquals(name, "a<a", "a>a", "b", "c");
0262:
0263: name = new CompoundName("\\<a/a>/b/c", props);
0264: assertNameEquals(name, "<a", "a>", "b", "c");
0265:
0266: name = new CompoundName("<a/a\\>>/b/c", props);
0267: assertNameEquals(name, "a/a>", "b", "c");
0268:
0269: assertInvalidName("<a/a>a/b/c", props);
0270:
0271: name = new CompoundName("<a\\>a>", props);
0272: assertNameEquals(name, "a>a");
0273: assertEquals("a>a", name.toString());
0274:
0275: name = new CompoundName("<a\\<a>", props);
0276: assertNameEquals(name, "a\\<a");
0277: assertEquals(new CompoundName(name.toString(), props), name);
0278: assertEquals("a\\\\<a", name.toString());
0279:
0280: name = new CompoundName("<a\\/a>", props);
0281: assertNameEquals(name, "a\\/a");
0282: assertEquals("<a\\/a>", name.toString());
0283: }
0284:
0285: public void testConstructor_WithProps_DSEQ_Eq()
0286: throws InvalidNameException {
0287: log.setMethod("testConstructor_WithProps_DSEQ_Eq()");
0288: CompoundName name;
0289: props.clear();
0290: props.put("jndi.syntax.direction", "left_to_right");
0291: props.put("jndi.syntax.separator", "/");
0292: props.put("jndi.syntax.escape", "\\");
0293: props.put("jndi.syntax.endquote", ">");
0294:
0295: name = new CompoundName("<a/a>/b/c", props);
0296: assertNameEquals(name, "<a", "a>", "b", "c");
0297:
0298: name = new CompoundName(">a/a>/b/c", props);
0299: assertNameEquals(name, "a/a", "b", "c");
0300: assertEquals(">a/a>/b/c", name.toString());
0301: }
0302:
0303: public void testConstructor_WithProps_DSEQ_Bq2()
0304: throws InvalidNameException {
0305: log.setMethod("testConstructor_WithProps_DSEQ_Bq2()");
0306: CompoundName name;
0307: props.clear();
0308: props.put("jndi.syntax.direction", "left_to_right");
0309: props.put("jndi.syntax.separator", "/");
0310: props.put("jndi.syntax.escape", "\\");
0311: props.put("jndi.syntax.beginquote2", "'");
0312:
0313: name = new CompoundName("'a/a'/b/c", props);
0314: assertNameEquals(name, "a/a", "b", "c");
0315:
0316: name = new CompoundName("a'a/a'a/b/c", props);
0317: assertNameEquals(name, "a'a", "a'a", "b", "c");
0318:
0319: name = new CompoundName("\\'a/b/c", props);
0320: assertNameEquals(name, "'a", "b", "c");
0321:
0322: assertInvalidName("'a/a'a/b/c", props);
0323: }
0324:
0325: public void testConstructor_WithProps_DSEQ_Bq2Eq2()
0326: throws InvalidNameException {
0327: log.setMethod("testConstructor_WithProps_DSEQ_Bq2Eq2()");
0328: CompoundName name;
0329: props.clear();
0330: props.put("jndi.syntax.direction", "left_to_right");
0331: props.put("jndi.syntax.separator", "/");
0332: props.put("jndi.syntax.escape", "\\");
0333: props.put("jndi.syntax.beginquote2", "<");
0334: props.put("jndi.syntax.endquote2", ">");
0335:
0336: name = new CompoundName("<a/a>/b/c", props);
0337: assertNameEquals(name, "a/a", "b", "c");
0338:
0339: name = new CompoundName("a<a/a>a/b/c", props);
0340: assertNameEquals(name, "a<a", "a>a", "b", "c");
0341:
0342: name = new CompoundName("\\<a/a>/b/c", props);
0343: assertNameEquals(name, "<a", "a>", "b", "c");
0344:
0345: name = new CompoundName("<a/a\\>>/b/c", props);
0346: assertNameEquals(name, "a/a>", "b", "c");
0347:
0348: assertInvalidName("<a/a>a/b/c", props);
0349:
0350: name = new CompoundName("<a\\>a>", props);
0351: assertNameEquals(name, "a>a");
0352: assertEquals("a>a", name.toString());
0353:
0354: name = new CompoundName("<a\\<a>", props);
0355: assertNameEquals(name, "a\\<a");
0356: assertEquals(new CompoundName(name.toString(), props), name);
0357: assertEquals("a\\\\<a", name.toString());
0358:
0359: name = new CompoundName("<a\\/a>", props);
0360: assertNameEquals(name, "a\\/a");
0361: assertEquals(new CompoundName(name.toString(), props), name);
0362: assertEquals("<a\\/a>", name.toString());
0363: }
0364:
0365: public void testConstructor_WithProps_DSEQ_Eq2()
0366: throws InvalidNameException {
0367: log.setMethod("testConstructor_WithProps_DSEQ_Eq2()");
0368: CompoundName name;
0369: props.clear();
0370: props.put("jndi.syntax.direction", "left_to_right");
0371: props.put("jndi.syntax.separator", "/");
0372: props.put("jndi.syntax.escape", "\\");
0373: props.put("jndi.syntax.endquote2", ">");
0374:
0375: name = new CompoundName("<a/a>/b/c", props);
0376: assertNameEquals(name, "<a", "a>", "b", "c");
0377:
0378: name = new CompoundName(">a/a>/b/c", props);
0379: assertNameEquals(name, "a/a", "b", "c");
0380: assertEquals(new CompoundName(name.toString(), props), name);
0381: }
0382:
0383: public void testConstructor_WithProps_DSEQ_DefaultIgnoreCase()
0384: throws InvalidNameException {
0385: log
0386: .setMethod("testConstructor_WithProps_DSEQ_DefaultIgnoreCase()");
0387: CompoundName name;
0388: props.clear();
0389: props.put("jndi.syntax.direction", "left_to_right");
0390: props.put("jndi.syntax.separator", "/");
0391: props.put("jndi.syntax.escape", "\\");
0392: props.put("jndi.syntax.beginquote", "<");
0393: props.put("jndi.syntax.endquote", ">");
0394: props.put("jndi.syntax.beginquote2", "'");
0395: props.put("jndi.syntax.endquote2", "'");
0396:
0397: name = new CompoundName("a/b/c", props);
0398: assertFalse(name.equals(new CompoundName("A/B/C/", props)));
0399: }
0400:
0401: public void testConstructor_WithProps_DSEQ_DefaultTrimBlanks()
0402: throws InvalidNameException {
0403: log
0404: .setMethod("testConstructor_WithProps_DSEQ_DefaultTrimBlanks()");
0405: CompoundName name;
0406: props.clear();
0407: props.put("jndi.syntax.direction", "left_to_right");
0408: props.put("jndi.syntax.separator", "/");
0409: props.put("jndi.syntax.escape", "\\");
0410: props.put("jndi.syntax.beginquote", "<");
0411: props.put("jndi.syntax.endquote", ">");
0412: props.put("jndi.syntax.beginquote2", "'");
0413: props.put("jndi.syntax.endquote2", "'");
0414:
0415: name = new CompoundName("a/b/c", props);
0416: assertFalse(name.equals(new CompoundName(" a / b / c ", props)));
0417: }
0418:
0419: public void testConstructor_WithProps_DSEQAv()
0420: throws InvalidNameException {
0421: log.setMethod("testConstructor_WithProps_DSEQAv()");
0422: CompoundName name;
0423: props.clear();
0424: props.put("jndi.syntax.direction", "left_to_right");
0425: props.put("jndi.syntax.separator", "/");
0426: props.put("jndi.syntax.escape", "\\");
0427: props.put("jndi.syntax.beginquote", "<");
0428: props.put("jndi.syntax.endquote", ">");
0429: props.put("jndi.syntax.beginquote2", "'");
0430: props.put("jndi.syntax.endquote2", "'");
0431: props.put("jndi.syntax.separator.ava", ",");
0432:
0433: assertInvalidName("'a','b'/'c'", props);
0434: assertInvalidName("'a', 'b'/'c'", props);
0435: assertInvalidName("'a', 'b' /'c'", props);
0436: assertInvalidName("'a', 'b' / 'c'", props);
0437: assertInvalidName("'a'\\,'b'/'c'", props);
0438: name = new CompoundName(",/a", props);
0439: assertNameEquals(name, ",", "a");
0440: name = new CompoundName("a/,", props);
0441: assertNameEquals(name, "a", ",");
0442: }
0443:
0444: public void testConstructor_WithProps_DSEQTv()
0445: throws InvalidNameException {
0446: log.setMethod("testConstructor_WithProps_DSEQTv()");
0447: CompoundName name;
0448: props.clear();
0449: props.put("jndi.syntax.direction", "left_to_right");
0450: props.put("jndi.syntax.separator", "/");
0451: props.put("jndi.syntax.escape", "\\");
0452: props.put("jndi.syntax.beginquote", "<");
0453: props.put("jndi.syntax.endquote", ">");
0454: props.put("jndi.syntax.beginquote2", "'");
0455: props.put("jndi.syntax.endquote2", "'");
0456: props.put("jndi.syntax.separator.typeval", "=");
0457:
0458: assertInvalidName("'a'=b", props);
0459: name = new CompoundName("a='b/b'/c", props);
0460: assertNameEquals(name, "a='b/b'", "c");
0461: name = new CompoundName("a=\\'b/b'/c", props);
0462: assertNameEquals(name, "a='b", "b'", "c");
0463: name = new CompoundName("a\\='b/b'/c", props);
0464: assertNameEquals(name, "a\\='b/b'", "c");
0465: assertInvalidName("'a/a'=b/c", props);
0466: name = new CompoundName("\\'a/a'=b/c", props);
0467: assertNameEquals(name, "'a", "a'=b", "c");
0468: assertInvalidName("'a/a\\'=b/c", props);
0469: name = new CompoundName("a=b,c=d/e", props);
0470: assertNameEquals(name, "a=b,c=d", "e");
0471: }
0472:
0473: public void testConstructor_WithProps_DSEQAvTv()
0474: throws InvalidNameException {
0475: log.setMethod("testConstructor_WithProps_DSEQAvTv()");
0476: CompoundName name, name2;
0477: props.clear();
0478: props.put("jndi.syntax.direction", "left_to_right");
0479: props.put("jndi.syntax.separator", "/");
0480: props.put("jndi.syntax.escape", "\\");
0481: props.put("jndi.syntax.beginquote", "<");
0482: props.put("jndi.syntax.endquote", ">");
0483: props.put("jndi.syntax.beginquote2", "'");
0484: props.put("jndi.syntax.endquote2", "'");
0485: props.put("jndi.syntax.separator.ava", ",");
0486: props.put("jndi.syntax.separator.typeval", "=");
0487:
0488: name = new CompoundName("a='b'/c", props);
0489: assertNameEquals(name, "a='b'", "c");
0490: assertInvalidName("a='b',/c", props);
0491: assertInvalidName("a='b',c/d", props);
0492: assertInvalidName("a='b',c=d/e", props);
0493: name = new CompoundName("a=<b/b>/abc", props);
0494: assertNameEquals(name, "a=<b/b>", "abc");
0495: name = new CompoundName("a=b='c'/d", props);
0496: assertNameEquals(name, "a=b='c'", "d");
0497: assertInvalidName("CN=<Ima Random>, O=HMY, C=UK", props);
0498: assertInvalidName("CN=<Ima Random, O=HMY, C=UK", props);
0499: name = new CompoundName("CN=<Ima Random>/O=HMY/C=UK", props);
0500: assertNameEquals(name, "CN=<Ima Random>", "O=HMY", "C=UK");
0501: assertInvalidName("CN=<Ima Random/O=HMY/C=UK", props);
0502: name = new CompoundName("a=b'b',c='d'/abc'", props);
0503: assertNameEquals(name, "a=b'b',c='d'", "abc'");
0504: assertInvalidName("a='b\\',c='d'/abc", props);
0505: assertInvalidName("a='b',/abc", props);
0506: assertInvalidName("a='b',abc/abc", props);
0507: assertInvalidName("'<a>'=b,c=d/abc", props);
0508: assertInvalidName("'a=b,c=d/abc", props);
0509: name = new CompoundName("a=,c=d/abc", props);
0510: assertNameEquals(name, "a=,c=d", "abc");
0511: name = new CompoundName("=b,c=d/abc", props);
0512: assertNameEquals(name, "=b,c=d", "abc");
0513: assertInvalidName("''=b,c=d/abc", props);
0514: assertInvalidName("a='b\\,b',c=d/abc", props);
0515: assertInvalidName("a\\=a='b',c=d/abc", props);
0516: name = new CompoundName(",,/,,", props);
0517: assertNameEquals(name, ",,", ",,");
0518: name = new CompoundName("a=/bc", props);
0519: assertNameEquals(name, "a=", "bc");
0520: name = new CompoundName("=b/bc", props);
0521: assertNameEquals(name, "=b", "bc");
0522: name = new CompoundName("=/bc", props);
0523: assertNameEquals(name, "=", "bc");
0524:
0525: // Does escape work for typeval?
0526: name = new CompoundName("a\\='b/c'/d", props);
0527: assertEquals("<a\\='b/c'>/d", name.toString());
0528: assertNameEquals(name, "a\\='b/c'", "d");
0529:
0530: name = new CompoundName("a=b, c=d/a=b, c=d", props);
0531: name2 = new CompoundName("a=b,c=d/a=b,c=d", props);
0532: assertFalse(name.equals(name2));
0533: props.put("jndi.syntax.trimblanks", "true");
0534: name = new CompoundName("a=b, c=d/a=b, c=d", props);
0535: name2 = new CompoundName("a=b,c=d/a=b,c=d", props);
0536: assertFalse(name.equals(name2));
0537:
0538: name = new CompoundName("a=b,c=d/a=b,c=d", props);
0539: name2 = new CompoundName("A=B,C=D/A=B,C=D", props);
0540: assertFalse(name.equals(name2));
0541: props.put("jndi.syntax.ignorecase", "true");
0542: name = new CompoundName("a=b,c=d/a=b,c=d", props);
0543: name2 = new CompoundName("A=B,C=D/A=B,C=D", props);
0544: assertTrue(name.equals(name2));
0545:
0546: }
0547:
0548: public void testConstructor_WithProps_DSEQAvTv_sameSE()
0549: throws InvalidNameException {
0550: log.setMethod("testConstructor_WithProps_DSEQAvTv_sameSE()");
0551: CompoundName name;
0552: props.clear();
0553: props.put("jndi.syntax.direction", "left_to_right");
0554: props.put("jndi.syntax.separator", "/");
0555: props.put("jndi.syntax.escape", "/");
0556: props.put("jndi.syntax.beginquote", "<");
0557: props.put("jndi.syntax.endquote", ">");
0558: props.put("jndi.syntax.beginquote2", "'");
0559: props.put("jndi.syntax.endquote2", "'");
0560: props.put("jndi.syntax.separator.ava", ",");
0561: props.put("jndi.syntax.separator.typeval", "=");
0562:
0563: name = new CompoundName("/", props);
0564: assertNameEquals(name, "");
0565: name = new CompoundName("//", props);
0566: assertNameEquals(name, "", "");
0567: name = new CompoundName("a/b/c", props);
0568: assertNameEquals(name, "a", "b", "c");
0569: name = new CompoundName("a//b/c", props);
0570: assertNameEquals(name, "a", "", "b", "c");
0571: }
0572:
0573: public void testConstructor_WithProps_DSEQAvTv_sameSQ()
0574: throws InvalidNameException {
0575: log.setMethod("testConstructor_WithProps_DSEQAvTv_sameSQ()");
0576: CompoundName name;
0577: props.clear();
0578: props.put("jndi.syntax.direction", "left_to_right");
0579: props.put("jndi.syntax.separator", "/");
0580: props.put("jndi.syntax.escape", "\\");
0581: props.put("jndi.syntax.beginquote", "<");
0582: props.put("jndi.syntax.endquote", ">");
0583: props.put("jndi.syntax.beginquote2", "/");
0584: props.put("jndi.syntax.endquote2", "/");
0585: props.put("jndi.syntax.separator.ava", ",");
0586: props.put("jndi.syntax.separator.typeval", "=");
0587:
0588: assertInvalidName("/", props);
0589: name = new CompoundName("//", props);
0590: assertNameEquals(name, "");
0591: name = new CompoundName("a/b/c", props);
0592: assertNameEquals(name, "a", "b", "c");
0593: name = new CompoundName("/a//b/c", props);
0594: assertNameEquals(name, "a", "b", "c");
0595: }
0596:
0597: public void testConstructor_WithProps_DSEQAvTv_sameEQ()
0598: throws InvalidNameException {
0599: log.setMethod("testConstructor_WithProps_DSEQAvTv_sameEQ()");
0600: CompoundName name;
0601: props.clear();
0602: props.put("jndi.syntax.direction", "left_to_right");
0603: props.put("jndi.syntax.separator", "/");
0604: props.put("jndi.syntax.escape", "\\");
0605: props.put("jndi.syntax.beginquote", "<");
0606: props.put("jndi.syntax.endquote", ">");
0607: props.put("jndi.syntax.beginquote2", "\\");
0608: props.put("jndi.syntax.endquote2", "\\");
0609: props.put("jndi.syntax.separator.ava", ",");
0610: props.put("jndi.syntax.separator.typeval", "=");
0611:
0612: assertInvalidName("\\", props);
0613: name = new CompoundName("\\\\", props);
0614: assertNameEquals(name, "");
0615: name = new CompoundName("\\asdf\\", props);
0616: assertNameEquals(name, "asdf");
0617: name = new CompoundName("\\asdf\\/asdf", props);
0618: assertNameEquals(name, "asdf", "asdf");
0619: }
0620:
0621: public void testConstructor_WithProps_DSEQAvTv_sameSAv()
0622: throws InvalidNameException {
0623: log.setMethod("testConstructor_WithProps_DSEQAvTv_sameSAv()");
0624: CompoundName name;
0625: props.clear();
0626: props.put("jndi.syntax.direction", "left_to_right");
0627: props.put("jndi.syntax.separator", "/");
0628: props.put("jndi.syntax.escape", "\\");
0629: props.put("jndi.syntax.beginquote", "<");
0630: props.put("jndi.syntax.endquote", ">");
0631: props.put("jndi.syntax.beginquote2", "'");
0632: props.put("jndi.syntax.endquote2", "'");
0633: props.put("jndi.syntax.separator.ava", "/");
0634: props.put("jndi.syntax.separator.typeval", "=");
0635:
0636: name = new CompoundName("//", props);
0637: assertNameEquals(name, "", "");
0638: name = new CompoundName("a/b/c", props);
0639: assertNameEquals(name, "a", "b", "c");
0640: name = new CompoundName("a=b/c=d", props);
0641: assertNameEquals(name, "a=b", "c=d");
0642: }
0643:
0644: public void testConstructor_WithProps_DSEQAvTv_sameSTv()
0645: throws InvalidNameException {
0646: log.setMethod("testConstructor_WithProps_DSEQAvTv_sameSTv()");
0647: CompoundName name;
0648: props.clear();
0649: props.put("jndi.syntax.direction", "left_to_right");
0650: props.put("jndi.syntax.separator", "/");
0651: props.put("jndi.syntax.escape", "\\");
0652: props.put("jndi.syntax.beginquote", "<");
0653: props.put("jndi.syntax.endquote", ">");
0654: props.put("jndi.syntax.beginquote2", "'");
0655: props.put("jndi.syntax.endquote2", "'");
0656: props.put("jndi.syntax.separator.ava", ",");
0657: props.put("jndi.syntax.separator.typeval", "/");
0658:
0659: name = new CompoundName("//", props);
0660: assertNameEquals(name, "", "");
0661: name = new CompoundName("a/b/c", props);
0662: assertNameEquals(name, "a", "b", "c");
0663: name = new CompoundName("a/b,c/d", props);
0664: assertNameEquals(name, "a", "b,c", "d");
0665: }
0666:
0667: public void testConstructor_WithProps_DSQ()
0668: throws InvalidNameException {
0669: log.setMethod("testConstructor_WithProps_DSQ()");
0670: props.clear();
0671: props.put("jndi.syntax.direction", "left_to_right");
0672: props.put("jndi.syntax.separator", "/");
0673: props.put("jndi.syntax.beginquote", "<");
0674: props.put("jndi.syntax.endquote", ">");
0675: props.put("jndi.syntax.beginquote2", "'");
0676: props.put("jndi.syntax.endquote2", "'");
0677: props.put("jndi.syntax.ignorecase", "false");
0678: props.put("jndi.syntax.trimblanks", "false");
0679: props.put("jndi.syntax.separator.ava", ",");
0680: props.put("jndi.syntax.separator.typeval", "=");
0681:
0682: testBehavior("'a<b>c'", props);
0683: }
0684:
0685: public void testConstructor_WithIrregularProps()
0686: throws InvalidNameException {
0687: log.setMethod("testConstructor_WithIrregularProps()");
0688: try {
0689: new CompoundName("name", new UncloneableProperties());
0690: } catch (UnsupportedOperationException e) {
0691: fail("unexpected UnsupportedOperationException");
0692: }
0693: }
0694:
0695: public void testConstructor_Advanced() throws InvalidNameException {
0696: log.setMethod("testConstructor_Advanced()");
0697:
0698: assertNameEmpty(new CompoundName("", props));
0699: assertNameEquals(new CompoundName("/", props), "");
0700: assertNameEquals(new CompoundName("//", props), "", "");
0701: assertNameEquals(new CompoundName("/a/", props), "", "a", "");
0702: assertNameEquals(new CompoundName("//a/", props), "", "", "a",
0703: "");
0704: assertNameEquals(new CompoundName("a/b/c/", props), "a", "b",
0705: "c", "");
0706: assertNameEquals(new CompoundName("/a/b/c", props), "", "a",
0707: "b", "c");
0708:
0709: assertNameEquals(new CompoundName("a/\\/b/c", props), "a",
0710: "/b", "c");
0711: assertNameEquals(new CompoundName("a/\\b/c", props), "a",
0712: "\\b", "c");
0713: assertInvalidName("a/b\\", props);
0714:
0715: assertNameEquals(new CompoundName("a/<b/>/c", props), "a",
0716: "b/", "c");
0717: assertNameEquals(new CompoundName("a/b<b/>b/c", props), "a",
0718: "b<b", ">b", "c");
0719: assertNameEquals(new CompoundName("a/<b</>/c", props), "a",
0720: "b</", "c");
0721: assertNameEquals(new CompoundName("a/\\/b>>>/c", props), "a",
0722: "/b>>>", "c");
0723: assertNameEquals(new CompoundName("a/</b\\a\\>b>/c", props),
0724: "a", "/b\\a>b", "c");
0725: assertInvalidName("a/<b/>b/c", props);
0726: assertInvalidName("a/</b>>/c", props);
0727:
0728: assertNameEquals(new CompoundName("a/'b/'/c", props), "a",
0729: "b/", "c");
0730: assertNameEquals(new CompoundName("a/'/b\\a\\'b'/c", props),
0731: "a", "/b\\a'b", "c");
0732: assertInvalidName("a/b'b/'b/c", props);
0733: assertInvalidName("a/'b/'b/c", props);
0734: }
0735:
0736: public void testConstructor_MultiChar_Separator()
0737: throws InvalidNameException {
0738: log.setMethod("testConstructor_MultiChar_Separator()");
0739: CompoundName name;
0740: props.clear();
0741: props.put("jndi.syntax.direction", "left_to_right");
0742: props.put("jndi.syntax.separator", "//");
0743: props.put("jndi.syntax.escape", "\\");
0744: props.put("jndi.syntax.beginquote", "<");
0745: props.put("jndi.syntax.endquote", ">");
0746: props.put("jndi.syntax.beginquote2", "'");
0747: props.put("jndi.syntax.endquote2", "'");
0748: props.put("jndi.syntax.separator.ava", ",");
0749: props.put("jndi.syntax.separator.typeval", "=");
0750:
0751: name = new CompoundName("/", props);
0752: assertNameEquals(name, "/");
0753: name = new CompoundName("//", props);
0754: assertNameEquals(name, "");
0755: name = new CompoundName("///", props);
0756: assertNameEquals(name, "", "/");
0757: name = new CompoundName("////", props);
0758: assertNameEquals(name, "", "");
0759: }
0760:
0761: public void testConstructor_MultiChar_Escape()
0762: throws InvalidNameException {
0763: log.setMethod("testConstructor_MultiChar_Escape()");
0764: CompoundName name;
0765: props.clear();
0766: props.put("jndi.syntax.direction", "left_to_right");
0767: props.put("jndi.syntax.separator", "/");
0768: props.put("jndi.syntax.escape", "@@");
0769: props.put("jndi.syntax.beginquote", "<");
0770: props.put("jndi.syntax.endquote", ">");
0771: props.put("jndi.syntax.beginquote2", "'");
0772: props.put("jndi.syntax.endquote2", "'");
0773: props.put("jndi.syntax.separator.ava", ",");
0774: props.put("jndi.syntax.separator.typeval", "=");
0775:
0776: name = new CompoundName("a@/b", props);
0777: assertNameEquals(name, "a@", "b");
0778: name = new CompoundName("a@@/b", props);
0779: assertNameEquals(name, "a/b");
0780: name = new CompoundName("a@@@/b", props);
0781: assertNameEquals(name, "a@/b");
0782: name = new CompoundName("a@@@@/b", props);
0783: assertNameEquals(name, "a@@", "b");
0784: /*
0785: * IGNORE ODD CASE name = new CompoundName("a@@@@@/b", props);
0786: * assertNameEquals(name, "a@/b");
0787: */
0788: }
0789:
0790: public void testConstructor_MultiChar_Escape_Advanced()
0791: throws InvalidNameException {
0792: log.setMethod("testConstructor_MultiChar_Escape_Advanced()");
0793: CompoundName name;
0794: props.clear();
0795: props.put("jndi.syntax.direction", "left_to_right");
0796: props.put("jndi.syntax.separator", "//");
0797: props.put("jndi.syntax.escape", "abc");
0798: props.put("jndi.syntax.beginquote", "<<");
0799: props.put("jndi.syntax.endquote", ">>");
0800: props.put("jndi.syntax.beginquote2", "'");
0801: props.put("jndi.syntax.endquote2", "'");
0802: props.put("jndi.syntax.separator.ava", ",");
0803: props.put("jndi.syntax.separator.typeval", "=");
0804:
0805: name = new CompoundName("abca", props);
0806: assertNameEquals(name, "abca");
0807: name = new CompoundName("abcb", props);
0808: assertNameEquals(name, "abcb");
0809: name = new CompoundName("abcab", props);
0810: assertNameEquals(name, "abcab");
0811: name = new CompoundName("abcabc", props);
0812: assertNameEquals(name, "abc");
0813: assertInvalidName("xyzabc", props);
0814: assertInvalidName("<<abc>>", props);
0815: name = new CompoundName("abc//xyz", props);
0816: assertNameEquals(name, "//xyz");
0817: /*
0818: * IGNORE ODD CASE name = new CompoundName("abc///xyz", props);
0819: * assertNameEquals(name, "/", "xyz");
0820: */
0821: /*
0822: * IGNORE ODD CASE name = new CompoundName("<<abc>>>", props);
0823: * assertNameEquals(name, ">");
0824: */
0825: /*
0826: * IGNORE ODD CASE assertInvalidName("<<abc>>>>", props);
0827: */
0828: }
0829:
0830: public void testConstructor_MultiChar_Quote1()
0831: throws InvalidNameException {
0832: log.setMethod("testConstructor_MultiChar_Quote1()");
0833: CompoundName name;
0834: props.clear();
0835: props.put("jndi.syntax.direction", "left_to_right");
0836: props.put("jndi.syntax.separator", "/");
0837: props.put("jndi.syntax.escape", "\\");
0838: props.put("jndi.syntax.beginquote", "<<");
0839: props.put("jndi.syntax.endquote", ">>");
0840: props.put("jndi.syntax.beginquote2", "'");
0841: props.put("jndi.syntax.endquote2", "'");
0842: props.put("jndi.syntax.separator.ava", ",");
0843: props.put("jndi.syntax.separator.typeval", "=");
0844:
0845: name = new CompoundName("<a/b>", props);
0846: assertNameEquals(name, "<a", "b>");
0847: assertInvalidName("<<a/b>", props);
0848: name = new CompoundName("<<a/b>>", props);
0849: assertNameEquals(name, "a/b");
0850: name = new CompoundName("<<<a/b>>", props);
0851: assertNameEquals(name, "<a/b");
0852: assertInvalidName("<<a/b>>>", props);
0853: }
0854:
0855: public void testConstructor_MultiChar_Quote2()
0856: throws InvalidNameException {
0857: log.setMethod("testConstructor_MultiChar_Quote2()");
0858: CompoundName name;
0859: props.clear();
0860: props.put("jndi.syntax.direction", "left_to_right");
0861: props.put("jndi.syntax.separator", "/");
0862: props.put("jndi.syntax.escape", "\\");
0863: props.put("jndi.syntax.beginquote", "<");
0864: props.put("jndi.syntax.endquote", ">");
0865: props.put("jndi.syntax.beginquote2", "''");
0866: props.put("jndi.syntax.separator.ava", ",");
0867: props.put("jndi.syntax.separator.typeval", "=");
0868:
0869: name = new CompoundName("'a/b'", props);
0870: assertNameEquals(name, "'a", "b'");
0871: assertInvalidName("''a/b'", props);
0872: name = new CompoundName("''a/b''", props);
0873: assertNameEquals(name, "a/b");
0874: name = new CompoundName("'''a/b''", props);
0875: assertNameEquals(name, "'a/b");
0876: assertInvalidName("''a/b'''", props);
0877: }
0878:
0879: public void testConstructor_MultiChar_Typeval()
0880: throws InvalidNameException {
0881: log.setMethod("testConstructor_MultiChar_Typeval()");
0882: CompoundName name;
0883: props.clear();
0884: props.put("jndi.syntax.direction", "left_to_right");
0885: props.put("jndi.syntax.separator", "/");
0886: props.put("jndi.syntax.escape", "\\");
0887: props.put("jndi.syntax.beginquote", "<");
0888: props.put("jndi.syntax.endquote", ">");
0889: props.put("jndi.syntax.beginquote2", "'");
0890: props.put("jndi.syntax.endquote2", "'");
0891: props.put("jndi.syntax.separator.ava", ",");
0892: props.put("jndi.syntax.separator.typeval", "==");
0893:
0894: name = new CompoundName("a='b/c'/d", props);
0895: assertNameEquals(name, "a='b", "c'", "d");
0896: name = new CompoundName("a=='b/c'/d", props);
0897: assertNameEquals(name, "a=='b/c'", "d");
0898: /*
0899: * IGNORE ODD CASE name = new CompoundName("a==='b/c'/d", props);
0900: * assertNameEquals(name, "a==='b/c'", "d");
0901: */
0902: }
0903:
0904: public void testGetAll() throws InvalidNameException {
0905: log.setMethod("testGetAll()");
0906: CompoundName name;
0907: Enumeration<?> enumeration;
0908:
0909: // has more than one elements
0910: name = new CompoundName("a/b/c", props);
0911: enumeration = name.getAll();
0912: assertTrue(enumeration.hasMoreElements());
0913: assertEquals("a", enumeration.nextElement());
0914: assertTrue(enumeration.hasMoreElements());
0915: assertEquals("b", enumeration.nextElement());
0916: assertTrue(enumeration.hasMoreElements());
0917: assertEquals("c", enumeration.nextElement());
0918: assertFalse(enumeration.hasMoreElements());
0919:
0920: // has no elements
0921: name = new CompoundName("", props);
0922: enumeration = name.getAll();
0923: assertFalse(enumeration.hasMoreElements());
0924: }
0925:
0926: public void testGet() throws InvalidNameException {
0927: log.setMethod("testGet()");
0928: CompoundName name;
0929:
0930: // has more than one elements
0931: name = new CompoundName("a/b/c", props);
0932: assertEquals("a", name.get(0));
0933: assertEquals("b", name.get(1));
0934: assertEquals("c", name.get(2));
0935: try {
0936: name.get(-1);
0937: fail();
0938: } catch (ArrayIndexOutOfBoundsException e) {
0939: }
0940: try {
0941: name.get(3);
0942: fail();
0943: } catch (ArrayIndexOutOfBoundsException e) {
0944: }
0945:
0946: // has no elements
0947: name = new CompoundName("", props);
0948: try {
0949: name.get(0);
0950: fail();
0951: } catch (ArrayIndexOutOfBoundsException e) {
0952: }
0953: }
0954:
0955: public void testGetPrefix() throws InvalidNameException {
0956: log.setMethod("testGetPrefix()");
0957: CompoundName name;
0958:
0959: // has more than one elements
0960: name = new CompoundName("a/b/c", props);
0961: assertNameEmpty(name.getPrefix(0));
0962: assertNameEquals(name.getPrefix(1), "a");
0963: assertNameEquals(name.getPrefix(2), "a", "b");
0964: assertNameEquals(name.getPrefix(3), "a", "b", "c");
0965: try {
0966: name.getPrefix(-1);
0967: fail();
0968: } catch (ArrayIndexOutOfBoundsException e) {
0969: }
0970: try {
0971: name.getPrefix(4);
0972: fail();
0973: } catch (ArrayIndexOutOfBoundsException e) {
0974: }
0975:
0976: // has no elements
0977: name = new CompoundName("", props);
0978: assertNameEmpty(name.getPrefix(0));
0979: try {
0980: name.getPrefix(-1);
0981: fail();
0982: } catch (ArrayIndexOutOfBoundsException e) {
0983: }
0984: try {
0985: name.getPrefix(1);
0986: fail();
0987: } catch (ArrayIndexOutOfBoundsException e) {
0988: }
0989: }
0990:
0991: public void testGetSuffix() throws InvalidNameException {
0992: log.setMethod("testGetSuffix()");
0993: CompoundName name;
0994:
0995: // has more than one elements
0996: name = new CompoundName("a/b/c", props);
0997: assertNameEquals(name.getSuffix(0), "a", "b", "c");
0998: assertNameEquals(name.getSuffix(1), "b", "c");
0999: assertNameEquals(name.getSuffix(2), "c");
1000: // assertNameEmpty(name.getSuffix(3)); // worth debate
1001: try {
1002: name.getPrefix(-1);
1003: fail();
1004: } catch (ArrayIndexOutOfBoundsException e) {
1005: }
1006: try {
1007: name.getPrefix(4);
1008: fail();
1009: } catch (ArrayIndexOutOfBoundsException e) {
1010: }
1011:
1012: // has no elements
1013: name = new CompoundName("", props);
1014: assertNameEmpty(name.getPrefix(0));
1015: try {
1016: name.getPrefix(-1);
1017: fail();
1018: } catch (ArrayIndexOutOfBoundsException e) {
1019: }
1020: try {
1021: name.getPrefix(1);
1022: fail();
1023: } catch (ArrayIndexOutOfBoundsException e) {
1024: }
1025: }
1026:
1027: public void testAddAll() throws InvalidNameException {
1028: log.setMethod("testAddAll()");
1029: CompoundName name;
1030:
1031: name = new CompoundName("", props);
1032: assertNameEmpty(name);
1033: name.addAll(new CompoundName("a", props));
1034: assertNameEquals(name, "a");
1035: name.addAll(new CompoundName("b/c", props));
1036: assertNameEquals(name, "a", "b", "c");
1037: }
1038:
1039: public void testAddAll_NotCompoundName()
1040: throws InvalidNameException {
1041: log.setMethod("testAddAll_NotCompoundName()");
1042: CompoundName name;
1043:
1044: name = new CompoundName("", props);
1045: try {
1046: name.addAll(new CompositeName("a/b/c"));
1047: fail("should throw InvalidNameException");
1048: } catch (InvalidNameException e) {
1049: }
1050: }
1051:
1052: public void testAddAll_Null() throws InvalidNameException {
1053: log.setMethod("testAddAll_Null()");
1054: CompoundName name;
1055:
1056: name = new CompoundName("", props);
1057: try {
1058: name.addAll(null);
1059: fail("should throw NullPointerException");
1060: } catch (NullPointerException e) {
1061: }
1062: }
1063:
1064: public void testAddAll_Flat() throws InvalidNameException {
1065: log.setMethod("testAddAll_Flat()");
1066: CompoundName name;
1067:
1068: name = new CompoundName("aaa", new Properties());
1069: try {
1070: name.addAll(new CompoundName("bbb", new Properties()));
1071: fail("should throw InvalidNameException");
1072: } catch (InvalidNameException e) {
1073: // Expected
1074: }
1075: }
1076:
1077: public void testAddAll_Indexed() throws InvalidNameException {
1078: log.setMethod("testAddAll_Indexed()");
1079: CompoundName name;
1080:
1081: name = new CompoundName("", props);
1082: assertNameEmpty(name);
1083: name.addAll(0, new CompoundName("a", props));
1084: assertNameEquals(name, "a");
1085: name.addAll(0, new CompoundName("b", props));
1086: assertNameEquals(name, "b", "a");
1087: name.addAll(1, new CompoundName("", props));
1088: assertNameEquals(name, "b", "a");
1089: name.addAll(2, new CompoundName("c", props));
1090: assertNameEquals(name, "b", "a", "c");
1091:
1092: try {
1093: name.addAll(-1, new CompoundName("d", props));
1094: fail();
1095: } catch (ArrayIndexOutOfBoundsException e) {
1096: }
1097: try {
1098: name.addAll(4, new CompoundName("d", props));
1099: fail();
1100: } catch (ArrayIndexOutOfBoundsException e) {
1101: }
1102: }
1103:
1104: public void testAddAll_Indexed_NotCompoundName()
1105: throws InvalidNameException {
1106: log.setMethod("testAddAll_Indexed_NotCompoundName()");
1107: CompoundName name;
1108:
1109: name = new CompoundName("", props);
1110: try {
1111: name.addAll(0, new CompositeName("a/b/c"));
1112: fail("should throw InvalidNameException");
1113: } catch (InvalidNameException e) {
1114: }
1115: }
1116:
1117: public void testAddAll_Indexed_Null() throws InvalidNameException {
1118: log.setMethod("testAddAll_Indexed_Null()");
1119: CompoundName name;
1120:
1121: name = new CompoundName("", props);
1122: try {
1123: name.addAll(0, null);
1124: fail("should throw NullPointerException");
1125: } catch (NullPointerException e) {
1126: }
1127: }
1128:
1129: public void testAdd() throws InvalidNameException {
1130: log.setMethod("testAdd()");
1131: CompoundName name;
1132:
1133: name = new CompoundName("", props);
1134: assertNameEmpty(name);
1135: name.add("a");
1136: assertNameEquals(name, "a");
1137: name.add("'<b>/'");
1138: assertNameEquals(name, "a", "'<b>/'");
1139: name.add("'c");
1140: assertNameEquals(name, "a", "'<b>/'", "'c");
1141:
1142: // regression for HARMONY-2525
1143: name = new CompoundName("a", new Properties());
1144: try {
1145: name.add("b");
1146: fail("InvalidNameException expected");
1147: } catch (InvalidNameException e) {
1148: //expected
1149: }
1150: }
1151:
1152: // regression for HARMONY-2525
1153: public void testAdd_Null() throws InvalidNameException {
1154: log.setMethod("testAdd_Null()");
1155: CompoundName name;
1156:
1157: name = new CompoundName("", props);
1158: try {
1159: name.add(null);
1160: fail("IllegalArgumentException expected");
1161: } catch (IllegalArgumentException e) {
1162: //expected
1163: }
1164:
1165: name = new CompoundName("", new Properties());
1166: try {
1167: name.add(null);
1168: fail("IllegalArgumentException expected");
1169: } catch (IllegalArgumentException e) {
1170: //expected
1171: }
1172: }
1173:
1174: public void testAdd_Indexed() throws InvalidNameException {
1175: log.setMethod("testAdd_Indexed()");
1176: CompoundName name;
1177:
1178: name = new CompoundName("", props);
1179: assertNameEmpty(name);
1180: name.add(0, "a");
1181: assertNameEquals(name, "a");
1182: name.add(0, "b");
1183: assertNameEquals(name, "b", "a");
1184: name.add(1, "");
1185: assertNameEquals(name, "b", "", "a");
1186: try {
1187: name.addAll(-1, new CompoundName("d", props));
1188: fail();
1189: } catch (ArrayIndexOutOfBoundsException e) {
1190: //expected
1191: }
1192: try {
1193: name.addAll(5, new CompoundName("d", props));
1194: fail();
1195: } catch (ArrayIndexOutOfBoundsException e) {
1196: //expected
1197: }
1198:
1199: // regression for HARMONY-2525
1200: name = new CompoundName("a", new Properties());
1201: try {
1202: name.add(0, "b");
1203: fail("InvalidNameException expected");
1204: } catch (InvalidNameException e) {
1205: //expected
1206: }
1207: try {
1208: name.add(1, "b");
1209: fail("InvalidNameException expected");
1210: } catch (InvalidNameException e) {
1211: //expected
1212: }
1213: try {
1214: name.add(-1, "b");
1215: fail("InvalidNameException expected");
1216: } catch (InvalidNameException e) {
1217: //expected
1218: }
1219: }
1220:
1221: // regression for HARMONY-2525
1222: public void testAdd_Indexed_Null() throws InvalidNameException {
1223: log.setMethod("testAdd_Indexed_Null()");
1224: CompoundName name;
1225:
1226: name = new CompoundName("", props);
1227: try {
1228: name.add(0, null);
1229: fail("IllegalArgumentException expected");
1230: } catch (IllegalArgumentException e) {
1231: //expected
1232: }
1233:
1234: // regression test for HARMONY-1021
1235: name = new CompoundName("", props);
1236: try {
1237: name.add(11, null);
1238: fail("IllegalArgumentException expected");
1239: } catch (IllegalArgumentException e) {
1240: //expected
1241: }
1242:
1243: name = new CompoundName("", new Properties());
1244: try {
1245: name.add(0, null);
1246: fail("IllegalArgumentException expected");
1247: } catch (IllegalArgumentException e) {
1248: //expected
1249: }
1250: }
1251:
1252: public void testRemove() throws InvalidNameException {
1253: log.setMethod("testRemove()");
1254: CompoundName name;
1255:
1256: name = new CompoundName("a/b/c/d", props);
1257: assertEquals("a", name.remove(0));
1258: assertNameEquals(name, "b", "c", "d");
1259: assertEquals("c", name.remove(1));
1260: assertNameEquals(name, "b", "d");
1261: assertEquals("d", name.remove(1));
1262: assertNameEquals(name, "b");
1263: assertEquals("b", name.remove(0));
1264: assertNameEmpty(name);
1265:
1266: try {
1267: name.remove(0);
1268: fail();
1269: } catch (ArrayIndexOutOfBoundsException e) {
1270: }
1271: name = new CompoundName("a/b/c/d", props);
1272: try {
1273: name.remove(-1);
1274: fail();
1275: } catch (ArrayIndexOutOfBoundsException e) {
1276: }
1277: try {
1278: name.remove(4);
1279: fail();
1280: } catch (ArrayIndexOutOfBoundsException e) {
1281: }
1282: }
1283:
1284: public void testClone() throws InvalidNameException {
1285: log.setMethod("testClone()");
1286: CompoundName name, name2;
1287:
1288: name = new CompoundName("a/b", props);
1289: name2 = (CompoundName) name.clone();
1290: assertNameEquals(name2, "a", "b");
1291:
1292: name.add("c");
1293: assertNameEquals(name, "a", "b", "c");
1294: assertNameEquals(name2, "a", "b");
1295:
1296: name2.remove(0);
1297: assertNameEquals(name, "a", "b", "c");
1298: assertNameEquals(name2, "b");
1299: }
1300:
1301: public void testClone_1() throws InvalidNameException {
1302: log.setMethod("testClone_1()");
1303: CompoundName name = null, name2 = null;
1304:
1305: try {
1306: name = new CompoundName("name", new UncloneableProperties());
1307: } catch (UnsupportedOperationException e) {
1308: fail("unexpected UnsupportedOperationException");
1309: }
1310:
1311: try {
1312: name2 = (CompoundName) name.clone();
1313: } catch (UnsupportedOperationException e) {
1314: fail("unexpected UnsupportedOperationException");
1315: }
1316: assertEquals(name, name2);
1317: }
1318:
1319: public void testCompareTo() throws InvalidNameException {
1320: log.setMethod("testCompareTo()");
1321:
1322: assertEquals(-1, new CompoundName("a/b/c/d", props)
1323: .compareTo(new CompoundName("a/c/c/d", props)));
1324: assertEquals(-1, new CompoundName("a/b/c/d", props)
1325: .compareTo(new CompoundName("ab/c/d", props)));
1326: assertEquals(-1, new CompoundName("a/b/c/d", props)
1327: .compareTo(new CompoundName("a/b/c/d/e", props)));
1328: }
1329:
1330: public void testCompareTo_Null() throws InvalidNameException {
1331: log.setMethod("testCompareTo_Null()");
1332: CompoundName name;
1333:
1334: name = new CompoundName("a/b/c/d", props);
1335: try {
1336: name.compareTo(null);
1337: fail("compareTo(null) should throw ClassCastException");
1338: } catch (ClassCastException e) {
1339: }
1340: }
1341:
1342: public void testCompareTo_NotCompoundName()
1343: throws InvalidNameException {
1344: log.setMethod("testCompareTo_NotCompoundName()");
1345: CompoundName name;
1346:
1347: name = new CompoundName("a/b/c/d", props);
1348: try {
1349: name.compareTo(new CompositeName("a/b/c"));
1350: fail("compareTo(CompositeName) should throw ClassCastException");
1351: } catch (ClassCastException e) {
1352: }
1353: }
1354:
1355: public void testCompareTo_IgnoreCaseAndTrimBlanks()
1356: throws InvalidNameException {
1357: log.setMethod("testCompareTo_IgnoreCaseAndTrimBlanks()");
1358:
1359: props.put("jndi.syntax.ignorecase", "false");
1360: props.put("jndi.syntax.trimblanks", "false");
1361: CompoundName abcd = new CompoundName("a/b/c/d", props);
1362:
1363: props2.put("jndi.syntax.ignorecase", "true");
1364: props2.put("jndi.syntax.trimblanks", "false");
1365: CompoundName abcd_ic = new CompoundName("a/b/c/d", props2);
1366: CompoundName ABCD_ic = new CompoundName("A/B/C/D", props2);
1367: assertEquals(0, abcd_ic.compareTo(ABCD_ic));
1368: assertEquals(0, ABCD_ic.compareTo(abcd_ic));
1369: assertEquals(0, abcd_ic.compareTo(abcd));
1370: assertEquals(0, abcd.compareTo(abcd_ic));
1371: assertEquals(0, ABCD_ic.compareTo(abcd));
1372: assertEquals(32, abcd.compareTo(ABCD_ic));
1373:
1374: props2.put("jndi.syntax.ignorecase", "false");
1375: props2.put("jndi.syntax.trimblanks", "true");
1376: CompoundName abcd_tb = new CompoundName("a/b/c/d", props2);
1377: CompoundName _a_b_c_d_tb = new CompoundName(" a / b / c / d ",
1378: props2);
1379: assertEquals(0, abcd_tb.compareTo(_a_b_c_d_tb));
1380: assertEquals(0, _a_b_c_d_tb.compareTo(abcd_tb));
1381: assertEquals(0, abcd_tb.compareTo(abcd));
1382: assertEquals(0, abcd.compareTo(abcd_tb));
1383: assertEquals(65, abcd.compareTo(_a_b_c_d_tb));
1384: assertEquals(0, _a_b_c_d_tb.compareTo(abcd));
1385: }
1386:
1387: public void testSize() throws InvalidNameException {
1388: log.setMethod("testSize()");
1389: CompoundName name;
1390:
1391: name = new CompoundName("a/b/c/d", props);
1392: assertEquals(4, name.size());
1393: name.remove(0);
1394: assertEquals(3, name.size());
1395: name.remove(0);
1396: assertEquals(2, name.size());
1397: name.remove(0);
1398: assertEquals(1, name.size());
1399: name.remove(0);
1400: assertEquals(0, name.size());
1401: }
1402:
1403: public void testIsEmpty() throws InvalidNameException {
1404: log.setMethod("testIsEmpty()");
1405: CompoundName name;
1406:
1407: name = new CompoundName("a/b/c/d", props);
1408: assertFalse(name.isEmpty());
1409: name.remove(0);
1410: assertFalse(name.isEmpty());
1411: name.remove(0);
1412: assertFalse(name.isEmpty());
1413: name.remove(0);
1414: assertFalse(name.isEmpty());
1415: name.remove(0);
1416: assertTrue(name.isEmpty());
1417: }
1418:
1419: public void testStartsWith() throws InvalidNameException {
1420: log.setMethod("testStartsWith()");
1421: CompoundName name;
1422:
1423: name = new CompoundName("a/b/c/d", props);
1424: assertTrue(name.startsWith(new CompoundName("", props)));
1425: assertTrue(name.startsWith(new CompoundName("a/b", props)));
1426: assertTrue(name.startsWith(new CompoundName("a/b/c/d", props)));
1427:
1428: assertFalse(name.startsWith(new CompoundName("b", props)));
1429: assertFalse(name
1430: .startsWith(new CompoundName("a/b/c/d/e", props)));
1431: }
1432:
1433: public void testStartsWith_NotCoumpoundName()
1434: throws InvalidNameException {
1435: log.setMethod("testStartsWith_NotCoumpoundName()");
1436: CompoundName name;
1437:
1438: name = new CompoundName("a/b/c/d", props);
1439: assertFalse(name.startsWith(new CompositeName("a/b")));
1440: }
1441:
1442: public void testStartsWith_Null() throws InvalidNameException {
1443: log.setMethod("testStartsWith_Null()");
1444: CompoundName name;
1445:
1446: name = new CompoundName("a/b/c/d", props);
1447: assertFalse(name.startsWith(null));
1448: }
1449:
1450: public void testEndsWith() throws InvalidNameException {
1451: log.setMethod("testEndsWith()");
1452: CompoundName name;
1453:
1454: name = new CompoundName("a/b/c/d", props);
1455: assertTrue(name.endsWith(new CompoundName("", props)));
1456: assertTrue(name.endsWith(new CompoundName("c/d", props)));
1457: assertTrue(name.endsWith(new CompoundName("a/b/c/d", props)));
1458:
1459: assertFalse(name.endsWith(new CompoundName("b", props)));
1460: assertFalse(name.endsWith(new CompoundName("a/b/c/d/e", props)));
1461: }
1462:
1463: public void testEndsWith_NotCoumpoundName()
1464: throws InvalidNameException {
1465: log.setMethod("testEndsWith_NotCoumpoundName()");
1466: CompoundName name;
1467:
1468: name = new CompoundName("a/b/c/d", props);
1469: assertFalse(name.endsWith(new CompositeName("a/b")));
1470: }
1471:
1472: public void testEndsWith_Null() throws InvalidNameException {
1473: log.setMethod("testEndsWith_Null()");
1474: CompoundName name;
1475:
1476: name = new CompoundName("a/b/c/d", props);
1477: assertFalse(name.endsWith(null));
1478: }
1479:
1480: public void testProperties_Separator() throws InvalidNameException {
1481: log.setMethod("testProperties_Separator()");
1482: CompoundName name;
1483: props.put("jndi.syntax.separator", ":");
1484:
1485: // a different separator
1486: name = new CompoundName(":a:b", props);
1487: assertNameEquals(name, "", "a", "b");
1488: }
1489:
1490: public void testProperties_Direction() throws InvalidNameException {
1491: log.setMethod("testProperties_Direction()");
1492: CompoundName name;
1493: props.put("jndi.syntax.direction", "right_to_left");
1494:
1495: // right to left
1496: name = new CompoundName("c/b/a", props);
1497: assertNameEquals(name, "a", "b", "c");
1498:
1499: // flat
1500: props.put("jndi.syntax.direction", "flat");
1501: name = new CompoundName("c/b/a", props);
1502: assertNameEquals(name, "c/b/a");
1503:
1504: // flat with no separator
1505: props.remove("jndi.syntax.separator");
1506: name = new CompoundName("c/b/a", props);
1507: assertNameEquals(name, "c/b/a");
1508:
1509: // flat other cases
1510: try {
1511: name = new CompoundName("<\"'''213^!$!@#$a/b//c///", props);
1512: fail();
1513: } catch (InvalidNameException e) {
1514: }
1515: name = new CompoundName("\"'''213^!$!@#$a/b//c///", props);
1516: assertNameEquals(name, "\"'''213^!$!@#$a/b//c///");
1517: }
1518:
1519: public void testProperties_EscapeAndQuote()
1520: throws InvalidNameException {
1521: log.setMethod("testProperties_EscapeAndQuote()");
1522: CompoundName name;
1523:
1524: name = new CompoundName("ab<abc>/de", props);
1525: assertNameEquals(name, "ab<abc>", "de");
1526:
1527: name = new CompoundName("<a>/<b//>/'<>sadf/'", props);
1528: assertNameEquals(name, "a", "b//", "<>sadf/");
1529:
1530: name = new CompoundName("<a\\>>/\\//'<>sadf/\\''", props);
1531: assertNameEquals(name, "a>", "/", "<>sadf/'");
1532:
1533: try {
1534: name = new CompoundName("<aba<b>c>/de", props);
1535: fail();
1536: } catch (InvalidNameException e) {
1537: }
1538: }
1539:
1540: public void testProperties_IgnoreCaseAndTrimBlank()
1541: throws InvalidNameException {
1542: log.setMethod("testProperties_IgnoreCaseAndTrimBlank()");
1543:
1544: props.put("jndi.syntax.ignorecase", "false");
1545: props.put("jndi.syntax.trimblanks", "false");
1546: CompoundName abcd = new CompoundName("a/b/c/d", props);
1547:
1548: props2.put("jndi.syntax.ignorecase", "true");
1549: props2.put("jndi.syntax.trimblanks", "false");
1550: CompoundName abcd_ic = new CompoundName("a/b/c/d", props2);
1551: CompoundName ABCD_ic = new CompoundName("A/B/C/D", props2);
1552: assertTrue(abcd_ic.equals(ABCD_ic));
1553: assertTrue(ABCD_ic.equals(abcd_ic));
1554: assertTrue(abcd_ic.equals(abcd));
1555: assertTrue(abcd.equals(abcd_ic));
1556: assertTrue(ABCD_ic.equals(abcd));
1557: assertFalse(abcd.equals(ABCD_ic));
1558:
1559: props2.put("jndi.syntax.ignorecase", "false");
1560: props2.put("jndi.syntax.trimblanks", "true");
1561: CompoundName abcd_tb = new CompoundName("a/b/c/d", props2);
1562: CompoundName _a_b_c_d_tb = new CompoundName(" a / b / c / d ",
1563: props2);
1564: assertTrue(abcd_tb.equals(_a_b_c_d_tb));
1565: assertTrue(_a_b_c_d_tb.equals(abcd_tb));
1566: assertTrue(abcd_tb.equals(abcd));
1567: assertTrue(abcd.equals(abcd_tb));
1568: assertFalse(abcd.equals(_a_b_c_d_tb));
1569: assertTrue(_a_b_c_d_tb.equals(abcd));
1570: }
1571:
1572: public void testProperties_IgnoreCaseAndTrimBlank_DefaultValue()
1573: throws InvalidNameException {
1574: log
1575: .setMethod("testProperties_IgnoreCaseAndTrimBlank_DefaultValue()");
1576:
1577: props.remove("jndi.syntax.ignorecase");
1578: props.remove("jndi.syntax.trimblanks");
1579: CompoundName abcd = new CompoundName("a/b/c/d", props);
1580: CompoundName ABCD = new CompoundName("A/B/C/D", props);
1581: CompoundName _a_b_c_d_ = new CompoundName(" a / b / c / d ",
1582: props);
1583: assertFalse(abcd.equals(ABCD));
1584: assertFalse(abcd.equals(_a_b_c_d_));
1585:
1586: props.remove("jndi.syntax.beginquote");
1587: props.remove("jndi.syntax.endquote");
1588: props.remove("jndi.syntax.beginquote2");
1589: props.remove("jndi.syntax.endquote2");
1590: CompoundName quote = new CompoundName("a/\\/b/c", props);
1591: assertEquals("a/\\/b/c", quote.toString());
1592: }
1593:
1594: public void testEquals() throws InvalidNameException {
1595: log.setMethod("testEquals()");
1596: CompoundName name;
1597:
1598: name = new CompoundName("a/b/c", props);
1599: assertTrue(name.equals(new CompoundName("a/b/c", props)));
1600: assertFalse(name.equals(new CompositeName("a/b/c")));
1601:
1602: CompoundName empty1 = new CompoundName("", props);
1603: CompoundName empty2 = new CompoundName("", new Properties());
1604: assertTrue(empty1.equals(empty2));
1605: assertTrue(empty2.equals(empty1));
1606: }
1607:
1608: public void testHashCode() throws InvalidNameException {
1609: log.setMethod("testHashCode()");
1610: CompoundName name;
1611:
1612: name = new CompoundName("a/b/c", props);
1613: assertTrue(name.hashCode() == new CompoundName("a/b/c", props)
1614: .hashCode());
1615: assertEquals(294, name.hashCode());
1616:
1617: props.put("jndi.syntax.ignorecase", "true");
1618: props.put("jndi.syntax.trimblanks", "false");
1619: name = new CompoundName(" A / B / c ", props);
1620: assertEquals(101466, name.hashCode());
1621:
1622: props.put("jndi.syntax.ignorecase", "false");
1623: props.put("jndi.syntax.trimblanks", "true");
1624: name = new CompoundName(" A / B / c ", props);
1625: assertEquals(230, name.hashCode());
1626:
1627: props.put("jndi.syntax.ignorecase", "true");
1628: props.put("jndi.syntax.trimblanks", "true");
1629: name = new CompoundName(" A / B / c ", props);
1630: assertEquals(294, name.hashCode());
1631: }
1632:
1633: public void testToString() throws InvalidNameException {
1634: log.setMethod("testToString()");
1635:
1636: testToString("", "");
1637: testToString("/", "/");
1638: testToString("//", "//");
1639: testToString("/a/", "/a/");
1640: testToString("//a/", "//a/");
1641: testToString("a/b/c/", "a/b/c/");
1642: testToString("/a/b/c", "/a/b/c");
1643:
1644: testToString("a/\\/b/c", "a/</b>/c");
1645: testToString("a/b\\", "fail");
1646:
1647: testToString("a/<b/>/c", "a/<b/>/c");
1648: testToString("a/b<b/>b/c", "a/b<b/>b/c");
1649: testToString("a/<b/>b/c", "fail");
1650: testToString("a/<b</>/c", "a/<b</>/c");
1651: testToString("a/\\/b>>>/c", "a/</b\\>\\>\\>>/c");
1652: testToString("a/</b>>/c", "fail");
1653: testToString("a/</b>>/c", "fail");
1654: testToString("a/</b\\a\\>b>/c", "a/</b\\a\\>b>/c");
1655:
1656: testToString("a/'b/'/c", "a/<b/>/c");
1657: testToString("a/b'b/'b/c", "fail");
1658: testToString("a/'b/'b/c", "fail");
1659: testToString("a/'/b\\a\\'b'/c", "a/</b\\a'b>/c");
1660:
1661: }
1662:
1663: public void testToStringRightToLeft() throws Exception {
1664:
1665: CompoundName name = new CompoundName("a/b/c", props);
1666: assertEquals("a/b/c", name.toString());
1667: }
1668:
1669: private void testBehavior(String str, Properties p) {
1670: try {
1671: CompoundName name = new CompoundName(str, p);
1672: log.log(str + "\t" + name.toString() + "\t"
1673: + toString(name));
1674: } catch (Throwable e) {
1675: log.log(str + " with props " + p + " causes error", e);
1676: }
1677: }
1678:
1679: private void testToString(String str, String expected)
1680: throws InvalidNameException {
1681: CompoundName name = null;
1682: try {
1683: props.put("jndi.syntax.direction", "left_to_right");
1684: name = new CompoundName(str, props);
1685: if ("fail".equals(expected)) {
1686: fail("fail.equals()" + expected);
1687: }
1688: assertEquals(expected, name.toString());
1689: props.put("jndi.syntax.direction", "right_to_left");
1690: name = new CompoundName(str, props);
1691: if ("fail".equals(expected)) {
1692: fail("fail.equals()" + expected);
1693: }
1694: assertEquals(expected, name.toString());
1695: } catch (Exception e) {
1696: if (!"fail".equals(expected)) {
1697: fail(str + "," + expected + "," + e.getMessage());
1698: }
1699: }
1700: }
1701:
1702: private String toString(Name n) {
1703: StringBuffer buf = new StringBuffer();
1704: buf.append("[" + n.size() + "]{");
1705: for (int i = 0; i < n.size(); i++) {
1706: if (i > 0) {
1707: buf.append("|");
1708: }
1709: buf.append(n.get(i));
1710: }
1711: buf.append("}");
1712: return buf.toString();
1713: }
1714:
1715: private void assertNameEmpty(Name n) {
1716: assertNameEquals(n, new String[0]);
1717: }
1718:
1719: private void assertNameEquals(Name n, String elem1) {
1720: assertNameEquals(n, new String[] { elem1 });
1721: }
1722:
1723: private void assertNameEquals(Name n, String elem1, String elem2) {
1724: assertNameEquals(n, new String[] { elem1, elem2 });
1725: }
1726:
1727: private void assertNameEquals(Name n, String elem1, String elem2,
1728: String elem3) {
1729: assertNameEquals(n, new String[] { elem1, elem2, elem3 });
1730: }
1731:
1732: private void assertNameEquals(Name n, String elem1, String elem2,
1733: String elem3, String elem4) {
1734: assertNameEquals(n, new String[] { elem1, elem2, elem3, elem4 });
1735: }
1736:
1737: private void assertNameEquals(Name n, String[] elems) {
1738:
1739: try {
1740: // compare
1741: assertEquals(elems.length, n.size());
1742:
1743: for (int i = 0; i < n.size(); i++) {
1744: assertEquals(elems[i], n.get(i));
1745: }
1746:
1747: int i = 0;
1748: Enumeration<?> enumeration = n.getAll();
1749: while (enumeration.hasMoreElements()) {
1750: assertEquals(elems[i++], enumeration.nextElement());
1751: }
1752:
1753: assertNotNull(n.toString());
1754: } catch (AssertionFailedError e) {
1755: // log
1756: StringBuffer buf = new StringBuffer();
1757: buf.append("Assert name ");
1758: buf.append(toString(n));
1759: buf.append(" has elements [" + elems.length + "]{");
1760: for (int i = 0; i < elems.length; i++) {
1761: if (i > 0) {
1762: buf.append("|");
1763: }
1764: buf.append(elems[i]);
1765: }
1766: buf.append("}");
1767: log.log(buf.toString());
1768:
1769: throw e;
1770: }
1771: }
1772:
1773: private void assertInvalidName(String str, Properties p) {
1774: try {
1775: new CompoundName(str, p);
1776: fail(str + " with props " + p
1777: + " should be an invalid name.");
1778: } catch (InvalidNameException e) {
1779: }
1780: }
1781:
1782: public void testWriteReadObject() throws Exception {
1783: log.setMethod("testWriteReadObject()");
1784: CompoundName name = new CompoundName("a/b/c/d", props);
1785: ByteArrayOutputStream bout = new ByteArrayOutputStream();
1786: ObjectOutputStream stream = new ObjectOutputStream(bout);
1787: stream.writeObject(name);
1788: stream.close();
1789: ObjectInputStream in = new ObjectInputStream(
1790: new ByteArrayInputStream(bout.toByteArray()));
1791: CompoundName name2 = (CompoundName) in.readObject();
1792: assertTrue(name.equals(name2));
1793: in.close();
1794: }
1795:
1796: public void testSerializationCompatibility() throws Exception {
1797: log.setMethod("testSerializationCompatibility()");
1798:
1799: try {
1800: ObjectInputStream in = new ObjectInputStream(
1801: getClass()
1802: .getResourceAsStream(
1803: "/serialization/javax/naming/CompoundName.ser"));
1804: CompoundName name = (CompoundName) in.readObject();
1805: assertEquals(new CompoundName("a/b/c/d", props), name);
1806: in.close();
1807: } catch (Exception e) {
1808: log.log(e);
1809: throw e;
1810: }
1811: }
1812:
1813: public void testSerializationCompatibility_bad() throws Exception {
1814: log.setMethod("testSerializationCompatibility_bad()");
1815:
1816: try {
1817: ObjectInputStream in = new ObjectInputStream(
1818: getClass()
1819: .getResourceAsStream(
1820: "/serialization/javax/naming/CompoundName_bad.ser"));
1821: CompoundName name = (CompoundName) in.readObject();
1822: assertEquals(new CompoundName("a/b/c/d", props), name);
1823: in.close();
1824: fail("Should throw IllegalArgumentException");
1825: } catch (IllegalArgumentException e) {
1826: }
1827: }
1828:
1829: public void testStringIndexOf() {
1830: assertEquals(3, "abc".indexOf("", 3));
1831: }
1832:
1833: public void testToStringHang() throws InvalidNameException {
1834: Properties synt = new Properties();
1835: synt.put("jndi.syntax.separator", "|");
1836: synt.put("jndi.syntax.ignorecase", "true");
1837: synt.put("jndi.syntax.direction", "left_to_right");
1838: synt.put("jndi.syntax.escape", "$");
1839: synt.put("jndi.syntax.beginquote", "`");
1840: synt.put("jndi.syntax.beginquote2", "/");
1841:
1842: String input = "'liberty|valley|army";
1843: CompoundName name = new CompoundName(input, synt);
1844: String output = name.toString();
1845: assertEquals(input, output);
1846:
1847: synt.put("jndi.syntax.separator", new String("||"));
1848: name = new CompoundName("||", synt);
1849: assertEquals("||", name.toString());
1850: }
1851:
1852: private static class UncloneableProperties extends Properties {
1853: private static final long serialVersionUID = 1L;
1854:
1855: @Override
1856: public Object clone() {
1857: throw new UnsupportedOperationException();
1858: }
1859: }
1860: }
|