Example usage for org.springframework.util LinkedMultiValueMap LinkedMultiValueMap

List of usage examples for org.springframework.util LinkedMultiValueMap LinkedMultiValueMap

Introduction

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

Prototype

public LinkedMultiValueMap() 

Source Link

Document

Create a new LinkedMultiValueMap that wraps a LinkedHashMap .

Usage

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

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

        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        params.add("timedCreated", LocalDateTime.now().plusDays(1).toString());
        namedQueryService.get("getAttributesCreatedBefore", params);
    });//from   w  w w .j a va  2s  . co m
}

From source file:natalia.dymnikova.cluster.scheduler.impl.RolesChecker.java

private boolean doCheck(final Set<String> roles, final Class<? extends Remote> aClass) {
    final Field[] declaredFields = aClass.getDeclaredFields();
    final List<TypeFilter> fields = Arrays.stream(declaredFields)
            .filter(field -> field.isAnnotationPresent(Autowired.class))
            // TODO deal with 3pp dependencies
            .filter(field -> field.getType().getPackage().getName().startsWith(basePackage)).map(Field::getType)
            .map(AssignableTypeFilter::new).collect(toList());

    final MultiValueMap<String, Object> matchAll = new LinkedMultiValueMap<>();
    matchAll.put("value", singletonList(roles.toArray(new String[roles.size()])));

    final List<Set<ScannedGenericBeanDefinition>> set = scan(basePackage, fields);

    return set.stream().map(definitions -> definitions.stream().map(def -> {
        final MultiValueMap<String, Object> map = ofNullable(
                def.getMetadata().getAllAnnotationAttributes(Profile.class.getName())).orElse(matchAll);

        //noinspection unchecked
        return ((List<String[]>) (Object) map.get("value")).stream().flatMap(Arrays::stream).collect(toList());
    }).flatMap(Collection::stream).collect(toList()))
            .allMatch(profiles -> profiles.stream().filter(roles::contains).findAny().isPresent());
}

From source file:org.cloudfoundry.identity.uaa.integration.NativeApplicationIntegrationTests.java

/**
 * tests that a client secret is required.
 *//*from  w  w  w .j ava  2 s  .  c o  m*/
@Test
public void testSecretRequired() throws Exception {
    MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
    formData.add("grant_type", "password");
    formData.add("username", resource.getUsername());
    formData.add("password", resource.getPassword());
    formData.add("scope", "cloud_controller.read");
    HttpHeaders headers = new HttpHeaders();
    headers.set("Authorization", "Basic " + new String(Base64.encode("no-such-client:".getBytes("UTF-8"))));
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    ResponseEntity<String> response = serverRunning.postForString("/oauth/token", formData, headers);
    assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreateScenario.java

/**
 * Method, where scenario information is pushed to server in order to new scenario.
 * All heavy lifting is made here./*from  www .  ja va2s  .  c o m*/
 *
 * @param scenarios only one scenario is accepted - scenario to be uploaded
 * @return scenario stored
 */
@Override
protected Scenario doInBackground(Scenario... scenarios) {
    SharedPreferences credentials = getCredentials();
    String username = credentials.getString("username", null);
    String password = credentials.getString("password", null);
    String url = credentials.getString("url", null) + Values.SERVICE_SCENARIOS;

    setState(RUNNING, R.string.working_ws_create_scenario);
    HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAuthorization(authHeader);
    requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));

    SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory();
    //so files wont buffer in memory
    factory.setBufferRequestBody(false);
    // Create a new RestTemplate instance
    RestTemplate restTemplate = new RestTemplate(factory);
    restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
    restTemplate.getMessageConverters().add(new FormHttpMessageConverter());
    restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());

    Scenario scenario = scenarios[0];

    try {
        Log.d(TAG, url);
        FileSystemResource toBeUploadedFile = new FileSystemResource(scenario.getFilePath());

        //due to multipart file, MultiValueMap is the simplest approach for performing the post request
        MultiValueMap<String, Object> form = new LinkedMultiValueMap<String, Object>();
        form.add("scenarioName", scenario.getScenarioName());
        form.add("researchGroupId", scenario.getResearchGroupId());
        form.add("description", scenario.getDescription());
        form.add("mimeType", scenario.getMimeType());
        form.add("private", Boolean.toString(scenario.isPrivate()));
        form.add("file", toBeUploadedFile);

        HttpEntity<Object> entity = new HttpEntity<Object>(form, requestHeaders);
        // Make the network request
        ResponseEntity<Scenario> response = restTemplate.postForEntity(url, entity, Scenario.class);
        return response.getBody();
    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
        setState(ERROR, e);
    } finally {
        setState(DONE);
    }
    return null;
}

