CSCairney / HobbyWebApplication-Project

Anime Watchlist Directory

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


Logo

Personal Anime Watchlist Directory - By Charles Cairney

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.

Getting Started

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.

Required Prerequisites:

What things you need to install the software and how to install them:

Extra Prerequisites (if you would like to alter the program):

Installing

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!

Example of Build

Step01: Starting up the Jar

Jar Running

Step02: Moving to the localhost8080 in the URL

Moved to localhost8080

Step03: Landing Page

Landing Page

Step04: Now enter the anime details in the forum and click "Create Anime"

Entry Details populated

Testing - How to run them

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 Tests:

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 Tests:

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));
	}

Built With

  • Maven - Dependency Management

Versioning

We use GitHub for versioning.

Authors

License

This project is licensed under the MIT license - see the LICENSE.md file for details

For help in Choosing a license

Acknowledgments

About

Anime Watchlist Directory


Languages

Language:Java 66.0%Language:HTML 20.4%Language:JavaScript 9.8%Language:CSS 3.8%