List of usage examples for java.util Collections singletonMap
public static <K, V> Map<K, V> singletonMap(K key, V value)
From source file:ch.cyberduck.core.spectra.SpectraUploadFeatureTest.java
@Test public void testUpload() throws Exception { final Host host = new Host(new SpectraProtocol() { @Override//ww w . j a v a2 s . c o m public Scheme getScheme() { return Scheme.http; } }, System.getProperties().getProperty("spectra.hostname"), Integer.valueOf(System.getProperties().getProperty("spectra.port")), new Credentials(System.getProperties().getProperty("spectra.user"), System.getProperties().getProperty("spectra.key"))); final SpectraSession session = new SpectraSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager()); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); final int length = 32770; final byte[] content = RandomUtils.nextBytes(length); final OutputStream out = local.getOutputStream(false); IOUtils.write(content, out); out.close(); final Path container = new Path("cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final TransferStatus writeStatus = new TransferStatus().length(content.length); final SpectraBulkService bulk = new SpectraBulkService(session); bulk.pre(Transfer.Type.upload, Collections.singletonMap(test, writeStatus), new DisabledConnectionCallback()); final SpectraUploadFeature upload = new SpectraUploadFeature(new SpectraWriteFeature(session), new SpectraBulkService(session)); upload.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), writeStatus, new DisabledConnectionCallback()); final byte[] buffer = new byte[content.length]; final TransferStatus readStatus = new TransferStatus().length(content.length); bulk.pre(Transfer.Type.download, Collections.singletonMap(test, readStatus), new DisabledConnectionCallback()); final InputStream in = new SpectraReadFeature(session).read(test, readStatus, new DisabledConnectionCallback()); IOUtils.readFully(in, buffer); in.close(); assertArrayEquals(content, buffer); new SpectraDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); local.delete(); session.close(); }
From source file:org.springframework.cloud.dataflow.shell.command.HttpCommands.java
@CliCommand(value = { POST_HTTPSOURCE }, help = "POST data to http endpoint") public String postHttp(@CliOption(mandatory = false, key = { "", "target" }, help = "the location to post to", unspecifiedDefaultValue = "http://localhost:9000") String target, @CliOption(mandatory = false, key = "data", help = "the text payload to post. exclusive with file. embedded double quotes are not supported if next to a space character") String data, @CliOption(mandatory = false, key = "file", help = "filename to read data from. exclusive with data") File file, @CliOption(mandatory = false, key = "contentType", help = "the content-type to use. file is also read using the specified charset", unspecifiedDefaultValue = DEFAULT_MEDIA_TYPE) MediaType mediaType) throws IOException { Assert.isTrue(file != null || data != null, "One of 'file' or 'data' must be set"); Assert.isTrue(file == null || data == null, "Only one of 'file' or 'data' must be set"); if (mediaType.getCharSet() == null) { mediaType = new MediaType(mediaType, Collections.singletonMap("charset", Charset.defaultCharset().toString())); }/* w ww .j ava2s.c o m*/ if (file != null) { InputStreamReader isr = new InputStreamReader(new FileInputStream(file), mediaType.getCharSet()); data = FileCopyUtils.copyToString(isr); } final StringBuilder buffer = new StringBuilder(); URI requestURI = URI.create(target); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(mediaType); final HttpEntity<String> request = new HttpEntity<String>(data, headers); try { outputRequest("POST", requestURI, mediaType, data, buffer); ResponseEntity<String> response = createRestTemplate(buffer).postForEntity(requestURI, request, String.class); outputResponse(response, buffer); if (!response.getStatusCode().is2xxSuccessful()) { buffer.append(OsUtils.LINE_SEPARATOR) .append(String.format("Error sending data '%s' to '%s'", data, target)); } return buffer.toString(); } catch (ResourceAccessException e) { return String.format(buffer.toString() + "Failed to access http endpoint %s", target); } catch (Exception e) { return String.format(buffer.toString() + "Failed to send data to http endpoint %s", target); } }
From source file:org.jasig.services.persondir.support.AttributeBasedCacheKeyGeneratorTest.java
@Test public void testCacheKeyGeneratorWithFactoryBean() { final IPersonAttributeDao personAttributeDao = (IPersonAttributeDao) applicationContext .getBean("personAttributeDao", IPersonAttributeDao.class); final MapCacheProviderFacade cacheProviderFacade = (MapCacheProviderFacade) applicationContext .getBean("cacheProviderFacade", MapCacheProviderFacade.class); assertEquals(0, cacheProviderFacade.getCacheSize()); assertEquals(0, cacheProviderFacade.getFlushCount()); assertEquals(0, cacheProviderFacade.getHitCount()); assertEquals(0, cacheProviderFacade.getMissCount()); assertEquals(0, cacheProviderFacade.getPutCount()); assertEquals(0, cacheProviderFacade.getRemoveCount()); //Should be a miss personAttributeDao.getMultivaluedUserAttributes("edalquist"); assertEquals(1, cacheProviderFacade.getCacheSize()); assertEquals(0, cacheProviderFacade.getFlushCount()); assertEquals(0, cacheProviderFacade.getHitCount()); assertEquals(1, cacheProviderFacade.getMissCount()); assertEquals(1, cacheProviderFacade.getPutCount()); assertEquals(0, cacheProviderFacade.getRemoveCount()); //Should be a hit personAttributeDao.getMultivaluedUserAttributes("edalquist"); assertEquals(1, cacheProviderFacade.getCacheSize()); assertEquals(0, cacheProviderFacade.getFlushCount()); assertEquals(1, cacheProviderFacade.getHitCount()); assertEquals(1, cacheProviderFacade.getMissCount()); assertEquals(1, cacheProviderFacade.getPutCount()); assertEquals(0, cacheProviderFacade.getRemoveCount()); //Should be a hit personAttributeDao.getMultivaluedUserAttributes( Collections.singletonMap("userName", Collections.singletonList((Object) "edalquist"))); assertEquals(1, cacheProviderFacade.getCacheSize()); assertEquals(0, cacheProviderFacade.getFlushCount()); assertEquals(2, cacheProviderFacade.getHitCount()); assertEquals(1, cacheProviderFacade.getMissCount()); assertEquals(1, cacheProviderFacade.getPutCount()); assertEquals(0, cacheProviderFacade.getRemoveCount()); //Should be a miss personAttributeDao.getUserAttributes("edalquist"); assertEquals(2, cacheProviderFacade.getCacheSize()); assertEquals(0, cacheProviderFacade.getFlushCount()); assertEquals(2, cacheProviderFacade.getHitCount()); assertEquals(2, cacheProviderFacade.getMissCount()); assertEquals(2, cacheProviderFacade.getPutCount()); assertEquals(0, cacheProviderFacade.getRemoveCount()); //Should be a hit personAttributeDao.getUserAttributes("edalquist"); assertEquals(2, cacheProviderFacade.getCacheSize()); assertEquals(0, cacheProviderFacade.getFlushCount()); assertEquals(3, cacheProviderFacade.getHitCount()); assertEquals(2, cacheProviderFacade.getMissCount()); assertEquals(2, cacheProviderFacade.getPutCount()); assertEquals(0, cacheProviderFacade.getRemoveCount()); //Should be a hit personAttributeDao.getUserAttributes(Collections.singletonMap("userName", (Object) "edalquist")); assertEquals(2, cacheProviderFacade.getCacheSize()); assertEquals(0, cacheProviderFacade.getFlushCount()); assertEquals(4, cacheProviderFacade.getHitCount()); assertEquals(2, cacheProviderFacade.getMissCount()); assertEquals(2, cacheProviderFacade.getPutCount()); assertEquals(0, cacheProviderFacade.getRemoveCount()); //Should miss personAttributeDao.getPossibleUserAttributeNames(); assertEquals(3, cacheProviderFacade.getCacheSize()); assertEquals(0, cacheProviderFacade.getFlushCount()); assertEquals(4, cacheProviderFacade.getHitCount()); assertEquals(3, cacheProviderFacade.getMissCount()); assertEquals(3, cacheProviderFacade.getPutCount()); assertEquals(0, cacheProviderFacade.getRemoveCount()); //Should hit/* w ww. jav a 2s . c om*/ personAttributeDao.getPossibleUserAttributeNames(); assertEquals(3, cacheProviderFacade.getCacheSize()); assertEquals(0, cacheProviderFacade.getFlushCount()); assertEquals(5, cacheProviderFacade.getHitCount()); assertEquals(3, cacheProviderFacade.getMissCount()); assertEquals(3, cacheProviderFacade.getPutCount()); assertEquals(0, cacheProviderFacade.getRemoveCount()); }
From source file:io.fabric8.maven.enricher.fabric8.IconEnricher.java
@Override public Map<String, String> getAnnotations(Kind kind) { if (kind.isController() || kind == Kind.SERVICE) { String iconUrl = getIconUrl(extractIconRef()); if (iconUrl != null) { log.info("Adding icon for %s", kind.toString().toLowerCase()); log.verbose("Icon URL: %s", iconUrl); return Collections.singletonMap(Fabric8Annotations.ICON_URL.value(), iconUrl); } else {/*from w ww .j a va2 s . c om*/ log.debug("No icon file found for resources of type " + kind); } } return null; }
From source file:com.flipkart.foxtrot.core.datastore.impl.hbase.HBaseDataStoreTest.java
@Test public void testSaveSingle() throws Exception { Document expectedDocument = new Document(); expectedDocument.setId(UUID.randomUUID().toString()); expectedDocument.setTimestamp(System.currentTimeMillis()); JsonNode data = mapper.valueToTree(Collections.singletonMap("TEST_NAME", "SINGLE_SAVE_TEST")); expectedDocument.setData(data);//from w ww .j a v a 2 s. co m HBaseDataStore.save(TEST_APP, expectedDocument); validateSave(expectedDocument); }
From source file:marshalsec.BlazeDSBase.java
@Override @Args(minArgs = 2, args = { "codebase", "class" }, defaultArgs = { MarshallerBase.defaultCodebase, MarshallerBase.defaultCodebaseClass }) public Object makeWrapperConnPool(UtilFactory uf, String[] args) throws Exception { return new PropertyInjectingProxy( Reflections.createWithoutConstructor(WrapperConnectionPoolDataSource.class), Collections.singletonMap("userOverridesAsString", C3P0WrapperConnPool.makeC3P0UserOverridesString(args[0], args[1]))); }
From source file:api.QuizResource.java
@GET @Path("check/{chapter}/{number}") @Produces(MediaType.APPLICATION_JSON)//from w w w .j a v a 2 s. c o m public String checkAnswer(@PathParam("chapter") Integer chapter, @PathParam("number") Integer number, @QueryParam("answer") List<String> answers) { boolean result = quizBean.checkAnswer(chapter, number, answers); ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(Collections.singletonMap("isCorrect", result)); } catch (JsonProcessingException ex) { ex.printStackTrace(); } return jsonError("Unknown json failure :("); }
From source file:org.springframework.social.linkedin.api.impl.CompanyTemplate.java
public void startFollowingCompany(int id) { restOperations.postForLocation(COMPANY_FOLLOW_START_STOP_URL, Collections.singletonMap("id", id)); }
From source file:it.geosolutions.utils.db.Gml2shp.java
public void importGmlIntoShp(File gmlFile, File shpFile) throws Exception { FileDataStoreFactorySpi factory = FileDataStoreFinder.getDataStoreFactory("shp"); Map map = Collections.singletonMap("url", shpFile.toURI().toURL()); DataStore datastore = factory.createNewDataStore(map); GmlImporter.importGml(gmlFile, datastore, forcedInputCrs); }
From source file:com.flipkart.flux.guice.module.AkkaModuleTest.java
@Test public void testGetRouterConfigurations_shouldUseDefaultConcurrentValue() throws Exception { when(deploymentUnit.getTaskConfiguration()).thenReturn(configuration); Map<String, DeploymentUnit> deploymentUnitsMap = new HashMap<String, DeploymentUnit>() { {//from w ww .j av a2s . c om 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", defaultNoOfActors); }