Search in sources :

Example 41 with TestRestTemplate

use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.

the class MustacheWebIntegrationTests method testPartialPage.

@Test
public void testPartialPage() throws Exception {
    String body = new TestRestTemplate().getForObject("http://localhost:" + this.port + "/partial", String.class);
    assertThat(body.contains("Hello World")).isTrue();
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 42 with TestRestTemplate

use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.

the class MustacheWebIntegrationTests method testHomePage.

@Test
public void testHomePage() throws Exception {
    String body = new TestRestTemplate().getForObject("http://localhost:" + this.port, String.class);
    assertThat(body.contains("Hello World")).isTrue();
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 43 with TestRestTemplate

use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.

the class SecurityFilterAutoConfigurationEarlyInitializationTests method testSecurityFilterDoesNotCauseEarlyInitialization.

@Test
public void testSecurityFilterDoesNotCauseEarlyInitialization() throws Exception {
    AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext();
    try {
        EnvironmentTestUtils.addEnvironment(context, "server.port:0", "security.user.password:password");
        context.register(Config.class);
        context.refresh();
        int port = context.getWebServer().getPort();
        new TestRestTemplate("user", "password").getForEntity("http://localhost:" + port, Object.class);
    // If early initialization occurred a ConverterNotFoundException is thrown
    } finally {
        context.close();
    }
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) Test(org.junit.Test)

Example 44 with TestRestTemplate

use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.

the class SpringBootWebSecurityConfigurationTests method testHiddenHttpMethodFilterOrderedFirst.

// gh-3447
@Test
public void testHiddenHttpMethodFilterOrderedFirst() throws Exception {
    this.context = SpringApplication.run(DenyPostRequestConfig.class, "--server.port=0");
    int port = Integer.parseInt(this.context.getEnvironment().getProperty("local.server.port"));
    TestRestTemplate rest = new TestRestTemplate();
    // not overriding causes forbidden
    MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
    ResponseEntity<Object> result = rest.postForEntity("http://localhost:" + port + "/", form, Object.class);
    assertThat(result.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
    // override method with GET
    form = new LinkedMultiValueMap<>();
    form.add("_method", "GET");
    result = rest.postForEntity("http://localhost:" + port + "/", form, Object.class);
    assertThat(result.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test)

Example 45 with TestRestTemplate

use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.

the class SampleWildFlyDeployApplicationIT method testHome.

@Test
public void testHome() throws Exception {
    String url = "http://localhost:" + this.port + "/bootapp/";
    ResponseEntity<String> entity = new TestRestTemplate().getForEntity(url, String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(entity.getBody()).isEqualTo("Hello World");
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Test(org.junit.Test)

Aggregations

TestRestTemplate (org.springframework.boot.test.web.client.TestRestTemplate)75 Test (org.junit.Test)67 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)53 Map (java.util.Map)23 HttpHeaders (org.springframework.http.HttpHeaders)15 Before (org.junit.Before)5 RequestEntity (org.springframework.http.RequestEntity)2 OAuth2ContextConfiguration (org.springframework.security.oauth2.client.test.OAuth2ContextConfiguration)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 File (java.io.File)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 JSONArray (net.minidev.json.JSONArray)1 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)1 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1 MethodArgumentNotValidException (org.springframework.web.bind.MethodArgumentNotValidException)1