TS 68 JavaEE Sanity

Revision as of 12:54, 19 April 2010 by Mschovanek (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)

"Java EE Sanity" Test Specification for "NetBeans 6.8"

Author: "Martin Schovanek"
Version: "beta"
Last update: "08/05/2009"
Introduction: "Java EE Validtion Test Specification"
Comments: "Based on http://java.sun.com/javaee/6/docs/firstcup/doc/"


Test suite: "Create Java EE 6 Application"

Purpose: "purpose description"
Setup: "setup description"

  1. "Creating Web Service project"
    1. "Create a new Java Web project, project name: dukes-age, server: GF v3, version: Java EE 6"
    2. "Set the context paht to: /DukeAgeService ."
    3. "Click Finish."
    4. "Delete index.jsp file."
    • EXPECTED RESULT: "You should now see the project you created in Projects pane."
  2. "Create DukeAgeResource class."
    1. "Select File > New File > Web Services > RESTful Web Services from Patterns"
    2. "Clic Next"
    3. "Choose 'Simple Root Resource' design pattern and click Next"
    4. "Set package: firstcup.webservice, path: dukesAge; class name: DukesAgeResource, mime-type: text/plain"
    5. "Click Finish"
    • EXPECTED RESULT: "You should see the DukeAgeResource.java class opened in the Editor."
  3. "Implement the DukeAgeResource class"
    1. "Highlight the putText generated method and their JavaDoc and delete it."
    2. "Highlight the current getText method body and replace it with following implementation:"
// Create a new Calendar for Duke's birthday
Calendar dukesBirthday = new GregorianCalendar(1995, Calendar.MAY, 23);
// Create a new Calendar for today
Calendar now = Calendar.getInstance();

// Subtract today's year from Duke's birth year, 1995
int dukesAge = now.get(Calendar.YEAR) - dukesBirthday.get(Calendar.YEAR);
dukesBirthday.add(Calendar.YEAR, dukesAge);

