- Add CDI test case - MS JEE-Testapp-02
Hafid Haddouti

Hafid Haddouti commited on 2014-04-26 20:30:13
Zeige 4 geänderte Dateien mit 24 Einfügungen und 38 Löschungen.


Change-Id: Ib4ad149c5ee0cd7416a3529e459fbc9724d40b4a
... ...
@@ -63,31 +63,6 @@
63 63
 					<failOnMissingWebXml>false</failOnMissingWebXml>
64 64
 				</configuration>
65 65
 			</plugin>
66
-			<plugin>
67
-				<groupId>org.apache.maven.plugins</groupId>
68
-				<artifactId>maven-dependency-plugin</artifactId>
69
-				<version>2.1</version>
70
-				<executions>
71
-					<execution>
72
-						<phase>validate</phase>
73
-						<goals>
74
-							<goal>copy</goal>
75
-						</goals>
76
-						<configuration>
77
-							<outputDirectory>${endorsed.dir}</outputDirectory>
78
-							<silent>true</silent>
79
-							<artifactItems>
80
-								<artifactItem>
81
-									<groupId>javax</groupId>
82
-									<artifactId>javaee-endorsed-api</artifactId>
83
-									<version>6.0</version>
84
-									<type>jar</type>
85
-								</artifactItem>
86
-							</artifactItems>
87
-						</configuration>
88
-					</execution>
89
-				</executions>
90
-			</plugin>
91 66
 		</plugins>
92 67
 	</build>
93 68
 	
... ...
@@ -1,27 +1,25 @@
1 1
 package com.haddouti.pg.jee6;
2 2
 
3 3
 import javax.annotation.PostConstruct;
4
-import javax.ejb.EJB;
5
-import javax.ejb.Stateless;
4
+import javax.inject.Inject;
6 5
 
7 6
 import com.haddouti.pg.jee6.service.OneStatelessBean;
8 7
 
9 8
 /**
10 9
  * This is service
11 10
  */
12
-@Stateless
13 11
 public class OneService {
14 12
 
15
-	@EJB
13
+	@Inject
16 14
 	private OneStatelessBean bean;
17 15
 	
18 16
 	@PostConstruct
19 17
 	public void init() {
20
-		// ToDo 
18
+		System.out.println("init(): " + this.getClass().getSimpleName()); 
21 19
 	}
22 20
 	
23 21
 	public String process() {
24 22
 		// lot of magic
25
-		return bean.process();
23
+		return this.getClass().getSimpleName() + "." + bean.process();
26 24
 	}
27 25
 }
... ...
@@ -1,11 +1,11 @@
1 1
 package com.haddouti.pg.jee6.service;
2 2
 
3
-import javax.ejb.Stateless;
3
+import javax.annotation.PostConstruct;
4
+
4 5
 
5 6
 /**
6 7
  * Session Bean implementation class OneStatelessBean
7 8
  */
8
-@Stateless
9 9
 public class OneStatelessBean {
10 10
 
11 11
     /**
... ...
@@ -14,8 +14,14 @@ public class OneStatelessBean {
14 14
     public OneStatelessBean() {
15 15
     }
16 16
 
17
+    @PostConstruct
18
+    public void init() {
19
+    	System.out.println("init(): " + this.getClass().getSimpleName());
20
+    }
21
+    
22
+    
17 23
     public String process() {
18 24
     	// lot of magic
19
-    	return this.getClass().getSimpleName() + this.hashCode();
25
+    	return this.getClass().getSimpleName() + "@" + this.hashCode();
20 26
     }
21 27
 }
... ...
@@ -1,6 +1,6 @@
1 1
 package com.haddouti.pg.jee6;
2 2
 
3
-import javax.ejb.EJB;
3
+import javax.inject.Inject;
4 4
 
5 5
 import junit.framework.Assert;
6 6
 
... ...
@@ -14,25 +14,32 @@ import org.junit.runner.RunWith;
14 14
 
15 15
 import com.haddouti.pg.jee6.service.OneStatelessBean;
16 16
 
17
+/**
18
+ * Arquillian test case for CDI classes
19
+ *
20
+ */
17 21
 @RunWith(Arquillian.class)
18 22
 public class OneServiceJarTest {
19 23
 
20
-	@EJB
24
+	@Inject
21 25
 	OneService oneService;
22 26
 	
23 27
 	@Deployment
24 28
 	public static JavaArchive createDeployment() {
25
-		return ShrinkWrap.create(JavaArchive.class)
29
+		final JavaArchive jar = ShrinkWrap.create(JavaArchive.class)
26 30
 				.addClass(OneStatelessBean.class)
27 31
 				.addClass(OneService.class)
28 32
 				.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
33
+		
34
+		System.out.println(jar.toString(true));
35
+		return jar;
29 36
 	}
30 37
 	
31 38
 	
32 39
 	
33 40
 	@Test
34 41
 	public void testOne() {
35
-		System.out.println(oneService);
36 42
 		Assert.assertNotNull(oneService);
43
+		System.out.println(oneService.process());
37 44
 	}
38 45
 }
39 46