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


Java MockMvcRequestBuilders.get方法代碼示例

本文整理匯總了Java中org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get方法的典型用法代碼示例。如果您正苦於以下問題:Java MockMvcRequestBuilders.get方法的具體用法?Java MockMvcRequestBuilders.get怎麽用?Java MockMvcRequestBuilders.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.test.web.servlet.request.MockMvcRequestBuilders的用法示例。


在下文中一共展示了MockMvcRequestBuilders.get方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getHttpResultContent

import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; //導入方法依賴的package包/類
public static MvcResult getHttpResultContent(MockMvc mockMvc, String uri, Method method, Map<String, String> keyvals) throws Exception {

        MockHttpServletRequestBuilder builder = null;
        switch (method) {
            case GET:
                builder = MockMvcRequestBuilders.get(uri);
                break;
            case POST:
                builder = MockMvcRequestBuilders.post(uri);
                break;
            case PUT:
                builder = MockMvcRequestBuilders.put(uri);
                break;
            case DELETE:
                builder = MockMvcRequestBuilders.delete(uri);
                break;
            default:
                builder = MockMvcRequestBuilders.get(uri);
        }
        for (Map.Entry<String, String> entry : keyvals.entrySet()) {
            builder = builder.param(entry.getKey(), entry.getValue());
        }
        MvcResult result = mockMvc.perform(builder.accept(MediaType.ALL)).andReturn();
//        result.getResponse().getHeaderNames();
        return result;
    }
 
開發者ID:aollio,項目名稱:school-express-delivery,代碼行數:27,代碼來源:TestUtil.java

示例2: shouldReturnGameLockerStatus

import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; //導入方法依賴的package包/類
@Test
public void shouldReturnGameLockerStatus() throws Exception {
	MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/api/status");

	mockMvc.perform(requestBuilder)
			.andExpect(status().isOk())
			.andExpect(jsonPath("$.latencySamples[0].latency").value(LATENCY))
			.andExpect(jsonPath("$.errorCount").value(ERROR_COUNT))
			.andExpect(jsonPath("$.successCount").value(SUCCESS_COUNT))
			.andExpect(jsonPath("$.minLatencyInMillis").value(MIN_LATENCY_IN_MILLIS))
			.andExpect(jsonPath("$.maxLatencyInMillis").value(MAX_LATENCY_IN_MILLIS))
			.andExpect(jsonPath("$.shards['NA'].errorCount").value(ERROR_COUNT))
			.andExpect(jsonPath("$.shards['NA'].successCount").value(SUCCESS_COUNT))
			.andExpect(jsonPath("$.shards['NA'].errorCount").value(ERROR_COUNT))
			.andExpect(jsonPath("$.shards['NA'].minLatencyInMillis").value(MIN_LATENCY_IN_MILLIS))
			.andExpect(jsonPath("$.shards['NA'].maxLatencyInMillis").value(MAX_LATENCY_IN_MILLIS))
			.andExpect(jsonPath("$.shards['NA'].meanLatencyInMillis").value(MEAN_LATENCY_IN_MILLIS))
			.andExpect(jsonPath("$.shards['NA'].latencyStandardDeviationInMillis").value(STANDARD_DEVIATION_IN_MILLIS));
}
 
開發者ID:UniteGG,項目名稱:gamelocker-status,代碼行數:20,代碼來源:StatusControllerTest.java

示例3: testList

import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; //導入方法依賴的package包/類
@Test
public void testList() throws Exception {
    //創建書籍列表的請求
    //請求方式為get
    MockHttpServletRequestBuilder mockHttpServletRequestBuilder = MockMvcRequestBuilders.get("/book/listAll.do");
    //此請求並不需要添加請求參數
    mockMvc.perform(mockHttpServletRequestBuilder).andExpect(status().isOk())
            .andDo(print());

}
 
開發者ID:ZHENFENG13,項目名稱:ssm-demo,代碼行數:11,代碼來源:BookControllerTest.java

示例4: requestAndPrint

import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; //導入方法依賴的package包/類
public static MvcResult requestAndPrint(MockMvc mockMvc, String uri, Method method, RequestParams params) throws Exception {


        MockHttpServletRequestBuilder builder = null;
        switch (method) {
            case GET:
                builder = MockMvcRequestBuilders.get(uri);
                break;
            case POST:
                builder = MockMvcRequestBuilders.post(uri);
                break;
            case PUT:
                builder = MockMvcRequestBuilders.put(uri);
                break;
            case DELETE:
                builder = MockMvcRequestBuilders.delete(uri);
                break;
            default:
                builder = MockMvcRequestBuilders.get(uri);
        }

        for (Map.Entry<String, String> entry : params.entrySet()) {
            builder = builder.param(entry.getKey(), entry.getValue());
        }
        MvcResult result = mockMvc.perform(builder.accept(MediaType.ALL)).andReturn();

        Map<String, Object> msg = new LinkedHashMap<>();
        Map<String, Object> json = new LinkedHashMap<>();

        System.out.println(uri + "  " + method.name());
        json.put("params", params);
        json.put("response_body", "null");
        msg.put(method.name(), json);

        System.out.println(new Gson().toJson(msg));
        System.out.println(result.getResponse().getContentAsString());
        return result;
    }
 
開發者ID:aollio,項目名稱:school-express-delivery,代碼行數:39,代碼來源:TestUtil.java

示例5: testAnonymousHeartbeat

import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; //導入方法依賴的package包/類
private Object[][] testAnonymousHeartbeat() {
    return new Object[][] {
            { MockMvcRequestBuilders.get(HEARTBEAT_URL), status().isOk(), content().string("alive") } };
}
 
開發者ID:eclipse,項目名稱:keti,代碼行數:5,代碼來源:SecurityFilterChainTest.java

示例6: testAnonymousHealth

import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; //導入方法依賴的package包/類
private Object[][] testAnonymousHealth() {
    return new Object[][] { { MockMvcRequestBuilders.get(HEALTH_URL), status().isServiceUnavailable(),
            content().string("{\"status\":\"DOWN\"}") } };
}
 
開發者ID:eclipse,項目名稱:keti,代碼行數:5,代碼來源:SecurityFilterChainTest.java


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