Example usage for java.util Collections singletonMap

List of usage examples for java.util Collections singletonMap

Introduction

In this page you can find the example usage for java.util Collections singletonMap.

Prototype

public static <K, V> Map<K, V> singletonMap(K key, V value) 

Source Link

Document

Returns an immutable map, mapping only the specified key to the specified value.

Usage

From source file:pw.spn.mptg.service.impl.ProjectServiceImpl.java

private void createReadme(Path workingDir, PomTemplate pomTemplate) {
    Map<String, Object> context = Collections.singletonMap("pomTemplate", pomTemplate);
    byte[] content = templateService.executeTemplate("readme", context);
    fileService.writeToFile(workingDir, "README.md", content);
}

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

@BeforeOAuth2Context
@OAuth2ContextConfiguration(OAuth2ContextConfiguration.ClientCredentials.class)
public void setUpUserAccounts() {

    // If running against vcap we don't want to run these tests because they create new user accounts
    // Assume.assumeTrue(!testAccounts.isProfileActive("vcap"));

    RestOperations client = serverRunning.getRestTemplate();

    ScimUser user = new ScimUser();
    user.setUserName(JOE);/*ww w .  ja  v  a2  s .  c o  m*/
    user.setName(new ScimUser.Name("Joe", "User"));
    user.addEmail("joe@blah.com");

    ResponseEntity<ScimUser> newuser = client.postForEntity(serverRunning.getUrl(usersEndpoint), user,
            ScimUser.class);

    joe = newuser.getBody();
    assertEquals(JOE, joe.getUserName());

    PasswordChangeRequest change = new PasswordChangeRequest();
    change.setPassword("password");

    HttpHeaders headers = new HttpHeaders();
    ResponseEntity<Void> result = client.exchange(serverRunning.getUrl(usersEndpoint) + "/{id}/password",
            HttpMethod.PUT, new HttpEntity<PasswordChangeRequest>(change, headers), null, joe.getId());
    assertEquals(HttpStatus.OK, result.getStatusCode());

    // The implicit grant for vmc requires extra parameters in the authorization request
    context.setParameters(Collections.singletonMap("credentials",
            testAccounts.getJsonCredentials(joe.getUserName(), "password")));

}

From source file:org.zenoss.zep.dao.impl.EventTimeDaoImpl.java

@Override
@TransactionalReadOnly/* w  w  w  .ja  va 2  s .  com*/
public List<Zep.EventTime> findProcessedSince(Date startDate, int limit) {
    long timestamp = startDate.getTime();
    final Map<String, Object> params = Collections.singletonMap("since",
            databaseCompatibility.getTimestampConverter().toDatabaseType(timestamp));

    String sql = "SELECT * from %s where %s >= :since order by %s asc limit %s";
    sql = String.format(sql, TABLE_EVENT_TIME, COLUMN_PROCESSED, COLUMN_PROCESSED, limit);

    return template.query(sql, new EventTimeRowMapper(), params);
}

From source file:ca.simplegames.micro.RoutingTest.java

@Test
public void testParametrizedRoutes() throws Exception {

    micro.getSite().getRouteManager()//from   ww  w.  jav  a 2  s  .  c o  m
            .add(new Route("/micro/{name}/{version:.*}", Collections.<String, Object>emptyMap()) {

                @Override
                public RackResponse call(MicroContext context) throws Exception {
                    String name = (String) context.getParams().get("name");
                    String version = (String) context.getParams().get("version");
                    Map<String, Object> microDetails = new HashMap<String, Object>();
                    microDetails.put("name", name);
                    microDetails.put("version", version);

                    JSONObject json = new JSONObject(Collections.singletonMap("micro", microDetails));
                    context.halt();
                    return ResponseUtils.standardJson(json.toString());
                }
            });

    Context<String> input = new MapContext<String>().with(Rack.REQUEST_METHOD, "GET").with(Rack.PATH_INFO,
            "/micro//0.1.2");

    RackResponse response = micro.call(input);
    Assert.assertEquals("Invalid response", "{\"micro\":{\"name\":\"\",\"version\":\"0.1.2\"}}",
            RackResponse.getBodyAsString(response, Charset.forName("UTF-8")));
}

From source file:com.sillelien.dollar.api.types.DollarNull.java

@NotNull
@Override//  w  w w.ja va 2s. c om
public <K extends Comparable<K>, V> ImmutableMap<K, V> toJavaMap() {
    return ImmutableMap.copyOf(Collections.singletonMap((K) "value", (V) null));
}

From source file:example.helloworld.CubbyholeAuthenticationTests.java

