Note
- Download fitnesse.zip http://selab.fbk.ru/marchetto/software/fitnesseImproved.zip
- Unzip it into the desktop
- Take a note of the directory path
Steps
Download the zip file “NameWeb.zip” and put it in the desktop http://selab.fbk.eu/marchetto/exercise/exe_testing/NameWeb.zip
1. Import it into EclipseFileImport”Existing Project into Workshopace” and click “next” select “Archive File” Browser your desktop to select the “exercise1.zip” click “Finish”
2. In the new Eclipse project: -- (if needed) create a directory called "work" if it doesn't exist -- (if needed) delete subdirectories of the directory "work" if it exist and contains errors
-- (if needed) Start Tomcat or restart it-- open the "Tomcat project" menu (right-button mouse in the project) and update the Tomcat context
3. Start Fitnesse for the imported project (named nameWeb)-- remember to modify the classpath with the path of the fitnesse.zip in your desktop
!path C:/…/fitnesseImproved/lib/*.jar
4. Execute the tasks described in wiki page: a) write Fit tables
b) bug fixingc) maintenanced) evolution
NameWeb is composed of:
1. A client side page named index.html- it contains a form composed of 2 text fields (name and surname) and a submit button - the form sends its data to the JSP page
2. A JSP page named nameWeb.jsp- it gets name and surname sent by the client - it stores name and surname in a JavaBean- it reads the data stored in the JavaBean- it writes in output a string such as “Welcome: name surname”
3. A JavaBean named beanPck.NameBean- it defines a field of type string - it contains two methods used to set/get the string
The NameWeb application
NameWeb –JSP and Form – (1)
Please, insert the requested data for JSP:<br><form method="get" action="nameWeb.jsp" > Name: <input type="text" name="nameJ" /> <br /> Surname: <input type="text" name="surnameJ" /> <br /> <input type="submit" value="submitToJSP" /></form>
index.html
NameWeb – Servlet, JSP and Form – (3)
<HTML> <HEAD>
<TITLE> JSP for name and surname </TITLE> </HEAD><BODY> <P> <jsp:useBean id="beanN" class="beanPck.NameBean" /> <% String name=request.getParameter("nameJ"); String surname=request.getParameter("surnameJ"); beanN.setContent(name, surname); %> <H1>Welcome: <I> <% String content=beanN.getContent(); out.println(content); %> </I> </H1> </BODY></HTML>
nameWeb.jsp
NameWeb – Servlet, JSP and Form – (5)
package beanPck;
public class NameBean {
private String content="anonymous";
public String getContent() { return(content); }
public void setContent(String name, String surname) { content=name+surname; }
}
beanPck.NameBean
The Fitnesse-wiki contained in the Eclipse project to do these tasks:
1) TestingWrite a test-case using the HtmlFixture for testing the application...
2) Bug FixingThere is a bug in the main functionality of the NameWeb application.
3) Maintenance:Refactoring: extract in a function the code used to concatenate name and surname written in the form by the user
4) Evolution:Add a field “nation” in the form so that the new output will be such as:“Welcome: name surname from nation” instead of “Welcome: namesurname”
1) Testing:
Write a test-case using the HtmlFixture for testing the application as follows:
A)- call the index.html- verify that the page does not contain/define a title- verify if the name of the “Surname” field of the HTML form is
“surnameJ” (note that it is an attribute of the element input)- verify how many input of type submit are contained in the page- verify that only 1 form element is contained in the page
B)- call the page index.html- fill the form with “myName” and “mySurname”- click the submit button- verify if the title of the built page is “JSP for name and surname”
|!-com.jbergin.HtmlFixture-!|| http://localhost:8080/NameWeb/index.html | requestPage |?
Test case (A)
|!-com.jbergin.HtmlFixture-!|| http://localhost:8080/NameWeb/index.html | requestPage |?
Test case (B)
!path fitnesse.jar!path *.jar!path lib/*.jar!path classes!path lib
|!-com.jbergin.HtmlFixture-!|| http://localhost:8080/ex2/index.html | requestPage || Focus | requestPage || Element Focus | nameJ | input | textField1 || Set Value | myName || Focus | requestPage || Element Focus | surnameJ | input | textField2 || Set Value | mySurname || Focus | requestPage || Element Focus | f_jsp | form || Submit | response1 || Focus | response1 || Has Text | Welcome: myName mySurname |
Test case
3) Maintenance:
Refactoring: extract in a function the code used to concatenate name and surname written in the form by the user
!path fitnesse.jar!path *.jar!path lib/*.jar!path classes!path lib
|!-com.jbergin.HtmlFixture-!|| http://localhost:8080/ex2/index.html | requestPage || Focus | requestPage || Element Focus | nameJ | input | textField1 || Set Value | myName || Focus | requestPage || Element Focus | surnameJ | input | textField2 || Set Value | mySurname || Focus | requestPage || Element Focus | f_jsp | form || Submit | response1 || Focus | response1 || Has Text | Welcome: myName mySurname |
Test case
package beanPck;
public class NameBean {
private String content="anonymous";
public String getContent() { return(content); }
public void setContent(String name, String surname) { content=concatenate(name, surname); }
public String concatenate(String name, String surname){return name+" "+surname;
}
}
beanPck.NameBean
4) Evolution:
Add a field “nation” in the Form so that the new output will be such as:“Welcome: name surname from nation” instead of “Welcome: name surname”
Test case!path fitnesse.jar!path *.jar!path lib/*.jar!path classes!path lib
|!-com.jbergin.HtmlFixture-!|| http://localhost:8080/ex2/indexEvolution.html | requestPage || Focus | requestPage || Element Focus | nameJ | input | textField1 || Set Value | myName || Focus | requestPage || Element Focus | surnameJ | input | textField2 || Set Value | mySurname || Focus | requestPage || Element Focus | nationJ | input | textField3 || Set Value | myNation || Focus | requestPage || Element Focus | f_jsp | form || Submit | response1 || Focus | response1 || Has Text | Welcome: myName mySurname from myNation |