Example usage for org.springframework.util MultiValueMap add

List of usage examples for org.springframework.util MultiValueMap add

Introduction

In this page you can find the example usage for org.springframework.util MultiValueMap add.

Prototype

void add(K key, @Nullable V value);

Source Link

Document

Add the given single value to the current list of values for the given key.

Usage

From source file:com.fns.grivet.service.NamedQueryServiceSprocTest.java

@Test
public void testSuccessfulNamedQueryExecution() throws IOException {
    Resource r = resolver.getResource("classpath:TestSprocQuery.json");
    String json = IOUtils.toString(r.getInputStream(), Charset.defaultCharset());
    NamedQuery namedQuery = objectMapper.readValue(json, NamedQuery.class);
    namedQueryService.create(namedQuery);

    MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
    Timestamp tomorrow = Timestamp.valueOf(LocalDateTime.now().plusDays(1));
    params.add("createdTime", tomorrow);
    String result = namedQueryService.get("sproc.getAttributesCreatedBefore", params);
    String[] expected = { "bigint", "varchar", "decimal", "datetime", "int", "text", "json", "boolean" };
    List<String> actual = JsonPath.given(result).getList("NAME");
    Assertions.assertTrue(actual.size() == 8, "Result should contain 8 attributes");
    Assertions.assertTrue(actual.containsAll(Arrays.asList(expected)));
}

From source file:org.cloudfoundry.identity.app.integration.AuthenticationIntegrationTests.java

@Test
public void formLoginSucceeds() throws Exception {

    ResponseEntity<Void> result;
    String location;//from w ww. j a v  a  2s.co  m
    String cookie;

    HttpHeaders uaaHeaders = new HttpHeaders();
    HttpHeaders appHeaders = new HttpHeaders();
    uaaHeaders.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    appHeaders.setAccept(Arrays.asList(MediaType.TEXT_HTML));

    // *** GET /app/id
    result = serverRunning.getForResponse("/id", appHeaders);
    assertEquals(HttpStatus.FOUND, result.getStatusCode());
    location = result.getHeaders().getLocation().toString();

    cookie = result.getHeaders().getFirst("Set-Cookie");
    assertNotNull("Expected cookie in " + result.getHeaders(), cookie);
    appHeaders.set("Cookie", cookie);

    assertTrue("Wrong location: " + location, location.contains("/oauth/authorize"));
    // *** GET /uaa/oauth/authorize
    result = serverRunning.getForResponse(location, uaaHeaders);
    assertEquals(HttpStatus.FOUND, result.getStatusCode());
    location = result.getHeaders().getLocation().toString();

    cookie = result.getHeaders().getFirst("Set-Cookie");
    assertNotNull("Expected cookie in " + result.getHeaders(), cookie);
    uaaHeaders.set("Cookie", cookie);

    assertTrue("Wrong location: " + location, location.contains("/login"));
    location = serverRunning.getAuthServerUrl("/login.do");

    MultiValueMap<String, String> formData;
    formData = new LinkedMultiValueMap<String, String>();
    formData.add("username", testAccounts.getUserName());
    formData.add("password", testAccounts.getPassword());

    // *** POST /uaa/login.do
    result = serverRunning.postForResponse(location, uaaHeaders, formData);

    cookie = result.getHeaders().getFirst("Set-Cookie");
    assertNotNull("Expected cookie in " + result.getHeaders(), cookie);
    uaaHeaders.set("Cookie", cookie);

    assertEquals(HttpStatus.FOUND, result.getStatusCode());
    location = result.getHeaders().getLocation().toString();

    assertTrue("Wrong location: " + location, location.contains("/oauth/authorize"));
    // *** GET /uaa/oauth/authorize
    result = serverRunning.getForResponse(location, uaaHeaders);

    // If there is no token in place already for this client we get the approval page.
    // TODO: revoke the token so we always get the approval page
    if (result.getStatusCode() == HttpStatus.OK) {
        location = serverRunning.getAuthServerUrl("/oauth/authorize");

        formData = new LinkedMultiValueMap<String, String>();
        formData.add("user_oauth_approval", "true");

        // *** POST /uaa/oauth/authorize
        result = serverRunning.postForResponse(location, uaaHeaders, formData);
    }

    location = result.getHeaders().getLocation().toString();

    // SUCCESS
    assertTrue("Wrong location: " + location, location.contains("/id"));

    // *** GET /app/id
    result = serverRunning.getForResponse(location, appHeaders);
    // System.err.println(result.getHeaders());
    assertEquals(HttpStatus.OK, result.getStatusCode());
}

