You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/10/30 11:18:18 UTC
svn commit: r1403653 - in /openejb/trunk/openejb/examples: ./
rest-applicationcomposer-mockito/ rest-applicationcomposer-mockito/src/
rest-applicationcomposer-mockito/src/main/
rest-applicationcomposer-mockito/src/main/java/
rest-applicationcomposer-mo...
Author: rmannibucau
Date: Tue Oct 30 10:18:16 2012
New Revision: 1403653
URL: http://svn.apache.org/viewvc?rev=1403653&view=rev
Log:
adding an example of rest service using applicatinocomposer and mockito
Added:
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/pom.xml
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/java/
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/java/org/
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/java/org/superbiz/
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/java/org/superbiz/composed/
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/java/org/superbiz/composed/rest/
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/java/org/superbiz/composed/rest/GreetingService.java
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/java/org/superbiz/composed/rest/Messager.java
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/resources/
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/resources/META-INF/
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/resources/META-INF/beans.xml
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/test/
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/test/java/
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/test/java/org/
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/test/java/org/superbiz/
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/test/java/org/superbiz/composed/
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/test/java/org/superbiz/composed/rest/
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/test/java/org/superbiz/composed/rest/GreetingServiceTest.java
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/test/resources/
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/test/resources/META-INF/
openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/test/resources/META-INF/beans.xml
Modified:
openejb/trunk/openejb/examples/pom.xml
Modified: openejb/trunk/openejb/examples/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/pom.xml?rev=1403653&r1=1403652&r2=1403653&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/pom.xml (original)
+++ openejb/trunk/openejb/examples/pom.xml Tue Oct 30 10:18:16 2012
@@ -98,6 +98,7 @@
<module>realm-in-tomee</module>
<module>reload-persistence-unit-properties</module>
<module>resources-declared-in-webapp</module>
+ <module>rest-applicationcomposer-mockito</module>
<module>rest-on-ejb</module>
<module>rest-example</module>
<module>rest-example-with-application</module>
Added: openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/pom.xml?rev=1403653&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/pom.xml (added)
+++ openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/pom.xml Tue Oct 30 10:18:16 2012
@@ -0,0 +1,110 @@
+<?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.
+-->
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.superbiz</groupId>
+ <artifactId>rest-applicationcomposer-mockito</artifactId>
+ <packaging>jar</packaging>
+ <version>1.1-SNAPSHOT</version>
+ <name>OpenEJB :: Examples :: REST, Mockito and Application Composer</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <repositories>
+ <repository>
+ <id>apache-m2-snapshot</id>
+ <name>Apache Snapshot Repository</name>
+ <url>http://repository.apache.org/snapshots</url>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>javaee-api</artifactId>
+ <version>6.0-4</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.10</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.9.0</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!--
+ The <scope>test</scope> guarantees that non of your runtime
+ code is dependent on any OpenEJB classes.
+ -->
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-core</artifactId>
+ <version>4.5.1-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-cxf-rs</artifactId>
+ <version>4.5.1-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <!--
+ This section allows you to configure where to publish libraries for sharing.
+ It is not required and may be deleted. For more information see:
+ http://maven.apache.org/plugins/maven-deploy-plugin/
+ -->
+ <distributionManagement>
+ <repository>
+ <id>localhost</id>
+ <url>file://${basedir}/target/repo/</url>
+ </repository>
+ <snapshotRepository>
+ <id>localhost</id>
+ <url>file://${basedir}/target/snapshot-repo/</url>
+ </snapshotRepository>
+ </distributionManagement>
+</project>
Added: openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/java/org/superbiz/composed/rest/GreetingService.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/java/org/superbiz/composed/rest/GreetingService.java?rev=1403653&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/java/org/superbiz/composed/rest/GreetingService.java (added)
+++ openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/java/org/superbiz/composed/rest/GreetingService.java Tue Oct 30 10:18:16 2012
@@ -0,0 +1,34 @@
+/**
+ * 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.superbiz.composed.rest;
+
+import javax.ejb.Singleton;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+@Singleton
+@Path("/greeting")
+public class GreetingService {
+ @Inject
+ private Messager messager;
+
+ @GET
+ public String message() {
+ return messager.message();
+ }
+}
Added: openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/java/org/superbiz/composed/rest/Messager.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/java/org/superbiz/composed/rest/Messager.java?rev=1403653&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/java/org/superbiz/composed/rest/Messager.java (added)
+++ openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/java/org/superbiz/composed/rest/Messager.java Tue Oct 30 10:18:16 2012
@@ -0,0 +1,21 @@
+/**
+ * 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.superbiz.composed.rest;
+
+public interface Messager {
+ String message();
+}
Added: openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/resources/META-INF/beans.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/resources/META-INF/beans.xml?rev=1403653&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/resources/META-INF/beans.xml (added)
+++ openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/main/resources/META-INF/beans.xml Tue Oct 30 10:18:16 2012
@@ -0,0 +1,19 @@
+<?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.
+-->
+<beans />
Added: openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/test/java/org/superbiz/composed/rest/GreetingServiceTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/test/java/org/superbiz/composed/rest/GreetingServiceTest.java?rev=1403653&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/test/java/org/superbiz/composed/rest/GreetingServiceTest.java (added)
+++ openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/test/java/org/superbiz/composed/rest/GreetingServiceTest.java Tue Oct 30 10:18:16 2012
@@ -0,0 +1,68 @@
+/**
+ * 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.superbiz.composed.rest;
+
+import org.apache.openejb.OpenEjbContainer;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.junit.Configuration;
+import org.apache.openejb.junit.Module;
+import org.apache.openejb.loader.IO;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import javax.enterprise.inject.Produces;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+
+@RunWith(ApplicationComposer.class)
+public class GreetingServiceTest {
+ @Mock
+ @Produces
+ public static Messager messager;
+
+ @Before
+ public void injectMocks() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Configuration
+ public Properties configuration() {
+ return new Properties() {{
+ setProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, Boolean.TRUE.toString());
+ }};
+ }
+
+ @Module
+ public Class<?>[] app() {
+ return new Class<?>[] { GreetingService.class, Messager.class };
+ }
+
+ @Test
+ public void checkMockIsUsed() throws IOException {
+ when(messager.message()).thenReturn("mockito");
+
+ final String message = IO.slurp(new URL("http://localhost:4204/GreetingServiceTest/greeting/"));
+ assertEquals("mockito", message);
+ }
+}
Added: openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/test/resources/META-INF/beans.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/test/resources/META-INF/beans.xml?rev=1403653&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/test/resources/META-INF/beans.xml (added)
+++ openejb/trunk/openejb/examples/rest-applicationcomposer-mockito/src/test/resources/META-INF/beans.xml Tue Oct 30 10:18:16 2012
@@ -0,0 +1,19 @@
+<?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.
+-->
+<beans />