From bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a Mon Sep 17 00:00:00 2001 From: dims Date: Tue, 17 Jun 2008 00:23:01 +0000 Subject: Move Tuscany from Incubator to top level. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68 --- .../ClassReferenceArtifactResolverTestCase.java | 75 +++++++++++++++++ .../java/impl/JavaExportProcessorTestCase.java | 92 +++++++++++++++++++++ .../java/impl/JavaImportProcessorTestCase.java | 93 ++++++++++++++++++++++ 3 files changed, 260 insertions(+) create mode 100644 branches/sca-java-1.0.1/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java create mode 100644 branches/sca-java-1.0.1/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java create mode 100644 branches/sca-java-1.0.1/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java (limited to 'branches/sca-java-1.0.1/modules/contribution-java/src/test') diff --git a/branches/sca-java-1.0.1/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java b/branches/sca-java-1.0.1/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/branches/sca-java-1.0.1/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/branches/sca-java-1.0.1/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java b/branches/sca-java-1.0.1/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/branches/sca-java-1.0.1/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 = + "" + + "" + + "" + + ""; + + private static final String INVALID_XML = + "" + + "" + + "" + + ""; + + 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/branches/sca-java-1.0.1/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java b/branches/sca-java-1.0.1/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/branches/sca-java-1.0.1/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 = + "" + + "" + + "" + + ""; + + private static final String INVALID_XML = + "" + + "" + + "" + + ""; + + 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); + } + } +} -- cgit v1.2.3