Skip to content

Commit 6dc0cdd

Browse files
committed
Add integration tests.
Signed-off-by: Youssef Aouichaoui <youssef3wi@icloud.com>
1 parent 4d47d6f commit 6dc0cdd

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchIntegrationTests.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3776,6 +3776,44 @@ void shouldThrowVersionConflictExceptionWhenSavingInvalidVersion() {
37763776
}).isInstanceOf(VersionConflictException.class);
37773777
}
37783778

3779+
@Test // GH-2865
3780+
public void shouldDeleteDocumentForGivenQueryUsingParameters() {
3781+
// Given
3782+
String documentId = nextIdAsString();
3783+
SampleEntity sampleEntity = SampleEntity.builder().id(documentId).message("some message")
3784+
.version(System.currentTimeMillis()).build();
3785+
3786+
IndexQuery indexQuery = getIndexQuery(sampleEntity);
3787+
String indexName = indexNameProvider.indexName();
3788+
3789+
operations.index(indexQuery, IndexCoordinates.of(indexName));
3790+
3791+
// When
3792+
final Query query = getTermQuery("id", documentId);
3793+
final DeleteQuery deleteQuery = DeleteQuery.builder(query).withSlices(2).build();
3794+
ByQueryResponse result = operations.delete(deleteQuery, SampleEntity.class, IndexCoordinates.of(indexName));
3795+
3796+
// Then
3797+
assertThat(result.getDeleted()).isEqualTo(1);
3798+
SearchHits<SampleEntity> searchHits = operations.search(query, SampleEntity.class,
3799+
IndexCoordinates.of(indexName));
3800+
assertThat(searchHits.getTotalHits()).isEqualTo(0);
3801+
}
3802+
3803+
@Test
3804+
public void shouldDeleteDocumentForGivenQueryAndUnavailableIndex() {
3805+
// Given
3806+
String indexName = UUID.randomUUID().toString();
3807+
3808+
// When
3809+
final Query query = operations.matchAllQuery();
3810+
final DeleteQuery deleteQuery = DeleteQuery.builder(query).withIgnoreUnavailable(true).build();
3811+
ByQueryResponse result = operations.delete(deleteQuery, SampleEntity.class, IndexCoordinates.of(indexName));
3812+
3813+
// Then
3814+
assertThat(result.getDeleted()).isEqualTo(0);
3815+
}
3816+
37793817
// region entities
37803818
@Document(indexName = "#{@indexNameProvider.indexName()}")
37813819
@Setting(shards = 1, replicas = 0, refreshInterval = "-1")

0 commit comments

Comments
 (0)