當前位置: 首頁>>代碼示例>>Java>>正文


Java MockMvc.perform方法代碼示例

本文整理匯總了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)));
  }
}
 
開發者ID:cloudfoundry-incubator,項目名稱:credhub,代碼行數:21,代碼來源:RequestHelper.java

示例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);
}
 
開發者ID:cloudfoundry-incubator,項目名稱:credhub,代碼行數:21,代碼來源:AuditOAuth2AccessDeniedHandlerTest.java

示例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;

    }
 
開發者ID:ProjectIndoor,項目名稱:projectindoorweb,代碼行數:14,代碼來源:TestHelper.java

示例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


注:本文中的org.springframework.test.web.servlet.MockMvc.perform方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。