Ver código fonte

Revert "compute result worked and then stopped working"

This reverts commit 075680e064349600417a268e06fadc5b67ca7dba.
Trinh Tong 7 anos atrás
pai
commit
7b432ab76b

+ 0
- 12
src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java Ver arquivo

38
         long voteCount = StreamSupport.stream(allVotes.spliterator(), false).count();
38
         long voteCount = StreamSupport.stream(allVotes.spliterator(), false).count();
39
         HashMap<Long, OptionCount> optionCountsMap = new HashMap<>();
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
         for (Vote v: allVotes) {
41
         for (Vote v: allVotes) {
53
             Long optionID = (v.getOption().getId());
42
             Long optionID = (v.getOption().getId());
54
             OptionCount temp;
43
             OptionCount temp;
55
             if (!optionCountsMap.keySet().contains(optionID)) {
44
             if (!optionCountsMap.keySet().contains(optionID)) {
56
                 temp = new OptionCount();
45
                 temp = new OptionCount();
57
-                temp.setOptionId(optionID);
58
                 temp.setCount(1);
46
                 temp.setCount(1);
59
                 optionCountsMap.put(optionID,temp);
47
                 optionCountsMap.put(optionID,temp);
60
             } else {
48
             } else {

+ 2
- 2
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/VoteRepository.java Ver arquivo

9
             "FROM Option o, Vote v " +
9
             "FROM Option o, Vote v " +
10
             "WHERE o.POLL_ID = ?1 " +
10
             "WHERE o.POLL_ID = ?1 " +
11
             "AND v.OPTION_ID = o.OPTION_ID", nativeQuery = true)
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 Ver arquivo

118
      postURLtemplate URL */
118
      postURLtemplate URL */
119
     public void testCreatePollSuccess() throws Exception {
119
     public void testCreatePollSuccess() throws Exception {
120
         Poll testPoll2 = new Poll();
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
         given(pollController.createPoll(testPoll2)).willReturn(null);
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
     @Test
149
     @Test

+ 15
- 0
src/test/java/io/zipcoder/tc_spring_poll_application/controller/VoteControllerTest.java Ver arquivo

140
 
140
 
141
         verify(voteController, times(1)).createVote(pollId, testVote2);
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
     }