use of org.springframework.test.web.servlet.MockMvc in project spring-framework by spring-projects.
the class MultipartControllerTests method multipartRequestWrapped.
// SPR-13317
@Test
public void multipartRequestWrapped() throws Exception {
byte[] json = "{\"name\":\"yeeeah\"}".getBytes(StandardCharsets.UTF_8);
MockMultipartFile jsonPart = new MockMultipartFile("json", "json", "application/json", json);
Filter filter = new RequestWrappingFilter();
MockMvc mockMvc = standaloneSetup(new MultipartController()).addFilter(filter).build();
Map<String, String> jsonMap = Collections.singletonMap("name", "yeeeah");
mockMvc.perform(multipart("/test-json").file(jsonPart)).andExpect(model().attribute("json", jsonMap));
}
use of org.springframework.test.web.servlet.MockMvc in project spring-framework by spring-projects.
the class HtmlUnitRequestBuilderTests method mergeSession.
@Test
public void mergeSession() throws Exception {
String attrName = "PARENT";
String attrValue = "VALUE";
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new HelloController()).defaultRequest(get("/").sessionAttr(attrName, attrValue)).build();
assertThat(mockMvc.perform(requestBuilder).andReturn().getRequest().getSession().getAttribute(attrName), equalTo(attrValue));
}
use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.
the class MetricFilterAutoConfigurationTests method correctlyRecordsMetricsForDeferredResultResponse.
@Test
public void correctlyRecordsMetricsForDeferredResultResponse() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetricFilterAutoConfiguration.class);
MetricsFilter filter = context.getBean(MetricsFilter.class);
CountDownLatch latch = new CountDownLatch(1);
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController(latch)).addFilter(filter).build();
String attributeName = MetricsFilter.class.getName() + ".StopWatch";
MvcResult result = mvc.perform(post("/create")).andExpect(status().isOk()).andExpect(request().asyncStarted()).andExpect(request().attribute(attributeName, is(notNullValue()))).andReturn();
latch.countDown();
mvc.perform(asyncDispatch(result)).andExpect(status().isCreated()).andExpect(request().attribute(attributeName, is(nullValue())));
verify(context.getBean(CounterService.class)).increment("status.201.create");
context.close();
}
use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.
the class MetricFilterAutoConfigurationTests method recordsHttpInteractionsWithRegexTemplateVariable.
@Test
public void recordsHttpInteractionsWithRegexTemplateVariable() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetricFilterAutoConfiguration.class);
Filter filter = context.getBean(Filter.class);
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController()).addFilter(filter).build();
mvc.perform(get("/templateVarRegexTest/foo")).andExpect(status().isOk());
verify(context.getBean(CounterService.class)).increment("status.200.templateVarRegexTest.someVariable");
verify(context.getBean(GaugeService.class)).submit(eq("response.templateVarRegexTest.someVariable"), anyDouble());
context.close();
}
use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.
the class MetricFilterAutoConfigurationTests method controllerMethodThatThrowsUnhandledException.
@Test
public void controllerMethodThatThrowsUnhandledException() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetricFilterAutoConfiguration.class);
Filter filter = context.getBean(Filter.class);
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController()).addFilter(filter).build();
try {
mvc.perform(get("/unhandledException")).andExpect(status().isInternalServerError());
} catch (NestedServletException ex) {
// Expected
}
verify(context.getBean(CounterService.class)).increment("status.500.unhandledException");
verify(context.getBean(GaugeService.class)).submit(eq("response.unhandledException"), anyDouble());
context.close();
}
Aggregations