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.elasticsearch.upgrades.IndexAuditUpgradeIT.java

private void assertNumUniqueNodeNameBuckets(int numBuckets) throws Exception {
    // call API that will hit all nodes
    assertEquals(200, client().performRequest("GET", "/_nodes").getStatusLine().getStatusCode());

    HttpEntity httpEntity = new StringEntity("{\n" + "    \"aggs\" : {\n" + "        \"nodes\" : {\n"
            + "            \"terms\" : { \"field\" : \"node_name\" }\n" + "        }\n" + "    }\n" + "}",
            ContentType.APPLICATION_JSON);
    Response aggResponse = client().performRequest("GET", "/.security_audit_log*/_search",
            Collections.singletonMap("pretty", "true"), httpEntity);
    Map<String, Object> aggResponseMap = entityAsMap(aggResponse);
    logger.debug("aggResponse {}", aggResponseMap);
    Map<String, Object> aggregations = (Map<String, Object>) aggResponseMap.get("aggregations");
    assertNotNull(aggregations);//from   ww w .j  av  a2s .  c o m
    Map<String, Object> nodesAgg = (Map<String, Object>) aggregations.get("nodes");
    assertNotNull(nodesAgg);
    List<Map<String, Object>> buckets = (List<Map<String, Object>>) nodesAgg.get("buckets");
    assertNotNull(buckets);
    assertEquals("Found node buckets " + buckets, numBuckets, buckets.size());
}

From source file:org.jboss.as.test.integration.logging.perdeploy.Log4jXmlTestCase.java

@Test
public void logsTest() throws IOException {
    final String msg = "logTest: log4j.xml message";
    final int statusCode = getResponse(msg, Collections.singletonMap("includeLevel", "true"));
    assertTrue("Invalid response statusCode: " + statusCode, statusCode == HttpStatus.SC_OK);
    boolean trace = false;
    boolean fatal = false;
    String traceLine = msg + " - trace";
    String fatalLine = msg + " - fatal";
    try (final BufferedReader reader = Files.newBufferedReader(logFile, StandardCharsets.UTF_8)) {
        String line;/*  w ww  . ja  v  a  2  s . c o  m*/
        while ((line = reader.readLine()) != null) {
            if (line.contains(traceLine)) {
                trace = true;
            }
            if (line.contains(fatalLine)) {
                fatal = true;
            }
        }
    }
    Assert.assertTrue("Log file should contain line: " + traceLine, trace);
    Assert.assertTrue("Log file should contain line: " + fatalLine, fatal);
}

From source file:com.smartitengineering.cms.spi.impl.hbase.Utils.java

public static void organizeByPrefix(Map<byte[], byte[]> fieldMap, Map<String, Map<String, byte[]>> fieldsByName,
        char separator) {
    logger.debug("Organize by their prefix so that each field cells can be processed at once");
    for (Entry<byte[], byte[]> entry : fieldMap.entrySet()) {
        final String key = Bytes.toString(entry.getKey());
        final int indexOfFirstColon = key.indexOf(separator);
        if (indexOfFirstColon > -1) {
            final String fieldName = key.substring(0, indexOfFirstColon);
            final byte[] fieldNameBytes = Bytes.toBytes(fieldName);
            if (Bytes.startsWith(entry.getKey(), fieldNameBytes)) {
                Map<String, byte[]> fieldCells = fieldsByName.get(fieldName);
                if (fieldCells == null) {
                    fieldCells = new LinkedHashMap<String, byte[]>();
                    fieldsByName.put(fieldName, fieldCells);
                }/*from   w  w  w.  jav  a  2  s.c  o  m*/
                fieldCells.put(Bytes.toString(entry.getKey()), entry.getValue());
            }
        } else {
            fieldsByName.put(key, Collections.singletonMap(Bytes.toString(entry.getKey()), entry.getValue()));
        }
    }
}

From source file:org.camunda.bpm.camel.spring.StartProcessFromRouteTest.java

