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.jboss.as.test.integration.logging.perdeploy.JBossLoggingPropertiesTestCase.java

@Test
public void logsTest() throws IOException {
    final String msg = "logTest: jboss-logging.properties 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;//from w w  w. j  av  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:ballantines.avionics.flightgear.connect.HttpPropertyServiceImpl.java

@Override
public void writeProperty(String property, Object value) {
    writeProperties(Collections.singletonMap(property, value));
}

From source file:com.flipkart.flux.guice.module.AkkaModuleTest.java

@Test
public void testGetRouterConfigurations_shouldGetConcurrencyValueFromConfigFile() throws Exception {
    when(configuration.getProperty(/*from   ww w .  ja v  a 2s  .co m*/
            "com.flipkart.flux.integration.SimpleWorkflow_simpleIntegerReturningTask.executionConcurrency"))
                    .thenReturn(5);
    when(deploymentUnit.getTaskConfiguration()).thenReturn(configuration);
    Map<String, DeploymentUnit> deploymentUnitsMap = new HashMap<String, DeploymentUnit>() {
        {
            put("DeploymentUnit1", deploymentUnit);
        }
    };
    int defaultNoOfActors = 10;

    Class simpleWorkflowClass = this.getClass().getClassLoader()
            .loadClass("com.flipkart.flux.integration.SimpleWorkflow");
    Map<String, Method> taskMethods = Collections.singletonMap(
            "com.flipkart.flux.integration.SimpleWorkflow_simpleIntegerReturningTask_com.flipkart.flux.integration.IntegerEvent_version1",
            simpleWorkflowClass.getMethod("simpleIntegerReturningTask"));
    when(deploymentUnit.getTaskMethods()).thenReturn(taskMethods);

    when(deploymentUnitManager.getAllDeploymentUnits()).thenReturn(Collections.singleton(deploymentUnit));

    assertThat(akkaModule.getRouterConfigs(deploymentUnitManager, new TaskRouterUtil(defaultNoOfActors)))
            .containsEntry("com.flipkart.flux.integration.SimpleWorkflow_simpleIntegerReturningTask", 5);
}

From source file:com.github.joshelser.accumulo.DelimitedIngestMiniClusterTest.java

@BeforeClass
public static void startMiniCluster() throws Exception {
    File targetDir = new File(System.getProperty("user.dir"), "target");
    File macDir = new File(targetDir, DelimitedIngestMiniClusterTest.class.getSimpleName() + "_cluster");
    if (macDir.exists()) {
        FileUtils.deleteDirectory(macDir);
    }/*from   w  w w. ja va 2 s  .c  o  m*/
    MiniAccumuloConfigImpl config = new MiniAccumuloConfigImpl(macDir, ROOT_PASSWORD);
    config.setNumTservers(1);
    config.setInstanceName(INSTANCE_NAME);
    config.setSiteConfig(Collections.singletonMap("fs.file.impl", RawLocalFileSystem.class.getName()));
    config.useMiniDFS(true);
    MAC = new MiniAccumuloClusterImpl(config);
    MAC.start();
    FS = FileSystem.get(MAC.getMiniDfs().getConfiguration(0));

    ARGS = new DelimitedIngestArguments();
    ARGS.setUsername("root");
    ARGS.setPassword(ROOT_PASSWORD);
    ARGS.setInstanceName(INSTANCE_NAME);
    ARGS.setZooKeepers(MAC.getZooKeepers());
    ARGS.setConfiguration(MAC.getMiniDfs().getConfiguration(0));
}

From source file:org.cloudfoundry.caldecott.client.TunnelHelper.java

public static void deployTunnelApp(CloudFoundryClient client) {
    ClassPathResource cpr = new ClassPathResource("caldecott_helper.zip");
    try {// www .j a  va2s  . co  m
        File temp = copyCaldecottZipFile(cpr);
        client.createApplication(TUNNEL_APP_NAME, new Staging("ruby19", "sinatra"), 64,
                Arrays.asList(getRandomUrl(client, TUNNEL_APP_NAME)), Arrays.asList(new String[] {}), false);
        client.uploadApplication(TUNNEL_APP_NAME, temp);
        client.updateApplicationEnv(TUNNEL_APP_NAME,
                Collections.singletonMap("CALDECOTT_AUTH", UUID.randomUUID().toString()));
        client.startApplication(TUNNEL_APP_NAME);
        temp.delete();
    } catch (IOException e) {
        throw new TunnelException("Unable to deploy the Caldecott server application", e);
    }
}

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

/**
 * Request Cognito Identity Id/*from w w w  .  j a v a  2  s  .  c  om*/
 *
 * @param authorization string that is associated to the identity of a user
 * @return user
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getIdentity(@HeaderParam("Authorization") String authorization) {
    try {
        Identity identity = identityService.getOpenIdTokenForDeveloperIdentity(authorization);
        return Response.ok(identity).build();
    } catch (AuthorizationException e) {
        String authenticateHeader = e.getAuthenticateHeader();
        if (authenticateHeader == null) {
            return response(Response.Status.UNAUTHORIZED, e.getMessage());
        } else {
            return response(Response.Status.UNAUTHORIZED, e.getMessage(),
                    Collections.singletonMap("WWW-Authenticate", authenticateHeader));
        }
    }
}

From source file:com.google.appengine.tck.blobstore.BlobstoreServeTest.java

@Test
@RunAsClient//from  ww w .j  a  va2s  . c o m
public void testUploadedFileHasCorrectContent_upload(@ArquillianResource URL url) throws Exception {
    FileUploader fileUploader = new FileUploader();
    String uploadUrl = fileUploader.getUploadUrl(new URL(url, "getUploadUrl"));
    final String blobKey = fileUploader.uploadFile(uploadUrl, "file", FILENAME, CONTENT_TYPE, UPLOADED_CONTENT);

    final String content = new String(UPLOADED_CONTENT);
    final URI uri = new URL(url, "blobserviceserve?blobKey=" + blobKey).toURI();
    final HttpClient client = new DefaultHttpClient();
    try {
        doTest(client, uri, null, null, content);
        doTest(client, uri, Collections.<Header>singleton(new BasicHeader("Range", "bytes=1-3")), null,
                content.substring(1, 3 + 1));
        doTest(client, uri, null, Collections.singletonMap("blobRange", "2"), content.substring(2));
        doTest(client, uri, null, Collections.singletonMap("blobRangeString", "bytes=2-5"),
                content.substring(2, 5 + 1));
    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:se.inera.intyg.intygstjanst.web.integration.stub.SendMessageToCareResponderStubRestApi.java

@POST
@Path("/clear")
@Produces(MediaType.APPLICATION_XML)/*from w  ww .  j av  a  2  s. c o  m*/
public Response clearJson() {
    storage.clear();
    String xmlResponse = buildXMLResponse(true, 0, Collections.singletonMap("result", "ok"));
    return Response.ok(xmlResponse).build();
}

From source file:com.smartitengineering.event.hub.spi.hbase.persistents.Utils.java

public static void organizeByPrefix(Map<byte[], byte[]> fieldMap, Map<String, Map<String, byte[]>> fieldsByName,
        char separator) {
    logger.info("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 . j  a  v  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:com.hortonworks.registries.schemaregistry.avro.AvroCompositeSchemasTest.java

@Before
public void testComposites() throws Exception {
    versions = new HashMap<>();
    versions.put("utils", cretaeSchemaVersionInfo("/avro/composites/util.avsc"));
    versions.put("account", cretaeSchemaVersionInfo("/avro/composites/account.avsc"));
    versions.put("account-cyclic", cretaeSchemaVersionInfo("/avro/composites/account-cyclic.avsc"));
    versions.put("account-dep", cretaeSchemaVersionInfo("/avro/composites/account-dep.avsc"));

    avroSchemaProvider = new AvroSchemaProvider();
    Map<String, Object> config = Collections.singletonMap(SchemaProvider.SCHEMA_VERSION_RETRIEVER_CONFIG,
            (SchemaVersionRetriever) key -> versions.get(key.getSchemaName()));
    avroSchemaProvider.init(config);// w ww . ja v  a 2 s.co  m
}