summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/implementation-java/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'java/sca/modules/implementation-java/src/test')
-rw-r--r--java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessorTestCase.java195
-rw-r--r--java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessorTestCase.java169
2 files changed, 184 insertions, 180 deletions
diff --git a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessorTestCase.java b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessorTestCase.java
index 1a8da7f1b3..6922f00afb 100644
--- a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessorTestCase.java
+++ b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessorTestCase.java
@@ -46,6 +46,13 @@ public class PropertyProcessorTestCase {
JavaImplementation type;
PropertyProcessor processor;
+ @Before
+ public void setUp() throws Exception {
+ JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+ type = javaImplementationFactory.createJavaImplementation();
+ processor = new PropertyProcessor(new DefaultAssemblyFactory());
+ }
+
@Test
public void testMethodAnnotation() throws Exception {
processor.visitMethod(Foo.class.getMethod("setFoo", String.class), type);
@@ -118,102 +125,6 @@ public class PropertyProcessorTestCase {
}
}
- @Before
- public void setUp() throws Exception {
- 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 setDupMethod(String s) {
- }
-
- @Property(name = "dupMethod")
- public void setDupSomeMethod(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 static class BadMethodProps {
-
- @org.oasisopen.sca.annotation.Constructor()
- public BadMethodProps(@Property(name = "myProp", required = true)String prop) {
-
- }
-
- /** Java can't tell that the @reference argument is disallowed by SCA, but the run time must reject it*/
- public void BadMethod(@Property(name = "badMethodArgProp")String methArg)
- {}
-
-
- }
-
- private static class BadStaticProps {
-
- @Property(name="badstaticfield")static int stint;
-
- @Property(name="badstaticfield")static void setStint(int theStint) {
- stint = theStint;
- }
- }
-
- private Class<?> getBaseType(JavaElementImpl element) {
- return JavaIntrospectionHelper.getBaseType(element.getType(), element.getGenericType());
- }
-
@Test
public void testMultiplicityCollection() throws Exception {
processor.visitField(Multiple.class.getDeclaredField("refs1"), type);
@@ -299,4 +210,96 @@ public class PropertyProcessorTestCase {
}
+ /**
+ * Private classes utilized in the tests
+ */
+
+ 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 setDupMethod(String s) {
+ }
+
+ @Property(name = "dupMethod")
+ public void setDupSomeMethod(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 static class BadMethodProps {
+
+ @org.oasisopen.sca.annotation.Constructor()
+ public BadMethodProps(@Property(name = "myProp", required = true)String prop) {
+
+ }
+
+ /** Java can't tell that the @reference argument is disallowed by SCA, but the run time must reject it*/
+ public void BadMethod(@Property(name = "badMethodArgProp")String methArg) {
+
+ }
+ }
+
+ private static class BadStaticProps {
+
+ @Property(name="badstaticfield")static int stint;
+
+ @Property(name="badstaticfield")static void setStint(int theStint) {
+ stint = theStint;
+ }
+ }
+
+ private Class<?> getBaseType(JavaElementImpl element) {
+ return JavaIntrospectionHelper.getBaseType(element.getType(), element.getGenericType());
+ }
+
}
diff --git a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessorTestCase.java b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessorTestCase.java
index 8e49674b7e..cb470e37fa 100644
--- a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessorTestCase.java
+++ b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessorTestCase.java
@@ -48,6 +48,13 @@ public class ReferenceProcessorTestCase {
private JavaImplementation type;
private ReferenceProcessor processor;
+ @Before
+ public void setUp() throws Exception {
+ JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+ type = javaImplementationFactory.createJavaImplementation();
+ processor = new ReferenceProcessor(new DefaultAssemblyFactory(), new DefaultJavaInterfaceFactory());
+ }
+
@Test
public void testMethodAnnotation() throws Exception {
processor.visitMethod(ReferenceProcessorTestCase.Foo.class.getMethod("setFoo", Ref.class), type);
@@ -142,22 +149,91 @@ public class ReferenceProcessorTestCase {
}
}
- @Before
- public void setUp() throws Exception {
- JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
- type = javaImplementationFactory.createJavaImplementation();
- processor = new ReferenceProcessor(new DefaultAssemblyFactory(), new DefaultJavaInterfaceFactory());
+ @Test
+ 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());
+ }
+
+ @Test
+ 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());
+ }
+
+ @Test
+ 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());
+ }
+
+ @Test
+ 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());
}
+
+ @Test
+ public void testRejectStaticFieldReference() throws Exception {
+ try {
+ processor.visitField(BadStaticRefs.class.getDeclaredField("stint"), type);
+ fail("Processor should not accept a static field with Property annotation");
+ }
+ catch (IllegalReferenceException e) {
+ // System.out.println("Caught expected exception");
+ }
+ catch (Exception e) {
+ fail("Wrong exception detected");
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testRejectStaticMethodReference() throws Exception {
+ try {
+ processor.visitMethod(BadStaticRefs.class.getDeclaredMethod("setStint",int.class), type);
+ fail("Processor should not accept a static method with Property annotation");
+ }
+ catch (IllegalPropertyException e) {
+ // System.out.println("Caught expected exception");
+ }
+ catch (Exception e) {
+ fail("Wrong exception detected");
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ * Private classes utilized in the tests
+ */
private interface Ref {
}
private class Foo {
-
@Reference
protected Ref baz;
+
@Reference(required = true)
protected Ref bazRequired;
+
@Reference(name = "theBaz")
protected Ref bazField;
@@ -172,11 +248,9 @@ public class ReferenceProcessorTestCase {
@Reference(name = "bar")
public void setBarMethod(Ref ref) {
}
-
}
private class Bar {
-
@Reference
protected Ref dup;
@@ -211,7 +285,6 @@ public class ReferenceProcessorTestCase {
@Reference(required = false)
public void setRefs4(Collection<Ref> refs) {
}
-
}
private static class BadStaticRefs {
@@ -232,80 +305,8 @@ public class ReferenceProcessorTestCase {
}
/** Java can't tell that the @reference argument is disallowed by SCA, but the run time must reject it*/
- public void BadMethod(@Reference(name = "badMethodArgRef")String methArg)
- {}
-
- }
-
- @Test
- 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());
- }
-
- @Test
- 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());
- }
-
- @Test
- 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());
- }
-
- @Test
- 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());
- }
-
- @Test
- public void testRejectStaticFieldReference() throws Exception {
- try {
- processor.visitField(BadStaticRefs.class.getDeclaredField("stint"), type);
- fail("Processor should not accept a static field with Property annotation");
- }
- catch (IllegalReferenceException e) {
- // System.out.println("Caught expected exception");
- }
- catch (Exception e) {
- fail("Wrong exception detected");
- e.printStackTrace();
- }
- }
-
- @Test
- public void testRejectStaticMethodReference() throws Exception {
- try {
- processor.visitMethod(BadStaticRefs.class.getDeclaredMethod("setStint",int.class), type);
- fail("Processor should not accept a static method with Property annotation");
- }
- catch (IllegalPropertyException e) {
- // System.out.println("Caught expected exception");
- }
- catch (Exception e) {
- fail("Wrong exception detected");
- e.printStackTrace();
- }
-
+ public void BadMethod(@Reference(name = "badMethodArgRef")String methArg) {
+
+ }
}
-
}