- Integrate arquillian - first test case for JavaArchive - container: Weld EE embedded - MS: JEE-Testapp-01
Hafid Haddouti

Hafid Haddouti commited on 2014-04-26 19:46:52
Zeige 8 geänderte Dateien mit 195 Einfügungen und 6 Löschungen.


Change-Id: I1eeaf9ee11f471d5a32a2c195210b426ac087020
... ...
@@ -21,12 +21,12 @@
21 21
 			</arguments>
22 22
 		</buildCommand>
23 23
 		<buildCommand>
24
-			<name>org.eclipse.m2e.core.maven2Builder</name>
24
+			<name>org.eclipse.wst.validation.validationbuilder</name>
25 25
 			<arguments>
26 26
 			</arguments>
27 27
 		</buildCommand>
28 28
 		<buildCommand>
29
-			<name>org.eclipse.wst.validation.validationbuilder</name>
29
+			<name>org.eclipse.m2e.core.maven2Builder</name>
30 30
 			<arguments>
31 31
 			</arguments>
32 32
 		</buildCommand>
... ...
@@ -1,3 +1,4 @@
1 1
 eclipse.preferences.version=1
2 2
 encoding//src/main/java=UTF-8
3
+encoding//src/test/java=UTF-8
3 4
 encoding/<project>=UTF-8
... ...
@@ -12,16 +12,29 @@
12 12
 	<properties>
13 13
 		<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
14 14
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15
+
16
+		<version.junit>4.8.1</version.junit>
17
+		<version.arquillian>1.1.4.Final</version.arquillian>
15 18
 	</properties>
16 19
 
20
+	<dependencyManagement>
17 21
 		<dependencies>
18 22
 			<dependency>
19
-            <groupId>javax</groupId>
20
-            <artifactId>javaee-web-api</artifactId>
21
-            <version>6.0</version>
22
-            <scope>provided</scope>
23
+				<groupId>junit</groupId>
24
+				<artifactId>junit</artifactId>
25
+				<version>${version.junit}</version>
26
+				<scope>test</scope>
27
+			</dependency>
28
+			<dependency>
29
+				<groupId>org.jboss.arquillian</groupId>
30
+				<artifactId>arquillian-bom</artifactId>
31
+				<version>${version.arquillian}</version>
32
+				<scope>import</scope>
33
+				<type>pom</type>
23 34
 			</dependency>
24 35
 		</dependencies>
36
+	</dependencyManagement>
37
+
25 38
 
26 39
 	<build>
27 40
 		<plugins>
... ...
@@ -37,6 +50,11 @@
37 50
 					</compilerArguments>
38 51
 				</configuration>
39 52
 			</plugin>
53
+			<!-- Updating the Surefire plugin to resolve a bug with clearing the context -->
54
+			<plugin>
55
+				<artifactId>maven-surefire-plugin</artifactId>
56
+				<version>2.12</version>
57
+			</plugin>
40 58
 			<plugin>
41 59
 				<groupId>org.apache.maven.plugins</groupId>
42 60
 				<artifactId>maven-war-plugin</artifactId>
... ...
@@ -73,4 +91,51 @@
73 91
 		</plugins>
74 92
 	</build>
75 93
 	
94
+	
95
+	<dependencies>
96
+		<!-- JEE Spec -->
97
+		<dependency>
98
+            <groupId>org.jboss.spec</groupId>
99
+            <artifactId>jboss-javaee-6.0</artifactId>
100
+            <version>1.0.0.Final</version>
101
+            <type>pom</type>
102
+            <scope>provided</scope>
103
+        </dependency>
104
+
105
+		<!-- Testing: JUnit, Arquillian -->
106
+		<dependency>
107
+			<groupId>junit</groupId>
108
+			<artifactId>junit</artifactId>
109
+			<scope>test</scope>
110
+		</dependency>
111
+		<dependency>
112
+			<groupId>org.jboss.arquillian.junit</groupId>
113
+			<artifactId>arquillian-junit-container</artifactId>
114
+			<scope>test</scope>
115
+		</dependency>
116
+
117
+		<!-- Weld EE container -->
118
+		<dependency>
119
+			<groupId>org.jboss.arquillian.container</groupId>
120
+			<artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
121
+			<version>1.0.0.CR3</version>
122
+			<scope>test</scope>
123
+		</dependency>
124
+		<dependency>
125
+			<groupId>org.jboss.weld</groupId>
126
+			<artifactId>weld-core</artifactId>
127
+			<version>1.1.5.Final</version>
128
+			<scope>test</scope>
129
+		</dependency>
130
+		<dependency>
131
+			<groupId>org.slf4j</groupId>
132
+			<artifactId>slf4j-simple</artifactId>
133
+			<version>1.6.4</version>
134
+			<scope>test</scope>
135
+		</dependency>
136
+		
137
+		
138
+		
139
+	</dependencies>
140
+
76 141
 </project>
