You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jm...@apache.org on 2006/07/15 00:30:45 UTC

svn commit: r422079 - in /incubator/tuscany/sandbox/chianti/sca/core/src: main/java/org/apache/tuscany/core/implementation/processor/ test/java/org/apache/tuscany/core/implementation/processor/

Author: jmarino
Date: Fri Jul 14 15:30:44 2006
New Revision: 422079

URL: http://svn.apache.org/viewvc?rev=422079&view=rev
Log:
additional cdi testcases; add support to check @Constructor param validity

Added:
    incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidConstructorException.java   (with props)
Modified:
    incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessor.java
    incubator/tuscany/sandbox/chianti/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java
    incubator/tuscany/sandbox/chianti/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java

Modified: incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessor.java?rev=422079&r1=422078&r2=422079&view=diff
==============================================================================
--- incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessor.java (original)
+++ incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessor.java Fri Jul 14 15:30:44 2006
@@ -18,15 +18,17 @@
 import org.apache.tuscany.spi.component.CompositeComponent;
 import org.apache.tuscany.spi.deployer.DeploymentContext;
 
+import org.apache.tuscany.core.implementation.ConstructorDefinition;
 import org.apache.tuscany.core.implementation.ImplementationProcessorSupport;
 import org.apache.tuscany.core.implementation.JavaMappedProperty;
 import org.apache.tuscany.core.implementation.JavaMappedReference;
 import org.apache.tuscany.core.implementation.JavaMappedService;
 import org.apache.tuscany.core.implementation.PojoComponentType;
 import org.apache.tuscany.core.implementation.ProcessingException;
-import org.apache.tuscany.core.implementation.ConstructorDefinition;
 
 /**
+ * Handles processing of a constructor decorated with {@link org.osoa.sca.annotations.Constructor}
+ *
  * @version $Rev$ $Date$
  */
 public class ConstructorProcessor extends ImplementationProcessorSupport {
@@ -48,6 +50,10 @@
         }
         definition = new ConstructorDefinition(constructor);
         String[] names = annotation.value();
+        if (names.length != constructor.getParameterTypes().length) {
+            throw new InvalidConstructorException(
+                "Number of parameters does not match values specified in @Cosntructor");
+        }
         for (String name : names) {
             definition.getInjectionNames().add(name);
         }

Added: incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidConstructorException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidConstructorException.java?rev=422079&view=auto
==============================================================================
--- incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidConstructorException.java (added)
+++ incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidConstructorException.java Fri Jul 14 15:30:44 2006
@@ -0,0 +1,39 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import org.apache.tuscany.core.implementation.ProcessingException;
+
+/**
+ * Denotes an invalid constructor definition, e.g. when the number of injection names specified in {@link
+ * org.osoa.sca.annotations.Constructor} do not match the number of actual constructor parameters
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidConstructorException extends ProcessingException {
+    public InvalidConstructorException() {
+    }
+
+    public InvalidConstructorException(String message) {
+        super(message);
+    }
+
+    public InvalidConstructorException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public InvalidConstructorException(Throwable cause) {
+        super(cause);
+    }
+}

Propchange: incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidConstructorException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidConstructorException.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Modified: incubator/tuscany/sandbox/chianti/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/chianti/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java?rev=422079&r1=422078&r2=422079&view=diff
==============================================================================
--- incubator/tuscany/sandbox/chianti/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java (original)
+++ incubator/tuscany/sandbox/chianti/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java Fri Jul 14 15:30:44 2006
@@ -12,9 +12,9 @@
  * @version $Rev$ $Date$
  */
 public class ConstructorProcessorTestCase extends TestCase {
+    private ConstructorProcessor processor = new ConstructorProcessor();
 
     public void testDuplicateConstructor() throws Exception {
-        ConstructorProcessor processor = new ConstructorProcessor();
         PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
             new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
         Constructor ctor1 = BadFoo.class.getConstructor(String.class);
@@ -28,6 +28,34 @@
         }
     }
 
+    public void testConstructorAnnotation() throws Exception {
+        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+            new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+        Constructor ctor1 = Foo.class.getConstructor(String.class);
+        processor.visitConstructor(null, ctor1, type, null);
+        assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(0));
+    }
+
+    public void testNoAnnotation() throws Exception {
+        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+            new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+        Constructor ctor1 = NoAnnotation.class.getConstructor();
+        processor.visitConstructor(null, ctor1, type, null);
+        assertNull(type.getConstructorDefinition());
+    }
+
+    public void testBadAnnotation() throws Exception {
+        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+            new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+        Constructor ctor1 = BadAnnotation.class.getConstructor(String.class, Foo.class);
+        try {
+            processor.visitConstructor(null, ctor1, type, null);
+            fail();
+        } catch (InvalidConstructorException e) {
+            // expected
+        }
+
+    }
 
     private static class BadFoo {
 
@@ -43,5 +71,22 @@
 
     }
 
+    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) {
+        }
+    }
 
 }

Modified: incubator/tuscany/sandbox/chianti/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/chianti/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java?rev=422079&r1=422078&r2=422079&view=diff
==============================================================================
--- incubator/tuscany/sandbox/chianti/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java (original)
+++ incubator/tuscany/sandbox/chianti/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java Fri Jul 14 15:30:44 2006
@@ -1,3 +1,16 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
 package org.apache.tuscany.core.implementation.processor;
 
 import org.osoa.sca.annotations.Remotable;



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org