Skip to content

Commit 64bb729

Browse files
authored
Merge pull request #80 from TAMULib/sprint6-staging-test-improvements
Sprint6 staging test improvements
2 parents 49cad2a + 6782116 commit 64bb729

5 files changed

Lines changed: 122 additions & 5 deletions

File tree

src/test/java/edu/tamu/app/controller/FeatureProposalControllerTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package edu.tamu.app.controller;
22

3+
import static edu.tamu.weaver.response.ApiStatus.INVALID;
34
import static edu.tamu.weaver.response.ApiStatus.SUCCESS;
45
import static org.junit.Assert.assertEquals;
6+
import static org.junit.Assert.assertNotEquals;
57
import static org.mockito.Matchers.any;
68
import static org.mockito.Mockito.doNothing;
79
import static org.mockito.Mockito.when;
@@ -102,7 +104,7 @@ public void setup() throws UserNotFoundException {
102104
when(featureProposalRepo.create(any(FeatureProposal.class), any(Credentials.class))).thenReturn(TEST_FEATURE_PROPOSAL1);
103105
when(featureProposalRepo.create(any(Idea.class))).thenReturn(TEST_FEATURE_PROPOSAL1);
104106
when(featureProposalRepo.update(any(FeatureProposal.class))).thenReturn(TEST_MODIFIED_FEATURE_PROPOSAL);
105-
when(featureProposalRepo.reject(TEST_FEATURE_PROPOSAL1)).thenReturn(rejectedFeatureProposal);
107+
when(featureProposalRepo.reject(featureProposalWithFeedback)).thenReturn(rejectedFeatureProposal);
106108
when(serviceRepo.findOne(any(Long.class))).thenReturn(TEST_SERVICE);
107109
doNothing().when(featureProposalRepo).delete(any(FeatureProposal.class));
108110
doNothing().when(featureProposalRepo).delete(any(FeatureProposal.class));
@@ -156,6 +158,12 @@ public void testReject() {
156158
FeatureProposal featureProposal = (FeatureProposal) response.getPayload().get("FeatureProposal");
157159
assertEquals("State was not set to Rejected", rejectedFeatureProposal.getState(), featureProposal.getState());
158160
}
161+
162+
@Test
163+
public void testInvalidReject() {
164+
response = featureProposalController.reject(TEST_FEATURE_PROPOSAL1);
165+
assertEquals("Ffeature proposal without feedback was not rejected", INVALID, response.getMeta().getStatus());
166+
}
159167

160168
@Test
161169
public void testRemove() {

src/test/java/edu/tamu/app/controller/IdeaControllerTest.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import edu.tamu.app.model.repo.UserRepo;
3636
import edu.tamu.app.model.repo.specification.IdeaSpecification;
3737
import edu.tamu.app.model.request.FilteredPageRequest;
38+
import edu.tamu.app.model.request.IssueRequest;
39+
import edu.tamu.app.service.ProjectService;
3840
import edu.tamu.weaver.auth.model.Credentials;
3941
import edu.tamu.weaver.response.ApiResponse;
4042

@@ -44,6 +46,15 @@ public class IdeaControllerTest {
4446
private static User TEST_USER1 = new User("123456789");
4547
private static User TEST_USER2 = new User("987654321");
4648

49+
private static final Credentials TEST_CREDENTIALS_1 = new Credentials();
50+
static {
51+
TEST_CREDENTIALS_1.setUin("123456789");
52+
TEST_CREDENTIALS_1.setEmail("aggieJack@tamu.edu");
53+
TEST_CREDENTIALS_1.setFirstName("Aggie");
54+
TEST_CREDENTIALS_1.setLastName("Jack");
55+
TEST_CREDENTIALS_1.setRole("ROLE_USER");
56+
}
57+
4758
private static final String TEST_IDEA_TITLE1 = "Test Idea Title 1";
4859
private static final String TEST_IDEA_TITLE2 = "Test Idea Title 2";
4960
private static final String TEST_IDEA_TITLE3 = "Test Idea Title 3";
@@ -56,14 +67,15 @@ public class IdeaControllerTest {
5667
private static final String TEST_FEEDBACK = "Test Rejection Feedback";
5768

5869
private static Service TEST_SERVICE = new Service(TEST_SERVICE_NAME, Status.UP, false, true, true, "", "");
59-
private static Idea TEST_IDEA1 = new Idea(TEST_IDEA_TITLE1, TEST_IDEA_DESCRIPTION1, TEST_USER1);
70+
private static Idea TEST_IDEA1 = new Idea(TEST_IDEA_TITLE1, TEST_IDEA_DESCRIPTION1, TEST_USER1, TEST_SERVICE);
6071
private static Idea TEST_IDEA2 = new Idea(TEST_IDEA_TITLE2, TEST_IDEA_DESCRIPTION2, TEST_USER1);
6172
private static Idea TEST_IDEA3 = new Idea(TEST_IDEA_TITLE3, TEST_IDEA_DESCRIPTION3, TEST_USER1);
6273
private static Idea TEST_MODIFIED_IDEA = new Idea(TEST_MODIFIED_IDEA_TITLE, TEST_MODIFIED_IDEA_DESCRIPTION, TEST_USER2, TEST_SERVICE);
6374
private static Idea ideaWithFeedback = new Idea(TEST_IDEA_TITLE1, TEST_IDEA_DESCRIPTION1, TEST_USER1);
6475
private Idea rejectedIdea = new Idea(TEST_IDEA_TITLE1, TEST_IDEA_DESCRIPTION1, TEST_USER1);
6576
private static List<Idea> mockIdeaList = new ArrayList<Idea>(Arrays.asList(new Idea[] { TEST_IDEA1, TEST_IDEA2, TEST_IDEA3 }));
6677
private static Page<Idea> mockPageableIdeaList = new PageImpl<Idea>(Arrays.asList(new Idea[] { TEST_IDEA1, TEST_IDEA2, TEST_IDEA3 }));
78+
private static IssueRequest TEST_ISSUE_REQUEST = new IssueRequest(TEST_IDEA1, TEST_CREDENTIALS_1);
6779

6880
private static User user = new User("123456789");
6981

@@ -78,6 +90,9 @@ public class IdeaControllerTest {
7890
@Mock
7991
private ServiceRepo serviceRepo;
8092

93+
@Mock
94+
private ProjectService projectService;
95+
8196
@Mock
8297
private SimpMessagingTemplate simpMessagingTemplate;
8398

@@ -102,6 +117,7 @@ public void setup() throws UserNotFoundException {
102117
when(ideaRepo.update(any(Idea.class))).thenReturn(TEST_MODIFIED_IDEA);
103118
when(ideaRepo.reject(TEST_IDEA1)).thenReturn(rejectedIdea);
104119
when(serviceRepo.findOne(any(Long.class))).thenReturn(TEST_SERVICE);
120+
when(projectService.submitIssueRequest(any(IssueRequest.class))).thenReturn(new ApiResponse(SUCCESS, TEST_ISSUE_REQUEST));
105121
doNothing().when(ideaRepo).delete(any(Idea.class));
106122
doNothing().when(ideaRepo).delete(any(Idea.class));
107123
}
@@ -153,7 +169,14 @@ public void testInvalidReject() {
153169
response = ideaController.reject(TEST_IDEA1);
154170
assertEquals("Idea without feedback was successfull", INVALID, response.getMeta().getStatus());
155171
}
156-
172+
173+
@Test
174+
public void testHelpdesk() {
175+
when(ideaRepo.update(any(Idea.class))).thenReturn(TEST_IDEA1);
176+
response = ideaController.helpdesk(TEST_IDEA1, credentials);
177+
assertEquals("Request was not successfull", SUCCESS, response.getMeta().getStatus());
178+
}
179+
157180
@Test
158181
public void testRemove() {
159182
response = ideaController.remove(TEST_MODIFIED_IDEA);

src/test/java/edu/tamu/app/controller/ProjectControllerTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import com.fasterxml.jackson.databind.JsonMappingException;
2828
import com.fasterxml.jackson.databind.ObjectMapper;
2929

30+
import edu.tamu.app.exception.UserNotFoundException;
31+
import edu.tamu.app.model.FeatureProposal;
3032
import edu.tamu.app.model.response.Project;
3133
import edu.tamu.app.service.ProjectService;
3234
import edu.tamu.weaver.response.ApiResponse;
@@ -35,6 +37,9 @@
3537
@RunWith(SpringRunner.class)
3638
public class ProjectControllerTest {
3739

40+
private static String TEST_FEATURE_PROPOSAL_NAME = "Test FP name";
41+
private static String TEST_FEATURE_PROPOSAL_DESCRIPTION = "Test FP name";
42+
private static FeatureProposal TEST_FEATURE_PROPOSAL = new FeatureProposal(TEST_FEATURE_PROPOSAL_NAME, TEST_FEATURE_PROPOSAL_DESCRIPTION);
3843
private static List<Project> projects = new ArrayList<Project>();
3944

4045
@Value("classpath:mock/projects.json")
@@ -52,9 +57,11 @@ public class ProjectControllerTest {
5257
@Before
5358
public void setup() throws JsonParseException, JsonMappingException, IOException {
5459
MockitoAnnotations.initMocks(this);
55-
projects = objectMapper.readValue(resource.getFile(), new TypeReference<List<Project>>() {});
60+
projects = objectMapper.readValue(resource.getFile(), new TypeReference<List<Project>>() {
61+
});
5662
when(projectService.getAll()).thenReturn(new ApiResponse(SUCCESS, projects));
5763
when(projectService.getById(any(Long.class))).thenReturn(new ApiResponse(SUCCESS, projects.get(0)));
64+
when(projectService.submitFeatureRequest(any(FeatureProposal.class))).thenReturn(new ApiResponse(SUCCESS, TEST_FEATURE_PROPOSAL));
5865
}
5966

6067
@Test
@@ -81,4 +88,10 @@ public void getById() throws JsonParseException, JsonMappingException, Malformed
8188
assertEquals("Project did not have the correct name!", projects.get(0).getName(), project.getName());
8289
}
8390

91+
@Test
92+
public void testSubmitFeatureRequest() throws UserNotFoundException {
93+
ApiResponse response = projectController.submitFeatureRequest(TEST_FEATURE_PROPOSAL);
94+
assertEquals("Request was not successfull", SUCCESS, response.getMeta().getStatus());
95+
}
96+
8497
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package edu.tamu.app.controller;
2+
3+
import static edu.tamu.weaver.response.ApiStatus.SUCCESS;
4+
import static org.junit.Assert.assertEquals;
5+
import static org.mockito.Mockito.when;
6+
7+
import org.junit.Before;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
import org.mockito.InjectMocks;
11+
import org.mockito.Mock;
12+
import org.mockito.MockitoAnnotations;
13+
import org.springframework.test.context.junit4.SpringRunner;
14+
15+
import edu.tamu.app.enums.OverallMessageType;
16+
import edu.tamu.app.model.OverallStatus;
17+
import edu.tamu.app.service.MonitorService;
18+
import edu.tamu.weaver.response.ApiResponse;
19+
20+
@RunWith(SpringRunner.class)
21+
public class StatusControllerTest {
22+
23+
private static final String TEST_OVERALL_STATUS_MESSAGE = "Test message";
24+
private static final OverallMessageType TEST_STATUS = OverallMessageType.SUCCESS;
25+
26+
private static OverallStatus TEST_OVERALL_STATUS = new OverallStatus(TEST_STATUS, TEST_OVERALL_STATUS_MESSAGE);
27+
28+
private ApiResponse response;
29+
30+
@Mock
31+
private MonitorService monitorService;
32+
33+
@InjectMocks
34+
private StatusController statusController;
35+
36+
@Before
37+
public void setup() {
38+
MockitoAnnotations.initMocks(this);
39+
when(monitorService.getOverallStatus()).thenReturn(TEST_OVERALL_STATUS);
40+
when(monitorService.getOverallStatusPublic()).thenReturn(TEST_OVERALL_STATUS);
41+
}
42+
43+
@Test
44+
public void testOverallFull() {
45+
response = statusController.overallFull();
46+
assertEquals("Response was not successfull", SUCCESS, response.getMeta().getStatus());
47+
}
48+
49+
@Test
50+
public void testOverallPublic() {
51+
response = statusController.overallPublic();
52+
assertEquals("Response was not successfull", SUCCESS, response.getMeta().getStatus());
53+
}
54+
}

src/test/java/edu/tamu/app/controller/UserControllerTest.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package edu.tamu.app.controller;
22

3+
import static edu.tamu.weaver.response.ApiStatus.ERROR;
34
import static edu.tamu.weaver.response.ApiStatus.SUCCESS;
45
import static org.junit.Assert.assertEquals;
56
import static org.mockito.Matchers.any;
@@ -54,7 +55,7 @@ public class UserControllerTest {
5455

5556
@Mock
5657
private UserRepo userRepo;
57-
58+
5859
@Mock
5960
private SimpMessagingTemplate simpMessagingTemplate;
6061

@@ -74,6 +75,24 @@ public void testCredentials() {
7475
assertEquals("Unable to get user credentials", SUCCESS, apiResponse.getMeta().getStatus());
7576
}
7677

78+
@Test
79+
public void testNullCredentials() {
80+
apiResponse = userController.credentials(null);
81+
assertEquals("Unable to get user credentials", ERROR, apiResponse.getMeta().getStatus());
82+
}
83+
84+
@Test
85+
public void testGetUser() {
86+
apiResponse = userController.getUser(testUser1);
87+
assertEquals("Unable to get user", SUCCESS, apiResponse.getMeta().getStatus());
88+
}
89+
90+
@Test
91+
public void testGetNullUser() {
92+
apiResponse = userController.getUser(null);
93+
assertEquals("Unable to get user", ERROR, apiResponse.getMeta().getStatus());
94+
}
95+
7796
@Test
7897
@SuppressWarnings("unchecked")
7998
public void testAllUsers() throws Exception {

0 commit comments

Comments
 (0)