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:org.apereo.services.persondir.support.ldap.LdapPersonAttributeDaoTest.java

public void testNotFoundQuery() 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", null));

    impl.afterPropertiesSet();/*from w  w  w  .ja  v  a  2s  . c om*/

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

    try {
        final Map<String, List<Object>> attribs = impl.getMultivaluedUserAttributes(queryMap);
        assertNull(attribs);
    } catch (final DataAccessResourceFailureException darfe) {
        //OK, No net connection
    }
}

From source file:io.openshift.booster.BoosterApplicationTest.java

@Test
public void testPost() {
    given().contentType(ContentType.JSON).body(Collections.singletonMap("name", "Cherry")).when().post().then()
            .statusCode(201).body("id", not(isEmptyString())).body("name", is("Cherry"));
}

From source file:org.logstash.log.CustomLogEventTests.java

@Test
@SuppressWarnings("unchecked")
public void testJSONLayout() throws Exception {
    appender = CTX.getListAppender("JSONEventLogger").clear();
    Logger logger = LogManager.getLogger("JSONEventLogger");
    logger.info("simple message");
    logger.warn("complex message", Collections.singletonMap("foo", "bar"));
    logger.error("my name is: {}", "foo");
    logger.error("here is a map: {}", Collections.singletonMap(2, 5));
    logger.warn("ignored params {}", 4, 6, 8);

    List<String> messages = appender.getMessages();

    Map<String, Object> firstMessage = mapper.readValue(messages.get(0), Map.class);

    assertEquals(5, firstMessage.size());
    assertEquals("INFO", firstMessage.get("level"));
    assertEquals("JSONEventLogger", firstMessage.get("loggerName"));
    assertNotNull(firstMessage.get("thread"));
    assertEquals(Collections.singletonMap("message", "simple message"), firstMessage.get("logEvent"));

    Map<String, Object> secondMessage = mapper.readValue(messages.get(1), Map.class);

    assertEquals(5, secondMessage.size());
    assertEquals("WARN", secondMessage.get("level"));
    assertEquals("JSONEventLogger", secondMessage.get("loggerName"));
    assertNotNull(secondMessage.get("thread"));
    Map<String, Object> logEvent = new HashMap<>();
    logEvent.put("message", "complex message");
    logEvent.put("foo", "bar");
    assertEquals(logEvent, secondMessage.get("logEvent"));

    Map<String, Object> thirdMessage = mapper.readValue(messages.get(2), Map.class);
    assertEquals(5, thirdMessage.size());
    logEvent = Collections.singletonMap("message", "my name is: foo");
    assertEquals(logEvent, thirdMessage.get("logEvent"));

    Map<String, Object> fourthMessage = mapper.readValue(messages.get(3), Map.class);
    assertEquals(5, fourthMessage.size());
    logEvent = new HashMap<>();
    logEvent.put("message", "here is a map: {}");
    logEvent.put("2", 5);
    assertEquals(logEvent, fourthMessage.get("logEvent"));

    Map<String, Object> fifthMessage = mapper.readValue(messages.get(4), Map.class);
    assertEquals(5, fifthMessage.size());
    logEvent = Collections.singletonMap("message", "ignored params 4");
    assertEquals(logEvent, fifthMessage.get("logEvent"));
}

From source file:com.thoughtworks.go.spark.RoutesHelper.java

private void invalidJsonPayload(JsonParseException ex, Request req, Response res) {
    res.body(new Gson()
            .toJson(Collections.singletonMap("error", "Payload data is not valid JSON: " + ex.getMessage())));
    res.status(HttpStatus.SC_BAD_REQUEST);
}

From source file:com.logsniffer.reader.log4j.Log4jTextReaderTest.java

@Test
public void testParsingConversionPattern() throws FormatException {
    final Log4jTextReader r = new Log4jTextReader();
    r.setFormatPattern("%d{ABSOLUTE} %-5p [%c] %m%n");
    r.setCharset("UTF-8");
    r.setSpecifiersFieldMapping(Collections.singletonMap("m", "Message"));
    final String[] fieldNames = r.getFieldTypes().keySet().toArray(new String[0]);
    Assert.assertEquals(7, fieldNames.length);
    Assert.assertEquals(LogEntry.FIELD_RAW_CONTENT, fieldNames[0]);
    Assert.assertEquals("d", fieldNames[1]);
    Assert.assertEquals("p", fieldNames[2]);
    Assert.assertEquals("c", fieldNames[3]);
    Assert.assertEquals("Message", fieldNames[4]);
    Assert.assertEquals(LogEntry.FIELD_TIMESTAMP, fieldNames[5]);
    Assert.assertEquals(LogEntry.FIELD_SEVERITY_LEVEL, fieldNames[6]);

    Assert.assertEquals(FieldBaseTypes.DATE, r.getFieldTypes().get(LogEntry.FIELD_TIMESTAMP));
    Assert.assertEquals(FieldBaseTypes.STRING, r.getFieldTypes().get(fieldNames[0]));
    Assert.assertEquals(FieldBaseTypes.STRING, r.getFieldTypes().get(fieldNames[1]));
    Assert.assertEquals(FieldBaseTypes.STRING, r.getFieldTypes().get(fieldNames[2]));
    Assert.assertEquals(FieldBaseTypes.STRING, r.getFieldTypes().get(fieldNames[3]));
    Assert.assertEquals(FieldBaseTypes.STRING, r.getFieldTypes().get(fieldNames[4]));
    Assert.assertEquals(FieldBaseTypes.DATE, r.getFieldTypes().get(fieldNames[5]));
    Assert.assertEquals(FieldBaseTypes.SEVERITY, r.getFieldTypes().get(fieldNames[6]));
}

