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:com.opentable.jaxrs.exceptions.TestArgumentExceptionMapping.java

@Test
public void testMappingOkJson() throws Exception {
    final String result = client.target(baseUrl + "/message").request()
            .post(Entity.json(Collections.singletonMap("message", "foo")), String.class);
    assertEquals("foo", result);
}

From source file:marshalsec.BlazeDSBase.java

@Override
@Args(minArgs = 1, args = { "jndiUrl" }, defaultArgs = { MarshallerBase.defaultJNDIUrl })
public Object makePropertyPathFactory(UtilFactory uf, String[] args) throws Exception {
    String jndiUrl = args[0];/*from   w w w .j ava 2  s. c o m*/
    PropertyInjectingProxy bfproxy = new PropertyInjectingProxy(new SimpleJndiBeanFactory(),
            Collections.singletonMap("shareableResources", Arrays.asList(jndiUrl) // this would actually be an array,
                                                                                                                                                                           // but AMFX has some trouble with
                                                                                                                                                                           // non-readable array properties
            ));

    Map<String, Object> values = new LinkedHashMap<>();
    values.put("targetBeanName", jndiUrl);
    values.put("propertyPath", "foo");
    values.put("beanFactory", bfproxy);
    return new PropertyInjectingProxy(new PropertyPathFactoryBean(), values);
}

From source file:org.springframework.data.rest.webmvc.json.DomainObjectReaderUnitTests.java

/**
 * @see DATAREST-605/*  w  ww .j  a  v a  2s .c  o  m*/
 */
@Test
public void mergesMapCorrectly() throws Exception {

    SampleUser user = new SampleUser("firstname", "password");
    user.relatedUsers = Collections.singletonMap("parent", new SampleUser("firstname", "password"));

    JsonNode node = new ObjectMapper().readTree(
            "{ \"relatedUsers\" : { \"parent\" : { \"password\" : \"sneeky\", \"name\" : \"Oliver\" } } }");

    SampleUser result = reader.readPut((ObjectNode) node, user, new ObjectMapper());

    // Assert that the nested Map values also consider ignored properties
    assertThat(result.relatedUsers.get("parent").password, is("password"));
    assertThat(result.relatedUsers.get("parent").name, is("Oliver"));
}

From source file:com.vivastream.security.oauth2.provider.token.store.DynamoDBTokenStore.java

public OAuth2AccessToken getAccessToken(OAuth2Authentication authentication) {
    OAuth2AccessToken accessToken = null;

    String key = authenticationKeyGenerator.extractKey(authentication);
    try {/*from   w  ww.j  a va 2 s. c  o m*/
        String accessTokenId = dynamoDBTemplate.queryUnique(schema.getAccessTableName(),
                schema.getAccessIndexAuthenticationId(), // 
                Collections.singletonMap(schema.getAccessColumnAuthenticationId(),
                        new Condition().withComparisonOperator(ComparisonOperator.EQ)
                                .withAttributeValueList(new AttributeValue(key))), // 
                new ObjectExtractor<String>() {

                    public String extract(Map<String, AttributeValue> values) {
                        return values.get(schema.getAccessColumnTokenId()).getS();
                    }
                });
        accessToken = dynamoDBTemplate.get(schema.getAccessTableName(),
                Collections.singletonMap(schema.getAccessColumnTokenId(), new AttributeValue(accessTokenId)),
                new ObjectExtractor<OAuth2AccessToken>() {

                    public OAuth2AccessToken extract(Map<String, AttributeValue> values) {
                        return deserializeAccessToken(values.get(schema.getAccessColumnToken()).getB());
                    }
                });
    } catch (EmptyResultDataAccessException | IncorrectResultSizeDataAccessException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Failed to find access token for authentication " + authentication);
        }
    } catch (IllegalArgumentException e) {
        LOG.error("Could not extract access token for authentication " + authentication, e);
    }

    if (accessToken != null
            && !key.equals(authenticationKeyGenerator.extractKey(readAuthentication(accessToken.getValue())))) {
        // Keep the store consistent (maybe the same user is represented by this authentication but the details have
        // changed)
        storeAccessToken(accessToken, authentication);
    }
    return accessToken;
}

From source file:io.jmnarloch.spring.cloud.stream.binder.hermes.HermesClientBinderTest.java

