11package edu .tamu .app .controller ;
22
3+ import static edu .tamu .weaver .response .ApiStatus .INVALID ;
34import static edu .tamu .weaver .response .ApiStatus .SUCCESS ;
45import static org .junit .Assert .assertEquals ;
56import static org .mockito .Matchers .any ;
2324import org .springframework .messaging .simp .SimpMessagingTemplate ;
2425import org .springframework .test .context .junit4 .SpringRunner ;
2526
27+ import edu .tamu .app .enums .IdeaState ;
2628import edu .tamu .app .enums .Status ;
2729import edu .tamu .app .exception .UserNotFoundException ;
2830import edu .tamu .app .model .Idea ;
@@ -51,12 +53,15 @@ public class IdeaControllerTest {
5153 private static final String TEST_MODIFIED_IDEA_TITLE = "Modified Idea Title" ;
5254 private static final String TEST_MODIFIED_IDEA_DESCRIPTION = "Modified Idea Description" ;
5355 private static final String TEST_SERVICE_NAME = "Test Service" ;
56+ private static final String TEST_FEEDBACK = "Test Rejection Feedback" ;
5457
5558 private static Service TEST_SERVICE = new Service (TEST_SERVICE_NAME , Status .UP , false , true , true , "" , "" );
5659 private static Idea TEST_IDEA1 = new Idea (TEST_IDEA_TITLE1 , TEST_IDEA_DESCRIPTION1 , TEST_USER1 );
5760 private static Idea TEST_IDEA2 = new Idea (TEST_IDEA_TITLE2 , TEST_IDEA_DESCRIPTION2 , TEST_USER1 );
5861 private static Idea TEST_IDEA3 = new Idea (TEST_IDEA_TITLE3 , TEST_IDEA_DESCRIPTION3 , TEST_USER1 );
5962 private static Idea TEST_MODIFIED_IDEA = new Idea (TEST_MODIFIED_IDEA_TITLE , TEST_MODIFIED_IDEA_DESCRIPTION , TEST_USER2 , TEST_SERVICE );
63+ private static Idea ideaWtihFeedback = new Idea (TEST_IDEA_TITLE1 , TEST_IDEA_DESCRIPTION1 , TEST_USER1 );
64+ private Idea rejectedIdea = new Idea (TEST_IDEA_TITLE1 , TEST_IDEA_DESCRIPTION1 , TEST_USER1 );
6065 private static List <Idea > mockIdeaList = new ArrayList <Idea >(Arrays .asList (new Idea [] { TEST_IDEA1 , TEST_IDEA2 , TEST_IDEA3 }));
6166 private static Page <Idea > mockPageableIdeaList = new PageImpl <Idea >(Arrays .asList (new Idea [] { TEST_IDEA1 , TEST_IDEA2 , TEST_IDEA3 }));
6267
@@ -85,6 +90,8 @@ public class IdeaControllerTest {
8590 @ Before
8691 @ SuppressWarnings ("unchecked" )
8792 public void setup () throws UserNotFoundException {
93+ rejectedIdea .setState (IdeaState .REJECTED );
94+ ideaWtihFeedback .setFeedback (TEST_FEEDBACK );
8895 MockitoAnnotations .initMocks (this );
8996 when (credentials .getUin ()).thenReturn ("123456789" );
9097 when (userRepo .findByUsername (any (String .class ))).thenReturn (Optional .of (user ));
@@ -93,6 +100,7 @@ public void setup() throws UserNotFoundException {
93100 when (ideaRepo .findOne (any (Long .class ))).thenReturn (TEST_IDEA1 );
94101 when (ideaRepo .create (any (Idea .class ), any (Credentials .class ))).thenReturn (TEST_IDEA1 );
95102 when (ideaRepo .update (any (Idea .class ))).thenReturn (TEST_MODIFIED_IDEA );
103+ when (ideaRepo .reject (TEST_IDEA1 )).thenReturn (rejectedIdea );
96104 when (serviceRepo .findOne (any (Long .class ))).thenReturn (TEST_SERVICE );
97105 doNothing ().when (ideaRepo ).delete (any (Idea .class ));
98106 doNothing ().when (ideaRepo ).delete (any (Idea .class ));
@@ -132,6 +140,20 @@ public void testUpdate() {
132140 assertEquals ("Notification Author was not properly updated" , TEST_MODIFIED_IDEA .getAuthor (), idea .getAuthor ());
133141 }
134142
143+ @ Test
144+ public void testReject () {
145+ response = ideaController .reject (ideaWtihFeedback );
146+ assertEquals ("Not successful at rejecting idea" , SUCCESS , response .getMeta ().getStatus ());
147+ Idea idea = (Idea ) response .getPayload ().get ("Idea" );
148+ assertEquals ("State was not set to Rejected" , rejectedIdea .getState (), idea .getState ());
149+ }
150+
151+ @ Test
152+ public void testInvalidReject () {
153+ response = ideaController .reject (TEST_IDEA1 );
154+ assertEquals ("Idea without feedback was successfull" , INVALID , response .getMeta ().getStatus ());
155+ }
156+
135157 @ Test
136158 public void testRemove () {
137159 response = ideaController .remove (TEST_MODIFIED_IDEA );
0 commit comments