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.bccriskadvisory.link.monitor.EdgescanMonitorImpl.java

@Override
public void schedule() {
    synchronized (this) {
        if (scheduled)
            return;

        try {/*w w w  .ja v  a2  s. c om*/
            Map<String, Object> jobDataMap = Collections.singletonMap(KEY, this);

            scheduler.scheduleJob(JOB_NAME, EdgescanLinkTask.class, jobDataMap,
                    Date.from(Utilities.now().toInstant()), interval);
        } catch (Exception e) {
            getLog().error("Unable to schedule edgescan link task.");
        }

        scheduled = true;
    }
}

From source file:marshalsec.YAMLBase.java

@Args(minArgs = 2, args = { "codebase", "class" }, defaultArgs = { MarshallerBase.defaultCodebase,
        MarshallerBase.defaultCodebaseClass })
public Object makeWrapperConnPool(UtilFactory uf, String[] args) throws Exception {
    return writeObject(WrapperConnectionPoolDataSource.class, Collections.singletonMap("userOverridesAsString",
            writeString(C3P0WrapperConnPool.makeC3P0UserOverridesString(args[0], args[1]))));
}

From source file:io.wcm.caravan.io.http.impl.CaravanHttpClientHystrixTest.java

@Before
public void setUp() {

    ArchaiusConfig.initialize();//  w w w  .  j  a  v  a2s.  c  om
    context.registerInjectActivateService(new CaravanHttpClientConfig(),
            Collections.singletonMap(CaravanHttpClientConfig.SERVLET_CLIENT_ENABLED, true));
    context.registerInjectActivateService(new SimpleLoadBalancerFactory());
    context.registerInjectActivateService(new LoadBalancerCommandFactory());
    context.registerInjectActivateService(new HttpClientFactoryImpl());
    context.registerInjectActivateService(new ServletHttpClient());
    context.registerInjectActivateService(new ApacheHttpClient());
    context.registerInjectActivateService(new RibbonHttpClient());
    underTest = context.registerInjectActivateService(new CaravanHttpClientImpl());

    host = "localhost:" + server.port();

    server.stubFor(get(urlEqualTo(HTTP_200_URI)).willReturn(aResponse()
            .withHeader("Content-Type", "text/plain;charset=" + CharEncoding.UTF_8).withBody("success")));
    server.stubFor(
            get(urlEqualTo(HTTP_404_URI)).willReturn(aResponse().withStatus(HttpServletResponse.SC_NOT_FOUND)));
    server.stubFor(get(urlEqualTo(HTTP_500_URI))
            .willReturn(aResponse().withStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR)));

    context.registerInjectActivateService(new CaravanHttpServiceConfig(),
            ImmutableMap.<String, Object>builder()
                    .put(CaravanHttpServiceConfig.SERVICE_ID_PROPERTY, SERVICE_NAME)
                    .put(CaravanHttpServiceConfig.RIBBON_HOSTS_PROPERTY, host)
                    .put(CaravanHttpServiceConfig.RIBBON_MAXAUTORETRIES_PROPERTY, 0)
                    .put(CaravanHttpServiceConfig.RIBBON_MAXAUTORETRIESNEXTSERVER_PROPERTY, 0)
                    .put(CaravanHttpServiceConfig.HYSTRIX_CIRCUITBREAKER_REQUESTVOLUMETHRESHOLD_PROPERTY, 20)
                    .put(CaravanHttpServiceConfig.HYSTRIX_CIRCUITBREAKER_ERRORTHRESHOLDPERCENTAGE_PROPERTY, 50)
                    .build());
}

From source file:net.skhome.roborace.web.controller.UserController.java

@RequestMapping(method = RequestMethod.POST)
@ResponseBody/*w  w  w . ja  v  a2s  . c om*/
public Map<String, String> createUserAccount(@RequestBody @Valid final UserAccount account,
        final HttpServletResponse response) {

    try {
        service.createUserAccount(account);
        response.setStatus(HttpServletResponse.SC_CREATED);
        return Collections.singletonMap("id", account.getId());
    } catch (DataAccessException ex) {
        throw new ResourceAlreadyExistsException(account.getUsername());
    }

}

