List of usage examples for java.util StringJoiner toString
@Override
public String toString()
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testSyncedFlush() { String[] indices = randomBoolean() ? null : randomIndicesNames(0, 5); SyncedFlushRequest syncedFlushRequest; if (randomBoolean()) { syncedFlushRequest = new SyncedFlushRequest(indices); } else {//from w ww . j av a 2 s . c om syncedFlushRequest = new SyncedFlushRequest(); syncedFlushRequest.indices(indices); } Map<String, String> expectedParams = new HashMap<>(); setRandomIndicesOptions(syncedFlushRequest::indicesOptions, syncedFlushRequest::indicesOptions, expectedParams); Request request = RequestConverters.flushSynced(syncedFlushRequest); StringJoiner endpoint = new StringJoiner("/", "/", ""); if (indices != null && indices.length > 0) { endpoint.add(String.join(",", indices)); } endpoint.add("_flush/synced"); assertThat(request.getEndpoint(), equalTo(endpoint.toString())); assertThat(request.getParameters(), equalTo(expectedParams)); assertThat(request.getEntity(), nullValue()); assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME)); }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testFlush() { String[] indices = randomBoolean() ? null : randomIndicesNames(0, 5); FlushRequest flushRequest;/*from www . j a va 2 s . c om*/ if (randomBoolean()) { flushRequest = new FlushRequest(indices); } else { flushRequest = new FlushRequest(); flushRequest.indices(indices); } Map<String, String> expectedParams = new HashMap<>(); setRandomIndicesOptions(flushRequest::indicesOptions, flushRequest::indicesOptions, expectedParams); if (randomBoolean()) { flushRequest.force(randomBoolean()); } expectedParams.put("force", Boolean.toString(flushRequest.force())); if (randomBoolean()) { flushRequest.waitIfOngoing(randomBoolean()); } expectedParams.put("wait_if_ongoing", Boolean.toString(flushRequest.waitIfOngoing())); Request request = RequestConverters.flush(flushRequest); StringJoiner endpoint = new StringJoiner("/", "/", ""); if (indices != null && indices.length > 0) { endpoint.add(String.join(",", indices)); } endpoint.add("_flush"); assertThat(request.getEndpoint(), equalTo(endpoint.toString())); assertThat(request.getParameters(), equalTo(expectedParams)); assertThat(request.getEntity(), nullValue()); assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME)); }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testForceMerge() { String[] indices = randomBoolean() ? null : randomIndicesNames(0, 5); ForceMergeRequest forceMergeRequest; if (randomBoolean()) { forceMergeRequest = new ForceMergeRequest(indices); } else {//from w w w.j a v a 2 s . com forceMergeRequest = new ForceMergeRequest(); forceMergeRequest.indices(indices); } Map<String, String> expectedParams = new HashMap<>(); setRandomIndicesOptions(forceMergeRequest::indicesOptions, forceMergeRequest::indicesOptions, expectedParams); if (randomBoolean()) { forceMergeRequest.maxNumSegments(randomInt()); } expectedParams.put("max_num_segments", Integer.toString(forceMergeRequest.maxNumSegments())); if (randomBoolean()) { forceMergeRequest.onlyExpungeDeletes(randomBoolean()); } expectedParams.put("only_expunge_deletes", Boolean.toString(forceMergeRequest.onlyExpungeDeletes())); if (randomBoolean()) { forceMergeRequest.flush(randomBoolean()); } expectedParams.put("flush", Boolean.toString(forceMergeRequest.flush())); Request request = RequestConverters.forceMerge(forceMergeRequest); StringJoiner endpoint = new StringJoiner("/", "/", ""); if (indices != null && indices.length > 0) { endpoint.add(String.join(",", indices)); } endpoint.add("_forcemerge"); assertThat(request.getEndpoint(), equalTo(endpoint.toString())); assertThat(request.getParameters(), equalTo(expectedParams)); assertThat(request.getEntity(), nullValue()); assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME)); }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testPutMapping() throws IOException { PutMappingRequest putMappingRequest = new PutMappingRequest(); String[] indices = randomIndicesNames(0, 5); putMappingRequest.indices(indices);//from w ww . j av a2 s . c om String type = randomAlphaOfLengthBetween(3, 10); putMappingRequest.type(type); Map<String, String> expectedParams = new HashMap<>(); setRandomTimeout(putMappingRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams); setRandomMasterTimeout(putMappingRequest, expectedParams); Request request = RequestConverters.putMapping(putMappingRequest); StringJoiner endpoint = new StringJoiner("/", "/", ""); String index = String.join(",", indices); if (Strings.hasLength(index)) { endpoint.add(index); } endpoint.add("_mapping"); endpoint.add(type); assertEquals(endpoint.toString(), request.getEndpoint()); assertEquals(expectedParams, request.getParameters()); assertEquals(HttpPut.METHOD_NAME, request.getMethod()); assertToXContentBody(putMappingRequest, request.getEntity()); }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testClearCache() { String[] indices = randomBoolean() ? null : randomIndicesNames(0, 5); ClearIndicesCacheRequest clearIndicesCacheRequest; if (randomBoolean()) { clearIndicesCacheRequest = new ClearIndicesCacheRequest(indices); } else {//from w ww . java2 s . c o m clearIndicesCacheRequest = new ClearIndicesCacheRequest(); clearIndicesCacheRequest.indices(indices); } Map<String, String> expectedParams = new HashMap<>(); setRandomIndicesOptions(clearIndicesCacheRequest::indicesOptions, clearIndicesCacheRequest::indicesOptions, expectedParams); if (randomBoolean()) { clearIndicesCacheRequest.queryCache(randomBoolean()); } expectedParams.put("query", Boolean.toString(clearIndicesCacheRequest.queryCache())); if (randomBoolean()) { clearIndicesCacheRequest.fieldDataCache(randomBoolean()); } expectedParams.put("fielddata", Boolean.toString(clearIndicesCacheRequest.fieldDataCache())); if (randomBoolean()) { clearIndicesCacheRequest.requestCache(randomBoolean()); } expectedParams.put("request", Boolean.toString(clearIndicesCacheRequest.requestCache())); if (randomBoolean()) { clearIndicesCacheRequest.fields(randomIndicesNames(1, 5)); expectedParams.put("fields", String.join(",", clearIndicesCacheRequest.fields())); } Request request = RequestConverters.clearCache(clearIndicesCacheRequest); StringJoiner endpoint = new StringJoiner("/", "/", ""); if (indices != null && indices.length > 0) { endpoint.add(String.join(",", indices)); } endpoint.add("_cache/clear"); assertThat(request.getEndpoint(), equalTo(endpoint.toString())); assertThat(request.getParameters(), equalTo(expectedParams)); assertThat(request.getEntity(), nullValue()); assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME)); }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testFieldCaps() { // Create a random request. String[] indices = randomIndicesNames(0, 5); String[] fields = generateRandomStringArray(5, 10, false, false); FieldCapabilitiesRequest fieldCapabilitiesRequest = new FieldCapabilitiesRequest().indices(indices) .fields(fields);// ww w . j a v a 2 s .c om Map<String, String> indicesOptionsParams = new HashMap<>(); setRandomIndicesOptions(fieldCapabilitiesRequest::indicesOptions, fieldCapabilitiesRequest::indicesOptions, indicesOptionsParams); Request request = RequestConverters.fieldCaps(fieldCapabilitiesRequest); // Verify that the resulting REST request looks as expected. StringJoiner endpoint = new StringJoiner("/", "/", ""); String joinedIndices = String.join(",", indices); if (!joinedIndices.isEmpty()) { endpoint.add(joinedIndices); } endpoint.add("_field_caps"); assertEquals(endpoint.toString(), request.getEndpoint()); assertEquals(4, request.getParameters().size()); // Note that we don't check the field param value explicitly, as field names are // passed through // a hash set before being added to the request, and can appear in a // non-deterministic order. assertThat(request.getParameters(), hasKey("fields")); String[] requestFields = Strings.splitStringByCommaToArray(request.getParameters().get("fields")); assertEquals(new HashSet<>(Arrays.asList(fields)), new HashSet<>(Arrays.asList(requestFields))); for (Map.Entry<String, String> param : indicesOptionsParams.entrySet()) { assertThat(request.getParameters(), hasEntry(param.getKey(), param.getValue())); } assertNull(request.getEntity()); }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testSearchTemplate() throws Exception { // Create a random request. String[] indices = randomIndicesNames(0, 5); SearchRequest searchRequest = new SearchRequest(indices); Map<String, String> expectedParams = new HashMap<>(); setRandomSearchParams(searchRequest, expectedParams); setRandomIndicesOptions(searchRequest::indicesOptions, searchRequest::indicesOptions, expectedParams); SearchTemplateRequest searchTemplateRequest = new SearchTemplateRequest(searchRequest); searchTemplateRequest.setScript("{\"query\": { \"match\" : { \"{{field}}\" : \"{{value}}\" }}}"); searchTemplateRequest.setScriptType(ScriptType.INLINE); searchTemplateRequest.setProfile(randomBoolean()); Map<String, Object> scriptParams = new HashMap<>(); scriptParams.put("field", "name"); scriptParams.put("value", "soren"); searchTemplateRequest.setScriptParams(scriptParams); // Verify that the resulting REST request looks as expected. Request request = RequestConverters.searchTemplate(searchTemplateRequest); StringJoiner endpoint = new StringJoiner("/", "/", ""); String index = String.join(",", indices); if (Strings.hasLength(index)) { endpoint.add(index);//from w w w. ja v a2s . c om } endpoint.add("_search/template"); assertEquals(HttpGet.METHOD_NAME, request.getMethod()); assertEquals(endpoint.toString(), request.getEndpoint()); assertEquals(expectedParams, request.getParameters()); assertToXContentBody(searchTemplateRequest, request.getEntity()); }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testGetMapping() throws IOException { GetMappingsRequest getMappingRequest = new GetMappingsRequest(); String[] indices = Strings.EMPTY_ARRAY; if (randomBoolean()) { indices = randomIndicesNames(0, 5); getMappingRequest.indices(indices); } else if (randomBoolean()) { getMappingRequest.indices((String[]) null); }//from w w w. j a va 2 s .co m String type = null; if (randomBoolean()) { type = randomAlphaOfLengthBetween(3, 10); getMappingRequest.types(type); } else if (randomBoolean()) { getMappingRequest.types((String[]) null); } Map<String, String> expectedParams = new HashMap<>(); setRandomIndicesOptions(getMappingRequest::indicesOptions, getMappingRequest::indicesOptions, expectedParams); setRandomMasterTimeout(getMappingRequest, expectedParams); setRandomLocal(getMappingRequest, expectedParams); Request request = RequestConverters.getMappings(getMappingRequest); StringJoiner endpoint = new StringJoiner("/", "/", ""); String index = String.join(",", indices); if (Strings.hasLength(index)) { endpoint.add(index); } endpoint.add("_mapping"); if (type != null) { endpoint.add(type); } assertThat(endpoint.toString(), equalTo(request.getEndpoint())); assertThat(expectedParams, equalTo(request.getParameters())); assertThat(HttpGet.METHOD_NAME, equalTo(request.getMethod())); }
From source file:com.cotrino.langnet.GenerateVisualization.java
/** * based on http://bl.ocks.org/1377729/* w w w . j av a2 s . c om*/ * @param jsFile */ private void generateVisualization(String jsFile) { String content = ""; int i = 0; double max = 0.0, min = 100.0; StringJoiner sj = new StringJoiner(","); StringJoiner nodesHash = new StringJoiner(" "); StringJoiner linkList = new StringJoiner(","); HashMap<String, Integer> languageIds = new HashMap<String, Integer>(); for (String language : amountWordsPerLanguage.keySet()) { // language bubble color & size int red = (int) (Math.random() * 127.0); int green = (int) (Math.random() * 127.0); int blue = (int) (Math.random() * 127.0); int color = ((red + 128) << 16) | ((green + 128) << 8) | ((blue + 128)); int textcolor = ((red + 64) << 16) | ((green + 64) << 8) | ((blue + 64)); int size = amountWordsPerLanguage.get(language) / 2000; if (size < 5) { size = 5; } // language information String description = "Language: " + getWikiURL(language) + "<br/><br/>"; if (languageSimilarities.containsKey(language)) { List<LanguageSimilarity> similarLanguages = languageSimilarities.get(language); Collections.sort(similarLanguages); description += "Similar to:<ul>"; // look for most similar languages for (LanguageSimilarity languageB : similarLanguages) { description += "<li>" + getWikiURL(languageB.language) + " at " + String.format("%d", (int) (languageB.similarity * 100)) + "%</li>"; max = Math.max(max, languageB.similarity); min = Math.min(min, languageB.similarity); } description += "</ul>"; } else { description += "No similar languages found."; } sj.add("{ label : \"" + language + "\", " + "id : " + i + ", " + "color : \"#" + String.format("%6x", color) + "\", " + "textcolor : \"#" + String.format("%6x", textcolor) + "\", " + "size : " + size + ", desc : \"" + description + "\" }"); nodesHash.add("nodesHash[\"" + language + "\"] = " + i + ";"); languageIds.put(language, i); i++; } content += "var nodesArray = [\n" + sj.toString() + "\n];\n\n"; content += "var nodesHash = [];\n" + nodesHash.toString() + "\n\n"; for (String languageA : languageSimilarities.keySet()) { for (LanguageSimilarity languageB : languageSimilarities.get(languageA)) { int color = (int) (240 * (1.0 + MIN_SIMILARITY - languageB.similarity)); if (color > 240) { color = 240; } if (languageIds.containsKey(languageA) && languageIds.containsKey(languageB.language)) { linkList.add("{ desc : \"" + languageA + " -- " + languageB.language + "\", " + "source : " + languageIds.get(languageA) + ", " + "target : " + languageIds.get(languageB.language) + ", " + "weight : " + languageB.similarity + ", " + "color : \"#" + String.format("%02x%02xff", color, color) + "\" }"); } } } content += "var linksArray = [\n" + linkList.toString() + "\n];\n"; IOUtil.write(jsFile, content); }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testExistsAlias() { GetAliasesRequest getAliasesRequest = new GetAliasesRequest(); String[] indices = randomBoolean() ? null : randomIndicesNames(0, 5); getAliasesRequest.indices(indices);/* w w w . j av a 2 s.com*/ // the HEAD endpoint requires at least an alias or an index boolean hasIndices = indices != null && indices.length > 0; String[] aliases; if (hasIndices) { aliases = randomBoolean() ? null : randomIndicesNames(0, 5); } else { aliases = randomIndicesNames(1, 5); } getAliasesRequest.aliases(aliases); Map<String, String> expectedParams = new HashMap<>(); setRandomLocal(getAliasesRequest, expectedParams); setRandomIndicesOptions(getAliasesRequest::indicesOptions, getAliasesRequest::indicesOptions, expectedParams); Request request = RequestConverters.existsAlias(getAliasesRequest); StringJoiner expectedEndpoint = new StringJoiner("/", "/", ""); if (indices != null && indices.length > 0) { expectedEndpoint.add(String.join(",", indices)); } expectedEndpoint.add("_alias"); if (aliases != null && aliases.length > 0) { expectedEndpoint.add(String.join(",", aliases)); } assertEquals(HttpHead.METHOD_NAME, request.getMethod()); assertEquals(expectedEndpoint.toString(), request.getEndpoint()); assertEquals(expectedParams, request.getParameters()); assertNull(request.getEntity()); }