This repo is for the creation of a personal hobby web application for QA. Here I have choosen to build a personal anime watchlist directory that allows users to actively read, create, update and delete entries into their personal watchlist to keep track of their proggress on shows they are currently watching/intend to watch.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system including maven packaging and how the frontend will be loaded once the JAR has been executed.
What things you need to install the software and how to install them:
- You will need the the Java SE Development kit which can be found here
https://www.oracle.com/java/technologies/downloads/ - You will also need a version of MySQL Community including MySQL Workbench
https://dev.mysql.com/downloads/windows/installer/8.0.html
- You wil need a version of gitbash for terminal access
https://git-scm.com/downloads - You will need spring boot IDE for API alterations
https://spring.io/tools - You will need VS code for any CSS, HTML or Javascript changes
https://code.visualstudio.com/download - You will need to have Apache Maven for testing
https://maven.apache.org/download.cgi - - With Maven you will need two dependencies:
Here is how to acquire and get the program running:
STEP01:
Clone the Repo into a safe location on your personal computer.
STEP02:
In the Root Folder HobbyWebApplication-Project
- Open CMD or GitBash
- Type "java -jar JuneEnableSpring-0.0.1-SNAPSHOT.jar"
- Now the application will be running in the background and if you wish to stop the application from running. Go back to the CMD or gitbash terminal, make sure the window is active and then click CTRL-C.
STEP03:
Now the application is running in the background
- Open Chrome Browser
- Type "localhost8080" in URL
- Enjoy!
Step01: Starting up the Jar
Step02: Moving to the localhost8080 in the URL
Step03: Landing Page
Step04: Now enter the anime details in the forum and click "Create Anime"
Coverage: 87%
Once all Prerequisites have been complete you gain access to the testing feature through the src/test/java.
- Select folder with right click.
- Select "Coverage As"
- Select "JUnit test" This will run all the tests and generate a coverage table indicating how much of the code has been covered in the testing and what percentage passed/failed/errored.
Unit testing is a testing method where you test smaller isolated pieces of code that can be used logically by setting up condition to use before testing.
An example of where unit testing was used in our project was for the testing the anime controller method of create, here the unit testing was applied by using Mockito to "mock" the actions of the methods dependences. Shown below the create method relied on Anime service therefore Mocktio mocked what to do when the method called the service.create.
@Test
void createTest() throws Exception {
Anime entry = new Anime("e", "j", 1, 5, 5, true);
String entryAsJSON = mapper.writeValueAsString(entry);
//Create an Object to check result
Anime result = new Anime(2L, "e", "j", 1, 5, 5, true);
String resultAsJSON = mapper.writeValueAsString(result);
Mockito.when(service.create(entry)).thenReturn(result);
mvc.perform(post("/Anime/create")
.contentType(MediaType.APPLICATION_JSON)
.content(entryAsJSON))
.andExpect(content().json(resultAsJSON));
}
@Test
void updateTest() throws Exception {
//Create an Object to check result
Anime result = new Anime(1L, "english", "japanese", 1, 10, 5, true);
String resultAsJSON = mapper.writeValueAsString(result);
Mockito.when(service.update(1L, result)).thenReturn(result);
mvc.perform(put("/Anime/update/1")
.contentType(MediaType.APPLICATION_JSON)
.content(resultAsJSON))
.andExpect(content().json(resultAsJSON));
}
@Test
public void testGetAll() {
//Create objects of Anime
List<Anime> result = new ArrayList<>();
result.add(new Anime("e", "j", 1, 5, 5, true));
Mockito.when(repo.findAll()).thenReturn(result);
assertEquals(result, service.getAll());
}
Integration testing is where you test multiple combined components of a application to see if they logically work together and produce the correct outcome.
Here we used Integration testing also for our controller and service classes.
@Test
public void createTest() throws Exception {
//Create an Object for posting
Anime entry = new Anime("e", "j", 1, 5, 5, true);
String entryAsJSON = mapper.writeValueAsString(entry);
//Create an Object to check result
Anime result = new Anime(2L, "e", "j", 1, 5, 5, true);
String resultAsJSON = mapper.writeValueAsString(result);
mvc.perform(post("/Anime/create")
.contentType(MediaType.APPLICATION_JSON)
.content(entryAsJSON))
.andExpect(content().json(resultAsJSON));
}
@Test
public void readAllTest() throws Exception {
//Create a list to cehck the output of readAll
List<Anime> result = new ArrayList<>();
//Add the single entry to the list
result.add(new Anime(1L, "english", "japanese", 1, 10, 5, true));
//converts the list to a JSON (As API responds in JSON)
String resultAsJSON = mapper.writeValueAsString(result);
mvc.perform(get("/Anime/getAll")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(content().json(resultAsJSON));
}
@Test
public void updateTest() throws Exception {
//Create an Object for posting
Anime result = new Anime(1L, "english", "japanese", 1, 10, 5, true);
String resultAsJSON = mapper.writeValueAsString(result);
mvc.perform(put("/Anime/update/1")
.contentType(MediaType.APPLICATION_JSON)
.content(resultAsJSON))
.andExpect(content().json(resultAsJSON));
}
- Maven - Dependency Management
We use GitHub for versioning.
- Charles Cairney - Final Product - CharlesCairney
This project is licensed under the MIT license - see the LICENSE.md file for details
For help in Choosing a license
- Trainer - AnoushLowton
- Trainer - JordanBenBelaid
- Trainer - Edward Reynolds
- Trainer - Piers Barber
- Testing Developer - JUnit