15. Web Application
Main steps
- insertTeacher() requirements
- findTeacher() requirements
- deleteTeacher() requirements
- Run unit tests
- Additional info
Add execution permissions to the geckodriver library1:
cd ~/workspace/JTM/lib
chmod +x geckodriver- 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.
- Investigate package jtm.activity15.
- Implement and annotate required main() method of JettyApplication class and teachers(...) method of JettyController class, to create simple web application.
- Run JettyApplication class as Java application and check in browser page http://localhost:8800/.
- Implement insertTeacher(...), findTeacher(...) and deleteTeacher(...) methods, which:
- respond on appropriate web folders of the application,
- take passed parameters from the web browser,
- call appropriate methods from TeacherManager class in package jtm.activity13 and
- sets success or error status of the response and show returned value as HTML.
insertTeacher() requirements
- Method responds to /insertTeacher folder
- Method takes two optional parameters name and surname
- Method calls insertTeacher(String, String) method of TeacherManager class
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>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>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
- Method responds to /findTeacher folder
- Method takes two optional parameters name and surname
- Method calls findTeacher(String, String) method of TeacherManager class
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>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
- Method responds to /deleteTeacher folder
- Method takes one optional parameters id
- Method calls deleteTeacher(int) method of TeacherManager class
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>When valid parameter is passed, e.g. http://localhost:8800/deleteTeacher?id=5, it returns:
Status: OK
HTML:true<br/>
<a href='/'>Back</a>When invalid parameters ar passed, e.g. http://localhost:8800/deleteTeacher?id=1, it returns:
HTTP status: Bad Requestfalse<br/>
<a href='/'>Back</a>
Run unit tests
- JettyApplicationTest.java is unit test, which test web application using API calls.
- SeleniumWebDriverTests.java is web GUI test, which tests web application by emulating user activities in Firefox browser.
Additional info
For implementation:
- http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestMapping.html
- http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestParam.html
- http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/ResponseBody.html
- https://tomcat.apache.org/tomcat-8.0-doc/servletapi/javax/servlet/http/HttpServletRequest.html
- https://tomcat.apache.org/tomcat-8.0-doc/servletapi/javax/servlet/http/HttpServletResponse.html
For API testing:
For GUI testing:
- ^ 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.