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 [8/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/HeuristicPojoProcessorTestCase.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/HeuristicPojoProcessorTestCase.java?view=auto&rev=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/HeuristicPojoProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/HeuristicPojoProcessorTestCase.java Tue Apr 10 19:55:00 2007
@@ -0,0 +1,403 @@
+/*
+ * 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.Collection;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+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.introspect.ProcessingException;
+import org.apache.tuscany.interfacedef.java.introspect.DefaultJavaInterfaceIntrospector;
+import org.apache.tuscany.interfacedef.util.JavaXMLMapper;
+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.introspect.impl.HeuristicPojoProcessor processor;
+
+    public HeuristicPojoProcessorTestCase() {
+        DefaultJavaInterfaceIntrospector introspector = new DefaultJavaInterfaceIntrospector();
+        processor = new org.apache.tuscany.implementation.java.introspect.impl.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 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, null));
+        org.apache.tuscany.assembly.Reference ref2 = factory.createReference();
+        ref2.setName("reference2");
+        type.getReferences().add(ref2);
+        type.getReferenceMembers().put("reference2", new JavaElement("reference2", Ref.class, null));
+        org.apache.tuscany.assembly.Property prop1 = factory.createProperty();
+        prop1.setName("string1");
+        type.getProperties().add(prop1);
+        type.getPropertyMembers().put("string1", new JavaElement("string1", String.class, null));
+        org.apache.tuscany.assembly.Property prop2 = factory.createProperty();
+        prop2.setName("string2");
+        type.getProperties().add(prop2);
+        type.getPropertyMembers().put("string2", new JavaElement("string2", String.class, null));
+        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/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/HeuristicPojoProcessorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/HeutisticExtensibleConstructorTestCase.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/HeutisticExtensibleConstructorTestCase.java?view=auto&rev=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/HeutisticExtensibleConstructorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/HeutisticExtensibleConstructorTestCase.java Tue Apr 10 19:55:00 2007
@@ -0,0 +1,145 @@
+/*
+ * 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 org.apache.tuscany.assembly.Property;
+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.introspect.ProcessingException;
+import org.apache.tuscany.interfacedef.java.introspect.DefaultJavaInterfaceIntrospector;
+
+/**
+ * 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.introspect.impl.HeuristicPojoProcessor processor;
+
+    public HeutisticExtensibleConstructorTestCase() {
+        DefaultJavaInterfaceIntrospector introspector = new DefaultJavaInterfaceIntrospector();
+        processor = new org.apache.tuscany.implementation.java.introspect.impl.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 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 = &quot;foo&quot;) 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, null);
+        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/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/HeutisticExtensibleConstructorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

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

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

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ModelHelper.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/ModelHelper.java?view=auto&rev=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ModelHelper.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ModelHelper.java Tue Apr 10 19:55:00 2007
@@ -0,0 +1,100 @@
+/*
+ * 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 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.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.interfacedef.Interface;
+import org.apache.tuscany.interfacedef.java.JavaInterface;
+import org.apache.tuscany.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.interfacedef.java.impl.JavaInterfaceContractImpl;
+import org.apache.tuscany.interfacedef.java.impl.JavaInterfaceImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ModelHelper {
+    private final static AssemblyFactory factory = new DefaultAssemblyFactory();
+
+    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.getInterfaceContract().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);
+        JavaInterfaceContract ic = new JavaInterfaceContractImpl();
+        ic.setInterface(i);
+        ref.setInterfaceContract(ic);
+        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);
+        JavaInterfaceContract ic = new JavaInterfaceContractImpl();
+        ic.setInterface(i);
+        ref.setInterfaceContract(ic);
+        return ref;
+    }
+
+}

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

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

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

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

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ReferenceProcessorTestCase.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/ReferenceProcessorTestCase.java?view=auto&rev=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ReferenceProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ReferenceProcessorTestCase.java Tue Apr 10 19:55:00 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.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.implementation.java.introspect.impl.ModelHelper.getReference;
+
+import java.util.Collection;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+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.IllegalReferenceException;
+import org.apache.tuscany.implementation.java.introspect.impl.ReferenceProcessor;
+import org.apache.tuscany.interfacedef.java.JavaInterface;
+import org.apache.tuscany.interfacedef.java.introspect.DefaultJavaInterfaceIntrospector;
+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.getInterfaceContract().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.getInterfaceContract().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.setInterfaceVisitorExtensionPoint(new DefaultJavaInterfaceIntrospector());
+    }
+
+    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.getInterfaceContract().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.getInterfaceContract().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.getInterfaceContract().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.getInterfaceContract().getInterface()).getJavaClass());
+        assertEquals(Multiplicity.ZERO_N, ref.getMultiplicity());
+        // assertFalse(ref.isMustSupply());
+    }
+
+}

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

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

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ResourceProcessorTestCase.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/ResourceProcessorTestCase.java?view=auto&rev=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ResourceProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ResourceProcessorTestCase.java Tue Apr 10 19:55:00 2007
@@ -0,0 +1,117 @@
+/*
+ * 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.impl.Resource;
+import org.apache.tuscany.implementation.java.introspect.impl.DuplicateResourceException;
+import org.apache.tuscany.implementation.java.introspect.impl.IllegalResourceException;
+import org.apache.tuscany.implementation.java.introspect.impl.ResourceProcessor;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ResourceProcessorTestCase extends TestCase {
+
+    JavaImplementationDefinition type;
+    ResourceProcessor processor = new ResourceProcessor();
+
+    public void testVisitField() throws Exception {
+        Field field = Foo.class.getDeclaredField("bar");
+        processor.visitField(field, type);
+        Resource resource = type.getResources().get("bar");
+        assertFalse(resource.isOptional());
+        assertNull(resource.getMappedName());
+        assertEquals(field.getType(), resource.getElement().getType());
+    }
+
+    public void testVisitMethod() throws Exception {
+        Method method = Foo.class.getMethod("setBar", Bar.class);
+        processor.visitMethod(method, type);
+        Resource resource = type.getResources().get("bar");
+        assertFalse(resource.isOptional());
+        assertNull(resource.getMappedName());
+        assertEquals(method.getParameterTypes()[0], resource.getElement().getType());
+    }
+
+    public void testVisitNamedMethod() throws Exception {
+        Method method = Foo.class.getMethod("setBar2", Bar.class);
+        processor.visitMethod(method, type);
+        Resource resource = type.getResources().get("someName");
+        assertFalse(resource.isOptional());
+        assertEquals("mapped", resource.getMappedName());
+    }
+
+    public void testVisitBadMethod() throws Exception {
+        Method method = Foo.class.getMethod("setBad");
+        try {
+            processor.visitMethod(method, type);
+            fail();
+        } catch (IllegalResourceException e) {
+            // expected
+        }
+    }
+
+    public void testDuplicateResources() throws Exception {
+        Field field = Foo.class.getDeclaredField("bar");
+        processor.visitField(field, type);
+        try {
+            processor.visitField(field, type);
+            fail();
+        } catch (DuplicateResourceException e) {
+            //expected
+        }
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        type = new JavaImplementationDefinition();
+    }
+
+    private class Foo {
+
+        @org.apache.tuscany.api.annotation.Resource
+        protected Bar bar;
+
+        @org.apache.tuscany.api.annotation.Resource(optional = true)
+        protected Bar barNotRequired;
+
+        @org.apache.tuscany.api.annotation.Resource
+        public void setBar(Bar bar) {
+        }
+
+        @org.apache.tuscany.api.annotation.Resource(name = "someName", mappedName = "mapped")
+        public void setBar2(Bar bar) {
+        }
+
+        @org.apache.tuscany.api.annotation.Resource
+        public void setBad() {
+        }
+
+    }
+
+    private interface Bar {
+
+    }
+}

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

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

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ScopeProcessorTestCase.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/ScopeProcessorTestCase.java?view=auto&rev=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ScopeProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ScopeProcessorTestCase.java Tue Apr 10 19:55:00 2007
@@ -0,0 +1,126 @@
+/*
+ * 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.assembly.Component;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.impl.Scope;
+import org.apache.tuscany.implementation.java.introspect.ProcessingException;
+import org.apache.tuscany.implementation.java.introspect.impl.ScopeProcessor;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ScopeProcessorTestCase extends TestCase {
+
+    Component parent;
+
+    public void testCompositeScope() throws ProcessingException {
+        ScopeProcessor processor = new ScopeProcessor();
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+
+        processor.visitClass(Composite.class, type);
+        assertEquals(Scope.COMPOSITE, type.getScope());
+    }
+
+    public void testSessionScope() throws ProcessingException {
+        ScopeProcessor processor = new ScopeProcessor();
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        processor.visitClass(Session.class, type);
+        assertEquals(Scope.SESSION, type.getScope());
+    }
+
+    public void testConversationalScope() throws ProcessingException {
+        ScopeProcessor processor = new ScopeProcessor();
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        processor.visitClass(Conversation.class, type);
+        assertEquals(Scope.CONVERSATION, type.getScope());
+    }
+
+    public void testRequestScope() throws ProcessingException {
+        ScopeProcessor processor = new ScopeProcessor();
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        processor.visitClass(Request.class, type);
+        assertEquals(Scope.REQUEST, type.getScope());
+    }
+
+    public void testSystemScope() throws ProcessingException {
+        ScopeProcessor processor = new ScopeProcessor();
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        processor.visitClass(System.class, type);
+        assertEquals(Scope.SYSTEM, type.getScope());
+    }
+
+    public void testStatelessScope() throws ProcessingException {
+        ScopeProcessor processor = new ScopeProcessor();
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        processor.visitClass(Stateless.class, type);
+        assertEquals(Scope.STATELESS, type.getScope());
+    }
+
+    public void testNoScope() throws ProcessingException {
+        ScopeProcessor processor = new ScopeProcessor();
+        JavaImplementationDefinition type =
+            new JavaImplementationDefinition();
+        processor.visitClass(None.class, type);
+        assertEquals(Scope.STATELESS, type.getScope());
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        parent = EasyMock.createNiceMock(Component.class);
+    }
+
+    @org.osoa.sca.annotations.Scope("COMPOSITE")
+    private class Composite {
+    }
+
+    @org.osoa.sca.annotations.Scope("SESSION")
+    private class Session {
+    }
+
+    @org.osoa.sca.annotations.Scope("CONVERSATION")
+    private class Conversation {
+    }
+
+    @org.osoa.sca.annotations.Scope("REQUEST")
+    private class Request {
+    }
+
+    @org.osoa.sca.annotations.Scope("SYSTEM")
+    private class System {
+    }
+
+    @org.osoa.sca.annotations.Scope("STATELESS")
+    private class Stateless {
+    }
+
+    private class None {
+    }
+
+}

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

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

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ServiceCallbackTestCase.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/ServiceCallbackTestCase.java?view=auto&rev=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ServiceCallbackTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ServiceCallbackTestCase.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.getService;
+
+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.ProcessingException;
+import org.apache.tuscany.implementation.java.introspect.impl.IllegalCallbackReferenceException;
+import org.apache.tuscany.implementation.java.introspect.impl.ServiceProcessor;
+import org.apache.tuscany.interfacedef.InvalidCallbackException;
+import org.apache.tuscany.interfacedef.java.introspect.DefaultJavaInterfaceIntrospector;
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServiceCallbackTestCase extends TestCase {
+    private ServiceProcessor processor;
+
+    @Override
+    protected void setUp() throws Exception {
+        processor = new ServiceProcessor();
+        processor.setInterfaceVisitorExtensionPoint(new DefaultJavaInterfaceIntrospector());
+    }
+
+    public void testMethodCallbackInterface() throws Exception {
+        JavaImplementationDefinition type = new JavaImplementationDefinition();
+        processor.visitClass(FooImpl.class, type);
+        org.apache.tuscany.assembly.Service service = getService(type, Foo.class.getSimpleName());
+        assertNotNull(service);
+        Method method = FooImpl.class.getMethod("setCallback", FooCallback.class);
+        processor.visitMethod(method, type);
+        assertEquals(method, type.getCallbackMembers().get("callback").getAnchor());
+    }
+
+    public void testFieldCallbackInterface() throws Exception {
+        JavaImplementationDefinition type = new JavaImplementationDefinition();
+        processor.visitClass(FooImpl.class, type);
+        org.apache.tuscany.assembly.Service service = getService(type, Foo.class.getSimpleName());
+        assertNotNull(service);
+        Field field = FooImpl.class.getDeclaredField("callback");
+        processor.visitField(field, type);
+        assertEquals(field, type.getCallbackMembers().get(field.getName()).getAnchor());
+    }
+
+    public void testMethodDoesNotMatchCallback() throws Exception {
+        JavaImplementationDefinition type = new JavaImplementationDefinition();
+        processor.visitClass(BadBarImpl.class, type);
+        Method method = BadBarImpl.class.getMethod("setWrongInterfaceCallback", String.class);
+        try {
+            processor.visitMethod(method, type);
+            fail();
+        } catch (IllegalCallbackReferenceException e) {
+            // expected
+        }
+    }
+
+    public void testNoParamCallback() throws Exception {
+        JavaImplementationDefinition type = new JavaImplementationDefinition();
+        processor.visitClass(BadBarImpl.class, type);
+        Method method = BadBarImpl.class.getMethod("setNoParamCallback");
+        try {
+            processor.visitMethod(method, type);
+            fail();
+        } catch (IllegalCallbackReferenceException e) {
+            // expected
+        }
+    }
+
+    public void testFieldDoesNotMatchCallback() throws Exception {
+        JavaImplementationDefinition type = new JavaImplementationDefinition();
+        processor.visitClass(BadBarImpl.class, type);
+        Field field = BadBarImpl.class.getDeclaredField("wrongInterfaceCallback");
+        try {
+            processor.visitField(field, type);
+            fail();
+        } catch (IllegalCallbackReferenceException e) {
+            // expected
+        }
+    }
+
+    public void testBadCallbackInterfaceAnnotation() throws Exception {
+        JavaImplementationDefinition type = new JavaImplementationDefinition();
+        try {
+            processor.visitClass(BadFooImpl.class, type);
+            fail();
+        } catch (ProcessingException e) {
+            // expected
+            assertTrue(e.getCause() instanceof InvalidCallbackException);
+        }
+    }
+
+    @Callback(FooCallback.class)
+    private interface Foo {
+
+    }
+
+    private interface FooCallback {
+
+    }
+
+    @Service(Foo.class)
+    private static class FooImpl implements Foo {
+
+        @Callback
+        protected FooCallback callback;
+
+        @Callback
+        public void setCallback(FooCallback cb) {
+
+        }
+    }
+
+    private static class BadBarImpl implements Foo {
+        @Callback
+        protected String wrongInterfaceCallback;
+
+        @Callback
+        public void setWrongInterfaceCallback(String cb) {
+
+        }
+
+        @Callback
+        public void setNoParamCallback() {
+
+        }
+
+    }
+
+    @Callback
+    private interface BadFoo {
+
+    }
+
+    @Service(BadFoo.class)
+    private static class BadFooImpl implements BadFoo {
+
+    }
+
+}

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

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

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ServiceProcessorTestCase.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/ServiceProcessorTestCase.java?view=auto&rev=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ServiceProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/introspect/impl/ServiceProcessorTestCase.java Tue Apr 10 19:55:00 2007
@@ -0,0 +1,148 @@
+/*
+ * 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.impl.IllegalServiceDefinitionException;
+import org.apache.tuscany.implementation.java.introspect.impl.InvalidServiceType;
+import org.apache.tuscany.implementation.java.introspect.impl.ServiceProcessor;
+import org.apache.tuscany.interfacedef.java.JavaInterface;
+import org.apache.tuscany.interfacedef.java.introspect.DefaultJavaInterfaceIntrospector;
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Remotable;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServiceProcessorTestCase extends TestCase {
+    private ServiceProcessor processor;
+    private JavaImplementationDefinition type;
+
+    public void testMultipleInterfaces() throws Exception {
+        processor.visitClass(FooMultiple.class, type);
+        assertEquals(2, type.getServices().size());
+        org.apache.tuscany.assembly.Service service = ModelHelper.getService(type, Baz.class.getSimpleName());
+        assertEquals(Baz.class, ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass());
+        assertEquals(Bar.class, ((JavaInterface)service.getInterfaceContract().getCallbackInterface()).getJavaClass());
+        assertNotNull(ModelHelper.getService(type, Bar.class.getSimpleName()));
+    }
+
+    public void testSingleInterfaces() throws Exception {
+        processor.visitClass(FooSingle.class, type);
+        assertEquals(1, type.getServices().size());
+        assertNotNull(ModelHelper.getService(type, Baz.class.getSimpleName()));
+    }
+
+    public void testMultipleNoService() throws Exception {
+        processor.visitClass(FooMultipleNoService.class, type);
+        assertEquals(0, type.getServices().size());
+    }
+
+    /**
+     * Verifies a service with a callback annotation is recognized
+     */
+    public void testMultipleWithCallbackAnnotation() throws Exception {
+        processor.visitClass(FooMultipleWithCalback.class, type);
+        assertEquals(1, type.getServices().size());
+    }
+
+    public void testRemotableNoService() throws Exception {
+        processor.visitClass(FooRemotableNoService.class, type);
+        assertEquals(1, type.getServices().size());
+        org.apache.tuscany.assembly.Service service = ModelHelper.getService(type, BazRemotable.class.getSimpleName());
+        assertEquals(BazRemotable.class, ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass());
+    }
+
+    public void testNonInterface() throws Exception {
+        try {
+            processor.visitClass(BadImpl.class, type);
+            fail();
+        } catch (InvalidServiceType e) {
+            //expected
+        }
+    }
+
+    public void testNoInterfaces() throws Exception {
+        try {
+            processor.visitClass(BadDefinition.class, type);
+            fail();
+        } catch (IllegalServiceDefinitionException e) {
+            //expected
+        }
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        DefaultJavaInterfaceIntrospector introspector = new DefaultJavaInterfaceIntrospector();
+        processor = new ServiceProcessor();
+        processor.setInterfaceVisitorExtensionPoint(introspector);
+        type = new JavaImplementationDefinition();
+    }
+
+    @Callback(Bar.class)
+    private interface Baz {
+    }
+
+    private interface Bar {
+    }
+
+    private interface Bar2 {
+    }
+
+    @Remotable
+    private interface BazRemotable {
+    }
+
+    @Service(interfaces = {Baz.class, Bar.class})
+    private class FooMultiple implements Baz, Bar {
+
+    }
+
+    @Service(Baz.class)
+    private class FooSingle implements Baz, Bar {
+
+    }
+
+    private class FooMultipleNoService implements Bar, Bar2 {
+
+    }
+
+    private class FooMultipleWithCalback implements Baz, Bar {
+
+    }
+
+    private class FooRemotableNoService implements BazRemotable, Bar {
+
+    }
+
+    @Service(FooSingle.class)
+    private class BadImpl extends FooSingle {
+
+    }
+
+
+    @Service()
+    private class BadDefinition extends FooSingle {
+
+    }
+
+}

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

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