... ...
@@ -1,17 +1,27 @@
1 1
 package com.haddouti.pg.jee6;
2 2
 
3 3
 import javax.annotation.PostConstruct;
4
+import javax.ejb.EJB;
4 5
 import javax.ejb.Stateless;
5 6
 
7
+import com.haddouti.pg.jee6.service.OneStatelessBean;
8
+
6 9
 /**
7 10
  * This is service
8 11
  */
9 12
 @Stateless
10 13
 public class OneService {
11 14
 
15
+	@EJB
16
+	private OneStatelessBean bean;
17
+	
12 18
 	@PostConstruct
13 19
 	public void init() {
14 20
 		// ToDo 
15 21
 	}
16 22
 	
23
+	public String process() {
24
+		// lot of magic
25
+		return bean.process();
26
+	}
17 27
 }
... ...
@@ -0,0 +1,21 @@
1
+package com.haddouti.pg.jee6.service;
2
+
3
+import javax.ejb.Stateless;
4
+
5
+/**
6
+ * Session Bean implementation class OneStatelessBean
7
+ */
8
+@Stateless
9
+public class OneStatelessBean {
10
+
11
+    /**
12
+     * Default constructor. 
13
+     */
14
+    public OneStatelessBean() {
15
+    }
16
+
17
+    public String process() {
18
+    	// lot of magic
19
+    	return this.getClass().getSimpleName() + this.hashCode();
20
+    }
21
+}
... ...
@@ -0,0 +1,8 @@
1
+package com.haddouti.pg.jee6.util;
2
+
3
+public class OneUtils {
4
+
5
+	public long getCurrentMillis() {
6
+		return System.currentTimeMillis();
7
+	}
8
+}
... ...
@@ -0,0 +1,38 @@
1
+package com.haddouti.pg.jee6;
2
+
3
+import javax.ejb.EJB;
4
+
5
+import junit.framework.Assert;
6
+
7
+import org.jboss.arquillian.container.test.api.Deployment;
8
+import org.jboss.arquillian.junit.Arquillian;
9
+import org.jboss.shrinkwrap.api.ShrinkWrap;
10
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
11
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
12
+import org.junit.Test;
13
+import org.junit.runner.RunWith;
14
+
15
+import com.haddouti.pg.jee6.service.OneStatelessBean;
16
+
17
+@RunWith(Arquillian.class)
18
+public class OneServiceJarTest {
19
+
20
+	@EJB
21
+	OneService oneService;
22
+	
23
+	@Deployment
24
+	public static JavaArchive createDeployment() {
25
+		return ShrinkWrap.create(JavaArchive.class)
26
+				.addClass(OneStatelessBean.class)
27
+				.addClass(OneService.class)
28
+				.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
29
+	}
30
+	
31
+	
32
+	
33
+	@Test
34
+	public void testOne() {
35
+		System.out.println(oneService);
36
+		Assert.assertNotNull(oneService);
37
+	}
38
+}
... ...
@@ -0,0 +1,46 @@
1
+package com.haddouti.pg.jee6.util;
2
+
3
+import javax.inject.Inject;
4
+
5
+import junit.framework.Assert;
6
+
7
+import org.jboss.arquillian.container.test.api.Deployment;
8
+import org.jboss.arquillian.junit.Arquillian;
9
+import org.jboss.shrinkwrap.api.ShrinkWrap;
10
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
11
+import org.junit.Test;
12
+import org.junit.runner.RunWith;
13
+
14
+/**
15
+ * Arquillian test unit
16
+ * <ul>
17
+ *  <li>JavaArchive</li>
18
+ *  <li>Test normal java classes</li>
19
+ *  <li>Inject them</li>
20
+ * </ul>
21
+ *
22
+ */
23
+@RunWith(Arquillian.class)
24
+public class OneUtilsTest {
25
+
26
+	@Inject
27
+	private OneUtils oneUtils;
28
+	
29
+	
30
+	@Deployment
31
+	public static JavaArchive createDeployment() {
32
+		final JavaArchive jar = ShrinkWrap.create(JavaArchive.class)
33
+				.addClass(OneUtils.class);
34
+
35
+		// Print out the archive
36
+		System.out.println(jar.toString(true));
37
+		return jar;
38
+	}
39
+	
40
+	@Test
41
+	public void testUtilGetCurrentMillis() {
42
+		
43
+		Assert.assertNotNull(oneUtils);
44
+		System.out.println(oneUtils.getCurrentMillis());
45
+	}
46
+}
0 47