From source file:org.cloudfoundry.identity.uaa.login.integration.AuthorizationCodeGrantIntegrationTests.java

@Test
public void testSuccessfulAuthorizationCodeFlow() throws Exception {

    HttpHeaders headers = new HttpHeaders();
    // TODO: should be able to handle just TEXT_HTML
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML, MediaType.ALL));

    AuthorizationCodeResourceDetails resource = testAccounts.getDefaultAuthorizationCodeResource();

    URI uri = serverRunning.buildUri("/oauth/authorize").queryParam("response_type", "code")
            .queryParam("state", "mystateid").queryParam("client_id", resource.getClientId())
            .queryParam("redirect_uri", resource.getPreEstablishedRedirectUri()).build();
    ResponseEntity<Void> result = serverRunning.getForResponse(uri.toString(), headers);
    assertEquals(HttpStatus.FOUND, result.getStatusCode());
    String location = result.getHeaders().getLocation().toString();

    if (result.getHeaders().containsKey("Set-Cookie")) {
        String cookie = result.getHeaders().getFirst("Set-Cookie");
        headers.set("Cookie", cookie);
    }//from w ww. ja v  a 2 s  .  c  o  m

    ResponseEntity<String> response = serverRunning.getForString(location, headers);
    // should be directed to the login screen...
    String body = response.getBody();
    assertTrue(body.contains("/login.do"));
    assertTrue(body.contains("username"));
    assertTrue(body.contains("password"));

    MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
    formData.add("username", testAccounts.getUserName());
    formData.add("password", testAccounts.getPassword());

    // Should be redirected to the original URL, but now authenticated
    result = serverRunning.postForResponse("/login.do", headers, formData);
    assertEquals(HttpStatus.FOUND, result.getStatusCode());

    if (result.getHeaders().containsKey("Set-Cookie")) {
        String cookie = result.getHeaders().getFirst("Set-Cookie");
        headers.set("Cookie", cookie);
    }

    response = serverRunning.getForString(result.getHeaders().getLocation().toString(), headers);
    if (response.getStatusCode() == HttpStatus.OK) {
        body = response.getBody();
        // The grant access page should be returned
        assertTrue(body.contains("Application Authorization"));
        // Forms should have the right action
        assertTrue(body.matches("(?s).*\\saction=\"\\S*oauth/authorize\".*"));

        formData.clear();
        formData.add("user_oauth_approval", "true");
        result = serverRunning.postForResponse("/oauth/authorize", headers, formData);
        assertEquals(HttpStatus.FOUND, result.getStatusCode());
        location = result.getHeaders().getLocation().toString();
    } else {
        // Token cached so no need for second approval
        assertEquals(HttpStatus.FOUND, response.getStatusCode());
        location = response.getHeaders().getLocation().toString();
    }
    assertTrue("Wrong location: " + location,
            location.matches(resource.getPreEstablishedRedirectUri() + ".*code=.+"));
    assertFalse("Location should not contain cookie: " + location,
            location.matches(resource.getPreEstablishedRedirectUri() + ".*cookie=.+"));

    formData.clear();
    formData.add("client_id", resource.getClientId());
    formData.add("redirect_uri", resource.getPreEstablishedRedirectUri());
    formData.add("grant_type", "authorization_code");
    formData.add("code", location.split("code=")[1].split("&")[0]);
    HttpHeaders tokenHeaders = new HttpHeaders();
    tokenHeaders.set("Authorization",
            testAccounts.getAuthorizationHeader(resource.getClientId(), resource.getClientSecret()));
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> tokenResponse = serverRunning.postForMap("/oauth/token", formData, tokenHeaders);
    assertEquals(HttpStatus.OK, tokenResponse.getStatusCode());
}

