You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/03/15 15:57:17 UTC
svn commit: r386087 [10/45] - in /incubator/harmony/enhanced/classlib/trunk:
make/ make/patternsets/ modules/jndi/ modules/jndi/META-INF/
modules/jndi/make/ modules/jndi/make/common/ modules/jndi/src/
modules/jndi/src/main/ modules/jndi/src/main/java/ ...
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/dazzle/jndi/testing/spi/jndi.properties
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/dazzle/jndi/testing/spi/jndi.properties?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/dazzle/jndi/testing/spi/jndi.properties (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/dazzle/jndi/testing/spi/jndi.properties Wed Mar 15 06:55:38 2006
@@ -0,0 +1,13 @@
+# Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
\ No newline at end of file
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/app1.properties
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/app1.properties?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/app1.properties (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/app1.properties Wed Mar 15 06:55:38 2006
@@ -0,0 +1,41 @@
+# Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#app1: classes/test
+
+# type==F
+
+java.naming.factory.initial=tests.api.javax.naming.mock.MockContextFactory
+java.naming.provider.url=java.naming.provider.url.app1
+#java.naming.applet=
+java.naming.authoritative=java.naming.authoritative.app1
+java.naming.batchsize=java.naming.batchsize.app1
+java.naming.dns.url=java.naming.dns.url.app1
+java.naming.language=java.naming.language.app1
+java.naming.referral=java.naming.referral.app1
+java.naming.security.authentication=java.naming.security.authentication.app1
+java.naming.security.credentials=java.naming.security.credentials.app1
+java.naming.security.principal=java.naming.security.principal.app1
+java.naming.security.protocol=java.naming.security.protocol.app1
+
+# type==C
+java.naming.factory.control=java.naming.factory.control.app1
+java.naming.factory.object=java.naming.factory.object.app1
+java.naming.factory.state=java.naming.factory.state.app1
+java.naming.factory.url.pkgs=java.naming.factory.url.pkgs.app1
+
+#other
+dazzle.jndi.testing.spi.app1=dazzle.jndi.testing.spi.app1.app1
+
+#junk
+app1.type=classes/test
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/app2.properties
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/app2.properties?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/app2.properties (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/app2.properties Wed Mar 15 06:55:38 2006
@@ -0,0 +1,40 @@
+# Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#app2: ext-classes
+
+# type==F
+java.naming.factory.initial=tests.api.javax.naming.mock.MockContextFactory
+java.naming.provider.url=java.naming.provider.url.app2
+#java.naming.applet=
+java.naming.authoritative=java.naming.authoritative.app2
+java.naming.batchsize=java.naming.batchsize.app2
+java.naming.dns.url=java.naming.dns.url.app2
+java.naming.language=java.naming.language.app2
+java.naming.referral=java.naming.referral.app2
+java.naming.security.authentication=java.naming.security.authentication.app2
+java.naming.security.credentials=java.naming.security.credentials.app2
+java.naming.security.principal=java.naming.security.principal.app2
+java.naming.security.protocol=java.naming.security.protocol.app2
+
+# type==C
+java.naming.factory.control=java.naming.factory.control.app2
+java.naming.factory.object=java.naming.factory.object.app2
+java.naming.factory.state=java.naming.factory.state.app2
+java.naming.factory.url.pkgs=java.naming.factory.url.pkgs.app2
+
+#other
+dazzle.jndi.testing.spi.app2=dazzle.jndi.testing.spi.app2.app2
+
+#junk
+app2.type=ext-classes
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/app3.properties
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/app3.properties?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/app3.properties (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/app3.properties Wed Mar 15 06:55:38 2006
@@ -0,0 +1,40 @@
+# Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#app1: /temp/cls1
+
+# type==F
+java.naming.factory.initial=tests.api.javax.naming.mock.MockContextFactory
+java.naming.provider.url=java.naming.provider.url.app3
+#java.naming.applet=
+java.naming.authoritative=java.naming.authoritative.app3
+java.naming.batchsize=java.naming.batchsize.app3
+java.naming.dns.url=java.naming.dns.url.app3
+java.naming.language=java.naming.language.app3
+java.naming.referral=java.naming.referral.app3
+java.naming.security.authentication=java.naming.security.authentication.app3
+java.naming.security.credentials=java.naming.security.credentials.app3
+java.naming.security.principal=java.naming.security.principal.app3
+java.naming.security.protocol=java.naming.security.protocol.app3
+
+# type==C
+java.naming.factory.control=java.naming.factory.control.app3
+java.naming.factory.object=java.naming.factory.object.app3
+java.naming.factory.state=java.naming.factory.state.app3
+java.naming.factory.url.pkgs=java.naming.factory.url.pkgs.app3
+
+#other
+dazzle.jndi.testing.spi.app3=dazzle.jndi.testing.spi.app3.app3
+
+#junk
+app3.type=/temp/cls1
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/lib.properties
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/lib.properties?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/lib.properties (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/lib.properties Wed Mar 15 06:55:38 2006
@@ -0,0 +1,40 @@
+# Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#app1: java.home/lib
+
+# type==F
+java.naming.factory.initial=tests.api.javax.naming.mock.MockContextFactory
+java.naming.provider.url=java.naming.provider.url.lib
+#java.naming.applet=
+java.naming.authoritative=java.naming.authoritative.lib
+java.naming.batchsize=java.naming.batchsize.lib
+java.naming.dns.url=java.naming.dns.url.lib
+java.naming.language=java.naming.language.lib
+java.naming.referral=java.naming.referral.lib
+java.naming.security.authentication=java.naming.security.authentication.lib
+java.naming.security.credentials=java.naming.security.credentials.lib
+java.naming.security.principal=java.naming.security.principal.lib
+java.naming.security.protocol=java.naming.security.protocol.lib
+
+# type==C
+java.naming.factory.control=java.naming.factory.control.lib
+java.naming.factory.object=java.naming.factory.object.lib
+java.naming.factory.state=java.naming.factory.state.lib
+java.naming.factory.url.pkgs=java.naming.factory.url.pkgs.lib
+
+#other
+dazzle.jndi.testing.spi.lib=dazzle.jndi.testing.spi.lib.lib
+
+#junk
+lib.type=java.home.lib
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/spi1.properties
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/spi1.properties?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/spi1.properties (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/spi1.properties Wed Mar 15 06:55:38 2006
@@ -0,0 +1,40 @@
+# Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#app1: classes/test/dazzle/jndi/testing/spi/jndiprovider.properties
+
+# type==F
+java.naming.factory.initial=tests.api.javax.naming.mock.MockFiveContextFactory
+java.naming.provider.url=java.naming.provider.url.spi1
+#java.naming.applet=
+java.naming.authoritative=java.naming.authoritative.spi1
+java.naming.batchsize=java.naming.batchsize.spi1
+java.naming.dns.url=java.naming.dns.url.spi1
+java.naming.language=java.naming.language.spi1
+java.naming.referral=java.naming.referral.spi1
+java.naming.security.authentication=java.naming.security.authentication.spi1
+java.naming.security.credentials=java.naming.security.credentials.spi1
+java.naming.security.principal=java.naming.security.principal.spi1
+java.naming.security.protocol=java.naming.security.protocol.spi1
+
+# type==C
+java.naming.factory.control=tests.api.javax.naming.ldap.MockControlFactory$ControlFactorySPI1
+java.naming.factory.object=java.naming.factory.object.spi1
+java.naming.factory.state=java.naming.factory.state.spi1
+java.naming.factory.url.pkgs=java.naming.factory.url.pkgs.spi1
+
+#other
+dazzle.jndi.testing.spi.spi1=dazzle.jndi.testing.spi.spi1.spi1
+
+#junk
+spi1.type=spi1.type.spi1
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/spi2.properties
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/spi2.properties?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/spi2.properties (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/jndiproperties/spi2.properties Wed Mar 15 06:55:38 2006
@@ -0,0 +1,40 @@
+# Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#app1: ext-classes/dazzle/jndi/testing/spi/jndiprovider.properties
+
+# type==F
+java.naming.factory.initial=tests.api.javax.naming.mock.MockSixContextFactory
+java.naming.provider.url=java.naming.provider.url.spi2
+#java.naming.applet=
+java.naming.authoritative=java.naming.authoritative.spi2
+java.naming.batchsize=java.naming.batchsize.spi2
+java.naming.dns.url=java.naming.dns.url.spi2
+java.naming.language=java.naming.language.spi2
+java.naming.referral=java.naming.referral.spi2
+java.naming.security.authentication=java.naming.security.authentication.spi2
+java.naming.security.credentials=java.naming.security.credentials.spi2
+java.naming.security.principal=java.naming.security.principal.spi2
+java.naming.security.protocol=java.naming.security.protocol.spi2
+
+# type==C
+java.naming.factory.control=tests.api.javax.naming.ldap.MockControlFactory$ControlFactorySPI2
+java.naming.factory.object=java.naming.factory.object.spi2
+java.naming.factory.state=java.naming.factory.state.spi2
+java.naming.factory.url.pkgs=java.naming.factory.url.pkgs.spi2
+
+#other
+dazzle.jndi.testing.spi.spi2=dazzle.jndi.testing.spi.spi2.spi2
+
+#junk
+spi2.type=spi2.type.spi2
\ No newline at end of file
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/AllTests.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/AllTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/AllTests.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,48 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.javax.naming;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Test for tests.api.javax.naming");
+ // $JUnit-BEGIN$
+ suite.addTestSuite(TestInitialContextMock.class);
+ suite.addTestSuite(TestReference.class);
+ suite.addTestSuite(TestCannotProceedException.class);
+ suite.addTestSuite(TestLinkException.class);
+ suite.addTestSuite(TestLinkRef.class);
+ suite.addTestSuite(TestCompositeName.class);
+ suite.addTestSuite(TestInvalidNameException.class);
+ suite.addTestSuite(TestNamingException.class);
+ suite.addTestSuite(TestBinaryRefAddr.class);
+ suite.addTestSuite(TestMalformedLinkException.class);
+ suite.addTestSuite(TestNamingExceptions.class);
+ suite.addTestSuite(TestLinkLoopException.class);
+ suite.addTestSuite(TestBinding.class);
+ suite.addTestSuite(TestNoInitialContextException.class);
+ suite.addTestSuite(TestReferralException.class);
+ suite.addTestSuite(TestNameClassPair.class);
+ suite.addTestSuite(TestCompoundName.class);
+ suite.addTestSuite(TestStringRefAddr.class);
+ suite.addTestSuite(TestNotContextException.class);
+ // $JUnit-END$
+ return suite;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/MockNameParser.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/MockNameParser.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/MockNameParser.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/MockNameParser.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,43 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.javax.naming;
+
+import javax.naming.InvalidNameException;
+import javax.naming.Name;
+import javax.naming.NameParser;
+import javax.naming.NamingException;
+
+/**
+ *
+ */
+public class MockNameParser implements NameParser {
+
+ /**
+ *
+ */
+ public MockNameParser() {
+ super();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.NameParser#parse(java.lang.String)
+ */
+ public Name parse(String s) throws NamingException, InvalidNameException {
+ return null;
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestBinaryRefAddr.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestBinaryRefAddr.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestBinaryRefAddr.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestBinaryRefAddr.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,378 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.javax.naming;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Random;
+
+import javax.naming.BinaryRefAddr;
+import javax.naming.RefAddr;
+
+import junit.framework.TestCase;
+
+public class TestBinaryRefAddr extends TestCase {
+
+ /**
+ * Constructor for BinaryRefAddr.
+ *
+ * @param arg0
+ */
+ public TestBinaryRefAddr(String arg0) {
+ super(arg0);
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testBinaryRefAddr_SimpleNormale() {
+ byte[] ab = new byte[] { 1, 2, 3 };
+ byte[] ab2;
+
+ // Test normal condition
+ BinaryRefAddr addr = new BinaryRefAddr("binary", ab);
+ TestCase.assertNotNull(addr);
+ TestCase.assertEquals("binary", addr.getType());
+ ab2 = (byte[]) addr.getContent();
+ TestCase.assertEquals(ab.length, ab2.length);
+ for (int i = ab2.length - 1; i >= 0; i--) {
+ TestCase.assertEquals(ab[i], ab2[i]);
+ }
+ assertNotSame(ab, ab2);
+ }
+
+ public void testBinaryRefAddr_SimpleNullType() {
+ byte[] ab = new byte[] { 1, 2, 3 };
+ byte[] ab2;
+
+ // Test null "type" parameter
+ BinaryRefAddr addr = new BinaryRefAddr(null, ab);
+ TestCase.assertNotNull(addr);
+ TestCase.assertNull(addr.getType());
+ ab2 = (byte[]) addr.getContent();
+ TestCase.assertEquals(ab.length, ab2.length);
+ for (int i = ab2.length - 1; i >= 0; i--) {
+ TestCase.assertEquals(ab[i], ab2[i]);
+ }
+ }
+
+ public void testBinaryRefAddr_SimpleNullAddress() {
+ BinaryRefAddr addr = null;
+
+ // Test null address content
+ try {
+ addr = new BinaryRefAddr("binary", null);
+ fail("Should throw NullPointerException here.");
+ } catch (NullPointerException e) {
+ }
+ TestCase.assertNull(addr);
+ }
+
+ public void testBinaryRefAddr_ComplexNormal() {
+ byte[] ab = new byte[] { 1, 2, 3 };
+ byte[] ab2;
+
+ // Test normal condition
+ BinaryRefAddr addr = new BinaryRefAddr("binary", ab, 1, 1);
+ TestCase.assertNotNull(addr);
+ TestCase.assertEquals("binary", addr.getType());
+ ab2 = (byte[]) addr.getContent();
+ TestCase.assertEquals(ab2.length, 1);
+ for (int i = ab2.length - 1; i >= 0; i--) {
+ TestCase.assertEquals(ab[i + 1], ab2[i]);
+ }
+ assertNotSame(ab, ab2);
+ }
+
+ public void testBinaryRefAddr_ComplexNullType() {
+ byte[] ab = new byte[] { 1, 2, 3 };
+ byte[] ab2;
+
+ // Test null "type" parameter
+ BinaryRefAddr addr = new BinaryRefAddr(null, ab, 1, 1);
+ TestCase.assertNotNull(addr);
+ TestCase.assertNull(addr.getType());
+ ab2 = (byte[]) addr.getContent();
+ TestCase.assertEquals(ab2.length, 1);
+ for (int i = ab2.length - 1; i >= 0; i--) {
+ TestCase.assertEquals(ab[i + 1], ab2[i]);
+ }
+ }
+
+ public void testBinaryRefAddr_ComplexNullAddress() {
+ BinaryRefAddr addr = null;
+
+ // Test null address content
+ try {
+ addr = new BinaryRefAddr("binary", null, 1, 1);
+ fail("Should throw NullPointerException here.");
+ } catch (NullPointerException e) {
+ }
+ TestCase.assertNull(addr);
+ }
+
+ public void testBinaryRefAddr_TooSmallIndex() {
+ BinaryRefAddr addr = null;
+
+ // Test too small index
+ try {
+ addr = new BinaryRefAddr("binary", new byte[] { 2, 3 }, -1, 1);
+ fail("Should throw ArrayIndexOutOfBoundsException here.");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
+ TestCase.assertNull(addr);
+ }
+
+ public void testBinaryRefAddr_TooBigIndex() {
+ BinaryRefAddr addr = null;
+
+ // Test too big index
+ try {
+ addr = new BinaryRefAddr("binary", new byte[] { 2, 3 }, 2, 1);
+ fail("Should throw ArrayIndexOutOfBoundsException here.");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
+ TestCase.assertNull(addr);
+ }
+
+ public void testBinaryRefAddr_ComplexZeroSize() {
+ byte[] ab;
+ BinaryRefAddr addr = null;
+
+ // Test zero size
+ addr = new BinaryRefAddr("binary", new byte[] { 2, 3 }, 0, 0);
+ ab = (byte[]) addr.getContent();
+ TestCase.assertEquals(ab.length, 0);
+ TestCase.assertNotNull(addr);
+ }
+
+ public void testBinaryRefAddr_TooSmallSize() {
+ BinaryRefAddr addr = null;
+
+ // Test too small size
+ try {
+ addr = new BinaryRefAddr("binary", new byte[] { 2, 3 }, 0, -1);
+ fail("Should throw NegativeArraySizeException here.");
+ } catch (NegativeArraySizeException e) {
+ }
+ TestCase.assertNull(addr);
+ }
+
+ public void testBinaryRefAddr_TooBigSize() {
+ BinaryRefAddr addr = null;
+
+ // Test too big size
+ try {
+ addr = new BinaryRefAddr("binary", new byte[] { 2, 3 }, 0, 3);
+ fail("Should throw ArrayIndexOutOfBoundsException here.");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
+ TestCase.assertNull(addr);
+
+ }
+
+ public void testGetType() {
+ // Test empty type
+ BinaryRefAddr addr = new BinaryRefAddr("", new byte[] { 1 });
+ TestCase.assertEquals("", addr.getType());
+
+ // Other conditions are tested in testBinaryRefAddr_XXX
+ }
+
+ public void testEquals_Simple() {
+ String type = "Binary Address";
+ int count = 10;
+ byte[] address0 = new byte[count];
+ byte[] address1 = new byte[count];
+ Random random = new Random(100);
+ for (int i = 0; i < count; i++) {
+ address0[i] = (byte) random.nextInt();
+ address1[i] = address0[i];
+ }
+ BinaryRefAddr addr0 = new BinaryRefAddr(type, address0);
+ BinaryRefAddr addr1 = new BinaryRefAddr(type, address1);
+ assertTrue(addr0.equals(addr0));
+ assertFalse(addr0.equals(null));
+ assertTrue(addr1.equals(addr0));
+ assertTrue(addr0.equals(addr1));
+ }
+
+ public void testEquals_TypeNull() {
+ int count = 10;
+ byte[] address0 = new byte[count];
+ byte[] address1 = new byte[count];
+ Random random = new Random(10);
+ for (int i = 0; i < count; i++) {
+ address0[i] = (byte) random.nextInt();
+ address1[i] = address0[i];
+ }
+
+ BinaryRefAddr addr0 = new BinaryRefAddr(null, address0);
+ BinaryRefAddr addr1 = new BinaryRefAddr(null, address1);
+ try {
+ boolean result = addr0.equals(addr1);
+ fail("Should throw NullPoinerException.");
+ } catch (NullPointerException e) {
+ }
+ }
+
+ public void testtestEquals_refAddr() {
+ String type = "Binary Type";
+ byte[] address = { 1, 2, 3, 4 };
+ BinaryRefAddr addr = new BinaryRefAddr(type, address);
+ MyRefAddr addr2 = new MyRefAddr(type, address);
+
+ assertFalse(addr.equals(addr2));
+ }
+
+ public void testHashcode_Simple() {
+ String type = "Binary Address";
+
+ int count = 10;
+ byte[] address = new byte[count];
+ Random random = new Random(20);
+ for (int i = 0; i < count; i++) {
+ address[i] = (byte) random.nextInt();
+ }
+
+ int hashCode = type.hashCode();
+ for (int i = 0; i < address.length; i++) {
+ hashCode += address[i];
+ }
+ BinaryRefAddr addr = new BinaryRefAddr(type, address);
+ assertEquals(hashCode, addr.hashCode());
+ }
+
+ public void testHashcode_TypeNull() {
+ int count = 10;
+ byte[] address = { 1, 2, 3, };
+
+ BinaryRefAddr addr = new BinaryRefAddr(null, address);
+ try {
+ int hashCode = addr.hashCode();
+ fail("Should throw NullPointerException.");
+ } catch (NullPointerException e) {
+ }
+
+ }
+
+ public void testGetContent_Simple() {
+ String type = "Binary Address";
+ byte[] address = { 1, 2, 3, 4, 5, 6 };
+ BinaryRefAddr addr = new BinaryRefAddr(type, address);
+
+ assertTrue(java.util.Arrays.equals(address, (byte[]) addr.getContent()));
+ }
+
+ public void testToString() {
+ String type = "Binary Address";
+ byte[] address = { 'a', 3, 0x7F, (byte) 0x80, (byte) 90, (byte) 0xFF };
+
+ BinaryRefAddr addr = new BinaryRefAddr(type, address);
+
+ String str = "The type of the address is: " + type
+ + "\nThe content of the address is:";
+ for (int i = 0; i < address.length; i++) {
+ str += " " + Integer.toHexString(address[i]);
+ }
+ str += "\n";
+ // assertEquals(str, addr.toString());
+ assertNotNull(addr.toString());
+ }
+
+ public void testToString_TypeNull() {
+ byte[] address = { 1, 2, 3, };
+ BinaryRefAddr addr = new BinaryRefAddr(null, address);
+ String str = "The type of the address is: null"
+ + "\nThe content of the address is: 1 2 3\n";
+ // assertEquals(str, addr.toString());
+ assertNotNull(addr.toString());
+ }
+
+ public void testSerializable_Simple() throws ClassNotFoundException,
+ IOException {
+ String type = "Binary Address";
+ int count = 10;
+ byte[] address = new byte[count];
+ Random random = new Random(20);
+ for (int i = 0; i < count; i++) {
+ address[i] = (byte) random.nextInt();
+ }
+ BinaryRefAddr addr = new BinaryRefAddr(type, address);
+
+ // write to byte array
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(addr);
+ byte[] buffer = baos.toByteArray();
+ oos.close();
+ baos.close();
+
+ // read from byte array
+ ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ BinaryRefAddr addr2 = (BinaryRefAddr) ois.readObject();
+ ois.close();
+ bais.close();
+
+ assertEquals(addr, addr2);
+ }
+
+ public void testSerializable_compatibility() throws ClassNotFoundException,
+ IOException {
+ // TO DO R: need to implement
+ ObjectInputStream ois = new ObjectInputStream(getClass()
+ .getClassLoader().getResourceAsStream("data/BinaryRefAddr.ser"));
+ BinaryRefAddr addr = (BinaryRefAddr) ois.readObject();
+ ois.close();
+
+ String type = "Binary Address";
+ int count = 100;
+ byte[] address = new byte[count];
+ for (int i = 0; i < count; i++) {
+ address[i] = (byte) i;
+ }
+ BinaryRefAddr addr2 = new BinaryRefAddr(type, address);
+ assertEquals(addr, addr2);
+ }
+
+ class MyRefAddr extends RefAddr {
+ byte[] address;
+
+ public MyRefAddr(String type, byte[] address) {
+ super(type);
+ this.address = new byte[address.length];
+ System.arraycopy(address, 0, this.address, 0, address.length);
+ }
+
+ public Object getContent() {
+ return address;
+ }
+ }
+}
\ No newline at end of file
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestBinding.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestBinding.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestBinding.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestBinding.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,133 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.javax.naming;
+
+import javax.naming.Binding;
+
+import junit.framework.TestCase;
+import tests.api.javax.naming.util.Log;
+
+public class TestBinding extends TestCase {
+
+ private static Log log = new Log(TestBinding.class);
+
+ /**
+ * Constructor for TestBinding.
+ *
+ * @param arg0
+ */
+ public TestBinding(String arg0) {
+ super(arg0);
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testConstructor_Simple() {
+ Binding p;
+
+ p = new Binding("name1", new Integer(1));
+ assertEquals("name1", p.getName());
+ assertEquals("java.lang.Integer", p.getClassName());
+ assertEquals(new Integer(1), p.getObject());
+ assertEquals(true, p.isRelative());
+ }
+
+ public void testConstructor_NullValue() {
+ Binding p;
+ p = new Binding(null, null, null);
+ assertTrue(null == p.getName());
+ assertTrue(null == p.getClassName());
+ assertTrue(null == p.getObject());
+ }
+
+ public void testConstructor_DefaultRelativeValue() {
+ Binding p;
+
+ p = new Binding(null, null);
+ assertEquals(true, p.isRelative());
+ }
+
+ public void testToString() {
+ log.setMethod("testToString");
+ Binding p;
+ p = new Binding(null, null, false);
+ assertTrue(p.toString().startsWith("(not relative"));
+ p = new Binding("name1", new Integer(3));
+ String str = p.toString();
+ assertTrue(str.indexOf("name1") > -1);
+ assertTrue(str.indexOf("3") > -1);
+ assertTrue(str.indexOf("java.lang.Integer") > -1);
+ }
+
+ public void testGetSetObject() {
+ Binding p;
+ log.setMethod("testGetSetObject");
+ p = new Binding("name", null);
+ p.setObject(new Integer(2));
+ assertEquals(new Integer(2), p.getObject());
+ assertEquals("java.lang.Integer", p.getClassName());
+ p.setObject(null);
+ assertNull(p.getObject());
+ assertNull(p.getClassName());
+ p.setObject(new Float(2));
+ assertEquals(new Float(2), p.getObject());
+ assertEquals(Float.class.getName(), p.getClassName());
+ p.setObject(null);
+ assertNull(p.getObject());
+ assertNull(p.getClassName());
+ }
+
+ public void testGetSetName() {
+ Binding p = new Binding("name", new Integer(1));
+
+ assertEquals("name", p.getName());
+ p.setName("name1");
+ assertEquals("name1", p.getName());
+ p.setName("");
+ assertEquals("", p.getName());
+ p.setName(null);
+ assertEquals(null, p.getName());
+ }
+
+ public void testGetSetClassName() {
+ Binding p;
+
+ p = new Binding("name", new Integer(1));
+ assertEquals(Integer.class.getName(), p.getClassName());
+ p.setClassName(Character.class.getName());
+ assertEquals(Character.class.getName(), p.getClassName());
+ }
+
+ public void testGetSetRelative() {
+ Binding p;
+ p = new Binding("name", new Integer(1));
+ assertTrue(p.isRelative());
+ p.setRelative(false);
+ assertFalse(p.isRelative());
+ }
+
+}
\ No newline at end of file
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestCannotProceedException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestCannotProceedException.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestCannotProceedException.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestCannotProceedException.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,76 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.javax.naming;
+
+import java.util.Hashtable;
+
+import javax.naming.CannotProceedException;
+import javax.naming.CompositeName;
+import javax.naming.Context;
+import javax.naming.InvalidNameException;
+import javax.naming.Name;
+
+import tests.api.javax.naming.util.Log;
+import junit.framework.TestCase;
+
+public class TestCannotProceedException extends TestCase {
+
+ static private Log log = new Log(TestCannotProceedException.class);
+
+ /**
+ * Constructor for TestCannotProceedException.
+ *
+ * @param arg0
+ */
+ public TestCannotProceedException(String arg0) {
+ super(arg0);
+ }
+
+ public void testConstructorAndGetterSetter() throws InvalidNameException {
+ log.setMethod("testConstructorAndGetterSetter()");
+
+ CannotProceedException cpe = new CannotProceedException();
+ Name altName = new CompositeName("1");
+ Context altContext = null;
+ Hashtable h = new Hashtable();
+ Name newName = new CompositeName("2");
+
+ cpe.setAltName(altName);
+ assertEquals(altName, cpe.getAltName());
+
+ cpe.setAltNameCtx(altContext);
+ assertEquals(altContext, cpe.getAltNameCtx());
+
+ cpe.setEnvironment(h);
+ assertEquals(h, cpe.getEnvironment());
+
+ cpe.setRemainingNewName(newName);
+ assertEquals(newName, cpe.getRemainingNewName());
+ }
+
+ public void testConstructor_defaultValue() {
+ CannotProceedException cpe = new CannotProceedException();
+ assertNull(cpe.getMessage());
+ assertNull(cpe.getAltName());
+ assertNull(cpe.getAltNameCtx());
+ assertNull(cpe.getEnvironment());
+ assertNull(cpe.getRemainingNewName());
+ }
+
+ public void testGetEnvironment() {
+ CannotProceedException exception = new CannotProceedException("Test");
+ assertNull(exception.getEnvironment());
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestCompositeName.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestCompositeName.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestCompositeName.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestCompositeName.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,666 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.javax.naming;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import javax.naming.CompositeName;
+import javax.naming.CompoundName;
+import javax.naming.InvalidNameException;
+import javax.naming.Name;
+
+import junit.framework.TestCase;
+import tests.api.javax.naming.util.Log;
+
+/**
+ * unit test for composite name
+ *
+ */
+public class TestCompositeName extends TestCase {
+
+ /*
+ * -------------------------------------------------------------------
+ * Constants
+ * -------------------------------------------------------------------
+ */
+ private static Log log = new Log(TestCompositeName.class);
+
+ private static final char SEPARATOR = '/';
+
+ /*
+ * -------------------------------------------------------------------
+ * Instance variables (Should be private)
+ * -------------------------------------------------------------------
+ */
+ private CompositeName name;
+
+ private String[] elements = { "www.apache.org", "gbank" };
+
+ private String initName;
+
+ private Properties props;
+
+ /**
+ * Constructor for TestCompositeName.
+ *
+ * @param arg0
+ */
+ public TestCompositeName(String arg0) {
+ super(arg0);
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < elements.length; i++) {
+ sb.append(elements[i]).append(SEPARATOR);
+ }
+ initName = sb.toString();
+ }
+
+ /*
+ * -------------------------------------------------------------------
+ * Methods
+ * -------------------------------------------------------------------
+ */
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ name = new CompositeName(initName);
+ props = new Properties();
+ props.put("jndi.syntax.separator", "/");
+ props.put("jndi.syntax.direction", "left_to_right");
+ props.put("jndi.syntax.escape", "\\");
+ props.put("jndi.syntax.beginquote", "<");
+ props.put("jndi.syntax.endquote", ">");
+ props.put("jndi.syntax.beginquote2", "'");
+ props.put("jndi.syntax.endquote2", "'");
+ props.put("jndi.syntax.ignorecase", "false");
+ props.put("jndi.syntax.trimblanks", "false");
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * test constructor with null string parameter
+ *
+ * @throws InvalidNameException
+ */
+ public void TestConstructorNull() throws InvalidNameException {
+ log.setMethod("TestConstructorNull");
+ try {
+ name = new CompositeName((String) null);
+ log.log("fail: try to construct a compositename with null succeed");
+ fail();
+ } catch (NullPointerException e) {
+ }
+ }
+
+ public void testConstructorSimple() throws InvalidNameException {
+ assertNameEquals(new CompositeName("a/b/c"), new String[] { "a", "b",
+ "c" });
+ }
+
+ public void testConstructorException() throws InvalidNameException {
+ try {
+ name = new CompositeName("'abc'd/ef");
+ fail();
+ } catch (InvalidNameException e) {
+ }
+ name = new CompositeName("abc'abc'/ab");
+ assertNameEquals(name, new String[] { "abc'abc'", "ab" });
+ }
+
+ /**
+ * test toString()
+ *
+ * @throws InvalidNameException
+ */
+ public void testToString() throws InvalidNameException {
+ log.setMethod("testToString()");
+ assertEquals("", new CompositeName("").toString());
+ assertEquals("/", new CompositeName("/").toString());
+ assertEquals("//", new CompositeName("//").toString());
+ assertEquals("/a/", new CompositeName("/a/").toString());
+ name.add("abc\"abc");
+ assertEquals(4, name.size());
+ name.add("abc/abc");
+ assertEquals(5, name.size());
+ name.add("abc\\abc");
+ assertEquals(6, name.size());
+ assertEquals(new CompositeName(name.toString()), name);
+ assertNameEquals(name, new String[] { "www.apache.org", "gbank",
+ "", "abc\"abc", "abc/abc", "abc\\abc" });
+ }
+
+ /**
+ * test getAll()
+ *
+ */
+ public void testGetAll() {
+ log.setMethod("testGetAll()");
+ Enumeration enumeration = name.getAll();
+ for (int j = 0; j < elements.length; j++) {
+ assertTrue(elements[j].equals(enumeration.nextElement()));
+ }
+ assertTrue("".equals(enumeration.nextElement()));
+ }
+
+ /**
+ * test get()
+ *
+ */
+ public void testGet() {
+ log.setMethod("testGet()");
+ for (int j = 0; j < elements.length; j++) {
+ assertEquals(elements[j], name.get(j));
+ }
+ try {
+ name.get(-1);
+ fail();
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
+ try {
+ name.get(name.size());
+ fail();
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
+ }
+
+ /**
+ * test getPrefix()
+ *
+ */
+ public void testGetPrefix() {
+ log.setMethod("testGetPrefix()");
+ Name prefix = name.getPrefix(0);
+ assertEquals("", prefix.toString());
+ try {
+ name.getPrefix(elements.length + 2);
+ fail("name.getPrefix(elements.length + 2)");
+ } catch (IndexOutOfBoundsException e) {
+ }
+ try {
+ name.getPrefix(-1);
+ fail("name.getPrefix(-1)");
+ } catch (IndexOutOfBoundsException e) {
+ }
+ prefix = name.getPrefix(1);
+ assertEquals(elements[0], prefix.toString());
+ }
+
+ /**
+ * test getSuffix
+ *
+ */
+ public void testGetSuffix() {
+ log.setMethod("testGetSuffix()");
+ Name suffix = name.getSuffix(elements.length + 1);
+ assertEquals("", suffix.toString());
+ try {
+ name.getSuffix(elements.length + 2);
+ fail("name.getSuffix(elements.length + 2)");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
+ try {
+ name.getSuffix(-1);
+ fail("name.getSuffix(-1)");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
+ suffix = name.getSuffix(2);
+ assertEquals("/", suffix.toString());
+ }
+
+ /**
+ * Test addAll(Name), include exceptional case
+ */
+ public void testAddAllName() throws InvalidNameException {
+ log.setMethod("testAddAllName()");
+ int oldSize = name.size();
+ name.addAll(new CompositeName(initName));
+ assertEquals(name.size(), oldSize * 2);
+ assertEquals(name.getPrefix(3).toString(), name.getSuffix(3).toString());
+ assertEquals(name.getPrefix(3).toString(), initName);
+ name = new CompositeName("a");
+ try {
+ name.addAll(new CompoundName("b/c", props));
+ fail("name.addAll(new CompoundName(\"b/c\", props));");
+ } catch (InvalidNameException t) {
+ }
+ try {
+ name.addAll(null);
+ fail("Add null should throw NullPointerException");
+ } catch (NullPointerException e) {
+ }
+ }
+
+ /**
+ * test addAll(int), include exceptional case
+ */
+ public void testAddAllintName() throws InvalidNameException {
+ log.setMethod("testAddAllintName()");
+ int oldSize = name.size();
+ name.addAll(1, new CompositeName(initName));
+ assertEquals(name.size(), oldSize * 2);
+ assertEquals(name.getSuffix(1).getPrefix(3).toString(), initName);
+ name = new CompositeName("a");
+ try {
+ name.addAll(0, new CompoundName("b/c", props));
+ fail("name.addAll(0, new CompoundName(\"b/c\", props));");
+ } catch (InvalidNameException t) {
+ }
+ try {
+ name.addAll(0, null);
+ fail("Add null should throw NullPointerException");
+ } catch (NullPointerException e) {
+ }
+ try {
+ name.addAll(-1, new CompositeName(initName));
+ fail("-1 should be out of bound.");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
+ try {
+ name.addAll(name.size() + 1, new CompositeName(initName));
+ fail((name.size() + 1) + " should out of bound.");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
+ }
+
+ /**
+ * test add(String), include exceptional case of null parameter
+ */
+ public void testAddString() throws InvalidNameException {
+ log.setMethod("testAddString()");
+ int oldSize = name.size();
+ name.add(elements[0]);
+ assertEquals(name.size(), oldSize + 1);
+ assertEquals(elements[0], name.getSuffix(3).toString());
+ name.add(null);
+ assertEquals(name.size(), oldSize + 2);
+ try {
+ assertEquals(null, name.getSuffix(4).toString());
+ fail();
+ } catch (NullPointerException e) {
+ }
+
+ }
+
+ /**
+ * Test add(int, String), include boundary case
+ */
+ public void testAddintString() throws InvalidNameException {
+ log.setMethod("testAddintString()");
+ int oldSize = name.size();
+ name.add(1, elements[0]);
+ assertEquals(name.size(), oldSize + 1);
+ assertEquals(name.getSuffix(1).toString(), initName);
+ try {
+ name.add(oldSize + 2, elements[0]);
+ fail();
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
+ try {
+ name.add(-1, elements[0]);
+ fail();
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
+ }
+
+ /**
+ * test remove, include boundary case
+ *
+ * @throws InvalidNameException
+ */
+ public void testRemove() throws InvalidNameException {
+ log.setMethod("testRemove()");
+ int oldSize = name.size();
+ name.remove(1);
+ assertEquals(name.size(), oldSize - 1);
+ assertEquals(name.toString(), elements[0] + "/");
+ try {
+ name.remove(-1);
+ fail();
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
+ try {
+ name.remove(oldSize - 1);
+ fail();
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
+
+ }
+
+ /**
+ * test size()
+ *
+ * @throws InvalidNameException
+ */
+ public void testSize() throws InvalidNameException {
+ log.setMethod("testSize()");
+ assertEquals(elements.length + 1, name.size());
+ name = new CompositeName("/");
+ assertEquals(1, name.size());
+ }
+
+ /**
+ * test isEmpty()
+ *
+ * @throws InvalidNameException
+ */
+ public void testIsEmpty() throws InvalidNameException {
+ log.setMethod("testIsEmpty()");
+ assertFalse(name.isEmpty());
+ for (int i = 0; i < elements.length; i++) {
+ name.remove(0);
+ }
+ name.remove(0);
+ assertTrue(name.isEmpty());
+ name = new CompositeName("");
+ assertTrue(name.isEmpty());
+
+ }
+
+ /**
+ * test startWith(), include exceptional case of null and CompoundName
+ *
+ * @throws InvalidNameException
+ */
+ public void testStartsWith() throws InvalidNameException {
+ log.setMethod("testStartsWith()");
+ CompositeName start = new CompositeName(elements[0]);
+ assertTrue(name.startsWith(start));
+ start = new CompositeName(elements[1]);
+ assertFalse(name.startsWith(start));
+ try {
+ assertFalse(name.startsWith(null));
+ } catch (Throwable e) {
+ log.log("start with null?", e);
+ }
+ try {
+ assertFalse(name.startsWith(new CompoundName(elements[0], props)));
+ } catch (Throwable e) {
+ log.log("start with compoundName?", e);
+ }
+ }
+
+ /**
+ * test endsWith(), include exceptional case of null and CompoundName
+ *
+ * @throws InvalidNameException
+ */
+ public void testEndsWith() throws InvalidNameException {
+ log.setMethod("testEndsWith()");
+ CompositeName end = new CompositeName("");
+ assertTrue(name.endsWith(end));
+ end = new CompositeName("12345");
+ assertFalse(name.endsWith(end));
+ try {
+ name.endsWith(null);
+ } catch (Throwable e) {
+ log.log("end with null?", e);
+ }
+ try {
+ assertFalse(name.endsWith(new CompoundName("", props)));
+ } catch (Throwable e) {
+ log.log("end with compoundName?", e);
+ }
+ }
+
+ /**
+ * Special characters are as follows: The separator is / The escape
+ * character is \ Quotes can be used - both single quotes and double quotes
+ * are allowed. This allows you to quote strings which contain chars such as /
+ * which are part of a CompositeName element to avoid them being read as a
+ * separator.
+ *
+ * @throws InvalidNameException
+ */
+ public void testSpecialCharacter() throws InvalidNameException {
+ log.setMethod("testSpecialCharacter()");
+ // The name "a//a" has 3 elements. The middle element is empty and the
+ // first & third elements are both "a".
+ name = new CompositeName("a//a");
+ Enumeration enumeration = name.getAll();
+ assertEquals("a", enumeration.nextElement());
+ assertEquals("", enumeration.nextElement());
+ assertEquals("a", enumeration.nextElement());
+
+ // The name "a/'b/c'/a" has 3 elements. The middle element is b/c.
+ name = new CompositeName("a/'b/c'/a");
+ enumeration = name.getAll();
+ assertEquals("a", enumeration.nextElement());
+ assertEquals("b/c", enumeration.nextElement());
+ assertEquals("a", enumeration.nextElement());
+
+ name = new CompositeName("a/a'b/c'c/a");
+ enumeration = name.getAll();
+ assertEquals("a", enumeration.nextElement());
+ assertEquals("a'b", enumeration.nextElement());
+ assertEquals("c'c", enumeration.nextElement());
+ assertEquals("a", enumeration.nextElement());
+ name = new CompositeName("a/a'b/c'/a/\\abc/ab\\\"c");
+ enumeration = name.getAll();
+ assertEquals("a", enumeration.nextElement());
+ assertEquals("a'b", enumeration.nextElement());
+ assertEquals("c'", enumeration.nextElement());
+ assertEquals("a", enumeration.nextElement());
+ assertEquals("\\abc", enumeration.nextElement());
+ assertEquals("ab\"c", enumeration.nextElement());
+
+ name = new CompositeName("\"ab/c\"/ab");
+ assertNameEquals(name, new String[] { "ab/c", "ab" });
+
+ // The name "a/'b/a" is invalid as there is no closing quote for the '
+ // character.
+ try {
+ name = new CompositeName("a/'b/a");
+ fail("a/'b/a");
+ } catch (InvalidNameException e) {
+ }
+
+ // The name "a/\"b/a" is interpreted as a/"b/a and is invalid as there
+ // is no closing quote for the embedded escaped " character.
+ try {
+ name = new CompositeName("a/\"'b/a");
+ fail("a/\"'b/a");
+ } catch (InvalidNameException e) {
+ }
+ try {
+ name = new CompositeName("a/bcd/a\\");
+ fail("a/bcd/a\\");
+ } catch (InvalidNameException e) {
+ }
+ }
+
+ /**
+ * test equals, include exceptional case, i.e, CompoundName, null, etc.
+ *
+ * @throws InvalidNameException
+ */
+ public void testEquals() throws InvalidNameException {
+ log.setMethod("testEquals()");
+ Name name2 = null;
+ name2 = new CompositeName(initName);
+ assertTrue(name.equals(name2));
+ assertTrue(name2.equals(name));
+ name2.add("abc");
+ assertFalse(name2.equals(name));
+ name2 = new CompoundName("abc", props);
+ name = new CompositeName("abc");
+ assertFalse(name.equals(name2));
+ assertFalse(name.equals(null));
+ assertTrue(name.equals(name));
+ }
+
+ /**
+ * test compareTo(), include exceptional case, i.e, CompoundName, null, etc.
+ *
+ * @throws InvalidNameException
+ */
+ public void testCompareTo() throws InvalidNameException {
+ log.setMethod("testCompareTo()");
+ Name name1 = new CompositeName("a/b/c/d");
+ Name name2 = new CompositeName("ab/b/c/d");
+ Name name3 = new CompositeName("a/b/c/d/e");
+ Name name4 = new CompositeName("b/b/c/d");
+ assertEquals(-1, name1.compareTo(name2));
+ assertEquals(1, name3.compareTo(name1));
+ assertEquals(-1, name1.compareTo(name4));
+ assertEquals(name1.compareTo(name1), 0);
+ try {
+ name1.compareTo(null);
+ fail();
+ } catch (ClassCastException e) {
+ }
+ name2 = new CompoundName("a/b/c/d", props);
+ try {
+ name1.compareTo(name2);
+ fail();
+ } catch (ClassCastException e) {
+ }
+ }
+
+ /**
+ * test hashCode()
+ *
+ * @throws InvalidNameException
+ */
+ public void testHashCode() throws InvalidNameException {
+ log.setMethod("testHashCode()");
+ Name name2 = new CompositeName(initName);
+ assertEquals(name.hashCode(), name2.hashCode());
+ assertEquals(767782430, name2.hashCode());
+ name2 = new CompositeName("a");
+ assertEquals(97, name2.hashCode());
+ }
+
+ /**
+ * test serialization
+ *
+ * @throws Exception
+ */
+ public void testWriteReadObject() throws Exception {
+ log.setMethod("testWriteReadObject()");
+ CompositeName name = new CompositeName("a/b/c/d");
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ ObjectOutputStream stream = new ObjectOutputStream(bout);
+ stream.writeObject(name);
+ stream.close();
+ ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(
+ bout.toByteArray()));
+ CompositeName name2 = (CompositeName) in.readObject();
+ assertTrue(name.equals(name2));
+ in.close();
+ }
+
+ /**
+ * utility method for name assertion
+ *
+ * @param n
+ * @param elems
+ */
+ private void assertNameEquals(Name n, String[] elems) {
+
+ try {
+ // compare
+ assertEquals(elems.length, n.size());
+
+ for (int i = 0; i < n.size(); i++) {
+ assertEquals(elems[i], n.get(i));
+ }
+
+ int i = 0;
+ Enumeration enumeration = n.getAll();
+ while (enumeration.hasMoreElements()) {
+ assertEquals(elems[i++], enumeration.nextElement());
+ }
+ } catch (RuntimeException e) {
+ // log
+ StringBuffer buf = new StringBuffer();
+ buf.append("Assert name ");
+ buf.append(n.toString());
+ buf.append(" has elements [" + elems.length + "]{");
+ for (int i = 0; i < elems.length; i++) {
+ if (i > 0) {
+ buf.append(",");
+ }
+ buf.append(elems[i]);
+ }
+ buf.append("}");
+ log.log(buf.toString());
+
+ throw e;
+ }
+ }
+
+ /**
+ * test serialization compatibility
+ *
+ * @throws Exception
+ */
+ public void testSerializationCompatibility() throws Exception {
+ log.setMethod("testSerializationCompatibility()");
+
+ try {
+ ObjectInputStream in = new ObjectInputStream(getClass()
+ .getResourceAsStream("/data/CompositeName.ser"));
+ CompositeName name = (CompositeName) in.readObject();
+ assertEquals(new CompositeName("a/b/c/d"), name);
+ in.close();
+ } catch (Exception e) {
+ log.log(e);
+ throw e;
+ }
+ }
+
+ /**
+ * test clone
+ *
+ */
+ public void testClone() throws InvalidNameException {
+ CompositeName name = new CompositeName("a/b/c/d");
+ CompositeName name2 = (CompositeName) name.clone();
+ assertEquals(name, name2);
+ name.add(1, elements[0]);
+ assertFalse(name.equals(name2));
+ }
+
+ public void testConstructorEnum() {
+ log.setMethod("testConstructorEnum");
+ CompositeName name2 = new MockCompositeName(name.getAll());
+ assertEquals(name2, name);
+ try {
+ name2 = new MockCompositeName((Enumeration) null);
+ fail();
+ } catch (NullPointerException e) {
+ }
+ }
+
+ // mock class to test protected methods
+ public class MockCompositeName extends CompositeName {
+ public MockCompositeName(Enumeration enumeration) {
+ super(enumeration);
+ }
+ }
+}