Search in sources :

Example 46 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-boot by spring-projects.

the class SampleWebSecureCustomApplicationTests method testLogin.

@Test
public void testLogin() throws Exception {
    HttpHeaders headers = getHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
    form.set("username", "user");
    form.set("password", "user");
    ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, new HttpEntity<>(form, headers), String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
    assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/");
    assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull();
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 47 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-boot by spring-projects.

the class SampleWebSecureJdbcApplicationTests method testLogin.

@Test
public void testLogin() throws Exception {
    HttpHeaders headers = getHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
    form.set("username", "user");
    form.set("password", "user");
    ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, new HttpEntity<>(form, headers), String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
    assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/");
    assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull();
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 48 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-boot by spring-projects.

the class SampleSecureApplicationTests method testLogin.

@Test
public void testLogin() throws Exception {
    HttpHeaders headers = getHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
    form.set("username", "user");
    form.set("password", "user");
    ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, new HttpEntity<>(form, headers), String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
    assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/");
    assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull();
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 49 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-boot by spring-projects.

the class SampleWebUiApplicationTests method testCreate.

@Test
public void testCreate() throws Exception {
    MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
    map.set("text", "FOO text");
    map.set("summary", "FOO");
    URI location = this.restTemplate.postForLocation("/", map);
    assertThat(location.toString()).contains("localhost:" + this.port);
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) URI(java.net.URI) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 50 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-boot by spring-projects.

the class LinksEnhancer method addEndpointLinks.

public void addEndpointLinks(ResourceSupport resource, String self) {
    if (!resource.hasLink("self")) {
        resource.add(linkTo(LinksEnhancer.class).slash(this.rootPath + self).withSelfRel());
    }
    MultiValueMap<String, String> added = new LinkedMultiValueMap<>();
    for (MvcEndpoint endpoint : this.endpoints.getEndpoints()) {
        if (!endpoint.getPath().equals(self)) {
            String rel = getRel(endpoint);
            List<String> paths = added.get(rel);
            if (paths == null || !paths.contains(endpoint.getPath())) {
                addEndpointLink(resource, endpoint, rel);
                added.add(rel, endpoint.getPath());
            }
        }
    }
}
Also used : MvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint) NamedMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.NamedMvcEndpoint) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Aggregations

LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)66 Test (org.junit.Test)32 HttpHeaders (org.springframework.http.HttpHeaders)20 MultiValueMap (org.springframework.util.MultiValueMap)18 Map (java.util.Map)9 HttpEntity (org.springframework.http.HttpEntity)9 ClassPathResource (org.springframework.core.io.ClassPathResource)7 MediaType (org.springframework.http.MediaType)7 RestTemplate (org.springframework.web.client.RestTemplate)7 URI (java.net.URI)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 Resource (org.springframework.core.io.Resource)5 HashMap (java.util.HashMap)4 FileItem (org.apache.commons.fileupload.FileItem)4 HttpCookie (org.springframework.http.HttpCookie)3 Cookie (io.netty.handler.codec.http.cookie.Cookie)2 Charset (java.nio.charset.Charset)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 StringTokenizer (java.util.StringTokenizer)2