@Test
@Deployment(resources = { "process/StartProcessFromRoute.bpmn20.xml" })
public void doTest() throws Exception {
    ProducerTemplate tpl = camelContext.createProducerTemplate();

    String processInstanceId = (String) tpl.requestBody("direct:start",
            Collections.singletonMap("var1", "valueOfVar1"));
    assertThat(processInstanceId).isNotNull();
    System.out.println("Process instance ID: " + processInstanceId);

    // Verify that a process instance was executed and there are no instances executing now
    assertThat(historyService.createHistoricProcessInstanceQuery().processDefinitionKey("startProcessFromRoute")
            .count()).isEqualTo(1);// w  ww  .java2s  .com
    assertThat(
            runtimeService.createProcessInstanceQuery().processDefinitionKey("startProcessFromRoute").count())
                    .isEqualTo(0);

    // Assert that the camunda BPM process instance ID has been added as a property to the message
    assertThat(mockEndpoint.assertExchangeReceived(0).getProperty(CAMUNDA_BPM_PROCESS_INSTANCE_ID))
            .isEqualTo(processInstanceId);

    // The body of the message comming out from the camunda-bpm:<process definition> endpoint is the process instance
    assertThat(mockEndpoint.assertExchangeReceived(0).getIn().getBody(String.class))
            .isEqualTo(processInstanceId);

    // We should receive a hash map as the body of the message with a 'var1' key
    assertThat(processVariableEndpoint.assertExchangeReceived(0).getIn().getBody(String.class))
            .isEqualTo("{var1=valueOfVar1}");
}

From source file:org.cloudfoundry.identity.uaa.client.OAuthClientAuthenticationFilterTests.java

private void setUpContext(String tokenName, String secretName, String keyName, String sharedName) {
    resource.setId("foo");
    String consumerKey = System.getProperty(keyName);
    Assume.assumeNotNull(consumerKey);/*from   w w w .  j a  va2 s  .c o m*/
    String sharedSecret = System.getProperty(sharedName);
    Assume.assumeNotNull(sharedSecret);
    String accessToken = System.getProperty(tokenName);
    Assume.assumeNotNull(accessToken);
    String secret = System.getProperty(secretName);
    Assume.assumeNotNull(accessToken);
    OAuthSecurityContextImpl context = new OAuthSecurityContextImpl();
    OAuthConsumerToken token = new OAuthConsumerToken();
    resource.setConsumerKey(consumerKey);
    resource.setSharedSecret(new SharedConsumerSecretImpl(sharedSecret));
    token.setValue(accessToken);
    token.setSecret(secret);
    context.setAccessTokens(Collections.singletonMap("foo", token));
    OAuthSecurityContextHolder.setContext(context);
}

From source file:org.apache.lucene.replicator.http.HttpReplicatorTest.java

private void startServer() throws Exception {
    ServletHandler replicationHandler = new ServletHandler();
    ReplicationService service = new ReplicationService(Collections.singletonMap("s1", serverReplicator));
    replicationServlet = new ReplicationServlet(service);
    ServletHolder servlet = new ServletHolder(replicationServlet);
    replicationHandler.addServletWithMapping(servlet, ReplicationService.REPLICATION_CONTEXT + "/*");
    server = newHttpServer(replicationHandler);
    port = serverPort(server);//from w  w  w  .ja v  a 2 s  .  c  o m
    host = serverHost(server);
}

From source file:org.terasoluna.gfw.functionaltest.domain.service.date.DateServiceImpl.java

@Override
public void deleteOperationDate(int id) {
    jdbcTemplate.update(DELETE_OPERATION_DATE_BY_ID,
            Collections.singletonMap("operation_date_id", new Integer(id)));
}

From source file:hrytsenko.gscripts.App.java

private static GroovyShell createShell(AppArgs args) {
    Binding binding = new Binding(Collections.singletonMap("args", args.getScriptsArgs()));

    ImportCustomizer imports = new ImportCustomizer();
    imports.addStaticStars(CsvFiles.class.getCanonicalName()).addStaticStars(XlsFiles.class.getCanonicalName());

    CompilerConfiguration configuration = new CompilerConfiguration().addCompilationCustomizers(imports);

    return new GroovyShell(binding, configuration);
}

From source file:example.users.UserController.java

/**
 * Returns the payload of {@link #getJson()} wrapped into another element to simulate a change in the representation.
 * /* w ww .  j a  va 2  s. c  om*/
 * @return
 */
@GetMapping(path = "/changed", produces = MediaType.APPLICATION_JSON_VALUE)
Map<String, Object> getChangedJson() {
    return Collections.singletonMap("user", getJson());
}

From source file:com.ethlo.kfka.mysql.MysqlKfkaMapStore.java

@Override
public Map<Long, T> loadAll(Collection<Long> keys) {
    logger.debug("Loading data for keys {}", StringUtils.collectionToCommaDelimitedString(keys));
    final List<T> res = tpl.query("SELECT * FROM kfka WHERE id IN (:keys)",
            Collections.singletonMap("keys", keys), mapper);
    final Map<Long, T> retVal = new HashMap<>(keys.size());
    res.forEach(e -> {/*w  w w. j a  v a  2  s .c o m*/
        retVal.put(e.getId(), e);
    });
    return retVal;
}