private static Map<String, Object> json() {
    return Collections.singletonMap(MessageHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
}

From source file:com.betfair.cougar.client.CougarRequestFactoryTest.java

@Test
public void shouldMakeGetRequestWithAllHeaders() {
    httpMethod = "GET";
    contentType = CONTENT_TYPE;//from  w  w w  . j  av a  2 s  .  co  m
    String uuid = UUID.randomUUID().toString();
    Date date = new Date();
    when(mockMessage.getHeaderMap()).thenReturn(Collections.singletonMap("X-My-Header", (Object) "value"));
    when(mockCallContext.traceLoggingEnabled()).thenReturn(true);
    RequestUUID toReturn = new RequestUUIDImpl(uuid);
    when(mockCallContext.getRequestUUID()).thenReturn(toReturn.getNewSubUUID());
    factory.setGzipCompressionEnabled(true);

    Object result = factory.create(uri, httpMethod, mockMessage, mockMarshaller, contentType, mockCallContext,
            mockTimeConstraints);

    assertSame(httpRequest, result);
    assertEquals(9, headers.size());
    assertHeadersContains(headers, ACCEPT, contentType);
    assertHeadersContains(headers, USER_AGENT, CougarRequestFactory.USER_AGENT_HEADER);
    assertHeadersContains(headers, ACCEPT_ENCODING, "gzip");
    assertHeadersContains(headers, "X-Trace-Me", "true");
    String uuidHeaderParent = assertHeadersContains(headers, "X-REQUEST-UUID-PARENTS");
    assertEquals(uuid + ":" + uuid, uuidHeaderParent);
    String uuidHeader = assertHeadersContains(headers, "X-REQUEST-UUID");
    assertNotEquals(uuid, uuidHeader);
    assertHeadersContains(headers, "X-RequestTime");
    assertHeadersContains(headers, "X-RequestTimeout", "0");
    assertHeadersContains(headers, "X-My-Header", "value");
}

From source file:com.adobe.acs.commons.wcm.impl.DynamicClassicUiClientLibraryServletTest.java

@Test
public void testExcludeAll() throws Exception {
    Map<String, Object> config = Collections.singletonMap("exclude.all", true);
    servlet.activate(config);/*from w ww.j a v  a 2s.  co m*/

    servlet.doGet(request, response);
    JSONAssert.assertEquals("{'js':[], 'css':[]}", writer.toString(), false);
}

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

@Override
@TransactionalReadOnly//w ww. ja v  a 2  s.  c  o  m
public EventTrigger findByUuid(String uuidStr) throws ZepException {
    final Object uuid = uuidConverter.toDatabaseType(uuidStr);
    final Map<String, Object> fields = Collections.singletonMap(COLUMN_UUID, uuid);
    String sql = "SELECT event_trigger.*,sub.uuid AS event_sub_uuid,sub.subscriber_uuid,sub.delay_seconds,"
            + "sub.repeat_seconds,sub.send_initial_occurrence FROM event_trigger "
            + "LEFT JOIN event_trigger_subscription AS sub ON event_trigger.uuid = sub.event_trigger_uuid "
            + "WHERE event_trigger.uuid=:uuid";
    List<EventTrigger> triggers = this.template.getNamedParameterJdbcOperations().query(sql, fields,
            new EventTriggerExtractor());
    EventTrigger trigger = null;
    if (!triggers.isEmpty()) {
        trigger = triggers.get(0);
    }
    return trigger;
}

From source file:com.flipkart.foxtrot.core.querystore.impl.ElasticsearchQueryStoreTest.java

@Test
public void testSaveSingle() throws Exception {
    Document originalDocument = new Document();
    originalDocument.setId(UUID.randomUUID().toString());
    originalDocument.setTimestamp(System.currentTimeMillis());
    JsonNode data = mapper.valueToTree(Collections.singletonMap("TEST_NAME", "SINGLE_SAVE_TEST"));
    originalDocument.setData(data);/*from  w w  w .  ja  va  2 s.co m*/
    queryStore.save(TestUtils.TEST_TABLE_NAME, originalDocument);
    final Document translatedDocuemnt = translator
            .translate(tableMetadataManager.get(TestUtils.TEST_TABLE_NAME), originalDocument);
    GetResponse getResponse = elasticsearchServer.getClient()
            .prepareGet(
                    ElasticsearchUtils.getCurrentIndex(TestUtils.TEST_TABLE_NAME,
                            originalDocument.getTimestamp()),
                    ElasticsearchUtils.DOCUMENT_TYPE_NAME, translatedDocuemnt.getId())
            .setFields("_timestamp").execute().actionGet();
    assertTrue("Id should exist in ES", getResponse.isExists());
    assertEquals("Id should match requestId", translatedDocuemnt.getId(), getResponse.getId());
    assertEquals("Timestamp should match request timestamp", translatedDocuemnt.getTimestamp(),
            getResponse.getField("_timestamp").getValue());
}

From source file:ru.mystamps.web.dao.impl.JdbcCategoryDao.java

@Override
public long countBySlug(String slug) {
    return jdbcTemplate.queryForObject(countBySlugSql, Collections.singletonMap("slug", slug), Long.class);
}