aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1718643 - in /aries/trunk/jpa/jpa-blueprint/src: main/java/org/apache/aries/jpa/blueprint/impl/ test/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/aries/ test/java/org/apache/aries/jpa/ test/java/org/apache/aries/jp...
Date Tue, 08 Dec 2015 16:31:12 GMT
Author: cschneider
Date: Tue Dec  8 16:31:12 2015
New Revision: 1718643

URL: http://svn.apache.org/viewvc?rev=1718643&view=rev
Log:
Add unit tests for AnnoationScanner

Added:
    aries/trunk/jpa/jpa-blueprint/src/test/
    aries/trunk/jpa/jpa-blueprint/src/test/java/
    aries/trunk/jpa/jpa-blueprint/src/test/java/org/
    aries/trunk/jpa/jpa-blueprint/src/test/java/org/apache/
    aries/trunk/jpa/jpa-blueprint/src/test/java/org/apache/aries/
    aries/trunk/jpa/jpa-blueprint/src/test/java/org/apache/aries/jpa/
    aries/trunk/jpa/jpa-blueprint/src/test/java/org/apache/aries/jpa/blueprint/
    aries/trunk/jpa/jpa-blueprint/src/test/java/org/apache/aries/jpa/blueprint/impl/
    aries/trunk/jpa/jpa-blueprint/src/test/java/org/apache/aries/jpa/blueprint/impl/AnnotationScannerTest.java
    aries/trunk/jpa/jpa-blueprint/src/test/java/org/apache/aries/jpa/blueprint/impl/TestClass.java
Modified:
    aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/AnnotationScanner.java

Modified: aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/AnnotationScanner.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/AnnotationScanner.java?rev=1718643&r1=1718642&r2=1718643&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/AnnotationScanner.java
(original)
+++ aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/AnnotationScanner.java
Tue Dec  8 16:31:12 2015
@@ -59,10 +59,14 @@ public class AnnotationScanner {
             if (!name.startsWith("set")) {
                 return null;
             }
-            return name. substring(3, 4).toLowerCase() + name.substring(4);
+            return lowerCamelCase(name.substring(3));
         }
         throw new IllegalArgumentException();
     }
+
+    private static String lowerCamelCase(String name) {
+        return name.substring(0, 1).toLowerCase() + name.substring(1);
+    }
     
     public static Class<?> getType(AccessibleObject member) {
         if (member instanceof Field) {

Added: aries/trunk/jpa/jpa-blueprint/src/test/java/org/apache/aries/jpa/blueprint/impl/AnnotationScannerTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-blueprint/src/test/java/org/apache/aries/jpa/blueprint/impl/AnnotationScannerTest.java?rev=1718643&view=auto
==============================================================================
--- aries/trunk/jpa/jpa-blueprint/src/test/java/org/apache/aries/jpa/blueprint/impl/AnnotationScannerTest.java
(added)
+++ aries/trunk/jpa/jpa-blueprint/src/test/java/org/apache/aries/jpa/blueprint/impl/AnnotationScannerTest.java
Tue Dec  8 16:31:12 2015
@@ -0,0 +1,91 @@
+
+/*
+ * 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.aries.jpa.blueprint.impl;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceUnit;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+
+public class AnnotationScannerTest {
+    
+    private Method setEmMethod;
+    private Field emField;
+    private Method setEmfMethod;
+    private Field emfField;
+
+    public AnnotationScannerTest() throws NoSuchMethodException, SecurityException, NoSuchFieldException
{
+        setEmMethod = TestClass.class.getMethod("setEm", new Class<?>[] {EntityManager.class});
+        emField = TestClass.class.getDeclaredField("em");
+        setEmfMethod = TestClass.class.getMethod("setEmf", new Class<?>[] {EntityManagerFactory.class});
+        emfField = TestClass.class.getDeclaredField("emf");
+    }
+
+    @Test
+    public void getNameTest() throws NoSuchMethodException, SecurityException, NoSuchFieldException
{
+        Assert.assertEquals("em", AnnotationScanner.getName(setEmMethod));
+        Assert.assertEquals("em", AnnotationScanner.getName(emField));
+        Assert.assertEquals("emf", AnnotationScanner.getName(setEmfMethod));
+        Assert.assertEquals("emf", AnnotationScanner.getName(emfField));
+
+    }
+
+    @Test
+    public void getTypeTest() {
+        Assert.assertEquals(EntityManager.class, AnnotationScanner.getType(setEmMethod));
+        Assert.assertEquals(EntityManager.class, AnnotationScanner.getType(emField));
+        Assert.assertEquals(EntityManagerFactory.class, AnnotationScanner.getType(setEmfMethod));
+        Assert.assertEquals(EntityManagerFactory.class, AnnotationScanner.getType(emfField));
+
+    }
+    
+    @Test
+    public void getPCAnnotatedMembersTest() {
+        AnnotationScanner scanner = new AnnotationScanner();
+        List<AccessibleObject> members = scanner.getJpaAnnotatedMembers(TestClass.class,
PersistenceContext.class);
+        Assert.assertEquals(1, members.size());
+        AccessibleObject member = members.get(0);
+        Assert.assertEquals(Field.class, member.getClass());
+        Field field = (Field)member;
+        Assert.assertEquals("em", field.getName());
+    }
+
+    @Test
+    public void getPUAnnotatedMembersTest() {
+        AnnotationScanner scanner = new AnnotationScanner();
+        List<AccessibleObject> members = scanner.getJpaAnnotatedMembers(TestClass.class,
PersistenceUnit.class);
+        Assert.assertEquals(1, members.size());
+        AccessibleObject member = members.get(0);
+        Assert.assertEquals(Method.class, member.getClass());
+        Method method = (Method)member;
+        Assert.assertEquals("setEmf", method.getName());
+    }
+
+    
+}

Added: aries/trunk/jpa/jpa-blueprint/src/test/java/org/apache/aries/jpa/blueprint/impl/TestClass.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-blueprint/src/test/java/org/apache/aries/jpa/blueprint/impl/TestClass.java?rev=1718643&view=auto
==============================================================================
--- aries/trunk/jpa/jpa-blueprint/src/test/java/org/apache/aries/jpa/blueprint/impl/TestClass.java
(added)
+++ aries/trunk/jpa/jpa-blueprint/src/test/java/org/apache/aries/jpa/blueprint/impl/TestClass.java
Tue Dec  8 16:31:12 2015
@@ -0,0 +1,41 @@
+/*
+ * 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.aries.jpa.blueprint.impl;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceUnit;
+
+public class TestClass {
+
+    @PersistenceContext(unitName="test")
+    EntityManager em;
+    
+    public void setEm(EntityManager em) {
+        this.em = em;
+    }
+    
+    EntityManagerFactory emf;
+    
+    @PersistenceUnit(unitName="test2")
+    public void setEmf(EntityManagerFactory emf) {
+        this.emf = emf;
+    }
+}



Mime
View raw message