You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2011/07/29 19:41:29 UTC
svn commit: r1152319 - in /tapestry/tapestry5/trunk/plastic/src/test:
groovy/org/apache/tapestry5/plastic/ java/testannotations/
java/testinterfaces/ java/testsubjects/
Author: hlship
Date: Fri Jul 29 17:41:27 2011
New Revision: 1152319
URL: http://svn.apache.org/viewvc?rev=1152319&view=rev
Log:
Add some tests to plastic to check for base class and subclass both injecting same value into same name private field
Added:
tapestry/tapestry5/trunk/plastic/src/test/java/testannotations/KindaInject.java
tapestry/tapestry5/trunk/plastic/src/test/java/testinterfaces/Logger.java
tapestry/tapestry5/trunk/plastic/src/test/java/testsubjects/InjectBaseClass.java
tapestry/tapestry5/trunk/plastic/src/test/java/testsubjects/InjectSubClass.java
Modified:
tapestry/tapestry5/trunk/plastic/src/test/groovy/org/apache/tapestry5/plastic/FieldConduitTests.groovy
tapestry/tapestry5/trunk/plastic/src/test/groovy/org/apache/tapestry5/plastic/FieldInjection.groovy
Modified: tapestry/tapestry5/trunk/plastic/src/test/groovy/org/apache/tapestry5/plastic/FieldConduitTests.groovy
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/plastic/src/test/groovy/org/apache/tapestry5/plastic/FieldConduitTests.groovy?rev=1152319&r1=1152318&r2=1152319&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/plastic/src/test/groovy/org/apache/tapestry5/plastic/FieldConduitTests.groovy (original)
+++ tapestry/tapestry5/trunk/plastic/src/test/groovy/org/apache/tapestry5/plastic/FieldConduitTests.groovy Fri Jul 29 17:41:27 2011
@@ -14,9 +14,13 @@
package org.apache.tapestry5.plastic
+import testannotations.KindaInject
+import testinterfaces.Logger
+
class FieldConduitTests extends AbstractPlasticSpecification
{
- def "setting a field invokes the conduit"() {
+ def "setting a field invokes the conduit"()
+ {
FieldConduit fc = Mock()
@@ -49,7 +53,8 @@ class FieldConduitTests extends Abstract
o.@value == 0
}
- def "use of computed conduit"() {
+ def "use of computed conduit"()
+ {
FieldConduit fc = Mock()
def pc = mgr.getPlasticClass("testsubjects.IntFieldHolder")
@@ -67,7 +72,8 @@ class FieldConduitTests extends Abstract
1 * fc.set(_, _, 456)
}
- def "field initializations are visible to the conduit"() {
+ def "field initializations are visible to the conduit"()
+ {
FieldConduit fc = Mock()
def pc = mgr.getPlasticClass("testsubjects.LongFieldHolder")
@@ -90,16 +96,17 @@ class FieldConduitTests extends Abstract
* synthetic static methods (package private visibility). This ensures that those methods are
* also subject to field access transformations.
*/
- def "inner class access methods are routed through field conduit"() {
+ def "inner class access methods are routed through field conduit"()
+ {
FieldConduit fc = Mock()
def mgr = PlasticManager.withContextClassLoader().delegate(
[
- transform: { PlasticClass pc ->
- pc.allFields.first().setConduit(fc)
- },
- configureInstantiator: { className, instantiator -> instantiator }
+ transform: { PlasticClass pc ->
+ pc.allFields.first().setConduit(fc)
+ },
+ configureInstantiator: { className, instantiator -> instantiator }
] as PlasticManagerDelegate).packages(["testsubjects"]).create()
@@ -124,7 +131,8 @@ class FieldConduitTests extends Abstract
1 * fc.get(o, _) >> "plastic"
}
- def "verify writebehind on normal field"() {
+ def "verify writebehind on normal field"()
+ {
FieldConduit fc = Mock()
def mgr = PlasticManager.withContextClassLoader().enable(TransformationOption.FIELD_WRITEBEHIND).create()
@@ -157,8 +165,9 @@ class FieldConduitTests extends Abstract
o.m_value == 1097
}
-
- def "verify writebehind on wide field"() {
+
+ def "verify writebehind on wide field"()
+ {
FieldConduit fc = Mock()
def mgr = PlasticManager.withContextClassLoader().enable(TransformationOption.FIELD_WRITEBEHIND).create()
@@ -191,4 +200,42 @@ class FieldConduitTests extends Abstract
o.m_value == 987654321L
}
+
+ def "ensure same field name and conduit is not a conflict between base class and sub class"()
+ {
+ def logger = Mock(Logger)
+
+ FieldConduit conduit = Mock(FieldConduit)
+ PlasticClassTransformer transformer = { PlasticClass pc ->
+ pc.getFieldsWithAnnotation(KindaInject.class).each({
+ PlasticField field -> field.setConduit(conduit)
+ })
+ } as PlasticClassTransformer
+
+ when:
+
+ def mgr = createMgr(transformer);
+ mgr.addPlasticClassListener({ PlasticClassEvent event ->
+
+ print(event.getDissasembledBytecode())
+
+ } as PlasticClassListener)
+
+ def o = mgr.getClassInstantiator("testsubjects.InjectSubClass").newInstance()
+
+ assert o.subClassLogger == logger
+
+ then:
+
+ 1 * conduit.get(_, _) >> logger
+
+ when:
+
+ assert o.baseClassLogger == logger
+
+ then:
+
+ 1 * conduit.get(_, _) >> logger
+ }
+
}
Modified: tapestry/tapestry5/trunk/plastic/src/test/groovy/org/apache/tapestry5/plastic/FieldInjection.groovy
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/plastic/src/test/groovy/org/apache/tapestry5/plastic/FieldInjection.groovy?rev=1152319&r1=1152318&r2=1152319&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/plastic/src/test/groovy/org/apache/tapestry5/plastic/FieldInjection.groovy (original)
+++ tapestry/tapestry5/trunk/plastic/src/test/groovy/org/apache/tapestry5/plastic/FieldInjection.groovy Fri Jul 29 17:41:27 2011
@@ -14,11 +14,14 @@
package org.apache.tapestry5.plastic
+import java.util.logging.Logger
+import testannotations.KindaInject
import testsubjects.StringPropertyHolder
class FieldInjection extends AbstractPlasticSpecification
{
- def "injection of a reference value"() {
+ def "injection of a reference value"()
+ {
String injected = "Value injected into the Empty class"
def pc = mgr.getPlasticClass("testsubjects.Empty")
@@ -29,13 +32,14 @@ class FieldInjection extends AbstractPla
def ins = pc.createInstantiator()
- def o = ins.newInstance()
+ def o = ins.newInstance()
expect:
o.stringValue.is(injected)
}
- def "computed injection"() {
+ def "computed injection"()
+ {
def instanceType
@@ -57,7 +61,7 @@ class FieldInjection extends AbstractPla
o.value.is(injected)
instanceType.is(o.getClass())
- ! instanceType.is(StringPropertyHolder.class) // it's a new class with the same name
+ !instanceType.is(StringPropertyHolder.class) // it's a new class with the same name
when:
o.value = "attempt to update"
@@ -66,7 +70,8 @@ class FieldInjection extends AbstractPla
thrown(IllegalStateException)
}
- def "injection from instance context"() {
+ def "injection from instance context"()
+ {
String injected = "InstanceContext value injected into the StringPropertyHolder class"
@@ -87,7 +92,8 @@ class FieldInjection extends AbstractPla
thrown(IllegalStateException)
}
- def "injection of primitive value"() {
+ def "injection of primitive value"()
+ {
def pc = mgr.getPlasticClass("testsubjects.Empty")
@@ -97,14 +103,15 @@ class FieldInjection extends AbstractPla
def ins = pc.createInstantiator()
- def o = ins.newInstance()
+ def o = ins.newInstance()
expect:
o.pi == Math.PI
}
- def "injected field is read-only"() {
+ def "injected field is read-only"()
+ {
def pc = mgr.getPlasticClass("testsubjects.InjectFieldSubject")
@@ -135,7 +142,8 @@ class FieldInjection extends AbstractPla
thrown(IllegalStateException)
}
- def "injected field is read-only, even via handle"() {
+ def "injected field is read-only, even via handle"()
+ {
def pc = mgr.getPlasticClass("testsubjects.InjectFieldSubject")
def f = pc.allFields.first();
def h = f.handle
@@ -156,7 +164,8 @@ class FieldInjection extends AbstractPla
e.message == "Field value of class testsubjects.InjectFieldSubject is read-only."
}
- def "a field may only be injected once"() {
+ def "a field may only be injected once"()
+ {
def pc = mgr.getPlasticClass("testsubjects.StringHolder")
def f = pc.allFields.first();
@@ -172,4 +181,6 @@ class FieldInjection extends AbstractPla
e.message == "Unable to inject a value into field value of class testsubjects.StringHolder, as it already has an injection."
}
+
+
}
Added: tapestry/tapestry5/trunk/plastic/src/test/java/testannotations/KindaInject.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/plastic/src/test/java/testannotations/KindaInject.java?rev=1152319&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/plastic/src/test/java/testannotations/KindaInject.java (added)
+++ tapestry/tapestry5/trunk/plastic/src/test/java/testannotations/KindaInject.java Fri Jul 29 17:41:27 2011
@@ -0,0 +1,16 @@
+package testannotations;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.FIELD;
+
+/**
+ * Used to test {code @Inject}-like behavior.
+ */
+@Target(FIELD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface KindaInject
+{
+}
Added: tapestry/tapestry5/trunk/plastic/src/test/java/testinterfaces/Logger.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/plastic/src/test/java/testinterfaces/Logger.java?rev=1152319&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/plastic/src/test/java/testinterfaces/Logger.java (added)
+++ tapestry/tapestry5/trunk/plastic/src/test/java/testinterfaces/Logger.java Fri Jul 29 17:41:27 2011
@@ -0,0 +1,8 @@
+package testinterfaces;
+
+/**
+ * Used for testing of injection & field conduits
+ */
+public interface Logger
+{
+}
Added: tapestry/tapestry5/trunk/plastic/src/test/java/testsubjects/InjectBaseClass.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/plastic/src/test/java/testsubjects/InjectBaseClass.java?rev=1152319&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/plastic/src/test/java/testsubjects/InjectBaseClass.java (added)
+++ tapestry/tapestry5/trunk/plastic/src/test/java/testsubjects/InjectBaseClass.java Fri Jul 29 17:41:27 2011
@@ -0,0 +1,13 @@
+package testsubjects;
+
+import testannotations.KindaInject;
+import testinterfaces.Logger;
+
+
+public class InjectBaseClass
+{
+ @KindaInject
+ private Logger logger;
+
+ public Logger getBaseClassLogger() { return logger; }
+}
Added: tapestry/tapestry5/trunk/plastic/src/test/java/testsubjects/InjectSubClass.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/plastic/src/test/java/testsubjects/InjectSubClass.java?rev=1152319&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/plastic/src/test/java/testsubjects/InjectSubClass.java (added)
+++ tapestry/tapestry5/trunk/plastic/src/test/java/testsubjects/InjectSubClass.java Fri Jul 29 17:41:27 2011
@@ -0,0 +1,18 @@
+package testsubjects;
+
+import testannotations.KindaInject;
+import testinterfaces.Logger;
+
+/**
+ *
+ */
+public class InjectSubClass extends InjectBaseClass
+{
+ @KindaInject
+ private Logger logger;
+
+ public Logger getSubClassLogger()
+ {
+ return logger;
+ }
+}