Skip to content

Commit

Permalink
Added coverage for project controller tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rladdusaw committed Apr 25, 2018
1 parent fa2ca44 commit 523a2c0
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/test/java/edu/tamu/app/controller/ProjectControllerTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.tamu.app.controller;

import static edu.tamu.weaver.response.ApiStatus.ERROR;
import static edu.tamu.weaver.response.ApiStatus.SUCCESS;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
Expand All @@ -13,15 +14,17 @@
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.core.io.ClassPathResource;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestClientException;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
Expand All @@ -33,8 +36,11 @@
import edu.tamu.app.model.repo.ProjectRepo;
import edu.tamu.app.model.repo.VersionManagementSoftwareRepo;
import edu.tamu.app.model.request.FeatureRequest;
import edu.tamu.app.model.request.TicketRequest;
import edu.tamu.app.model.response.VersionProject;
import edu.tamu.app.service.registry.ManagementBeanRegistry;
import edu.tamu.app.service.ticketing.SugarService;
import edu.tamu.app.service.versioning.VersionManagementSoftwareBean;
import edu.tamu.app.service.versioning.VersionOneService;
import edu.tamu.app.utility.JsonNodeUtility;
import edu.tamu.weaver.response.ApiResponse;
Expand All @@ -55,6 +61,9 @@ public class ProjectControllerTest {

private static Project TEST_MODIFIED_PROJECT = new Project(TEST_MODIFIED_PROJECT_NAME);

private static TicketRequest TEST_TICKET_REQUEST = new TicketRequest();
private static FeatureRequest TEST_INVALID_FEATURE_REQUEST = new FeatureRequest();

private static List<Project> mockProjectList = new ArrayList<Project>(Arrays.asList(new Project[] { TEST_PROJECT1, TEST_PROJECT2 }));

private static ApiResponse apiResponse;
Expand All @@ -65,15 +74,25 @@ public class ProjectControllerTest {
@Mock
private VersionManagementSoftwareRepo versionManagementSoftwareRepo;

@Mock
private SugarService sugarService;

@Mock
private ManagementBeanRegistry managementBeanRegistry;

@Mock
private VersionManagementSoftwareBean managementBean;

@Mock
private HttpServletRequest httpServletRequest;

@InjectMocks
private ProjectController projectController;

private ObjectMapper objectMapper;

@Before
@SuppressWarnings("unchecked")
public void setup() {
MockitoAnnotations.initMocks(this);
when(projectRepo.findAll()).thenReturn(mockProjectList);
Expand All @@ -82,6 +101,8 @@ public void setup() {
when(projectRepo.update(any(Project.class))).thenReturn(TEST_MODIFIED_PROJECT);
when(versionManagementSoftwareRepo.findOne(any(Long.class))).thenReturn(TEST_PROJECT1_VERSION_MANAGERMENT_SOFTWARE);
doNothing().when(projectRepo).delete(any(Project.class));
when(sugarService.submit(any(TicketRequest.class))).thenReturn("Successfully submitted issue for test service!");
when(managementBean.push(TEST_INVALID_FEATURE_REQUEST)).thenThrow(RestClientException.class);
objectMapper = new ObjectMapper();
}

Expand Down Expand Up @@ -121,6 +142,12 @@ public void testDelete() {
apiResponse = projectController.deleteProject(TEST_PROJECT1);
assertEquals("Not successful at deleting Project", SUCCESS, apiResponse.getMeta().getStatus());
}

@Test
public void testSubmitIssueRequest() {
apiResponse = projectController.submitIssueRequest(TEST_TICKET_REQUEST);
assertEquals("Not successful at submitting issue request", SUCCESS, apiResponse.getMeta().getStatus());
}

@Test
public void testPushRequest() throws JsonProcessingException, IOException {
Expand All @@ -135,6 +162,12 @@ public void testPushRequest() throws JsonProcessingException, IOException {
JsonNode actualResponse = objectMapper.convertValue(apiResponse.getPayload().get("ObjectNode"), JsonNode.class);
assertEquals("Response of push to version one not as expected!", expectedResponse, actualResponse);
}

@Test
public void testPushRequestToInvalidVMS() {
apiResponse = projectController.pushRequest(httpServletRequest, TEST_INVALID_FEATURE_REQUEST);
assertEquals("Invalid push did not throw an exception", ERROR, apiResponse.getMeta().getStatus());
}

@Test
public void testGetAllVersionProjects() throws JsonProcessingException, IOException {
Expand Down

0 comments on commit 523a2c0

Please sign in to comment.