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


Java TestRestTemplate.getForEntity方法代碼示例

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


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

示例1: testTraces

import org.springframework.boot.test.web.client.TestRestTemplate; //導入方法依賴的package包/類
@Test(timeout = 180000)
public void testTraces() throws Exception {
    waitForAppsToStart();

    String uri = "http://localhost:" + shoppingCart.port() + "/checkout";
    TestRestTemplate restTemplate = new TestRestTemplate();
    ResponseEntity<String> response = restTemplate.getForEntity(uri, String.class);

    assertEquals("{\"message\":\"order processed successfully\"}", response.getBody());

    Trace shoppingCartTrace = shoppingCart.getTrace();
    Trace ordersTrace = orders.getTrace();
    Trace paymentsTrace = payments.getTrace();

    assertThat(paymentsTrace.getTraceId()).isEqualTo(shoppingCartTrace.getTraceId());
    assertThat(ordersTrace.getTraceId()).isEqualTo(shoppingCartTrace.getTraceId());

    assertThat(paymentsTrace.getParentSpanId()).isEqualTo(ordersTrace.getSpanId());
    assertThat(ordersTrace.getParentSpanId()).isEqualTo(shoppingCartTrace.getSpanId());

    assertThat(shoppingCartTrace.getSpanId()).isNotEqualTo(ordersTrace.getSpanId());
    assertThat(ordersTrace.getSpanId()).isNotEqualTo(paymentsTrace.getSpanId());
}
 
開發者ID:pivotal-cf,項目名稱:pcf-metrics-trace-example-spring,代碼行數:24,代碼來源:TraceTest.java

示例2: i_request_resource

import org.springframework.boot.test.web.client.TestRestTemplate; //導入方法依賴的package包/類
/**
 * Make an api call to /users.
 */
@When("^I get resource \"([/\\w]+)\"$")
public void i_request_resource(String endpoint) {
	TestRestTemplate template = restTemplate;

	if (authenticationWorld.haveCredentials()) {
		template = restTemplate.withBasicAuth(authenticationWorld.getUsername(), authenticationWorld.getPassword());
	}

	ResponseEntity<String> response = template.getForEntity(endpoint, String.class);
	httpWorld.saveResponse(response);
}
 
開發者ID:cmateosl,項目名稱:role-api,代碼行數:15,代碼來源:HttpSteps.java

示例3: page

import org.springframework.boot.test.web.client.TestRestTemplate; //導入方法依賴的package包/類
/**
 * Make an api call to /users.
 */
@When("^I get resource \"([/\\w]+)\" with page (\\d+)$")
public void i_request_resource_with_page(String endpoint, int page) {
	TestRestTemplate template = restTemplate;

	if (authenticationWorld.haveCredentials()) {
		template = restTemplate.withBasicAuth(authenticationWorld.getUsername(), authenticationWorld.getPassword());
	}

	Map<String, String> urlVariables = new HashMap<>();
	urlVariables.put("page", String.valueOf(page));

	ResponseEntity<String> response = template.getForEntity(endpoint + "?page={page}", String.class, urlVariables);
	httpWorld.saveResponse(response);
}
 
開發者ID:cmateosl,項目名稱:role-api,代碼行數:18,代碼來源:HttpSteps.java

示例4: actuatorTest

import org.springframework.boot.test.web.client.TestRestTemplate; //導入方法依賴的package包/類
@Test
public void actuatorTest() throws ExecutionException, InterruptedException {
    final TestRestTemplate template = new TestRestTemplate();

    ResponseEntity<String> response = template.getForEntity("http://localhost:8080/env", String.class);
    assertEquals(HttpStatus.OK, response.getStatusCode());
}
 
開發者ID:LogNet,項目名稱:grpc-spring-boot-starter,代碼行數:8,代碼來源:DemoAppTest.java

示例5: testHome

import org.springframework.boot.test.web.client.TestRestTemplate; //導入方法依賴的package包/類
@Test
public void testHome() throws Exception {
	TestRestTemplate testRestTemplate = new TestRestTemplate(HttpClientOption.SSL);
	ResponseEntity<String> entity = testRestTemplate
			.getForEntity("https://localhost:" + this.port, String.class);
	assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
	assertThat(entity.getBody()).isEqualTo("Hello World");
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:9,代碼來源:SampleJettySslApplicationTests.java

示例6: testHome

import org.springframework.boot.test.web.client.TestRestTemplate; //導入方法依賴的package包/類
@Test
public void testHome() throws Exception {
	TestRestTemplate testRestTemplate = new TestRestTemplate(HttpClientOption.SSL);
	ResponseEntity<String> entity = testRestTemplate
			.getForEntity("https://localhost:" + this.port, String.class);
	assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
	assertThat(entity.getBody()).isEqualTo("Hello, world");
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:9,代碼來源:SampleTomcatSslApplicationTests.java

示例7: everythingIsSecuredByDefault

import org.springframework.boot.test.web.client.TestRestTemplate; //導入方法依賴的package包/類
@Test
public void everythingIsSecuredByDefault() throws Exception {
	TestRestTemplate restTemplate = new TestRestTemplate();
	ResponseEntity<Void> entity = restTemplate
			.getForEntity("http://localhost:" + this.port, Void.class);
	assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
	assertThat(entity.getHeaders().getLocation())
			.isEqualTo(URI.create("http://localhost:" + this.port + "/login"));
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:10,代碼來源:SampleGithubApplicationTests.java

示例8: loginRedirectsToGithub

import org.springframework.boot.test.web.client.TestRestTemplate; //導入方法依賴的package包/類
@Test
public void loginRedirectsToGithub() throws Exception {
	TestRestTemplate restTemplate = new TestRestTemplate();
	ResponseEntity<Void> entity = restTemplate
			.getForEntity("http://localhost:" + this.port + "/login", Void.class);
	assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
	assertThat(entity.getHeaders().getLocation().toString())
			.startsWith("https://github.com/login/oauth");
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:10,代碼來源:SampleGithubApplicationTests.java


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