Skip to content

Commit a2c4d60

Browse files
committed
ISSUE8 - AlternativesFoodProcessorTest no longer works - worse with Open Web Beans
1 parent ef96232 commit a2c4d60

7 files changed

Lines changed: 124 additions & 102 deletions

File tree

ch02/standalone/build.gradle

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,35 @@ dependencies {
2525
// 'org.apache.deltaspike.cdictrl:deltaspike-cdictrl-api:1.0.0'
2626
// 'org.jboss.weld.se:weld-se-core:3.0.0.Alpha14'
2727

28+
compile files("build/class/main/META-INF")
29+
2830
compile "javax:javaee-api:${javaeeVersion}"
2931

30-
compile "org.jboss.weld.se:weld-se-core:${weldSEVersion}"
32+
// compile "org.jboss.weld.se:weld-se-core:${weldSEVersion}"
33+
compile "org.apache.openwebbeans:openwebbeans-impl:1.6.2"
3134
compile "org.slf4j:slf4j-simple:${slf4jVersion}"
3235
compile "org.apache.deltaspike.cdictrl:deltaspike-cdictrl-api:${deltaspikeVersion}"
33-
compile "org.apache.deltaspike.cdictrl:deltaspike-cdictrl-weld:${deltaspikeVersion}"
34-
compile "org.apache.deltaspike.cdictrl:deltaspike-test-control-module-api:${deltaspikeVersion}"
35-
testCompile "org.apache.deltaspike.cdictrl:deltaspike-test-control-module-impl:${deltaspikeVersion}"
36+
// compile "org.apache.deltaspike.cdictrl:deltaspike-cdictrl-weld:${deltaspikeVersion}"
37+
compile "org.apache.deltaspike.cdictrl:deltaspike-cdictrl-owb:${deltaspikeVersion}"
38+
compile "org.apache.deltaspike.modules:deltaspike-test-control-module-api:${deltaspikeVersion}"
39+
testCompile "org.apache.deltaspike.modules:deltaspike-test-control-module-impl:${deltaspikeVersion}"
3640
}
3741

