Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Delete*IntegrationTests to compact code #1295

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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