From source file:com.fns.grivet.service.NamedQueryServiceSprocTest.java

@Test
public void testNamedQueryNotFound() throws IOException {
    Assertions.assertThrows(IllegalArgumentException.class, () -> {
        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
        Timestamp tomorrow = Timestamp.valueOf(LocalDateTime.now().plusDays(1));
        params.add("createdTime", tomorrow);
        namedQueryService.get("sproc.getAttributesCreatedBefore", params);
    });/*  w w w.  jav  a2s . c o  m*/
}

From source file:com.fns.grivet.service.NamedQueryServiceSprocTest.java

@Test
public void testNamedQueryNotExecutedBecauseParamSuppliedForExecutionNotCorrectlyNamed() throws IOException {
    Assertions.assertThrows(IllegalArgumentException.class, () -> {
        Resource r = resolver.getResource("classpath:TestSprocQuery.json");
        String json = IOUtils.toString(r.getInputStream(), Charset.defaultCharset());
        NamedQuery namedQuery = objectMapper.readValue(json, NamedQuery.class);
        namedQueryService.create(namedQuery);

        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
        Timestamp tomorrow = Timestamp.valueOf(LocalDateTime.now().plusDays(1));
        params.add("timeCreated", tomorrow);
        namedQueryService.get("sproc.getAttributesCreatedBefore", params);
    });/*w ww.j  a va 2s  .  c  om*/
}

From source file:com.weibo.api.Statuses.java

/**
 * http://open.weibo.com/wiki/2/statuses/destroy
 * @param id//from w  w w  . java2 s  . c  o  m
 * @param accessToken
 * @return
 */
public Status destroy(String id, String accessToken) {
    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
    map.add("id", id);
    map.add("access_token", accessToken);
    return weiboHttpClient.postForm(STATUSES_DESTROY_URL, map, Status.class);
}

From source file:com.weibo.api.Statuses.java

/**
 * http://open.weibo.com/wiki/2/statuses/filter/create
 * @deprecated TODO: need to added testcase.
 * @param id// w  ww. j  a va 2  s  .c  o  m
 * @param accessToken
 * @return
 */
public Status filterCreate(String id, String accessToken) {
    MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
    map.add("id", id);
    map.add("access_token", accessToken);
    return weiboHttpClient.postForm(STATUSES_FILTER_CREATE_URL, map, Status.class);
}

From source file:com.weibo.api.Statuses.java

/**
 * http://open.weibo.com/wiki/2/statuses/mentions/shield
 * @deprecated TODO: need to added testcase.
 * @param id//  w w w.  j  a v  a  2s  . c o  m
 * @param followUp
 * @param accessToken
 * @return
 */
public Result mentionsShield(String id, String followUp, String accessToken) {
    MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
    map.add("id", id);
    map.add("follow_up", followUp);
    map.add("access_token", accessToken);
    return weiboHttpClient.postForm(STATUSES_MENTIONS_SHIELD_URL, map, Result.class);
}

From source file:fr.itldev.koya.services.impl.KoyaContentServiceImpl.java

private Document upload(User user, NodeRef parent, Object o) throws AlfrescoServiceException {
    MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
    parts.add("filedata", o);
    parts.add("destination", parent.toString());
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.MULTIPART_FORM_DATA);
    HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(parts, headers);
    AlfrescoUploadReturn upReturn = fromJSON(new TypeReference<AlfrescoUploadReturn>() {
    }, user.getRestTemplate().postForObject(getAlfrescoServerUrl() + REST_POST_UPLOAD, request, String.class));

    return (Document) getSecuredItem(user, upReturn.getNodeRef());

}

From source file:com.weibo.api.OAuth2.java

/**
 * http://open.weibo.com/wiki/Oauth2/revokeoauth2
 * @param accessToken//from   www  .  j av  a 2 s  . c  o  m
 * @return
 */
public String revokeOauth2(String accessToken) {
    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
    map.add("access_token", accessToken);
    return weiboHttpClient.postForm(OAUTH2_REVOKE_OAUTH2, map, String.class);
}