You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2014/01/08 14:14:19 UTC

[2/2] git commit: [OLINGO-111] Added additional tests for ClassHelper

[OLINGO-111] Added additional tests for ClassHelper


Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/e4ebe867
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/e4ebe867
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/e4ebe867

Branch: refs/heads/master
Commit: e4ebe8677bf1eaa08c814580c14f971a1650ceee
Parents: 48d53ea
Author: Michael Bolz <mi...@apache.org>
Authored: Wed Jan 8 13:53:16 2014 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Wed Jan 8 14:00:20 2014 +0100

----------------------------------------------------------------------
 .../annotation-processor-core/pom.xml           |  32 +--
 .../processor/core/util/ClassHelperTest.java    | 101 ++++++++++
 odata2-lib/odata-testutil/pom.xml               | 199 +++++++++----------
 .../odata2/testutil/mock/AnnotatedEntity.java   |  26 +++
 4 files changed, 244 insertions(+), 114 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e4ebe867/odata2-annotation-processor/annotation-processor-core/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/pom.xml b/odata2-annotation-processor/annotation-processor-core/pom.xml
index 4732522..b5246ec 100644
--- a/odata2-annotation-processor/annotation-processor-core/pom.xml
+++ b/odata2-annotation-processor/annotation-processor-core/pom.xml
@@ -1,13 +1,16 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- 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. -->
+<!-- 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. -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
 
   <artifactId>olingo-odata2-annotation-processor-core-incubating</artifactId>
@@ -29,12 +32,12 @@ the License. -->
     </dependency>
     <dependency>
       <groupId>org.apache.olingo</groupId>
-      <artifactId>olingo-odata2-api-incubating</artifactId>
+      <artifactId>olingo-odata2-api-annotation-incubating</artifactId>
       <version>${project.version}</version>
     </dependency>
     <dependency>
       <groupId>org.apache.olingo</groupId>
-      <artifactId>olingo-odata2-api-annotation-incubating</artifactId>
+      <artifactId>olingo-odata2-api-incubating</artifactId>
       <version>${project.version}</version>
     </dependency>
     <dependency>
@@ -42,7 +45,12 @@ the License. -->
       <artifactId>olingo-odata2-core-incubating</artifactId>
       <version>${project.version}</version>
     </dependency>
