summaryrefslogtreecommitdiffstats
path: root/java/sdo/sdo-api/src/test
diff options
context:
space:
mode:
authordims <dims@13f79535-47bb-0310-9956-ffa450edef68>2008-06-17 00:23:01 +0000
committerdims <dims@13f79535-47bb-0310-9956-ffa450edef68>2008-06-17 00:23:01 +0000
commitbdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a (patch)
tree38a92061c0793434c4be189f1d70c3458b6bc41d /java/sdo/sdo-api/src/test
Move Tuscany from Incubator to top level.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sdo/sdo-api/src/test')
-rw-r--r--java/sdo/sdo-api/src/test/java/commonj/sdo/impl/HelperProviderTestCase.java93
-rw-r--r--java/sdo/sdo-api/src/test/java/test/DefaultHelperProvider.java71
-rw-r--r--java/sdo/sdo-api/src/test/java/test/TCCL1HelperProvider.java71
-rw-r--r--java/sdo/sdo-api/src/test/resources/default/META-INF/services/commonj.sdo.impl.HelperProvider3
-rw-r--r--java/sdo/sdo-api/src/test/resources/tccl1/META-INF/services/commonj.sdo.impl.HelperProvider1
5 files changed, 239 insertions, 0 deletions
diff --git a/java/sdo/sdo-api/src/test/java/commonj/sdo/impl/HelperProviderTestCase.java b/java/sdo/sdo-api/src/test/java/commonj/sdo/impl/HelperProviderTestCase.java
new file mode 100644
index 0000000000..a434f6f989
--- /dev/null
+++ b/java/sdo/sdo-api/src/test/java/commonj/sdo/impl/HelperProviderTestCase.java
@@ -0,0 +1,93 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 commonj.sdo.impl;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import junit.framework.TestCase;
+import test.DefaultHelperProvider;
+import test.TCCL1HelperProvider;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class HelperProviderTestCase extends TestCase {
+ private URL classes;
+ private URL testClasses;
+ private URL def;
+ private URL tccl1;
+
+ public void testInstanceIsNullWithNoImplementation() throws Exception {
+ assertNull(HelperProvider.INSTANCE);
+ }
+
+ public void testDefaultInstance() throws Exception {
+ ClassLoader cl = new URLClassLoader(new URL[]{classes, def, testClasses}, null);
+ Class providerClass = cl.loadClass(HelperProvider.class.getName());
+ Class implClass = cl.loadClass(DefaultHelperProvider.class.getName());
+ Object instance = providerClass.getField("INSTANCE").get(null);
+ assertNotNull(instance);
+ assertEquals(implClass, instance.getClass());
+ }
+
+ public void testLocateFromClassLoader() throws Exception {
+ ClassLoader cl = new URLClassLoader(new URL[]{classes, tccl1, testClasses}, null);
+ Class providerClass = cl.loadClass(HelperProvider.class.getName());
+ Object provider = providerClass.getMethod("getInstance", new Class[] {ClassLoader.class})
+ .invoke(null, new Object[] {cl});
+ assertNotNull(provider);
+ assertEquals(TCCL1HelperProvider.class.getName(), provider.getClass().getName());
+ }
+
+ public void testThreadContextInstance() throws Exception {
+ ClassLoader cl = new URLClassLoader(new URL[]{classes, tccl1, testClasses}, null);
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(cl);
+ Class providerClass = cl.loadClass(HelperProvider.class.getName());
+ Object provider = providerClass.getMethod("getInstance", new Class[0]).invoke(null, new Object[0]);
+ assertNotNull(provider);
+ assertEquals(TCCL1HelperProvider.class.getName(), provider.getClass().getName());
+ } finally {
+ Thread.currentThread().setContextClassLoader(tccl);
+ }
+
+ }
+
+ public void testSystemProperty() {
+ System.setProperty("commonj.sdo.impl.HelperProvider", "test.TCCL1HelperProvider");
+ try {
+ HelperProvider provider = HelperProvider.getInstance();
+ assertNotNull(provider);
+ assertEquals(TCCL1HelperProvider.class, provider.getClass());
+ } finally {
+ System.getProperties().remove("commonj.sdo.impl.HelperProvider");
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ classes = new URL(HelperProvider.class.getResource("HelperProvider.class"), "../../..");
+ testClasses = new URL(HelperProviderTestCase.class.getResource("HelperProviderTestCase.class"), "../../..");
+ tccl1 = new URL(testClasses, "tccl1/");
+ def = new URL(testClasses, "default/");
+ }
+}
diff --git a/java/sdo/sdo-api/src/test/java/test/DefaultHelperProvider.java b/java/sdo/sdo-api/src/test/java/test/DefaultHelperProvider.java
new file mode 100644
index 0000000000..77d6206972
--- /dev/null
+++ b/java/sdo/sdo-api/src/test/java/test/DefaultHelperProvider.java
@@ -0,0 +1,71 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 test;
+
+import commonj.sdo.impl.HelperProvider;
+import commonj.sdo.impl.ExternalizableDelegator;
+import commonj.sdo.helper.CopyHelper;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.DataHelper;
+import commonj.sdo.helper.EqualityHelper;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XSDHelper;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class DefaultHelperProvider extends HelperProvider {
+ public CopyHelper copyHelper() {
+ throw new UnsupportedOperationException();
+ }
+
+ public DataFactory dataFactory() {
+ throw new UnsupportedOperationException();
+ }
+
+ public DataHelper dataHelper() {
+ throw new UnsupportedOperationException();
+ }
+
+ public EqualityHelper equalityHelper() {
+ throw new UnsupportedOperationException();
+ }
+
+ public TypeHelper typeHelper() {
+ throw new UnsupportedOperationException();
+ }
+
+ public XMLHelper xmlHelper() {
+ throw new UnsupportedOperationException();
+ }
+
+ public XSDHelper xsdHelper() {
+ throw new UnsupportedOperationException();
+ }
+
+ public ExternalizableDelegator.Resolvable resolvable() {
+ throw new UnsupportedOperationException();
+ }
+
+ public ExternalizableDelegator.Resolvable resolvable(Object target) {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/java/sdo/sdo-api/src/test/java/test/TCCL1HelperProvider.java b/java/sdo/sdo-api/src/test/java/test/TCCL1HelperProvider.java
new file mode 100644
index 0000000000..05b1b04925
--- /dev/null
+++ b/java/sdo/sdo-api/src/test/java/test/TCCL1HelperProvider.java
@@ -0,0 +1,71 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 test;
+
+import commonj.sdo.impl.HelperProvider;
+import commonj.sdo.impl.ExternalizableDelegator;
+import commonj.sdo.helper.CopyHelper;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.DataHelper;
+import commonj.sdo.helper.EqualityHelper;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XSDHelper;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class TCCL1HelperProvider extends HelperProvider {
+ public CopyHelper copyHelper() {
+ throw new UnsupportedOperationException();
+ }
+
+ public DataFactory dataFactory() {
+ throw new UnsupportedOperationException();
+ }
+
+ public DataHelper dataHelper() {
+ throw new UnsupportedOperationException();
+ }
+
+ public EqualityHelper equalityHelper() {
+ throw new UnsupportedOperationException();
+ }
+
+ public TypeHelper typeHelper() {
+ throw new UnsupportedOperationException();
+ }
+
+ public XMLHelper xmlHelper() {
+ throw new UnsupportedOperationException();
+ }
+
+ public XSDHelper xsdHelper() {
+ throw new UnsupportedOperationException();
+ }
+
+ public ExternalizableDelegator.Resolvable resolvable() {
+ throw new UnsupportedOperationException();
+ }
+
+ public ExternalizableDelegator.Resolvable resolvable(Object target) {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/java/sdo/sdo-api/src/test/resources/default/META-INF/services/commonj.sdo.impl.HelperProvider b/java/sdo/sdo-api/src/test/resources/default/META-INF/services/commonj.sdo.impl.HelperProvider
new file mode 100644
index 0000000000..5175e5abea
--- /dev/null
+++ b/java/sdo/sdo-api/src/test/resources/default/META-INF/services/commonj.sdo.impl.HelperProvider
@@ -0,0 +1,3 @@
+# test comment and blank line
+
+ test.DefaultHelperProvider # comment
diff --git a/java/sdo/sdo-api/src/test/resources/tccl1/META-INF/services/commonj.sdo.impl.HelperProvider b/java/sdo/sdo-api/src/test/resources/tccl1/META-INF/services/commonj.sdo.impl.HelperProvider
new file mode 100644
index 0000000000..fa88e4c705
--- /dev/null
+++ b/java/sdo/sdo-api/src/test/resources/tccl1/META-INF/services/commonj.sdo.impl.HelperProvider
@@ -0,0 +1 @@
+test.TCCL1HelperProvider