42+
43+
sourceSets {
44+
main {
45+
output.resourcesDir = 'build/classes/main'
46+
output.classesDir = 'build/classes/main'
47+
}
48+
test {
49+
output.resourcesDir = 'build/classes/test'
50+
output.classesDir = 'build/classes/test'
51+
}
52+
}
53+
54+
55+
// 'org.apache.deltaspike.modules:deltaspike-test-control-module-api:1.5.2'
56+
3857
// See also https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html
3958
test {
4059
// jvmArgs '-XX:MaxPermSize=768m'
@@ -50,23 +69,4 @@ test {
5069
workingDir = project.projectDir
5170
}
5271

53-
task(run, dependsOn: 'classes', type: JavaExec) {
54-
description = 'Runs the main application'
55-
main = 'je7hb.standalone.HelloWorld'
56-
classpath = sourceSets.main.runtimeClasspath
57-
args 'Mary', 'Peter', 'Jane'
58-
}
59-
60-
task(generateScript, dependsOn: 'classes') {
61-
description = 'Generates UNIX bash script that launches the program.'
62-
if (!System.properties['os.name'].toLowerCase().contains('windows')) {
63-
// Not Microsoft Windows
64-
new File("HelloWorld").withWriter { out ->
65-
out.println("#!/bin/bash")
66-
out.println("java -cp ${sourceSets.main.runtimeClasspath.getAsPath()} je7hb.standalone.HelloWorld")
67-
}
68-
"chmod 755 HelloWorld".execute()
69-
}
70-
}
71-
7272
// fini

ch02/standalone/src/main/java/je7hb/standalone/HelloWorld.java

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

ch02/standalone/src/test/java/je7hb/standalone/AlternativesFoodProcessorTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323

2424
import je7hb.standalone.alternatives.FoodProcessor;
2525
import je7hb.travelfunk.AbstractCdiContainerTest;
26+
import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner;
2627
import org.junit.*;
28+
import org.junit.runner.RunWith;
2729

2830
import javax.inject.Inject;
2931

@@ -32,7 +34,11 @@
3234
*
3335
* @author Peter Pilgrim
3436
*/
35-
public class AlternativesFoodProcessorTest extends AbstractCdiContainerTest {
37+
38+
// https://deltaspike.apache.org/documentation/test-control.html
39+
40+
@RunWith(CdiTestRunner.class)
41+
public class AlternativesFoodProcessorTest {
3642

3743
private @Inject FoodProcessor foodProcessor;
3844

ch02/standalone/src/test/java/je7hb/travelfunk/AbstractCdiContainerTest.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,21 @@ public abstract class AbstractCdiContainerTest {
4545

4646
@Before
4747
public final void setUp() throws Exception {
48-
containerRefCount.incrementAndGet();
4948
System.out.printf("AbstractCdiContainerTest#setUp() containerRefCount=%d, cdiContainer=%s\n", containerRefCount.get(), cdiContainer );
5049

51-
cdiContainer.getContextControl().stopContext(RequestScoped.class);
52-
cdiContainer.getContextControl().startContext(RequestScoped.class);
50+
if ( cdiContainer != null ) {
51+
containerRefCount.incrementAndGet();
52+
cdiContainer.getContextControl().stopContext(RequestScoped.class);
53+
cdiContainer.getContextControl().startContext(RequestScoped.class);
5354

54-
// perform injection into the very own test class
55-
BeanManager beanManager = cdiContainer.getBeanManager();
56-
CreationalContext creationalContext = beanManager.createCreationalContext(null);
55+
// perform injection into the very own test class
56+
final BeanManager beanManager = cdiContainer.getBeanManager();
57+
final CreationalContext creationalContext = beanManager.createCreationalContext(null);
5758

58-
AnnotatedType annotatedType = beanManager.createAnnotatedType(this.getClass());
59-
InjectionTarget injectionTarget = beanManager.createInjectionTarget(annotatedType);
60-
injectionTarget.inject(this, creationalContext);
59+
final AnnotatedType annotatedType = beanManager.createAnnotatedType(this.getClass());
60+
final InjectionTarget injectionTarget = beanManager.createInjectionTarget(annotatedType);
61+
injectionTarget.inject(this, creationalContext);
62+
}
6163
}
6264

6365
@After
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*******************************************************************************
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2013,2016 by Peter Pilgrim, Addiscombe, Surrey, XeNoNiQUe UK
5+
*
6+
* All rights reserved. This program and the accompanying materials
7+
* are made available under the terms of the GNU GPL v3.0
8+
* which accompanies this distribution, and is available at:
9+
* http://www.gnu.org/licenses/gpl-3.0.txt
10+
*
11+
* Developers:
12+
* Peter Pilgrim -- design, development and implementation
13+
* -- Blog: http://www.xenonique.co.uk/blog/
14+
* -- Twitter: @peter_pilgrim
15+
*
16+
* Contributors:
17+
*
18+
*******************************************************************************/
19+
20+
archivesBaseName = 'ch02-weld-se-helloworld'
21+
22+
dependencies {
23+
compile "javax:javaee-api:${javaeeVersion}"
24+
25+
compile "org.jboss.weld.se:weld-se-core:${weldSEVersion}"
26+
compile "org.slf4j:slf4j-simple:${slf4jVersion}"
27+
compile "org.apache.deltaspike.cdictrl:deltaspike-cdictrl-api:${deltaspikeVersion}"
28+
compile "org.apache.deltaspike.cdictrl:deltaspike-cdictrl-weld:${deltaspikeVersion}"
29+
compile "org.apache.deltaspike.modules:deltaspike-test-control-module-api:${deltaspikeVersion}"
30+
testCompile "org.apache.deltaspike.modules:deltaspike-test-control-module-impl:${deltaspikeVersion}"
31+
}
32+
33+
34+
sourceSets {
35+
main {
36+
output.resourcesDir = 'build/classes/main'
37+
output.classesDir = 'build/classes/main'
38+
}
39+
test {
40+
output.resourcesDir = 'build/classes/test'
41+
output.classesDir = 'build/classes/test'
42+
}
43+
}
44+
45+
46+
// 'org.apache.deltaspike.modules:deltaspike-test-control-module-api:1.5.2'
47+
48+
// See also https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html
49+
test {
50+
// jvmArgs '-XX:MaxPermSize=768m'
51+
52+
testLogging.showStandardStreams = true
53+
54+
// set heap size for the test JVM(s)
55+
minHeapSize = "128m"
56+
maxHeapSize = "768m"
57+
58+
// Ensure that the working directory for the test is the same as the project directory in order to run the Spike Delta container tests
59+
// *PP* 11/02/2016
60+
workingDir = project.projectDir
61+
}
62+
63+
task(run, dependsOn: 'classes', type: JavaExec) {
64+
description = 'Runs the main application'
65+
main = 'je7hb.weld.helloworld.HelloWorld'
66+
classpath = sourceSets.main.runtimeClasspath
67+
args 'Mary', 'Peter', 'Jane'
68+
}
69+
70+
task(generateScript, dependsOn: 'classes') {
71+
description = 'Generates UNIX bash script that launches the program.'
72+
if (!System.properties['os.name'].toLowerCase().contains('windows')) {
73+
// Not Microsoft Windows
74+
new File("HelloWorld").withWriter { out ->
75+
out.println("#!/bin/bash")
76+
out.println("java -cp ${sourceSets.main.runtimeClasspath.getAsPath()} je7hb.weld.helloworld.HelloWorld")
77+
}
78+
"chmod 755 HelloWorld".execute()
79+
}
80+
}
81+
82+
// fini

ch02/weld-se-helloworld/src/test/resources/META-INF/beans.xml

Whitespace-only changes.

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ include 'appendix01:glassfish-embedded',
55
'appendix04:jsonp-examples',
66
'ch01:xentracker-angularjs',
77
'ch01:xentracker-basic',
8+
'ch02:weld-se-helloworld',
89
'ch02:arquillian',
910
'ch02:standalone',
1011
'ch03:ejb',

0 commit comments

Comments
 (0)