Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit 9a93537

Browse files
committed
add ee based unit tests
1 parent fdeb2f4 commit 9a93537

File tree

4 files changed

+162
-0
lines changed

4 files changed

+162
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package io.openliberty.boost.common.boosters;
2+
3+
import static io.openliberty.boost.common.config.ConfigConstants.*;
4+
import static io.openliberty.boost.common.utils.DOMUtils.getDirectChildrenByTag;
5+
import static org.junit.Assert.assertEquals;
6+
import static org.junit.Assert.assertTrue;
7+
8+
import java.io.IOException;
9+
import java.lang.reflect.InvocationTargetException;
10+
import java.util.List;
11+
import java.util.Map;
12+
import java.util.Properties;
13+
14+
import javax.xml.parsers.ParserConfigurationException;
15+
import javax.xml.transform.TransformerException;
16+
17+
import org.junit.Rule;
18+
import org.junit.Test;
19+
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
20+
import org.junit.rules.TemporaryFolder;
21+
import org.w3c.dom.Element;
22+
23+
import io.openliberty.boost.common.BoostException;
24+
import io.openliberty.boost.common.BoostLoggerI;
25+
import io.openliberty.boost.common.config.BoostProperties;
26+
import io.openliberty.boost.common.config.BoosterConfigurator;
27+
import io.openliberty.boost.common.config.LibertyServerConfigGenerator;
28+
import io.openliberty.boost.common.utils.BoostUtil;
29+
import io.openliberty.boost.common.utils.BoosterUtil;
30+
import io.openliberty.boost.common.utils.CommonLogger;
31+
import io.openliberty.boost.common.utils.ConfigFileUtils;
32+
33+
public class CDIBoosterTest {
34+
35+
@Rule
36+
public TemporaryFolder outputDir = new TemporaryFolder();
37+
38+
@Rule
39+
public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
40+
41+
// private Map<String, String> getCDIDependency(String version) throws
42+
// BoostException {
43+
// return
44+
// BoosterUtil.createDependenciesWithBoosterAndVersion(CDIBoosterConfig.class,
45+
// version);
46+
// }
47+
48+
BoostLoggerI logger = CommonLogger.getInstance();
49+
50+
/**
51+
* Test that the cdi-2.0 feature is added to server.xml when the CDI booster
52+
* version is set to 0.2-SNAPSHOT
53+
*
54+
*/
55+
@Test
56+
public void testCDIBoosterFeature_20() throws Exception {
57+
58+
LibertyServerConfigGenerator serverConfig = new LibertyServerConfigGenerator(
59+
outputDir.getRoot().getAbsolutePath(), logger);
60+
61+
List<AbstractBoosterConfig> boosters = BoosterConfigurator.getBoosterConfigs(
62+
BoosterUtil.createDependenciesWithBoosterAndVersion(CDIBoosterConfig.class, "0.2-SNAPSHOT"), logger);
63+
64+
System.out.println("AJM: lib feature: " + boosters.get(0).getLibertyFeature());
65+
serverConfig.addFeature(boosters.get(0).getLibertyFeature());
66+
serverConfig.writeToServer();
67+
68+
String serverXML = outputDir.getRoot().getAbsolutePath() + "/server.xml";
69+
boolean featureFound = ConfigFileUtils.findStringInServerXml(serverXML, "<feature>" + CDI_20 + "</feature>");
70+
71+
assertTrue("The " + CDI_20 + " feature was not found in the server configuration", featureFound);
72+
73+
}
74+
75+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package io.openliberty.boost.common.boosters;
2+
3+
import static io.openliberty.boost.common.config.ConfigConstants.*;
4+
import static io.openliberty.boost.common.utils.DOMUtils.getDirectChildrenByTag;
5+
import static org.junit.Assert.assertEquals;
6+
import static org.junit.Assert.assertTrue;
7+
8+
import java.io.IOException;
9+
import java.lang.reflect.InvocationTargetException;
10+
import java.util.List;
11+
import java.util.Map;
12+
import java.util.Properties;
13+
14+
import javax.xml.parsers.ParserConfigurationException;
15+
import javax.xml.transform.TransformerException;
16+
17+
import org.junit.Rule;
18+
import org.junit.Test;
19+
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
20+
import org.junit.rules.TemporaryFolder;
21+
import org.w3c.dom.Element;
22+
23+
import io.openliberty.boost.common.BoostException;
24+
import io.openliberty.boost.common.BoostLoggerI;
25+
import io.openliberty.boost.common.config.BoostProperties;
26+
import io.openliberty.boost.common.config.BoosterConfigurator;
27+
import io.openliberty.boost.common.config.LibertyServerConfigGenerator;
28+
import io.openliberty.boost.common.utils.BoostUtil;
29+
import io.openliberty.boost.common.utils.BoosterUtil;
30+
import io.openliberty.boost.common.utils.CommonLogger;
31+
import io.openliberty.boost.common.utils.ConfigFileUtils;
32+
33+
public class JSONPBoosterTest {
34+
35+
@Rule
36+
public TemporaryFolder outputDir = new TemporaryFolder();
37+
38+
@Rule
39+
public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
40+
41+
BoostLoggerI logger = CommonLogger.getInstance();
42+
43+
/**
44+
* Test that the jsonp-1.1 feature is added to server.xml when the jsonp booster
45+
* version is set to 0.2-SNAPSHOT
46+
*
47+
*/
48+
@Test
49+
public void testJSONPBoosterFeature() throws Exception {
50+
51+
LibertyServerConfigGenerator serverConfig = new LibertyServerConfigGenerator(
52+
outputDir.getRoot().getAbsolutePath(), logger);
53+
54+
List<AbstractBoosterConfig> boosters = BoosterConfigurator.getBoosterConfigs(
55+
BoosterUtil.createDependenciesWithBoosterAndVersion(JSONPBoosterConfig.class, "0.2-SNAPSHOT"), logger);
56+
57+
serverConfig.addFeature(boosters.get(0).getLibertyFeature());
58+
serverConfig.writeToServer();
59+
60+
String serverXML = outputDir.getRoot().getAbsolutePath() + "/server.xml";
61+
boolean featureFound = ConfigFileUtils.findStringInServerXml(serverXML, "<feature>" + JSONP_11 + "</feature>");
62+
63+
assertTrue("The " + JSONP_11 + " feature was not found in the server configuration", featureFound);
64+
65+
}
66+
67+
}

boost-maven/boost-boms/boost-ee8-apis-bom/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@
3636
<artifactId>javax.transaction-api</artifactId>
3737
<version>1.2</version>
3838
</dependency>
39+
<dependency>
40+
<groupId>javax.enterprise</groupId>
41+
<artifactId>cdi-api</artifactId>
42+
<version>2.0</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>javax.json</groupId>
46+
<artifactId>javax.json-api</artifactId>
47+
<version>1.1</version>
48+
</dependency>
3949
</dependencies>
4050
</dependencyManagement>
4151

boost-maven/boost-boms/booster-ee8-bom/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@
5959
<version>0.2-SNAPSHOT</version>
6060
<scope>provided</scope>
6161
</dependency>
62+
<dependency>
63+
<groupId>io.openliberty.boosters</groupId>
64+
<artifactId>cdi</artifactId>
65+
<version>0.2-SNAPSHOT</version>
66+
</dependency>
67+
<dependency>
68+
<groupId>io.openliberty.boosters</groupId>
69+
<artifactId>jsonp</artifactId>
70+
<version>0.2-SNAPSHOT</version>
71+
</dependency>
6272
</dependencies>
6373
</dependencyManagement>
6474

0 commit comments

Comments
 (0)