From source file:com.linkedin.pinot.integration.tests.ConvertToRawIndexMinionClusterIntegrationTest.java

@Override
protected TableTaskConfig getTaskConfig() {
    TableTaskConfig taskConfig = new TableTaskConfig();
    Map<String, String> convertToRawIndexTaskConfigs = new HashMap<>();
    convertToRawIndexTaskConfigs.put(MinionConstants.TABLE_MAX_NUM_TASKS_KEY, "5");
    convertToRawIndexTaskConfigs.put(MinionConstants.ConvertToRawIndexTask.COLUMNS_TO_CONVERT_KEY,
            COLUMNS_TO_CONVERT);/*w w w. j  ava 2s.co  m*/
    taskConfig.setTaskTypeConfigsMap(Collections.singletonMap(MinionConstants.ConvertToRawIndexTask.TASK_TYPE,
            convertToRawIndexTaskConfigs));
    return taskConfig;
}

From source file:org.tradex.camel.enrich.TradeCommonCodeEnricher.java

/**
 * {@inheritDoc}/*from  w  w  w.  j  a  va  2s  .com*/
 * @see org.apache.camel.Processor#process(org.apache.camel.Exchange)
 */
@Override
public void process(Exchange exchange) throws Exception {
    ITrade trade = exchange.getIn().getBody(ITrade.class);
    String commonCode = jdbcTemplate.queryForObject("SELECT COMMON_CODE FROM ISIN WHERE ISIN = :isin",
            Collections.singletonMap("isin", trade.getIsin()), String.class);
    if (commonCode == null || commonCode.trim().isEmpty()) {
        throw new TradeImportBusinessException("Failed to get common code for trade [" + trade + "]");
    }
    trade.setCommonCode(commonCode);
}

From source file:org.cloudfoundry.identity.uaa.api.user.impl.UaaUserOperationsImpl.java

public void changeUserPassword(String userId, String newPassword) {
    Assert.hasText(userId);//from   ww w.ja  v  a  2  s  .c o m
    Assert.hasText(newPassword);

    helper.put("/Users/{id}/password", Collections.singletonMap("password", newPassword), STRING_REF, userId);
}

From source file:com.amazonaws.sample.entitlement.rs.JaxRsAdministrationService.java

/**
 * Get users/*from  ww w  . jav a 2s .c  o  m*/
 * @param authorization string that is associated to the identity of the requester
 * @return prettified JSON
 */
@GET
@Path("/users/")
@Produces(MediaType.APPLICATION_JSON)
public Response getUsers(@HeaderParam("Authorization") String authorization) {
    try {
        administrationService.getUserFromAuthorization(authorization);
        String response = administrationService.getUsers();
        return response(Status.OK, response);
    } catch (AuthorizationException e) {
        String authenticateHeader = e.getAuthenticateHeader();

        if (authenticateHeader == null) {
            return response(Status.UNAUTHORIZED, e.getMessage());
        } else {
            return response(Status.UNAUTHORIZED, e.getMessage(),
                    Collections.singletonMap("WWW-Authenticate", authenticateHeader));
        }
    } catch (ApplicationBadStateException e) {
        return response(Status.CONFLICT, e.getMessage());
    }
}

From source file:com.codepine.api.testrail.internal.StringToMapDeserializerTest.java

@Test
public void W_singleCommaSeparatedValuePair_T_singlePair() throws IOException {
    // WHEN//w w  w  . j av  a2 s  .  c  o  m
    when(jsonParser.getValueAsString()).thenReturn("a,b");
    Map<String, String> actualMap = stringToMapDeserializer.deserialize(jsonParser, null);

    // THEN
    Map<String, String> expectedMap = Collections.singletonMap("a", "b");
    assertEquals(expectedMap, actualMap);
}