List of usage examples for java.util Collections singletonMap
public static <K, V> Map<K, V> singletonMap(K key, V value)
From source file:marshalsec.Jackson.java
private static String makeSpringJndiBeanFactory(String jndiUrl) { return writeObject(SimpleJndiBeanFactory.class, Collections.singletonMap("shareableResources", writeArray(quoteString(jndiUrl)))); }
From source file:org.craftercms.core.controller.rest.CacheRestController.java
@RequestMapping(value = URL_CLEAR_SCOPE, method = RequestMethod.GET) @ResponseBody/* w w w . j ava 2 s.c om*/ public Map<String, String> clearScope(@RequestParam(REQUEST_PARAM_CONTEXT_ID) String contextId) throws InvalidContextException, CacheException { Context context = storeService.getContext(contextId); if (context == null) { throw new InvalidContextException("No context found for ID " + contextId); } cacheTemplate.getCacheService().clearScope(context); if (logger.isInfoEnabled()) { logger.info("[CACHE] Scope for context " + context + " has been cleared"); } return Collections.singletonMap(MODEL_ATTRIBUTE_MESSAGE, "Cache scope for context '" + contextId + "' has been cleared"); }
From source file:ch.cyberduck.core.spectra.SpectraWriteFeatureTest.java
@Test public void testWriteOverwrite() throws Exception { final Host host = new Host(new SpectraProtocol() { @Override/*from w w w. j ava2 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 Path container = new Path("cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path test = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); final byte[] content = RandomUtils.nextBytes(1000); final TransferStatus status = new TransferStatus().length(content.length); status.setChecksum(new CRC32ChecksumCompute().compute(new ByteArrayInputStream(content), status)); // Allocate final SpectraBulkService bulk = new SpectraBulkService(session); bulk.pre(Transfer.Type.upload, Collections.singletonMap(test, status), new DisabledConnectionCallback()); { final OutputStream out = new SpectraWriteFeature(session).write(test, status, new DisabledConnectionCallback()); assertNotNull(out); new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out); out.close(); } assertEquals(content.length, new S3AttributesFinderFeature(session).find(test).getSize()); // Overwrite bulk.pre(Transfer.Type.upload, Collections.singletonMap(test, status.exists(true)), new DisabledConnectionCallback()); { final OutputStream out = new SpectraWriteFeature(session).write(test, status.exists(true), new DisabledConnectionCallback()); new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out); out.close(); } assertEquals(content.length, new S3AttributesFinderFeature(session).find(test).getSize()); new SpectraDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:com.nesscomputing.httpclient.testing.TestingHttpClientBuilderTest.java
License:asdf
@Test public void testJsonResponse() throws Exception { ObjectMapper mapper = new ObjectMapper(); TestingHttpClientBuilder builder = new TestingHttpClientBuilder().withObjectMapper(mapper); Map<String, String> superImportantMap = Collections.singletonMap("foo", "bar"); builder.on(GET).of("/json").respondWith(Response.ok(superImportantMap)); HttpClient httpClient = builder.build(); HttpClientResponse response = httpClient.get("/json", handler).perform(); assertEquals(Status.OK.getStatusCode(), response.getStatusCode()); assertEquals(MediaType.APPLICATION_JSON, response.getContentType()); Map<String, String> result = mapper.readValue(response.getResponseBodyAsStream(), new TypeReference<Map<String, String>>() { });/*from w w w .ja v a 2 s. c o m*/ assertEquals(superImportantMap, result); }
From source file:org.jasig.services.persondir.support.ldap.LdapPersonAttributeDaoTest.java
/** * Test for a query with a single attribute. *//*from w w w . ja va 2 s. c o m*/ public void testSingleAttrQuery() throws Exception { LdapPersonAttributeDao impl = new LdapPersonAttributeDao(); Map<String, Object> ldapAttribsToPortalAttribs = new HashMap<String, Object>(); ldapAttribsToPortalAttribs.put("mail", "email"); impl.setResultAttributeMapping(ldapAttribsToPortalAttribs); impl.setContextSource(this.getContextSource()); impl.setQueryAttributeMapping(Collections.singletonMap("uid", "uid")); impl.afterPropertiesSet(); Map<String, List<Object>> queryMap = new HashMap<String, List<Object>>(); queryMap.put("uid", Util.list("edalquist")); try { Map<String, List<Object>> attribs = impl.getMultivaluedUserAttributes(queryMap); assertEquals(Util.list("eric.dalquist@example.com"), attribs.get("email")); } catch (DataAccessResourceFailureException darfe) { //OK, No net connection } }
From source file:com.hp.alm.ali.idea.services.AttachmentService.java
public boolean updateAttachmentContent(String name, EntityRef parent, IndicatingInputStream is, long length, boolean silent) { Map<String, String> headers = Collections.singletonMap("Content-Type", "application/octet-stream"); MyResultInfo result = new MyResultInfo(); if (restService.put(new MyInputData(is, length, headers), result, "{0}s/{1}/attachments/{2}", parent.type, parent.id, EntityQuery.encode(name)) != HttpStatus.SC_OK) { if (!silent) { errorService.showException(new RestException(result)); }/* w w w .jav a 2 s . c o m*/ return false; } else { EntityList list = EntityList.create(result.getBodyAsStream(), true); if (!list.isEmpty()) { entityService.fireEntityLoaded(list.get(0), EntityListener.Event.GET); } return true; } }
From source file:com.epam.reportportal.auth.integration.github.GitHubTokenServices.java
@Override public OAuth2Authentication loadAuthentication(String accessToken) throws AuthenticationException, InvalidTokenException { GitHubClient gitHubClient = GitHubClient.withAccessToken(accessToken); UserResource gitHubUser = gitHubClient.getUser(); List<String> allowedOrganizations = ofNullable(loginDetails.get().getRestrictions()) .flatMap(restrictions -> ofNullable(restrictions.get("organizations"))) .map(it -> Splitter.on(",").omitEmptyStrings().splitToList(it)).orElse(emptyList()); if (!allowedOrganizations.isEmpty()) { boolean assignedToOrganization = gitHubClient.getUserOrganizations(gitHubUser).stream() .map(userOrg -> userOrg.login).anyMatch(allowedOrganizations::contains); if (!assignedToOrganization) { throw new InsufficientOrganizationException( "User '" + gitHubUser.login + "' does not belong to allowed GitHUB organization"); }/*from w ww. j a v a 2s.c o m*/ } User user = replicator.replicateUser(gitHubUser, gitHubClient); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(user.getId(), "N/A", AuthUtils.AS_AUTHORITIES.apply(user.getRole())); Map<String, Serializable> extensionProperties = Collections.singletonMap("upstream_token", accessToken); OAuth2Request request = new OAuth2Request(null, loginDetails.get().getClientId(), null, true, null, null, null, null, extensionProperties); return new OAuth2Authentication(request, token); }
From source file:org.cloudfoundry.identity.uaa.config.YamlPropertiesFactoryBeanTests.java
@Test public void testLoadResourceWithSelectedDocuments() throws Exception { YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean(); factory.setResources(new Resource[] { new ByteArrayResource("foo: bar\nspam: baz\n---\nfoo: bag\nspam: bad".getBytes()) }); factory.setDocumentMatchers(Collections.singletonMap("foo", "bag")); Properties properties = factory.getObject(); assertEquals("bag", properties.get("foo")); assertEquals("bad", properties.get("spam")); }
From source file:de.codecentric.boot.admin.services.ApplicationRegistratorTest.java
@SuppressWarnings("rawtypes") @Test/*from w w w . j ava2 s .c o m*/ public void register_retry() { when(restTemplate.postForEntity(isA(String.class), isA(HttpEntity.class), eq(Application.class))) .thenThrow(new RestClientException("Error")); 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()); }
From source file:com.btoddb.chronicle.ChronicleIT.java
@Test public void testPutEventList() throws Exception { int numEvents = 5; List<Event> eventList = new ArrayList<>(numEvents); for (int i = 0; i < numEvents; i++) { eventList.add(new Event(Collections.singletonMap("msgId", String.valueOf(i)), String.valueOf(i), true)); }/*from ww w .j ava 2 s .c om*/ Client client = ClientBuilder.newClient(); Response resp = client.target("http://localhost:8083/v1/events").request() .post(Entity.entity(eventList, MediaType.APPLICATION_JSON_TYPE)); assertThat(resp.getStatus(), is(200)); Map<String, Integer> respObj = resp.readEntity(Map.class); assertThat(respObj.get("received"), is(numEvents)); List<Event> plunkEventList = retrieveChronicleEvents(numEvents); assertThat(plunkEventList, hasSize(numEvents)); for (Event evt : plunkEventList) { assertThat(Long.parseLong(evt.getHeaders().get("timestamp")), is(greaterThanOrEqualTo(now))); evt.getHeaders().remove("timestamp"); } assertThat(plunkEventList, containsInAnyOrder(eventList.toArray())); }