本文整理匯總了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;
}
示例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));
}
示例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());
}
示例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;
}
示例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") } };
}
示例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\"}") } };
}