diff --git a/README.md b/README.md index f1a03ae..e0c3b68 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,29 @@ -Testing Java EE Applications Using Arquillian -========== +Testing Java EE Applications using Arquillian +================================================================ +This application demonstrates how Java EE applications can be effectively +tested using Arquillian. The application contains a +set of JUnit tests that you should examine. The tests will be run as part +of the Maven build. We used JBoss EAP 7 for the application (see setup +instructions below) but it should be easy to port to any Java EE 7 application +server such as GlassFish, WildFly, WebLogic or WebSphere. -This application demonstrates how Java EE applications can be effectively tested using Arquillian. \ No newline at end of file +Setup +----- +* Install JBoss EAP 7. It should be a simple matter of downloading the installation + jar and running the GUI wizard (you will need a Red Hat account). Just accept + all the defaults. Remember the admin password you choose. +* Please download this repository. You can use Git or just the simple zip + download. +* The demo is just a simple Maven project under the [actionbazaar](actionbazaar) + directory. You should be able to open it up in any Maven capable IDE, we used + NetBeans. +* If desired setup JBoss EAP in your IDE; we did. At the current time, NetBeans does + not directly support JBoss EAP 7 yet. You can use the NetBeans features for + WildFly 10; it worked fine for us. +* Make sure JBoss EAP 7 is up and running before you run the tests. +* The tests in the Maven build are executed against a running JBoss EAP instance. + You will need to configure + [this file] (actionbazaar/src/test/resources/arquillian.xml) with the details + of your JBoss EAP installation. You must set the admin password for JBoss EAP. +* If desired, you can deploy and run the application manually. We did this both + via NetBeans and by using the plain Maven generated war file. \ No newline at end of file diff --git a/actionbazaar/nb-configuration.xml b/actionbazaar/nb-configuration.xml index b00b5e1..39882f4 100644 --- a/actionbazaar/nb-configuration.xml +++ b/actionbazaar/nb-configuration.xml @@ -14,14 +14,6 @@ That way multiple projects can share the same settings (useful for formatting ru Any value defined here will override the pom.xml file value but is only applicable to the current project. --> ide - WebLogic9 - Facelets - - /less:/css - false - /scss:/css - false - - js/libs + WildFly diff --git a/actionbazaar/nbactions.xml b/actionbazaar/nbactions.xml deleted file mode 100644 index 9636d3e..0000000 --- a/actionbazaar/nbactions.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - run - - war - ear - ejb - - - package - - - true - /add_bid.jsf - - - - debug - - war - ear - ejb - - - package - - - true - true - /add_bid.jsf - - - - profile - - ejb - ear - war - - - package - - - true - true - /add_bid.jsf - - - diff --git a/actionbazaar/pom.xml b/actionbazaar/pom.xml index c4ec329..b4cbe29 100644 --- a/actionbazaar/pom.xml +++ b/actionbazaar/pom.xml @@ -47,19 +47,6 @@ 7.0 provided - - org.glassfish.jersey.media - jersey-media-json-processing - 2.5.1 - compile - - - org.glassfish.jersey.containers - jersey-container-servlet-core - 2.0 - jar - provided - junit junit @@ -84,21 +71,9 @@ test - org.jboss.arquillian.container - arquillian-wls-remote-12.1 - 1.0.0.Alpha2 - test - - - org.glassfish.tyrus - tyrus-server - 1.7 - test - - - org.glassfish.tyrus - tyrus-container-grizzly-server - 1.7 + org.arquillian.container + arquillian-container-chameleon + 1.0.0.Alpha6 test diff --git a/actionbazaar/src/main/java/com/actionbazaar/application/DefaultBidService.java b/actionbazaar/src/main/java/com/actionbazaar/application/DefaultBidService.java index 54e6098..7f316a9 100644 --- a/actionbazaar/src/main/java/com/actionbazaar/application/DefaultBidService.java +++ b/actionbazaar/src/main/java/com/actionbazaar/application/DefaultBidService.java @@ -39,36 +39,48 @@ */ package com.actionbazaar.application; -import javax.ejb.Stateless; -import javax.inject.Inject; - import com.actionbazaar.domain.Bid; import com.actionbazaar.domain.BidRepository; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.ejb.Stateless; +import javax.inject.Inject; @Stateless @Profiled public class DefaultBidService implements BidService { + private static final Logger logger = Logger + .getLogger(DefaultBidService.class.getName()); + @Inject private BidRepository bidRepository; @Override public Bid addBid(Bid bid) { + logger.log(Level.INFO, "Adding bid: {0}", bid); + return bidRepository.addBid(bid); } @Override public Bid getBid(Long id) { + logger.log(Level.INFO, "Getting bid: {0}", id); + return bidRepository.getBid(id); } @Override public void updateBid(Bid bid) { + logger.log(Level.INFO, "Updating bid: {0}", bid); + bidRepository.updateBid(bid); } @Override public void deleteBid(Bid bid) { + logger.log(Level.INFO, "Deleting bid: {0}", bid); + bidRepository.deleteBid(bid); } -} \ No newline at end of file +} diff --git a/actionbazaar/src/main/java/com/actionbazaar/domain/BidRepository.java b/actionbazaar/src/main/java/com/actionbazaar/domain/BidRepository.java index 69c599f..4641c42 100644 --- a/actionbazaar/src/main/java/com/actionbazaar/domain/BidRepository.java +++ b/actionbazaar/src/main/java/com/actionbazaar/domain/BidRepository.java @@ -48,4 +48,4 @@ public interface BidRepository { public void updateBid(Bid bid); public void deleteBid(Bid bid); -} \ No newline at end of file +} diff --git a/actionbazaar/src/main/java/com/actionbazaar/interfaces/rest/BidRestService.java b/actionbazaar/src/main/java/com/actionbazaar/interfaces/rest/BidRestService.java index 8c2c542..e0f9b8c 100644 --- a/actionbazaar/src/main/java/com/actionbazaar/interfaces/rest/BidRestService.java +++ b/actionbazaar/src/main/java/com/actionbazaar/interfaces/rest/BidRestService.java @@ -87,4 +87,4 @@ public void deleteBid(@PathParam("id") Long id) { Bid bid = bidService.getBid(id); bidService.deleteBid(bid); } -} \ No newline at end of file +} diff --git a/actionbazaar/src/main/java/com/actionbazaar/interfaces/rest/RestConfiguration.java b/actionbazaar/src/main/java/com/actionbazaar/interfaces/rest/RestConfiguration.java index 12f6ff4..a21b12d 100644 --- a/actionbazaar/src/main/java/com/actionbazaar/interfaces/rest/RestConfiguration.java +++ b/actionbazaar/src/main/java/com/actionbazaar/interfaces/rest/RestConfiguration.java @@ -1,56 +1,16 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common Development - * and Distribution License("CDDL") (collectively, the "License"). You - * may not use this file except in compliance with the License. You can - * obtain a copy of the License at - * http://glassfish.java.net/public/CDDL+GPL_1_1.html - * or packager/legal/LICENSE.txt. See the License for the specific - * language governing permissions and limitations under the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License file at packager/legal/LICENSE.txt. - * - * GPL Classpath Exception: - * Oracle designates this particular file as subject to the "Classpath" - * exception as provided by Oracle in the GPL Version 2 section of the License - * file that accompanied this code. - * - * Modifications: - * If applicable, add the following below the License Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyright [year] [name of copyright owner]" - * - * Contributor(s): - * If you wish your version of this file to be governed by only the CDDL or - * only the GPL Version 2, indicate your decision by adding "[Contributor] - * elects to include this software in this distribution under the [CDDL or GPL - * Version 2] license." If you don't indicate a single choice of license, a - * recipient has the option to distribute your version of this file under - * either the CDDL, the GPL Version 2 or to extend the choice of license to - * its licensees as provided above. However, if you add GPL Version 2 code - * and therefore, elected the GPL Version 2 license, then the option applies - * only if the new code is made subject to such option by the copyright - * holder. - */ package com.actionbazaar.interfaces.rest; +import java.util.Set; import javax.ws.rs.ApplicationPath; -import org.glassfish.jersey.server.ResourceConfig; +import javax.ws.rs.core.Application; -/** - * JAX-RS configuration. - */ @ApplicationPath("rest") -// TODO Move this to XML. -public class RestConfiguration extends ResourceConfig { +public class RestConfiguration extends Application { - public RestConfiguration() { - // Resource - packages(new String[]{BidRestService.class.getPackage().getName()}); // removed. + @Override + public Set> getClasses() { + Set> resources = new java.util.HashSet<>(); + resources.add(BidRestService.class); + return resources; } } \ No newline at end of file diff --git a/actionbazaar/src/main/java/com/actionbazaar/interfaces/socket/ChatMessage.java b/actionbazaar/src/main/java/com/actionbazaar/interfaces/socket/ChatMessage.java index fd01b02..3cfea7a 100644 --- a/actionbazaar/src/main/java/com/actionbazaar/interfaces/socket/ChatMessage.java +++ b/actionbazaar/src/main/java/com/actionbazaar/interfaces/socket/ChatMessage.java @@ -40,6 +40,8 @@ package com.actionbazaar.interfaces.socket; import java.io.StringReader; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.json.Json; import javax.json.JsonObject; import javax.json.JsonReader; @@ -50,6 +52,9 @@ public class ChatMessage implements Decoder.Text, Encoder.Text { + private static final Logger logger = Logger + .getLogger(ChatMessage.class.getName()); + private String user; private String message; @@ -77,6 +82,8 @@ public void init(EndpointConfig config) { @Override public ChatMessage decode(String value) { + logger.log(Level.FINE, "Decoding JSON: {0}", value); + try (JsonReader jsonReader = Json.createReader( new StringReader(value))) { JsonObject jsonObject = jsonReader.readObject(); @@ -94,6 +101,8 @@ public boolean willDecode(String string) { @Override public String encode(ChatMessage chatMessage) { + logger.log(Level.FINE, "Encoding to JSON: {0}", chatMessage); + JsonObject jsonObject = Json.createObjectBuilder() .add("user", chatMessage.user) .add("message", chatMessage.message) @@ -111,4 +120,4 @@ public void destroy() { public String toString() { return "ChatMessage{" + "user=" + user + ", message=" + message + '}'; } -} \ No newline at end of file +} diff --git a/actionbazaar/src/main/java/com/actionbazaar/interfaces/socket/ChatServer.java b/actionbazaar/src/main/java/com/actionbazaar/interfaces/socket/ChatServer.java index fb9da44..31ccb8f 100644 --- a/actionbazaar/src/main/java/com/actionbazaar/interfaces/socket/ChatServer.java +++ b/actionbazaar/src/main/java/com/actionbazaar/interfaces/socket/ChatServer.java @@ -42,6 +42,7 @@ import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; +import javax.ejb.Singleton; import javax.websocket.EncodeException; import javax.websocket.OnClose; import javax.websocket.OnMessage; @@ -49,6 +50,7 @@ import javax.websocket.Session; import javax.websocket.server.ServerEndpoint; +@Singleton @ServerEndpoint(value = "/chat", encoders = {ChatMessage.class}, decoders = {ChatMessage.class}) public class ChatServer { diff --git a/actionbazaar/src/main/java/com/actionbazaar/interfaces/web/AddBid.java b/actionbazaar/src/main/java/com/actionbazaar/interfaces/web/AddBid.java index e411568..1620bc3 100644 --- a/actionbazaar/src/main/java/com/actionbazaar/interfaces/web/AddBid.java +++ b/actionbazaar/src/main/java/com/actionbazaar/interfaces/web/AddBid.java @@ -1,54 +1,15 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common Development - * and Distribution License("CDDL") (collectively, the "License"). You - * may not use this file except in compliance with the License. You can - * obtain a copy of the License at - * http://glassfish.java.net/public/CDDL+GPL_1_1.html - * or packager/legal/LICENSE.txt. See the License for the specific - * language governing permissions and limitations under the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License file at packager/legal/LICENSE.txt. - * - * GPL Classpath Exception: - * Oracle designates this particular file as subject to the "Classpath" - * exception as provided by Oracle in the GPL Version 2 section of the License - * file that accompanied this code. - * - * Modifications: - * If applicable, add the following below the License Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyright [year] [name of copyright owner]" - * - * Contributor(s): - * If you wish your version of this file to be governed by only the CDDL or - * only the GPL Version 2, indicate your decision by adding "[Contributor] - * elects to include this software in this distribution under the [CDDL or GPL - * Version 2] license." If you don't indicate a single choice of license, a - * recipient has the option to distribute your version of this file under - * either the CDDL, the GPL Version 2 or to extend the choice of license to - * its licensees as provided above. However, if you add GPL Version 2 code - * and therefore, elected the GPL Version 2 license, then the option applies - * only if the new code is made subject to such option by the copyright - * holder. - */ package com.actionbazaar.interfaces.web; import com.actionbazaar.application.BidService; import com.actionbazaar.domain.Bid; import java.io.Serializable; -import javax.enterprise.context.RequestScoped; +import javax.enterprise.context.ApplicationScoped; import javax.enterprise.inject.Produces; import javax.inject.Inject; import javax.inject.Named; @Named -@RequestScoped +@ApplicationScoped // TODO Change this to flow scoped. public class AddBid implements Serializable { private static final long serialVersionUID = 1L; @@ -58,7 +19,7 @@ public class AddBid implements Serializable { @Produces @Named - @RequestScoped + @ApplicationScoped private final Bid bid = new Bid(); public String onAdd() { @@ -66,4 +27,4 @@ public String onAdd() { return "confirm_add_bid.jsf"; } -} \ No newline at end of file +} diff --git a/actionbazaar/src/main/java/com/actionbazaar/interfaces/web/AlertServlet.java b/actionbazaar/src/main/java/com/actionbazaar/interfaces/web/AlertServlet.java index 06ea4ae..6acd3e0 100644 --- a/actionbazaar/src/main/java/com/actionbazaar/interfaces/web/AlertServlet.java +++ b/actionbazaar/src/main/java/com/actionbazaar/interfaces/web/AlertServlet.java @@ -41,7 +41,8 @@ import java.io.IOException; import java.io.PrintWriter; - +import java.util.logging.Level; +import java.util.logging.Logger; import javax.json.Json; import javax.json.stream.JsonGenerator; import javax.servlet.ServletException; @@ -54,17 +55,20 @@ public class AlertServlet extends HttpServlet { private static final long serialVersionUID = 1L; + private static final Logger logger = Logger + .getLogger(AlertServlet.class.getName()); @Override public void service(ServletRequest request, ServletResponse response) throws IOException, ServletException { - response.setContentType("application/json"); PrintWriter out = response.getWriter(); long userId = Long.parseLong(request.getParameter("user_id")); + logger.log(Level.INFO, "Generating alerts for: {0}", userId); + try (JsonGenerator generator = Json.createGenerator(out)) { generator.writeStartObject(); @@ -85,11 +89,11 @@ public void service(ServletRequest request, ServletResponse response) } generator.writeEnd(); - + generator.write("goodbye", "No more alerts for now, timing out"); - + generator.writeEnd(); generator.close(); } } -} \ No newline at end of file +} diff --git a/actionbazaar/src/main/resources/META-INF/persistence.xml b/actionbazaar/src/main/resources/META-INF/persistence.xml index c4125d2..80c589f 100644 --- a/actionbazaar/src/main/resources/META-INF/persistence.xml +++ b/actionbazaar/src/main/resources/META-INF/persistence.xml @@ -1,15 +1,13 @@ - - - jdbc/ActionBazaarDB + + + java:global/jdbc/ActionBazaarDB - + value="drop-and-create"/> + - \ No newline at end of file + diff --git a/actionbazaar/src/main/webapp/WEB-INF/beans.xml b/actionbazaar/src/main/webapp/WEB-INF/beans.xml index 5a535b3..0af1b98 100644 --- a/actionbazaar/src/main/webapp/WEB-INF/beans.xml +++ b/actionbazaar/src/main/webapp/WEB-INF/beans.xml @@ -1,5 +1,6 @@ - + xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_2.xsd" + version="1.2" bean-discovery-mode="all"> \ No newline at end of file diff --git a/actionbazaar/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/actionbazaar/src/main/webapp/WEB-INF/jboss-deployment-structure.xml new file mode 100644 index 0000000..9f03b31 --- /dev/null +++ b/actionbazaar/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/actionbazaar/src/main/webapp/WEB-INF/web.xml b/actionbazaar/src/main/webapp/WEB-INF/web.xml index ea9d986..7dc30dd 100644 --- a/actionbazaar/src/main/webapp/WEB-INF/web.xml +++ b/actionbazaar/src/main/webapp/WEB-INF/web.xml @@ -1,9 +1,8 @@ - + javax.faces.PROJECT_STAGE Development @@ -19,8 +18,13 @@ 30 - + add_bid.jsf + + java:global/jdbc/ActionBazaarDB + org.h2.jdbcx.JdbcDataSource + jdbc:h2:/tmp/actionbazaar-development-database + \ No newline at end of file diff --git a/actionbazaar/src/main/webapp/WEB-INF/weblogic.xml b/actionbazaar/src/main/webapp/WEB-INF/weblogic.xml deleted file mode 100644 index 51fdd77..0000000 --- a/actionbazaar/src/main/webapp/WEB-INF/weblogic.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - /actionbazaar - - jax-rs - 2.0 - false - - \ No newline at end of file diff --git a/actionbazaar/src/main/webapp/confirm_add_bid.xhtml b/actionbazaar/src/main/webapp/confirm_add_bid.xhtml index 9741540..e10612c 100644 --- a/actionbazaar/src/main/webapp/confirm_add_bid.xhtml +++ b/actionbazaar/src/main/webapp/confirm_add_bid.xhtml @@ -8,11 +8,11 @@

