summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java')
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/AddService.java25
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/AddServiceImpl.java35
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/CalculatorService.java34
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/CalculatorServiceImpl.java71
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/DivideService.java25
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/DivideServiceImpl.java33
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/MultiplyService.java25
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/MultiplyServiceImpl.java33
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/SubtractService.java25
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/SubtractServiceImpl.java33
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/DefaultJavaClassIntrospectorTestCase.java95
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractProcessorTest.java80
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessorTestCase.java168
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessorTestCase.java70
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessorTestCase.java197
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorPropertyTestCase.java158
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorReferenceTestCase.java166
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorResourceTestCase.java153
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessorTestCase.java188
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessorTestCase.java144
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java116
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessorTestCase.java99
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessorTestCase.java59
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java75
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicConstructorTestCase.java315
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessorTestCase.java411
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeutisticExtensibleConstructorTestCase.java153
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessorTestCase.java99
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ModelHelper.java99
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java406
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessorTestCase.java213
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessorTestCase.java224
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessorTestCase.java118
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessorTestCase.java116
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceCallbackTestCase.java169
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessorTestCase.java152
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java120
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/TestModelResolver.java88
-rw-r--r--sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java97
39 files changed, 4887 insertions, 0 deletions
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/AddService.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/AddService.java
new file mode 100644
index 0000000000..4eeb30a9c2
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/AddService.java
@@ -0,0 +1,25 @@
+/*
+ * 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 calculator;
+
+public interface AddService {
+
+ double add(double n1, double n2);
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/AddServiceImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/AddServiceImpl.java
new file mode 100644
index 0000000000..ea3e5341d5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/AddServiceImpl.java
@@ -0,0 +1,35 @@
+/*
+ * 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 calculator;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * An implementation of the Add service
+ */
+@Scope("COMPOSITE")
+@EagerInit
+public class AddServiceImpl implements AddService {
+
+ public double add(double n1, double n2) {
+ return n1 + n2;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/CalculatorService.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/CalculatorService.java
new file mode 100644
index 0000000000..c89043276e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/CalculatorService.java
@@ -0,0 +1,34 @@
+/*
+ * 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 calculator;
+
+/**
+ * The Calculator service interface.
+ */
+public interface CalculatorService {
+
+ double add(double n1, double n2);
+
+ double subtract(double n1, double n2);
+
+ double multiply(double n1, double n2);
+
+ double divide(double n1, double n2);
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/CalculatorServiceImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/CalculatorServiceImpl.java
new file mode 100644
index 0000000000..11e8974657
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/CalculatorServiceImpl.java
@@ -0,0 +1,71 @@
+/*
+ * 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 calculator;
+
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * An implementation of the Calculator service.
+ */
+@Scope("COMPOSITE")
+public class CalculatorServiceImpl implements CalculatorService {
+
+ private AddService addService;
+ private SubtractService subtractService;
+ private MultiplyService multiplyService;
+ private DivideService divideService;
+
+ @Reference
+ public void setAddService(AddService addService) {
+ this.addService = addService;
+ }
+
+ @Reference
+ public void setSubtractService(SubtractService subtractService) {
+ this.subtractService = subtractService;
+ }
+
+ @Reference
+ public void setDivideService(DivideService divideService) {
+ this.divideService = divideService;
+ }
+
+ @Reference
+ public void setMultiplyService(MultiplyService multiplyService) {
+ this.multiplyService = multiplyService;
+ }
+
+ public double add(double n1, double n2) {
+ return addService.add(n1, n2);
+ }
+
+ public double subtract(double n1, double n2) {
+ return subtractService.subtract(n1, n2);
+ }
+
+ public double multiply(double n1, double n2) {
+ return multiplyService.multiply(n1, n2);
+ }
+
+ public double divide(double n1, double n2) {
+ return divideService.divide(n1, n2);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/DivideService.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/DivideService.java
new file mode 100644
index 0000000000..131c5a8014
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/DivideService.java
@@ -0,0 +1,25 @@
+/*
+ * 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 calculator;
+
+public interface DivideService {
+
+ double divide(double n1, double n2);
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/DivideServiceImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/DivideServiceImpl.java
new file mode 100644
index 0000000000..9c7e96a668
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/DivideServiceImpl.java
@@ -0,0 +1,33 @@
+/*
+ * 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 calculator;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * An implementation of the Divide service.
+ */
+@Scope("COMPOSITE")
+public class DivideServiceImpl implements DivideService {
+
+ public double divide(double n1, double n2) {
+ return n1 / n2;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/MultiplyService.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/MultiplyService.java
new file mode 100644
index 0000000000..a917896aeb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/MultiplyService.java
@@ -0,0 +1,25 @@
+/*
+ * 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 calculator;
+
+public interface MultiplyService {
+
+ double multiply(double n1, double n2);
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/MultiplyServiceImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/MultiplyServiceImpl.java
new file mode 100644
index 0000000000..4892481203
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/MultiplyServiceImpl.java
@@ -0,0 +1,33 @@
+/*
+ * 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 calculator;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * An implementation of the Multiply service.
+ */
+@Scope("COMPOSITE")
+public class MultiplyServiceImpl implements MultiplyService {
+
+ public double multiply(double n1, double n2) {
+ return n1 * n2;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/SubtractService.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/SubtractService.java
new file mode 100644
index 0000000000..e328f024ea
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/SubtractService.java
@@ -0,0 +1,25 @@
+/*
+ * 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 calculator;
+
+public interface SubtractService {
+
+ double subtract(double n1, double n2);
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/SubtractServiceImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/SubtractServiceImpl.java
new file mode 100644
index 0000000000..ee1d7c3457
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/calculator/SubtractServiceImpl.java
@@ -0,0 +1,33 @@
+/*
+ * 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 calculator;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * An implementation of the subtract service.
+ */
+@Scope("COMPOSITE")
+public class SubtractServiceImpl implements SubtractService {
+
+ public double subtract(double n1, double n2) {
+ return n1 - n2;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/DefaultJavaClassIntrospectorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/DefaultJavaClassIntrospectorTestCase.java
new file mode 100644
index 0000000000..9ecd439611
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/DefaultJavaClassIntrospectorTestCase.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DefaultJavaClassIntrospectorTestCase extends TestCase {
+
+ public void testRegister() throws Exception {
+ DefaultJavaClassIntrospectorExtensionPoint visitors = new DefaultJavaClassIntrospectorExtensionPoint();
+ JavaClassVisitor extension = EasyMock.createNiceMock(JavaClassVisitor.class);
+ visitors.addClassVisitor(extension);
+ }
+
+ public void testUnegister() throws Exception {
+ DefaultJavaClassIntrospectorExtensionPoint visitors = new DefaultJavaClassIntrospectorExtensionPoint();
+ JavaClassVisitor extension = EasyMock.createNiceMock(JavaClassVisitor.class);
+ visitors.addClassVisitor(extension);
+ visitors.removeClassVisitor(extension);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testWalk() throws Exception {
+ DefaultJavaClassIntrospectorExtensionPoint visitors = new DefaultJavaClassIntrospectorExtensionPoint();
+ JavaClassVisitor extension = EasyMock.createMock(JavaClassVisitor.class);
+ extension.visitClass(EasyMock.eq(Bar.class), EasyMock.isA(JavaImplementation.class));
+ extension.visitConstructor(EasyMock.isA(Constructor.class), EasyMock.isA(JavaImplementation.class));
+ extension.visitMethod(EasyMock.isA(Method.class), EasyMock.isA(JavaImplementation.class));
+ extension.visitField(EasyMock.isA(Field.class), EasyMock.isA(JavaImplementation.class));
+ extension.visitSuperClass(EasyMock.isA(Class.class), EasyMock.isA(JavaImplementation.class));
+ extension.visitEnd(EasyMock.isA(Class.class), EasyMock.isA(JavaImplementation.class));
+
+ // mock.expects(once()).method("visitClass");
+ // mock.expects(once()).method("visitMethod");
+ // mock.expects(once()).method("visitField");
+ // mock.expects(once()).method("visitConstructor");
+ // mock.expects(once()).method("visitSuperClass");
+ // mock.expects(once()).method("visitEnd");
+ EasyMock.replay(extension);
+ visitors.addClassVisitor(extension);
+ JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+ ExtensibleJavaClassIntrospector introspector = new ExtensibleJavaClassIntrospector(visitors);
+ introspector.introspect(Bar.class, javaImplementationFactory.createJavaImplementation());
+ EasyMock.verify(extension);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ private class Baz {
+
+ }
+
+ private class Bar extends Baz {
+
+ protected String bar;
+
+ public Bar() {
+ }
+
+ public void bar() {
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractProcessorTest.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractProcessorTest.java
new file mode 100644
index 0000000000..adefc4f7fc
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractProcessorTest.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Constructor;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.impl.JavaConstructorImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaParameterImpl;
+import org.apache.tuscany.sca.implementation.java.introspect.IntrospectionException;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.introspect.DefaultJavaInterfaceIntrospectorExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.java.introspect.ExtensibleJavaInterfaceIntrospector;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospectorExtensionPoint;
+
+
+/**
+ * Base class to simulate the processor sequences
+ *
+ * @version $Rev$ $Date$
+ */
+public class AbstractProcessorTest extends TestCase {
+ protected AssemblyFactory factory;
+ protected JavaInterfaceFactory javaFactory;
+ protected ConstructorProcessor constructorProcessor;
+ private ReferenceProcessor referenceProcessor;
+ private PropertyProcessor propertyProcessor;
+ private ResourceProcessor resourceProcessor;
+
+
+ protected AbstractProcessorTest() {
+ factory = new DefaultAssemblyFactory();
+ javaFactory = new DefaultJavaInterfaceFactory();
+ JavaInterfaceIntrospectorExtensionPoint visitors = new DefaultJavaInterfaceIntrospectorExtensionPoint();
+ referenceProcessor = new ReferenceProcessor(factory, javaFactory, new ExtensibleJavaInterfaceIntrospector(javaFactory, visitors));
+ propertyProcessor = new PropertyProcessor(factory);
+ resourceProcessor = new ResourceProcessor(factory);
+ constructorProcessor = new ConstructorProcessor(factory);
+ referenceProcessor = new ReferenceProcessor(factory, javaFactory, new ExtensibleJavaInterfaceIntrospector(javaFactory, visitors));
+ propertyProcessor = new PropertyProcessor(factory);
+ }
+
+ protected <T> void visitConstructor(Constructor<T> constructor,
+ JavaImplementation type) throws IntrospectionException {
+ constructorProcessor.visitConstructor(constructor, type);
+ JavaConstructorImpl<?> definition = type.getConstructor();
+ if (definition == null) {
+ definition = new JavaConstructorImpl<T>(constructor);
+ type.getConstructors().put(constructor, definition);
+ }
+ JavaParameterImpl[] parameters = definition.getParameters();
+ for (int i = 0; i < parameters.length; i++) {
+ referenceProcessor.visitConstructorParameter(parameters[i], type);
+ propertyProcessor.visitConstructorParameter(parameters[i], type);
+ resourceProcessor.visitConstructorParameter(parameters[i], type);
+ // monitorProcessor.visitConstructorParameter(parameters[i], type);
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessorTestCase.java
new file mode 100644
index 0000000000..df316b3623
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessorTestCase.java
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.ModelHelper.getProperty;
+
+import java.lang.annotation.Retention;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaConstructorImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaParameterImpl;
+import org.apache.tuscany.sca.implementation.java.introspect.DuplicatePropertyException;
+import org.apache.tuscany.sca.implementation.java.introspect.IllegalPropertyException;
+import org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor;
+
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AbstractPropertyProcessorTestCase extends TestCase {
+
+ private JavaClassVisitor extension;
+ private JavaImplementationFactory javaImplementationFactory;
+
+ public void testVisitMethod() throws Exception {
+ Method method = Foo.class.getMethod("setBar", String.class);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ extension.visitMethod(method, type);
+ Property prop = getProperty(type, "test");
+ assertNotNull(prop);
+ }
+
+ public void testVisitNoParamsMethod() throws Exception {
+ Method method = Foo.class.getMethod("setNoParamsBar");
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ extension.visitMethod(method, type);
+ fail();
+ } catch (IllegalPropertyException e) {
+ // expected
+ }
+ }
+
+ public void testVisitNonVoidMethod() throws Exception {
+ Method method = Foo.class.getMethod("setBadBar", String.class);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ extension.visitMethod(method, type);
+ fail();
+ } catch (IllegalPropertyException e) {
+ // expected
+ }
+ }
+
+ public void testDuplicateMethod() throws Exception {
+ Method method = Foo.class.getMethod("setBar", String.class);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ extension.visitMethod(method, type);
+ try {
+ extension.visitMethod(method, type);
+ fail();
+ } catch (DuplicatePropertyException e) {
+ // expected
+ }
+ }
+
+ public void testVisitField() throws Exception {
+ Field field = Foo.class.getDeclaredField("d");
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ extension.visitField(field, type);
+ Property prop = getProperty(type, "test");
+ assertNotNull(prop);
+ }
+
+ public void testVisitConstructor() throws Exception {
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ JavaConstructorImpl<Foo> def = new JavaConstructorImpl<Foo>(ctor);
+ JavaParameterImpl parameter = def.getParameters()[0];
+ extension.visitConstructorParameter(parameter, type);
+ assertEquals("test", def.getParameters()[0].getName());
+ assertNotNull(getProperty(type, "test"));
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ extension = new TestProcessor();
+ javaImplementationFactory = new DefaultJavaImplementationFactory();
+ }
+
+ @Retention(RUNTIME)
+ private @interface Bar {
+
+ }
+
+ private class TestProcessor extends AbstractPropertyProcessor<Bar> {
+
+ public TestProcessor() {
+ super(new DefaultAssemblyFactory(), Bar.class);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void initProperty(Property property, Bar annotation) {
+ // property.setDefaultValueFactory(EasyMock.createMock(ObjectFactory.class));
+ property.setName("test");
+ }
+
+ protected String getName(Bar annotation) {
+ return "test";
+ }
+ }
+
+ private static class Foo {
+
+ @Bar
+ protected String d;
+
+ public Foo(String a, @Bar
+ String b) {
+ }
+
+ public Foo(@Bar
+ String d) {
+ this.d = d;
+ }
+
+ @Bar
+ public void setBar(String d) {
+ this.d = d;
+ }
+
+ @Bar
+ public void setNoParamsBar() {
+ }
+
+ @Bar
+ public String setBadBar(String d) {
+ return null;
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessorTestCase.java
new file mode 100644
index 0000000000..9b3437b07a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessorTestCase.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.osoa.sca.annotations.AllowsPassByReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AllowsPassByReferenceProcessorTestCase extends TestCase {
+
+ JavaImplementation type;
+ AllowsPassByReferenceProcessor processor;
+ private JavaImplementationFactory javaImplementationFactory;
+
+ public void testClassAnnotation() throws Exception {
+ processor.visitClass(Foo.class, type);
+ assertEquals(true, type.isAllowsPassByReference());
+
+ processor.visitClass(Bar.class, type);
+ assertEquals(false, type.isAllowsPassByReference());
+
+ Method m1 = Bar.class.getMethod("m1", new Class[] {});
+ processor.visitMethod(m1, type);
+ assertTrue(type.isAllowsPassByReference(m1));
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ javaImplementationFactory = new DefaultJavaImplementationFactory();
+ type = javaImplementationFactory.createJavaImplementation();
+ processor = new AllowsPassByReferenceProcessor(new DefaultAssemblyFactory());
+ }
+
+ @AllowsPassByReference
+ private class Foo {
+ }
+
+ // no annotation
+ private class Bar {
+ @AllowsPassByReference
+ public void m1() {
+
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessorTestCase.java
new file mode 100644
index 0000000000..ce236c1d10
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessorTestCase.java
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.ModelHelper.getProperty;
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.ModelHelper.getReference;
+
+import java.lang.reflect.Constructor;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.assembly.Multiplicity;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaParameterImpl;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.introspect.DefaultJavaInterfaceIntrospectorExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.java.introspect.ExtensibleJavaInterfaceIntrospector;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospectorExtensionPoint;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorProcessorTestCase extends TestCase {
+ private ConstructorProcessor processor = new ConstructorProcessor(new DefaultAssemblyFactory());
+
+ private JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+
+ public void testDuplicateConstructor() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ processor.visitClass(BadFoo.class, type);
+ fail();
+ } catch (DuplicateConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testConstructorAnnotation() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor1 = Foo.class.getConstructor(String.class);
+ processor.visitConstructor(ctor1, type);
+ assertEquals("foo", type.getConstructor().getParameters()[0].getName());
+ }
+
+ public void testNoAnnotation() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<NoAnnotation> ctor1 = NoAnnotation.class.getConstructor();
+ processor.visitConstructor(ctor1, type);
+ assertNull(type.getConstructor());
+ }
+
+ public void testBadAnnotation() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<BadAnnotation> ctor1 = BadAnnotation.class.getConstructor(String.class, Foo.class);
+ try {
+ processor.visitConstructor(ctor1, type);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testMixedParameters() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Mixed> ctor1 = Mixed.class.getConstructor(String.class, String.class, String.class);
+ processor.visitConstructor(ctor1, type);
+
+ AssemblyFactory assemblyFactory = new DefaultAssemblyFactory();
+ JavaInterfaceFactory javaFactory = new DefaultJavaInterfaceFactory();
+ JavaInterfaceIntrospectorExtensionPoint visitors = new DefaultJavaInterfaceIntrospectorExtensionPoint();
+ ReferenceProcessor referenceProcessor = new ReferenceProcessor(assemblyFactory, javaFactory, new ExtensibleJavaInterfaceIntrospector(javaFactory, visitors));
+ PropertyProcessor propertyProcessor = new PropertyProcessor(assemblyFactory);
+ JavaParameterImpl[] parameters = type.getConstructor().getParameters();
+ for (int i = 0; i < parameters.length; i++) {
+ referenceProcessor.visitConstructorParameter(parameters[i], type);
+ propertyProcessor.visitConstructorParameter(parameters[i], type);
+ }
+
+ assertEquals("_ref0", parameters[0].getName());
+ assertEquals("foo", parameters[1].getName());
+ assertEquals("bar", parameters[2].getName());
+ }
+
+ private static class BadFoo {
+
+ @org.osoa.sca.annotations.Constructor("foo")
+ public BadFoo(String foo) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor( {"foo", "bar"})
+ public BadFoo(String foo, String bar) {
+
+ }
+ }
+
+ private static class Foo {
+ @org.osoa.sca.annotations.Constructor("foo")
+ public Foo(String foo) {
+
+ }
+ }
+
+ private static class NoAnnotation {
+ public NoAnnotation() {
+ }
+ }
+
+ private static class BadAnnotation {
+ @org.osoa.sca.annotations.Constructor("foo")
+ public BadAnnotation(String foo, Foo ref) {
+ }
+ }
+
+ public static final class Mixed {
+ @org.osoa.sca.annotations.Constructor
+ public Mixed(@Reference
+ String param1, @Property(name = "foo")
+ String param2, @Reference(name = "bar")
+ String param3) {
+ }
+ }
+
+ public static final class Multiple {
+ @org.osoa.sca.annotations.Constructor
+ public Multiple(@Reference
+ Collection<String> param1, @Property(name = "foo")
+ String[] param2, @Reference(name = "bar", required = true)
+ List<String> param3, @Property(name = "abc")
+ Set<String> param4, @Reference(name = "xyz")
+ String[] param5) {
+ }
+ }
+
+ public void testMultiplicity() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Multiple> ctor1 = Multiple.class.getConstructor(Collection.class,
+ String[].class,
+ List.class,
+ Set.class,
+ String[].class);
+ processor.visitConstructor(ctor1, type);
+ AssemblyFactory assemblyFactory = new DefaultAssemblyFactory();
+ JavaInterfaceFactory javaFactory = new DefaultJavaInterfaceFactory();
+ JavaInterfaceIntrospectorExtensionPoint visitors = new DefaultJavaInterfaceIntrospectorExtensionPoint();
+ ReferenceProcessor referenceProcessor = new ReferenceProcessor(assemblyFactory, javaFactory, new ExtensibleJavaInterfaceIntrospector(javaFactory, visitors));
+ PropertyProcessor propertyProcessor = new PropertyProcessor(assemblyFactory);
+ JavaParameterImpl[] parameters = type.getConstructor().getParameters();
+ for (int i = 0; i < parameters.length; i++) {
+ referenceProcessor.visitConstructorParameter(parameters[i], type);
+ propertyProcessor.visitConstructorParameter(parameters[i], type);
+ }
+
+ org.apache.tuscany.sca.assembly.Reference ref0 = getReference(type, "_ref0");
+ assertNotNull(ref0);
+ assertEquals(Multiplicity.ONE_N, ref0.getMultiplicity());
+ org.apache.tuscany.sca.assembly.Reference ref1 = getReference(type, "bar");
+ assertNotNull(ref1);
+ assertEquals(Multiplicity.ONE_N, ref1.getMultiplicity());
+ org.apache.tuscany.sca.assembly.Reference ref2 = getReference(type, "xyz");
+ assertNotNull(ref2);
+ assertEquals(Multiplicity.ONE_N, ref2.getMultiplicity());
+ org.apache.tuscany.sca.assembly.Property prop1 = getProperty(type, "foo");
+ assertNotNull(prop1);
+ assertTrue(prop1.isMany());
+ org.apache.tuscany.sca.assembly.Property prop2 = getProperty(type, "abc");
+ assertNotNull(prop2);
+ assertTrue(prop2.isMany());
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorPropertyTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorPropertyTestCase.java
new file mode 100644
index 0000000000..aef565b3e4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorPropertyTestCase.java
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.ModelHelper.getProperty;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.introspect.DuplicatePropertyException;
+import org.osoa.sca.annotations.Property;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorPropertyTestCase extends AbstractProcessorTest {
+
+ private JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+
+ public void testProperty() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+ visitConstructor(ctor, type);
+ org.apache.tuscany.sca.assembly.Property property = getProperty(type, "myProp");
+ assertTrue(property.isMustSupply());
+ assertEquals("myProp", property.getName());
+ }
+
+ public void testTwoPropertiesSameType() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+ visitConstructor(ctor, type);
+ assertNotNull(getProperty(type, "myProp1"));
+ assertNotNull(getProperty(type, "myProp2"));
+ }
+
+ public void testDuplicateProperty() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (DuplicatePropertyException e) {
+ // expected
+ }
+ }
+
+ public void testNoName() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidPropertyException e) {
+ // expected
+ }
+ }
+
+ public void testNamesOnConstructor() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class);
+ visitConstructor(ctor, type);
+ assertNotNull(getProperty(type, "myProp"));
+ }
+
+ public void testInvalidNumberOfNames() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(Integer.class, Integer.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testNoMatchingNames() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(List.class, List.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+// public void testMultiplicityRequired() throws Exception {
+ // TODO multiplicity
+// }
+
+ private static class Foo {
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Property(name = "myProp", required = true)String prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myProp")
+ public Foo(@Property Integer prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Property(name = "myProp1")String prop1, @Property(name = "myProp2")String prop2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Property List prop) {
+
+ }
+ }
+
+ private static class BadFoo {
+
+ @org.osoa.sca.annotations.Constructor()
+ public BadFoo(@Property(name = "myProp")String prop1, @Property(name = "myProp")String prop2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor()
+ public BadFoo(@Property String prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myProp")
+ public BadFoo(@Property Integer prop, @Property Integer prop2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor({"myRef", "myRef2"})
+ public BadFoo(@Property List ref, @Property(name = "myOtherRef")List ref2) {
+
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorReferenceTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorReferenceTestCase.java
new file mode 100644
index 0000000000..9d4204d114
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorReferenceTestCase.java
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.ModelHelper.getReference;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Multiplicity;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorReferenceTestCase extends AbstractProcessorTest {
+
+ private JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+
+ public void testReference() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+ visitConstructor(ctor, type);
+ org.apache.tuscany.sca.assembly.Reference reference = getReference(type, "myRef");
+ assertEquals(Multiplicity.ONE_ONE, reference.getMultiplicity());
+ assertEquals("myRef", reference.getName());
+ }
+
+ public void testTwoReferencesSameType() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+ visitConstructor(ctor, type);
+ assertNotNull(getReference(type, "myRef1"));
+ assertNotNull(getReference(type, "myRef2"));
+ }
+
+ public void testDuplicateProperty() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (DuplicateReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testNoName() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<NoNameFoo> ctor = NoNameFoo.class.getConstructor(String.class);
+ visitConstructor(ctor, type);
+ assertNotNull(getReference(type, "_ref0"));
+ }
+
+ public void testNamesOnConstructor() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class);
+ visitConstructor(ctor, type);
+ assertNotNull(getReference(type, "myRef"));
+ }
+
+ public void testInvalidNumberOfNames() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(Integer.class, Integer.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testNoMatchingNames() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(List.class, List.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+// public void testMultiplicityRequired() throws Exception {
+ // TODO multiplicity
+// }
+
+ private static class Foo {
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Reference(name = "myRef", required = true)String prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Reference(name = "myRef1")String prop1, @Reference(name = "myRef2")String prop2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myRef")
+ public Foo(@Reference Integer prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Reference List prop) {
+
+ }
+ }
+
+ private static class NoNameFoo {
+
+ @org.osoa.sca.annotations.Constructor
+ public NoNameFoo(@Reference String prop) {
+
+ }
+ }
+
+ private static class BadFoo {
+
+ @org.osoa.sca.annotations.Constructor
+ public BadFoo(@Reference(name = "myRef")String prop1, @Reference(name = "myRef")String prop2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor
+ public BadFoo(@Reference String prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myRef")
+ public BadFoo(@Reference Integer ref, @Reference Integer ref2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor({"myRef", "myRef2"})
+ public BadFoo(@Reference List ref, @Reference(name = "myOtherRef")List ref2) {
+
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorResourceTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorResourceTestCase.java
new file mode 100644
index 0000000000..2e56a2a812
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorResourceTestCase.java
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.apache.tuscany.api.annotation.Resource;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorResourceTestCase extends AbstractProcessorTest {
+
+ private JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+
+ public void testResource() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+ visitConstructor(ctor, type);
+ org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl resource = type.getResources().get("myResource");
+ assertFalse(resource.isOptional());
+ }
+
+ public void testTwoResourcesSameType() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+ visitConstructor(ctor, type);
+ assertNotNull(type.getResources().get("myResource1"));
+ assertNotNull(type.getResources().get("myResource2"));
+ }
+
+ public void testDuplicateResource() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (DuplicateResourceException e) {
+ // expected
+ }
+ }
+
+ public void testNoName() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+ ConstructorResourceTestCase.BadFoo.class.getConstructor(String.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidResourceException e) {
+ // expected
+ }
+ }
+
+ public void testNamesOnConstructor() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class);
+ visitConstructor(ctor, type);
+ assertNotNull(type.getResources().get("myResource"));
+ }
+
+ public void testInvalidNumberOfNames() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+ ConstructorResourceTestCase.BadFoo.class.getConstructor(Integer.class, Integer.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testNoMatchingNames() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+ ConstructorResourceTestCase.BadFoo.class.getConstructor(List.class, List.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ private static class Foo {
+
+ @org.osoa.sca.annotations.Constructor
+ public Foo(@Resource(name = "myResource") String resource) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myResource")
+ public Foo(@Resource Integer resource) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor
+ public Foo(@Resource(name = "myResource1") String res1, @Resource(name = "myResource2") String res2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor
+ public Foo(@Resource List res) {
+
+ }
+ }
+
+ private static class BadFoo {
+
+ @org.osoa.sca.annotations.Constructor
+ public BadFoo(@Resource(name = "myResource") String res1, @Resource(name = "myResource") String res2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor
+ public BadFoo(@Resource String res) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myProp")
+ public BadFoo(@Resource Integer res, @Resource Integer res2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor({"myRes", "myRes2"})
+ public BadFoo(@Resource List res, @Resource(name = "myOtherRes") List res2) {
+
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessorTestCase.java
new file mode 100644
index 0000000000..5f0e189f69
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessorTestCase.java
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.easymock.EasyMock;
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.RequestContext;
+import org.osoa.sca.annotations.Context;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ContextProcessorTestCase extends TestCase {
+ private ContextProcessor processor;
+ private Component composite;
+ private JavaImplementationFactory javaImplementationFactory;
+
+ // FIXME: resurrect to test ComponentContext injection
+/*
+ public void testCompositeContextMethod() throws Exception {
+ Method method = Foo.class.getMethod("setContext", ComponentContext.class);
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ processor.visitMethod(composite, method, type);
+ assertNotNull(type.getResources().get("context"));
+ }
+*/
+
+ // FIXME: resurrect to test ComponentContext injection
+/*
+ public void testCompositeContextField() throws Exception {
+ Field field = Foo.class.getDeclaredField("context");
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ processor.visitField(composite, field, type);
+ assertNotNull(type.getResources().get("context"));
+ }
+*/
+
+ public void testRequestContextMethod() throws Exception {
+ Method method = Foo.class.getMethod("setRequestContext", RequestContext.class);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitMethod(method, type);
+ assertNotNull(type.getResources().get("requestContext"));
+ }
+
+ public void testRequestContextField() throws Exception {
+ Field field = Foo.class.getDeclaredField("requestContext");
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitField(field, type);
+ assertNotNull(type.getResources().get("requestContext"));
+ }
+
+ public void testInvalidParamType() throws Exception {
+ Method method = Foo.class.getMethod("setContext", String.class);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (UnknownContextTypeException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidParamTypeField() throws Exception {
+ Field field = Foo.class.getDeclaredField("badContext");
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ processor.visitField(field, type);
+ fail();
+ } catch (UnknownContextTypeException e) {
+ // expected
+ }
+ }
+
+
+ public void testInvalidParamNum() throws Exception {
+ Method method = Foo.class.getMethod("setContext", ComponentContext.class, String.class);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (IllegalContextException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidNoParams() throws Exception {
+ Method method = Foo.class.getMethod("setContext");
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (IllegalContextException e) {
+ // expected
+ }
+ }
+
+ public void testNoContext() throws Exception {
+ Method method = Foo.class.getMethod("noContext", ComponentContext.class);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitMethod(method, type);
+ assertEquals(0, type.getResources().size());
+ }
+
+ public void testNoContextField() throws Exception {
+ Field field = Foo.class.getDeclaredField("noContext");
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitField(field, type);
+ assertEquals(0, type.getResources().size());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ javaImplementationFactory = new DefaultJavaImplementationFactory();
+ processor = new ContextProcessor(new DefaultAssemblyFactory());
+ // processor.setWorkContext(EasyMock.createNiceMock(WorkContext.class));
+ composite = EasyMock.createNiceMock(Component.class);
+ }
+
+ private class Foo {
+ @Context
+ protected ComponentContext context;
+
+ @Context
+ protected Object badContext;
+
+ protected ComponentContext noContext;
+
+ @Context
+ protected RequestContext requestContext;
+
+ @Context
+ public void setContext(ComponentContext context) {
+
+ }
+
+ @Context
+ public void setContext(String context) {
+
+ }
+
+ @Context
+ public void setContext(ComponentContext context, String string) {
+
+ }
+
+ @Context
+ public void setContext() {
+
+ }
+
+ public void noContext(ComponentContext context) {
+
+ }
+
+ @Context
+ public void setRequestContext(RequestContext requestContext) {
+ this.requestContext = requestContext;
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessorTestCase.java
new file mode 100644
index 0000000000..239012d468
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessorTestCase.java
@@ -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.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.osoa.sca.annotations.ConversationAttributes;
+import org.osoa.sca.annotations.ConversationID;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConversationProcessorTestCase extends TestCase {
+ private ConversationProcessor processor = new ConversationProcessor(new DefaultAssemblyFactory());
+ private JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+
+ public void testMaxIdleTime() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(FooMaxIdle.class, type);
+ assertEquals(10000L, type.getMaxIdleTime());
+ assertEquals(-1, type.getMaxAge());
+ }
+
+ public void testMaxAge() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(FooMaxAge.class, type);
+ assertEquals(10000L, type.getMaxAge());
+ assertEquals(-1, type.getMaxIdleTime());
+ }
+
+ public void testBadFooBoth() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ processor.visitClass(BadFooBoth.class, type);
+ fail();
+ } catch (InvalidConversationalImplementation e) {
+ // expected
+ }
+ }
+
+ public void testImplicitScope() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(ImplicitFooScope.class, type);
+ assertEquals(org.apache.tuscany.sca.implementation.java.impl.JavaScopeImpl.CONVERSATION, type.getJavaScope());
+ }
+
+ public void testBadFooScope() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ processor.visitClass(BadFooScope.class, type);
+ fail();
+ } catch (InvalidConversationalImplementation e) {
+ // expected
+ }
+ }
+
+ public void testJustConversation() throws Exception {
+ // TODO do we want these semantics
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(FooJustConversation.class, type);
+ assertEquals(org.apache.tuscany.sca.implementation.java.impl.JavaScopeImpl.CONVERSATION, type.getJavaScope());
+ assertEquals(-1, type.getMaxAge());
+ assertEquals(-1, type.getMaxIdleTime());
+ }
+
+ public void testSetConversationIDField() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Field field = FooWithConversationIDField.class.getDeclaredField("conversationID");
+ processor.visitField(field, type);
+ assertNotNull(type.getConversationIDMember());
+ assertEquals(field, type.getConversationIDMember());
+ }
+
+ public void testSetConversationIDMethod() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Method method = FooWithConversationIDMethod.class.getDeclaredMethods()[0];
+ processor.visitMethod(method, type);
+ assertNotNull(type.getConversationIDMember());
+ assertEquals(method, type.getConversationIDMember());
+ }
+
+ @Scope("CONVERSATION")
+ @ConversationAttributes(maxIdleTime = "10 seconds")
+ private class FooMaxIdle {
+ }
+
+ @Scope("CONVERSATION")
+ @ConversationAttributes(maxAge = "10 seconds")
+ private class FooMaxAge {
+ }
+
+ @Scope("CONVERSATION")
+ @ConversationAttributes(maxAge = "10 seconds", maxIdleTime = "10 seconds")
+ private class BadFooBoth {
+ }
+
+ @ConversationAttributes(maxAge = "10 seconds")
+ private class ImplicitFooScope {
+ }
+
+ @Scope("STATELESS")
+ @ConversationAttributes(maxAge = "10 seconds")
+ private class BadFooScope {
+ }
+
+ @ConversationAttributes
+ private class FooJustConversation {
+ }
+
+ private class FooWithConversationIDField {
+ @ConversationID
+ private String conversationID;
+ }
+
+ private class FooWithConversationIDMethod {
+ @ConversationID
+ void setConversationID(String conversationID) {
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java
new file mode 100644
index 0000000000..1c00df8e04
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConvertTimeMillisTestCase extends TestCase {
+ private MockProcessor registy;
+
+ public void testConvertSeconds() throws Exception {
+ assertEquals(10000L, registy.convertTimeMillis("10 seconds"));
+ assertEquals(10000L, registy.convertTimeMillis("10 SECONDS"));
+ try {
+ registy.convertTimeMillis("10seconds");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ public void testConvertMinutes() throws Exception {
+ assertEquals(600000L, registy.convertTimeMillis("10 minutes"));
+ assertEquals(600000L, registy.convertTimeMillis("10 MINUTES"));
+ try {
+ registy.convertTimeMillis("10minutes");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ public void testConvertHours() throws Exception {
+ assertEquals(36000000L, registy.convertTimeMillis("10 hours"));
+ assertEquals(36000000L, registy.convertTimeMillis("10 HOURS"));
+ try {
+ registy.convertTimeMillis("10hours");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ public void testConvertDays() throws Exception {
+ assertEquals(864000000L, registy.convertTimeMillis("10 days"));
+ assertEquals(864000000L, registy.convertTimeMillis("10 DAYS"));
+ try {
+ registy.convertTimeMillis("10days");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ public void testConvertYears() throws Exception {
+ assertEquals(315569260000L, registy.convertTimeMillis("10 years"));
+ assertEquals(315569260000L, registy.convertTimeMillis("10 YEARS"));
+ try {
+ registy.convertTimeMillis("10years");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ public void testConvertDefault() throws Exception {
+ assertEquals(10000L, registy.convertTimeMillis("10 "));
+ assertEquals(10000L, registy.convertTimeMillis("10"));
+ }
+
+ public void testInvalid() throws Exception {
+ try {
+ registy.convertTimeMillis("foo");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ registy = new MockProcessor();
+ }
+
+ private class MockProcessor extends ConversationProcessor {
+
+ public MockProcessor() {
+ super(new DefaultAssemblyFactory());
+ }
+
+ @Override
+ protected long convertTimeMillis(String expr) throws NumberFormatException {
+ return super.convertTimeMillis(expr);
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessorTestCase.java
new file mode 100644
index 0000000000..657ad757e5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessorTestCase.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.osoa.sca.annotations.Destroy;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DestroyProcessorTestCase extends TestCase {
+
+ private AssemblyFactory assemblyFactory = new DefaultAssemblyFactory();
+ private JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+
+ public void testDestroy() throws Exception {
+ DestroyProcessor processor = new DestroyProcessor(assemblyFactory);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Method method = Foo.class.getMethod("destroy");
+ processor.visitMethod(method, type);
+ assertNotNull(type.getDestroyMethod());
+ }
+
+ public void testBadDestroy() throws Exception {
+ DestroyProcessor processor = new DestroyProcessor(assemblyFactory);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Method method = Bar.class.getMethod("badDestroy", String.class);
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (IllegalDestructorException e) {
+ // expected
+ }
+ }
+
+ public void testTwoDestroy() throws Exception {
+ DestroyProcessor processor = new DestroyProcessor(assemblyFactory);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Method method = Bar.class.getMethod("destroy");
+ Method method2 = Bar.class.getMethod("destroy2");
+ processor.visitMethod(method, type);
+ try {
+ processor.visitMethod(method2, type);
+ fail();
+ } catch (DuplicateDestructorException e) {
+ // expected
+ }
+ }
+
+
+ private class Foo {
+
+ @Destroy
+ public void destroy() {
+ }
+ }
+
+
+ private class Bar {
+
+ @Destroy
+ public void destroy() {
+ }
+
+ @Destroy
+ public void destroy2() {
+ }
+
+ @Destroy
+ public void badDestroy(String foo) {
+ }
+
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessorTestCase.java
new file mode 100644
index 0000000000..9ece6cd164
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessorTestCase.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.introspect.IntrospectionException;
+import org.osoa.sca.annotations.EagerInit;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class EagerInitProcessorTestCase extends TestCase {
+
+ private AssemblyFactory assemblyFactory = new DefaultAssemblyFactory();
+ private JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+
+ public void testNoLevel() throws IntrospectionException {
+ EagerInitProcessor processor = new EagerInitProcessor(assemblyFactory);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(Level.class, type);
+ }
+
+ public void testSubclass() throws IntrospectionException {
+ EagerInitProcessor processor = new EagerInitProcessor(assemblyFactory);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(SubClass.class, type);
+ }
+
+ @EagerInit
+ private class Level {
+ }
+
+ private class SubClass extends Level {
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java
new file mode 100644
index 0000000000..d125366707
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Constructor;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaConstructorImpl;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.introspect.DefaultJavaInterfaceIntrospectorExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.java.introspect.ExtensibleJavaInterfaceIntrospector;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospectorExtensionPoint;
+import org.osoa.sca.annotations.Property;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HeuristicAndPropertyTestCase extends TestCase {
+
+ private PropertyProcessor propertyProcessor;
+ private HeuristicPojoProcessor heuristicProcessor;
+ private AssemblyFactory assemblyFactory = new DefaultAssemblyFactory();
+ private JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+
+ /**
+ * Verifies the property and heuristic processors don't collide
+ */
+ @SuppressWarnings("unchecked")
+ public void testPropertyProcessorWithHeuristicProcessor() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor ctor = Foo.class.getConstructor(String.class);
+ type.setConstructor(new JavaConstructorImpl(ctor));
+ propertyProcessor.visitConstructorParameter(type.getConstructor().getParameters()[0], type);
+ heuristicProcessor.visitEnd(Foo.class, type);
+ assertEquals(1, type.getProperties().size());
+ assertEquals("foo", type.getProperties().get(0).getName());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ JavaInterfaceIntrospectorExtensionPoint visitors = new DefaultJavaInterfaceIntrospectorExtensionPoint();
+ ExtensibleJavaInterfaceIntrospector introspector = new ExtensibleJavaInterfaceIntrospector(new DefaultJavaInterfaceFactory(), visitors);
+ propertyProcessor = new PropertyProcessor(assemblyFactory);
+ heuristicProcessor = new HeuristicPojoProcessor(assemblyFactory, new DefaultJavaInterfaceFactory(), introspector);
+ }
+
+ public static class Foo {
+ public Foo(@Property(name = "foo")
+ String prop) {
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicConstructorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicConstructorTestCase.java
new file mode 100644
index 0000000000..de90130295
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicConstructorTestCase.java
@@ -0,0 +1,315 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.ModelHelper.getProperty;
+
+import java.lang.reflect.Constructor;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.implementation.java.introspect.IntrospectionException;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.introspect.DefaultJavaInterfaceIntrospectorExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.java.introspect.ExtensibleJavaInterfaceIntrospector;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospectorExtensionPoint;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Remotable;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HeuristicConstructorTestCase extends AbstractProcessorTest {
+
+ private AssemblyFactory factory;
+ private JavaInterfaceFactory javaFactory;
+ private HeuristicPojoProcessor processor;
+ private JavaImplementationFactory javaImplementationFactory;
+
+ public HeuristicConstructorTestCase() {
+ factory = new DefaultAssemblyFactory();
+ javaFactory = new DefaultJavaInterfaceFactory();
+ javaImplementationFactory = new DefaultJavaImplementationFactory();
+ JavaInterfaceIntrospectorExtensionPoint visitors = new DefaultJavaInterfaceIntrospectorExtensionPoint();
+ ExtensibleJavaInterfaceIntrospector introspector = new ExtensibleJavaInterfaceIntrospector(javaFactory, visitors);
+ processor = new HeuristicPojoProcessor(factory, javaFactory, introspector);
+ }
+
+ private <T> void visitEnd(Class<T> clazz, JavaImplementation type) throws IntrospectionException {
+ for (Constructor<T> constructor : clazz.getConstructors()) {
+ visitConstructor(constructor, type);
+ }
+ processor.visitEnd(clazz, type);
+ }
+
+ /**
+ * Verifies a single constructor is chosen with a parameter as the type
+ */
+ public void testSingleConstructorWithParam() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ org.apache.tuscany.sca.assembly.Property prop = factory.createProperty();
+ prop.setName("foo");
+ type.getProperties().add(prop);
+ // Hack to add a property member
+ JavaElementImpl element = new JavaElementImpl("foo", String.class, null);
+ type.getPropertyMembers().put("foo", element);
+ visitEnd(Foo1.class, type);
+ assertNotNull(type.getConstructor().getConstructor());
+ assertEquals("foo", type.getConstructor().getParameters()[0].getName());
+ }
+
+ /**
+ * Verifies a single constructor is chosen with a reference as the type
+ */
+ public void testSingleConstructorWithRef() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ org.apache.tuscany.sca.assembly.Reference ref = factory.createReference();
+ ref.setName("foo");
+ type.getReferences().add(ref);
+ type.getReferenceMembers().put("foo", new JavaElementImpl("foo", String.class, null));
+ visitEnd(Foo1.class, type);
+ assertNotNull(type.getConstructor().getConstructor());
+ assertEquals("foo", type.getConstructor().getParameters()[0].getName());
+ }
+
+ /**
+ * Verifies a single constructor is chosen with a property and a reference
+ * as the type
+ */
+ public void testSingleConstructorWithPropRef() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+
+ org.apache.tuscany.sca.assembly.Property prop = factory.createProperty();
+ prop.setName("foo");
+ type.getProperties().add(prop);
+ // Hack to add a property member
+ JavaElementImpl element = new JavaElementImpl("foo", String.class, null);
+ type.getPropertyMembers().put("foo", element);
+
+ org.apache.tuscany.sca.assembly.Reference ref = ModelHelper.createReference(factory, javaFactory, "ref", Foo1.class);
+ type.getReferences().add(ref);
+ type.getReferenceMembers().put("ref", new JavaElementImpl("ref", Foo1.class, null));
+ visitEnd(Foo2.class, type);
+ assertNotNull(type.getConstructor().getConstructor());
+ assertEquals(2, type.getConstructor().getParameters().length);
+ }
+
+ public void testSingleConstructorResolvableParam() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ visitEnd(Foo5.class, type);
+ assertEquals(String.class, type.getPropertyMembers().get("string").getType());
+ }
+
+ public void testSingleConstructorResolvableRef() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ visitEnd(Foo6.class, type);
+ assertTrue(ModelHelper.matches(ModelHelper.getReference(type, "ref"), Ref.class));
+ }
+
+ public void testSingleConstructorAmbiguousRef() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ org.apache.tuscany.sca.assembly.Reference ref = ModelHelper.createReference(factory, javaFactory, "ref", Foo1.class);
+ type.getReferences().add(ref);
+ type.getReferenceMembers().put("ref", new JavaElementImpl("ref", Foo1.class, null));
+ org.apache.tuscany.sca.assembly.Reference ref2 = ModelHelper.createReference(factory, javaFactory, "ref2", Foo1.class);
+ type.getReferences().add(ref2);
+ type.getReferenceMembers().put("ref2", new JavaElementImpl("ref2", Foo1.class, null));
+ try {
+ visitEnd(Foo4.class, type);
+ fail();
+ } catch (AmbiguousConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testConstructorPropertyAnnotatedParamsOnly() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ visitEnd(Foo7.class, type);
+ assertNotNull(getProperty(type, "myProp"));
+ }
+
+ public void testConstructorReferenceAnnotatedParamsOnly() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ visitEnd(Foo8.class, type);
+ assertNotNull(ModelHelper.getReference(type, "myRef"));
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testDefaultConstructor() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ visitEnd(Foo3.class, type);
+ assertNotNull(type.getConstructor().getConstructor());
+ }
+
+ public void testSameTypesButAnnotated() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ visitEnd(Foo12.class, type);
+ assertEquals(2, type.getProperties().size());
+ assertNotNull(getProperty(type, "prop1"));
+ assertNotNull(getProperty(type, "prop2"));
+ }
+
+ /**
+ * Verifies processing executes with additional extension annotations
+ */
+ public void testRandomAnnotation() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ visitEnd(Foo11.class, type);
+ assertEquals(1, type.getProperties().size());
+ assertNotNull(getProperty(type, "prop1"));
+ }
+
+ public void testPrivateConstructor() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ visitEnd(Foo14.class, type);
+ fail();
+ } catch (NoConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testMultipleConstructors() throws Exception {
+ // throw new UnsupportedOperationException("Finish heuristic multiple
+ // constructors - Foo10");
+ }
+
+ public static class Foo1 {
+ public Foo1(String val) {
+ }
+ }
+
+ public static class Foo2 {
+ public Foo2(String val, Foo1 ref) {
+ }
+ }
+
+ public static class Foo3 {
+ }
+
+ public static class Foo4 {
+ public Foo4(Foo1 ref) {
+ }
+ }
+
+ public static class Prop {
+
+ }
+
+ @Remotable
+ public static interface Ref {
+
+ }
+
+ public static class Foo5 {
+ public Foo5(String val) {
+ }
+ }
+
+ public static class Foo6 {
+ public Foo6(Ref ref) {
+ }
+ }
+
+ public static class Foo7 {
+ public Foo7(@Property(name = "myProp")
+ String prop) {
+ }
+ }
+
+ public static class Foo8 {
+ public Foo8(@Reference(name = "myRef")
+ String ref) {
+ }
+ }
+
+ public static class Foo9 {
+ public Foo9(@Reference(name = "myRef")
+ String ref) {
+ }
+ }
+
+ public static class Foo10 {
+
+ public Foo10() {
+ }
+
+ public Foo10(String prop) {
+ }
+
+ public Foo10(@Property(name = "prop1")
+ String prop1, @Property(name = "prop2")
+ String prop2) {
+
+ }
+ }
+
+ public static class Foo11 {
+
+ public Foo11(@Property(name = "prop1")
+ String prop, @Baz
+ String baz) {
+ }
+ }
+
+ public static class Foo12 {
+
+ public Foo12(@Property(name = "prop1")
+ String prop, @Property(name = "prop2")
+ String baz) {
+ }
+ }
+
+ public @interface Baz {
+
+ }
+
+ public static class Foo13 {
+ public Foo13(@Reference
+ String foo) {
+ }
+ }
+
+ public static final class Foo14 {
+ private Foo14() {
+ }
+ }
+
+ public static final class Foo15 {
+ public Foo15(@Reference
+ String param1, @Reference
+ String param2) {
+ }
+ }
+
+ public static final class Foo16 {
+ public Foo16(@Reference
+ String param1, @Property(name = "foo")
+ String param2, @Reference(name = "bar")
+ String param3) {
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessorTestCase.java
new file mode 100644
index 0000000000..323daf52d0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessorTestCase.java
@@ -0,0 +1,411 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.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.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaConstructorImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.implementation.java.introspect.IntrospectionException;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.introspect.DefaultJavaInterfaceIntrospectorExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.java.introspect.ExtensibleJavaInterfaceIntrospector;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospectorExtensionPoint;
+import org.apache.tuscany.sca.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.sca.implementation.java.introspect.impl.HeuristicPojoProcessor processor;
+ private JavaImplementationFactory javaImplementationFactory;
+
+ public HeuristicPojoProcessorTestCase() {
+ JavaInterfaceIntrospectorExtensionPoint visitors = new DefaultJavaInterfaceIntrospectorExtensionPoint();
+ ExtensibleJavaInterfaceIntrospector introspector = new ExtensibleJavaInterfaceIntrospector(new DefaultJavaInterfaceFactory(), visitors);
+ processor = new HeuristicPojoProcessor(new DefaultAssemblyFactory(), new DefaultJavaInterfaceFactory(), introspector);
+ javaImplementationFactory = new DefaultJavaImplementationFactory();
+ }
+
+ private <T> void visitEnd(Class<T> clazz, JavaImplementation type) throws IntrospectionException {
+ 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 {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<SingleInterfaceImpl> ctor = SingleInterfaceImpl.class.getConstructor();
+ type.setConstructor(new JavaConstructorImpl<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 {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<SingleInterfaceWithPropertyReferenceImpl> ctor = SingleInterfaceWithPropertyReferenceImpl.class
+ .getConstructor();
+ type.setConstructor(new JavaConstructorImpl<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.sca.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 {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<SingleInterfaceImpl> ctor = SingleInterfaceImpl.class.getConstructor();
+ type.setConstructor(new JavaConstructorImpl<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 {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<RefInterfaceImpl> ctor = RefInterfaceImpl.class.getConstructor();
+ type.setConstructor(new JavaConstructorImpl<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 {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<ReferenceCollectionImpl> ctor = ReferenceCollectionImpl.class.getConstructor();
+ type.setConstructor(new JavaConstructorImpl<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 {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<PropertyCollectionImpl> ctor = PropertyCollectionImpl.class.getConstructor();
+ type.setConstructor(new JavaConstructorImpl<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 {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<RemotableRefImpl> ctor = RemotableRefImpl.class.getConstructor();
+ type.setConstructor(new JavaConstructorImpl<RemotableRefImpl>(ctor));
+ processor.visitEnd(RemotableRefImpl.class, type);
+ assertEquals(2, type.getReferences().size());
+ assertEquals(0, type.getProperties().size());
+ }
+
+ public void testParentInterface() throws IntrospectionException, NoSuchMethodException {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Child> ctor = Child.class.getConstructor();
+ type.setConstructor(new JavaConstructorImpl<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 {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ org.apache.tuscany.sca.assembly.Reference ref = factory.createReference();
+ ref.setName("reference");
+ type.getReferences().add(ref);
+ type.getReferenceMembers().put("reference", new JavaElementImpl("reference", Ref.class, null));
+ org.apache.tuscany.sca.assembly.Reference ref2 = factory.createReference();
+ ref2.setName("reference2");
+ type.getReferences().add(ref2);
+ type.getReferenceMembers().put("reference2", new JavaElementImpl("reference2", Ref.class, null));
+ org.apache.tuscany.sca.assembly.Property prop1 = factory.createProperty();
+ prop1.setName("string1");
+ type.getProperties().add(prop1);
+ type.getPropertyMembers().put("string1", new JavaElementImpl("string1", String.class, null));
+ org.apache.tuscany.sca.assembly.Property prop2 = factory.createProperty();
+ prop2.setName("string2");
+ type.getProperties().add(prop2);
+ type.getPropertyMembers().put("string2", new JavaElementImpl("string2", String.class, null));
+ visitEnd(MockService.class, type);
+ assertEquals(1, type.getServices().size());
+ }
+
+ public void testProtectedRemotableRefField() throws IntrospectionException, NoSuchMethodException {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<ProtectedRemotableRefFieldImpl> ctor = ProtectedRemotableRefFieldImpl.class.getConstructor();
+ type.setConstructor(new JavaConstructorImpl<ProtectedRemotableRefFieldImpl>(ctor));
+ processor.visitEnd(ProtectedRemotableRefFieldImpl.class, type);
+ assertNotNull(ModelHelper.getReference(type, "otherRef"));
+ }
+
+ public void testProtectedRemotableRefMethod() throws IntrospectionException, NoSuchMethodException {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<ProtectedRemotableRefMethodImpl> ctor = ProtectedRemotableRefMethodImpl.class.getConstructor();
+ type.setConstructor(new JavaConstructorImpl<ProtectedRemotableRefMethodImpl>(ctor));
+ processor.visitEnd(ProtectedRemotableRefMethodImpl.class, type);
+ assertNotNull(ModelHelper.getReference(type, "otherRef"));
+ }
+
+ public void testSetDataTypes() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<PropertyIntTypeOnConstructor> ctor = PropertyIntTypeOnConstructor.class.getConstructor();
+ type.setConstructor(new JavaConstructorImpl<PropertyIntTypeOnConstructor>(ctor));
+ processor.visitEnd(PropertyIntTypeOnConstructor.class, type);
+ org.apache.tuscany.sca.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) {
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeutisticExtensibleConstructorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeutisticExtensibleConstructorTestCase.java
new file mode 100644
index 0000000000..8499e344ce
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeutisticExtensibleConstructorTestCase.java
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Constructor;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaConstructorImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.implementation.java.introspect.IntrospectionException;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.introspect.DefaultJavaInterfaceIntrospectorExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.java.introspect.ExtensibleJavaInterfaceIntrospector;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospectorExtensionPoint;
+
+/**
+ * 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.sca.implementation.java.introspect.impl.HeuristicPojoProcessor processor;
+ private JavaImplementationFactory javaImplementationFactory;
+
+ public HeutisticExtensibleConstructorTestCase() {
+ JavaInterfaceIntrospectorExtensionPoint visitors = new DefaultJavaInterfaceIntrospectorExtensionPoint();
+ ExtensibleJavaInterfaceIntrospector introspector = new ExtensibleJavaInterfaceIntrospector(new DefaultJavaInterfaceFactory(), visitors);
+ processor = new HeuristicPojoProcessor(new DefaultAssemblyFactory(), new DefaultJavaInterfaceFactory(), introspector);
+ javaImplementationFactory = new DefaultJavaImplementationFactory();
+ }
+
+ private <T> void visitEnd(Class<T> clazz, JavaImplementation type) throws IntrospectionException {
+ 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 {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+ JavaConstructorImpl<Foo> definition = new JavaConstructorImpl<Foo>(ctor);
+ type.setConstructor(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 {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ visitEnd(Foo.class, type);
+
+ // now simulate process the bar impl
+ JavaConstructorImpl<?> definition = type.getConstructor();
+ 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 {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo2> ctor = Foo2.class.getConstructor(String.class, String.class, String.class);
+ JavaConstructorImpl<Foo2> definition = new JavaConstructorImpl<Foo2>(ctor);
+ type.setConstructor(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
+ JavaElementImpl element = new JavaElementImpl("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) {
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessorTestCase.java
new file mode 100644
index 0000000000..be2b5aa56e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessorTestCase.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.osoa.sca.annotations.Init;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InitProcessorTestCase extends TestCase {
+
+ private JavaImplementationFactory javaImplementationFactory;
+
+ public InitProcessorTestCase() {
+ javaImplementationFactory = new DefaultJavaImplementationFactory();
+ }
+
+ public void testInit() throws Exception {
+ InitProcessor processor = new InitProcessor(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Method method = InitProcessorTestCase.Foo.class.getMethod("init");
+ processor.visitMethod(method, type);
+ assertNotNull(type.getInitMethod());
+ }
+
+ public void testBadInit() throws Exception {
+ InitProcessor processor = new InitProcessor(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ 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(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ 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) {
+ }
+
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ModelHelper.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ModelHelper.java
new file mode 100644
index 0000000000..aad6b96cf9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ModelHelper.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Contract;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ModelHelper {
+
+ public static Property getProperty(JavaImplementation type, String name) {
+ for (Property prop : type.getProperties()) {
+ if (prop.getName().equals(name)) {
+ return prop;
+ }
+ }
+ return null;
+ }
+
+ public static Reference getReference(JavaImplementation type, String name) {
+ for (Reference ref : type.getReferences()) {
+ if (ref.getName().equals(name)) {
+ return ref;
+ }
+ }
+ return null;
+ }
+
+ public static Service getService(JavaImplementation 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(AssemblyFactory factory,
+ JavaInterfaceFactory javaFactory, Class<?> type) {
+ org.apache.tuscany.sca.assembly.ComponentService ref = factory.createComponentService();
+ ref.setName(type.getSimpleName());
+ JavaInterface i = javaFactory.createJavaInterface();
+ i.setJavaClass(type);
+ JavaInterfaceContract ic = javaFactory.createJavaInterfaceContract();
+ ic.setInterface(i);
+ ref.setInterfaceContract(ic);
+ return ref;
+ }
+
+ public static Reference createReference(AssemblyFactory factory,
+ JavaInterfaceFactory javaFactory, String name, Class<?> type) {
+ org.apache.tuscany.sca.assembly.Reference ref = factory.createReference();
+ ref.setName(name);
+ JavaInterface i = javaFactory.createJavaInterface();
+ i.setJavaClass(type);
+ JavaInterfaceContract ic = javaFactory.createJavaInterfaceContract();
+ ic.setInterface(i);
+ ref.setInterfaceContract(ic);
+ return ref;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java
new file mode 100644
index 0000000000..25d37a6eca
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java
@@ -0,0 +1,406 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.introspect.DefaultJavaInterfaceIntrospectorExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.java.introspect.ExtensibleJavaInterfaceIntrospector;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospectorExtensionPoint;
+import org.apache.tuscany.sca.policy.DefaultPolicyFactory;
+import org.apache.tuscany.sca.policy.Intent;
+import org.osoa.sca.annotations.Requires;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PolicyProcessorTestCase extends TestCase {
+ private ServiceProcessor serviceProcessor;
+ private PolicyProcessor policyProcessor;
+ private JavaImplementation type;
+
+ // This actually is a test for PolicyJavaInterfaceProcessor. It will get
+ // invoked via the call to ImplementationProcessorServiceImpl.createService in
+ // ServiceProcessor. Of course ServiceProcessor class has to be working.
+ public void testSingleInterfaceWithIntentsOnInterfaceAtInterfaceLevel() throws Exception {
+ serviceProcessor.visitClass(Service1.class, type);
+ policyProcessor.visitClass(Service1.class, type);
+ verifyIntents(Service1.class, type);
+ }
+
+ public void testMultipleInterfacesWithIntentsOnInterfaceAtInterfaceLevel() throws Exception {
+ serviceProcessor.visitClass(Service2.class, type);
+ policyProcessor.visitClass(Service2.class, type);
+ verifyIntents(Service2.class, type);
+ }
+
+ public void testSingleInterfaceWithIntentsOnImplAtClassLevel() throws Exception {
+ serviceProcessor.visitClass(Service3.class, type);
+ policyProcessor.visitClass(Service3.class, type);
+ verifyIntents(Service3.class, type);
+ }
+
+ public void testMultipleInterfacesWithIntentsOnImplAtClassLevel() throws Exception {
+ serviceProcessor.visitClass(Service4.class, type);
+ policyProcessor.visitClass(Service4.class, type);
+ verifyIntents(Service4.class, type);
+ }
+
+ public void testSingleInterfaceWithIntentsOnInterfaceAtMethodLevel() throws Exception {
+ serviceProcessor.visitClass(Service5.class, type);
+ policyProcessor.visitClass(Service5.class, type);
+ verifyIntents(Service5.class, type);
+ }
+
+ public void testSingleInterfaceWithIntentsOnServiceAndInterfaceAtImplAndInertfaceAndMethodLevel() throws Exception {
+ serviceProcessor.visitClass(Service6.class, type);
+ policyProcessor.visitClass(Service6.class, type);
+ for (Method method : Service6.class.getDeclaredMethods()) {
+ policyProcessor.visitMethod(method, type);
+ }
+ verifyIntents(Service6.class, type);
+ }
+
+ private void verifyIntents(Class serviceImplClass, JavaImplementation type) {
+
+ Requires serviceImplIntentAnnotation = (Requires)serviceImplClass.getAnnotation(Requires.class);
+ if (serviceImplIntentAnnotation != null) {
+ String[] serviceImplIntents = serviceImplIntentAnnotation.value();
+ List<Intent> requiredIntents = type.getRequiredIntents();
+ if (serviceImplIntents.length > 0) {
+ if (requiredIntents == null || requiredIntents.size() == 0) {
+ fail("No Intents on the service ");
+ }
+ Map<String, Intent> intentMap = new HashMap<String, Intent>();
+ for (Intent intent : requiredIntents) {
+ intentMap.put(intent.getName().getLocalPart(), intent);
+ }
+ for (String intent : serviceImplIntents) {
+ assertTrue("ComponentType for Service class " + serviceImplClass.getName()
+ + " did not contain Service Implementation intent "
+ + intent, intentMap.containsKey(intent));
+ }
+ }
+ }
+
+ // This should match what was specified on @Service for a Service Implementation
+ // If we use these to get the Service names and we get a null Service
+ // name then it would seem that wrong values were put on the @Service annotation
+ // or the wrong interfaces were specified on the implements list of the class
+ // statement?
+ Map<String, org.apache.tuscany.sca.assembly.Service> serviceMap = new HashMap<String, org.apache.tuscany.sca.assembly.Service>();
+ for (org.apache.tuscany.sca.assembly.Service service: type.getServices()) {
+ serviceMap.put(service.getName(), service);
+ }
+ for (Class interfaceClass : serviceImplClass.getInterfaces()) {
+ Requires interfaceIntentAnnotation = (Requires)interfaceClass.getAnnotation(Requires.class);
+ org.apache.tuscany.sca.assembly.Service service = serviceMap.get(interfaceClass.getSimpleName());
+ if (service == null) {
+ fail("No service defined for interface " + interfaceClass.getSimpleName()
+ + " on Service Implementation "
+ + serviceImplClass.getName());
+ }
+
+ if (interfaceIntentAnnotation != null) {
+ String[] interfaceIntents = interfaceIntentAnnotation.value();
+ List<Intent> requiredIntents = service.getRequiredIntents();
+ if (interfaceIntents.length > 0) {
+ if (requiredIntents == null || requiredIntents.size() == 0) {
+ fail("No Intents on the service " + service.getName());
+ }
+ Map<String, Intent> intentMap = new HashMap<String, Intent>();
+ for (Intent intent : requiredIntents) {
+ intentMap.put(intent.getName().getLocalPart(), intent);
+ }
+ for (String intent : interfaceIntents) {
+ assertTrue("Interface " + service.getName()
+ + " did not contain Service Interface intent "
+ + intent, intentMap.containsKey(intent));
+ }
+ }
+ }
+
+ for (Method method : interfaceClass.getDeclaredMethods()) {
+ Requires methodIntentAnnotation = method.getAnnotation(Requires.class);
+
+ // Verify that each of the Intents on each of the Service
+ // Interface Methods exist on their associated operation.
+ if (methodIntentAnnotation != null) {
+ String[] methodIntents = methodIntentAnnotation.value();
+ if (methodIntents.length > 0) {
+ List<Intent> requiredIntents = service.getRequiredIntents();
+ if (requiredIntents.size() == 0) {
+ fail("No Intents on operation " + method.getName());
+ }
+ for (String intent : methodIntents) {
+ boolean found = false;
+ for (Intent requiredIntent: requiredIntents) {
+ if (requiredIntent.getName().getLocalPart().equals(intent)) {
+ for (Operation operation: requiredIntent.getOperations()) {
+ if (operation.getName().equals(method.getName())) {
+ found = true;
+ break;
+ }
+ }
+ }
+ if (found)
+ break;
+ }
+ assertTrue("Operation " + method.getName()
+ + " did not contain Service Interface method intent "
+ + intent, found);
+ }
+ }
+ }
+ }
+
+ for (Method method : serviceImplClass.getDeclaredMethods()) {
+ Requires methodIntentAnnotation = method.getAnnotation(Requires.class);
+
+ // Verify that each of the Intents on each of the Service
+ // Implementation Methods exist on their associated
+ // operation.
+ if (methodIntentAnnotation != null) {
+ String[] methodIntents = methodIntentAnnotation.value();
+ if (methodIntents.length > 0) {
+ List<Intent> requiredIntents = type.getRequiredIntents();
+ if (requiredIntents.size() == 0) {
+ fail("No Intents on operation " + method.getName());
+ }
+ for (String intent : methodIntents) {
+ boolean found = false;
+ for (Intent requiredIntent: requiredIntents) {
+ if (requiredIntent.getName().getLocalPart().equals(intent)) {
+ for (Operation operation: requiredIntent.getOperations()) {
+ if (operation.getName().equals(method.getName())) {
+ found = true;
+ break;
+ }
+ }
+ }
+ if (found)
+ break;
+ }
+ assertTrue("Operation " + method.getName()
+ + " did not contain Service Interface method intent "
+ + intent, found);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ JavaInterfaceIntrospectorExtensionPoint visitors = new DefaultJavaInterfaceIntrospectorExtensionPoint();
+ ExtensibleJavaInterfaceIntrospector introspector = new ExtensibleJavaInterfaceIntrospector(new DefaultJavaInterfaceFactory(), visitors);
+ serviceProcessor = new ServiceProcessor(new DefaultAssemblyFactory(), new DefaultJavaInterfaceFactory(), introspector);
+ policyProcessor = new PolicyProcessor(new DefaultAssemblyFactory(), new DefaultPolicyFactory());
+ JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+ type = javaImplementationFactory.createJavaImplementation();
+ }
+
+ // @Remotable
+ @Requires( {"transaction.global"})
+ private interface Interface1 {
+ int method1();
+
+ int method2();
+
+ int method3();
+
+ int method4();
+ }
+
+ @Service(Interface1.class)
+ private class Service1 implements Interface1 {
+ public int method1() {
+ return 0;
+ }
+
+ public int method2() {
+ return 0;
+ }
+
+ public int method3() {
+ return 0;
+ }
+
+ public int method4() {
+ return 0;
+ }
+ }
+
+ // @Remotable
+ @Requires( {"transaction.local"})
+ private interface Interface2 {
+ int method5();
+
+ int method6();
+ }
+
+ @Service(interfaces = {Interface1.class, Interface2.class})
+ private class Service2 implements Interface1, Interface2 {
+ public int method1() {
+ return 0;
+ }
+
+ public int method2() {
+ return 0;
+ }
+
+ public int method3() {
+ return 0;
+ }
+
+ public int method4() {
+ return 0;
+ }
+
+ public int method5() {
+ return 0;
+ }
+
+ public int method6() {
+ return 0;
+ }
+ }
+
+ // @Remotable
+ private interface Interface3 {
+ int method1();
+
+ int method2();
+
+ int method3();
+
+ int method4();
+ }
+
+ @Service(Interface3.class)
+ @Requires( {"transaction.global"})
+ private class Service3 implements Interface3 {
+ public int method1() {
+ return 0;
+ }
+
+ public int method2() {
+ return 0;
+ }
+
+ public int method3() {
+ return 0;
+ }
+
+ public int method4() {
+ return 0;
+ }
+ }
+
+ // @Remotable
+ private interface Interface4 {
+ int method5();
+
+ int method6();
+ }
+
+ @Service(interfaces = {Interface3.class, Interface4.class})
+ @Requires( {"transaction.local"})
+ private class Service4 implements Interface3, Interface4 {
+ public int method1() {
+ return 0;
+ }
+
+ public int method2() {
+ return 0;
+ }
+
+ public int method3() {
+ return 0;
+ }
+
+ public int method4() {
+ return 0;
+ }
+
+ public int method5() {
+ return 0;
+ }
+
+ public int method6() {
+ return 0;
+ }
+ }
+
+ private interface Interface5 {
+ @Requires( {"transaction.global"})
+ int method1();
+
+ @Requires( {"transaction.local"})
+ int method2();
+ }
+
+ @Service(Interface5.class)
+ private class Service5 implements Interface5 {
+ public int method1() {
+ return 0;
+ }
+
+ public int method2() {
+ return 0;
+ }
+ }
+
+ @Requires( {"transaction.global.Interface6"})
+ private interface Interface6 {
+ @Requires( {"transaction.global.Interface6.method1"})
+ int method1();
+
+ @Requires( {"transaction.local.Interface6.method2"})
+ int method2();
+ }
+
+ @Service(Interface6.class)
+ @Requires( {"transaction.global.Service6"})
+ private class Service6 implements Interface6 {
+ @Requires( {"transaction.global.Service6.method1"})
+ public int method1() {
+ return 0;
+ }
+
+ @Requires( {"transaction.global.Service6.method1"})
+ public int method2() {
+ return 0;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessorTestCase.java
new file mode 100644
index 0000000000..ccac012138
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessorTestCase.java
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.ModelHelper.getProperty;
+
+import java.util.Collection;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.implementation.java.introspect.DuplicatePropertyException;
+import org.apache.tuscany.sca.implementation.java.introspect.IllegalPropertyException;
+import org.osoa.sca.annotations.Property;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PropertyProcessorTestCase extends TestCase {
+
+ JavaImplementation 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.sca.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.sca.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();
+ JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+ type = javaImplementationFactory.createJavaImplementation();
+ processor = new PropertyProcessor(new DefaultAssemblyFactory());
+ }
+
+ 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(JavaElementImpl element) {
+ return JavaIntrospectionHelper.getBaseType(element.getType(), element.getGenericType());
+ }
+
+ public void testMultiplicityCollection() throws Exception {
+ processor.visitField(Multiple.class.getDeclaredField("refs1"), type);
+ org.apache.tuscany.sca.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.sca.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.sca.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.sca.assembly.Property prop = getProperty(type, "refs4");
+ assertNotNull(prop);
+ assertSame(String.class, getBaseType(type.getPropertyMembers().get(prop.getName())));
+ assertTrue(prop.isMany());
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessorTestCase.java
new file mode 100644
index 0000000000..f70cef6090
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessorTestCase.java
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.ModelHelper.getReference;
+
+import java.util.Collection;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.assembly.Multiplicity;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.introspect.DefaultJavaInterfaceIntrospectorExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.java.introspect.ExtensibleJavaInterfaceIntrospector;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospectorExtensionPoint;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReferenceProcessorTestCase extends TestCase {
+
+ private JavaImplementation type;
+ private ReferenceProcessor processor;
+
+ public void testMethodAnnotation() throws Exception {
+ processor.visitMethod(ReferenceProcessorTestCase.Foo.class.getMethod("setFoo", Ref.class), type);
+ org.apache.tuscany.sca.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.sca.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.sca.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.sca.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();
+ JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+ type = javaImplementationFactory.createJavaImplementation();
+ JavaInterfaceIntrospectorExtensionPoint visitors = new DefaultJavaInterfaceIntrospectorExtensionPoint();
+ processor = new ReferenceProcessor(new DefaultAssemblyFactory(), new DefaultJavaInterfaceFactory(), new ExtensibleJavaInterfaceIntrospector(new DefaultJavaInterfaceFactory(), visitors));
+ }
+
+ 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.sca.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.sca.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.sca.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.sca.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());
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessorTestCase.java
new file mode 100644
index 0000000000..87ac37fea9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessorTestCase.java
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ResourceProcessorTestCase extends TestCase {
+
+ JavaImplementation type;
+ ResourceProcessor processor = new ResourceProcessor(new DefaultAssemblyFactory());
+
+ public void testVisitField() throws Exception {
+ Field field = Foo.class.getDeclaredField("bar");
+ processor.visitField(field, type);
+ JavaResourceImpl 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);
+ JavaResourceImpl 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);
+ JavaResourceImpl 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();
+ JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+ type = javaImplementationFactory.createJavaImplementation();
+ }
+
+ 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 {
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessorTestCase.java
new file mode 100644
index 0000000000..8faaf6949f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessorTestCase.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaScopeImpl;
+import org.apache.tuscany.sca.implementation.java.introspect.IntrospectionException;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ScopeProcessorTestCase extends TestCase {
+
+ Component parent;
+ private JavaImplementationFactory javaImplementationFactory;
+
+ public void testCompositeScope() throws IntrospectionException {
+ ScopeProcessor processor = new ScopeProcessor(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+
+ processor.visitClass(Composite.class, type);
+ assertEquals(JavaScopeImpl.COMPOSITE, type.getJavaScope());
+ }
+
+ public void testSessionScope() throws IntrospectionException {
+ ScopeProcessor processor = new ScopeProcessor(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(Session.class, type);
+ assertEquals(JavaScopeImpl.SESSION, type.getJavaScope());
+ }
+
+ public void testConversationalScope() throws IntrospectionException {
+ ScopeProcessor processor = new ScopeProcessor(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(Conversation.class, type);
+ assertEquals(JavaScopeImpl.CONVERSATION, type.getJavaScope());
+ }
+
+ public void testRequestScope() throws IntrospectionException {
+ ScopeProcessor processor = new ScopeProcessor(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(Request.class, type);
+ assertEquals(JavaScopeImpl.REQUEST, type.getJavaScope());
+ }
+
+ public void testStatelessScope() throws IntrospectionException {
+ ScopeProcessor processor = new ScopeProcessor(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(Stateless.class, type);
+ assertEquals(JavaScopeImpl.STATELESS, type.getJavaScope());
+ }
+
+ public void testNoScope() throws IntrospectionException {
+ ScopeProcessor processor = new ScopeProcessor(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(None.class, type);
+ assertEquals(JavaScopeImpl.STATELESS, type.getJavaScope());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ javaImplementationFactory = new DefaultJavaImplementationFactory();
+ 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 {
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceCallbackTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceCallbackTestCase.java
new file mode 100644
index 0000000000..0c98c0655e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceCallbackTestCase.java
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.ModelHelper.getService;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.introspect.IntrospectionException;
+import org.apache.tuscany.sca.interfacedef.InvalidCallbackException;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.introspect.DefaultJavaInterfaceIntrospectorExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.java.introspect.ExtensibleJavaInterfaceIntrospector;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospectorExtensionPoint;
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServiceCallbackTestCase extends TestCase {
+ private ServiceProcessor processor;
+ private JavaImplementationFactory javaImplementationFactory;
+
+ @Override
+ protected void setUp() throws Exception {
+ JavaInterfaceIntrospectorExtensionPoint visitors = new DefaultJavaInterfaceIntrospectorExtensionPoint();
+ processor = new ServiceProcessor(new DefaultAssemblyFactory(), new DefaultJavaInterfaceFactory(), new ExtensibleJavaInterfaceIntrospector(new DefaultJavaInterfaceFactory(), visitors));
+ javaImplementationFactory = new DefaultJavaImplementationFactory();
+ }
+
+ public void testMethodCallbackInterface() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(FooImpl.class, type);
+ org.apache.tuscany.sca.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(FooCallback.class.getName()).getAnchor());
+ }
+
+ public void testFieldCallbackInterface() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(FooImpl.class, type);
+ org.apache.tuscany.sca.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(FooCallback.class.getName()).getAnchor());
+ }
+
+ public void testMethodDoesNotMatchCallback() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ 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 {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ 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 {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ 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 {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ processor.visitClass(BadFooImpl.class, type);
+ fail();
+ } catch (IntrospectionException 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 {
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessorTestCase.java
new file mode 100644
index 0000000000..f905be7dc8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessorTestCase.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.introspect.DefaultJavaInterfaceIntrospectorExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.java.introspect.ExtensibleJavaInterfaceIntrospector;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospectorExtensionPoint;
+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 JavaImplementation type;
+
+ public void testMultipleInterfaces() throws Exception {
+ processor.visitClass(FooMultiple.class, type);
+ assertEquals(2, type.getServices().size());
+ org.apache.tuscany.sca.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.sca.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();
+ JavaInterfaceIntrospectorExtensionPoint visitors = new DefaultJavaInterfaceIntrospectorExtensionPoint();
+ ExtensibleJavaInterfaceIntrospector introspector = new ExtensibleJavaInterfaceIntrospector(new DefaultJavaInterfaceFactory(), visitors);
+ processor = new ServiceProcessor(new DefaultAssemblyFactory(), new DefaultJavaInterfaceFactory(), introspector);
+ JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+ type = javaImplementationFactory.createJavaImplementation();
+ }
+
+ @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 {
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java
new file mode 100644
index 0000000000..64ba0667f5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.java.xml;
+
+import java.io.InputStream;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.assembly.DefaultSCABindingFactory;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl;
+import org.apache.tuscany.sca.assembly.xml.CompositeProcessor;
+import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.introspect.DefaultJavaClassIntrospectorExtensionPoint;
+import org.apache.tuscany.sca.implementation.java.introspect.ExtensibleJavaClassIntrospector;
+import org.apache.tuscany.sca.implementation.java.introspect.JavaClassIntrospector;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
+import org.apache.tuscany.sca.policy.DefaultPolicyFactory;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+
+/**
+ * Test reading Java implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReadTestCase extends TestCase {
+
+ XMLInputFactory inputFactory;
+ DefaultStAXArtifactProcessorExtensionPoint staxProcessors;
+ ExtensibleStAXArtifactProcessor staxProcessor;
+ private AssemblyFactory assemblyFactory;
+ private SCABindingFactory scaBindingFactory;
+ private PolicyFactory policyFactory;
+ private InterfaceContractMapper mapper;
+
+ public void setUp() throws Exception {
+ assemblyFactory = new DefaultAssemblyFactory();
+ scaBindingFactory = new DefaultSCABindingFactory();
+ policyFactory = new DefaultPolicyFactory();
+ mapper = new InterfaceContractMapperImpl();
+ inputFactory = XMLInputFactory.newInstance();
+ staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint();
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance());
+
+ JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+ JavaClassIntrospector classIntrospector = new ExtensibleJavaClassIntrospector(new DefaultJavaClassIntrospectorExtensionPoint());
+
+ CompositeProcessor compositeProcessor = new CompositeProcessor(assemblyFactory, policyFactory, mapper, staxProcessor);
+ staxProcessors.addArtifactProcessor(compositeProcessor);
+
+ JavaImplementationProcessor javaProcessor = new JavaImplementationProcessor(assemblyFactory, policyFactory, javaImplementationFactory, classIntrospector);
+ staxProcessors.addArtifactProcessor(javaProcessor);
+ }
+
+ public void tearDown() throws Exception {
+ inputFactory = null;
+ staxProcessors = null;
+ policyFactory = null;
+ assemblyFactory = null;
+ mapper = null;
+ }
+
+ public void testReadComposite() throws Exception {
+ CompositeProcessor compositeProcessor = new CompositeProcessor(assemblyFactory, policyFactory, mapper, staxProcessor);
+ InputStream is = getClass().getResourceAsStream("Calculator.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = compositeProcessor.read(reader);
+ assertNotNull(composite);
+
+ CompositeBuilderImpl compositeUtil = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, mapper, null);
+ compositeUtil.build(composite);
+
+ }
+
+ public void testReadAndResolveComposite() throws Exception {
+ CompositeProcessor compositeProcessor = new CompositeProcessor(assemblyFactory, policyFactory, mapper, staxProcessor);
+ InputStream is = getClass().getResourceAsStream("Calculator.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = compositeProcessor.read(reader);
+ assertNotNull(composite);
+
+ ModelResolver resolver = new TestModelResolver(getClass().getClassLoader());
+ staxProcessor.resolve(composite, resolver);
+
+ CompositeBuilderImpl compositeUtil = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, mapper, null);
+ compositeUtil.build(composite);
+
+ //new PrintUtil(System.out).print(composite);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/TestModelResolver.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/TestModelResolver.java
new file mode 100644
index 0000000000..a19c7def04
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/TestModelResolver.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.java.xml;
+
+import java.lang.ref.WeakReference;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+
+/**
+ * A default implementation of an artifact resolver, based on a map.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestModelResolver implements ModelResolver {
+ private static final long serialVersionUID = -7826976465762296634L;
+
+ private Map<Object, Object> map = new HashMap<Object, Object>();
+
+ private WeakReference<ClassLoader> classLoader;
+
+ public TestModelResolver(ClassLoader classLoader) {
+ this.classLoader = new WeakReference<ClassLoader>(classLoader);
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ Object resolved = map.get(unresolved);
+ if (resolved != null) {
+
+ // Return the resolved object
+ return modelClass.cast(resolved);
+
+ } else if (unresolved instanceof ClassReference) {
+
+ // Load a class on demand
+ ClassReference classReference = (ClassReference)unresolved;
+ Class clazz;
+ try {
+ clazz = Class.forName(classReference.getClassName(), true, classLoader.get());
+ } catch (ClassNotFoundException e) {
+
+ // Return the unresolved object
+ return unresolved;
+ }
+
+ // Store a new ClassReference wrappering the loaded class
+ resolved = new ClassReference(clazz);
+ map.put(resolved, resolved);
+
+ // Return the resolved ClassReference
+ return modelClass.cast(resolved);
+
+ } else {
+
+ // Return the unresolved object
+ return unresolved;
+ }
+ }
+
+ public void addModel(Object resolved) {
+ map.put(resolved, resolved);
+ }
+
+ public Object removeModel(Object resolved) {
+ return map.remove(resolved);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java
new file mode 100644
index 0000000000..bbac819bc9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-0.90/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.java.xml;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.assembly.xml.ComponentTypeProcessor;
+import org.apache.tuscany.sca.assembly.xml.CompositeProcessor;
+import org.apache.tuscany.sca.assembly.xml.ConstrainingTypeProcessor;
+import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.introspect.DefaultJavaClassIntrospectorExtensionPoint;
+import org.apache.tuscany.sca.implementation.java.introspect.ExtensibleJavaClassIntrospector;
+import org.apache.tuscany.sca.implementation.java.introspect.JavaClassIntrospector;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
+import org.apache.tuscany.sca.policy.DefaultPolicyFactory;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+
+/**
+ * Test writing Java implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class WriteTestCase extends TestCase {
+
+ XMLInputFactory inputFactory;
+ DefaultStAXArtifactProcessorExtensionPoint staxProcessors;
+ ExtensibleStAXArtifactProcessor staxProcessor;
+ private AssemblyFactory factory;
+ private PolicyFactory policyFactory;
+ private InterfaceContractMapper mapper;
+
+ public void setUp() throws Exception {
+ factory = new DefaultAssemblyFactory();
+ policyFactory = new DefaultPolicyFactory();
+ mapper = new InterfaceContractMapperImpl();
+ inputFactory = XMLInputFactory.newInstance();
+ staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint();
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance());
+
+ JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+ JavaClassIntrospector classIntrospector = new ExtensibleJavaClassIntrospector(new DefaultJavaClassIntrospectorExtensionPoint());
+
+ staxProcessors.addArtifactProcessor(new CompositeProcessor(factory, policyFactory, mapper, staxProcessor));
+ staxProcessors.addArtifactProcessor(new ComponentTypeProcessor(factory, policyFactory, staxProcessor));
+ staxProcessors.addArtifactProcessor(new ConstrainingTypeProcessor(factory, policyFactory, staxProcessor));
+
+ JavaImplementationProcessor javaProcessor = new JavaImplementationProcessor(factory, policyFactory, javaImplementationFactory, classIntrospector);
+ staxProcessors.addArtifactProcessor(javaProcessor);
+ }
+
+ public void tearDown() throws Exception {
+ inputFactory = null;
+ staxProcessors = null;
+ policyFactory = null;
+ factory = null;
+ mapper = null;
+ }
+
+ public void testReadWriteComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("Calculator.composite");
+ Composite composite = staxProcessor.read(is, Composite.class);
+ assertNotNull(composite);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, bos);
+ }
+
+}