/**
 * {@link org.springframework.vault.core.VaultTemplate},
 * {@link CubbyholeAuthentication} retrieves the wrapped token from
 * {@code cubbyhole/response} and uses the wrapped token to access Vault.
 *//*  w  w  w .  j a va  2  s .  c o  m*/
@Test
public void environmentShouldExposeVaultPropertySource() {

    vaultOperations.write("secret/key", Collections.singletonMap("key", "value"));
    assertThat(vaultOperations.read("secret/key").getData()).containsEntry("key", "value");
}

From source file:com.vivastream.dynamodb.core.DynamoDBTemplate.java

public <T> List<T> batchGet(String tableName, KeysAndAttributes keysAndAttributes,
        final ObjectExtractor<T> extractor) throws EmptyResultDataAccessException {
    Assert.notNull(tableName, "Table must not be null");
    Assert.notNull(extractor, "ObjectExtractor must not be null");
    if (logger.isDebugEnabled()) {
        logger.debug("Executing batch get on " + tableName + " for " + keysAndAttributes.toString());
    }/* www .  j av  a 2 s.  c o  m*/

    List<T> results = new ArrayList<T>(keysAndAttributes.getKeys().size());

    Map<String, KeysAndAttributes> unprocessedKeys = Collections.singletonMap(tableName, keysAndAttributes);
    while (unprocessedKeys.size() > 0) {
        BatchGetItemResult result = client.batchGetItem(unprocessedKeys);
        List<Map<String, AttributeValue>> items = result.getResponses().get(tableName);
        if (items != null) {
            for (Map<String, AttributeValue> item : items) {
                results.add(extractor.extract(item));
            }
        }

        unprocessedKeys = result.getUnprocessedKeys();
    }

    if (results.size() == 0) {
        throw new EmptyResultDataAccessException(
                "No results found in " + tableName + "for " + keysAndAttributes.toString());
    }

    return results;
}

From source file:org.apereo.services.persondir.support.ldap.LdapPersonAttributeDaoTest.java

/**
 * Test for a query with a single attribute. 
 *///w w w  .  j  a v a 2  s .  co m
public void testSingleAttrQuery() throws Exception {
    final LdapPersonAttributeDao impl = new LdapPersonAttributeDao();

    final Map<String, Object> ldapAttribsToPortalAttribs = new HashMap<>();
    ldapAttribsToPortalAttribs.put("mail", "email");

    impl.setResultAttributeMapping(ldapAttribsToPortalAttribs);

    impl.setContextSource(this.getContextSource());

    impl.setQueryAttributeMapping(Collections.singletonMap("uid", "uid"));

    impl.afterPropertiesSet();

    final Map<String, List<Object>> queryMap = new HashMap<>();
    queryMap.put("uid", Util.list("edalquist"));

    try {
        final Map<String, List<Object>> attribs = impl.getMultivaluedUserAttributes(queryMap);
        assertEquals(Util.list("eric.dalquist@example.com"), attribs.get("email"));
    } catch (final DataAccessResourceFailureException darfe) {
        //OK, No net connection
    }
}

From source file:org.cloudfoundry.identity.uaa.config.NestedMapPropertySource.java

private void appendCache(Map<String, Object> output, Set<String> seen, Map<String, Object> input, String path) {

    synchronized (this.cache) {

        seen.add(ObjectUtils.getIdentityHexString(input));

        for (Entry<String, Object> entry : input.entrySet()) {
            String key = entry.getKey();
            if (StringUtils.hasText(path)) {
                if (key.startsWith("[")) {
                    key = path + key;/*from   w w w . j  ava2 s  .c o  m*/
                } else {
                    key = path + "." + key;
                }
            }
            Object value = entry.getValue();
            if (value instanceof String) {
                output.put(key, value);
            } else if (value instanceof Map) {
                // Need a compound key
                @SuppressWarnings("unchecked")
                Map<String, Object> map = (Map<String, Object>) value;
                output.put(key, map);
                if (!seen.contains(ObjectUtils.getIdentityHexString(map))) {
                    appendCache(output, seen, map, key);
                }
            } else if (value instanceof Collection) {
                // Need a compound key
                @SuppressWarnings("unchecked")
                Collection<Object> collection = (Collection<Object>) value;
                output.put(key, collection);
                int count = 0;
                for (Object object : collection) {
                    String index = "[" + (count++) + "]";
                    if (!seen.contains(ObjectUtils.getIdentityHexString(object))) {
                        appendCache(output, seen, Collections.singletonMap(index, object), key);
                    } else {
                        output.put(key + index, object);
                    }
                }
            } else {
                output.put(key, value);
            }
        }

    }

}