Skip to content

Commit

Permalink
Merge pull request #620 from FgForrest/317-create-test-including-larg…
Browse files Browse the repository at this point in the history
…e-constraint-query-to-test-translation-layer-for-gqlrest-apis

test(#317): add tests for testing large query in GQL and REST APIs
  • Loading branch information
lukashornych committed Jun 25, 2024
2 parents 5106472 + 87c2c19 commit c2dfd10
Show file tree
Hide file tree
Showing 5 changed files with 644 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@
import io.evitadb.exception.GenericEvitaInternalError;
import io.evitadb.externalApi.api.model.PropertyDescriptor;
import io.evitadb.test.Entities;
import org.apache.commons.io.IOUtils;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
Expand All @@ -60,6 +63,13 @@
*/
public interface ExternalApiFunctionTestsSupport {

default String readFromClasspath(String path) throws IOException {
return IOUtils.toString(
Objects.requireNonNull(ExternalApiFunctionTestsSupport.class.getClassLoader().getResourceAsStream(path)),
StandardCharsets.UTF_8
);
}

/**
* Returns value of "random" value in the dataset.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
*
* _ _ ____ ____
* _____ _(_) |_ __ _| _ \| __ )
* / _ \ \ / / | __/ _` | | | | _ \
* | __/\ V /| | || (_| | |_| | |_) |
* \___| \_/ |_|\__\__,_|____/|____/
*
* Copyright (c) 2024
*
* Licensed under the Business Source License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://github.com/FgForrest/evitaDB/blob/master/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.evitadb.externalApi.graphql.api.catalog.dataApi;

import io.evitadb.core.Evita;
import io.evitadb.test.annotation.UseDataSet;
import io.evitadb.test.tester.GraphQLTester;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static io.evitadb.externalApi.graphql.api.testSuite.TestDataGenerator.GRAPHQL_THOUSAND_PRODUCTS;
import static org.hamcrest.Matchers.nullValue;

/**
* Tests the widest possible range of constraints and variants of evitaDB query through GraphQL API. It tests if
* the query can be successfully parsed and converted into evitaDB API. It doesn't test if it returns correct data, that's
* what other tests are for.
*
* @author Lukáš Hornych, FG Forrest a.s. (c) 2024
*/
public class CatalogGraphQLQueryTranslationVerifyingFunctionTest extends CatalogGraphQLDataEndpointFunctionalTest {

@Test
@UseDataSet(GRAPHQL_THOUSAND_PRODUCTS)
@DisplayName("Should accept and process large query")
void shouldAcceptAndProcessLargeQuery(Evita evita) throws IOException {
new GraphQLTester("https://demo.evitadb.io:5555/gql").test("evita")
.document(readFromClasspath("testData/CatalogGraphQLQueryTranslationVerifyingFunctionTest_query.graphql"))
.executeAndExpectOkAndThen()
.body(ERRORS_PATH, nullValue());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
*
* _ _ ____ ____
* _____ _(_) |_ __ _| _ \| __ )
* / _ \ \ / / | __/ _` | | | | _ \
* | __/\ V /| | || (_| | |_| | |_) |
* \___| \_/ |_|\__\__,_|____/|____/
*
* Copyright (c) 2023-2024
*
* Licensed under the Business Source License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://github.com/FgForrest/evitaDB/blob/master/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.evitadb.externalApi.rest.api.catalog.dataApi;

import io.evitadb.core.Evita;
import io.evitadb.test.annotation.UseDataSet;
import io.evitadb.test.tester.RestTester;
import io.evitadb.test.tester.RestTester.Request;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static io.evitadb.externalApi.rest.api.testSuite.TestDataGenerator.REST_THOUSAND_PRODUCTS;

/**
* Tests the widest possible range of constraints and variants of evitaDB query through REST API. It tests if
* the query can be successfully parsed and converted into evitaDB API. It doesn't test if it returns correct data, that's
* what other tests are for.
*
* @author Lukáš Hornych, FG Forrest a.s. (c) 2024
*/
class CatalogRestQueryTranslationVerifyingFunctionalTest extends CatalogRestDataEndpointFunctionalTest {

@Test
@UseDataSet(REST_THOUSAND_PRODUCTS)
@DisplayName("Should accept and process large query")
void shouldAcceptAndProcessLargeQuery(Evita evita) throws IOException {
new RestTester("https://demo.evitadb.io:5555/rest").test("evita")
.urlPathSuffix("/Product/query")
.httpMethod(Request.METHOD_POST)
.requestBody(readFromClasspath("testData/CatalogRestQueryTranslationVerifyingFunctionalTest_query.json"))
.executeAndExpectOkAndThen();
}
}
Loading

0 comments on commit c2dfd10

Please sign in to comment.