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.kitodo.data.index.elasticsearch.RestClientImplementation.java

/**
 * Get information about client server./*from  w  ww.  jav a2s.c  o  m*/
 *
 * @return information about the server
 */
public String getServerInformation() throws IOException {
    Response response = restClient.performRequest("GET", "/", Collections.singletonMap("pretty", "true"));
    return EntityUtils.toString(response.getEntity());
}

From source file:com.xyxy.platform.examples.showcase.demos.web.MashupServerController.java

@RequestMapping(value = "/web/mashup2", produces = MediaTypes.JAVASCRIPT_UTF_8)
@ResponseBody/*from  w  w  w  . j a  v a2s.  com*/
public JSONPObject mashup2(@RequestParam(DEFAULT_JQUERY_JSONP_CALLBACK_PARM_NAME) String callbackName) {

    // ??JSON.
    Map<String, String> map = Collections.singletonMap("content", "<p>?</p>");

    // .
    return new JSONPObject(callbackName, map);
}

From source file:com.sequenceiq.ambari.shell.support.TableRendererTest.java

@Test
public void testRenderMapValueMap() throws IOException {
    Map<String, Map<String, String>> map = new HashMap<String, Map<String, String>>();
    map.put("HDFS", Collections.singletonMap("DATANODE", "STARTED"));
    map.put("MAPREDUCE2", Collections.singletonMap("HISTORYSERVER", "STARTED"));
    map.put("ZOOKEEPER", Collections.singletonMap("ZOOKEEPER_SERVER", "INSTALLED"));
    assertEquals(IOUtils.toString(new FileInputStream(new File("src/test/resources/3columns"))),
            TableRenderer.renderMapValueMap(map, "SERVICE", "COMPONENT", "STATE"));
}

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

@Test
public void testPatternLayout() {
    appender = CTX.getListAppender("EventLogger").clear();
    Logger logger = LogManager.getLogger("EventLogger");
    logger.info("simple message");
    logger.warn("complex message", Collections.singletonMap("foo", "bar"));
    logger.error("my name is: {}", "foo");
    logger.error("here is a map: {}. ok?", Collections.singletonMap(2, 5));
    logger.warn("ignored params {}", 4, 6);
    List<String> messages = appender.getMessages();
    assertEquals(5, messages.size());// ww w. ja  v a2s  .  c om
    assertEquals("[INFO][EventLogger] simple message", messages.get(0));
    assertEquals("[WARN][EventLogger] complex message {foo=bar}", messages.get(1));
    assertEquals("[ERROR][EventLogger] my name is: foo", messages.get(2));
    assertEquals("[ERROR][EventLogger] here is a map: {}. ok? {2=5}", messages.get(3));
    assertEquals("[WARN][EventLogger] ignored params 4", messages.get(4));
}

From source file:io.coala.bind.LocalConfig.java

static LocalConfig of(final String id, final Map<?, ?>... imports) {
    return ConfigFactory.create(LocalConfig.class,
            ConfigUtil.join(Collections.singletonMap(ID_KEY, id), imports));
}

From source file:od.framework.api.FeatureFlagController.java

@RequestMapping(value = {
        "/features/{key}" }, method = RequestMethod.GET, produces = "application/json;charset=utf-8")
public Map<String, Object> featuresByKey(@PathVariable("key") final String key) {
    Object value = features.get(key);
    return Collections.singletonMap(key, value);
}

From source file:org.appcomponents.platform.context.PlatformDefaultModuleWebIntegrationTest.java

@Test
public void moduleIntegrationTest() {
    when().get("/echo").then().contentType(ContentType.TEXT).statusCode(HttpStatus.SC_OK)
            .content(Matchers.is("echo"));
    when().get("/?component={component}",
            Collections.singletonMap(PlatformComponent.PARAM_COMPONENT, PlatformComponent.NONE_COMPONENT))
            .then().contentType(ContentType.TEXT).statusCode(HttpStatus.SC_OK).content(Matchers.is("index"));
    /** Module 1 */
    when().get("/").then().contentType(ContentType.TEXT).statusCode(HttpStatus.SC_OK)
            .content(Matchers.is("main"));
    when().get("/hello").then().contentType(ContentType.TEXT).statusCode(HttpStatus.SC_OK)
            .content(Matchers.is("hello"));
    /** Module 2 */
    when().get("/?component={component}",
            Collections.singletonMap(PlatformComponent.PARAM_COMPONENT, BasicPlatform.MODULE_2)).then()
            .contentType(ContentType.TEXT).statusCode(HttpStatus.SC_OK).content(Matchers.is("main2"));
    when().get("/hello?component={component}",
            Collections.singletonMap(PlatformComponent.PARAM_COMPONENT, BasicPlatform.MODULE_2)).then()
            .contentType(ContentType.TEXT).statusCode(HttpStatus.SC_OK).content(Matchers.is("hello2"));
}

