You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2007/04/11 04:55:07 UTC

svn commit: r527378 [7/9] - in /incubator/tuscany/java/sca/modules: assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/ assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ assembly-xml/src/test/java/org/apache/tuscany/assembly/xml/...

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorProcessorTestCase.java?view=auto&rev=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorProcessorTestCase.java Tue Apr 10 19:55:00 2007
@@ -0,0 +1,188 @@
+/*
+ * 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.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.implementation.java.introspect.impl.ModelHelper.getProperty;
+import static org.apache.tuscany.implementation.java.introspect.impl.ModelHelper.getReference;
+
+import java.lang.reflect.Constructor;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.assembly.Multiplicity;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.impl.Parameter;
+import org.apache.tuscany.implementation.java.introspect.impl.ConstructorProcessor;
+import org.apache.tuscany.implementation.java.introspect.impl.DuplicateConstructorException;
+import org.apache.tuscany.implementation.java.introspect.impl.InvalidConstructorException;
+import org.apache.tuscany.implementation.java.introspect.impl.PropertyProcessor;
+import org.apache.tuscany.implementation.java.introspect.impl.ReferenceProcessor;
+import org.apache.tuscany.interfacedef.java.introspect.DefaultJavaInterfaceIntrospector;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorProcessorTestCase extends TestCase {
+    private ConstructorProcessor processor = new ConstructorProcessor();
+
+    public void testDuplicateConstructor() throws Exception {
+        JavaImplementationDefinition type = new JavaImplementationDefinition();
+        try {
+            processor.visitClass(BadFoo.class, type);
+            fail();
+        } catch (DuplicateConstructorException e) {
+            // expected
+        }
+    }
+
+    public void testConstructorAnnotation() throws Exception {
+        JavaImplementationDefinition type = new JavaImplementationDefinition();
+        Constructor<Foo> ctor1 = Foo.class.getConstructor(String.class);
+        processor.visitConstructor(ctor1, type);
+        assertEquals("foo", type.getConstructorDefinition().getParameters()[0].getName());
+    }
+
+    public void testNoAnnotation() throws Exception {
+        JavaImplementationDefinition type = new JavaImplementationDefinition();
+        Constructor<NoAnnotation> ctor1 = NoAnnotation.class.getConstructor();
+        processor.visitConstructor(ctor1, type);
+        assertNull(type.getConstructorDefinition());
+    }
+
+    public void testBadAnnotation() throws Exception {
+        JavaImplementationDefinition type = new JavaImplementationDefinition();
+        Constructor<BadAnnotation> ctor1 = BadAnnotation.class.getConstructor(String.class, Foo.class);
+        try {
+            processor.visitConstructor(ctor1, type);
+            fail();
+        } catch (InvalidConstructorException e) {
+            // expected
+        }
+    }
+
+    public void testMixedParameters() throws Exception {
+        JavaImplementationDefinition type = new JavaImplementationDefinition();
+        Constructor<Mixed> ctor1 = Mixed.class.getConstructor(String.class, String.class, String.class);
+        processor.visitConstructor(ctor1, type);
+
+        ReferenceProcessor referenceProcessor = new ReferenceProcessor();
+        referenceProcessor.setInterfaceVisitorExtensionPoint(new DefaultJavaInterfaceIntrospector());
+        PropertyProcessor propertyProcessor = new PropertyProcessor();
+        Parameter[] parameters = type.getConstructorDefinition().getParameters();
+        for (int i = 0; i < parameters.length; i++) {
+            referenceProcessor.visitConstructorParameter(parameters[i], type);
+            propertyProcessor.visitConstructorParameter(parameters[i], type);
+        }
+
+        assertEquals("_ref0", parameters[0].getName());
+        assertEquals("foo", parameters[1].getName());
+        assertEquals("bar", parameters[2].getName());
+    }
+
+    private static class BadFoo {
+
+        @org.osoa.sca.annotations.Constructor("foo")
+        public BadFoo(String foo) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor( {"foo", "bar"})
+        public BadFoo(String foo, String bar) {
+
+        }
+    }
+
+    private static class Foo {
+        @org.osoa.sca.annotations.Constructor("foo")
+        public Foo(String foo) {
+
+        }
+    }
+
+    private static class NoAnnotation {
+        public NoAnnotation() {
+        }
+    }
+
+    private static class BadAnnotation {
+        @org.osoa.sca.annotations.Constructor("foo")
+        public BadAnnotation(String foo, Foo ref) {
+        }
+    }
+
+    public static final class Mixed {
+        @org.osoa.sca.annotations.Constructor
+        public Mixed(@Reference
+        String param1, @Property(name = "foo")
+        String param2, @Reference(name = "bar")
+        String param3) {
+        }
+    }
+
+    public static final class Multiple {
+        @org.osoa.sca.annotations.Constructor
+        public Multiple(@Reference
+        Collection<String> param1, @Property(name = "foo")
+        String[] param2, @Reference(name = "bar", required = true)
+        List<String> param3, @Property(name = "abc")
+        Set<String> param4, @Reference(name = "xyz")
+        String[] param5) {
+        }
+    }
+
+    public void testMultiplicity() throws Exception {
+        JavaImplementationDefinition type = new JavaImplementationDefinition();
+        Constructor<Multiple> ctor1 = Multiple.class.getConstructor(Collection.class,
+                                                                    String[].class,
+                                                                    List.class,
+                                                                    Set.class,
+                                                                    String[].class);
+        processor.visitConstructor(ctor1, type);
+        ReferenceProcessor referenceProcessor = new ReferenceProcessor();
+        referenceProcessor.setInterfaceVisitorExtensionPoint(new DefaultJavaInterfaceIntrospector());
+        PropertyProcessor propertyProcessor = new PropertyProcessor();
+        Parameter[] parameters = type.getConstructorDefinition().getParameters();
+        for (int i = 0; i < parameters.length; i++) {
+            referenceProcessor.visitConstructorParameter(parameters[i], type);
+            propertyProcessor.visitConstructorParameter(parameters[i], type);
+        }
+
+        org.apache.tuscany.assembly.Reference ref0 = getReference(type, "_ref0");
+        assertNotNull(ref0);
+        assertEquals(Multiplicity.ZERO_N, ref0.getMultiplicity());
+        org.apache.tuscany.assembly.Reference ref1 = getReference(type, "bar");
+        assertNotNull(ref1);
+        assertEquals(Multiplicity.ONE_N, ref1.getMultiplicity());
+        org.apache.tuscany.assembly.Reference ref2 = getReference(type, "xyz");
+        assertNotNull(ref2);
+        assertEquals(Multiplicity.ZERO_N, ref2.getMultiplicity());
+        org.apache.tuscany.assembly.Property prop1 = getProperty(type, "foo");
+        assertNotNull(prop1);
+        assertTrue(prop1.isMany());
+        org.apache.tuscany.assembly.Property prop2 = getProperty(type, "abc");
+        assertNotNull(prop2);
+        assertTrue(prop2.isMany());
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorProcessorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorProcessorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorPropertyTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorPropertyTestCase.java?view=auto&rev=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorPropertyTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorPropertyTestCase.java Tue Apr 10 19:55:00 2007
@@ -0,0 +1,163 @@
+/*
+ * 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.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.implementation.java.introspect.impl.ModelHelper.getProperty;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.introspect.DuplicatePropertyException;
+import org.apache.tuscany.implementation.java.introspect.impl.InvalidConstructorException;
+import org.apache.tuscany.implementation.java.introspect.impl.InvalidPropertyException;
+import org.osoa.sca.annotations.Property;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorPropertyTestCase extends AbstractProcessorTest {
+
+    public void testProperty() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+        visitConstructor(ctor, type);
+        org.apache.tuscany.assembly.Property property = getProperty(type, "myProp");
+        assertTrue(property.isMustSupply());
+        assertEquals("myProp", property.getName());
+    }
+
+    public void testTwoPropertiesSameType() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+        visitConstructor(ctor, type);
+        assertNotNull(getProperty(type, "myProp1"));
+        assertNotNull(getProperty(type, "myProp2"));
+    }
+
+    public void testDuplicateProperty() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class);
+        try {
+            visitConstructor(ctor, type);
+            fail();
+        } catch (DuplicatePropertyException e) {
+            // expected
+        }
+    }
+
+    public void testNoName() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class);
+        try {
+            visitConstructor(ctor, type);
+            fail();
+        } catch (InvalidPropertyException e) {
+            // expected
+        }
+    }
+
+    public void testNamesOnConstructor() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class);
+        visitConstructor(ctor, type);
+        assertNotNull(getProperty(type, "myProp"));
+    }
+
+    public void testInvalidNumberOfNames() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<BadFoo> ctor = BadFoo.class.getConstructor(Integer.class, Integer.class);
+        try {
+            visitConstructor(ctor, type);
+            fail();
+        } catch (InvalidConstructorException e) {
+            // expected
+        }
+    }
+
+    public void testNoMatchingNames() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<BadFoo> ctor = BadFoo.class.getConstructor(List.class, List.class);
+        try {
+            visitConstructor(ctor, type);
+            fail();
+        } catch (InvalidConstructorException e) {
+            // expected
+        }
+    }
+
+//    public void testMultiplicityRequired() throws Exception {
+    // TODO multiplicity
+//    }
+
+    private static class Foo {
+
+        @org.osoa.sca.annotations.Constructor()
+        public Foo(@Property(name = "myProp", required = true)String prop) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor("myProp")
+        public Foo(@Property Integer prop) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor()
+        public Foo(@Property(name = "myProp1")String prop1, @Property(name = "myProp2")String prop2) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor()
+        public Foo(@Property List prop) {
+
+        }
+    }
+
+    private static class BadFoo {
+
+        @org.osoa.sca.annotations.Constructor()
+        public BadFoo(@Property(name = "myProp")String prop1, @Property(name = "myProp")String prop2) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor()
+        public BadFoo(@Property String prop) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor("myProp")
+        public BadFoo(@Property Integer prop, @Property Integer prop2) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor({"myRef", "myRef2"})
+        public BadFoo(@Property List ref, @Property(name = "myOtherRef")List ref2) {
+
+        }
+
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorPropertyTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorPropertyTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorReferenceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorReferenceTestCase.java?view=auto&rev=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorReferenceTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorReferenceTestCase.java Tue Apr 10 19:55:00 2007
@@ -0,0 +1,171 @@
+/*
+ * 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.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.implementation.java.introspect.impl.ModelHelper.getReference;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.apache.tuscany.assembly.Multiplicity;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.introspect.impl.DuplicateReferenceException;
+import org.apache.tuscany.implementation.java.introspect.impl.InvalidConstructorException;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorReferenceTestCase extends AbstractProcessorTest {
+
+    public void testReference() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+        visitConstructor(ctor, type);
+        org.apache.tuscany.assembly.Reference reference = getReference(type, "myRef");
+        assertEquals(Multiplicity.ONE_ONE, reference.getMultiplicity());
+        assertEquals("myRef", reference.getName());
+    }
+
+    public void testTwoReferencesSameType() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+        visitConstructor(ctor, type);
+        assertNotNull(getReference(type, "myRef1"));
+        assertNotNull(getReference(type, "myRef2"));
+    }
+
+    public void testDuplicateProperty() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class);
+        try {
+            visitConstructor(ctor, type);
+            fail();
+        } catch (DuplicateReferenceException e) {
+            // expected
+        }
+    }
+
+    public void testNoName() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<NoNameFoo> ctor = NoNameFoo.class.getConstructor(String.class);
+        visitConstructor(ctor, type);
+        assertNotNull(getReference(type, "_ref0"));
+    }
+
+    public void testNamesOnConstructor() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class);
+        visitConstructor(ctor, type);
+        assertNotNull(getReference(type, "myRef"));
+    }
+
+    public void testInvalidNumberOfNames() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<BadFoo> ctor = BadFoo.class.getConstructor(Integer.class, Integer.class);
+        try {
+            visitConstructor(ctor, type);
+            fail();
+        } catch (InvalidConstructorException e) {
+            // expected
+        }
+    }
+
+    public void testNoMatchingNames() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<BadFoo> ctor = BadFoo.class.getConstructor(List.class, List.class);
+        try {
+            visitConstructor(ctor, type);
+            fail();
+        } catch (InvalidConstructorException e) {
+            // expected
+        }
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+//    public void testMultiplicityRequired() throws Exception {
+    // TODO multiplicity
+//    }
+
+    private static class Foo {
+
+        @org.osoa.sca.annotations.Constructor()
+        public Foo(@Reference(name = "myRef", required = true)String prop) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor()
+        public Foo(@Reference(name = "myRef1")String prop1, @Reference(name = "myRef2")String prop2) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor("myRef")
+        public Foo(@Reference Integer prop) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor()
+        public Foo(@Reference List prop) {
+
+        }
+    }
+
+    private static class NoNameFoo {
+
+        @org.osoa.sca.annotations.Constructor
+        public NoNameFoo(@Reference String prop) {
+
+        }
+    }
+
+    private static class BadFoo {
+
+        @org.osoa.sca.annotations.Constructor
+        public BadFoo(@Reference(name = "myRef")String prop1, @Reference(name = "myRef")String prop2) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor
+        public BadFoo(@Reference String prop) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor("myRef")
+        public BadFoo(@Reference Integer ref, @Reference Integer ref2) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor({"myRef", "myRef2"})
+        public BadFoo(@Reference List ref, @Reference(name = "myOtherRef")List ref2) {
+
+        }
+
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorReferenceTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorReferenceTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorResourceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorResourceTestCase.java?view=auto&rev=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorResourceTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorResourceTestCase.java Tue Apr 10 19:55:00 2007
@@ -0,0 +1,159 @@
+/*
+ * 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.implementation.java.introspect.impl;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.apache.tuscany.api.annotation.Resource;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.introspect.impl.DuplicateResourceException;
+import org.apache.tuscany.implementation.java.introspect.impl.InvalidConstructorException;
+import org.apache.tuscany.implementation.java.introspect.impl.InvalidResourceException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorResourceTestCase extends AbstractProcessorTest {
+
+    public void testResource() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+        visitConstructor(ctor, type);
+        org.apache.tuscany.implementation.java.impl.Resource resource = type.getResources().get("myResource");
+        assertFalse(resource.isOptional());
+    }
+
+    public void testTwoResourcesSameType() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+        visitConstructor(ctor, type);
+        assertNotNull(type.getResources().get("myResource1"));
+        assertNotNull(type.getResources().get("myResource2"));
+    }
+
+    public void testDuplicateResource() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class);
+        try {
+            visitConstructor(ctor, type);
+            fail();
+        } catch (DuplicateResourceException e) {
+            // expected
+        }
+    }
+
+    public void testNoName() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+            ConstructorResourceTestCase.BadFoo.class.getConstructor(String.class);
+        try {
+            visitConstructor(ctor, type);
+            fail();
+        } catch (InvalidResourceException e) {
+            // expected
+        }
+    }
+
+    public void testNamesOnConstructor() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class);
+        visitConstructor(ctor, type);
+        assertNotNull(type.getResources().get("myResource"));
+    }
+
+    public void testInvalidNumberOfNames() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+            ConstructorResourceTestCase.BadFoo.class.getConstructor(Integer.class, Integer.class);
+        try {
+            visitConstructor(ctor, type);
+            fail();
+        } catch (InvalidConstructorException e) {
+            // expected
+        }
+    }
+
+    public void testNoMatchingNames() throws Exception {
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+            ConstructorResourceTestCase.BadFoo.class.getConstructor(List.class, List.class);
+        try {
+            visitConstructor(ctor, type);
+            fail();
+        } catch (InvalidConstructorException e) {
+            // expected
+        }
+    }
+
+    private static class Foo {
+
+        @org.osoa.sca.annotations.Constructor
+        public Foo(@Resource(name = "myResource") String resource) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor("myResource")
+        public Foo(@Resource Integer resource) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor
+        public Foo(@Resource(name = "myResource1") String res1, @Resource(name = "myResource2") String res2) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor
+        public Foo(@Resource List res) {
+
+        }
+    }
+
+    private static class BadFoo {
+
+        @org.osoa.sca.annotations.Constructor
+        public BadFoo(@Resource(name = "myResource") String res1, @Resource(name = "myResource") String res2) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor
+        public BadFoo(@Resource String res) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor("myProp")
+        public BadFoo(@Resource Integer res, @Resource Integer res2) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor({"myRes", "myRes2"})
+        public BadFoo(@Resource List res, @Resource(name = "myOtherRes") List res2) {
+
+        }
+
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorResourceTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConstructorResourceTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ContextProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ContextProcessorTestCase.java?view=auto&rev=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ContextProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ContextProcessorTestCase.java Tue Apr 10 19:55:00 2007
@@ -0,0 +1,194 @@
+/*
+ * 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.implementation.java.introspect.impl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.assembly.Component;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.introspect.impl.ContextProcessor;
+import org.apache.tuscany.implementation.java.introspect.impl.IllegalContextException;
+import org.apache.tuscany.implementation.java.introspect.impl.UnknownContextTypeException;
+import org.easymock.EasyMock;
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.RequestContext;
+import org.osoa.sca.annotations.Context;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ContextProcessorTestCase extends TestCase {
+    private ContextProcessor processor;
+    private Component composite;
+
+    // FIXME: resurrect to test ComponentContext injection
+/*
+    public void testCompositeContextMethod() throws Exception {
+        Method method = Foo.class.getMethod("setContext", ComponentContext.class);
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        processor.visitMethod(composite, method, type);
+        assertNotNull(type.getResources().get("context"));
+    }
+*/
+
+    // FIXME: resurrect to test ComponentContext injection
+/*
+    public void testCompositeContextField() throws Exception {
+        Field field = Foo.class.getDeclaredField("context");
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        processor.visitField(composite, field, type);
+        assertNotNull(type.getResources().get("context"));
+    }
+*/
+
+    public void testRequestContextMethod() throws Exception {
+        Method method = Foo.class.getMethod("setRequestContext", RequestContext.class);
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        processor.visitMethod(method, type);
+        assertNotNull(type.getResources().get("requestContext"));
+    }
+
+    public void testRequestContextField() throws Exception {
+        Field field = Foo.class.getDeclaredField("requestContext");
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        processor.visitField(field, type);
+        assertNotNull(type.getResources().get("requestContext"));
+    }
+
+    public void testInvalidParamType() throws Exception {
+        Method method = Foo.class.getMethod("setContext", String.class);
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        try {
+            processor.visitMethod(method, type);
+            fail();
+        } catch (UnknownContextTypeException e) {
+            // expected
+        }
+    }
+
+    public void testInvalidParamTypeField() throws Exception {
+        Field field = Foo.class.getDeclaredField("badContext");
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        try {
+            processor.visitField(field, type);
+            fail();
+        } catch (UnknownContextTypeException e) {
+            // expected
+        }
+    }
+
+
+    public void testInvalidParamNum() throws Exception {
+        Method method = Foo.class.getMethod("setContext", ComponentContext.class, String.class);
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        try {
+            processor.visitMethod(method, type);
+            fail();
+        } catch (IllegalContextException e) {
+            // expected
+        }
+    }
+
+    public void testInvalidNoParams() throws Exception {
+        Method method = Foo.class.getMethod("setContext");
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        try {
+            processor.visitMethod(method, type);
+            fail();
+        } catch (IllegalContextException e) {
+            // expected
+        }
+    }
+
+    public void testNoContext() throws Exception {
+        Method method = Foo.class.getMethod("noContext", ComponentContext.class);
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        processor.visitMethod(method, type);
+        assertEquals(0, type.getResources().size());
+    }
+
+    public void testNoContextField() throws Exception {
+        Field field = Foo.class.getDeclaredField("noContext");
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        processor.visitField(field, type);
+        assertEquals(0, type.getResources().size());
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        processor = new ContextProcessor();
+        // processor.setWorkContext(EasyMock.createNiceMock(WorkContext.class));
+        composite = EasyMock.createNiceMock(Component.class);
+    }
+
+    private class Foo {
+        @Context
+        protected ComponentContext context;
+
+        @Context
+        protected Object badContext;
+
+        protected ComponentContext noContext;
+
+        @Context
+        protected RequestContext requestContext;
+
+        @Context
+        public void setContext(ComponentContext context) {
+
+        }
+
+        @Context
+        public void setContext(String context) {
+
+        }
+
+        @Context
+        public void setContext(ComponentContext context, String string) {
+
+        }
+
+        @Context
+        public void setContext() {
+
+        }
+
+        public void noContext(ComponentContext context) {
+
+        }
+
+        @Context
+        public void setRequestContext(RequestContext requestContext) {
+            this.requestContext = requestContext;
+        }
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ContextProcessorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ContextProcessorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConversationProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConversationProcessorTestCase.java?view=auto&rev=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConversationProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConversationProcessorTestCase.java Tue Apr 10 19:55:00 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.implementation.java.introspect.impl;
+
+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.introspect.impl.ConversationProcessor;
+import org.apache.tuscany.implementation.java.introspect.impl.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/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConversationProcessorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConversationProcessorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java?view=auto&rev=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java Tue Apr 10 19:55:00 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.implementation.java.introspect.impl;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.implementation.java.introspect.impl.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/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/DestroyProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/DestroyProcessorTestCase.java?view=auto&rev=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/DestroyProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/DestroyProcessorTestCase.java Tue Apr 10 19:55:00 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.implementation.java.introspect.impl;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.introspect.impl.DestroyProcessor;
+import org.apache.tuscany.implementation.java.introspect.impl.DuplicateDestructorException;
+import org.apache.tuscany.implementation.java.introspect.impl.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/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/DestroyProcessorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/DestroyProcessorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/EagerInitProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/EagerInitProcessorTestCase.java?view=auto&rev=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/EagerInitProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/EagerInitProcessorTestCase.java Tue Apr 10 19:55:00 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.implementation.java.introspect.impl;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.introspect.ProcessingException;
+import org.apache.tuscany.implementation.java.introspect.impl.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/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/EagerInitProcessorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/EagerInitProcessorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java?view=auto&rev=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java Tue Apr 10 19:55:00 2007
@@ -0,0 +1,69 @@
+/*
+ * 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.implementation.java.introspect.impl;
+
+import java.lang.reflect.Constructor;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.implementation.java.impl.ConstructorDefinition;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.introspect.impl.HeuristicPojoProcessor;
+import org.apache.tuscany.implementation.java.introspect.impl.PropertyProcessor;
+import org.apache.tuscany.interfacedef.java.introspect.DefaultJavaInterfaceIntrospector;
+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();
+        DefaultJavaInterfaceIntrospector introspector = new DefaultJavaInterfaceIntrospector();
+        propertyProcessor = new PropertyProcessor();
+        propertyProcessor.setInterfaceVisitorExtensionPoint(introspector);
+        heuristicProcessor = new HeuristicPojoProcessor();
+        heuristicProcessor.setInterfaceVisitorExtensionPoint(introspector);
+    }
+
+    public static class Foo {
+        public Foo(@Property(name = "foo")
+        String prop) {
+        }
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/HeuristicConstructorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/HeuristicConstructorTestCase.java?view=auto&rev=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/HeuristicConstructorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/HeuristicConstructorTestCase.java Tue Apr 10 19:55:00 2007
@@ -0,0 +1,304 @@
+/*
+ * 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.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.implementation.java.introspect.impl.ModelHelper.getProperty;
+
+import java.lang.reflect.Constructor;
+
+import org.apache.tuscany.implementation.java.impl.JavaElement;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.introspect.ProcessingException;
+import org.apache.tuscany.implementation.java.introspect.impl.AmbiguousConstructorException;
+import org.apache.tuscany.implementation.java.introspect.impl.HeuristicPojoProcessor;
+import org.apache.tuscany.implementation.java.introspect.impl.NoConstructorException;
+import org.apache.tuscany.interfacedef.java.introspect.DefaultJavaInterfaceIntrospector;
+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() {
+        DefaultJavaInterfaceIntrospector introspector = new DefaultJavaInterfaceIntrospector();
+        processor = new HeuristicPojoProcessor();
+        processor.setInterfaceVisitorExtensionPoint(introspector);
+    }
+
+    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, null);
+        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, null));
+        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, null);
+        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, null));
+        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, null));
+        org.apache.tuscany.assembly.Reference ref2 = ModelHelper.createReference("ref2", Foo1.class);
+        type.getReferences().add(ref2);
+        type.getReferenceMembers().put("ref2", new JavaElement("ref2", Foo1.class, null));
+        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/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/HeuristicConstructorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/HeuristicConstructorTestCase.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