Modified: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/xml/ReadTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/xml/ReadTestCase.java?view=diff&rev=527378&r1=527377&r2=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/xml/ReadTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/xml/ReadTestCase.java Tue Apr 10 19:55:00 2007
@@ -28,7 +28,7 @@
 
 import org.apache.tuscany.assembly.Composite;
 import org.apache.tuscany.assembly.util.CompositeUtil;
-import org.apache.tuscany.assembly.xml.impl.CompositeProcessor;
+import org.apache.tuscany.assembly.xml.CompositeProcessor;
 import org.apache.tuscany.services.spi.contribution.ArtifactResolver;
 import org.apache.tuscany.services.spi.contribution.DefaultArtifactResolver;
 import org.apache.tuscany.services.spi.contribution.DefaultStAXArtifactProcessorRegistry;

Modified: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/xml/WriteTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/xml/WriteTestCase.java?view=diff&rev=527378&r1=527377&r2=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/xml/WriteTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/implementation/java/xml/WriteTestCase.java Tue Apr 10 19:55:00 2007
@@ -27,9 +27,9 @@
 import junit.framework.TestCase;
 
 import org.apache.tuscany.assembly.Composite;
-import org.apache.tuscany.assembly.xml.impl.ComponentTypeProcessor;
-import org.apache.tuscany.assembly.xml.impl.CompositeProcessor;
-import org.apache.tuscany.assembly.xml.impl.ConstrainingTypeProcessor;
+import org.apache.tuscany.assembly.xml.ComponentTypeProcessor;
+import org.apache.tuscany.assembly.xml.CompositeProcessor;
+import org.apache.tuscany.assembly.xml.ConstrainingTypeProcessor;
 import org.apache.tuscany.services.spi.contribution.DefaultStAXArtifactProcessorRegistry;
 
 /**

Added: incubator/tuscany/java/sca/modules/interface-java-xml/src/main/java/org/apache/tuscany/interfacedef/java/introspect/DefaultJavaInterfaceIntrospector.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-java-xml/src/main/java/org/apache/tuscany/interfacedef/java/introspect/DefaultJavaInterfaceIntrospector.java?view=auto&rev=527378
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-java-xml/src/main/java/org/apache/tuscany/interfacedef/java/introspect/DefaultJavaInterfaceIntrospector.java (added)
+++ incubator/tuscany/java/sca/modules/interface-java-xml/src/main/java/org/apache/tuscany/interfacedef/java/introspect/DefaultJavaInterfaceIntrospector.java Tue Apr 10 19:55:00 2007
@@ -0,0 +1,144 @@
+/*
+ * 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.interfacedef.java.introspect;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.interfacedef.DataType;
+import org.apache.tuscany.interfacedef.InvalidCallbackException;
+import org.apache.tuscany.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.interfacedef.InvalidOperationException;
+import org.apache.tuscany.interfacedef.Operation;
+import org.apache.tuscany.interfacedef.OverloadedOperationException;
+import org.apache.tuscany.interfacedef.impl.DataTypeImpl;
+import org.apache.tuscany.interfacedef.impl.OperationImpl;
+import org.apache.tuscany.interfacedef.java.JavaFactory;
+import org.apache.tuscany.interfacedef.java.JavaInterface;
+import org.apache.tuscany.interfacedef.java.impl.DefaultJavaFactory;
+import org.osoa.sca.annotations.Conversational;
+import org.osoa.sca.annotations.EndsConversation;
+import org.osoa.sca.annotations.OneWay;
+import org.osoa.sca.annotations.Remotable;
+
+/**
+ * Default implementation of an InterfaceJavaIntrospector.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class DefaultJavaInterfaceIntrospector implements JavaInterfaceIntrospectorExtensionPoint {
+    public static final String IDL_INPUT = "idl:input";
+
+    private static final String UNKNOWN_DATABINDING = null;
+
+    private JavaFactory javaFactory;
+    private List<JavaInterfaceIntrospectorExtension> processors = new ArrayList<JavaInterfaceIntrospectorExtension>();
+
+    public DefaultJavaInterfaceIntrospector() {
+        this.javaFactory = new DefaultJavaFactory();
+    }
+
+    public void addIntrospectorExtension(JavaInterfaceIntrospectorExtension processor) {
+        processors.add(processor);
+    }
+
+    public void removeIntrospectorExtension(JavaInterfaceIntrospectorExtension processor) {
+        processors.remove(processor);
+    }
+
+    public JavaInterface introspect(Class<?> type) throws InvalidInterfaceException {
+        JavaInterface javaInterface = javaFactory.createJavaInterface();
+        javaInterface.setJavaClass(type);
+
+        boolean remotable = type.isAnnotationPresent(Remotable.class);
+        javaInterface.setRemotable(remotable);
+        
+        boolean conversational = type.isAnnotationPresent(Conversational.class);
+        javaInterface.setConversational(conversational);
+        
+        Class<?> callbackClass = null;
+        org.osoa.sca.annotations.Callback callback = type.getAnnotation(org.osoa.sca.annotations.Callback.class);
+        if (callback != null && !Void.class.equals(callback.value())) {
+            callbackClass = callback.value();
+        } else if (callback != null && Void.class.equals(callback.value())) {
+            throw new InvalidCallbackException("No callback interface specified on annotation");
+        }
+        javaInterface.setCallbackClass(callbackClass);
+        
+        javaInterface.getOperations().addAll(getOperations(type, remotable, conversational).values());
+
+        for (JavaInterfaceIntrospectorExtension processor : processors) {
+            processor.visitInterface(type);
+        }
+        return javaInterface;
+    }
+
+    private <T> Map<String, Operation> getOperations(Class<T> type, boolean remotable, boolean conversational)
+        throws InvalidInterfaceException {
+        Method[] methods = type.getMethods();
+        Map<String, Operation> operations = new HashMap<String, Operation>(methods.length);
+        for (Method method : methods) {
+            String name = method.getName();
+            if (remotable && operations.containsKey(name)) {
+                throw new OverloadedOperationException(method);
+            }
+
+            Class returnType = method.getReturnType();
+            Class[] paramTypes = method.getParameterTypes();
+            Class[] faultTypes = method.getExceptionTypes();
+            boolean nonBlocking = method.isAnnotationPresent(OneWay.class);
+            Operation.ConversationSequence conversationSequence = Operation.ConversationSequence.NO_CONVERSATION;
+            if (method.isAnnotationPresent(EndsConversation.class)) {
+                if (!conversational) {
+                    throw new InvalidOperationException(
+                                                        "Method is marked as end conversation but contract is not conversational",
+                                                        method);
+                }
+                conversationSequence = Operation.ConversationSequence.CONVERSATION_END;
+            } else if (conversational) {
+                conversationSequence = Operation.ConversationSequence.CONVERSATION_CONTINUE;
+            }
+
+            DataType<Class> returnDataType = new DataTypeImpl<Class>(UNKNOWN_DATABINDING, returnType, returnType);
+            List<DataType> paramDataTypes = new ArrayList<DataType>(paramTypes.length);
+            for (Class paramType : paramTypes) {
+                paramDataTypes.add(new DataTypeImpl<Class>(UNKNOWN_DATABINDING, paramType, paramType));
+            }
+            List<DataType> faultDataTypes = new ArrayList<DataType>(faultTypes.length);
+            for (Class faultType : faultTypes) {
+                faultDataTypes.add(new DataTypeImpl<Class>(UNKNOWN_DATABINDING, faultType, faultType));
+            }
+
+            DataType<List<DataType>> inputType = new DataTypeImpl<List<DataType>>(IDL_INPUT, Object[].class,
+                                                                                  paramDataTypes);
+            Operation operation = new OperationImpl(name);
+            operation.setInputType(inputType);
+            operation.setOutputType(returnDataType);
+            operation.setFaultTypes(faultDataTypes);
+            operation.setConversationSequence(conversationSequence);
+            operation.setNonBlocking(nonBlocking);
+            operations.put(name, operation);
+        }
+        return operations;
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/interface-java-xml/src/main/java/org/apache/tuscany/interfacedef/java/introspect/DefaultJavaInterfaceIntrospector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/interface-java-xml/src/main/java/org/apache/tuscany/interfacedef/java/introspect/DefaultJavaInterfaceIntrospector.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