Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 0 additions & 85 deletions src/test/java/gov/nih/nci/bento/EsServiceTest.java

This file was deleted.

127 changes: 0 additions & 127 deletions src/test/java/gov/nih/nci/bento/GraphQLControllerTest.java

This file was deleted.

100 changes: 96 additions & 4 deletions src/test/java/gov/nih/nci/bento/IndexControllerTest.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
package gov.nih.nci.bento;

import gov.nih.nci.bento.controller.IndexController;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import static org.junit.Assert.assertNotNull;

@RunWith(SpringRunner.class)
@WebMvcTest(IndexController.class)
public class IndexControllerTest {

@Autowired
private MockMvc mockMvc;

@Before
public void setup() {
this.mockMvc = MockMvcBuilders.standaloneSetup(new IndexController()).build();
}

/**
* Confirm that the "/ping" endpoint accept GET requests and verify the following within the response:
* Http Status Code is 200 (OK)
Expand Down Expand Up @@ -54,4 +57,93 @@ public void pingEndpointTestPOST() throws Exception {
assertNotNull(result);
}

/**
* Confirm that the "/ping" endpoint does NOT accept PUT requests and verify the following within the response:
* Http Status Code is 405 (METHOD NOT ALLOWED)
*
* @throws Exception
*/
@Test
public void pingEndpointTestPUT() throws Exception {
MvcResult result = this.mockMvc.perform(MockMvcRequestBuilders.put("/ping"))
.andExpect(MockMvcResultMatchers.status().isMethodNotAllowed())
.andReturn();
//assert method to satisfy codacy requirement, this statement will not be reached if the test fails
assertNotNull(result);
}

/**
* Confirm that the "/ping" endpoint does NOT accept DELETE requests and verify the following within the response:
* Http Status Code is 405 (METHOD NOT ALLOWED)
*
* @throws Exception
*/
@Test
public void pingEndpointTestDELETE() throws Exception {
MvcResult result = this.mockMvc.perform(MockMvcRequestBuilders.delete("/ping"))
.andExpect(MockMvcResultMatchers.status().isMethodNotAllowed())
.andReturn();
//assert method to satisfy codacy requirement, this statement will not be reached if the test fails
assertNotNull(result);
}

/**
* Confirm that the "/" (root) endpoint accepts GET requests and verify the following within the response:
* Http Status Code is 200 (OK)
* View name is "/index"
*
* @throws Exception
*/
@Test
public void rootEndpointTestGET() throws Exception {
MvcResult result = this.mockMvc.perform(MockMvcRequestBuilders.get("/"))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.view().name("/index"))
.andReturn();
//assert method to satisfy codacy requirement, this statement will not be reached if the test fails
assertNotNull(result);
}

/**
* Confirm that the "/" (root) endpoint accepts POST requests and returns a successful response
*
* @throws Exception
*/
@Test
public void rootEndpointTestPOST() throws Exception {
MvcResult result = this.mockMvc.perform(MockMvcRequestBuilders.post("/"))
.andExpect(MockMvcResultMatchers.status().isOk())
.andReturn();
//assert method to satisfy codacy requirement, this statement will not be reached if the test fails
assertNotNull(result);
}

/**
* Confirm that the "/" (root) endpoint accepts PUT requests and returns a successful response
*
* @throws Exception
*/
@Test
public void rootEndpointTestPUT() throws Exception {
MvcResult result = this.mockMvc.perform(MockMvcRequestBuilders.put("/"))
.andExpect(MockMvcResultMatchers.status().isOk())
.andReturn();
//assert method to satisfy codacy requirement, this statement will not be reached if the test fails
assertNotNull(result);
}

/**
* Confirm that the "/" (root) endpoint accepts DELETE requests and returns a successful response
*
* @throws Exception
*/
@Test
public void rootEndpointTestDELETE() throws Exception {
MvcResult result = this.mockMvc.perform(MockMvcRequestBuilders.delete("/"))
.andExpect(MockMvcResultMatchers.status().isOk())
.andReturn();
//assert method to satisfy codacy requirement, this statement will not be reached if the test fails
assertNotNull(result);
}

}