Bid Added

- Item name: + Item name: - Bidder name: + Bidder name: - Bid amount: + Bid amount:
diff --git a/actionbazaar/src/test/java/com/actionbazaar/application/BidServiceTest.java b/actionbazaar/src/test/java/com/actionbazaar/application/BidServiceTest.java index a176957..2646aaa 100644 --- a/actionbazaar/src/test/java/com/actionbazaar/application/BidServiceTest.java +++ b/actionbazaar/src/test/java/com/actionbazaar/application/BidServiceTest.java @@ -1,42 +1,3 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common Development - * and Distribution License("CDDL") (collectively, the "License"). You - * may not use this file except in compliance with the License. You can - * obtain a copy of the License at - * http://glassfish.java.net/public/CDDL+GPL_1_1.html - * or packager/legal/LICENSE.txt. See the License for the specific - * language governing permissions and limitations under the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License file at packager/legal/LICENSE.txt. - * - * GPL Classpath Exception: - * Oracle designates this particular file as subject to the "Classpath" - * exception as provided by Oracle in the GPL Version 2 section of the License - * file that accompanied this code. - * - * Modifications: - * If applicable, add the following below the License Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyright [year] [name of copyright owner]" - * - * Contributor(s): - * If you wish your version of this file to be governed by only the CDDL or - * only the GPL Version 2, indicate your decision by adding "[Contributor] - * elects to include this software in this distribution under the [CDDL or GPL - * Version 2] license." If you don't indicate a single choice of license, a - * recipient has the option to distribute your version of this file under - * either the CDDL, the GPL Version 2 or to extend the choice of license to - * its licensees as provided above. However, if you add GPL Version 2 code - * and therefore, elected the GPL Version 2 license, then the option applies - * only if the new code is made subject to such option by the copyright - * holder. - */ package com.actionbazaar.application; import static org.junit.Assert.assertEquals; @@ -64,13 +25,14 @@ public class BidServiceTest { @Deployment public static WebArchive createDeployment() { return ShrinkWrap - .create(WebArchive.class, "actionbazaar-test.war") + .create(WebArchive.class, "actionbazaar-service-test.war") .addClasses(BidService.class, DefaultBidService.class, Profiled.class, ProfilingInterceptor.class, BidRepository.class, DefaultBidRepository.class, Bid.class) - .addAsWebInfResource("test-beans.xml", "beans.xml") - .addAsResource("test-persistence.xml", - "META-INF/persistence.xml"); + .addAsWebInfResource("test-persistence-web.xml", "web.xml") + .addAsWebInfResource("jboss-deployment-structure.xml", "jboss-deployment-structure.xml") + .addAsWebInfResource("test-persistence-beans.xml", "beans.xml") + .addAsResource("test-persistence.xml", "META-INF/persistence.xml"); } @EJB diff --git a/actionbazaar/src/test/java/com/actionbazaar/application/BidServiceUnitTest.java b/actionbazaar/src/test/java/com/actionbazaar/application/BidServiceUnitTest.java index 5efa906..72bd16e 100644 --- a/actionbazaar/src/test/java/com/actionbazaar/application/BidServiceUnitTest.java +++ b/actionbazaar/src/test/java/com/actionbazaar/application/BidServiceUnitTest.java @@ -1,71 +1,28 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common Development - * and Distribution License("CDDL") (collectively, the "License"). You - * may not use this file except in compliance with the License. You can - * obtain a copy of the License at - * http://glassfish.java.net/public/CDDL+GPL_1_1.html - * or packager/legal/LICENSE.txt. See the License for the specific - * language governing permissions and limitations under the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License file at packager/legal/LICENSE.txt. - * - * GPL Classpath Exception: - * Oracle designates this particular file as subject to the "Classpath" - * exception as provided by Oracle in the GPL Version 2 section of the License - * file that accompanied this code. - * - * Modifications: - * If applicable, add the following below the License Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyright [year] [name of copyright owner]" - * - * Contributor(s): - * If you wish your version of this file to be governed by only the CDDL or - * only the GPL Version 2, indicate your decision by adding "[Contributor] - * elects to include this software in this distribution under the [CDDL or GPL - * Version 2] license." If you don't indicate a single choice of license, a - * recipient has the option to distribute your version of this file under - * either the CDDL, the GPL Version 2 or to extend the choice of license to - * its licensees as provided above. However, if you add GPL Version 2 code - * and therefore, elected the GPL Version 2 license, then the option applies - * only if the new code is made subject to such option by the copyright - * holder. - */ package com.actionbazaar.application; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - +import com.actionbazaar.domain.Bid; +import com.actionbazaar.domain.BidRepository; +import com.actionbazaar.infrastructure.database.MockBidRepository; import javax.ejb.EJB; - import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import org.junit.Test; import org.junit.runner.RunWith; -import com.actionbazaar.domain.Bid; -import com.actionbazaar.domain.BidRepository; -import com.actionbazaar.infrastructure.database.MockBidRepository; - @RunWith(Arquillian.class) public class BidServiceUnitTest { @Deployment public static WebArchive createDeployment() { return ShrinkWrap - .create(WebArchive.class, "actionbazaar-test.war") + .create(WebArchive.class, "actionbazaar-service-unit-test.war") .addClasses(BidService.class, DefaultBidService.class, BidRepository.class, MockBidRepository.class, Bid.class) - .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); + .addAsWebInfResource("test-beans.xml", "beans.xml"); } @EJB diff --git a/actionbazaar/src/test/java/com/actionbazaar/infrastructure/database/MockBidRepository.java b/actionbazaar/src/test/java/com/actionbazaar/infrastructure/database/MockBidRepository.java index ee5eb5c..3c0c2d6 100644 --- a/actionbazaar/src/test/java/com/actionbazaar/infrastructure/database/MockBidRepository.java +++ b/actionbazaar/src/test/java/com/actionbazaar/infrastructure/database/MockBidRepository.java @@ -39,18 +39,27 @@ */ package com.actionbazaar.infrastructure.database; -import com.actionbazaar.domain.BidRepository; import com.actionbazaar.domain.Bid; +import com.actionbazaar.domain.BidRepository; +import java.util.logging.Level; +import java.util.logging.Logger; public class MockBidRepository implements BidRepository { + private static final Logger logger = Logger + .getLogger(MockBidRepository.class.getName()); + @Override public Bid addBid(Bid bid) { + logger.log(Level.INFO, "Mock add bid."); + return bid; } @Override public Bid getBid(Long id) { + logger.log(Level.INFO, "Mock get bid."); + Bid bid = new Bid(); bid.setId(id); bid.setBidder("nrahman"); @@ -62,11 +71,11 @@ public Bid getBid(Long id) { @Override public void updateBid(Bid bid) { - // NOOP + logger.log(Level.INFO, "Mock update bid."); } @Override public void deleteBid(Bid bid) { - // NOOP + logger.log(Level.INFO, "Mock delete bid."); } } diff --git a/actionbazaar/src/test/java/com/actionbazaar/interfaces/rest/BidRestServiceTest.java b/actionbazaar/src/test/java/com/actionbazaar/interfaces/rest/BidRestServiceTest.java index 30bf50e..09ab7ee 100644 --- a/actionbazaar/src/test/java/com/actionbazaar/interfaces/rest/BidRestServiceTest.java +++ b/actionbazaar/src/test/java/com/actionbazaar/interfaces/rest/BidRestServiceTest.java @@ -1,42 +1,3 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common Development - * and Distribution License("CDDL") (collectively, the "License"). You - * may not use this file except in compliance with the License. You can - * obtain a copy of the License at - * http://glassfish.java.net/public/CDDL+GPL_1_1.html - * or packager/legal/LICENSE.txt. See the License for the specific - * language governing permissions and limitations under the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License file at packager/legal/LICENSE.txt. - * - * GPL Classpath Exception: - * Oracle designates this particular file as subject to the "Classpath" - * exception as provided by Oracle in the GPL Version 2 section of the License - * file that accompanied this code. - * - * Modifications: - * If applicable, add the following below the License Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyright [year] [name of copyright owner]" - * - * Contributor(s): - * If you wish your version of this file to be governed by only the CDDL or - * only the GPL Version 2, indicate your decision by adding "[Contributor] - * elects to include this software in this distribution under the [CDDL or GPL - * Version 2] license." If you don't indicate a single choice of license, a - * recipient has the option to distribute your version of this file under - * either the CDDL, the GPL Version 2 or to extend the choice of license to - * its licensees as provided above. However, if you add GPL Version 2 code - * and therefore, elected the GPL Version 2 license, then the option applies - * only if the new code is made subject to such option by the copyright - * holder. - */ package com.actionbazaar.interfaces.rest; import com.actionbazaar.application.BidService; @@ -51,15 +12,15 @@ import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.junit.InSequence; import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import org.junit.Test; import org.junit.runner.RunWith; +// Ran into weird bugs trying to run this on the client. +// Probably another Maven dependency melee. @RunWith(Arquillian.class) -// TODO Move this to client side. public class BidRestServiceTest { private static Long bidId; @@ -67,12 +28,13 @@ public class BidRestServiceTest { @Deployment public static WebArchive createDeployment() { return ShrinkWrap - .create(WebArchive.class, "actionbazaar-test.war") + .create(WebArchive.class, "actionbazaar-rest-test.war") .addClasses(BidRestService.class, RestConfiguration.class, BidService.class, DefaultBidService.class, BidRepository.class, DefaultBidRepository.class, Bid.class) - .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") - .addAsWebInfResource("test-weblogic.xml", "weblogic.xml") + .addAsWebInfResource("test-beans.xml", "beans.xml") + .addAsWebInfResource("test-persistence-web.xml", "web.xml") + .addAsWebInfResource("jboss-deployment-structure.xml", "jboss-deployment-structure.xml") .addAsResource("test-persistence.xml", "META-INF/persistence.xml"); } @@ -81,7 +43,7 @@ public static WebArchive createDeployment() { @InSequence(1) public void testAddBid() { WebTarget target = ClientBuilder.newClient() - .target("http://localhost:7001/actionbazaar-test/rest/bids"); + .target("http://localhost:8080/actionbazaar-rest-test/rest/bids"); // Save a new bid. Bid bid = new Bid(); @@ -106,7 +68,7 @@ public void testAddBid() { @InSequence(2) public void testUpdateBid() { WebTarget target = ClientBuilder.newClient() - .target("http://localhost:7001/actionbazaar-test/rest/bids/{id}") + .target("http://localhost:8080/actionbazaar-rest-test/rest/bids/{id}") .resolveTemplate("id", bidId); // Update bid. @@ -128,7 +90,7 @@ public void testUpdateBid() { @InSequence(3) public void testDeleteBid() { WebTarget target = ClientBuilder.newClient() - .target("http://localhost:7001/actionbazaar-test/rest/bids/{id}") + .target("http://localhost:8080/actionbazaar-rest-test/rest/bids/{id}") .resolveTemplate("id", bidId); target.request().delete(); diff --git a/actionbazaar/src/test/java/com/actionbazaar/interfaces/socket/ChatServerTest.java b/actionbazaar/src/test/java/com/actionbazaar/interfaces/socket/ChatServerTest.java index aefafcb..7e1509c 100644 --- a/actionbazaar/src/test/java/com/actionbazaar/interfaces/socket/ChatServerTest.java +++ b/actionbazaar/src/test/java/com/actionbazaar/interfaces/socket/ChatServerTest.java @@ -42,7 +42,6 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.net.URL; import java.util.Arrays; import java.util.logging.Level; import java.util.logging.Logger; @@ -59,13 +58,14 @@ import javax.websocket.WebSocketContainer; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import static org.junit.Assert.assertEquals; import org.junit.Test; import org.junit.runner.RunWith; +// Ran into weird bugs trying to run this on the client. +// Probably another Maven dependency melee. @RunWith(Arquillian.class) public class ChatServerTest { @@ -75,73 +75,69 @@ public class ChatServerTest { private static ChatMessage testMessage; private static ChatMessage testReply; - @Deployment(testable = false) + @Deployment public static WebArchive createDeployment() { return ShrinkWrap - .create(WebArchive.class, "actionbazaar-test.war") + .create(WebArchive.class, "actionbazaar-websocket-test.war") .addClass(ChatMessage.class) .addClass(ChatServer.class); } @Test - public void testChat() { - try { - URI uri = new URI("ws://localhost:7001/actionbazaar-test/chat"); + public void testChat() throws URISyntaxException, DeploymentException, IOException, InterruptedException { + URI uri = new URI("ws://localhost:8080/actionbazaar-websocket-test/chat"); - WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); - ClientEndpointConfig configuration = ClientEndpointConfig.Builder.create() - .decoders(Arrays.>asList(ChatMessage.class)) - .encoders(Arrays.>asList(ChatMessage.class)) - .build(); + ClientEndpointConfig configuration = ClientEndpointConfig.Builder.create() + .decoders(Arrays.>asList(ChatMessage.class)) + .encoders(Arrays.>asList(ChatMessage.class)) + .build(); - Endpoint client1 = new Endpoint() { - @Override - public void onOpen(Session session, EndpointConfig config) { - try { - session.addMessageHandler(new MessageHandler.Whole() { - @Override - public void onMessage(ChatMessage message) { - testReply = message; - } - }); - session.getBasicRemote().sendObject( - new ChatMessage("rrahman", "Test message")); - } catch (IOException | EncodeException e) { - logger.log(Level.SEVERE, "Error in chat client", e); - } - } - }; - - Endpoint client2 = new Endpoint() { - @Override - public void onOpen(final Session session, final EndpointConfig config) { + Endpoint client1 = new Endpoint() { + @Override + public void onOpen(Session session, EndpointConfig config) { + try { session.addMessageHandler(new MessageHandler.Whole() { @Override public void onMessage(ChatMessage message) { - try { - testMessage = message; - session.getBasicRemote().sendObject(new ChatMessage("nrahman", "Test reply")); - } catch (IOException | EncodeException ex) { - logger.log(Level.SEVERE, "Error responding to message", ex); - } + testReply = message; } }); + session.getBasicRemote().sendObject( + new ChatMessage("rrahman", "Test message")); + } catch (IOException | EncodeException e) { + logger.log(Level.SEVERE, "Error in chat client", e); } - }; + } + }; - container.connectToServer(client2, configuration, uri); - container.connectToServer(client1, configuration, uri); + Endpoint client2 = new Endpoint() { + @Override + public void onOpen(final Session session, final EndpointConfig config) { + session.addMessageHandler(new MessageHandler.Whole() { + @Override + public void onMessage(ChatMessage message) { + try { + testMessage = message; + session.getBasicRemote().sendObject(new ChatMessage("nrahman", "Test reply")); + } catch (IOException | EncodeException ex) { + logger.log(Level.SEVERE, "Error responding to message", ex); + } + } + }); + } + }; + + container.connectToServer(client2, configuration, uri); + container.connectToServer(client1, configuration, uri); - // Wait for conversation to finish. - Thread.sleep(2000); + // Wait for conversation to finish. + Thread.sleep(2000); - assertEquals("rrahman", testMessage.getUser()); - assertEquals("Test message", testMessage.getMessage()); - assertEquals("nrahman", testReply.getUser()); - assertEquals("Test reply", testReply.getMessage()); - } catch (URISyntaxException | DeploymentException | IOException | InterruptedException ex) { - logger.log(Level.SEVERE, "Error connecting to server", ex); - } + assertEquals("rrahman", testMessage.getUser()); + assertEquals("Test message", testMessage.getMessage()); + assertEquals("nrahman", testReply.getUser()); + assertEquals("Test reply", testReply.getMessage()); } } diff --git a/actionbazaar/src/test/java/com/actionbazaar/interfaces/web/AddBidTest.java b/actionbazaar/src/test/java/com/actionbazaar/interfaces/web/AddBidTest.java index 25b4998..d9ad813 100644 --- a/actionbazaar/src/test/java/com/actionbazaar/interfaces/web/AddBidTest.java +++ b/actionbazaar/src/test/java/com/actionbazaar/interfaces/web/AddBidTest.java @@ -1,42 +1,3 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common Development - * and Distribution License("CDDL") (collectively, the "License"). You - * may not use this file except in compliance with the License. You can - * obtain a copy of the License at - * http://glassfish.java.net/public/CDDL+GPL_1_1.html - * or packager/legal/LICENSE.txt. See the License for the specific - * language governing permissions and limitations under the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License file at packager/legal/LICENSE.txt. - * - * GPL Classpath Exception: - * Oracle designates this particular file as subject to the "Classpath" - * exception as provided by Oracle in the GPL Version 2 section of the License - * file that accompanied this code. - * - * Modifications: - * If applicable, add the following below the License Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyright [year] [name of copyright owner]" - * - * Contributor(s): - * If you wish your version of this file to be governed by only the CDDL or - * only the GPL Version 2, indicate your decision by adding "[Contributor] - * elects to include this software in this distribution under the [CDDL or GPL - * Version 2] license." If you don't indicate a single choice of license, a - * recipient has the option to distribute your version of this file under - * either the CDDL, the GPL Version 2 or to extend the choice of license to - * its licensees as provided above. However, if you add GPL Version 2 code - * and therefore, elected the GPL Version 2 license, then the option applies - * only if the new code is made subject to such option by the copyright - * holder. - */ package com.actionbazaar.interfaces.web; import com.actionbazaar.application.BidService; @@ -51,7 +12,6 @@ import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import static org.junit.Assert.assertEquals; import org.junit.Test; @@ -71,14 +31,15 @@ public class AddBidTest { @Deployment(testable = false) public static Archive createDeployment() { return ShrinkWrap - .create(WebArchive.class, "actionbazaar-test.war") + .create(WebArchive.class, "actionbazaar-jsf-test.war") .addClasses(BidService.class, DefaultBidService.class, BidRepository.class, DefaultBidRepository.class, Bid.class, AddBid.class) .addAsWebInfResource("test-web.xml", "web.xml") + .addAsWebInfResource("jboss-deployment-structure.xml", "jboss-deployment-structure.xml") .addAsWebResource("add_bid.xhtml", "add_bid.xhtml") .addAsWebResource("confirm_add_bid.xhtml", "confirm_add_bid.xhtml") - .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") + .addAsWebInfResource("test-beans.xml", "beans.xml") .addAsResource("test-persistence.xml", "META-INF/persistence.xml"); } diff --git a/actionbazaar/src/test/java/com/actionbazaar/interfaces/web/AlertServletTest.java b/actionbazaar/src/test/java/com/actionbazaar/interfaces/web/AlertServletTest.java index b039040..06e7628 100644 --- a/actionbazaar/src/test/java/com/actionbazaar/interfaces/web/AlertServletTest.java +++ b/actionbazaar/src/test/java/com/actionbazaar/interfaces/web/AlertServletTest.java @@ -1,77 +1,26 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common Development - * and Distribution License("CDDL") (collectively, the "License"). You - * may not use this file except in compliance with the License. You can - * obtain a copy of the License at - * http://glassfish.java.net/public/CDDL+GPL_1_1.html - * or packager/legal/LICENSE.txt. See the License for the specific - * language governing permissions and limitations under the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License file at packager/legal/LICENSE.txt. - * - * GPL Classpath Exception: - * Oracle designates this particular file as subject to the "Classpath" - * exception as provided by Oracle in the GPL Version 2 section of the License - * file that accompanied this code. - * - * Modifications: - * If applicable, add the following below the License Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyright [year] [name of copyright owner]" - * - * Contributor(s): - * If you wish your version of this file to be governed by only the CDDL or - * only the GPL Version 2, indicate your decision by adding "[Contributor] - * elects to include this software in this distribution under the [CDDL or GPL - * Version 2] license." If you don't indicate a single choice of license, a - * recipient has the option to distribute your version of this file under - * either the CDDL, the GPL Version 2 or to extend the choice of license to - * its licensees as provided above. However, if you add GPL Version 2 code - * and therefore, elected the GPL Version 2 license, then the option applies - * only if the new code is made subject to such option by the copyright - * holder. - */ package com.actionbazaar.interfaces.web; -import static org.junit.Assert.assertEquals; - -import java.io.File; - import javax.json.JsonObject; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; - import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.jboss.shrinkwrap.resolver.api.maven.Maven; +import static org.junit.Assert.assertEquals; import org.junit.Test; import org.junit.runner.RunWith; +// Ran into weird bugs trying to run this on the client. +// Probably another Maven dependency melee. @RunWith(Arquillian.class) -// TODO Move to client side. public class AlertServletTest { @Deployment public static WebArchive createDeployment() { - WebArchive archive = ShrinkWrap - .create(WebArchive.class, "actionbazaar-test.war") - .addClass(AlertServlet.class) - .addAsWebInfResource("test-weblogic.xml", "weblogic.xml"); - File[] files = Maven - .resolver() - .resolve("org.glassfish.jersey.media:jersey-media-json-processing:2.5.1") - .withTransitivity().asFile(); - archive.addAsLibraries(files); - - return archive; + return ShrinkWrap + .create(WebArchive.class, "actionbazaar-servlet-test.war") + .addClass(AlertServlet.class); } @Test @@ -80,7 +29,7 @@ public void testGetAlerts() { // Get account balance JsonObject response = client - .target("http://localhost:7001/actionbazaar-test/alerts") + .target("http://localhost:8080/actionbazaar-servlet-test/alerts") .queryParam("user_id", "1111").request("application/json") .get(JsonObject.class); // TODO Assert more of the content. diff --git a/actionbazaar/src/test/resources/arquillian.xml b/actionbazaar/src/test/resources/arquillian.xml index e98d17e..0671cfa 100644 --- a/actionbazaar/src/test/resources/arquillian.xml +++ b/actionbazaar/src/test/resources/arquillian.xml @@ -1,19 +1,17 @@ - target/ - + - t3://localhost:7001 - weblogic - welcome123 - C:\Oracle\Middleware\Oracle_Home\wlserver - AdminServer + jboss eap:7.0.0.Final:remote + localhost + admin + YOUR_JBOSSEAP_PASSWORD - + \ No newline at end of file diff --git a/actionbazaar/src/test/resources/jboss-deployment-structure.xml b/actionbazaar/src/test/resources/jboss-deployment-structure.xml new file mode 100644 index 0000000..9f03b31 --- /dev/null +++ b/actionbazaar/src/test/resources/jboss-deployment-structure.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/actionbazaar/src/test/resources/test-beans.xml b/actionbazaar/src/test/resources/test-beans.xml index 2bf376f..0af1b98 100644 --- a/actionbazaar/src/test/resources/test-beans.xml +++ b/actionbazaar/src/test/resources/test-beans.xml @@ -1,8 +1,6 @@ - - - com.actionbazaar.application.ProfilingInterceptor - + xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_2.xsd" + version="1.2" bean-discovery-mode="all"> \ No newline at end of file diff --git a/actionbazaar/src/test/resources/test-persistence-beans.xml b/actionbazaar/src/test/resources/test-persistence-beans.xml new file mode 100644 index 0000000..eefc806 --- /dev/null +++ b/actionbazaar/src/test/resources/test-persistence-beans.xml @@ -0,0 +1,9 @@ + + + + com.actionbazaar.application.ProfilingInterceptor + + \ No newline at end of file diff --git a/actionbazaar/src/test/resources/test-persistence-web.xml b/actionbazaar/src/test/resources/test-persistence-web.xml new file mode 100644 index 0000000..5b8d245 --- /dev/null +++ b/actionbazaar/src/test/resources/test-persistence-web.xml @@ -0,0 +1,11 @@ + + + + java:global/jdbc/ActionBazaarDB + org.h2.jdbcx.JdbcDataSource + jdbc:h2:/tmp/actionbazaar-test-database + + \ No newline at end of file diff --git a/actionbazaar/src/test/resources/test-persistence.xml b/actionbazaar/src/test/resources/test-persistence.xml index d86e9f3..16918a5 100644 --- a/actionbazaar/src/test/resources/test-persistence.xml +++ b/actionbazaar/src/test/resources/test-persistence.xml @@ -1,9 +1,11 @@ - + - jdbc/ActionBazaarDB + java:global/jdbc/ActionBazaarDB diff --git a/actionbazaar/src/test/resources/test-web.xml b/actionbazaar/src/test/resources/test-web.xml index 4bf2f9a..b0a1d82 100644 --- a/actionbazaar/src/test/resources/test-web.xml +++ b/actionbazaar/src/test/resources/test-web.xml @@ -1,8 +1,8 @@ - + javax.faces.PROJECT_STAGE UnitTest @@ -19,4 +19,9 @@ add_bid.jsf + + java:global/jdbc/ActionBazaarDB + org.h2.jdbcx.JdbcDataSource + jdbc:h2:/tmp/actionbazaar-test-database + \ No newline at end of file diff --git a/actionbazaar/src/test/resources/test-weblogic.xml b/actionbazaar/src/test/resources/test-weblogic.xml deleted file mode 100644 index 444d0aa..0000000 --- a/actionbazaar/src/test/resources/test-weblogic.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - jax-rs - 2.0 - false - - \ No newline at end of file