|
@@ -118,32 +118,34 @@ 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);
|
128
|
|
-
|
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();
|
134
|
127
|
|
135
|
|
- mvc.perform(post("/polls/{id}",2)
|
|
128
|
+ MockHttpServletResponse response = mvc.perform(post("/polls/2")
|
|
129
|
+ .content(asJsonString(testPoll2))
|
136
|
130
|
.contentType(MediaType.APPLICATION_JSON)
|
137
|
|
- .contentType(asJsonString(testPoll2)))
|
138
|
|
- .andExpect(status().isCreated())
|
139
|
|
- .andExpect(header().string("location", containsString("/polls/2")));
|
|
131
|
+ .accept(MediaType.APPLICATION_JSON))
|
|
132
|
+ .andReturn().getResponse();
|
140
|
133
|
|
141
|
|
- verify(pollController, times(1)).createPoll(testPoll2);
|
|
134
|
+ String header = response.getHeader("Location");
|
142
|
135
|
|
143
|
|
-// String header = response.getHeader("Location");
|
|
136
|
+ Assert.assertEquals(HttpStatus.CREATED.value(),(response.getStatus()));
|
|
137
|
+ Assert.assertEquals(expected, header);
|
|
138
|
+
|
|
139
|
+ // =============== Mockito Version to implement
|
|
140
|
+
|
|
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")));
|
144
|
147
|
//
|
145
|
|
-// Assert.assertEquals(HttpStatus.CREATED.value(),(response.getStatus()));
|
146
|
|
-// Assert.assertEquals(expected, header);
|
|
148
|
+// verify(pollController, times(1)).createPoll(testPoll2);
|
147
|
149
|
}
|
148
|
150
|
|
149
|
151
|
@Test
|