|
|
@@ -17,7 +17,6 @@ import org.springframework.boot.test.json.JacksonTester;
|
|
17
|
17
|
import org.springframework.http.HttpHeaders;
|
|
18
|
18
|
import org.springframework.http.HttpStatus;
|
|
19
|
19
|
import org.springframework.http.MediaType;
|
|
20
|
|
-import org.springframework.http.ResponseEntity;
|
|
21
|
20
|
import org.springframework.mock.web.MockHttpServletResponse;
|
|
22
|
21
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
23
|
22
|
import org.springframework.test.web.servlet.MockMvc;
|
|
|
@@ -27,14 +26,8 @@ import java.net.URI;
|
|
27
|
26
|
import java.util.Arrays;
|
|
28
|
27
|
|
|
29
|
28
|
import static io.zipcoder.tc_spring_poll_application.JsonTestUtilities.asJsonString;
|
|
30
|
|
-import static org.hamcrest.Matchers.containsString;
|
|
31
|
29
|
import static org.mockito.BDDMockito.given;
|
|
32
|
|
-import static org.mockito.Mockito.doNothing;
|
|
33
|
|
-import static org.mockito.Mockito.times;
|
|
34
|
|
-import static org.mockito.Mockito.verify;
|
|
35
|
30
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
|
36
|
|
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
|
|
37
|
|
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
38
|
31
|
|
|
39
|
32
|
@SpringBootTest
|
|
40
|
33
|
@RunWith(SpringRunner.class)
|
|
|
@@ -118,32 +111,23 @@ public class PollControllerTest {
|
|
118
|
111
|
postURLtemplate URL */
|
|
119
|
112
|
public void testCreatePollSuccess() throws Exception {
|
|
120
|
113
|
Poll testPoll2 = new Poll();
|
|
121
|
|
-// String expected = "http://localhost/polls/2/";
|
|
|
114
|
+ String expected = "http://localhost/polls/2/";
|
|
122
|
115
|
|
|
123
|
|
-// HttpHeaders responseHeader = new HttpHeaders();
|
|
124
|
|
-// responseHeader.setLocation(URI.create(expected));
|
|
|
116
|
+ HttpHeaders responseHeader = new HttpHeaders();
|
|
|
117
|
+ responseHeader.setLocation(URI.create(expected));
|
|
125
|
118
|
|
|
126
|
119
|
given(pollController.createPoll(testPoll2)).willReturn(null);
|
|
127
|
|
-// doNothing().when(pollController).createPoll(testPoll2);
|
|
128
|
120
|
|
|
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
|
|
-
|
|
135
|
|
- mvc.perform(post("/polls/{id}",2)
|
|
|
121
|
+ MockHttpServletResponse response = mvc.perform(post("/polls/2")
|
|
|
122
|
+ .content(asJsonString(testPoll2))
|
|
136
|
123
|
.contentType(MediaType.APPLICATION_JSON)
|
|
137
|
|
- .contentType(asJsonString(testPoll2)))
|
|
138
|
|
- .andExpect(status().isCreated())
|
|
139
|
|
- .andExpect(header().string("location", containsString("/polls/2")));
|
|
|
124
|
+ .accept(MediaType.APPLICATION_JSON))
|
|
|
125
|
+ .andReturn().getResponse();
|
|
140
|
126
|
|
|
141
|
|
- verify(pollController, times(1)).createPoll(testPoll2);
|
|
|
127
|
+ String header = response.getHeader("Location");
|
|
142
|
128
|
|
|
143
|
|
-// String header = response.getHeader("Location");
|
|
144
|
|
-//
|
|
145
|
|
-// Assert.assertEquals(HttpStatus.CREATED.value(),(response.getStatus()));
|
|
146
|
|
-// Assert.assertEquals(expected, header);
|
|
|
129
|
+ Assert.assertEquals(HttpStatus.CREATED.value(),(response.getStatus()));
|
|
|
130
|
+ Assert.assertEquals(expected, header);
|
|
147
|
131
|
}
|
|
148
|
132
|
|
|
149
|
133
|
@Test
|