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.vivastream.security.oauth2.provider.DynamoDBUserDetailsManager.java

protected UserDetails loadUserByUsername(String username, boolean consistentRead)
        throws UsernameNotFoundException {
    GetItemResult result = client.getItem(schema.getTableName(),
            Collections.singletonMap(schema.getColumnUsername(), new AttributeValue(username)), consistentRead);

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

    String password = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnPassword()));
    String authoritiesStr = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnAuthorities()));

    List<GrantedAuthority> authorities = null;
    if (StringUtils.hasText(authoritiesStr)) {
        authorities = AuthorityUtils.commaSeparatedStringToAuthorityList(authoritiesStr);
    } else {
        authorities = Collections.emptyList();
    }

    UserDetails user = buildUserFromItem(username, password, authorities, item);
    return user;
}

From source file:ca.uhn.hunit.example.MllpHl7v2MessageSwapper.java

public MllpHl7v2MessageSwapper(boolean thePrintOutput, String theOldValue, String theNewValue,
        int theIterations) {
    this(thePrintOutput, Collections.singletonMap(theOldValue, theNewValue), theIterations);
}

From source file:com.netflix.nicobar.core.persistence.ArchiveRepositoryTest.java

/**
 * Test insert, update, delete/*from  w ww .j  a v  a2s  .c om*/
 */
@Test
public void testRoundTrip() throws Exception {
    ArchiveRepository repository = createRepository();
    JarScriptArchive jarScriptArchive = new JarScriptArchive.Builder(testArchiveJarFile).build();
    ModuleId testModuleId = TEST_MODULE_SPEC_JAR.getModuleId();
    repository.insertArchive(jarScriptArchive);
    Map<ModuleId, Long> archiveUpdateTimes = repository.getDefaultView().getArchiveUpdateTimes();
    long expectedUpdateTime = Files.getLastModifiedTime(testArchiveJarFile).toMillis();
    assertEquals(archiveUpdateTimes, Collections.singletonMap(testModuleId, expectedUpdateTime));

    // assert getScriptArchives
    Set<ScriptArchive> scriptArchives = repository.getScriptArchives(archiveUpdateTimes.keySet());
    assertEquals(scriptArchives.size(), 1, scriptArchives.toString());
    ScriptArchive scriptArchive = scriptArchives.iterator().next();
    assertEquals(scriptArchive.getModuleSpec().getModuleId(), testModuleId);
    assertEquals(scriptArchive.getCreateTime(), expectedUpdateTime);

    // assert getArchiveSummaries
    List<ArchiveSummary> archiveSummaries = repository.getDefaultView().getArchiveSummaries();
    assertEquals(archiveSummaries.size(), 1);
    ArchiveSummary archiveSummary = archiveSummaries.get(0);
    assertEquals(archiveSummary.getModuleId(), testModuleId);
    assertEquals(archiveSummary.getLastUpdateTime(), expectedUpdateTime);

    // assert getRepositorySummary
    RepositorySummary repositorySummary = repository.getDefaultView().getRepositorySummary();
    assertNotNull(repositorySummary);
    assertEquals(repositorySummary.getArchiveCount(), 1);
    assertEquals(repositorySummary.getLastUpdated(), expectedUpdateTime);

    // advance the timestamp by 10 seconds and update
    expectedUpdateTime = expectedUpdateTime + 10000;
    Files.setLastModifiedTime(testArchiveJarFile, FileTime.fromMillis(expectedUpdateTime));
    jarScriptArchive = new JarScriptArchive.Builder(testArchiveJarFile).build();
    repository.insertArchive(jarScriptArchive);
    archiveUpdateTimes = repository.getDefaultView().getArchiveUpdateTimes();
    assertEquals(archiveUpdateTimes, Collections.singletonMap(testModuleId, expectedUpdateTime));

    // assert getScriptArchives
    scriptArchives = repository.getScriptArchives(archiveUpdateTimes.keySet());
    assertEquals(scriptArchives.size(), 1, scriptArchives.toString());
    scriptArchive = scriptArchives.iterator().next();
    assertEquals(scriptArchive.getModuleSpec().getModuleId(), testModuleId);
    assertEquals(scriptArchive.getCreateTime(), expectedUpdateTime);

    // assert getArchiveSummaries
    archiveSummaries = repository.getDefaultView().getArchiveSummaries();
    assertEquals(archiveSummaries.size(), 1);
    archiveSummary = archiveSummaries.get(0);
    assertEquals(archiveSummary.getModuleId(), testModuleId);
    assertEquals(archiveSummary.getLastUpdateTime(), expectedUpdateTime);

    // assert getRepositorySummary
    repositorySummary = repository.getDefaultView().getRepositorySummary();
    assertNotNull(repositorySummary);
    assertEquals(repositorySummary.getArchiveCount(), 1);
    assertEquals(repositorySummary.getLastUpdated(), expectedUpdateTime);

    // delete module
    repository.deleteArchive(testModuleId);
    archiveUpdateTimes = repository.getDefaultView().getArchiveUpdateTimes();
    assertTrue(archiveUpdateTimes.isEmpty(), archiveUpdateTimes.toString());
}

