List of usage examples for java.util Collections emptyMap
@SuppressWarnings("unchecked") public static final <K, V> Map<K, V> emptyMap()
From source file:io.crate.operation.auth.HostBasedAuthenticationTest.java
@Test public void testMissingUserOrAddress() throws Exception { authService.updateHbaConfig(Collections.emptyMap()); AuthenticationMethod method;/*from w w w . j av a 2 s.c om*/ method = authService.resolveAuthenticationType(null, new ConnectionProperties(LOCALHOST, Protocol.POSTGRES, null)); assertNull(method); method = authService.resolveAuthenticationType("crate", new ConnectionProperties(null, Protocol.POSTGRES, null)); assertNull(method); }
From source file:org.elasticsearch.integration.BulkUpdateTests.java
public void testThatBulkUpdateDoesNotLoseFieldsHttp() throws IOException { final String path = "/index1/type/1"; final Header basicAuthHeader = new BasicHeader("Authorization", UsernamePasswordToken.basicAuthHeaderValue(SecuritySettingsSource.TEST_USER_NAME, new SecureString(SecuritySettingsSourceField.TEST_PASSWORD.toCharArray()))); StringEntity body = new StringEntity("{\"test\":\"test\"}", ContentType.APPLICATION_JSON); Response response = getRestClient().performRequest("PUT", path, Collections.emptyMap(), body, basicAuthHeader);//from www. java2 s. c om assertThat(response.getStatusLine().getStatusCode(), equalTo(201)); response = getRestClient().performRequest("GET", path, basicAuthHeader); assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); assertThat(EntityUtils.toString(response.getEntity()), containsString("\"test\":\"test\"")); if (randomBoolean()) { flushAndRefresh(); } //update with new field body = new StringEntity("{\"doc\": {\"not test\": \"not test\"}}", ContentType.APPLICATION_JSON); response = getRestClient().performRequest("POST", path + "/_update", Collections.emptyMap(), body, basicAuthHeader); assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); response = getRestClient().performRequest("GET", path, basicAuthHeader); assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); String responseBody = EntityUtils.toString(response.getEntity()); assertThat(responseBody, containsString("\"test\":\"test\"")); assertThat(responseBody, containsString("\"not test\":\"not test\"")); // this part is important. Without this, the document may be read from the translog which would bypass the bug where // FLS kicks in because the request can't be found and only returns meta fields flushAndRefresh(); body = new StringEntity("{\"update\": {\"_index\": \"index1\", \"_type\": \"type\", \"_id\": \"1\"}}\n" + "{\"doc\": {\"bulk updated\":\"bulk updated\"}}\n", ContentType.APPLICATION_JSON); response = getRestClient().performRequest("POST", "/_bulk", Collections.emptyMap(), body, basicAuthHeader); assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); response = getRestClient().performRequest("GET", path, basicAuthHeader); responseBody = EntityUtils.toString(response.getEntity()); assertThat(responseBody, containsString("\"test\":\"test\"")); assertThat(responseBody, containsString("\"not test\":\"not test\"")); assertThat(responseBody, containsString("\"bulk updated\":\"bulk updated\"")); }
From source file:fr.ritaly.dungeonmaster.ai.CreatureManager.java
/** * Returns the creatures occupying this position as a map. * * @return a map of creatures per sector. Never returns null. *//*w ww . j a v a 2 s . co m*/ public final Map<Sector, Creature> getCreatureMap() { if (creatures == null) { return Collections.emptyMap(); } // Defensive recopy return Collections.unmodifiableMap(creatures); }
From source file:com.hortonworks.streamline.streams.common.StreamlineEventImplTest.java
@Test(expected = UnsupportedOperationException.class) public void testPutAll() throws Exception { Map<String, Object> map = new HashMap<>(); map.put("foo", "bar"); StreamlineEvent event = new StreamlineEventImpl(Collections.emptyMap(), StringUtils.EMPTY); event.putAll(map);//from w ww.j a v a 2s. c o m }
From source file:org.elasticsearch.upgrades.TokenBackwardsCompatibilityIT.java
public void testMixedCluster() throws Exception { assumeTrue("this test should only run against the mixed cluster", clusterType == CLUSTER_TYPE.MIXED); assumeTrue("the master must be on the latest version before we can write", isMasterOnLatestVersion()); Response getResponse = client().performRequest("GET", "token_backwards_compatibility_it/doc/old_cluster_token2"); assertOK(getResponse);/*from w ww . j a va 2 s .c o m*/ Map<String, Object> source = (Map<String, Object>) entityAsMap(getResponse).get("_source"); final String token = (String) source.get("token"); assertTokenWorks(token); final StringEntity body = new StringEntity("{\"token\": \"" + token + "\"}", ContentType.APPLICATION_JSON); Response invalidationResponse = client().performRequest("DELETE", "_xpack/security/oauth2/token", Collections.emptyMap(), body); assertOK(invalidationResponse); assertTokenDoesNotWork(token); // create token and refresh on version that supports it final StringEntity tokenPostBody = new StringEntity("{\n" + " \"username\": \"test_user\",\n" + " \"password\": \"x-pack-test-password\",\n" + " \"grant_type\": \"password\"\n" + "}", ContentType.APPLICATION_JSON); try (RestClient client = getRestClientForCurrentVersionNodesOnly()) { Response response = client.performRequest("POST", "_xpack/security/oauth2/token", Collections.emptyMap(), tokenPostBody); assertOK(response); Map<String, Object> responseMap = entityAsMap(response); String accessToken = (String) responseMap.get("access_token"); String refreshToken = (String) responseMap.get("refresh_token"); assertNotNull(accessToken); assertNotNull(refreshToken); assertTokenWorks(accessToken); final StringEntity tokenRefresh = new StringEntity("{\n" + " \"refresh_token\": \"" + refreshToken + "\",\n" + " \"grant_type\": \"refresh_token\"\n" + "}", ContentType.APPLICATION_JSON); response = client.performRequest("POST", "_xpack/security/oauth2/token", Collections.emptyMap(), tokenRefresh); assertOK(response); responseMap = entityAsMap(response); String updatedAccessToken = (String) responseMap.get("access_token"); String updatedRefreshToken = (String) responseMap.get("refresh_token"); assertNotNull(updatedAccessToken); assertNotNull(updatedRefreshToken); assertTokenWorks(updatedAccessToken); assertTokenWorks(accessToken); assertNotEquals(accessToken, updatedAccessToken); assertNotEquals(refreshToken, updatedRefreshToken); } }
From source file:com.netflix.genie.common.internal.aws.s3.S3ClientFactory.java
/** * Constructor.// ww w . j av a 2 s.c o m * * @param awsCredentialsProvider The base AWS credentials provider to use for the generated S3 clients * @param regionProvider How this factory should determine the default {@link Regions} * @param environment The Spring application {@link Environment} */ public S3ClientFactory(final AWSCredentialsProvider awsCredentialsProvider, final AwsRegionProvider regionProvider, final Environment environment) { this.awsCredentialsProvider = awsCredentialsProvider; /* * Use the Spring property binder to dynamically map properties under a common root into a map of key to object. * * In this case we're trying to get bucketName -> BucketProperties * * So if there were properties like: * genie.aws.s3.buckets.someBucket1.roleARN = blah * genie.aws.s3.buckets.someBucket2.region = us-east-1 * genie.aws.s3.buckets.someBucket2.roleARN = blah * * The result of this should be two entries in the map "bucket1" and "bucket2" mapping to property binding * object instances of BucketProperties with the correct property set or null if option wasn't specified. */ this.bucketProperties = Binder.get(environment) .bind(BUCKET_PROPERTIES_ROOT_KEY, Bindable.mapOf(String.class, BucketProperties.class)) .orElse(Collections.emptyMap()); // Set the initial size to the number of special cases defined in properties + 1 for the default client // NOTE: Should we proactively create all necessary clients or be lazy about it? For now, lazy. final int initialCapacity = this.bucketProperties.size() + 1; this.clientCache = new ConcurrentHashMap<>(initialCapacity); this.transferManagerCache = new ConcurrentHashMap<>(initialCapacity); String tmpRegion; try { tmpRegion = regionProvider.getRegion(); } catch (final SdkClientException e) { tmpRegion = Regions.getCurrentRegion() != null ? Regions.getCurrentRegion().getName() : Regions.US_EAST_1.getName(); log.warn("Couldn't determine the AWS region from the provider ({}) supplied. Defaulting to {}", regionProvider.toString(), tmpRegion); } this.defaultRegion = Regions.fromName(tmpRegion); // Create a token service client to use if we ever need to assume a role // TODO: Perhaps this should be just set to null if the bucket properties are empty as we'll never need it? this.stsClient = AWSSecurityTokenServiceClientBuilder.standard().withRegion(this.defaultRegion) .withCredentials(this.awsCredentialsProvider).build(); this.bucketToClientKey = new ConcurrentHashMap<>(); }
From source file:org.thingsboard.server.dao.audit.sink.ElasticsearchAuditLogSink.java
@Override public void logAction(AuditLog auditLogEntry) { String jsonContent = createElasticJsonRecord(auditLogEntry); HttpEntity entity = new NStringEntity(jsonContent, ContentType.APPLICATION_JSON); restClient.performRequestAsync(HttpMethod.POST.name(), String.format("/%s/%s", getIndexName(auditLogEntry.getTenantId()), INDEX_TYPE), Collections.emptyMap(), entity, responseListener); }
From source file:ch.rasc.wampspring.testsupport.BaseWampTest.java
protected void authenticate(CompletableFutureWebSocketHandler result, WebSocketSession webSocketSession) throws IOException, InterruptedException, InvalidKeyException, NoSuchAlgorithmException, ExecutionException, TimeoutException { CallMessage authReqCallMessage = new CallMessage("1", "http://api.wamp.ws/procedure#authreq", "a", Collections.emptyMap()); webSocketSession.sendMessage(new TextMessage(authReqCallMessage.toJson(this.jsonFactory))); WampMessage response = result.getWampMessage(); assertThat(response).isInstanceOf(CallResultMessage.class); CallResultMessage resultMessage = (CallResultMessage) response; assertThat(resultMessage.getCallID()).isEqualTo("1"); assertThat(resultMessage.getResult()).isNotNull(); result.reset();//from www . j av a2 s . c o m String challengeBase64 = (String) resultMessage.getResult(); String signature = DefaultAuthenticationHandler.generateHMacSHA256("secretofa", challengeBase64); CallMessage authCallMessage = new CallMessage("2", "http://api.wamp.ws/procedure#auth", signature); webSocketSession.sendMessage(new TextMessage(authCallMessage.toJson(this.jsonFactory))); response = result.getWampMessage(); assertThat(response).isInstanceOf(CallResultMessage.class); resultMessage = (CallResultMessage) response; assertThat(resultMessage.getCallID()).isEqualTo("2"); assertThat(resultMessage.getResult()).isNull(); result.reset(); }
From source file:com.sunchenbin.store.feilong.core.lang.ArrayUtil.java
/** * Group ./*from w w w . j a v a 2 s. co m*/ * * @param <O> * the generic type * @param <T> * the generic type * @param objectArray * * @param propertyName * ???? * @return the map< t, list< o>> * @see com.sunchenbin.store.feilong.core.bean.PropertyUtil#getProperty(Object, String) * @see com.sunchenbin.store.feilong.core.util.CollectionsUtil#group(java.util.Collection, String) * @since 1.0.8 */ public static <O, T> Map<T, List<O>> group(O[] objectArray, String propertyName) { if (null == objectArray) { return Collections.emptyMap(); } if (Validator.isNullOrEmpty(propertyName)) { throw new NullPointerException("the propertyName is null or empty!"); } // ??? HashMap TreeMap Map<T, List<O>> map = new LinkedHashMap<T, List<O>>(objectArray.length); for (O o : objectArray) { T t = PropertyUtil.getProperty(o, propertyName); List<O> valueList = map.get(t); if (null == valueList) { valueList = new ArrayList<O>(); } valueList.add(o); map.put(t, valueList); } return map; }
From source file:com.domingosuarez.boot.autoconfigure.jade4j.Jade4JAutoConfigurationTests.java
@Test public void shouldRenderPrettyTemplateTemplate() throws Exception { EnvironmentTestUtils.addEnvironment(this.context, "spring.jade4j.prettyPrint:true"); this.context.register(Jade4JAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); JadeConfiguration engine = this.context.getBean(JadeConfiguration.class); JadeTemplate template = engine.getTemplate("demo.jade"); Map<String, Object> params = Collections.emptyMap(); String result = engine.renderTemplate(template, params); String expected = "<html>\n" + " <head>\n" + " <title>Jade</title>\n" + " </head>\n" + " <body>\n" + " <h1>Jade - Template engine</h1>\n" + " </body>\n" + "</html>"; assertEquals(expected, result);//from ww w.ja v a2 s . co m }