Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
WTP JEE5 Test Scenarios
Contents
- 1 WTP 2.0 JEE 5 Use Cases
- 2 Test Plan
- 3 Prereqs
- 4 UC-1(a) SIMPLE WEB APPLICATION USE CASE
- 5 UC-1(b) ADD A SERVLET TO SIMPLE WEB APPLICATION USE CASE
- 6 UC-1(c) SIMPLE EJB3 APPLICATION USE CASE
- 7 UC-1(d) EJB3 WEB CLIENT USE CASE
- 8 UC-1(e) EAR5 Combining EJB3 /WEB CLIENT USE CASE
- 9 EXTENDED USE CASES (JPA 1.0 + JSF 1.2)
WTP 2.0 JEE 5 Use Cases
These scenarios are created to test the basic functionality that we would expect from WTP 2.0 to support JEE5. Please note that NO wizards are used other than the ones needed to create the servers, projects and add the necessary facets to these projects. The idea is if we are provided with valid JEE5 module and components (such as EJBs, JPA, Servlets, JSPs, etc), WTP 2.0 should support it. This includes Web, EJB, and EAR and Run As> Run on Server support. Of course this involves basic models for deployment descriptors (sans Annotation injections). Annotation support will only include that provided by JDT.
If you have questions, comments, etc., about these use cases, send a note to the WTP Dev List or contact me, Naci Dai.
Test Plan
As we get close to releasing 2.0, we will report on the status of these use-cases with each I-Build. After an I-Build is declared (Typically on Thursdays), we will run the following use-cases using this build and report any problems via bugzilla. To facilitate easy reporting and searching of these bugs, we will use an indexing key called JEE5-UC in Status Whiteboard. You can use a search like JEE5-UC to list them. Use cases and steps are numbered to make it easy to refer to them.
Please try these use cases or similar ones yourselves and help us improve the quality of WTP tools for 2.0 release.
Prereqs
To try these use cases you will need the latest build of WTP, Apache Tomcat version 6, JDK 1.5 and up, JSF v1.1 Reference Implementation or Apache MyFaces1.1.5, TOPLink Essentials, and Apache Derby. Follow their instructions to install these software. Additionally, EJB/Ear use cases require Apache Geronimo, JBoss v5.0, Glassfish or a similar JEE 5 compatible application server. WTP comes with a server adapter for JBoss v5.0, you can obtain the latest Geronimo adapters for WTP 2.0 from Geronimo Server Adapters, for other servers you will need a WTP server adapter that supports JEE5 features. There is an example glassfish server adapter that me and John Lanuti have created during an eclipsecon 2007 tutorial.
UC-1(a) SIMPLE WEB APPLICATION USE CASE
This use case is the most basic Web application scenario that involves creating the Web module, targeting it to a JEE5 runtime, and testing it using Run As> Run on Server
- Step 1 - Go to Installed Runtimes and add Tomcat 6 as a runtime.
EJB 3.0, and all other WTP JEE5 support should work with any server runtime that has JEE 5 capability such as JBoss, IBM WAS, BEA WebLogic Server, Oracle AS, JOnAS, Apache Geronimo among many others, although there maybe some delays in providing server adapters for all.
- Step 2 - Create a new Dynamic Web Project named HelloWorldWeb, select Tomcat 6 as the target runtime
- Step 3 - Select Dynamic Web Module 2.5, and Java 5 as facets, click next to accept defaults. A new Web 2.5 project is created.
- Step 4 - Click Next. In the next wizard page, you have the option to specify context root and content directories, and option to create a Deployment Descriptor.
Make sure that Generate Deployment Descriptor is checked. WTP will create the web.xml file WebContents/Web-Inf folder. web.xml should look like the following:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5" metadata-complete="true"> </web-app>
- Step 5 - Add a new JSP file called test.jsp with the following content:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> Hello World! </body> </html>
- Step 6 - Right click test.jsp, Choose Run As: Run on Server, select Tomcat 6 as the server
- Step 7 - Tomcat 6 starts and results are correctly displayed (using current code in CVS, 3/28)
UC-1(b) ADD A SERVLET TO SIMPLE WEB APPLICATION USE CASE
This use case adds a servlet to the simple Web application scenario (previos use-case)and testing it using Run As> Run on Server
- Step 1 - Use File->new to choose the Servlet Wizard. Complete the wizard pages to create a Servlet class in a package named demo with the class named HelloWorldServlet. The servlet should be the subclass of HttpServlet. Click next to proceed to the next pages and give the name helloworld to the servlet, /helloworld as the URL mapping and select check the box to create the doGet method.
- Step 2 - The wizard will create the Servlet class and add the required entries to the web.xml file.
<?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>helloworld</servlet-name> <servlet-class>demo.HelloWorldServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>helloworld</servlet-name> <url-pattern>/helloworld</url-pattern> </servlet-mapping> </web-app>
- Step 2 - Edit the Servlet class so that the code looks like the following:
public class HelloWorldServlet extends HttpServlet { @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.getWriter().print("Hello World"); } }
- Step 3 - Right click on the Servlet, Choose Run As: Run on Server, select Tomcat 6 as the server, or after starting Tomcat type thw URL (http://localhost:8080/HelloWorldWeb/helloworld) to test your servlet
- Step 4 - Tomcat 6 starts and results are correctly displayed
UC-1(c) SIMPLE EJB3 APPLICATION USE CASE
This use case is the most basic EJB3 application scenario that involves creating the EJB3 module, targeting it to a JEE5 runtime, and testing it.
- Step 1 - Go to Installed Runtimes and add JBoss v5.0 as a runtime.
EJB 3.0, and all other WTP JEE5 support should work with any server runtime that has JEE 5 capability such as JBoss v5, IBM WAS, BEA WebLogic Server, Oracle AS, JOnAS, Apache Geronimo among many others, although there maybe some delays in providing server adapters for all.
- Step 2 - Create a new EJB Project named HelloWorldEJB, select JBoss v5.0 as the target runtime
- Step 3 - Select EJB Module 3.0, and Java 5 as facets, click next to accept defaults.
- Step 4 - Click Next. In the next wizard page, you have the option to specify source directories, and option to create a Deployment Descriptor.
Make sure that Generate Deployment Descriptor is unchecked. WTP will create the new EJB Project.
- Step 5 - Now we can add a new Stateless EJB. First start with the Interface. Create a new interfaces using the New Interface wizard. Place it in the demo package and name it HelloWorld.
Edit the interface and make sure that the code looks like the following. When you save you will have an error because we did not create the HelloWorldMessage class yet.
public interface HelloWorld { public HelloWorldMessage hello(String language); }
Next we will create the HelloWorldMessage class, which can say HelloWorld in many different languages!
- Step 5 - Create a new class using the New Class wizard. Place it in the demo package and name it HelloWorldMessage. Edit the class and make sure that the code looks like the following. It will have three attributes named id, language and message, getter and setter methods, a toString method that prints the message and constructors. When you save your previos error messages should dissappear.
public class HelloWorldMessage implements Serializable { private static final long serialVersionUID = 1L; //attributes private Long id; private String language; private String message; public HelloWorldMessage() { super(); } public HelloWorldMessage(Long id, String language, String message) { super(); this.id = id; this.language = language; this.message = message; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getLanguage() { return language; } public void setLanguage(String language) { this.language = language; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } @Override public String toString() { return message; } }
- Step 6 - It is time to create the Stateless EJB that implements the HelloWorld interface. Create a new class using the New Class wizard. Place it in the demo package and name it HelloWorldBean.
Edit the class and make sure that the code looks like the following. It will have two annotations @Stateless and @Remote and implements the hello message defined in the interface.
@Stateless(name="HelloWorldStateless") @Remote(HelloWorld.class) public class HelloWorldBean implements HelloWorld { public HelloWorldMessage hello(String language) { // Return a hard coded message for now return new HelloWorldMessage(0L,"en","Hello World!"); } }
That is it for the EJB3 development. You can now create a new Server for the JBoss and deploy our EJB.
- Step 6 - Choose the HelloWorldEJB and choose Run On>Run On Server, and create new new server for JBoss v5.0.
- Step 7 - Add the EJB3 project to the new server.
- Step 8 - Click finish. WTP will deploy the EJB jar to JBoss and start it. When JBoss start you should see a message like the following that confirms that EJB has been deployed to the server succesfully.
17:50:46,875 INFO [Catalina] Server startup in 203 ms 17:50:59,671 INFO [MCKernelAbstraction] installing bean: jboss.j2ee:jar=HelloWorldEJB.jar,name=HelloWorldStateless,service=EJB3 with dependencies: 17:51:02,890 INFO [EJBContainer] STARTED EJB: demo.HelloWorldBean ejbName: HelloWorldStateless
- Step 9 - In the next use case we will extend the simple Web application to be a client to the EJB.
UC-1(d) EJB3 WEB CLIENT USE CASE
This use case is a simple Web client to the previous EJB3 application scenario that involves creating a dependency to the EJB3 module, targeting it to a JEE5 runtime, and testing it.
JBoss v5.0 BUG: If you are using JBoss v5.0 fo testing this use case. There is a JBoss v5.0 bug that prevents WTP from redeploying an EJB jar, ear or a war file to JBoss (see http://jira.jboss.com/jira/browse/JBAS-4310). As a workaround stop the JBoss v5.0 server before you start this use case.
- Step 1 - Go to HelloWorldWeb project and open its properties window. Click on the J2EE dependencies item on the list to choose HelloWorldEJB as a module that our Web application will depend on. By doing this we can access the types defined in the EJB module from the Web application and make remote calls to the stateless EJB.
- Step 2 - Edit the test.jsp JSP to make a call to our EJB. JNDI naming for remote and local EJB interfaces is not prtable among application servers so you will have to identify how it is implemented. For JBoss the suffix /remote is appended to the end of the JNDI name for the EJB. So we will use HelloWorldStateless/remote. Make sure your JSP looks like the following:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@page import="javax.naming.InitialContext"%> <%@page import="demo.HelloWorld"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Hello World</title> </head> <body> <% InitialContext ctx = new InitialContext(); HelloWorld message = (HelloWorld)ctx.lookup("HelloWorldStateless/remote"); %> <%= message.hello("en")%> </body> </html>
- Step 3 - Make sure that your Web project is also targeted to JBoss. To check this go to project properties window and check the JBoss v5.0 as one of the targeted runtimes.
- Step 3 - Select test.jsp file. Right click to choose Run On>Run On Server to test your code. WTP should deploy both Web and EJB modules to the JBoss v5.0 server, start it and display the Hello World message that comes from the EJB using the internal browser.
File:UC1d-StartingServer.png
UC-1(e) EAR5 Combining EJB3 /WEB CLIENT USE CASE
This use case is a simple Enterprise Application v5.0 that combines the previous EJB3 application scenario and the Web Client in an EAR file, targeting it to a JEE5 runtime, and testing it.
- Step 1 - Go to Installed Runtimes and add JBoss v5.0 as a runtime.
EJB 3.0, and all other WTP JEE5 support should work with any server runtime that has JEE 5 capability such as JBoss v5, IBM WAS, BEA WebLogic Server, Oracle AS, JOnAS, Apache Geronimo among many others, although there maybe some delays in providing server adapters for all.
- Step 2 - Create a new Enterprise Application Project named HelloEar, select JBoss v5.0 as the target runtime
File:UC1d-NewEARProject.png
- Step 3 - Select EAR 5.0 click next to accept defaults.
- Step 4 - Click Next. In the next wizard page, you have the option to specify the mdoules in the EAR module. Choose HelloWorldEJB and HelloWorldWeb. If you have started this usecase from scratch, you can create new Web and EJB3 modules and follow the steps described in th eprevious usecases to develop them. Do NOT check the option to create a Deployment Descriptor, EAR 5.0 modules can figure out what is in an EAR module automatically. Click Finish.
- Step 5 - The global JNDI name for the EJB3 changes when an EJB is packaged in an EAR file. Each application server may have its own way of naming the EJBs. Our JSP file in the Web client needs to be edited. For JBoss v5.0, make sure that the code looks like the following:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@page import="javax.naming.InitialContext"%> <%@page import="demo.HelloWorld"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Hello World</title> </head> <body> <% InitialContext ctx = new InitialContext(); HelloWorld message = (HelloWorld)ctx.lookup("HelloEar/HelloWorldStateless/remote"); %> <%= message.hello("en")%> </body> </html>
- Step 6 - Choose the test.jsp, and choose Run On>Run On Server, WTP will deploy the Ear module to the server, start it, open the JSP file and you sill see the Hello World Message.
JBoss v5.0 BUG: If you are using JBoss v5.0 fo testing this use case. There is a JBoss v5.0 bug that prevents WTP from redeploying an EJB jar, ear or a war file to JBoss (see http://jira.jboss.com/jira/browse/JBAS-4310). As a workaround stop the JBoss v5.0 server before you start this use case.
EXTENDED USE CASES (JPA 1.0 + JSF 1.2)
These scenarios extend the use cases described in the first section by adding JPA 1.0 facet to the EJB3 module to persist HelloWorldMessage and using JSF 1.2 for the Web client. They build on the last scenario that combines the EJB3 module and the Web application using an EAR file.
JPA 1.0 use case is and adaptation of the Dali Tutorial. This use case is about building and deploying dynamic web application for an order-entry system using JPA 1.0 and JSF 1.1. The complete application is packaged as a web application.
EJB3 with JPA use case involves creating an EJB 3.0 stateless session bean, that uses JPA 1.0 to map a simple class. A web application using JSF is the EJB client. Whole application is packaged as an EAR.
UC-2(a) EAR5 Combining JPA version of EJB3 /WEB CLIENT USE CASE
This use case is the most creates a simple POJO mapped using JPA 1.0. A stateless session references the entity manager to query the DB. The EJB jar is packaged in an EAR module
- Step 1 - Go to Installed Runtimes and add Glassfish as a runtime.
EJB 3.0, and all other WTP JEE5 support should work with any server runtime that has JEE 5 capability such as JBoss, IBM WAS, BEA WebLogic Server, Oracle AS, JOnAS, Apache Geronimo among many others, although there maybe some delays in providing server adapters for all.
- Step 2 - If you have not done so, create an EJB3 module, a Web module and include them in an EAR module as described in the previous use cases. Follow the step to develop the testçjsp and the HelloWorld EJB.
- Step 3 - Use the data tools to create a connection to the new Derby database named myderbydb. Visit How to create a connection to Derby using DTP if you need assistance to create a DTP connection.
- Step 4 - Create a connection to it and create a new table using the following script:
CREATE TABLE HelloWorldMessage( ID varchar(10) NOT NULL, MESSAGE varchar(50) NOT NULL, LANGUAGE varchar(50) NOT NULL, PRIMARY KEY(ID) );
- Step 5 - Add a few rows of data such as
1 Hello World! en 2 Merhaba Dünya tr
- Step 6 - Choose project properties to add a new Facet. Choose Java Persistence version 1.0. Click Next.
- Step 6 - In the modify facet page, choose the generic platform and the database connection you have created. You will have two choices for JPA implementation, the default one that comes with the server runtime (JBoss v5.0), or choose a specific implementation library. You can use the links below the selection box to define new ones if you have not done so already. Choose Click Next.
- Step 6-Optional- Click on Configure user libraries to define TOPLink Essentials as JPA implementation. Add TOPLink jar and click OK. When you are done choose it as the default JPA library.
- Step 7 - Choose Window>Open Perspective and switch to the JPA Development perspective.
- Step 8 - Edit the HelloWorldMessage class using the Java editor in the JPA Development perspective.
- Step 9 - In the Java editor click on the HelloWorldMessage class text. In the JPA Details view, select Map As: Entity, table name and schema to reflect our choices for this class.
- Step 10 - In the JPA outline click on the attribute id. In the JPA Details view, select Map As: Id.
- Step 11 - When you are done HelloWorldMessage class will look like the following:
@Entity @Table(schema="DALI", name = "HELLOWORLDMESSAGE") public class HelloWorldMessage implements Serializable { private static final long serialVersionUID = 1L; @Id private Long id; private String language; private String message; ...
(Note: We had to add an @Table(schema="DALI", name="HELLOWORLDMESSAGE") in order to get this working.)
- Step 8 - Open your persistence.xml in the META-INF folder. (create one if it does not exists in….) file, and make sure that it looks like:
<?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="HelloWorldPU"> <jta-data-source>jdbc/MyDataSource</jta-data-source> <mapping-file>META-INF/orm.xml</mapping-file> </persistence-unit> </persistence>
- Step 9 - Refer to Application Server manuals to create a new DataSource to the Derby database with the JNDI name “jdbc/MyDataSource”.
(Note: In JBoss you create an XML file in the server/default/deploy folder. In Glassfish, bring up the Admin Console for Glassfish by pointing to http://localhost:4848 and entering userid: admin password: adminadmin)
- Step 10 - Update the code for your EJB3 stateless session bean implementation HelloWorldBean, and make sure that it looks like the following:
@Stateless(name = "HelloWorldStateless", mappedName = "HelloWorldStateless") @Remote(HelloWorld.class) public class HelloWorldBean implements HelloWorld { @PersistenceUnit(name = "HelloWorldPU") EntityManagerFactory emf; public HelloWorldMessage hello(String language) { Query query = emf.createEntityManager().createQuery( "select h from HelloWorld h where h.language = :lang "); query.setParameter("lang", language); List<HelloWorldMessage> list = query.getResultList(); if (list.size() == 0) return list.get(0); return null; } }
- Step 11 - You are done with creating an EJB 3.0 Module. Next you will create a client Web application.
- Step 12 - There is no need to change the Web module now. Select test.jsp, Run As > Run On Server, the ear should be packaged and deployed with EJB and WAR, page should display the message.
UC-2(b) EAR5 Combining JPA version of EJB3 / JSF version WEB CLIENT USE CASE
(Note: THIS SCENARIO HAS NOT BEEN UPDATED YET BECAUSE WE FAIL TO EXECUTE IT WITH THE LATEST DRIVER)
- Step 12 - Create a new Dynamic Web Project (Web 2.5, Java 5, JSF 1.1) named HelloWorldWeb, select GlassFish as the target runtime. Make sure that HelloWorldWeb is also added to the HelloWorldEAR.
- Step 13 - Select Dynamic Web Module 2.5, and Java 5, JSF 1.1 as facets, click next to accept defaults. A new Web 2.5 project is created.
- Step 14 - Go to module dependencies and add a dependency to HelloWorldEJB from HelloWorldWeb
- Step 15 - Add a JSF backing bean called HelloWorldBean as follows:
public class HelloWorldBean implements Serializable { String language= “en”; HelloBeanFacade helloBean; public String hello(){ if(helloBean == null) init(); return helloBean.hello(getLanguage); } public void setLanguage(..) public String getLanguage(..) private void init() { try { //JSF BEANS DO NOT SUPPORT INJECTION WITH // ANNOTATIONS so use Naming Context InitialContext ctx = new InitialContext(); helloBean = (HelloBeanFacade) ctx.lookup("HelloWorldStateless"); } catch (Exception e) { // Handle exception ... } } }
- Step 16 - Add the following managed bean to the faces-config.xml
<faces-config> <managed-bean> <description>hello world</description> <managed-bean-name>helloBean</managed-bean-name> <managed-bean-class> demo.web.HelloWorldBean </managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> ... ...
- Step 17 - Create a new file named hello.jsp. JSP file should look like:
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Hello World</title> <head> <body> <f:view> <h:form> <h:outputText value="#{helloBean.hello}"/> <h:selectOneMenu onchange="submit()" value="#{helloBean.language}" immediate="true"> <f:selectItem itemLabel="en" itemValue="en"/> <f:selectItem itemLabel="tr" itemValue="tr"/> </h:selectOneMenu> </h:form> </f:view> </body> </html>
- Step 18 - Select hello.jsp, Run As > Run On Server, the ear should be packaged and deployed with EJB and WAR, page should display the message.