From source file:de.zib.gndms.gndmc.gorfx.Test.TaskClientTest.java

@Test(groups = { "TaskFlowClientTest" })
public void createTaskFlow() {
    FailureOrder order = new FailureOrder();
    order.setMessage(ORDER_MESSAGE);/*  w  w  w  . j a va2 s .  c om*/
    order.setWhere(FailureOrder.FailurePlace.NOWHERE);

    ResponseEntity<Specifier<Facets>> responseEntity = gorfxClient.createTaskFlow(
            FailureTaskFlowMeta.TASK_FLOW_TYPE_KEY, order, admindn, TASKFLOW_WID,
            new LinkedMultiValueMap<String, String>());

    Assert.assertNotNull(responseEntity);
    Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.CREATED);

    taskFlowId = responseEntity.getBody().getUriMap().get(UriFactory.TASKFLOW_ID);
}

From source file:com.hyrt.cnp.account.AccountAuthenticator.java

@Override
public Bundle getAuthToken(final AccountAuthenticatorResponse response, final Account account,
        final String authTokenType, final Bundle options) throws NetworkErrorException {
    Log.d(TAG, "Retrieving OAuth2 token");

    final Bundle bundle = new Bundle();

    if (!ACCOUNT_TYPE.equals(authTokenType))
        return bundle;

    AccountManager am = AccountManager.get(context);
    String password = am.getPassword(account);
    if (TextUtils.isEmpty(password)) {
        bundle.putParcelable(KEY_INTENT, createLoginIntent(response));
        return bundle;
    }/*from  w  ww.  j ava 2  s .  c  o  m*/
    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    params.set("username", account.name);
    params.set("password", password);
    User.UserModel userModel = null;
    try {
        userModel = getCustomRestTemplate().postForObject("http://api.chinaxueqian.com/account/login", params,
                User.UserModel.class);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (userModel == null || userModel.getData() == null || TextUtils.isEmpty(userModel.getData().getToken()))
        bundle.putParcelable(KEY_INTENT, createLoginIntent(response));
    else {
        bundle.putString(KEY_ACCOUNT_NAME, account.name);
        bundle.putString(KEY_ACCOUNT_TYPE, ACCOUNT_TYPE);
        bundle.putString(KEY_AUTHTOKEN, userModel.getData().getToken() + "&uuid="
                + userModel.getData().getUuid() + "&sid=" + userModel.getData().getNursery_id());
        am.clearPassword(account);
    }
    return bundle;
}

From source file:com.svds.resttest.model.GenericCountOutputNGTest.java

/**
 * Test of setRequestParams method, of class GenericCountOutput.
 *//*w ww.j a v a2  s  . co m*/
@Test
public void testSetRequestParams() {
    System.out.println("setRequestParams");
    MultiValueMap<String, String> requestParams = new LinkedMultiValueMap<>();
    GenericCountOutput instance = new GenericCountOutput();
    instance.setRequestParams(requestParams);
    assertEquals(instance.getRequestParams(), requestParams);
}

From source file:com.svds.resttest.model.GenericResultsOutputNGTest.java

/**
 * Test of setRequestParams method, of class GenericResultsOutput.
 *///  ww  w. j a  va2s .  c om
@Test
public void testSetRequestParams() {
    System.out.println("setRequestParams");
    MultiValueMap<String, String> requestParams = new LinkedMultiValueMap<>();
    GenericResultsOutput instance = new GenericResultsOutput();
    instance.setRequestParams(requestParams);
    assertEquals(instance.getRequestParams(), requestParams);
}