You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2007/04/06 19:30:47 UTC
svn commit: r526232 [4/5] - in /incubator/tuscany/java/sca/modules: ./
idl/src/main/java/org/apache/tuscany/idl/util/
impl-java-xml/src/main/java/org/apache/tuscany/api/
impl-java-xml/src/main/java/org/apache/tuscany/api/annotation/
impl-java-xml/src/m...
Added: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java?view=auto&rev=526232
==============================================================================
--- incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java Fri Apr 6 10:30:44 2007
@@ -0,0 +1,150 @@
+/*
+ * 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.core.implementation.processor;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.processor.ConversationProcessor;
+import org.apache.tuscany.implementation.java.processor.InvalidConversationalImplementation;
+import org.osoa.sca.annotations.ConversationAttributes;
+import org.osoa.sca.annotations.ConversationID;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConversationProcessorTestCase extends TestCase {
+ private ConversationProcessor processor = new ConversationProcessor();
+
+ public void testMaxIdleTime() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ processor.visitClass(FooMaxIdle.class, type);
+ assertEquals(10000L, type.getMaxIdleTime());
+ assertEquals(-1, type.getMaxAge());
+ }
+
+ public void testMaxAge() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ processor.visitClass(FooMaxAge.class, type);
+ assertEquals(10000L, type.getMaxAge());
+ assertEquals(-1, type.getMaxIdleTime());
+ }
+
+ public void testBadFooBoth() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ try {
+ processor.visitClass(BadFooBoth.class, type);
+ fail();
+ } catch (InvalidConversationalImplementation e) {
+ // expected
+ }
+ }
+
+ public void testImplicitScope() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ processor.visitClass(ImplicitFooScope.class, type);
+ assertEquals(org.apache.tuscany.implementation.java.impl.Scope.CONVERSATION, type.getScope());
+ }
+
+ public void testBadFooScope() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ try {
+ processor.visitClass(BadFooScope.class, type);
+ fail();
+ } catch (InvalidConversationalImplementation e) {
+ // expected
+ }
+ }
+
+ public void testJustConversation() throws Exception {
+ // TODO do we want these semantics
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ processor.visitClass(FooJustConversation.class, type);
+ assertEquals(org.apache.tuscany.implementation.java.impl.Scope.CONVERSATION, type.getScope());
+ assertEquals(-1, type.getMaxAge());
+ assertEquals(-1, type.getMaxIdleTime());
+ }
+
+ public void testSetConversationIDField() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Field field = FooWithConversationIDField.class.getDeclaredField("conversationID");
+ processor.visitField(field, type);
+ assertNotNull(type.getConversationIDMember());
+ assertEquals(field, type.getConversationIDMember());
+ }
+
+ public void testSetConversationIDMethod() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Method method = FooWithConversationIDMethod.class.getDeclaredMethods()[0];
+ processor.visitMethod(method, type);
+ assertNotNull(type.getConversationIDMember());
+ assertEquals(method, type.getConversationIDMember());
+ }
+
+ @Scope("CONVERSATION")
+ @ConversationAttributes(maxIdleTime = "10 seconds")
+ private class FooMaxIdle {
+ }
+
+ @Scope("CONVERSATION")
+ @ConversationAttributes(maxAge = "10 seconds")
+ private class FooMaxAge {
+ }
+
+ @Scope("CONVERSATION")
+ @ConversationAttributes(maxAge = "10 seconds", maxIdleTime = "10 seconds")
+ private class BadFooBoth {
+ }
+
+ @ConversationAttributes(maxAge = "10 seconds")
+ private class ImplicitFooScope {
+ }
+
+ @Scope("STATELESS")
+ @ConversationAttributes(maxAge = "10 seconds")
+ private class BadFooScope {
+ }
+
+ @ConversationAttributes
+ private class FooJustConversation {
+ }
+
+ private class FooWithConversationIDField {
+ @ConversationID
+ private String conversationID;
+ }
+
+ private class FooWithConversationIDMethod {
+ @ConversationID
+ void setConversationID(String conversationID) {
+ }
+ }
+}
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.java?view=auto&rev=526232
==============================================================================
--- incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.java Fri Apr 6 10:30:44 2007
@@ -0,0 +1,112 @@
+/*
+ * 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.core.implementation.processor;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.implementation.java.processor.ConversationProcessor;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConvertTimeMillisTestCase extends TestCase {
+ private MockProcessor registy;
+
+ public void testConvertSeconds() throws Exception {
+ assertEquals(10000L, registy.convertTimeMillis("10 seconds"));
+ assertEquals(10000L, registy.convertTimeMillis("10 SECONDS"));
+ try {
+ registy.convertTimeMillis("10seconds");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ public void testConvertMinutes() throws Exception {
+ assertEquals(600000L, registy.convertTimeMillis("10 minutes"));
+ assertEquals(600000L, registy.convertTimeMillis("10 MINUTES"));
+ try {
+ registy.convertTimeMillis("10minutes");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ public void testConvertHours() throws Exception {
+ assertEquals(36000000L, registy.convertTimeMillis("10 hours"));
+ assertEquals(36000000L, registy.convertTimeMillis("10 HOURS"));
+ try {
+ registy.convertTimeMillis("10hours");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ public void testConvertDays() throws Exception {
+ assertEquals(864000000L, registy.convertTimeMillis("10 days"));
+ assertEquals(864000000L, registy.convertTimeMillis("10 DAYS"));
+ try {
+ registy.convertTimeMillis("10days");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ public void testConvertYears() throws Exception {
+ assertEquals(315569260000L, registy.convertTimeMillis("10 years"));
+ assertEquals(315569260000L, registy.convertTimeMillis("10 YEARS"));
+ try {
+ registy.convertTimeMillis("10years");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ public void testConvertDefault() throws Exception {
+ assertEquals(10000L, registy.convertTimeMillis("10 "));
+ assertEquals(10000L, registy.convertTimeMillis("10"));
+ }
+
+ public void testInvalid() throws Exception {
+ try {
+ registy.convertTimeMillis("foo");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ registy = new MockProcessor();
+ }
+
+ private class MockProcessor extends ConversationProcessor {
+
+ @Override
+ protected long convertTimeMillis(String expr) throws NumberFormatException {
+ return super.convertTimeMillis(expr);
+ }
+ }
+}
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.java?view=auto&rev=526232
==============================================================================
--- incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.java Fri Apr 6 10:30:44 2007
@@ -0,0 +1,98 @@
+/*
+ * 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.core.implementation.processor;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.processor.DestroyProcessor;
+import org.apache.tuscany.implementation.java.processor.DuplicateDestructorException;
+import org.apache.tuscany.implementation.java.processor.IllegalDestructorException;
+import org.osoa.sca.annotations.Destroy;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DestroyProcessorTestCase extends TestCase {
+
+ public void testDestroy() throws Exception {
+ DestroyProcessor processor = new DestroyProcessor();
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Method method = Foo.class.getMethod("destroy");
+ processor.visitMethod(method, type);
+ assertNotNull(type.getDestroyMethod());
+ }
+
+ public void testBadDestroy() throws Exception {
+ DestroyProcessor processor = new DestroyProcessor();
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Method method = Bar.class.getMethod("badDestroy", String.class);
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (IllegalDestructorException e) {
+ // expected
+ }
+ }
+
+ public void testTwoDestroy() throws Exception {
+ DestroyProcessor processor = new DestroyProcessor();
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Method method = Bar.class.getMethod("destroy");
+ Method method2 = Bar.class.getMethod("destroy2");
+ processor.visitMethod(method, type);
+ try {
+ processor.visitMethod(method2, type);
+ fail();
+ } catch (DuplicateDestructorException e) {
+ // expected
+ }
+ }
+
+
+ private class Foo {
+
+ @Destroy
+ public void destroy() {
+ }
+ }
+
+
+ private class Bar {
+
+ @Destroy
+ public void destroy() {
+ }
+
+ @Destroy
+ public void destroy2() {
+ }
+
+ @Destroy
+ public void badDestroy(String foo) {
+ }
+
+
+ }
+}
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.java?view=auto&rev=526232
==============================================================================
--- incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.java Fri Apr 6 10:30:44 2007
@@ -0,0 +1,55 @@
+/*
+ * 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.core.implementation.processor;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.introspection.ProcessingException;
+import org.apache.tuscany.implementation.java.processor.EagerInitProcessor;
+import org.osoa.sca.annotations.EagerInit;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class EagerInitProcessorTestCase extends TestCase {
+
+ public void testNoLevel() throws ProcessingException {
+ EagerInitProcessor processor = new EagerInitProcessor();
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ processor.visitClass(Level.class, type);
+ }
+
+ public void testSubclass() throws ProcessingException {
+ EagerInitProcessor processor = new EagerInitProcessor();
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ processor.visitClass(SubClass.class, type);
+ }
+
+ @EagerInit
+ private class Level {
+ }
+
+ private class SubClass extends Level {
+
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.java?view=auto&rev=526232
==============================================================================
--- incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.java Fri Apr 6 10:30:44 2007
@@ -0,0 +1,70 @@
+/*
+ * 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.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.idl.java.introspection.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.idl.java.introspection.impl.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.implementation.java.impl.ConstructorDefinition;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.processor.HeuristicPojoProcessor;
+import org.apache.tuscany.implementation.java.processor.PropertyProcessor;
+import org.osoa.sca.annotations.Property;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HeuristicAndPropertyTestCase extends TestCase {
+
+ private PropertyProcessor propertyProcessor;
+ private HeuristicPojoProcessor heuristicProcessor;
+
+ /**
+ * Verifies the property and heuristic processors don't collide
+ */
+ @SuppressWarnings("unchecked")
+ public void testPropertyProcessorWithHeuristicProcessor() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ Constructor ctor = Foo.class.getConstructor(String.class);
+ type.setConstructorDefinition(new ConstructorDefinition(ctor));
+ propertyProcessor.visitConstructorParameter(type.getConstructorDefinition().getParameters()[0], type);
+ heuristicProcessor.visitEnd(Foo.class, type);
+ assertEquals(1, type.getProperties().size());
+ assertEquals("foo", type.getProperties().get(0).getName());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ propertyProcessor = new PropertyProcessor();
+ propertyProcessor.setInterfaceProcessorRegistry(registry);
+ heuristicProcessor = new HeuristicPojoProcessor();
+ heuristicProcessor.setInterfaceProcessorRegistry(registry);
+ }
+
+ public static class Foo {
+ public Foo(@Property(name = "foo")
+ String prop) {
+ }
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java?view=auto&rev=526232
==============================================================================
--- incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java Fri Apr 6 10:30:44 2007
@@ -0,0 +1,305 @@
+/*
+ * 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.core.implementation.processor;
+
+import static org.apache.tuscany.core.implementation.processor.ModelHelper.getProperty;
+
+import java.lang.reflect.Constructor;
+
+import org.apache.tuscany.idl.java.introspection.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.idl.java.introspection.impl.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.implementation.java.impl.JavaElement;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.introspection.ProcessingException;
+import org.apache.tuscany.implementation.java.processor.AmbiguousConstructorException;
+import org.apache.tuscany.implementation.java.processor.HeuristicPojoProcessor;
+import org.apache.tuscany.implementation.java.processor.NoConstructorException;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Remotable;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HeuristicConstructorTestCase extends AbstractProcessorTest {
+
+ private HeuristicPojoProcessor processor;
+
+ public HeuristicConstructorTestCase() {
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ processor = new HeuristicPojoProcessor();
+ processor.setInterfaceProcessorRegistry(registry);
+ }
+
+ private <T> void visitEnd(Class<T> clazz, JavaImplementationDefinition type) throws ProcessingException {
+ for (Constructor<T> constructor : clazz.getConstructors()) {
+ visitConstructor(constructor, type);
+ }
+ processor.visitEnd(clazz, type);
+ }
+
+ /**
+ * Verifies a single constructor is chosen with a parameter as the type
+ */
+ public void testSingleConstructorWithParam() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ org.apache.tuscany.assembly.Property prop = factory.createProperty();
+ prop.setName("foo");
+ type.getProperties().add(prop);
+ // Hack to add a property member
+ JavaElement element = new JavaElement("foo", String.class);
+ type.getPropertyMembers().put("foo", element);
+ visitEnd(Foo1.class, type);
+ assertNotNull(type.getConstructorDefinition().getConstructor());
+ assertEquals("foo", type.getConstructorDefinition().getParameters()[0].getName());
+ }
+
+ /**
+ * Verifies a single constructor is chosen with a reference as the type
+ */
+ public void testSingleConstructorWithRef() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ org.apache.tuscany.assembly.Reference ref = factory.createReference();
+ ref.setName("foo");
+ type.getReferences().add(ref);
+ type.getReferenceMembers().put("foo", new JavaElement("foo", String.class));
+ visitEnd(Foo1.class, type);
+ assertNotNull(type.getConstructorDefinition().getConstructor());
+ assertEquals("foo", type.getConstructorDefinition().getParameters()[0].getName());
+ }
+
+ /**
+ * Verifies a single constructor is chosen with a property and a reference
+ * as the type
+ */
+ public void testSingleConstructorWithPropRef() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+
+ org.apache.tuscany.assembly.Property prop = factory.createProperty();
+ prop.setName("foo");
+ type.getProperties().add(prop);
+ // Hack to add a property member
+ JavaElement element = new JavaElement("foo", String.class);
+ type.getPropertyMembers().put("foo", element);
+
+ org.apache.tuscany.assembly.Reference ref = ModelHelper.createReference("ref", Foo1.class);
+ type.getReferences().add(ref);
+ type.getReferenceMembers().put("ref", new JavaElement("ref", Foo1.class));
+ visitEnd(Foo2.class, type);
+ assertNotNull(type.getConstructorDefinition().getConstructor());
+ assertEquals(2, type.getConstructorDefinition().getParameters().length);
+ }
+
+ public void testSingleConstructorResolvableParam() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ visitEnd(Foo5.class, type);
+ assertEquals(String.class, type.getPropertyMembers().get("string").getType());
+ }
+
+ public void testSingleConstructorResolvableRef() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ visitEnd(Foo6.class, type);
+ assertTrue(ModelHelper.matches(ModelHelper.getReference(type, "ref"), Ref.class));
+ }
+
+ public void testSingleConstructorAmbiguousRef() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ org.apache.tuscany.assembly.Reference ref = ModelHelper.createReference("ref", Foo1.class);
+ type.getReferences().add(ref);
+ type.getReferenceMembers().put("ref", new JavaElement("ref", Foo1.class));
+ org.apache.tuscany.assembly.Reference ref2 = ModelHelper.createReference("ref2", Foo1.class);
+ type.getReferences().add(ref2);
+ type.getReferenceMembers().put("ref2", new JavaElement("ref2", Foo1.class));
+ try {
+ visitEnd(Foo4.class, type);
+ fail();
+ } catch (AmbiguousConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testConstructorPropertyAnnotatedParamsOnly() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ visitEnd(Foo7.class, type);
+ assertNotNull(getProperty(type, "myProp"));
+ }
+
+ public void testConstructorReferenceAnnotatedParamsOnly() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ visitEnd(Foo8.class, type);
+ assertNotNull(ModelHelper.getReference(type, "myRef"));
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testDefaultConstructor() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ visitEnd(Foo3.class, type);
+ assertNotNull(type.getConstructorDefinition().getConstructor());
+ }
+
+ public void testSameTypesButAnnotated() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ visitEnd(Foo12.class, type);
+ assertEquals(2, type.getProperties().size());
+ assertNotNull(getProperty(type, "prop1"));
+ assertNotNull(getProperty(type, "prop2"));
+ }
+
+ /**
+ * Verifies processing executes with additional extension annotations
+ */
+ public void testRandomAnnotation() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ visitEnd(Foo11.class, type);
+ assertEquals(1, type.getProperties().size());
+ assertNotNull(getProperty(type, "prop1"));
+ }
+
+ public void testPrivateConstructor() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ try {
+ visitEnd(Foo14.class, type);
+ fail();
+ } catch (NoConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testMultipleConstructors() throws Exception {
+ // throw new UnsupportedOperationException("Finish heuristic multiple
+ // constructors - Foo10");
+ }
+
+ public static class Foo1 {
+ public Foo1(String val) {
+ }
+ }
+
+ public static class Foo2 {
+ public Foo2(String val, Foo1 ref) {
+ }
+ }
+
+ public static class Foo3 {
+ }
+
+ public static class Foo4 {
+ public Foo4(Foo1 ref) {
+ }
+ }
+
+ public static class Prop {
+
+ }
+
+ @Remotable
+ public static interface Ref {
+
+ }
+
+ public static class Foo5 {
+ public Foo5(String val) {
+ }
+ }
+
+ public static class Foo6 {
+ public Foo6(Ref ref) {
+ }
+ }
+
+ public static class Foo7 {
+ public Foo7(@Property(name = "myProp")
+ String prop) {
+ }
+ }
+
+ public static class Foo8 {
+ public Foo8(@Reference(name = "myRef")
+ String ref) {
+ }
+ }
+
+ public static class Foo9 {
+ public Foo9(@Reference(name = "myRef")
+ String ref) {
+ }
+ }
+
+ public static class Foo10 {
+
+ public Foo10() {
+ }
+
+ public Foo10(String prop) {
+ }
+
+ public Foo10(@Property(name = "prop1")
+ String prop1, @Property(name = "prop2")
+ String prop2) {
+
+ }
+ }
+
+ public static class Foo11 {
+
+ public Foo11(@Property(name = "prop1")
+ String prop, @Baz
+ String baz) {
+ }
+ }
+
+ public static class Foo12 {
+
+ public Foo12(@Property(name = "prop1")
+ String prop, @Property(name = "prop2")
+ String baz) {
+ }
+ }
+
+ public @interface Baz {
+
+ }
+
+ public static class Foo13 {
+ public Foo13(@Reference
+ String foo) {
+ }
+ }
+
+ public static final class Foo14 {
+ private Foo14() {
+ }
+ }
+
+ public static final class Foo15 {
+ public Foo15(@Reference
+ String param1, @Reference
+ String param2) {
+ }
+ }
+
+ public static final class Foo16 {
+ public Foo16(@Reference
+ String param1, @Property(name = "foo")
+ String param2, @Reference(name = "bar")
+ String param3) {
+ }
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java?view=auto&rev=526232
==============================================================================
--- incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java Fri Apr 6 10:30:44 2007
@@ -0,0 +1,404 @@
+/*
+ * 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.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.util.Collection;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.idl.java.introspection.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.idl.java.introspection.impl.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.idl.util.JavaXMLMapper;
+import org.apache.tuscany.implementation.java.impl.ConstructorDefinition;
+import org.apache.tuscany.implementation.java.impl.JavaElement;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.introspection.ProcessingException;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Remotable;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * Verfies component type information is properly introspected from an unadorned
+ * POJO according to the SCA Java Client and Implementation Model Specification
+ *
+ * @version $Rev$ $Date$
+ */
+public class HeuristicPojoProcessorTestCase extends AbstractProcessorTest {
+
+ private org.apache.tuscany.implementation.java.processor.HeuristicPojoProcessor processor;
+
+ public HeuristicPojoProcessorTestCase() {
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ processor = new org.apache.tuscany.implementation.java.processor.HeuristicPojoProcessor();
+ processor.setInterfaceProcessorRegistry(registry);
+ }
+
+ private <T> void visitEnd(Class<T> clazz, JavaImplementationDefinition type) throws ProcessingException {
+ for (Constructor<T> constructor : clazz.getConstructors()) {
+ visitConstructor(constructor, type);
+ }
+ processor.visitEnd(clazz, type);
+ }
+
+ /**
+ * Verifies a single service interface is computed when only one interface
+ * is implemented
+ */
+ public void testSingleInterface() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ Constructor<SingleInterfaceImpl> ctor = SingleInterfaceImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<SingleInterfaceImpl>(ctor));
+ processor.visitEnd(SingleInterfaceImpl.class, type);
+ assertEquals(1, type.getServices().size());
+ assertTrue(ModelHelper.matches(ModelHelper.getService(type, PropertyInterface.class.getSimpleName()),
+ PropertyInterface.class));
+ assertTrue(type.getProperties().isEmpty());
+ assertTrue(type.getReferences().isEmpty());
+ }
+
+ /**
+ * Verifies property and reference setters are computed
+ */
+ public void testPropertyReference() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ Constructor<SingleInterfaceWithPropertyReferenceImpl> ctor = SingleInterfaceWithPropertyReferenceImpl.class
+ .getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<SingleInterfaceWithPropertyReferenceImpl>(ctor));
+ processor.visitEnd(SingleInterfaceWithPropertyReferenceImpl.class, type);
+ assertEquals(1, type.getServices().size());
+ assertTrue(ModelHelper
+ .matches(ModelHelper.getService(type, Interface1.class.getSimpleName()), Interface1.class));
+ assertEquals(1, type.getProperties().size());
+ org.apache.tuscany.assembly.Property prop = ModelHelper.getProperty(type, "property");
+ assertNotNull(prop);
+ assertEquals(ComplexProperty.class, type.getPropertyMembers().get("property").getType());
+ assertEquals(1, type.getReferences().size());
+ assertTrue(ModelHelper.matches(ModelHelper.getReference(type, "reference"), Ref.class));
+ }
+
+ /**
+ * Verifies that a property setter is not introspected if an analogous
+ * operation is in the service interface
+ */
+ public void testPropertySetterInInterface() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ Constructor<SingleInterfaceImpl> ctor = SingleInterfaceImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<SingleInterfaceImpl>(ctor));
+ processor.visitEnd(SingleInterfaceImpl.class, type);
+ assertEquals(0, type.getProperties().size());
+ }
+
+ /**
+ * Verifies that a reference setter is not introspected if an analogous
+ * operation is in the service interface
+ */
+ public void testReferenceSetterInInterface() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ Constructor<RefInterfaceImpl> ctor = RefInterfaceImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<RefInterfaceImpl>(ctor));
+ processor.visitEnd(RefInterfaceImpl.class, type);
+ assertEquals(0, type.getReferences().size());
+ }
+
+ /**
+ * Verifies collection generic types or array types are introspected as
+ * references according to spec rules
+ */
+ public void testReferenceCollectionType() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ Constructor<ReferenceCollectionImpl> ctor = ReferenceCollectionImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<ReferenceCollectionImpl>(ctor));
+ processor.visitEnd(ReferenceCollectionImpl.class, type);
+ assertEquals(1, type.getProperties().size());
+ assertEquals(3, type.getReferences().size());
+ }
+
+ /**
+ * Verifies collection generic types or array types are introspected as
+ * properties according to spec rules
+ */
+ public void testPropertyCollectionType() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ Constructor<PropertyCollectionImpl> ctor = PropertyCollectionImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<PropertyCollectionImpl>(ctor));
+ processor.visitEnd(PropertyCollectionImpl.class, type);
+ assertEquals(0, type.getReferences().size());
+ assertEquals(4, type.getProperties().size());
+ }
+
+ /**
+ * Verifies references are calculated when the type marked with is
+ *
+ * @Remotable
+ */
+ public void testRemotableRef() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ Constructor<RemotableRefImpl> ctor = RemotableRefImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<RemotableRefImpl>(ctor));
+ processor.visitEnd(RemotableRefImpl.class, type);
+ assertEquals(2, type.getReferences().size());
+ assertEquals(0, type.getProperties().size());
+ }
+
+ public void testParentInterface() throws ProcessingException, NoSuchMethodException {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ Constructor<Child> ctor = Child.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<Child>(ctor));
+ processor.visitEnd(Child.class, type);
+ assertNotNull(ModelHelper.getService(type, Interface1.class.getSimpleName()));
+ }
+
+ /**
+ * Verifies a service inteface is calculated when only props and refs are
+ * given
+ */
+ public void testExcludedPropertyAndReference() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ org.apache.tuscany.assembly.Reference ref = factory.createReference();
+ ref.setName("reference");
+ type.getReferences().add(ref);
+ type.getReferenceMembers().put("reference", new JavaElement("reference", Ref.class));
+ org.apache.tuscany.assembly.Reference ref2 = factory.createReference();
+ ref2.setName("reference2");
+ type.getReferences().add(ref2);
+ type.getReferenceMembers().put("reference2", new JavaElement("reference2", Ref.class));
+ org.apache.tuscany.assembly.Property prop1 = factory.createProperty();
+ prop1.setName("string1");
+ type.getProperties().add(prop1);
+ type.getPropertyMembers().put("string1", new JavaElement("string1", String.class));
+ org.apache.tuscany.assembly.Property prop2 = factory.createProperty();
+ prop2.setName("string2");
+ type.getProperties().add(prop2);
+ type.getPropertyMembers().put("string2", new JavaElement("string2", String.class));
+ visitEnd(MockService.class, type);
+ assertEquals(1, type.getServices().size());
+ }
+
+ public void testProtectedRemotableRefField() throws ProcessingException, NoSuchMethodException {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ Constructor<ProtectedRemotableRefFieldImpl> ctor = ProtectedRemotableRefFieldImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<ProtectedRemotableRefFieldImpl>(ctor));
+ processor.visitEnd(ProtectedRemotableRefFieldImpl.class, type);
+ assertNotNull(ModelHelper.getReference(type, "otherRef"));
+ }
+
+ public void testProtectedRemotableRefMethod() throws ProcessingException, NoSuchMethodException {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ Constructor<ProtectedRemotableRefMethodImpl> ctor = ProtectedRemotableRefMethodImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<ProtectedRemotableRefMethodImpl>(ctor));
+ processor.visitEnd(ProtectedRemotableRefMethodImpl.class, type);
+ assertNotNull(ModelHelper.getReference(type, "otherRef"));
+ }
+
+ public void testSetDataTypes() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ Constructor<PropertyIntTypeOnConstructor> ctor = PropertyIntTypeOnConstructor.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<PropertyIntTypeOnConstructor>(ctor));
+ processor.visitEnd(PropertyIntTypeOnConstructor.class, type);
+ org.apache.tuscany.assembly.Property foo = ModelHelper.getProperty(type, "foo");
+ assertEquals(int.class, type.getPropertyMembers().get("foo").getType());
+ assertEquals(new QName(JavaXMLMapper.URI_2001_SCHEMA_XSD, "int"), foo.getXSDType());
+ }
+
+ private static class PropertyIntTypeOnConstructor {
+ protected int foo;
+
+ public PropertyIntTypeOnConstructor() {
+ }
+
+ public int getFoo() {
+ return foo;
+ }
+ }
+
+ private interface PropertyInterface {
+ void setString1(String val);
+ }
+
+ private interface Interface1 {
+ }
+
+ private static class Parent implements Interface1 {
+
+ }
+
+ private static class Child extends Parent {
+ public Child() {
+ }
+
+ }
+
+ private static class SingleInterfaceImpl implements PropertyInterface {
+ public SingleInterfaceImpl() {
+ }
+
+ public void setString1(String val) {
+ }
+
+ }
+
+ private interface HeuristicServiceInterface {
+ void fooOperation(String ref);
+
+ void setInvalid1(); // No parameter
+
+ void setInvalid2(String str, int i); // More than one parameter
+
+ String setInvalid3(String str); // return should be void
+ }
+
+ public static class MockService implements PropertyInterface, RefInterface, HeuristicServiceInterface {
+
+ @Property
+ public void setString1(String val) {
+ }
+
+ @Property
+ public void setString2(String val) {
+ }
+
+ @Reference
+ public void setReference(Ref ref) {
+ }
+
+ @Reference
+ public void setReference2(Ref ref) {
+ }
+
+ public void fooOperation(String ref) {
+
+ }
+
+ public void setInvalid1() {
+ }
+
+ public void setInvalid2(String str, int i) {
+ }
+
+ public String setInvalid3(String str) {
+ return null;
+ }
+
+ }
+
+ @Service
+ private interface Ref {
+ }
+
+ private class ComplexProperty {
+ }
+
+ private interface RefInterface {
+ void setReference(Ref ref);
+ }
+
+ private static class RefInterfaceImpl implements RefInterface {
+ public RefInterfaceImpl() {
+ }
+
+ public void setReference(Ref ref) {
+ }
+ }
+
+ private static class SingleInterfaceWithPropertyReferenceImpl implements Interface1 {
+ public SingleInterfaceWithPropertyReferenceImpl() {
+ }
+
+ public void setReference(Ref ref) {
+ }
+
+ public void setProperty(ComplexProperty prop) {
+ }
+ }
+
+ private static class ReferenceCollectionImpl implements Interface1 {
+ public ReferenceCollectionImpl() {
+ }
+
+ public void setCollectionReference(Collection<Ref> ref) {
+ }
+
+ public void setNonGenericCollectionReference(Collection ref) {
+ // [rfeng] By the SCA spec, this should be classified as property
+ }
+
+ public void setListReference(List<Ref> ref) {
+ }
+
+ public void setArrayReference(Ref[] ref) {
+ }
+ }
+
+ private static class PropertyCollectionImpl implements Interface1 {
+ public PropertyCollectionImpl() {
+ }
+
+ public void setCollectionProperty(Collection<ComplexProperty> prop) {
+ }
+
+ public void setCollectionProperty2(Collection<String> prop) {
+ }
+
+ public void setArrayProperty(ComplexProperty[] prop) {
+ }
+
+ public void setArrayProperty2(String[] prop) {
+ }
+ }
+
+ @Remotable
+ private interface RemotableRef {
+ }
+
+ private static class RemotableRefImpl implements Interface1 {
+ protected RemotableRef otherRef;
+
+ public RemotableRefImpl() {
+ }
+
+ public void setRef(RemotableRef ref) {
+
+ }
+ }
+
+ private static class ProtectedRemotableRefFieldImpl implements Interface1 {
+ protected RemotableRef otherRef;
+
+ public ProtectedRemotableRefFieldImpl() {
+ }
+
+ public ProtectedRemotableRefFieldImpl(RemotableRef otherRef) {
+ this.otherRef = otherRef;
+ }
+
+ }
+
+ private static class ProtectedRemotableRefMethodImpl implements Interface1 {
+ public ProtectedRemotableRefMethodImpl() {
+ }
+
+ protected void setOtherRef(RemotableRef otherRef) {
+ }
+
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java?view=auto&rev=526232
==============================================================================
--- incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java Fri Apr 6 10:30:44 2007
@@ -0,0 +1,146 @@
+/*
+ * 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.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+
+import org.apache.tuscany.assembly.Property;
+import org.apache.tuscany.idl.java.introspection.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.idl.java.introspection.impl.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.implementation.java.impl.ConstructorDefinition;
+import org.apache.tuscany.implementation.java.impl.JavaElement;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.introspection.ProcessingException;
+
+/**
+ * Verifies constructors that have extensible annotation types, i.e. that have
+ * parameters marked by annotations which are themselves processed by some other
+ * implementation processor
+ *
+ * @version $Rev$ $Date$
+ */
+public class HeutisticExtensibleConstructorTestCase extends AbstractProcessorTest {
+
+ private org.apache.tuscany.implementation.java.processor.HeuristicPojoProcessor processor;
+
+ public HeutisticExtensibleConstructorTestCase() {
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ processor = new org.apache.tuscany.implementation.java.processor.HeuristicPojoProcessor();
+ processor.setInterfaceProcessorRegistry(registry);
+ }
+
+ private <T> void visitEnd(Class<T> clazz, JavaImplementationDefinition type) throws ProcessingException {
+ for (Constructor<T> constructor : clazz.getConstructors()) {
+ visitConstructor(constructor, type);
+ }
+ processor.visitEnd(clazz, type);
+ }
+
+ /**
+ * Verifies heuristic processing can be called priot to an extension
+ * annotation processors being called.
+ */
+ public void testBarAnnotationProcessedFirst() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+ ConstructorDefinition<Foo> definition = new ConstructorDefinition<Foo>(ctor);
+ type.setConstructorDefinition(definition);
+ Property property = factory.createProperty();
+ property.setName("myBar");
+ definition.getParameters()[0].setName("myBar");
+ type.getProperties().add(property);
+ visitEnd(Foo.class, type);
+ assertEquals(2, type.getProperties().size());
+ }
+
+ /**
+ * Verifies heuristic processing can be called before an extension
+ * annotation processors is called. <p/> For example, given:
+ *
+ * <pre>
+ * Foo(@Bar String prop, @org.osoa.sca.annotations.Property(name = "foo") String prop2)
+ * </pre>
+ *
+ * <p/> Heuristic evaluation of
+ * @Property can occur prior to another implementation processor evaluating
+ * @Bar
+ * @throws Exception
+ */
+ public void testBarAnnotationProcessedLast() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ visitEnd(Foo.class, type);
+
+ // now simulate process the bar impl
+ ConstructorDefinition<?> definition = type.getConstructorDefinition();
+ definition.getParameters()[0].setName("myBar");
+ Property property = factory.createProperty();
+ property.setName("myBar");
+ type.getProperties().add(property);
+
+ assertEquals(2, type.getProperties().size());
+ assertEquals("foo", definition.getParameters()[1].getName());
+ }
+
+ /**
+ * Verifies heuristic processing can be called before an extension
+ * annotation processors is called with the extension parameter in a middle
+ * position. Specifically, verifies that the heuristic processor updates
+ * injection names and preserves their ordering.
+ */
+ public void testBarAnnotationProcessedFirstInMiddle() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ Constructor<Foo2> ctor = Foo2.class.getConstructor(String.class, String.class, String.class);
+ ConstructorDefinition<Foo2> definition = new ConstructorDefinition<Foo2>(ctor);
+ type.setConstructorDefinition(definition);
+ // insert placeholder for first param, which would be done by a
+ // processor
+ definition.getParameters()[0].setName("");
+ Property property = factory.createProperty();
+ // Hack to add a property member
+ JavaElement element = new JavaElement("myBar", String.class);
+ type.getPropertyMembers().put("myBar", element);
+ property.setName("myBar");
+ definition.getParameters()[1].setName("myBar");
+ type.getProperties().add(property);
+ visitEnd(Foo2.class, type);
+ assertEquals("baz", definition.getParameters()[0].getName());
+ assertEquals(2, type.getProperties().size());
+ assertEquals(1, type.getReferences().size());
+ }
+
+ public @interface Bar {
+
+ }
+
+ public static class Foo {
+ public Foo(@Bar
+ String prop, @org.osoa.sca.annotations.Property(name = "foo")
+ String prop2) {
+ }
+ }
+
+ public static class Foo2 {
+ public Foo2(@org.osoa.sca.annotations.Reference(name = "baz")
+ String prop1, @Bar
+ String prop2, @org.osoa.sca.annotations.Property(name = "foo")
+ String prop3) {
+ }
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.java?view=auto&rev=526232
==============================================================================
--- incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.java Fri Apr 6 10:30:44 2007
@@ -0,0 +1,96 @@
+/*
+ * 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.core.implementation.processor;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.processor.DuplicateInitException;
+import org.apache.tuscany.implementation.java.processor.IllegalInitException;
+import org.apache.tuscany.implementation.java.processor.InitProcessor;
+import org.osoa.sca.annotations.Init;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InitProcessorTestCase extends TestCase {
+
+ public void testInit() throws Exception {
+ InitProcessor processor = new InitProcessor();
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Method method = InitProcessorTestCase.Foo.class.getMethod("init");
+ processor.visitMethod(method, type);
+ assertNotNull(type.getInitMethod());
+ }
+
+ public void testBadInit() throws Exception {
+ InitProcessor processor = new InitProcessor();
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Method method = InitProcessorTestCase.Bar.class.getMethod("badInit", String.class);
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (IllegalInitException e) {
+ // expected
+ }
+ }
+
+ public void testTwoInit() throws Exception {
+ InitProcessor processor = new InitProcessor();
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Method method = InitProcessorTestCase.Bar.class.getMethod("init");
+ Method method2 = InitProcessorTestCase.Bar.class.getMethod("init2");
+ processor.visitMethod(method, type);
+ try {
+ processor.visitMethod(method2, type);
+ fail();
+ } catch (DuplicateInitException e) {
+ // expected
+ }
+ }
+
+
+ private class Foo {
+ @Init
+ public void init() {
+ }
+ }
+
+
+ private class Bar {
+ @Init
+ public void init() {
+ }
+
+ @Init
+ public void init2() {
+ }
+
+ @Init
+ public void badInit(String foo) {
+ }
+
+
+ }
+}
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ModelHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ModelHelper.java?view=auto&rev=526232
==============================================================================
--- incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ModelHelper.java (added)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ModelHelper.java Fri Apr 6 10:30:44 2007
@@ -0,0 +1,98 @@
+/*
+ * 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.core.implementation.processor;
+
+import org.apache.tuscany.assembly.AssemblyFactory;
+import org.apache.tuscany.assembly.ComponentService;
+import org.apache.tuscany.assembly.Contract;
+import org.apache.tuscany.assembly.Property;
+import org.apache.tuscany.assembly.Reference;
+import org.apache.tuscany.assembly.Service;
+import org.apache.tuscany.assembly.impl.DefaultAssemblyFactory;
+import org.apache.tuscany.core.implementation.processor.HeuristicConstructorTestCase.Foo1;
+import org.apache.tuscany.idl.Interface;
+import org.apache.tuscany.idl.java.JavaFactory;
+import org.apache.tuscany.idl.java.JavaInterface;
+import org.apache.tuscany.idl.java.impl.DefaultJavaFactory;
+import org.apache.tuscany.idl.java.impl.JavaInterfaceImpl;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ModelHelper {
+ private final static AssemblyFactory factory = new DefaultAssemblyFactory();
+ private final static JavaFactory javaFactory = new DefaultJavaFactory();
+
+ public static Property getProperty(JavaImplementationDefinition type, String name) {
+ for (Property prop : type.getProperties()) {
+ if (prop.getName().equals(name)) {
+ return prop;
+ }
+ }
+ return null;
+ }
+
+ public static Reference getReference(JavaImplementationDefinition type, String name) {
+ for (Reference ref : type.getReferences()) {
+ if (ref.getName().equals(name)) {
+ return ref;
+ }
+ }
+ return null;
+ }
+
+ public static Service getService(JavaImplementationDefinition type, String name) {
+ for (Service svc : type.getServices()) {
+ if (svc.getName().equals(name)) {
+ return svc;
+ }
+ }
+ return null;
+ }
+
+ public static boolean matches(Contract contract, Class<?> type) {
+ Interface interface1 = contract.getInterface();
+ if (interface1 instanceof JavaInterface) {
+ return type == ((JavaInterface)interface1).getJavaClass();
+ } else {
+ return false;
+ }
+ }
+
+ public static ComponentService createService(Class<?> type) {
+ org.apache.tuscany.assembly.ComponentService ref = factory.createComponentService();
+ ref.setName(type.getSimpleName());
+ JavaInterface i = new JavaInterfaceImpl();
+ i.setJavaClass(type);
+ ref.setInterface(i);
+ return ref;
+ }
+
+ public static Reference createReference(String name, Class<?> type) {
+ org.apache.tuscany.assembly.Reference ref = factory.createReference();
+ ref.setName(name);
+ JavaInterface i = new JavaInterfaceImpl();
+ i.setJavaClass(type);
+ ref.setInterface(i);
+ return ref;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ModelHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ModelHelper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java?view=auto&rev=526232
==============================================================================
--- incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java Fri Apr 6 10:30:44 2007
@@ -0,0 +1,211 @@
+/*
+ * 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.core.implementation.processor;
+
+import static org.apache.tuscany.core.implementation.processor.ModelHelper.getProperty;
+
+import java.util.Collection;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.implementation.java.impl.JavaElement;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.introspection.DuplicatePropertyException;
+import org.apache.tuscany.implementation.java.introspection.IllegalPropertyException;
+import org.apache.tuscany.implementation.java.processor.JavaIntrospectionHelper;
+import org.apache.tuscany.implementation.java.processor.PropertyProcessor;
+import org.osoa.sca.annotations.Property;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PropertyProcessorTestCase extends TestCase {
+
+ JavaImplementationDefinition type;
+ PropertyProcessor processor;
+
+ public void testMethodAnnotation() throws Exception {
+ processor.visitMethod(Foo.class.getMethod("setFoo", String.class), type);
+ assertNotNull(getProperty(type, "foo"));
+ }
+
+ public void testMethodRequired() throws Exception {
+ processor.visitMethod(Foo.class.getMethod("setFooRequired", String.class), type);
+ org.apache.tuscany.assembly.Property prop = getProperty(type, "fooRequired");
+ assertNotNull(prop);
+ assertTrue(prop.isMustSupply());
+ }
+
+ public void testMethodName() throws Exception {
+ processor.visitMethod(Foo.class.getMethod("setBarMethod", String.class), type);
+ assertNotNull(getProperty(type, "bar"));
+ }
+
+ public void testFieldAnnotation() throws Exception {
+ processor.visitField(Foo.class.getDeclaredField("baz"), type);
+ assertNotNull(getProperty(type, "baz"));
+ }
+
+ public void testFieldRequired() throws Exception {
+ processor.visitField(Foo.class.getDeclaredField("bazRequired"), type);
+ org.apache.tuscany.assembly.Property prop = getProperty(type, "bazRequired");
+ assertNotNull(prop);
+ assertTrue(prop.isMustSupply());
+ }
+
+ public void testFieldName() throws Exception {
+ processor.visitField(Foo.class.getDeclaredField("bazField"), type);
+ assertNotNull(getProperty(type, "theBaz"));
+ }
+
+ public void testDuplicateFields() throws Exception {
+ processor.visitField(Bar.class.getDeclaredField("dup"), type);
+ try {
+ processor.visitField(Bar.class.getDeclaredField("baz"), type);
+ fail();
+ } catch (DuplicatePropertyException e) {
+ // expected
+ }
+ }
+
+ public void testDuplicateMethods() throws Exception {
+ processor.visitMethod(Bar.class.getMethod("dupMethod", String.class), type);
+ try {
+ processor.visitMethod(Bar.class.getMethod("dupSomeMethod", String.class), type);
+ fail();
+ } catch (DuplicatePropertyException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidProperty() throws Exception {
+ try {
+ processor.visitMethod(Bar.class.getMethod("badMethod"), type);
+ fail();
+ } catch (IllegalPropertyException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ type = new JavaImplementationDefinition();
+ processor = new PropertyProcessor();
+ }
+
+ private class Foo {
+
+ @Property
+ protected String baz;
+ @Property(required = true)
+ protected String bazRequired;
+ @Property(name = "theBaz")
+ protected String bazField;
+
+ @Property
+ public void setFoo(String string) {
+ }
+
+ @Property(required = true)
+ public void setFooRequired(String string) {
+ }
+
+ @Property(name = "bar")
+ public void setBarMethod(String string) {
+ }
+
+ }
+
+ private class Bar {
+
+ @Property
+ protected String dup;
+
+ @Property(name = "dup")
+ protected String baz;
+
+ @Property
+ public void dupMethod(String s) {
+ }
+
+ @Property(name = "dupMethod")
+ public void dupSomeMethod(String s) {
+ }
+
+ @Property
+ public void badMethod() {
+ }
+
+ }
+
+ private class Multiple {
+ @Property
+ protected List<String> refs1;
+
+ @Property
+ protected String[] refs2;
+
+ @Property
+ public void setRefs3(String[] refs) {
+ }
+
+ @Property
+ public void setRefs4(Collection<String> refs) {
+ }
+
+ }
+
+ private Class<?> getBaseType(JavaElement element) {
+ return JavaIntrospectionHelper.getBaseType(element.getType(), element.getGenericType());
+ }
+
+ public void testMultiplicityCollection() throws Exception {
+ processor.visitField(Multiple.class.getDeclaredField("refs1"), type);
+ org.apache.tuscany.assembly.Property prop = getProperty(type, "refs1");
+ assertNotNull(prop);
+ assertSame(String.class, getBaseType(type.getPropertyMembers().get(prop.getName())));
+ assertTrue(prop.isMany());
+ }
+
+ public void testMultiplicityArray() throws Exception {
+ processor.visitField(Multiple.class.getDeclaredField("refs2"), type);
+ org.apache.tuscany.assembly.Property prop = getProperty(type, "refs2");
+ assertNotNull(prop);
+ assertSame(String.class, getBaseType(type.getPropertyMembers().get(prop.getName())));
+ assertTrue(prop.isMany());
+ }
+
+ public void testMultiplicityArrayMethod() throws Exception {
+ processor.visitMethod(Multiple.class.getMethod("setRefs3", String[].class), type);
+ org.apache.tuscany.assembly.Property prop = getProperty(type, "refs3");
+ assertNotNull(prop);
+ assertSame(String.class, getBaseType(type.getPropertyMembers().get(prop.getName())));
+ assertTrue(prop.isMany());
+ }
+
+ public void testMultiplicityCollectionMethod() throws Exception {
+ processor.visitMethod(Multiple.class.getMethod("setRefs4", Collection.class), type);
+ org.apache.tuscany.assembly.Property prop = getProperty(type, "refs4");
+ assertNotNull(prop);
+ assertSame(String.class, getBaseType(type.getPropertyMembers().get(prop.getName())));
+ assertTrue(prop.isMany());
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java?view=auto&rev=526232
==============================================================================
--- incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java Fri Apr 6 10:30:44 2007
@@ -0,0 +1,220 @@
+/*
+ * 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.core.implementation.processor;
+
+import static org.apache.tuscany.core.implementation.processor.ModelHelper.getReference;
+
+import java.util.Collection;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.assembly.Multiplicity;
+import org.apache.tuscany.idl.java.JavaInterface;
+import org.apache.tuscany.idl.java.introspection.impl.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.processor.DuplicateReferenceException;
+import org.apache.tuscany.implementation.java.processor.IllegalReferenceException;
+import org.apache.tuscany.implementation.java.processor.ReferenceProcessor;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReferenceProcessorTestCase extends TestCase {
+
+ private JavaImplementationDefinition type;
+ private ReferenceProcessor processor;
+
+ public void testMethodAnnotation() throws Exception {
+ processor.visitMethod(ReferenceProcessorTestCase.Foo.class.getMethod("setFoo", Ref.class), type);
+ org.apache.tuscany.assembly.Reference reference = getReference(type, "foo");
+ assertNotNull(reference);
+ assertEquals(Ref.class, ((JavaInterface)reference.getInterface()).getJavaClass());
+ }
+
+ public void testMethodRequired() throws Exception {
+ processor.visitMethod(ReferenceProcessorTestCase.Foo.class.getMethod("setFooRequired", Ref.class), type);
+ org.apache.tuscany.assembly.Reference ref = getReference(type, "fooRequired");
+ assertNotNull(ref);
+ assertEquals(Multiplicity.ONE_ONE, ref.getMultiplicity());
+ }
+
+ public void testMethodName() throws Exception {
+ processor.visitMethod(ReferenceProcessorTestCase.Foo.class.getMethod("setBarMethod", Ref.class), type);
+ assertNotNull(getReference(type, "bar"));
+ }
+
+ public void testFieldAnnotation() throws Exception {
+ processor.visitField(ReferenceProcessorTestCase.Foo.class.getDeclaredField("baz"), type);
+ org.apache.tuscany.assembly.Reference reference = getReference(type, "baz");
+ assertNotNull(reference);
+ assertEquals(Ref.class, ((JavaInterface)reference.getInterface()).getJavaClass());
+ }
+
+ public void testFieldRequired() throws Exception {
+ processor.visitField(ReferenceProcessorTestCase.Foo.class.getDeclaredField("bazRequired"), type);
+ org.apache.tuscany.assembly.Reference ref = getReference(type, "bazRequired");
+ assertNotNull(ref);
+ assertEquals(Multiplicity.ONE_ONE, ref.getMultiplicity());
+ }
+
+ public void testFieldName() throws Exception {
+ processor.visitField(ReferenceProcessorTestCase.Foo.class.getDeclaredField("bazField"), type);
+ assertNotNull(getReference(type, "theBaz"));
+ }
+
+ public void testDuplicateFields() throws Exception {
+ processor.visitField(ReferenceProcessorTestCase.Bar.class.getDeclaredField("dup"), type);
+ try {
+ processor.visitField(ReferenceProcessorTestCase.Bar.class.getDeclaredField("baz"), type);
+ fail();
+ } catch (DuplicateReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testDuplicateMethods() throws Exception {
+ processor.visitMethod(ReferenceProcessorTestCase.Bar.class.getMethod("dupMethod", Ref.class), type);
+ try {
+ processor.visitMethod(ReferenceProcessorTestCase.Bar.class.getMethod("dupSomeMethod", Ref.class), type);
+ fail();
+ } catch (DuplicateReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidProperty() throws Exception {
+ try {
+ processor.visitMethod(ReferenceProcessorTestCase.Bar.class.getMethod("badMethod"), type);
+ fail();
+ } catch (IllegalReferenceException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ type = new JavaImplementationDefinition();
+ processor = new ReferenceProcessor();
+ processor.setInterfaceProcessorRegistry(new JavaInterfaceProcessorRegistryImpl());
+ }
+
+ private interface Ref {
+ }
+
+ private class Foo {
+
+ @Reference
+ protected Ref baz;
+ @Reference(required = true)
+ protected Ref bazRequired;
+ @Reference(name = "theBaz")
+ protected Ref bazField;
+
+ @Reference
+ public void setFoo(Ref ref) {
+ }
+
+ @Reference(required = true)
+ public void setFooRequired(Ref ref) {
+ }
+
+ @Reference(name = "bar")
+ public void setBarMethod(Ref ref) {
+ }
+
+ }
+
+ private class Bar {
+
+ @Reference
+ protected Ref dup;
+
+ @Reference(name = "dup")
+ protected Ref baz;
+
+ @Reference
+ public void dupMethod(Ref s) {
+ }
+
+ @Reference(name = "dupMethod")
+ public void dupSomeMethod(Ref s) {
+ }
+
+ @Reference
+ public void badMethod() {
+ }
+
+ }
+
+ private class Multiple {
+ @Reference(required = true)
+ protected List<Ref> refs1;
+
+ @Reference(required = false)
+ protected Ref[] refs2;
+
+ @Reference(required = true)
+ public void setRefs3(Ref[] refs) {
+ }
+
+ @Reference(required = false)
+ public void setRefs4(Collection<Ref> refs) {
+ }
+
+ }
+
+ public void testMultiplicity1ToN() throws Exception {
+ processor.visitField(Multiple.class.getDeclaredField("refs1"), type);
+ org.apache.tuscany.assembly.Reference ref = getReference(type, "refs1");
+ assertNotNull(ref);
+ assertSame(Ref.class, ((JavaInterface)ref.getInterface()).getJavaClass());
+ assertEquals(Multiplicity.ONE_N, ref.getMultiplicity());
+ // assertEquals(Multiplicity.ONE_ONE, ref.getMultiplicity());
+ }
+
+ public void testMultiplicityTo0ToN() throws Exception {
+ processor.visitField(Multiple.class.getDeclaredField("refs2"), type);
+ org.apache.tuscany.assembly.Reference ref = getReference(type, "refs2");
+ assertNotNull(ref);
+ assertSame(Ref.class, ((JavaInterface)ref.getInterface()).getJavaClass());
+ assertEquals(Multiplicity.ZERO_N, ref.getMultiplicity());
+ // assertFalse(ref.isMustSupply());
+ }
+
+ public void testMultiplicity1ToNMethod() throws Exception {
+ processor.visitMethod(Multiple.class.getMethod("setRefs3", Ref[].class), type);
+ org.apache.tuscany.assembly.Reference ref = getReference(type, "refs3");
+ assertNotNull(ref);
+ assertSame(Ref.class, ((JavaInterface)ref.getInterface()).getJavaClass());
+ assertEquals(Multiplicity.ONE_N, ref.getMultiplicity());
+ // assertEquals(Multiplicity.ONE_ONE, ref.getMultiplicity());
+ }
+
+ public void testMultiplicity0ToNMethod() throws Exception {
+ processor.visitMethod(Multiple.class.getMethod("setRefs4", Collection.class), type);
+ org.apache.tuscany.assembly.Reference ref = getReference(type, "refs4");
+ assertNotNull(ref);
+ assertSame(Ref.class, ((JavaInterface)ref.getInterface()).getJavaClass());
+ assertEquals(Multiplicity.ZERO_N, ref.getMultiplicity());
+ // assertFalse(ref.isMustSupply());
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org