From source file:ch.cyberduck.core.sds.SDSMissingFileKeysSchedulerFeatureTest.java

@Test
public void testMissingKeys() throws Exception {
    final Host host = new Host(new SDSProtocol(), "duck.ssp-europe.eu", new Credentials(
            System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key")));
    final SDSSession session = new SDSSession(host, new DisabledX509TrustManager(),
            new DefaultX509KeyManager());
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path room = new Path("CD-TEST-ENCRYPTED",
            EnumSet.of(Path.Type.directory, Path.Type.volume, Path.Type.vault));
    final byte[] content = RandomUtils.nextBytes(32769);
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);//from ww  w  .j  a  va2 s.  c o m
    final Path test = new Path(room, UUID.randomUUID().toString(),
            EnumSet.of(Path.Type.file, Path.Type.decrypted));
    final SDSEncryptionBulkFeature bulk = new SDSEncryptionBulkFeature(session);
    bulk.pre(Transfer.Type.upload, Collections.singletonMap(test, status), new DisabledConnectionCallback());
    final CryptoWriteFeature writer = new CryptoWriteFeature(session, new SDSWriteFeature(session));
    final StatusOutputStream<VersionId> out = writer.write(test, status, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
    final VersionId version = out.getStatus();
    assertNotNull(version);
    assertTrue(new DefaultFindFeature(session).find(test));
    assertEquals(content.length, new SDSAttributesFinderFeature(session).find(test).getSize());
    final SDSMissingFileKeysSchedulerFeature background = new SDSMissingFileKeysSchedulerFeature(session);
    final List<UserFileKeySetRequest> processed = background.operate(new PasswordCallback() {
        @Override
        public Credentials prompt(final Host bookmark, final String title, final String reason,
                final LoginOptions options) throws LoginCanceledException {
            return new VaultCredentials("ahbic3Ae");
        }
    }, test);
    assertFalse(processed.isEmpty());
    boolean found = false;
    for (UserFileKeySetRequest p : processed) {
        if (p.getFileId().equals(Long.parseLong(version.id))) {
            found = true;
            break;
        }
    }
    assertTrue(found);
    new SDSDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();
}

From source file:com.phoenixnap.oss.ramlapisync.naming.SchemaHelper.java

/**
 * Converts a simple parameter, ie String, or Boxed Primitive into
 * /*from  w w w  .j a v  a2  s .c o  m*/
 * @param param The Java Parameter to convert
 * @param paramComment The associated Javadoc if any
 * @return A map of query parameters that map into the supplied type
 */
public static Map<String, QueryParameter> convertParameterToQueryParameter(final Parameter param,
        final String paramComment) {
    QueryParameter queryParam = new QueryParameter();
    ApiParameterMetadata parameterMetadata = new ApiParameterMetadata(param);

    ParamType type = mapSimpleType(param.getType());

    if (type == null) {
        throw new IllegalArgumentException("This method is only applicable to simple types or primitives");
    }

    if (StringUtils.hasText(paramComment)) {
        queryParam.setDescription(paramComment);
    }

    // Populate parameter model with data such as name, type and required/not

    queryParam.setDisplayName(parameterMetadata.getName());
    queryParam.setType(mapSimpleType(param.getType()));
    if (StringUtils.hasText(parameterMetadata.getExample())) {
        queryParam.setExample(parameterMetadata.getExample());
    }
    queryParam.setRequired(!parameterMetadata.isNullable());
    queryParam.setRepeat(param.getType().isArray()); // TODO we could add validation info
    // here - maybe hook into JSR303
    // annotations
    return Collections.singletonMap(parameterMetadata.getName(), queryParam);
}

From source file:com.espertech.esper.regression.event.TestObjectArrayEventNested.java

public void testConfiguredViaPropsAndXML() {
    Configuration configuration = SupportConfigFactory.getConfiguration();
    configuration.getEngineDefaults().getEventMeta()
            .setDefaultEventRepresentation(Configuration.EventRepresentation.OBJECTARRAY);
    configuration.addEventType("MyOAType", "bean,theString,map".split(","),
            new Object[] { SupportBean.class.getName(), "string", "java.util.Map" });

    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(configuration);
    epService.initialize();//from ww  w. ja v  a  2  s.co  m

    EventType eventType = epService.getEPAdministrator().getConfiguration().getEventType("MyOAType");
    assertEquals(Object[].class, eventType.getUnderlyingType());
    assertEquals(String.class, eventType.getPropertyType("theString"));
    assertEquals(Map.class, eventType.getPropertyType("map"));
    assertEquals(SupportBean.class, eventType.getPropertyType("bean"));

    EPStatement stmt = epService.getEPAdministrator()
            .createEPL("select bean, theString, map('key'), bean.theString from MyOAType");
    SupportUpdateListener listener = new SupportUpdateListener();
    stmt.addListener(listener);
    assertEquals(Object[].class, stmt.getEventType().getUnderlyingType());

    SupportBean bean = new SupportBean("E1", 1);
    epService.getEPRuntime().sendEvent(new Object[] { bean, "abc", Collections.singletonMap("key", "value") },
            "MyOAType");
    EPAssertionUtil.assertProps(listener.assertOneGetNew(),
            "bean,theString,map('key'),bean.theString".split(","), new Object[] { bean, "abc", "value", "E1" });
}

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

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

From source file:de.hybris.platform.core.RestartSlaveTenantTest.java

@Test
public void testCanQueryFlexibleSearchAfterRestart() {

    final TitleModel titleModel = modelService.create(TitleModel.class);
    titleModel.setCode("tm");
    titleModel.setName("foo");

    modelService.save(titleModel);//from  w ww .  ja  v  a2  s  .  c  o m

    SearchResult<TitleModel> result = flexibleSearchService.search(
            "SELECT {PK} from {" + TitleModel._TYPECODE + "} WHERE {" + TitleModel.CODE + "}  = ?code",
            Collections.singletonMap("code", "tm"));

    Assert.assertNotNull(result);
    Assert.assertTrue(CollectionUtils.isNotEmpty(result.getResult()));
    Assert.assertEquals(1, result.getResult().size());

    destroyAndForceStartupCurrentTenant();

    result = flexibleSearchService.search(
            "SELECT {PK} from {" + TitleModel._TYPECODE + "} WHERE {" + TitleModel.CODE + "}  = ?code",
            Collections.singletonMap("code", "tm"));

    Assert.assertNotNull(result);
    Assert.assertTrue(CollectionUtils.isNotEmpty(result.getResult()));
    Assert.assertEquals(1, result.getResult().size());
}

From source file:com.xtructure.xutil.coll.UTestMapBuilder.java

public void putAllBehavesAsExpected() {
    MapBuilder<String, String> mb = new MapBuilder<String, String>();
    assertThat("", //
            mb.newInstance(), isEmpty());
    MapBuilder<String, String> got = mb.putAll(Collections.singletonMap("one", "1"));
    assertThat("", //
            got, isSameAs(mb));/* ww w  .j  a  va 2  s.c o  m*/
    assertThat("", //
            mb.newInstance(), hasSize(1), containsKey("one"), containsValue("1"));
}

From source file:marshalsec.YAMLBase.java

@Args(minArgs = 1, args = { "jndiUrl" }, defaultArgs = { MarshallerBase.defaultJNDIUrl })
public Object makeBeanFactoryPointcutAdvisor(UtilFactory uf, String[] args) throws Exception {
    Map<String, String> properties = new LinkedHashMap<>();
    String jndiUrl = args[0];/*w  ww.j a  va  2s. com*/
    properties.put("adviceBeanName", writeString(jndiUrl));
    properties.put("beanFactory", writeObject(SimpleJndiBeanFactory.class,
            Collections.singletonMap("shareableResources", writeArray(writeString(jndiUrl))), 2));
    return writeSet(writeObject(DefaultBeanFactoryPointcutAdvisor.class, properties, 1),
            writeConstructor(DefaultBeanFactoryPointcutAdvisor.class, true));
}