本文整理汇总了Java中org.springframework.test.web.servlet.MockMvc.perform方法的典型用法代码示例。如果您正苦于以下问题:Java MockMvc.perform方法的具体用法?Java MockMvc.perform怎么用?Java MockMvc.perform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.test.web.servlet.MockMvc
的用法示例。
在下文中一共展示了MockMvc.perform方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: expectErrorWhenDeletingPermissions
import org.springframework.test.web.servlet.MockMvc; //导入方法依赖的package包/类
public static void expectErrorWhenDeletingPermissions(
MockMvc mockMvc,
int status,
String expectedErrorMessage,
String credentialName,
String grantorToken,
String grantee
) throws Exception {
ResultActions result = mockMvc.perform(
delete("/api/v1/permissions?" +
(credentialName == null ? "" : "credential_name=" + credentialName) +
(grantee == null ? "" : "&actor=" + grantee)
).header("Authorization", "Bearer " + grantorToken)
);
result.andExpect(status().is(status));
if (expectedErrorMessage != null) {
result.andExpect(jsonPath("$.error", equalTo(expectedErrorMessage)));
}
}
示例2: setUp
import org.springframework.test.web.servlet.MockMvc; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
MockMvc mockMvc = MockMvcBuilders
.webAppContextSetup(applicationContext)
.apply(springSecurity())
.build();
String bearer = "Bearer " + AuthConstants.INVALID_SCOPE_KEY_JWT;
MockHttpServletRequestBuilder getRequest = get(CREDENTIAL_URL)
.header("Authorization", bearer)
.header("X-Forwarded-For", "1.1.1.1,2.2.2.2")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.with(request -> {
request.setRemoteAddr("12346");
return request;
});
response = mockMvc.perform(getRequest);
}
示例3: addNewBuildingAndRetrieveId
import org.springframework.test.web.servlet.MockMvc; //导入方法依赖的package包/类
public static long addNewBuildingAndRetrieveId(MockMvc mockMvc, MediaType contentType) throws Exception {
ResultActions addBuildingActions = mockMvc.perform(post("/building/addNewBuilding")
.content(TestHelper.jsonify(createGenericBuildingRequestObject()))
.contentType(contentType));
addBuildingActions.andExpect(status().isOk());
String result = addBuildingActions.andReturn().getResponse().getContentAsString();
ResponseWrapper responseWrapper = new ObjectMapper().readValue(result, ResponseWrapper.class);
long buildingId = responseWrapper.getId();
return buildingId;
}
示例4: correctlyRecordsMetricsForFailedDeferredResultResponse
import org.springframework.test.web.servlet.MockMvc; //导入方法依赖的package包/类
@Test
public void correctlyRecordsMetricsForFailedDeferredResultResponse()
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("/createFailure")).andExpect(status().isOk())
.andExpect(request().asyncStarted())
.andExpect(request().attribute(attributeName, is(notNullValue())))
.andReturn();
latch.countDown();
try {
mvc.perform(asyncDispatch(result));
fail();
}
catch (Exception ex) {
assertThat(result.getRequest().getAttribute(attributeName)).isNull();
verify(context.getBean(CounterService.class))
.increment("status.500.createFailure");
}
finally {
context.close();
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:30,代码来源:MetricFilterAutoConfigurationTests.java