Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 94bbb87

Browse files
authored
Merge pull request javaee-samples#362 from rhanus/master
cdi/vetoed uses Arquillian container test instead of WebServlet
2 parents be0ca0f + 959b10d commit 94bbb87

File tree

4 files changed

+52
-154
lines changed

4 files changed

+52
-154
lines changed

cdi/vetoed/pom.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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">
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
36
<modelVersion>4.0.0</modelVersion>
47

58
<parent>
69
<groupId>org.javaee7</groupId>
710
<artifactId>cdi</artifactId>
811
<version>1.0-SNAPSHOT</version>
9-
<relativePath>../pom.xml</relativePath>
1012
</parent>
11-
<groupId>org.javaee7</groupId>
13+
1214
<artifactId>cdi-vetoed</artifactId>
13-
<version>1.0-SNAPSHOT</version>
14-
<packaging>war</packaging>
1515
<name>Java EE 7 Sample: cdi - vetoed</name>
16+
1617
</project>

cdi/vetoed/src/main/java/org/javaee7/cdi/vetoed/TestServlet.java

Lines changed: 0 additions & 127 deletions
This file was deleted.

cdi/vetoed/src/main/webapp/index.jsp renamed to cdi/vetoed/src/test/java/org/javaee7/cdi/vetoed/GreetingTest.java

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<!--
21
/*
32
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
43
*
@@ -38,18 +37,44 @@
3837
* only if the new code is made subject to such option by the copyright
3938
* holder.
4039
*/
41-
-->
42-
<%@page contentType="text/html" pageEncoding="UTF-8"%>
43-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
44-
"http://www.w3.org/TR/html4/loose.dtd">
40+
package org.javaee7.cdi.vetoed;
4541

46-
<html>
47-
<head>
48-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
49-
<title>CDI @Vetoed</title>
50-
</head>
51-
<body>
52-
<h1>CDI @Vetoed</h1>
53-
Invoke the <a href="${pageContext.request.contextPath}/TestServlet"/>Greeting Service</a>.
54-
</body>
55-
</html>
42+
import org.jboss.arquillian.container.test.api.Deployment;
43+
import org.jboss.arquillian.junit.Arquillian;
44+
import org.jboss.shrinkwrap.api.Archive;
45+
import org.jboss.shrinkwrap.api.ShrinkWrap;
46+
import org.jboss.shrinkwrap.api.spec.JavaArchive;
47+
import org.junit.Test;
48+
import org.junit.runner.RunWith;
49+
50+
import javax.inject.Inject;
51+
52+
import static org.hamcrest.CoreMatchers.*;
53+
import static org.junit.Assert.assertThat;
54+
55+
/**
56+
* @author Radim Hanus
57+
*/
58+
@RunWith(Arquillian.class)
59+
public class GreetingTest {
60+
@Deployment
61+
public static Archive<?> deploy() {
62+
return ShrinkWrap.create(JavaArchive.class)
63+
.addClasses(Greeting.class, SimpleGreeting.class, FancyGreeting.class)
64+
.addAsManifestResource("beans.xml");
65+
}
66+
67+
@Inject
68+
private Greeting bean;
69+
70+
@Test
71+
public void should_bean_be_injected() throws Exception {
72+
assertThat(bean, is(notNullValue()));
73+
}
74+
75+
@Test
76+
public void should_bean_be_fancy() throws Exception {
77+
// SimpleGreeting bean is vetoed
78+
assertThat(bean, instanceOf(FancyGreeting.class));
79+
}
80+
}

cdi/vetoed/src/main/webapp/WEB-INF/beans.xml renamed to cdi/vetoed/src/test/resources/beans.xml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<!--
2+
<!--
33
/*
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
55
*
@@ -40,10 +40,9 @@
4040
* holder.
4141
*/
4242
-->
43-
<beans
44-
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
45-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
46-
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
47-
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
48-
bean-discovery-mode="all">
43+
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
44+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
45+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
46+
bean-discovery-mode="all">
47+
4948
</beans>

0 commit comments

Comments
 (0)