Просмотр исходного кода

Revert "compute result worked and then stopped working"

This reverts commit 075680e064349600417a268e06fadc5b67ca7dba.
Trinh Tong 7 лет назад
Родитель
Сommit
7b432ab76b

+ 0
- 12
src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java Просмотреть файл

@@ -38,23 +38,11 @@ public class ComputeResultController {
38 38
         long voteCount = StreamSupport.stream(allVotes.spliterator(), false).count();
39 39
         HashMap<Long, OptionCount> optionCountsMap = new HashMap<>();
40 40
 
41
-        // Ok now it's grabbing all the votes, BUT the option ID is null??
42
-//        {
43
-//            "totalVotes": 3,
44
-//                "results": [
45
-//            {
46
-//                "optionId": null,
47
-//                    "count": 3
48
-//            }
49
-//    ]
50
-//        }
51
-
52 41
         for (Vote v: allVotes) {
53 42
             Long optionID = (v.getOption().getId());
54 43
             OptionCount temp;
55 44
             if (!optionCountsMap.keySet().contains(optionID)) {
56 45
                 temp = new OptionCount();
57
-                temp.setOptionId(optionID);
58 46
                 temp.setCount(1);
59 47
                 optionCountsMap.put(optionID,temp);
60 48
             } else {

+ 2
- 2
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/VoteRepository.java Просмотреть файл

@@ -9,6 +9,6 @@ public interface VoteRepository extends CrudRepository<Vote, Long> {
9 9
             "FROM Option o, Vote v " +
10 10
             "WHERE o.POLL_ID = ?1 " +
11 11
             "AND v.OPTION_ID = o.OPTION_ID", nativeQuery = true)
12
-    public Iterable<Vote> findVotesByPoll(Long pollId);
13
-}
12
+    Iterable<Vote> findVotesByPoll(Long pollId);
14 13
 
14
+}

+ 18
- 20
src/test/java/io/zipcoder/tc_spring_poll_application/controller/PollControllerTest.java Просмотреть файл

@@ -118,34 +118,32 @@ public class PollControllerTest {
118 118
      postURLtemplate URL */
119 119
     public void testCreatePollSuccess() throws Exception {
120 120
         Poll testPoll2 = new Poll();
121
-        String expected = "http://localhost/polls/2/";
121
+//        String expected = "http://localhost/polls/2/";
122 122
 
123
-        HttpHeaders responseHeader =  new HttpHeaders();
124
-        responseHeader.setLocation(URI.create(expected));
123
+//        HttpHeaders responseHeader =  new HttpHeaders();
124
+//        responseHeader.setLocation(URI.create(expected));
125 125
 
126 126
         given(pollController.createPoll(testPoll2)).willReturn(null);
127
+//        doNothing().when(pollController).createPoll(testPoll2);
127 128
 
128
-        MockHttpServletResponse response = mvc.perform(post("/polls/2")
129
-                .content(asJsonString(testPoll2))
130
-                .contentType(MediaType.APPLICATION_JSON)
131
-                .accept(MediaType.APPLICATION_JSON))
132
-                .andReturn().getResponse();
133
-
134
-        String header = response.getHeader("Location");
129
+//        MockHttpServletResponse response = mvc.perform(post("/polls/2")
130
+//                .content(asJsonString(testPoll2))
131
+//                .contentType(MediaType.APPLICATION_JSON)
132
+//                .accept(MediaType.APPLICATION_JSON))
133
+//                .andReturn().getResponse();
135 134
 
136
-        Assert.assertEquals(HttpStatus.CREATED.value(),(response.getStatus()));
137
-        Assert.assertEquals(expected, header);
135
+        mvc.perform(post("/polls/{id}",2)
136
+                .contentType(MediaType.APPLICATION_JSON)
137
+                .contentType(asJsonString(testPoll2)))
138
+                .andExpect(status().isCreated())
139
+                .andExpect(header().string("location", containsString("/polls/2")));
138 140
 
139
-        // =============== Mockito Version to implement
141
+        verify(pollController, times(1)).createPoll(testPoll2);
140 142
 
141
-//        doNothing().when(pollController).createPoll(testPoll2);
142
-//        mvc.perform(post("/polls/{id}",2)
143
-//                .contentType(MediaType.APPLICATION_JSON)
144
-//                .contentType(asJsonString(testPoll2)))
145
-//                .andExpect(status().isCreated())
146
-//                .andExpect(header().string("location", containsString("/polls/2")));
143
+//        String header = response.getHeader("Location");
147 144
 //
148
-//        verify(pollController, times(1)).createPoll(testPoll2);
145
+//        Assert.assertEquals(HttpStatus.CREATED.value(),(response.getStatus()));
146
+//        Assert.assertEquals(expected, header);
149 147
     }
150 148
 
151 149
     @Test

+ 15
- 0
src/test/java/io/zipcoder/tc_spring_poll_application/controller/VoteControllerTest.java Просмотреть файл

@@ -140,4 +140,19 @@ public class VoteControllerTest {
140 140
 
141 141
         verify(voteController, times(1)).createVote(pollId, testVote2);
142 142
     }
143
+//
144
+//    @Test
145
+//    public void test_create_user_fail_404_not_found() throws Exception {
146
+//        User user = new User("username exists");
147
+//
148
+//        when(userService.exists(user)).thenReturn(true);
149
+//
150
+//        mockMvc.perform(
151
+//                post("/users")
152
+//                        .contentType(MediaType.APPLICATION_JSON)
153
+//                        .content(asJsonString(user)))
154
+//                .andExpect(status().isConflict());
155
+//
156
+//        verify(userService, times(1)).exists(user);
157
+//        verifyNoMoreInteractions(userService);
143 158
     }