Presentation is loading. Please wait.

Presentation is loading. Please wait.

Servlet-JSP and HtmlFixture exercise and solution

Similar presentations


Presentation on theme: "Servlet-JSP and HtmlFixture exercise and solution"— Presentation transcript:

1 Servlet-JSP and HtmlFixture exercise and solution
Alessandro Marchetto

2 Exercise: NameWeb, four tasks: a) testing b) bug fixing c) maintenance d) evolution

3 Note - Download fitnesse.zip - Unzip it into the desktop
- Unzip it into the desktop - Take a note of the directory path

4 Steps Download the zip file “NameWeb.zip” and put it in the desktop
1. Import it into Eclipse FileImport”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

5 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 fixing c) maintenance d) evolution

6 The NameWeb application
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

7

8 NameWeb –JSP and Form – (1)
index.html 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" /> <input type="submit" value="submitToJSP" /> </form>

9 NameWeb – Servlet, JSP and Form – (3)
nameWeb.jsp <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>

10 NameWeb – Servlet, JSP and Form – (5)
beanPck.NameBean package beanPck; public class NameBean { private String content="anonymous"; public String getContent() { return(content); } public void setContent(String name, String surname) { content=name+surname;

11 The Fitnesse-wiki contained in the Eclipse project to do these tasks:
1) Testing Write a test-case using the HtmlFixture for testing the application... 2) Bug Fixing There 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: name surname”

12 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”

13 Test case (A) |!-com.jbergin.HtmlFixture-!|
| | requestPage | ?

14 Test case (B) |!-com.jbergin.HtmlFixture-!|
| | requestPage | ?

15 2) Bug fixing: There is a bug in the main functionality of the NameWeb application.

16 Test case !path fitnesse.jar !path *.jar !path lib/*.jar !path classes
|!-com.jbergin.HtmlFixture-!| | | requestPage | | Focus | requestPage | | Element Focus | nameJ | input | textField1 | | Set Value | myName | | Element Focus | surnameJ | input | textField2 | | Set Value | mySurname | | Element Focus | f_jsp | form | | Submit | response1 | | Focus | response1 | | Has Text | Welcome: myName mySurname | Test case

17 JavaBean Before and After bug-fixing

18 3) Maintenance: Refactoring: extract in a function the code used to concatenate name and surname written in the form by the user

19 Test case !path fitnesse.jar !path *.jar !path lib/*.jar !path classes
|!-com.jbergin.HtmlFixture-!| | | requestPage | | Focus | requestPage | | Element Focus | nameJ | input | textField1 | | Set Value | myName | | Element Focus | surnameJ | input | textField2 | | Set Value | mySurname | | Element Focus | f_jsp | form | | Submit | response1 | | Focus | response1 | | Has Text | Welcome: myName mySurname | Test case

20 JavaBean Before and After the task

21 beanPck.NameBean 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;

22 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”

23 Test case !path fitnesse.jar !path *.jar !path lib/*.jar !path classes
|!-com.jbergin.HtmlFixture-!| | | requestPage | | Focus | requestPage | | Element Focus | nameJ | input | textField1 | | Set Value | myName | | Element Focus | surnameJ | input | textField2 | | Set Value | mySurname | | Element Focus | nationJ | input | textField3 | | Set Value | myNation | | Element Focus | f_jsp | form | | Submit | response1 | | Focus | response1 | | Has Text | Welcome: myName mySurname from myNation |

24 Before the evolution

25 After the evolution


Download ppt "Servlet-JSP and HtmlFixture exercise and solution"

Similar presentations


Ads by Google