Skip to content

Commit e4970d5

Browse files
committed
add module for CDI with deltapike
allow to replace cdi-impl without any change at cucumber.
1 parent 437bb3a commit e4970d5

File tree

11 files changed

+299
-0
lines changed

11 files changed

+299
-0
lines changed

deltaspike/nbproject/project.properties

Whitespace-only changes.

deltaspike/pom.xml

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>io.cucumber</groupId>
9+
<artifactId>cucumber-jvm</artifactId>
10+
<version>4.3.1-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>cucumber-deltaspike</artifactId>
14+
<packaging>jar</packaging>
15+
<name>Cucumber-JVM: Deltaspike</name>
16+
17+
<properties>
18+
<deltaspike.version>1.9.0</deltaspike.version>
19+
<cdi-api.version>2.0.SP1</cdi-api.version>
20+
<jaxb-api.version>2.3.1</jaxb-api.version>
21+
22+
<weld-se.version>2.4.4.Final</weld-se.version>
23+
<openejb-core.version>8.0.0-M1</openejb-core.version>
24+
<owb.version>2.0.10</owb.version>
25+
</properties>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>${project.groupId}</groupId>
30+
<artifactId>cucumber-java</artifactId>
31+
<version>${project.version}</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.apache.deltaspike.cdictrl</groupId>
35+
<artifactId>deltaspike-cdictrl-api</artifactId>
36+
<version>${deltaspike.version}</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>javax.enterprise</groupId>
40+
<artifactId>cdi-api</artifactId>
41+
<version>${cdi-api.version}</version>
42+
<scope>provided</scope>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>io.cucumber</groupId>
47+
<artifactId>cucumber-junit</artifactId>
48+
<scope>test</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>junit</groupId>
52+
<artifactId>junit</artifactId>
53+
<scope>test</scope>
54+
</dependency>
55+
</dependencies>
56+
57+
<profiles>
58+
<profile>
59+
<id>deltaspike-weld</id>
60+
<activation>
61+
<activeByDefault>true</activeByDefault>
62+
</activation>
63+
64+
<dependencies>
65+
<dependency>
66+
<groupId>org.apache.deltaspike.cdictrl</groupId>
67+
<artifactId>deltaspike-cdictrl-weld</artifactId>
68+
<version>${deltaspike.version}</version>
69+
<scope>test</scope>
70+
</dependency>
71+
<dependency>
72+
<groupId>org.jboss.weld.se</groupId>
73+
<artifactId>weld-se-core</artifactId>
74+
<version>${weld-se.version}</version>
75+
<scope>test</scope>
76+
</dependency>
77+
</dependencies>
78+
</profile>
79+
80+
<profile>
81+
<id>deltaspike-openejb</id>
82+
83+
<dependencies>
84+
<dependency>
85+
<groupId>org.apache.deltaspike.cdictrl</groupId>
86+
<artifactId>deltaspike-cdictrl-openejb</artifactId>
87+
<version>${deltaspike.version}</version>
88+
<scope>test</scope>
89+
</dependency>
90+
91+
<dependency>
92+
<groupId>org.apache.tomee</groupId>
93+
<artifactId>openejb-core</artifactId>
94+
<version>${openejb-core.version}</version>
95+
<scope>test</scope>
96+
</dependency>
97+
<dependency>
98+
<groupId>javax.xml.bind</groupId>
99+
<artifactId>jaxb-api</artifactId>
100+
<version>${jaxb-api.version}</version>
101+
<scope>test</scope>
102+
</dependency>
103+
<dependency>
104+
<groupId>org.glassfish.jaxb</groupId>
105+
<artifactId>jaxb-runtime</artifactId>
106+
<version>${jaxb-api.version}</version>
107+
</dependency>
108+
</dependencies>
109+
</profile>
110+
111+
<profile>
112+
<id>deltaspike-owb</id>
113+
114+
<dependencies>
115+
<dependency>
116+
<groupId>org.apache.deltaspike.cdictrl</groupId>
117+
<artifactId>deltaspike-cdictrl-owb</artifactId>
118+
<version>${deltaspike.version}</version>
119+
<scope>test</scope>
120+
</dependency>
121+
122+
<dependency>
123+
<groupId>org.apache.openwebbeans</groupId>
124+
<artifactId>openwebbeans-impl</artifactId>
125+
<version>${owb.version}</version>
126+
<scope>test</scope>
127+
</dependency>
128+
<dependency>
129+
<groupId>javax.annotation</groupId>
130+
<artifactId>jsr250-api</artifactId>
131+
<version>1.0</version>
132+
<scope>test</scope>
133+
</dependency>
134+
</dependencies>
135+
</profile>
136+
137+
</profiles>
138+
139+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package cucumber.runtime.java.deltaspike;
2+
3+
import cucumber.api.java.ObjectFactory;
4+
import javax.enterprise.inject.spi.CDI;
5+
import org.apache.deltaspike.cdise.api.CdiContainer;
6+
import org.apache.deltaspike.cdise.api.CdiContainerLoader;
7+
8+
public class DeltaSpikeObjectFactory implements ObjectFactory {
9+
10+
private final CdiContainer container;
11+
12+
public DeltaSpikeObjectFactory() {
13+
this.container = CdiContainerLoader.getCdiContainer();
14+
}
15+
16+
@Override
17+
public void start() {
18+
container.boot();
19+
}
20+
21+
@Override
22+
public void stop() {
23+
container.shutdown();
24+
}
25+
26+
@Override
27+
public boolean addClass(final Class<?> clazz) {
28+
return true;
29+
}
30+
31+
@Override
32+
public <T> T getInstance(final Class<T> type) {
33+
return CDI.current().select(type).get();
34+
}
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package cucumber.runtime.java.deltaspike;
2+
3+
public class Belly {
4+
5+
private int cukes;
6+
7+
public void setCukes(int cukes) {
8+
this.cukes = cukes;
9+
}
10+
11+
public int getCukes() {
12+
return cukes;
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package cucumber.runtime.java.deltaspike;
2+
3+
import cucumber.api.java.en.Given;
4+
import cucumber.api.java.en.Then;
5+
import javax.inject.Inject;
6+
import javax.inject.Singleton;
7+
import static org.junit.Assert.assertEquals;
8+
import static org.junit.Assert.assertTrue;
9+
10+
@Singleton
11+
public class BellyStepdefs {
12+
13+
// For injecting classes from src/test/java, your beans.xml has to be
14+
// located in src/test/resources.
15+
// If you want to inject classes from src/main/java, you will need an
16+
// additional beans.xml in src/main/resources.
17+
@Inject
18+
private Belly belly;
19+
20+
private boolean inTheBelly = false;
21+
22+
@Given("I have {int} cukes in my belly")
23+
public void haveCukes(int n) {
24+
belly.setCukes(n);
25+
inTheBelly = true;
26+
}
27+
28+
@Then("there are {int} cukes in my belly")
29+
public void checkCukes(int n) {
30+
assertEquals(n, belly.getCukes());
31+
assertTrue(inTheBelly);
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package cucumber.runtime.java.deltaspike;
2+
3+
import cucumber.api.java.ObjectFactory;
4+
import static org.junit.Assert.assertNotNull;
5+
import static org.junit.Assert.assertNotSame;
6+
import org.junit.Test;
7+
8+
public class DeltaSpikeObjectFactoryTest {
9+
10+
private final ObjectFactory factory = new DeltaSpikeObjectFactory();
11+
12+
@Test
13+
public void shouldGiveUsNewInstancesForEachScenario() {
14+
factory.addClass(BellyStepdefs.class);
15+
16+
// Scenario 1
17+
factory.start();
18+
final BellyStepdefs o1 = factory.getInstance(BellyStepdefs.class);
19+
factory.stop();
20+
21+
// Scenario 2
22+
factory.start();
23+
final BellyStepdefs o2 = factory.getInstance(BellyStepdefs.class);
24+
factory.stop();
25+
26+
assertNotNull(o1);
27+
assertNotSame(o1, o2);
28+
}
29+
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package cucumber.runtime.java.deltaspike;
2+
3+
import cucumber.api.junit.Cucumber;
4+
import org.junit.runner.RunWith;
5+
6+
@RunWith(Cucumber.class)
7+
public class RunCukesTest {
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cucumber.runtime.java.deltaspike;
2+
3+
import cucumber.api.java.Before;
4+
import cucumber.api.java.en.Given;
5+
6+
public class UnusedGlue {
7+
8+
public UnusedGlue() {
9+
throw new IllegalStateException();
10+
}
11+
12+
@Given("unused")
13+
public void unused() {
14+
throw new IllegalStateException();
15+
}
16+
17+
@Before("@unused")
18+
public void unusedHook() {
19+
throw new IllegalStateException();
20+
}
21+
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<beans xmlns="http://java.sun.com/xml/ns/javaee"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="
4+
http://java.sun.com/xml/ns/javaee
5+
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
6+
7+
</beans>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Feature: Cukes
2+
3+
Scenario: Eat some cukes
4+
Given I have 4 cukes in my belly
5+
Then there are 4 cukes in my belly
6+
7+
Scenario: Eat some more cukes
8+
Given I have 6 cukes in my belly
9+
Then there are 6 cukes in my belly

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203
<module>weld</module>
204204
<module>openejb</module>
205205
<module>needle</module>
206+
<module>deltaspike</module>
206207
</modules>
207208

208209
<profiles>

0 commit comments

Comments
 (0)