cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1043458 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne: reflect/LifecycleCallbackRegistry_InheritanceTest.java testdo/testmap/annotations/Tag2.java
Date Wed, 08 Dec 2010 15:41:18 GMT
Author: aadamchik
Date: Wed Dec  8 15:41:18 2010
New Revision: 1043458

URL: http://svn.apache.org/viewvc?rev=1043458&view=rev
Log:
CAY-1509 Lifecycle event annotations support

and the unit tests

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/LifecycleCallbackRegistry_InheritanceTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/testmap/annotations/Tag2.java

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/LifecycleCallbackRegistry_InheritanceTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/LifecycleCallbackRegistry_InheritanceTest.java?rev=1043458&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/LifecycleCallbackRegistry_InheritanceTest.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/LifecycleCallbackRegistry_InheritanceTest.java
Wed Dec  8 15:41:18 2010
@@ -0,0 +1,79 @@
+/*****************************************************************
+ *   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.cayenne.reflect;
+
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.Persistent;
+import org.apache.cayenne.annotation.PostAdd;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.map.LifecycleEvent;
+import org.apache.cayenne.testdo.inheritance_flat.Group;
+import org.apache.cayenne.testdo.inheritance_flat.Role;
+import org.apache.cayenne.testdo.inheritance_flat.User;
+import org.apache.cayenne.testdo.inheritance_flat.UserProperties;
+import org.apache.cayenne.testdo.testmap.annotations.Tag2;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.INHERTITANCE_SINGLE_TABLE1_PROJECT)
+public class LifecycleCallbackRegistry_InheritanceTest extends ServerCase {
+
+    @Inject
+    private ObjectContext context;
+
+    public void testAddListener_PostAdd_EntityInheritance() {
+        LifecycleCallbackRegistry registry = new LifecycleCallbackRegistry(context
+                .getEntityResolver());
+
+        context.getEntityResolver().setCallbackRegistry(registry);
+
+        PostAddListenerInherited listener = new PostAddListenerInherited();
+        registry.addListener(listener);
+
+        assertEquals(1, registry.getHandler(LifecycleEvent.POST_ADD).listenersSize());
+
+        context.newObject(User.class);
+        assertEquals("a:User;", listener.getAndReset());
+
+        context.newObject(Group.class);
+        assertEquals("a:Group;", listener.getAndReset());
+
+        context.newObject(Role.class);
+        assertEquals("", listener.getAndReset());
+
+        context.newObject(UserProperties.class);
+        assertEquals("", listener.getAndReset());
+    }
+}
+
+class PostAddListenerInherited {
+
+    StringBuilder callbackBuffer = new StringBuilder();
+
+    @PostAdd(entityAnnotations = Tag2.class)
+    void postAddAnnotated(Persistent object) {
+        callbackBuffer.append("a:" + object.getObjectId().getEntityName() + ";");
+    }
+
+    String getAndReset() {
+        String v = callbackBuffer.toString();
+        callbackBuffer = new StringBuilder();
+        return v;
+    }
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/testmap/annotations/Tag2.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/testmap/annotations/Tag2.java?rev=1043458&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/testmap/annotations/Tag2.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/testmap/annotations/Tag2.java
Wed Dec  8 15:41:18 2010
@@ -0,0 +1,32 @@
+/*****************************************************************
+ *   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.cayenne.testdo.testmap.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+public @interface Tag2 {
+
+}



Mime
View raw message