diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-09-25 23:32:39 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-09-25 23:32:39 +0000 |
commit | 64343a678723bfe88024d10e5eb18e13e54d1405 (patch) | |
tree | 81f5f50efb493a0424ce8509f2c01ffe1bb04552 /java/sca/modules/implementation-java/src/test | |
parent | 9857eae38c74128f07b61e31327ea0af50fab2e5 (diff) |
Minor testcase re-formatting
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@819062 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/implementation-java/src/test')
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) { + + } } - } |