// If today's date is before May 23, subtract a year from Duke's age
if (now.before(dukesBirthday)) {
// Return a String representation of Duke's age
return Integer.toString(dukesAge);
    1. "Reformat the class, fix imports and save it"
    • EXPECTED RESULT: "there is not any visible error"
  1. "Configure, Build and deploy the Web Servicce Endpoint"
    1. "Right-click on dukes-age in the Projects tab and select Properties > Libraries."
    2. "Uncheck the boxe under Compile-time Libraries for 'retlib_gfv3ee6' library."
    3. "Set 'Run > Relative URL' to /resources/dukesAge."
    4. "Click OK."
    5. "Right click dukes-age and select Run"
    • EXPECTED RESULT: "The dukes-age sucessfully deploys to the GF v3 server, web browser load the URL of the DukesAgeResource path, and you'll see the returned String representing Duke's age."
  2. "Create the Web Application project"
    1. "Create a new Java Web project, project name: firstcup, server: GF v3, version Java EE 6, context path: /firstcup"
    2. "Under Framewroks select select Java Server Faces and set Servlet URL Patter to: /firstcupWeb/*"
    3. "Click Finish"
    4. "Delete the WelcomeJSF.jsp generated file."
    • EXPECTED RESULT: "You should now see the project you created in Projects pane."
  3. "Create the DukesBirthdayBean Enterprise Bean"
    1. "Select File > New File > Java EE > Session Bean"
    2. "Set ejb name: DukesBirthdayBean, package: firstcup.ejb, session type: Stateless"
    3. "Directly after class declaration, paste in following code:"
private static Logger logger = 
public int getAgeDifference(Date date) {
    int ageDifference;

    Calendar theirBirthday = new GregorianCalendar();
    Calendar dukesBirthday = new GregorianCalendar(1995, Calendar.MAY, 23);

    // Set the Calendar object to the passed in Date

    // Subtract the user's age from Duke's age
    ageDifference = dukesBirthday.get(Calendar.YEAR) - 
    logger.info("Raw ageDifference is: " + ageDifference);
    // Check to see if Duke's birthday occurs before the user's. If so, 
    // subtract one from the age difference
    if (dukesBirthday.before(theirBirthday) && (ageDifference > 0)) {
    logger.info("Final ageDifference is: " + ageDifference);

    return ageDifference;
    1. "Reformat the code and Fix Imports (choose: java.util.logging.Logger, java.util.Date)"
    2. "Save the file"
    • EXPECTED RESULT: "there is not any visible error"
  1. "Creata a Resource bundle"
    1. "Select File > New File > Other > Properties File"
    2. "Set file name: WebMessages, folder: src/java/firstcup/web"
    3. "Click Finish"
    4. "Copy the following messages to the file:"
Welcome=Hi. My name is Duke. Let us find out who is older -- You or I. 
DukeIs=Duke is
YearsOldToday=years old today.
Instructions=Enter your birthday and click submit.
YourBD=Your birthday
DateError=Please enter the date in the form MM/dd/yyyy.
YouAre=You are 
Older=older than Duke!
Younger=younger than Duke!
SameAge= the same age as Duke!
    1. "Save the file"
    2. "To add the Spanish translation copy the WebMessages into WebMessages_es and add 'SP:' prefix to each message"
    • EXPECTED RESULT: "You see two new properties files in the project."
  1. "Configure the Resource Bundles"
    1. "Open 'Configuration Files > faces0config.xml'"
    2. "Add an <application> tag with the following: "
    1. "Save the file."
    • EXPECTED RESULT: "You specified the default and supported locale."
  1. "Create the DukesBDay Managed Bean"
    1. "Select the firstcup module node"
    2. "Choose File > New File > JavaServer Faces > JSF Managed Bean"
    3. "Set {Class Name: DukesBDay, Package: firstcup.web, Scope: session}"
    4. "Click Finish"
    5. "Directly after the class declaration add the DukesBirthdayBean reference: "
private DukesBirthdayBean dukesBirthday;
    1. "After the dukesBirthday variable declaration, add the following private variables: "
private int age;
private Date yourBD;
private int ageDiff;
private int absAgeDiff;
private static Logger logger = Logger.getLogger("firstcup.web.DukesBDay");
    1. "Initialize the variables by adding a default constructor: "
public DukesBDay() {
    age = -1;
    yourBD = null;
    ageDiff = -1;
    absAgeDiff = -1;
    1. "Reformat the class."
    2. "Fix imports, choose java.util.Date and java.util.logging.Logger classes."
    3. "Right-click in the editor window."
    4. "Select Refactor > Encapsulate Fields from the popup window."
    5. "In the Encapsulate Fields dialog, select the Create Getter and Create Setter checkboxes for age, yourBD, ageDiff and absAgeDiff."
    6. "Click Refactor."
    7. "Add the following code to the getAge method: "
public int getAge() {
// Use the java.net.* APIs to access the Duke's Age RESTful web service
HttpURLConnection connection = null;
BufferedReader rd = null;
StringBuilder sb = null;
String line = null;
URL serverAddress = null;

try {
serverAddress = new URL(
connection = (HttpURLConnection) serverAddress.openConnection();

// Make the connection to Duke's Age

// Read in the response
rd = new BufferedReader(
    new InputStreamReader(connection.getInputStream()));
sb = new StringBuilder();
while ((line = rd.readLine()) != null) {

// Convert the response to an int
age = Integer.parseInt(sb.toString());
} catch (MalformedURLException e) {
logger.log(Level.WARNING, "A MalformedURLException occurred.", e);
} catch (ProtocolException e) {
logger.log(Level.WARNING, "A ProtocolException occurred.", e);
} catch (IOException e) {
logger.log(Level.WARNING, "An IOException occurred", e);

return age;
    1. "Reformat the class."
    2. "Fix Imports, choose the java.net.HttpURLConnection, java.net.ProtocolException, java.net.URL"
    3. "Inside the getAgeDiff method, directly before the return statement, add the foloowing code: "
ageDiff = dukesBirthday.getAgeDifference(yourBD);
    1. "Reformat the class."
    2. "Save it."
    • EXPECTED RESULT: "The DukesBDay have bean created."
  1. "Modify the web.xml"
    1. "Open firstcup > Configuration FIles > web.xml"
    2. "Expand Context Parameters and delete them all."
    3. "Modify Welcome Files to: firstcupWeb/greeting.xhml"
    4. "Save the file."
    • EXPECTED RESULT: "The web.xml have been sucessfully modified"
  2. "Create the inputDate Composite Component"
    1. "Select firstcup > Web Pages node"
    2. "Choose: File > New File > Other > Folder"
    3. "Enter: resurces/components uder Folder Name and click Finsh."
    4. "Select the resources.components folder"
    5. "Select File > New File > JavaServe Faces > JSF Page and click Next"
    6. "Enter inputDate under File Name and click Finish"
    7. "In the Newly creatd inputDate.xhtml replace the <html> tag with the following: "
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
<composite:attribute name="date" required="true" />
<h:inputText value="#{cc.attrs.date}">
<f:convertDateTime pattern="MM/dd/yyyy" />
    1. "Reformat the page and save it."
    • EXPECTED RESULT: "The inputDate.xhtml component have been created."
  1. "Create the greeting.xhtml page"
    1. "Select the firstcup > Web Pages node."
    2. "Choose File > New File > JavaServer Faces > JSF Page"
    3. "Enter greeting under File Name and click Finish."
    4. "Repeat the previous steps and create a new JSF Page called: response"
    5. "Replace the greeting.xhtml file with the following: "
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
      PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
    <title>Firstcup Greeting Page</title>
        <h:outputText value="#{bundle.Welcome}"/>
    <h:outputText value="#{bundle.DukeIs} "/>
    <h:outputText value="#{dukesBDay.age} #{bundle.YearsOldToday}"/>
    <h:outputText value="#{bundle.Instructions}"/>
    <h:outputText value="#{bundle.YourBD} "/>
    <fc:inputDate id="userBirthday" date="#{dukesBDay.yourBD}" />
    <h:outputText value=" #{bundle.Pattern}"/>
    <h:commandButton value="#{bundle.Submit}" action="response"/>
    <h:message for="userBirthday" style="color:red"/>
    1. "Reformat it and save it."
    2. "Replace the content of response.xhtml with the following: "
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
      PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
    <title>Response Page</title>
    <h:outputText value="#{bundle.YouAre} "/>
    <h:outputText value="#{bundle.SameAge}"
                  rendered="#{dukesBDay.ageDiff == 0}"/>
    <h:outputText value="#{dukesBDay.absAgeDiff}"
                  rendered="#{dukesBDay.ageDiff lt 0}"/>
    <h:outputText value=" #{bundle.Year} "
                  rendered="#{dukesBDay.ageDiff == -1}"/>
    <h:outputText value=" #{bundle.Years} "
                  rendered="#{dukesBDay.ageDiff lt -1}"/>
    <h:outputText value="#{bundle.Younger}"
                  rendered="#{dukesBDay.ageDiff lt 0}"/>
    <h:outputText value="#{dukesBDay.absAgeDiff}"
                  rendered="#{dukesBDay.ageDiff gt 0}"/>
    <h:outputText value=" #{bundle.Year} "
                  rendered="#{dukesBDay.ageDiff == 1}"/>
    <h:outputText value=" #{bundle.Years} "
                  rendered="#{dukesBDay.ageDiff gt 1}"/>
    <h:outputText value="#{bundle.Older}" rendered="#{dukesBDay.ageDiff gt 0}"/>    <p/>
    <h:commandButton id="back" value="#{bundle.Back}" action="greeting"/>
    1. "Reformat it and save it."
    • EXPECTED RESULT: "the greeting.xhtml and response.xhtml pages have been created."
  1. "Run the firstcup application"
    1. "Right-click the firstcup node in the Projects tab and choose Run."
    2. "Enter 01/01/2008 into the Your Birthday text fileld and click Submit."
    • EXPECTED RESULT: "response.xhtml page should display following message: "
You are 13 years younger than Duke!

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo