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:io.swagger.test.integration.responses.ResponseWithExceptionTestIT.java

@Test
public void verifyApiExceptionAsXml() throws IOException {
    try {/* w w w  .  j  a v  a  2 s .c  o m*/
        final Map<String, String> headerParams = Collections.singletonMap(HttpHeaders.ACCEPT,
                MediaType.APPLICATION_XML);
        client.invokeAPI("/throwApiException", "GET", new HashMap<String, String>(), null, headerParams, null,
                null, null, new String[0]);
        Assert.fail("Exception was expected!");
    } catch (ApiException e) {
        final Response.Status expected = Response.Status.CONFLICT;
        Assert.assertEquals(e.getCode(), expected.getStatusCode());
        final ApiError error = new XmlMapper().readValue(e.getMessage(), ApiError.class);
        Assert.assertEquals(error.getCode(), expected.getStatusCode());
        Assert.assertEquals(error.getMessage(), expected.getReasonPhrase());
    }
}

From source file:sample.jersey.RestEndpoint.java

@POST
@Path("multiply")
@Consumes(MediaType.APPLICATION_JSON)/* w  ww .  j  a v  a  2  s . co m*/
@Produces(MediaType.APPLICATION_JSON)
public Response multiply(Map<String, Object> request) {
    Integer a = (Integer) request.get("a");
    Integer b = (Integer) request.get("b");

    if (a == null || b == null) {
        return Response.status(Response.Status.BAD_REQUEST).entity(Collections.singletonMap("errorMessage",
                "request JSON should contain two numbers, with keys a & b")).build();
    }
    return Response.ok(Collections.singletonMap("product", a + b)).build();
}

From source file:com.gm.machine.dao.ProductHibernateDao.java

/**
 * {@inheritDoc}//from ww w  .j a  v a2  s.  c om
 * 
 * @since 2012-11-25
 * @see com.gm.machine.api.AdvertDao#batchDelete(java.util.List)
 */
@Override
public void batchDelete(List<Long> ids) {
    String hql = "delete from Product where id in(:ids)";
    Map<String, List<Long>> values = Collections.singletonMap("ids", ids);
    super.batchExecute(hql, values);

}

From source file:com.vivastream.security.oauth2.provider.DynamoDBClientDetailsService.java

@Override
public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
    GetItemResult result = client.getItem(schema.getTableName(),
            Collections.singletonMap(schema.getColumnClientId(), new AttributeValue(clientId)));

    Map<String, AttributeValue> item = result.getItem();
    if (item == null) {
        return null;
    }/*  www  . j  av a2 s .co  m*/

    String resourceIds = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnResourceIds()));
    String scopes = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnScopes()));
    String grantTypes = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnAuthorizedGrantTypes()));
    String authorities = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnAuthorities()));
    String redirectUris = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnRegisteredRedirectUris()));

    String clientSecret = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnClientSecret()));

    ClientDetails clientDetails = createClientDetails(clientId, resourceIds, scopes, grantTypes, authorities,
            redirectUris, clientSecret, item);
    return clientDetails;
}

From source file:com.rosy.bill.utils.jmx.JmxClientTemplate.java

/**
 * JMX Server./*from  w  w w.  j  a  v a2 s . c  o m*/
 */
@SuppressWarnings("unchecked")
private void initConnector(final String serviceUrl, final String userName, final String passwd)
        throws IOException {
    JMXServiceURL url = new JMXServiceURL(serviceUrl);

    boolean hasCredentlals = StringUtils.isNotBlank(userName);
    if (hasCredentlals) {
        Map environment = Collections.singletonMap(JMXConnector.CREDENTIALS, new String[] { userName, passwd });
        connector = JMXConnectorFactory.connect(url, environment);
    } else {
        connector = JMXConnectorFactory.connect(url);
    }

    connection = connector.getMBeanServerConnection();
    connected.set(true);
}

From source file:org.elasticsearch.smoketest.SmokeTestWatcherWithSecurityIT.java

@Before
public void startWatcher() throws Exception {
    StringEntity entity = new StringEntity("{ \"value\" : \"15\" }", ContentType.APPLICATION_JSON);
    assertOK(adminClient().performRequest("PUT", "my_test_index/doc/1",
            Collections.singletonMap("refresh", "true"), entity));

    // delete the watcher history to not clutter with entries from other test
    adminClient().performRequest("DELETE", ".watcher-history-*", Collections.emptyMap());

    // create one document in this index, so we can test in the YAML tests, that the index cannot be accessed
    Response resp = adminClient().performRequest("PUT", "/index_not_allowed_to_read/doc/1",
            Collections.emptyMap(), new StringEntity("{\"foo\":\"bar\"}", ContentType.APPLICATION_JSON));
    assertThat(resp.getStatusLine().getStatusCode(), is(201));

    assertBusy(() -> {/*from w w w . ja v a  2s  .  c  o m*/
        try {
            Response statsResponse = adminClient().performRequest("GET", "_xpack/watcher/stats");
            ObjectPath objectPath = ObjectPath.createFromResponse(statsResponse);
            String state = objectPath.evaluate("stats.0.watcher_state");

            switch (state) {
            case "stopped":
                Response startResponse = adminClient().performRequest("POST", "_xpack/watcher/_start");
                assertOK(startResponse);
                String body = EntityUtils.toString(startResponse.getEntity());
                assertThat(body, containsString("\"acknowledged\":true"));
                break;
            case "stopping":
                throw new AssertionError("waiting until stopping state reached stopped state to start again");
            case "starting":
                throw new AssertionError("waiting until starting state reached started state");
            case "started":
                // all good here, we are done
                break;
            default:
                throw new AssertionError("unknown state[" + state + "]");
            }
        } catch (IOException e) {
            throw new AssertionError(e);
        }
    });

    assertBusy(() -> {
        for (String template : WatcherIndexTemplateRegistryField.TEMPLATE_NAMES) {
            assertOK(adminClient().performRequest("HEAD", "_template/" + template));
        }
    });
}

From source file:playground.app.StubPersonController.java

@RequestMapping("/admin")
public Map<String, String> admin() {
    return Collections.singletonMap("isadmin", "true");
}

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

@Override
public long countActivatedSince(Date date) {
    return jdbcTemplate.queryForObject(countActivatedSinceSql, Collections.singletonMap("date", date),
            Long.class);
}