Skip to content

Commit f4b4ce6

Browse files
committed
first push for Java EE 8 test - starting with CDI events priority
1 parent 2ac3ba5 commit f4b4ce6

File tree

10 files changed

+558
-0
lines changed

10 files changed

+558
-0
lines changed

.gitignore

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Directories #
2+
build/
3+
bin/
4+
target/
5+
libs/
6+
tmp/
7+
node_modules/
8+
9+
# OS Files #
10+
.DS_Store
11+
12+
*.class
13+
14+
# Package Files #
15+
*.jar
16+
*.war
17+
*.ear
18+
*.db
19+
rebel.xml
20+
21+
######################
22+
# Windows
23+
######################
24+
25+
# Windows image file caches
26+
Thumbs.db
27+
28+
# Folder config file
29+
Desktop.ini
30+
31+
######################
32+
# OSX
33+
######################
34+
35+
.DS_Store
36+
.svn
37+
38+
# Thumbnails
39+
._*
40+
41+
# Files that might appear on external disk
42+
.Spotlight-V100
43+
.Trashes
44+
45+
######################
46+
# NetBeans
47+
######################
48+
nbproject/
49+
build/
50+
nbbuild/
51+
dist/
52+
nbdist/
53+
nbactions.xml
54+
nb-configuration.xml
55+
56+
######################
57+
# IDEA
58+
######################
59+
*.iml
60+
*.ipr
61+
*.iws
62+
.idea/
63+
atlassian-ide-plugin.xml
64+
65+
66+
######################
67+
# Eclipse
68+
######################
69+
70+
*.pydevproject
71+
.project
72+
.metadata
73+
*.tmp
74+
*.bak
75+
*.swp
76+
*~.nib
77+
local.properties
78+
.classpath
79+
.settings/
80+
.loadpath
81+
82+
# External tool builders
83+
.externalToolBuilders/
84+
85+
# Locally stored "Eclipse launch configurations"
86+
*.launch
87+
88+
# CDT-specific
89+
.cproject
90+
91+
# PDT-specific
92+
.buildpath
93+
94+
# Testing environment specific
95+
derby.log

cdi/events/pom.xml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?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">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>org.javaee8.cdi</groupId>
6+
<artifactId>cdi-samples</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<relativePath>../pom.xml</relativePath>
9+
</parent>
10+
11+
<artifactId>events</artifactId>
12+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.javaee8.cdi.events;
2+
3+
/**
4+
* @author Radim Hanus
5+
* @author Arun Gupta
6+
*/
7+
public interface EventReceiver {
8+
9+
String getGreet();
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.javaee8.cdi.events;
2+
3+
/**
4+
* @author Radim Hanus
5+
* @author Arun Gupta
6+
*/
7+
public interface EventSender {
8+
9+
void send(String message);
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.javaee8.cdi.events;
2+
3+
import javax.enterprise.context.SessionScoped;
4+
import javax.enterprise.event.Observes;
5+
import java.io.Serializable;
6+
import javax.annotation.Priority;
7+
import javax.interceptor.Interceptor;
8+
9+
/**
10+
* @author Radim Hanus
11+
* @author Arun Gupta
12+
*/
13+
@SessionScoped
14+
public class GreetingReceiver implements EventReceiver, Serializable {
15+
16+
private String greet = "Willkommen";
17+
18+
void receive(@Observes @Priority(Interceptor.Priority.APPLICATION + 200) String greet) {
19+
this.greet = greet;
20+
}
21+
22+
@Override
23+
public String getGreet() {
24+
return greet;
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.javaee8.cdi.events;
2+
3+
import javax.enterprise.event.Event;
4+
import javax.inject.Inject;
5+
6+
/**
7+
* @author Radim Hanus
8+
* @author Arun Gupta
9+
*/
10+
public class GreetingSender implements EventSender {
11+
12+
@Inject
13+
private Event<String> event;
14+
15+
@Override
16+
public void send(String message) {
17+
event.fire(message);
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.javaee8.cdi.events;
2+
3+
import org.jboss.arquillian.container.test.api.Deployment;
4+
import org.jboss.arquillian.junit.Arquillian;
5+
import org.jboss.shrinkwrap.api.Archive;
6+
import org.jboss.shrinkwrap.api.ShrinkWrap;
7+
import org.jboss.shrinkwrap.api.spec.JavaArchive;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import javax.inject.Inject;
12+
13+
import static org.hamcrest.CoreMatchers.instanceOf;
14+
import static org.hamcrest.CoreMatchers.is;
15+
import static org.hamcrest.CoreMatchers.notNullValue;
16+
import static org.junit.Assert.assertEquals;
17+
import static org.junit.Assert.assertThat;
18+
19+
/**
20+
* @author Radim Hanus
21+
*/
22+
@RunWith(Arquillian.class)
23+
public class GreetingTest {
24+
25+
@Deployment
26+
public static Archive<?> deploy() {
27+
return ShrinkWrap.create(JavaArchive.class)
28+
.addClasses(EventReceiver.class, EventSender.class, GreetingReceiver.class, GreetingSender.class)
29+
.addAsManifestResource("beans.xml");
30+
}
31+
32+
@Inject
33+
private EventSender sender;
34+
35+
@Inject
36+
private EventReceiver receiver;
37+
38+
@Test
39+
public void test() throws Exception {
40+
assertThat(sender, is(notNullValue()));
41+
assertThat(sender, instanceOf(GreetingSender.class));
42+
43+
assertThat(receiver, is(notNullValue()));
44+
assertThat(receiver, instanceOf(GreetingReceiver.class));
45+
46+
// default greet
47+
assertEquals("Willkommen", receiver.getGreet());
48+
// send a new greet
49+
sender.send("Welcome");
50+
// receiver must not belongs to the dependent pseudo-scope since we are checking the result
51+
assertEquals("Welcome", receiver.getGreet());
52+
}
53+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
6+
bean-discovery-mode="all">
7+
8+
</beans>

cdi/pom.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?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">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>org.javaee8</groupId>
6+
<artifactId>javaee8-samples</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<relativePath>../pom.xml</relativePath>
9+
</parent>
10+
11+
<groupId>org.javaee8.cdi</groupId>
12+
<artifactId>cdi-samples</artifactId>
13+
<version>1.0-SNAPSHOT</version>
14+
<packaging>pom</packaging>
15+
<name>Java EE 8 CDI Samples</name>
16+
17+
<modules>
18+
<module>events</module>
19+
</modules>
20+
</project>

0 commit comments

Comments
 (0)