Search in sources :

Example 86 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-cloud-netflix by spring-cloud.

the class RetryableRibbonClientConfiguration method postWithForm.

@Test
public void postWithForm() {
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.set("foo", "bar");
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    ResponseEntity<String> result = testRestTemplate.exchange("/simplerzpat/poster", HttpMethod.POST, new HttpEntity<>(form, headers), String.class);
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals("Posted! {foo=[bar]}", result.getBody());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 87 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-cloud-netflix by spring-cloud.

the class RestClientRibbonCommandIntegrationTests method javascriptEncodedFormParams.

@Override
@SuppressWarnings("deprecation")
@Test
public void javascriptEncodedFormParams() {
    TestRestTemplate testRestTemplate = new TestRestTemplate();
    ArrayList<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.addAll(Arrays.asList(new StringHttpMessageConverter(), new NoEncodingFormHttpMessageConverter()));
    testRestTemplate.getRestTemplate().setMessageConverters(converters);
    MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
    map.add("foo", "(bar)");
    ResponseEntity<String> result = testRestTemplate.postForEntity("http://localhost:" + this.port + "/simple/local", map, String.class);
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals("Posted [(bar)] and Content-Length was: -1!", result.getBody());
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) NoEncodingFormHttpMessageConverter(org.springframework.cloud.netflix.zuul.filters.route.support.NoEncodingFormHttpMessageConverter) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) NoEncodingFormHttpMessageConverter(org.springframework.cloud.netflix.zuul.filters.route.support.NoEncodingFormHttpMessageConverter) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 88 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-cloud-netflix by spring-cloud.

the class ZuulProxyTestBase method javascriptEncodedFormParams.

@SuppressWarnings("deprecation")
@Test
public void javascriptEncodedFormParams() {
    TestRestTemplate testRestTemplate = new TestRestTemplate();
    ArrayList<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.addAll(Arrays.asList(new StringHttpMessageConverter(), new NoEncodingFormHttpMessageConverter()));
    testRestTemplate.getRestTemplate().setMessageConverters(converters);
    MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
    map.add("foo", "(bar)");
    ResponseEntity<String> result = testRestTemplate.postForEntity("http://localhost:" + this.port + "/simple/local", map, String.class);
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals("Posted [(bar)] and Content-Length was: 13!", result.getBody());
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) FormHttpMessageConverter(org.springframework.http.converter.FormHttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) ArrayList(java.util.ArrayList) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) Test(org.junit.Test)

Example 89 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-cloud-netflix by spring-cloud.

the class RibbonCommandContextTest method givenRibbonCommandContextIsSetup.

private void givenRibbonCommandContextIsSetup() {
    LinkedMultiValueMap headers = new LinkedMultiValueMap();
    LinkedMultiValueMap params = new LinkedMultiValueMap();
    RibbonRequestCustomizer requestCustomizer = new RibbonRequestCustomizer<Request.Builder>() {

        @Override
        public boolean accepts(Class builderClass) {
            return builderClass == Request.Builder.class;
        }

        @Override
        public void customize(Request.Builder builder) {
            builder.addHeader("from-customizer", "foo");
        }
    };
    ribbonCommandContext = new RibbonCommandContext("serviceId", HttpMethod.POST.toString(), "/my/route", true, headers, params, new ByteArrayInputStream(TEST_CONTENT), Lists.newArrayList(requestCustomizer));
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ByteArrayInputStream(java.io.ByteArrayInputStream) Request(okhttp3.Request)

Example 90 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-cloud-netflix by spring-cloud.

the class RibbonCommandContextTest method testNullSafetyWithNullableParameters.

@Test
public void testNullSafetyWithNullableParameters() throws Exception {
    LinkedMultiValueMap headers = new LinkedMultiValueMap();
    LinkedMultiValueMap params = new LinkedMultiValueMap();
    RibbonCommandContext testContext = new RibbonCommandContext("serviceId", HttpMethod.POST.toString(), "/my/route", true, headers, params, new ByteArrayInputStream(TEST_CONTENT), Collections.<RibbonRequestCustomizer>emptyList(), null, null);
    assertNotEquals(0, testContext.hashCode());
    assertNotNull(testContext.toString());
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Aggregations

LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)427 Test (org.junit.Test)159 HttpHeaders (org.springframework.http.HttpHeaders)135 MultiValueMap (org.springframework.util.MultiValueMap)102 Test (org.junit.jupiter.api.Test)88 HttpEntity (org.springframework.http.HttpEntity)70 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)45 List (java.util.List)44 HashMap (java.util.HashMap)38 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)37 MediaType (org.springframework.http.MediaType)35 URI (java.net.URI)34 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)33 Map (java.util.Map)32 AbstractReadWriteDtoControllerRestTest (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)30 ArrayList (java.util.ArrayList)29 IOException (java.io.IOException)27 UUID (java.util.UUID)27 lombok.val (lombok.val)27 Autowired (org.springframework.beans.factory.annotation.Autowired)26