Skip to content

Commit b4cd0c9

Browse files
Merge pull request #511 from algolia/fix-deleteobject-objectid
Fix: objectID is required to deleteObject
2 parents f616cf3 + a684746 commit b4cd0c9

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

algoliasearch-common/src/main/java/com/algolia/search/APIClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,11 @@ <T> TaskSingleIndex saveObjects(String indexName, List<T> objects, RequestOption
810810

811811
Task deleteObject(String indexName, String objectID, RequestOptions requestOptions)
812812
throws AlgoliaException {
813+
814+
if (objectID.trim().length() == 0) {
815+
throw new IllegalArgumentException("ObjectID must not be empty");
816+
}
817+
813818
Task result =
814819
httpClient.requestWithRetry(
815820
new AlgoliaRequest<>(

algoliasearch-common/src/main/java/com/algolia/search/AsyncAPIClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,11 @@ <T> CompletableFuture<AsyncTaskSingleIndex> saveObjects(
793793

794794
CompletableFuture<AsyncTask> deleteObject(
795795
String indexName, String objectID, RequestOptions requestOptions) {
796+
797+
if (objectID.trim().length() == 0) {
798+
throw new IllegalArgumentException("ObjectID must not be empty");
799+
}
800+
796801
return httpClient
797802
.requestWithRetry(
798803
new AlgoliaRequest<>(

algoliasearch-tests/src/test/java/com/algolia/search/integration/common/async/AsyncObjectsTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,22 @@ public void getObjectsWithAttributesToRetrieve() throws Exception {
132132
futureAssertThat(result).hasSize(1);
133133
futureAssertThat(result).extracting("name").containsNull();
134134
}
135+
136+
@Test(expected = IllegalArgumentException.class)
137+
public void deleteObjectEmptyObjectIdShouldFail() throws IllegalArgumentException {
138+
AsyncIndex<AlgoliaObject> index = createIndex(AlgoliaObject.class);
139+
index.deleteObject("");
140+
}
141+
142+
@Test(expected = IllegalArgumentException.class)
143+
public void deleteObjectWhiteSpaceObjectIdShouldFail() throws IllegalArgumentException {
144+
AsyncIndex<AlgoliaObject> index = createIndex(AlgoliaObject.class);
145+
index.deleteObject(" ");
146+
}
147+
148+
@Test(expected = NullPointerException.class)
149+
public void deleteObjectNullObjectIdShouldFail() throws NullPointerException {
150+
AsyncIndex<AlgoliaObject> index = createIndex(AlgoliaObject.class);
151+
index.deleteObject(null);
152+
}
135153
}

algoliasearch-tests/src/test/java/com/algolia/search/integration/common/sync/SyncObjectsTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,24 @@ public void getObjectsWithAttributesToRetrieve() throws AlgoliaException {
130130
assertThat(objects.get(0))
131131
.isEqualToComparingFieldByField(new AlgoliaObjectWithID("1", null, 5));
132132
}
133+
134+
@Test(expected = IllegalArgumentException.class)
135+
public void deleteObjectEmptyObjectIdShouldFail()
136+
throws AlgoliaException, IllegalArgumentException {
137+
Index<AlgoliaObject> index = createIndex(AlgoliaObject.class);
138+
index.deleteObject("");
139+
}
140+
141+
@Test(expected = IllegalArgumentException.class)
142+
public void deleteObjectWhiteSpaceObjectIdShouldFail()
143+
throws AlgoliaException, IllegalArgumentException {
144+
Index<AlgoliaObject> index = createIndex(AlgoliaObject.class);
145+
index.deleteObject(" ");
146+
}
147+
148+
@Test(expected = NullPointerException.class)
149+
public void deleteObjectNullObjectIdShouldFail() throws AlgoliaException, NullPointerException {
150+
Index<AlgoliaObject> index = createIndex(AlgoliaObject.class);
151+
index.deleteObject(null);
152+
}
133153
}

0 commit comments

Comments
 (0)