Skip to content

Commit 5fc775f

Browse files
author
Reza Rahman
committed
Workarounds for GlassFish bugs
1 parent aa8946d commit 5fc775f

17 files changed

Lines changed: 142 additions & 87 deletions

File tree

README.md

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,59 @@
1-
Testing Java EE Applications Using Arquillian
2-
==========
1+
Testing Java EE Applications on WebLogic 12.1.3 Using Arquillian
2+
================================================================
3+
This application demonstrates how Java EE applications can be effectively
4+
tested using Arquillian on WebLogic 12.1.3. The application contains a
5+
set of JUnit tests that you should examine. The tests will be run as part
6+
of the Maven build. The tests require a running instance of
7+
WebLogic (please see setup instructions). The WebLogic Maven plugin used as
8+
part of the build also requires a running instance of WebLogic to be present.
39

4-
This application demonstrates how Java EE applications can be effectively tested using Arquillian.
10+
WebLogic 12.1.3 supports Java EE 6 and some key Java EE 7 APIs -
11+
WebSocket, JAX-RS 2, JSON-P and JPA 2.1. The application uses both
12+
these APIs as well as Java EE 6 features such as CDI, EJB 3.1 and JSF 2.
13+
14+
Setup
15+
-----
16+
* Install WebLogic 12.1.3
17+
* The Java EE 7 APIs are not automatically enabled. This
18+
[Aquarium blog entry](https://blogs.oracle.com/theaquarium/entry/java_ee_7_support_comes)
19+
is invaluable in better understanding the Java EE 7 API support in
20+
WebLogic 12.1.3. The referenced white paper explains the steps necessary to
21+
enable the APIs.
22+
* The demo application requires a data source. WebLogic 12.1.3 supports the
23+
Java EE 6 standard @DataSourceDefinition and corresponding XML elements.
24+
However, this does not seem to work with JPA 2.1 so we could not use it. A bug
25+
has been filed to get this fixed. Yet another approach is to use WebLogic
26+
proprietary JDBC modules. This requires an EAR file and would significantly
27+
complicate an otherwise simple WAR build. For this reason, this was not an
28+
approach we used. As a result, however, you will need to manually create a
29+
data source for the demo application. The data source is expected to be bound
30+
to 'jdbc/ActionBazaarDB'. We used embedded Derby but any underlying database
31+
should work. If helpful, a sample WebLogic data source definition is provided
32+
[here](ActionBazaarDB-jdbc.xml).
33+
* The demo application uses the WebLogic Maven plugin to automatically deploy
34+
as part of the build. You will need to enable the plugin in your environment.
35+
The detailed instructions to do this can be found
36+
[here](http://docs.oracle.com/middleware/1213/wls/WLPRG/maven.htm). This
37+
resource also contains details on how to configure the Maven plugin, which
38+
you will need to do (see below).
39+
* Please download this repository. You can use Git or just the simple zip
40+
download.
41+
* The demo is just a simple Maven project under the [actionbazaar](actionbazaar)
42+
directory. You should be able to open it up in any Maven capable IDE, we used
43+
NetBeans.
44+
* If desired setup WebLogic in your IDE. This is what we tested.
45+
* The tests in the Maven build are executed against a running WebLogic instance.
46+
You will need to configure
47+
[this file] (actionbazaar/src/test/resources/arquillian.xml) with the details
48+
of your running WebLogic instance (you could run the instance via the IDE).
49+
For details on configuring WebLogic for Arquillian, look
50+
[here] (https://docs.jboss.org/author/display/ARQ/WLS+12.1+-+Remote).
51+
* The build also automatically undeploys and deploys the application to the
52+
running WebLogic instance using the WebLogic Maven plugin. Please configure
53+
the plugin in the [Maven POM](actionbazaar/pom.xml) with the details
54+
of your running WebLogic instance.
55+
* If desired, you can deploy and run the application manually. We did this both
56+
via NetBeans and by using the plain Maven generated war file in addition to
57+
the automated build.
58+
* You can hook up the build to a continuous integration server such as Hudson.
59+
We tested such a setup.

actionbazaar/nb-configuration.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ That way multiple projects can share the same settings (useful for formatting ru
1414
Any value defined here will override the pom.xml file value but is only applicable to the current project.
1515
-->
1616
<org-netbeans-modules-maven-jaxws.rest_2e_config_2e_type>ide</org-netbeans-modules-maven-jaxws.rest_2e_config_2e_type>
17-
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>WebLogic9</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
17+
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>gfv3ee6</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
1818
<org-netbeans-modules-projectapi.jsf_2e_language>Facelets</org-netbeans-modules-projectapi.jsf_2e_language>
1919
<org-netbeans-modules-css-prep.sass_2e_compiler_2e_options/>
2020
<org-netbeans-modules-css-prep.less_2e_mappings>/less:/css</org-netbeans-modules-css-prep.less_2e_mappings>

actionbazaar/pom.xml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@
4747
<version>7.0</version>
4848
<scope>provided</scope>
4949
</dependency>
50-
<dependency>
51-
<groupId>org.glassfish.jersey.media</groupId>
52-
<artifactId>jersey-media-json-processing</artifactId>
53-
<version>2.5.1</version>
54-
<scope>compile</scope>
55-
</dependency>
5650
<dependency>
5751
<groupId>org.glassfish.jersey.containers</groupId>
5852
<artifactId>jersey-container-servlet-core</artifactId>
@@ -85,8 +79,8 @@
8579
</dependency>
8680
<dependency>
8781
<groupId>org.jboss.arquillian.container</groupId>
88-
<artifactId>arquillian-wls-remote-12.1</artifactId>
89-
<version>1.0.0.Alpha2</version>
82+
<artifactId>arquillian-glassfish-managed-3.1</artifactId>
83+
<version>1.0.0.CR4</version>
9084
<scope>test</scope>
9185
</dependency>
9286
<dependency>

actionbazaar/src/main/java/com/actionbazaar/interfaces/web/AddBid.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@
4242
import com.actionbazaar.application.BidService;
4343
import com.actionbazaar.domain.Bid;
4444
import java.io.Serializable;
45-
import javax.enterprise.context.RequestScoped;
45+
import javax.enterprise.context.SessionScoped;
4646
import javax.enterprise.inject.Produces;
47+
import javax.faces.view.ViewScoped;
4748
import javax.inject.Inject;
4849
import javax.inject.Named;
4950

5051
@Named
51-
@RequestScoped
52+
@ViewScoped
5253
public class AddBid implements Serializable {
5354

5455
private static final long serialVersionUID = 1L;
@@ -58,10 +59,11 @@ public class AddBid implements Serializable {
5859

5960
@Produces
6061
@Named
61-
@RequestScoped
62+
@SessionScoped
6263
private final Bid bid = new Bid();
6364

6465
public String onAdd() {
66+
System.err.println(bid);
6567
bidService.addBid(bid);
6668

6769
return "confirm_add_bid.jsf";
Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<persistence
3-
version="2.1"
4-
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
5-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6-
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
7-
<persistence-unit name="action-bazaar-unit">
8-
<jta-data-source>jdbc/ActionBazaarDB</jta-data-source>
9-
<properties>
10-
<property name="javax.persistence.schema-generation.database.action"
11-
value="drop-and-create" />
12-
<property name="eclipselink.logging.level" value="INFO" />
13-
</properties>
14-
</persistence-unit>
15-
</persistence>
2+
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
3+
<persistence-unit name="action-bazaar-unit" transaction-type="JTA">
4+
<jta-data-source>java:global/jdbc/ActionBazaarDB</jta-data-source>
5+
<properties>
6+
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
7+
<property name="eclipselink.logging.level" value="INFO"/>
8+
</properties>
9+
</persistence-unit>
10+
</persistence>

actionbazaar/src/main/webapp/WEB-INF/web.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@
2323
<welcome-file-list>
2424
<welcome-file>add_bid.jsf</welcome-file>
2525
</welcome-file-list>
26+
<data-source>
27+
<name>java:global/jdbc/ActionBazaarDB</name>
28+
<class-name>org.apache.derby.jdbc.EmbeddedDriver</class-name>
29+
<url>jdbc:derby:/tmp/actionbazaar-database;create=true</url>
30+
</data-source>
2631
</web-app>
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<weblogic-web-app
3-
xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"
4-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.7/weblogic-web-app.xsd">
6-
<context-root>/actionbazaar</context-root>
7-
<library-ref>
8-
<library-name>jax-rs</library-name>
9-
<specification-version>2.0</specification-version>
10-
<exact-match>false</exact-match>
11-
</library-ref>
12-
</weblogic-web-app>
2+
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.7/weblogic-web-app.xsd">
3+
<context-root>/actionbazaar</context-root>
4+
<library-ref>
5+
<library-name>jax-rs</library-name>
6+
<specification-version>2.0</specification-version>
7+
<exact-match>false</exact-match>
8+
</library-ref>
9+
</weblogic-web-app>

actionbazaar/src/main/webapp/confirm_add_bid.xhtml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
<h:body>
99
<h1>Bid Added</h1>
1010
<h:panelGrid columns="2">
11-
<h:outputLabel for="item">Item name:</h:outputLabel>
11+
<h:outputLabel for="itemField">Item name:</h:outputLabel>
1212
<h:outputText id="itemField" value="#{bid.item}" />
13-
<h:outputLabel for="bidder">Bidder name:</h:outputLabel>
13+
<h:outputLabel for="bidderField">Bidder name:</h:outputLabel>
1414
<h:outputText id="bidderField" value="#{bid.bidder}" />
15-
<h:outputLabel for="amount">Bid amount:</h:outputLabel>
15+
<h:outputLabel for="amountField">Bid amount:</h:outputLabel>
1616
<h:outputText id="amountField" value="#{bid.amount}" />
1717
</h:panelGrid>
1818
</h:body>

actionbazaar/src/test/java/com/actionbazaar/application/BidServiceTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ public static WebArchive createDeployment() {
6868
.addClasses(BidService.class, DefaultBidService.class,
6969
Profiled.class, ProfilingInterceptor.class,
7070
BidRepository.class, DefaultBidRepository.class, Bid.class)
71-
.addAsWebInfResource("test-beans.xml", "beans.xml")
72-
.addAsResource("test-persistence.xml",
73-
"META-INF/persistence.xml");
71+
.addAsWebInfResource("test-persistence-web.xml", "web.xml")
72+
.addAsWebInfResource("test-persistence-beans.xml", "beans.xml")
73+
.addAsResource("test-persistence.xml", "META-INF/persistence.xml");
7474
}
7575

7676
@EJB

actionbazaar/src/test/java/com/actionbazaar/application/BidServiceUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static WebArchive createDeployment() {
6565
.create(WebArchive.class, "actionbazaar-test.war")
6666
.addClasses(BidService.class, DefaultBidService.class,
6767
BidRepository.class, MockBidRepository.class, Bid.class)
68-
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
68+
.addAsWebInfResource("test-beans.xml", "beans.xml");
6969
}
7070

7171
@EJB

0 commit comments

Comments
 (0)