summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-2.0-M2/modules/contribution/src/test/java/org/apache
diff options
context:
space:
mode:
Diffstat (limited to 'branches/sca-java-2.0-M2/modules/contribution/src/test/java/org/apache')
-rw-r--r--branches/sca-java-2.0-M2/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java116
-rw-r--r--branches/sca-java-2.0-M2/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java91
-rw-r--r--branches/sca-java-2.0-M2/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java134
-rw-r--r--branches/sca-java-2.0-M2/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java58
4 files changed, 399 insertions, 0 deletions
diff --git a/branches/sca-java-2.0-M2/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java b/branches/sca-java-2.0-M2/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java
new file mode 100644
index 0000000000..3a18e2b987
--- /dev/null
+++ b/branches/sca-java-2.0-M2/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java
@@ -0,0 +1,116 @@
+/*
+ * 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.processor;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.net.URI;
+import java.net.URL;
+
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * URL Artifact Processor Extension Point test case
+ * Verifies the right registration and lookup for processors that handle filename and file types
+ *
+ * @version $Rev$ $Date$
+ */
+public class URLartifactProcessorExtensionPointTestCase {
+
+ private static URLArtifactProcessorExtensionPoint artifactProcessors;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ artifactProcessors = new DefaultURLArtifactProcessorExtensionPoint(extensionPoints);
+ artifactProcessors.addArtifactProcessor(new FileTypeArtifactProcessor());
+ artifactProcessors.addArtifactProcessor(new FileNameArtifactProcessor());
+ }
+
+ @Test
+ public final void testFileTypeProcessor() {
+ assertNotNull(artifactProcessors.getProcessor("dir1/file1.m1"));
+ assertNotNull(artifactProcessors.getProcessor("file1.m1"));
+ }
+
+ @Test
+ public final void testFileNameProcessor() {
+ assertNotNull(artifactProcessors.getProcessor("file.m2"));
+ assertNotNull(artifactProcessors.getProcessor("dir1/file.m2"));
+ assertNull(artifactProcessors.getProcessor("onefile.m2"));
+ }
+
+ /**
+ * Internal mock classes
+ *
+ */
+
+ private class M1 {
+ }
+
+ private class M2 {
+ }
+
+ private static class FileTypeArtifactProcessor implements URLArtifactProcessor<M1> {
+ public FileTypeArtifactProcessor() {
+ }
+
+ public M1 read(URL contributionURL, URI uri, URL url) throws ContributionReadException {
+ return null;
+ }
+
+ public void resolve(M1 m1, ModelResolver resolver) throws ContributionResolveException {
+ }
+
+ public String getArtifactType() {
+ return ".m1";
+ }
+
+ public Class<M1> getModelType() {
+ return M1.class;
+ }
+ }
+
+ private static class FileNameArtifactProcessor implements URLArtifactProcessor<M2> {
+ public FileNameArtifactProcessor() {
+ }
+
+ public M2 read(URL contributionURL, URI uri, URL url) throws ContributionReadException {
+ return null;
+ }
+
+ public void resolve(M2 m2, ModelResolver resolver) throws ContributionResolveException {
+ }
+
+ public String getArtifactType() {
+ return "file.m2";
+ }
+
+ public Class<M2> getModelType() {
+ return M2.class;
+ }
+ }
+
+}
diff --git a/branches/sca-java-2.0-M2/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java b/branches/sca-java-2.0-M2/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java
new file mode 100644
index 0000000000..b778167217
--- /dev/null
+++ b/branches/sca-java-2.0-M2/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java
@@ -0,0 +1,91 @@
+/*
+ * 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.resolver;
+
+import static org.junit.Assert.assertTrue;
+
+import org.apache.tuscany.sca.contribution.Artifact;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.DefaultContributionFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test the default model resolver implementation.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultModelResolverTestCase {
+
+ private ModelResolver resolver;
+ private ContributionFactory factory;
+
+ @Before
+ public void setUp() throws Exception {
+ resolver = new DefaultModelResolver();
+ factory = new DefaultContributionFactory();
+ }
+
+ @Test
+ public void testResolved() {
+ Model a = new Model("a");
+ resolver.addModel(a);
+ Model x = new Model("a");
+ x = resolver.resolveModel(Model.class, x);
+ assertTrue(x == a);
+ }
+
+ @Test
+ public void testUnresolved() {
+ Model x = new Model("a");
+ Model y = resolver.resolveModel(Model.class, x);
+ assertTrue(x == y);
+ }
+
+ @Test
+ public void testResolvedArtifact() {
+ Artifact artifact = factory.createArtifact();
+ artifact.setURI("foo/bar");
+ resolver.addModel(artifact);
+ Artifact x = factory.createArtifact();
+ x.setURI("foo/bar");
+ x = resolver.resolveModel(Artifact.class, x);
+ assertTrue(x == artifact);
+ }
+
+ class Model {
+ private String name;
+
+ Model(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return name.equals(((Model)obj).name);
+ }
+ }
+
+}
diff --git a/branches/sca-java-2.0-M2/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java b/branches/sca-java-2.0-M2/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java
new file mode 100644
index 0000000000..2422c8fb94
--- /dev/null
+++ b/branches/sca-java-2.0-M2/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java
@@ -0,0 +1,134 @@
+/*
+* 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.resolver;
+
+import static org.junit.Assert.assertTrue;
+
+import org.apache.tuscany.sca.contribution.Artifact;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.DefaultContributionFactory;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.DefaultFactoryExtensionPoint;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test DefaultArtifactResolver.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ExtensibleModelResolverTestCase {
+ private ExtensibleModelResolver resolver;
+
+ private ContributionFactory factory;
+
+ @Before
+ public void setUp() throws Exception {
+
+ ModelResolverExtensionPoint resolvers = new DefaultModelResolverExtensionPoint();
+ resolvers.addResolver(Model.class, TestModelResolver.class);
+
+ FactoryExtensionPoint factories = new DefaultFactoryExtensionPoint(new DefaultExtensionPointRegistry());
+
+ resolver = new ExtensibleModelResolver(null, resolvers, factories, null);
+
+ factory = new DefaultContributionFactory();
+ }
+
+ @Test
+ public void testResolvedDefault() {
+ OtherModel a = new OtherModel("a");
+ resolver.addModel(a);
+ OtherModel x = new OtherModel("a");
+ x = resolver.resolveModel(OtherModel.class, x);
+ assertTrue(x == a);
+ }
+
+ @Test
+ public void testResolvedRegisteredClass() {
+ Model a = new Model("a");
+ resolver.addModel(a);
+ Model x = new Model("a");
+ x = resolver.resolveModel(Model.class, x);
+ assertTrue(x == a);
+ }
+
+ @Test
+ public void testUnresolvedDefault() {
+ OtherModel x = new OtherModel("a");
+ OtherModel y = resolver.resolveModel(OtherModel.class, x);
+ assertTrue(x == y);
+ }
+
+ @Test
+ public void testUnresolved() {
+ Model x = new Model("a");
+ Model y = resolver.resolveModel(Model.class, x);
+ assertTrue(x == y);
+ }
+
+ @Test
+ public void testResolvedArtifact() {
+ Artifact artifact = factory.createArtifact();
+ artifact.setURI("foo/bar");
+ resolver.addModel(artifact);
+ Artifact x = factory.createArtifact();
+ x.setURI("foo/bar");
+ x = resolver.resolveModel(Artifact.class, x);
+ assertTrue(x == artifact);
+ }
+
+ private class Model {
+ private String name;
+
+ Model(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return name.equals(((Model)obj).name);
+ }
+ }
+
+ private class OtherModel {
+ private String name;
+
+ OtherModel(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return name.equals(((OtherModel)obj).name);
+ }
+ }
+}
diff --git a/branches/sca-java-2.0-M2/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java b/branches/sca-java-2.0-M2/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java
new file mode 100644
index 0000000000..cd586d3b2c
--- /dev/null
+++ b/branches/sca-java-2.0-M2/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java
@@ -0,0 +1,58 @@
+/*
+ * 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.resolver;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+
+/**
+ * A test implementation of a model resolver, based on a map.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestModelResolver implements ModelResolver {
+
+ private Map<Object, Object> map = new HashMap<Object, Object>();
+
+ public TestModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) {
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ Object resolved = map.get(unresolved);
+ if (resolved != null) {
+ // Return the resolved object
+ return modelClass.cast(resolved);
+ }
+ // Return the unresolved object
+ return unresolved;
+ }
+
+ public void addModel(Object resolved) {
+ map.put(resolved, resolved);
+ }
+
+ public Object removeModel(Object resolved) {
+ return map.remove(resolved);
+ }
+
+}