From source file:net.ontopia.topicmaps.nav2.servlets.AutoSuggestServlet.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setContentType("text/plain; charset=utf-8");

    String tmid = request.getParameter("tm");
    if (tmid == null)
        throw new ServletException("Parameter tm is not given.");
    String term = request.getParameter("term");
    if (term == null)
        throw new ServletException("Parameter term is not given.");

    TopicMapStoreIF store = TopicMaps.createStore(tmid, true);

    if (store instanceof net.ontopia.topicmaps.impl.basic.InMemoryTopicMapStore)
        term = term + '*';

    try {/*from www.  jav  a 2 s. c  o  m*/
        QueryProcessorIF qp = QueryUtils.getQueryProcessor(store.getTopicMap());
        QueryResultIF qr = qp.execute(query, Collections.singletonMap("TERM", term));
        System.out.println("query: " + query);
        PrintWriter w = response.getWriter();
        w.write("{ results: [\n");
        int count = 0;
        while (qr.next()) {
            if (count > limit)
                break;
            if (count > 0)
                w.write(",\n");
            TopicIF topic = (TopicIF) qr.getValue(0);
            String desc = (String) qr.getValue(1);
            w.write("    { id: \"");
            w.write(topic.getObjectId());
            w.write("\", value: \"");
            w.write(escape(TopicStringifiers.toString(topic)));
            w.write("\", info: \"");
            w.write((desc == null ? "" : escape(desc)));
            w.write("\" }");
            count++;
        }
        w.write("\n] }\n");

    } catch (Exception e) {
        throw new ServletException(e);
    } finally {
        store.close();
    }
}

From source file:de.codecentric.boot.admin.services.ApplicationRegistratorTest.java

@SuppressWarnings("rawtypes")
@Test/*  w  w w .j  ava2s  .c o  m*/
public void register_successful() {
    when(restTemplate.postForEntity(isA(String.class), isA(HttpEntity.class), eq(Map.class)))
            .thenReturn(new ResponseEntity<Map>(Collections.singletonMap("id", "-id-"), HttpStatus.CREATED));

    assertTrue(registrator.register());
    verify(restTemplate).postForEntity("http://sba:8080/api/applications",
            new HttpEntity<>(Application.create("AppName").withHealthUrl("http://localhost:8080/health")
                    .withManagementUrl("http://localhost:8080/mgmt").withServiceUrl("http://localhost:8080")
                    .build(), headers),
            Map.class);
}

From source file:feign.form.BasicClientTest.java

@Test
public void testQueryMap() {
    Map<String, Object> value = Collections.singletonMap("filter",
            Arrays.asList("one", "two", "three", "four"));

    val stringResponse = api.queryMap(value);
    Assert.assertEquals("4", stringResponse);
}

From source file:org.apache.niolex.config.ctrl.LoginController.java

@RequestMapping(method = RequestMethod.POST)
public @ResponseBody Map<String, ? extends Object> create(@ModelAttribute LoginInfo info,
        HttpServletRequest req) {/*w w  w .jav a2  s  .  com*/
    Set<ConstraintViolation<LoginInfo>> failures = validator.validate(info);
    if (!failures.isEmpty()) {
        return Collections.singletonMap("msg", failures.iterator().next().getMessage());
    } else {
        CenterConnector updater = null;
        try {
            updater = new CenterConnector(serverAddress);
            String res = updater.subscribeAuthInfo(info.getUsername(), info.getPassword());
            if (!res.startsWith("SUCC")) {
                updater.stop();
                return Collections.singletonMap("msg", "???");
            } else {
                // Attach the updater to session.
                HttpSession sess = req.getSession();
                sess.setAttribute("login_cli", updater);
                // Auth success.
                return Collections.singletonMap("msg", "SUCCESS");
            }
        } catch (Exception e) {
            LOG.error("Error occured when connect to config center.", e);
            if (updater != null) {
                updater.stop();
            }
            return Collections.singletonMap("msg", "?");
        }
    }
}

From source file:de.codecentric.boot.admin.registry.StatusUpdaterTest.java

@Test
@SuppressWarnings("rawtypes")
public void test_update_statusUnchanged() {
    when(template.getForEntity("health", Map.class))
            .thenReturn(ResponseEntity.ok((Map) Collections.singletonMap("status", "UNKNOWN")));

    updater.updateStatus(Application.create("foo").withId("id").withHealthUrl("health").build());

    verify(publisher, never()).publishEvent(argThat(isA(ClientApplicationStatusChangedEvent.class)));
}