summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/tags/0.99-incubating/modules/contribution-java/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-1.x/tags/0.99-incubating/modules/contribution-java/src/test/java/org')
-rw-r--r--sca-java-1.x/tags/0.99-incubating/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java75
-rw-r--r--sca-java-1.x/tags/0.99-incubating/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java92
-rw-r--r--sca-java-1.x/tags/0.99-incubating/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java93
3 files changed, 260 insertions, 0 deletions
diff --git a/sca-java-1.x/tags/0.99-incubating/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java b/sca-java-1.x/tags/0.99-incubating/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java
new file mode 100644
index 0000000000..f0e74b363a
--- /dev/null
+++ b/sca-java-1.x/tags/0.99-incubating/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java
@@ -0,0 +1,75 @@
+ /*
+ * 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 org.apache.tuscany.sca.contribution.java.impl;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolverExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
+
+/**
+ * Test ClassReferenceArtifactResolver.
+ *
+ * @version $Rev: 560435 $ $Date: 2007-07-27 18:26:55 -0700 (Fri, 27 Jul 2007) $
+ */
+public class ClassReferenceArtifactResolverTestCase extends TestCase {
+ private ExtensibleModelResolver resolver;
+
+ @Override
+ protected void setUp() throws Exception {
+
+ ModelResolverExtensionPoint resolvers = new DefaultModelResolverExtensionPoint();
+ resolvers.addResolver(ClassReference.class, ClassReferenceModelResolver.class);
+
+ ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint();
+
+ resolver = new ExtensibleModelResolver(null, resolvers, factories);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ }
+
+ /**
+ * Test ClassReference resolution
+ *
+ */
+ public void testResolveClass() {
+ ClassReference ref = new ClassReference(getClass().getName());
+ ClassReference clazz = resolver.resolveModel(ClassReference.class, ref);
+ assertFalse(clazz.isUnresolved());
+ assertTrue(clazz.getJavaClass() == getClass());
+ }
+
+ /**
+ * Test ClassReference resolution of inexistent class
+ *
+ */
+ public void testUnresolvedClass() {
+ ClassReference ref = new ClassReference("NonExistentClass");
+ ClassReference clazz = resolver.resolveModel(ClassReference.class, ref);
+ assertTrue(clazz.isUnresolved());
+ assertTrue(clazz.getJavaClass() == null);
+ }
+}
diff --git a/sca-java-1.x/tags/0.99-incubating/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java b/sca-java-1.x/tags/0.99-incubating/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java
new file mode 100644
index 0000000000..81c7ee525a
--- /dev/null
+++ b/sca-java-1.x/tags/0.99-incubating/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java
@@ -0,0 +1,92 @@
+/*
+ * 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 org.apache.tuscany.sca.contribution.java.impl;
+
+import java.io.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.java.JavaExport;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+
+/**
+ * Test JavaExportProcessorTestCase
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaExportProcessorTestCase extends TestCase {
+
+ private static final String VALID_XML =
+ "<?xml version=\"1.0\" encoding=\"ASCII\"?>"
+ + "<contribution xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\">"
+ + "<export.java package=\"org.apache.tuscany.sca.contribution.java\"/>"
+ + "</contribution>";
+
+ private static final String INVALID_XML =
+ "<?xml version=\"1.0\" encoding=\"ASCII\"?>"
+ + "<contribution xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\">"
+ + "<export.java/>"
+ + "</contribution>";
+
+ private XMLInputFactory xmlFactory;
+
+ @Override
+ protected void setUp() throws Exception {
+ xmlFactory = XMLInputFactory.newInstance();
+ }
+
+ /**
+ * Test loading a valid export element from a contribution metadata stream
+ * @throws Exception
+ */
+ public void testLoad() throws Exception {
+ XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(VALID_XML));
+
+ ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint();
+ factories.addFactory(new JavaImportExportFactoryImpl());
+ JavaExportProcessor exportProcessor = new JavaExportProcessor(factories);
+ JavaExport javaExport = exportProcessor.read(reader);
+
+ assertEquals("org.apache.tuscany.sca.contribution.java", javaExport.getPackage());
+ }
+
+ /**
+ * Test loading an INVALID export element from a contribution metadata stream
+ * @throws Exception
+ */
+ public void testLoadInvalid() throws Exception {
+ XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(INVALID_XML));
+
+ ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint();
+ factories.addFactory(new JavaImportExportFactoryImpl());
+ JavaExportProcessor exportProcessor = new JavaExportProcessor(factories);
+ try {
+ exportProcessor.read(reader);
+ fail("readerException should have been thrown");
+ } catch (ContributionReadException e) {
+ assertTrue(true);
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/0.99-incubating/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java b/sca-java-1.x/tags/0.99-incubating/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java
new file mode 100644
index 0000000000..7f342c2278
--- /dev/null
+++ b/sca-java-1.x/tags/0.99-incubating/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.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 org.apache.tuscany.sca.contribution.java.impl;
+
+import java.io.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.java.JavaImport;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+
+/**
+ * Test JavaImportProcessorTestCase
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaImportProcessorTestCase extends TestCase {
+
+ private static final String VALID_XML =
+ "<?xml version=\"1.0\" encoding=\"ASCII\"?>"
+ + "<contribution xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\">"
+ + "<import.java package=\"org.apache.tuscany.sca.contribution.java\" location=\"sca://contributions/001\"/>"
+ + "</contribution>";
+
+ private static final String INVALID_XML =
+ "<?xml version=\"1.0\" encoding=\"ASCII\"?>"
+ + "<contribution xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\">"
+ + "<import.java location=\"sca://contributions/001\"/>"
+ + "</contribution>";
+
+ private XMLInputFactory xmlFactory;
+
+ @Override
+ protected void setUp() throws Exception {
+ xmlFactory = XMLInputFactory.newInstance();
+ }
+
+ /**
+ * Test loading a valid import element from a contribution metadata stream
+ * @throws Exception
+ */
+ public void testLoad() throws Exception {
+ XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(VALID_XML));
+
+ ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint();
+ factories.addFactory(new JavaImportExportFactoryImpl());
+ JavaImportProcessor importProcessor = new JavaImportProcessor(factories);
+ JavaImport javaImport = importProcessor.read(reader);
+
+ assertEquals("org.apache.tuscany.sca.contribution.java", javaImport.getPackage());
+ assertEquals("sca://contributions/001", javaImport.getLocation());
+ }
+
+ /**
+ * Test loading a INVALID import element from a contribution metadata stream
+ * @throws Exception
+ */
+ public void testLoadInvalid() throws Exception {
+ XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(INVALID_XML));
+
+ ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint();
+ factories.addFactory(new JavaImportExportFactoryImpl());
+ JavaImportProcessor importProcessor = new JavaImportProcessor(factories);
+ try {
+ importProcessor.read(reader);
+ fail("readerException should have been thrown");
+ } catch (ContributionReadException e) {
+ assertTrue(true);
+ }
+ }
+}