Skip to content

Commit

Permalink
Convert Delete*IntegrationTests to compact code (#1295)
Browse files Browse the repository at this point in the history
  • Loading branch information
tatu-at-datastax authored Jul 23, 2024
1 parent 7e29681 commit 06c6be7
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 527 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,7 @@ protected void insertManyDocs(String docsJson, int docsAmount) {

/** Utility method for reducing boilerplate code for sending JSON commands */
protected ValidatableResponse givenHeadersPostJsonThen(String json) {
return given()
.headers(getHeaders())
.contentType(ContentType.JSON)
.body(json)
return givenHeadersAndJson(json)
.when()
.post(CollectionResource.BASE_PATH, namespaceName, collectionName)
.then();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.specification.RequestSpecification;
import io.stargate.sgv2.jsonapi.config.constants.HttpConstants;
import io.stargate.sgv2.jsonapi.service.embedding.operation.test.CustomITEmbeddingProvider;
import java.util.Base64;
Expand Down Expand Up @@ -209,4 +210,9 @@ public static void checkIndexUsageMetrics(String commandName, boolean vector) {
.toList();
assertThat(countMetrics.size()).isGreaterThan(0);
}

/** Utility method for reducing boilerplate code for sending JSON commands */
protected RequestSpecification givenHeadersAndJson(String json) {
return given().headers(getHeaders()).contentType(ContentType.JSON).body(json);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package io.stargate.sgv2.jsonapi.api.v1;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.is;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.restassured.http.ContentType;
import io.stargate.sgv2.jsonapi.testresource.DseTestResource;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.ClassOrderer;
Expand All @@ -28,41 +26,31 @@ public void happyPath() {
String collection = RandomStringUtils.randomAlphabetic(16);

// first create
String createJson =
givenHeadersAndJson(
"""
{
"createCollection": {
"name": "%s"
}
}
"""
{
"createCollection": {
"name": "%s"
}
}
"""
.formatted(collection);

given()
.headers(getHeaders())
.contentType(ContentType.JSON)
.body(createJson)
.formatted(collection))
.when()
.post(NamespaceResource.BASE_PATH, namespaceName)
.then()
.statusCode(200)
.body("status.ok", is(1));

// then delete
String json =
givenHeadersAndJson(
"""
{
"deleteCollection": {
"name": "%s"
}
}
"""
{
"deleteCollection": {
"name": "%s"
}
}
"""
.formatted(collection);

given()
.headers(getHeaders())
.contentType(ContentType.JSON)
.body(json)
.formatted(collection))
.when()
.post(NamespaceResource.BASE_PATH, namespaceName)
.then()
Expand All @@ -75,20 +63,15 @@ public void notExisting() {
String collection = RandomStringUtils.randomAlphabetic(16);

// delete not existing
String json =
givenHeadersAndJson(
"""
{
"deleteCollection": {
"name": "%s"
}
}
"""
{
"deleteCollection": {
"name": "%s"
}
}
"""
.formatted(collection);

given()
.headers(getHeaders())
.contentType(ContentType.JSON)
.body(json)
.formatted(collection))
.when()
.post(NamespaceResource.BASE_PATH, namespaceName)
.then()
Expand All @@ -98,18 +81,13 @@ public void notExisting() {

@Test
public void invalidCommand() {
String json =
"""
{
"deleteCollection": {
}
}
""";

given()
.headers(getHeaders())
.contentType(ContentType.JSON)
.body(json)
givenHeadersAndJson(
"""
{
"deleteCollection": {
}
}
""")
.when()
.post(NamespaceResource.BASE_PATH, namespaceName)
.then()
Expand Down
Loading

0 comments on commit 06c6be7

Please sign in to comment.