Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
200 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ nb*.xml | |
*.jar | ||
*.war | ||
*.ear | ||
target/ | ||
target/ | ||
/cdi-se/nbproject/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.hantsylabs.example.ee8</groupId> | ||
<artifactId>ee8-sandbox</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>cdi-se</artifactId> | ||
<packaging>jar</packaging> | ||
<name>CDI 2.0: Java SE example</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.weld.se</groupId> | ||
<artifactId>weld-se-core</artifactId> | ||
<version>3.0.0.Final</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-core</artifactId> | ||
<version>1.3</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<!-- <plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<mainClass>org.jboss.weld.environment.se.StartMain</mainClass> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<configuration> | ||
<mainClass>org.jboss.weld.environment.se.StartMain</mainClass> | ||
<arguments> | ||
<argument>${name}</argument> | ||
</arguments> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>run</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>java</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin>--> | ||
</plugins> | ||
</build> | ||
</project> |
22 changes: 22 additions & 0 deletions
22
cdi-se/src/main/java/com/hantsylabs/example/ee8/cdi/Greeter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package com.hantsylabs.example.ee8.cdi; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Named; | ||
|
||
/** | ||
* | ||
* @author hantsy | ||
*/ | ||
@Named | ||
@ApplicationScoped | ||
public class Greeter { | ||
|
||
public void say(String name) { | ||
System.out.println("Hi, " + name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans> | ||
</beans> |
78 changes: 78 additions & 0 deletions
78
cdi-se/src/test/java/com/hantsylabs/example/ee8/cdi/GreeterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package com.hantsylabs.example.ee8.cdi; | ||
|
||
import java.util.Set; | ||
import javax.enterprise.inject.se.SeContainer; | ||
import javax.enterprise.inject.se.SeContainerInitializer; | ||
import javax.enterprise.inject.spi.Bean; | ||
import javax.enterprise.inject.spi.Extension; | ||
import org.jboss.weld.environment.se.ContainerLifecycleObserver; | ||
import static org.jboss.weld.environment.se.ContainerLifecycleObserver.afterBeanDiscovery; | ||
import static org.jboss.weld.environment.se.ContainerLifecycleObserver.processAnnotatedType; | ||
import org.jboss.weld.environment.se.Weld; | ||
import org.jboss.weld.environment.se.WeldContainer; | ||
import org.jboss.weld.exceptions.UnsatisfiedResolutionException; | ||
import org.junit.After; | ||
import static org.junit.Assert.assertTrue; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** | ||
* | ||
* @author hantsy | ||
*/ | ||
public class GreeterTest { | ||
|
||
public GreeterTest() { | ||
} | ||
|
||
SeContainer container; | ||
|
||
@Before | ||
public void setUp() { | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
} | ||
|
||
@Test | ||
public void bootBasicContainer() { | ||
SeContainerInitializer initializer = SeContainerInitializer.newInstance(); | ||
try (SeContainer container = initializer.initialize()) { | ||
assertTrue(container.isRunning()); | ||
Set<Bean<?>> greeters = container.getBeanManager().getBeans("greeter"); | ||
assertTrue(greeters.size() == 1); | ||
} | ||
} | ||
|
||
@Test | ||
public void bootstrapWeldContainer() { | ||
Weld weld = new Weld(); | ||
|
||
try (WeldContainer container = weld.initialize()) { | ||
Greeter greeter = container.select(Greeter.class).get(); | ||
assertTrue(greeter != null); | ||
} | ||
} | ||
|
||
@Test(expected = UnsatisfiedResolutionException.class) | ||
public void bootWeldSeContainer() { | ||
Extension testExtension = ContainerLifecycleObserver.extensionBuilder() | ||
.add(afterBeanDiscovery((e) -> System.out.println("Bean discovery completed!"))) | ||
.add(processAnnotatedType().notify((e) -> { | ||
if (e.getAnnotatedType().getJavaClass().getName().startsWith("com.hantsylab")) { | ||
e.veto(); | ||
} | ||
})).build(); | ||
try (WeldContainer container = new Weld().addExtension(testExtension).initialize()) { | ||
Greeter greeter = container.select(Greeter.class).get(); | ||
//assertTrue(greeter == null); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<jboss-web version="8.0" xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/schema/jbossas/jboss-web_8_0.xsd"> | ||
<context-root>/jsf</context-root> | ||
</jboss-web> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters