If it is not explicitly told in following recipe, setting up services are described for Ubuntu 20.04 server, but applications are described for Xubuntu 20.04 workstation. If you use different Ubuntu version or Linux distribution, settings as well as content, names and places of configuration files may be different!
Got it.

15. Web Application

Tasks

General info

  1. Review presentation Java Web Frameworks

    Practical exercise

  2. Add execution permissions to the geckodriver library1:

    cd  ~/workspace/JTM/lib
    chmod +x geckodriver
  3. If necessary, change server.port=8800 value in .../src/main/resources/application.properties file value to different port number, e.g. 8801 according to the number given to you.
  4. Investigate package jtm.activity15.
  5. Implement and annotate required main() method of JettyApplication class and teachers(...) method of JettyController class, to create simple web application.
  6. Run JettyApplication class as Java application and check in browser page http://localhost:8800/.
  7. Implement insertTeacher(...), findTeacher(...) and deleteTeacher(...) methods, which:
    1. respond on appropriate web folders of the application,
    2. take passed parameters from the web browser,
    3. call appropriate methods from TeacherManager class in package jtm.activity13 and
    4. sets success or error status of the response and show returned value as HTML.

insertTeacher() requirements

  1. Method responds to /insertTeacher folder
  2. Method takes two optional parameters name and surname
  3. Method calls insertTeacher(String, String) method of TeacherManager class
  4. When no parameters are passed, e.g. http://localhost:8800/insertTeacher, is opened it returns:
    Status: OK (200),
    HTML:

    <form action=''>
    Name: <input type='text' name='name' value=''><br/>
    Surname: <input type='text' name='surname' value=''><br/>
    <input type='submit' value='Insert'></form><br/>
    <a href='/'>Back</a>
  5. When valid parameters are passed, e.g. http://localhost:8800/insertTeacher?name=Tom&surname=Tom, it returns:
    Status: OK
    HTML:

    true<br/>
    <a href='/'>Back</a>
  6. When invalid parameters ar passed, e.g. http://localhost:8800/insertTeacher?name=&surname=, it returns:
    HTTP status: Bad Request (400)

    false<br/>
    <a href='/'>Back</a>

findTeacher() requirements

  1. Method responds to /findTeacher folder
  2. Method takes two optional parameters name and surname
  3. Method calls findTeacher(String, String) method of TeacherManager class
  4. When no parameters are passed, e.g. http://localhost:8800/findTeacher, is opened it returns:
    Status: OK,
    HTML:

    <form action=''>
    Name: <input type='text' name='name' value=''><br/>
    Surname: <input type='text' name='surname' value=''><br/>
    <input type='submit' value='Find'></form><br/>
    <a href='/'>Back</a>
  5. When parameters are passed, e.g. http://localhost:8800/findTeacher?name=Tom&surname=Tom, it returns:
    Status OK
    HTML:

    <form action=''>
    Name: <input type='text' name='name' value=''><br/>
    Surname: <input type='text' name='surname' value=''><br/>
    <input type='submit' value='Find'></form><br/>
    <table>
    <tr>
    <td>11</td>
    <td>Tom</td>
    <td>Tom</td>
    </tr>
    </table><br>
    <a href='/'>Back</a>

    where each returned Teacher object is shown in separate row of the table.

deleteTeacher() requirements

  1. Method responds to /deleteTeacher folder
  2. Method takes one optional parameters id
  3. Method calls deleteTeacher(int) method of TeacherManager class
  4. When no parameters are passed, e.g. http://localhost:8800/deleteTeacher, is opened it returns:
    Status: OK,
    HTML:

    <form action=''>
    ID: <input type='text' name='id' value=''><br/>
    <input type='submit' value='Delete'></form><br/>
    <a href='/'>Back</a>
  5. When valid parameter is passed, e.g. http://localhost:8800/deleteTeacher?id=5, it returns:
    Status: OK
    HTML:

    true<br/>
    <a href='/'>Back</a>
  6. When invalid parameters ar passed, e.g. http://localhost:8800/deleteTeacher?id=1, it returns:
    HTTP status: Bad Request

    false<br/>
    <a href='/'>Back</a>

Run unit tests

  1. JettyApplicationTest.java is unit test, which test web application using API calls.
  2. SeleniumWebDriverTests.java is  web GUI test, which tests web application by emulating user activities in Firefox browser.

Additional info

For implementation:

  1. http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestMapping.html
  2. http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestParam.html
  3. http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/ResponseBody.html
  4. https://tomcat.apache.org/tomcat-8.0-doc/servletapi/javax/servlet/http/HttpServletRequest.html
  5. https://tomcat.apache.org/tomcat-8.0-doc/servletapi/javax/servlet/http/HttpServletResponse.html

For API testing:

  1. Spring Boot testing features

For GUI testing:

  1. SeleniumIDE and Plugin for Firefox
  2. Katalon Recorder and Plugin for Firefox

  1. ^ When project is extracted from *.zip file, execution property is lost for all files. Therefore execution permissions of SeleniumWebDriverTests.java file should be restored as Selenium tests need them.

  

Created by Valdis Vītoliņš on 2021-01-27 15:10
Last modified by Valdis Vītoliņš on 2023-04-11 19:16
 
Xwiki Powered
Creative Commons Attribution 3.0 Unported License