List of usage examples for java.util StringJoiner add
public StringJoiner add(CharSequence newElement)
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testDeletePipeline() { String pipelineId = "some_pipeline_id"; Map<String, String> expectedParams = new HashMap<>(); DeletePipelineRequest request = new DeletePipelineRequest(pipelineId); setRandomMasterTimeout(request, expectedParams); setRandomTimeout(request::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams); Request expectedRequest = RequestConverters.deletePipeline(request); StringJoiner endpoint = new StringJoiner("/", "/", ""); endpoint.add("_ingest/pipeline"); endpoint.add(pipelineId);//from www . jav a 2s . c o m assertEquals(endpoint.toString(), expectedRequest.getEndpoint()); assertEquals(HttpDelete.METHOD_NAME, expectedRequest.getMethod()); assertEquals(expectedParams, expectedRequest.getParameters()); }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testPutPipeline() throws IOException { String pipelineId = "some_pipeline_id"; PutPipelineRequest request = new PutPipelineRequest("some_pipeline_id", new BytesArray("{}".getBytes(StandardCharsets.UTF_8)), XContentType.JSON); Map<String, String> expectedParams = new HashMap<>(); setRandomMasterTimeout(request, expectedParams); setRandomTimeout(request::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams); Request expectedRequest = RequestConverters.putPipeline(request); StringJoiner endpoint = new StringJoiner("/", "/", ""); endpoint.add("_ingest/pipeline"); endpoint.add(pipelineId);/*ww w . ja v a 2s .com*/ assertEquals(endpoint.toString(), expectedRequest.getEndpoint()); assertEquals(HttpPut.METHOD_NAME, expectedRequest.getMethod()); assertEquals(expectedParams, expectedRequest.getParameters()); }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testRefresh() { String[] indices = randomBoolean() ? null : randomIndicesNames(0, 5); RefreshRequest refreshRequest;//w w w. j a v a 2s. c o m if (randomBoolean()) { refreshRequest = new RefreshRequest(indices); } else { refreshRequest = new RefreshRequest(); refreshRequest.indices(indices); } Map<String, String> expectedParams = new HashMap<>(); setRandomIndicesOptions(refreshRequest::indicesOptions, refreshRequest::indicesOptions, expectedParams); Request request = RequestConverters.refresh(refreshRequest); StringJoiner endpoint = new StringJoiner("/", "/", ""); if (indices != null && indices.length > 0) { endpoint.add(String.join(",", indices)); } endpoint.add("_refresh"); 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 testSyncedFlush() { String[] indices = randomBoolean() ? null : randomIndicesNames(0, 5); SyncedFlushRequest syncedFlushRequest; if (randomBoolean()) { syncedFlushRequest = new SyncedFlushRequest(indices); } else {/* w w w.j av a2s . co m*/ 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 testIndexPutSettings() throws IOException { String[] indices = randomBoolean() ? null : randomIndicesNames(0, 2); UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest(indices); Map<String, String> expectedParams = new HashMap<>(); setRandomMasterTimeout(updateSettingsRequest, expectedParams); setRandomTimeout(updateSettingsRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams); setRandomIndicesOptions(updateSettingsRequest::indicesOptions, updateSettingsRequest::indicesOptions, expectedParams);// w w w . j a v a 2 s.co m if (randomBoolean()) { updateSettingsRequest.setPreserveExisting(randomBoolean()); if (updateSettingsRequest.isPreserveExisting()) { expectedParams.put("preserve_existing", "true"); } } Request request = RequestConverters.indexPutSettings(updateSettingsRequest); StringJoiner endpoint = new StringJoiner("/", "/", ""); if (indices != null && indices.length > 0) { endpoint.add(String.join(",", indices)); } endpoint.add("_settings"); assertThat(endpoint.toString(), equalTo(request.getEndpoint())); assertEquals(HttpPut.METHOD_NAME, request.getMethod()); assertToXContentBody(updateSettingsRequest, request.getEntity()); assertEquals(expectedParams, request.getParameters()); }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testFlush() { String[] indices = randomBoolean() ? null : randomIndicesNames(0, 5); FlushRequest flushRequest;/*from w w w. ja va 2s. co m*/ 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 {// w w w . ja v a 2 s. c o m 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 testClearCache() { String[] indices = randomBoolean() ? null : randomIndicesNames(0, 5); ClearIndicesCacheRequest clearIndicesCacheRequest; if (randomBoolean()) { clearIndicesCacheRequest = new ClearIndicesCacheRequest(indices); } else {// w w w .j av a 2 s .c om 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 testExistsAlias() { GetAliasesRequest getAliasesRequest = new GetAliasesRequest(); String[] indices = randomBoolean() ? null : randomIndicesNames(0, 5); getAliasesRequest.indices(indices);//from ww w . j a v a 2 s. c om // 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()); }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testRankEval() throws Exception { RankEvalSpec spec = new RankEvalSpec( Collections.singletonList( new RatedRequest("queryId", Collections.emptyList(), new SearchSourceBuilder())), new PrecisionAtK()); String[] indices = randomIndicesNames(0, 5); RankEvalRequest rankEvalRequest = new RankEvalRequest(spec, indices); Map<String, String> expectedParams = new HashMap<>(); setRandomIndicesOptions(rankEvalRequest::indicesOptions, rankEvalRequest::indicesOptions, expectedParams); Request request = RequestConverters.rankEval(rankEvalRequest); StringJoiner endpoint = new StringJoiner("/", "/", ""); String index = String.join(",", indices); if (Strings.hasLength(index)) { endpoint.add(index); }// w ww . ja v a2 s. c o m endpoint.add(RestRankEvalAction.ENDPOINT); assertEquals(endpoint.toString(), request.getEndpoint()); assertEquals(3, request.getParameters().size()); assertEquals(expectedParams, request.getParameters()); assertToXContentBody(spec, request.getEntity()); }