Search in sources :

Example 56 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 57 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 58 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 59 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 60 with LinkedMultiValueMap

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

the class RequestParamMapMethodArgumentResolverTests method resolveMultiValueMapArgument.

@Test
public void resolveMultiValueMapArgument() throws Exception {
    String name = "foo";
    String value1 = "bar";
    String value2 = "baz";
    request.addParameter(name, value1, value2);
    MultiValueMap<String, String> expected = new LinkedMultiValueMap<>(1);
    expected.add(name, value1);
    expected.add(name, value2);
    MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultiValueMap.class);
    Object result = resolver.resolveArgument(param, null, webRequest, null);
    assertTrue(result instanceof MultiValueMap);
    assertEquals("Invalid result", expected, result);
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) MethodParameter(org.springframework.core.MethodParameter) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test)

Aggregations

LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)76 Test (org.junit.Test)40 HttpHeaders (org.springframework.http.HttpHeaders)20 MultiValueMap (org.springframework.util.MultiValueMap)19 Map (java.util.Map)9 HttpEntity (org.springframework.http.HttpEntity)9 RestTemplate (org.springframework.web.client.RestTemplate)9 ClassPathResource (org.springframework.core.io.ClassPathResource)8 MediaType (org.springframework.http.MediaType)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 Credential (org.apereo.cas.authentication.Credential)4 IdmAuditDto (eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto)3 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)3 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)3 X509CertificateCredential (org.apereo.cas.adaptors.x509.authentication.principal.X509CertificateCredential)3