+    <!-- Test dependencies -->
+    <dependency>
+      <groupId>org.apache.olingo</groupId>
+      <artifactId>olingo-odata2-testutil-incubating</artifactId>
+      <version>${project.version}</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
-  
-
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e4ebe867/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/util/ClassHelperTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/util/ClassHelperTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/util/ClassHelperTest.java
new file mode 100644
index 0000000..0e7c406
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/util/ClassHelperTest.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ * 
+ * Licensed 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.olingo.odata2.annotation.processor.core.util;
+
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.apache.olingo.odata2.annotation.processor.core.util.ClassHelper.ClassValidator;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.testutil.mock.AnnotatedEntity;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class ClassHelperTest {
+
+  private final ClassValidator annotatedTestEntityInnerClasses = new ClassValidator() {
+    @Override
+    public boolean isClassValid(Class<?> c) {
+      return c.isAnnotationPresent(EdmEntityType.class)
+          && c.getName().contains(ClassHelperTest.class.getSimpleName());
+    }
+  };
+
+  private final ClassValidator annotatedEntityClasses = new ClassValidator() {
+    @Override
+    public boolean isClassValid(Class<?> c) {
+      return c.isAnnotationPresent(EdmEntityType.class);
+    }
+  };
+
+  @Test
+  public void loadSingleEntity() throws ODataException {
+    String packageToScan = ClassHelperTest.class.getPackage().getName();
+
+    //
+    List<Class<?>> loadedClasses = ClassHelper.loadClasses(packageToScan, annotatedTestEntityInnerClasses);
+
+    //
+    Assert.assertEquals(1, loadedClasses.size());
+    Assert.assertEquals(SimpleEntity.class.getName(), loadedClasses.get(0).getName());
+  }
+  
+  @Test
+  public void loadSingleEntityFromJar() throws ODataException {
+    String packageToScan = AnnotatedEntity.class.getPackage().getName();
+
+    //
+    List<Class<?>> loadedClasses = ClassHelper.loadClasses(packageToScan, annotatedEntityClasses);
+
+    //
+    Assert.assertEquals(1, loadedClasses.size());
+    Assert.assertEquals(AnnotatedEntity.class.getName(), loadedClasses.get(0).getName());
+  }
+
+
+  //
+  // The below classes are 'unused' within the code but must be declared for loading via
+  // the 'ClassHelper'
+  //
+
+  @EdmEntityType
+  @SuppressWarnings("unused")
+  private class SimpleEntity {
+    @EdmKey
+    @EdmProperty
+    Long id;
+    @EdmProperty
+    String name;
+
+    public SimpleEntity() {}
+
+    public SimpleEntity(Long id, String name) {
+      this.id = id;
+      this.name = name;
+    }
+  }
+
+  @SuppressWarnings("unused")
+  private class NotAnnotatedBean {
+    private String name;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e4ebe867/odata2-lib/odata-testutil/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-testutil/pom.xml b/odata2-lib/odata-testutil/pom.xml
index 6c93d3f..81c3a15 100644
--- a/odata2-lib/odata-testutil/pom.xml
+++ b/odata2-lib/odata-testutil/pom.xml
@@ -1,110 +1,105 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
-  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.
--->
+<!-- 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. -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-	<modelVersion>4.0.0</modelVersion>
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
 
-	<artifactId>olingo-odata2-testutil-incubating</artifactId>
-	<packaging>jar</packaging>
-	<name>${project.artifactId}</name>
+  <artifactId>olingo-odata2-testutil-incubating</artifactId>
+  <packaging>jar</packaging>
+  <name>${project.artifactId}</name>
 
-	<parent>
-		<groupId>org.apache.olingo</groupId>
-		<artifactId>olingo-odata2-lib-incubating</artifactId>
-		<version>1.1.0-SNAPSHOT</version>
-		<relativePath>..</relativePath>
-	</parent>
+  <parent>
+    <groupId>org.apache.olingo</groupId>
+    <artifactId>olingo-odata2-lib-incubating</artifactId>
+    <version>1.1.0-SNAPSHOT</version>
+    <relativePath>..</relativePath>
+  </parent>
 
-	<build>
-		<plugins>
-			<plugin>
-				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-deploy-plugin</artifactId>
-				<configuration>
-					<skip>true</skip>
-				</configuration>
-			</plugin>
-		</plugins>
-	</build>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-deploy-plugin</artifactId>
+        <configuration>
+          <skip>true</skip>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
 
-	<profiles>
-		<profile>
-			<id>coverage</id>
-			<activation>
-				<property>
-					<name>ldi.parent.emma-coverage</name>
-				</property>
-			</activation>
-			<properties>
-				<coverage.report.excludeFromCoverageDataCreation>true</coverage.report.excludeFromCoverageDataCreation>
-			</properties>
-		</profile>
-	</profiles>
-
-	<dependencies>
-		<dependency>
-			<groupId>org.apache.olingo</groupId>
-			<artifactId>olingo-odata2-api-incubating</artifactId>
-			<version>${project.version}</version>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.cxf</groupId>
-			<artifactId>cxf-rt-frontend-jaxrs</artifactId>
-			<version>${cxf.version}</version>
-		</dependency>
-		<dependency>
-			<groupId>org.slf4j</groupId>
-			<artifactId>slf4j-api</artifactId>
-			<version>${slf4j.version}</version>
-		</dependency>
-		<dependency>
-			<groupId>org.slf4j</groupId>
-			<artifactId>slf4j-log4j12</artifactId>
-			<version>${slf4j.version}</version>
-		</dependency>
-		<dependency>
-			<groupId>junit</groupId>
-			<artifactId>junit</artifactId>
-			<version>${junit.version}</version>
-		</dependency>
-		<dependency>
-			<groupId>org.mockito</groupId>
-			<artifactId>mockito-all</artifactId>
-			<version>${mockito.version}</version>
-		</dependency>
-		<dependency>
-			<groupId>org.eclipse.jetty</groupId>
-			<artifactId>jetty-servlet</artifactId>
-			<version>${jetty.version}</version>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.httpcomponents</groupId>
-			<artifactId>httpclient</artifactId>
-			<version>${httpclient.version}</version>
-		</dependency>
-		<dependency>
-			<groupId>xmlunit</groupId>
-			<artifactId>xmlunit</artifactId>
-			<version>${xmlunit.version}</version>
-		</dependency>
-
-	</dependencies>
+  <profiles>
+    <profile>
+      <id>coverage</id>
+      <activation>
+        <property>
+          <name>ldi.parent.emma-coverage</name>
+        </property>
+      </activation>
+      <properties>
+        <coverage.report.excludeFromCoverageDataCreation>true</coverage.report.excludeFromCoverageDataCreation>
+      </properties>
+    </profile>
+  </profiles>
 
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.olingo</groupId>
+      <artifactId>olingo-odata2-api-incubating</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.olingo</groupId>
+      <artifactId>olingo-odata2-api-annotation-incubating</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cxf</groupId>
+      <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+      <version>${cxf.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>${slf4j.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <version>${slf4j.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>${junit.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-all</artifactId>
+      <version>${mockito.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.eclipse.jetty</groupId>
+      <artifactId>jetty-servlet</artifactId>
+      <version>${jetty.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpclient</artifactId>
+      <version>${httpclient.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>xmlunit</groupId>
+      <artifactId>xmlunit</artifactId>
+      <version>${xmlunit.version}</version>
+    </dependency>
+  </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e4ebe867/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/mock/AnnotatedEntity.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/mock/AnnotatedEntity.java b/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/mock/AnnotatedEntity.java
new file mode 100644
index 0000000..f36b8c8
--- /dev/null
+++ b/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/mock/AnnotatedEntity.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * 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.olingo.odata2.testutil.mock;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+
+@EdmEntityType
+public class AnnotatedEntity {
+
+}