From source file:com.streamsets.datacollector.event.handler.remote.TestRemoteStateEventListener.java

@Test
public void testRemoteStateEventListener() throws Exception {
    RemoteStateEventListener remoteStateEventListener = new RemoteStateEventListener(new Configuration());
    remoteStateEventListener.init();//from  w w w .j  av  a 2  s  .c o  m
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(RemoteDataCollector.IS_REMOTE_PIPELINE, true);
    PipelineState pipelineState = new PipelineStateImpl("user", "name", "0", PipelineStatus.RUNNING, "msg", -1,
            attributes, ExecutionMode.STANDALONE, "", 1, -1);
    remoteStateEventListener.onStateChange(null, pipelineState, null, null,
            Collections.singletonMap(Source.POLL_SOURCE_OFFSET_KEY, "offset:1000"));
    Collection<Pair<PipelineState, Map<String, String>>> pipelineStateAndOffset = remoteStateEventListener
            .getPipelineStateEvents();
    Assert.assertEquals(1, pipelineStateAndOffset.size());
    Assert.assertEquals(PipelineStatus.RUNNING, pipelineStateAndOffset.iterator().next().getLeft().getStatus());
    Assert.assertEquals("offset:1000",
            pipelineStateAndOffset.iterator().next().getRight().get(Source.POLL_SOURCE_OFFSET_KEY));
    Assert.assertEquals(0, remoteStateEventListener.getPipelineStateEvents().size());

    PipelineState pipelineStateDeleted = new PipelineStateImpl("user", "name", "0", PipelineStatus.DELETED,
            "msg", -1, attributes, ExecutionMode.STANDALONE, "", 1, -1);
    remoteStateEventListener.onStateChange(null, pipelineState, null, null,
            Collections.singletonMap(Source.POLL_SOURCE_OFFSET_KEY, "offset:old"));
    remoteStateEventListener.onStateChange(null, pipelineStateDeleted, null, null,
            Collections.singletonMap(Source.POLL_SOURCE_OFFSET_KEY, "offset:new"));
    pipelineStateAndOffset = remoteStateEventListener.getPipelineStateEvents();
    Assert.assertEquals(2, pipelineStateAndOffset.size());
    Iterator<Pair<PipelineState, Map<String, String>>> iterator = pipelineStateAndOffset.iterator();
    iterator.next();
    Pair<PipelineState, Map<String, String>> pair = iterator.next();
    Assert.assertEquals(PipelineStatus.DELETED, pair.getLeft().getStatus());
    Assert.assertEquals("offset:new", pair.getRight().get(Source.POLL_SOURCE_OFFSET_KEY));
    Assert.assertEquals(0, remoteStateEventListener.getPipelineStateEvents().size());
}

From source file:com.creactiviti.piper.core.pipeline.YamlPipelineRepository.java

protected Pipeline parsePipeline(IdentifiableResource aResource) {
    try {/*w  w  w  . j a  v  a2s.c om*/
        Map<String, Object> yamlMap = parse(aResource);
        yamlMap.put(DSL.ID, aResource.getId());
        return new SimplePipeline(yamlMap);
    } catch (Exception e) {
        SimplePipeline pipeline = new SimplePipeline(Collections.singletonMap(DSL.ID, aResource.getId()));
        pipeline.setError(new ErrorObject(e.getMessage(), ExceptionUtils.getStackFrames(e)));
        return pipeline;
    }
}

From source file:com.yahoo.elide.core.exceptions.HttpStatusException.java

public Pair<Integer, JsonNode> getErrorResponse() {
    Map<String, List<String>> errors = Collections.singletonMap("errors",
            Collections.singletonList(toString()));
    return buildResponse(errors);
}