From 97579394289f1ac4010fcf031b63066f48588352 Mon Sep 17 00:00:00 2001 From: Armin Date: Wed, 26 Jul 2023 18:50:31 +0200 Subject: [PATCH] [RFR-267] Remove api-test-environment (#12) --- README.adoc | 11 +- .../de/cyface/apitestutils/ApiServer.java | 178 ------------------ .../cyface/apitestutils/TestEnvironment.java | 172 ----------------- .../apitestutils/TestMongoDatabase.java | 100 ---------- .../cyface/apitestutils/TestParameters.java | 123 ------------ .../fixture/DatabaseConstants.java | 114 ----------- .../fixture/GeoLocationTestFixture.java | 95 ---------- .../apitestutils/fixture/MongoTestData.java | 41 ---- .../apitestutils/fixture/TestFixture.java | 43 ----- .../fixture/TestMeasurementDocument.java | 157 --------------- .../apitestutils/fixture/package-info.java | 27 --- api/build.gradle | 1 - settings.gradle | 3 +- 13 files changed, 2 insertions(+), 1063 deletions(-) delete mode 100644 api-test-environment/src/main/java/de/cyface/apitestutils/ApiServer.java delete mode 100644 api-test-environment/src/main/java/de/cyface/apitestutils/TestEnvironment.java delete mode 100644 api-test-environment/src/main/java/de/cyface/apitestutils/TestMongoDatabase.java delete mode 100644 api-test-environment/src/main/java/de/cyface/apitestutils/TestParameters.java delete mode 100644 api-test-environment/src/main/java/de/cyface/apitestutils/fixture/DatabaseConstants.java delete mode 100644 api-test-environment/src/main/java/de/cyface/apitestutils/fixture/GeoLocationTestFixture.java delete mode 100644 api-test-environment/src/main/java/de/cyface/apitestutils/fixture/MongoTestData.java delete mode 100644 api-test-environment/src/main/java/de/cyface/apitestutils/fixture/TestFixture.java delete mode 100644 api-test-environment/src/main/java/de/cyface/apitestutils/fixture/TestMeasurementDocument.java delete mode 100644 api-test-environment/src/main/java/de/cyface/apitestutils/fixture/package-info.java diff --git a/README.adoc b/README.adoc index f0db204..aca0034 100644 --- a/README.adoc +++ b/README.adoc @@ -19,9 +19,7 @@ The following sections provide an overview about those projects. == Overview -.link:#_libraries[Libraries] * link:#_api[API] -* link:#_api-test-environment[API Test Environment] .General information * link:#_release_a_new_version[Release a new Version] @@ -29,18 +27,11 @@ The following sections provide an overview about those projects. * link:#_licensing[Licensing] -== Libraries - [#_api] -=== API +== API Vert.X classes shared between multiple Cyface Vert.X API projects. -[#_api-test-environment] -=== API Test Environment - -Vert.X test classes shared between multiple Cyface Vert.X API projects. - [#_release_a_new_version] == Release a new Version diff --git a/api-test-environment/src/main/java/de/cyface/apitestutils/ApiServer.java b/api-test-environment/src/main/java/de/cyface/apitestutils/ApiServer.java deleted file mode 100644 index 24d7f5c..0000000 --- a/api-test-environment/src/main/java/de/cyface/apitestutils/ApiServer.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright 2019-2023 Cyface GmbH - * - * This file is part of the Cyface API Library. - * - * The Cyface API Library is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Cyface API Library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the Cyface API Library. If not, see . - */ -package de.cyface.apitestutils; - -import java.io.IOException; -import java.net.ServerSocket; - -import io.vertx.core.AsyncResult; -import io.vertx.core.DeploymentOptions; -import io.vertx.core.Future; -import io.vertx.core.Handler; -import io.vertx.core.MultiMap; -import io.vertx.core.Vertx; -import io.vertx.core.buffer.Buffer; -import io.vertx.core.json.JsonObject; -import io.vertx.ext.auth.authentication.TokenCredentials; -import io.vertx.ext.web.client.HttpRequest; -import io.vertx.ext.web.client.HttpResponse; -import io.vertx.ext.web.client.WebClient; -import io.vertx.junit5.VertxTestContext; - -/** - * A class providing capabilities for tests to communicate with a Cyface Data server. - * - * @author Armin Schnabel - * @author Klemens Muthmann - * @version 4.0.0 - * @since 1.0.0 - */ -public final class ApiServer { - - /** - * The host to run the test {@code ApiVerticle} - */ - public static final String HTTP_HOST = "localhost"; - /** - * The port the server is reachable at. - */ - private int port; - /** - * The endpoint on which the test {@code ApiVerticle} listens to. - */ - private final String httpEndpoint; - /** - * The parameter key required to be passed to the {@code Config} of the test {@code ApiVerticle}. - */ - private final String httpEndpointParameterKey; - - public ApiServer(final String httpEndpointParameterKey, final String httpEndpoint) { - this.httpEndpointParameterKey = httpEndpointParameterKey; - this.httpEndpoint = httpEndpoint; - } - - /** - * Starts a test Cyface Data server and creates a Vert.x WebClient usable to access the API. - * - * @param vertx The Vertx instance to start and access the server - * @param testContext The TestContext to create a new Server and WebClient - * @param mongoDatabase The Mongo database to store the test data to - * @param resultHandler The handler called after this server has finished starting - * @param verticleClassName The name of the {@code ApiVerticle} to deploy - * @throws IOException If the server port could not be opened - */ - @SuppressWarnings("unused") // Part of the API - public void start(final Vertx vertx, final VertxTestContext testContext, final TestMongoDatabase mongoDatabase, - final String verticleClassName, final Handler> resultHandler) throws IOException { - start(vertx, testContext, mongoDatabase, verticleClassName, new JsonObject(), resultHandler); - } - - /** - * Starts a test Cyface Data server and creates a Vert.x WebClient usable to access the API. - * - * @param vertx The Vertx instance to start and access the server - * @param testContext The TestContext to create a new Server and WebClient - * @param mongoDatabase The Mongo database to store the test data to - * @param resultHandler The handler called after this server has finished starting - * @param verticleClassName The name of the {@code ApiVerticle} to deploy - * @param config A {@code JsonObject} which contains custom config parameters to be used when deploying the verticle - * @throws IOException If the server port could not be opened - */ - public void start(final Vertx vertx, final VertxTestContext testContext, final TestMongoDatabase mongoDatabase, - final String verticleClassName, final JsonObject config, - final Handler> resultHandler) throws IOException { - - final ServerSocket socket = new ServerSocket(0); - port = socket.getLocalPort(); - socket.close(); - - config.put("mongo.db", mongoDatabase.config()) - .put("http.port", port) - .put("http.host", HTTP_HOST) - .put(httpEndpointParameterKey, httpEndpoint); - final DeploymentOptions options = new DeploymentOptions().setConfig(config); - - vertx.deployVerticle(verticleClassName, options, testContext - .succeeding(result -> resultHandler.handle(Future.succeededFuture(WebClient.create(vertx))))); - } - - /** - * Send an authenticated {@code GET} request to a test server instance - * - * @param client The Vert.x WebClient to use - * @param endpoint The service endpoint to call to get some data - * @param testContext The VertxTextContext provided by the current test case - * @param headers Additional headers to add to the request. - * @param resultHandler A handler provided with the result of the get request - */ - @SuppressWarnings("unused") // Part of the API - public void get(final WebClient client, final String endpoint, final VertxTestContext testContext, - final MultiMap headers, final Handler>> resultHandler) { - - final String authToken = "eyTestToken"; - - final HttpRequest builder = client - .get(port(), HTTP_HOST, httpEndpoint + endpoint) - .authentication(new TokenCredentials(authToken)); - if (headers.size() > 0) { - builder.putHeaders(headers); - } - builder.send(resultHandler); - } - - /** - * Send an unauthenticated {@code POST} request to a test server instance - * - * @param client The Vert.x WebClient to use - * @param endpoint The service endpoint to call to get some data - * @param body The body to post - * @param testContext The VertxTextContext provided by the current test case - * @param resultHandler A handler provided with the result of the get request - */ - @SuppressWarnings("unused") // Part of the API - public void postUnauthorized(final WebClient client, final String endpoint, final JsonObject body, - final VertxTestContext testContext, final Handler>> resultHandler) { - - client.post(port(), HTTP_HOST, httpEndpoint + endpoint) - .sendJsonObject(body, resultHandler); - } - - /** - * Send an unauthenticated {@code GET} request to a test server instance - * - * @param client The Vert.x WebClient to use - * @param endpoint The service endpoint to call to get some data - * @param testContext The VertxTextContext provided by the current test case - * @param resultHandler A handler provided with the result of the get request - */ - @SuppressWarnings("unused") // Part of the API - public void getUnauthorized(final WebClient client, final String endpoint, final VertxTestContext testContext, - final Handler>> resultHandler) { - - client.get(port(), HTTP_HOST, httpEndpoint + endpoint) - .send(resultHandler); - } - - /** - * @return The port the server is reachable at. - */ - private int port() { - return port; - } -} diff --git a/api-test-environment/src/main/java/de/cyface/apitestutils/TestEnvironment.java b/api-test-environment/src/main/java/de/cyface/apitestutils/TestEnvironment.java deleted file mode 100644 index ccd7a2a..0000000 --- a/api-test-environment/src/main/java/de/cyface/apitestutils/TestEnvironment.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright 2020-2022 Cyface GmbH - * - * This file is part of the Cyface API Library. - * - * The Cyface API Library is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Cyface API Library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the Cyface API Library. If not, see . - */ -package de.cyface.apitestutils; - -import java.io.IOException; -import java.util.UUID; - -import de.cyface.apitestutils.fixture.TestFixture; -import io.vertx.core.AsyncResult; -import io.vertx.core.Future; -import io.vertx.core.Handler; -import io.vertx.core.Vertx; -import io.vertx.core.json.JsonObject; -import io.vertx.ext.mongo.MongoClient; -import io.vertx.ext.web.client.WebClient; -import io.vertx.junit5.VertxTestContext; - -/** - * Test environment containing all dependencies required to run a Cyface data server in a local environment. - * - * @author Klemens Muthmann - * @author Armin Schnabel - * @version 3.1.1 - * @since 1.0.0 - */ -public final class TestEnvironment { - - /** - * The default data source name to use for user and data database if none is provided via configuration. - */ - private final String DEFAULT_MONGO_DATA_SOURCE_NAME = "cyface"; - /** - * A temporary Mongo database used only for one test. - */ - private final TestMongoDatabase testMongoDatabase; - /** - * The client to be used to access the test Mongo database. - */ - private MongoClient mongoClient; - /** - * A handle to the Cyface exporter server running within this environment. - */ - private final ApiServer apiServer; - /** - * The WebClient to simulate client requests. - */ - private WebClient webClient; - - /** - * Create a new object of this class and starting the simulated server. - * To do anything meaningful with it, you need to add some test data via - * {@link #insertFixture(TestFixture)}. - * ATTENTION: Do not forget to call {@link #shutdown()} after you finished using this object, for example in - * an org.junit.jupiter.api.AfterEach method. - * - * @param vertx A Vertx instance to set up the test environment - * @param testContext The Vertx-JUnit test context used to synchronize the JUnit lifecycle with Vertx - * @param resultHandler Called after the environment has finished setting up - * @param verticleClassName The name of the {@code ApiVerticle} to deploy - * @param httpEndpointParameterKey The parameter key required to be passed to the {@code Config} of the test - * {@code ApiVerticle}. - * @param httpEndpoint The endpoint on which the test {@code ApiVerticle} listens to. - * @throws IOException If the temporary Mongo database fails to start - */ - @SuppressWarnings("unused") // Part of the API - public TestEnvironment(final Vertx vertx, final VertxTestContext testContext, - final Handler> resultHandler, final String verticleClassName, - final String httpEndpointParameterKey, final String httpEndpoint) - throws IOException { - this(vertx, testContext, resultHandler, verticleClassName, httpEndpointParameterKey, httpEndpoint, - new JsonObject()); - } - - /** - * Create a new object of this class and starting the simulated server. - * To do anything meaningful with it, you need to add some test data via - * {@link #insertFixture(TestFixture)}. - * ATTENTION: Do not forget to call {@link #shutdown()} after you finished using this object, for example in - * an org.junit.jupiter.api.AfterEach method. - * - * @param vertx A Vertx instance to set up the test environment - * @param testContext The Vertx-JUnit test context used to synchronize the JUnit lifecycle with Vertx - * @param resultHandler Called after the environment has finished setting up - * @param verticleClassName The name of the {@code ApiVerticle} to deploy - * @param httpEndpointParameterKey The parameter key required to be passed to the {@code Config} of the test - * {@code ApiVerticle}. - * @param httpEndpoint The endpoint on which the test {@code ApiVerticle} listens to. - * @param config A {@code JsonObject} which contains custom config parameters to be used when deploying the verticle - * @throws IOException If the temporary Mongo database fails to start - */ - public TestEnvironment(final Vertx vertx, final VertxTestContext testContext, - final Handler> resultHandler, final String verticleClassName, - final String httpEndpointParameterKey, final String httpEndpoint, final JsonObject config) - throws IOException { - this.testMongoDatabase = new TestMongoDatabase(); - testMongoDatabase.start(); - - // Deploy ApiVerticle and a VertX WebClient usable to access the api - apiServer = new ApiServer(httpEndpointParameterKey, httpEndpoint); - apiServer.start(vertx, testContext, testMongoDatabase, verticleClassName, config, - testContext.succeeding(webClient -> { - this.webClient = webClient; - - // Set up a Mongo client to access the database - final var mongoDbConfiguration = testMongoDatabase.config(); - final var dataSourceName = config.getString("data_source_name", DEFAULT_MONGO_DATA_SOURCE_NAME); - this.mongoClient = MongoClient.createShared(vertx, mongoDbConfiguration, dataSourceName); - - resultHandler.handle(Future.succeededFuture()); - })); - } - - /** - * Asynchronously inserts the provided {@link TestFixture} into this environment and calls the result handler upon - * completion. - * - * @param fixture The fixture to add to this environment - * @return A {@code Future} which is resolves to the id of the created entry if successful. - */ - @SuppressWarnings("unused") // API - public Future insertFixture(final TestFixture fixture) { - return fixture.insertTestData(mongoClient); - } - - /** - * Call this method after your test has finished cleaning up the environment. The most convenient place to call this - * in an AfterEach method. - */ - @SuppressWarnings("unused") // API - public void shutdown() { - testMongoDatabase.stop(); - } - - /** - * @return A handle to the Cyface exporter server running within this environment - */ - @SuppressWarnings("unused") // API - public ApiServer getApiServer() { - return apiServer; - } - - /** - * @return The WebClient to simulate client requests - */ - @SuppressWarnings("unused") // API - public WebClient getWebClient() { - return webClient; - } - - /** - * @return The client to be used to access the test Mongo database. - */ - public MongoClient getMongoClient() { - return mongoClient; - } -} diff --git a/api-test-environment/src/main/java/de/cyface/apitestutils/TestMongoDatabase.java b/api-test-environment/src/main/java/de/cyface/apitestutils/TestMongoDatabase.java deleted file mode 100644 index 5b794f7..0000000 --- a/api-test-environment/src/main/java/de/cyface/apitestutils/TestMongoDatabase.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 20180-2022 Cyface GmbH - * - * This file is part of the Cyface API Library. - * - * The Cyface API Library is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Cyface API Library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the Cyface API Library. If not, see . - */ -package de.cyface.apitestutils; - -import java.io.IOException; -import java.net.ServerSocket; - -import de.flapdoodle.embed.mongo.MongodExecutable; -import de.flapdoodle.embed.mongo.MongodProcess; -import de.flapdoodle.embed.mongo.MongodStarter; -import de.flapdoodle.embed.mongo.config.MongodConfig; -import de.flapdoodle.embed.mongo.config.Net; -import de.flapdoodle.embed.mongo.distribution.Version; -import de.flapdoodle.embed.process.runtime.Network; -import io.vertx.core.json.JsonObject; - -/** - * A lifecycle handler for a Mongo database you can start and stop on the fly. The database is reinitialized after each - * restart. - * - * @author Armin Schnabel - * @author Klemens Muthmann - * @version 2.0.2 - * @since 1.0.0 - */ -public final class TestMongoDatabase { - /** - * The test Mongo database. This must be shut down after finishing this Mongo database run. - */ - private MongodProcess mongo; - /** - * The executable running the MongodProcess. This must be shut down after finishing this Mongo database - * run. - */ - private MongodExecutable mongodExecutable; - /** - * The host at which the mongo database is to be started. - */ - static final String MONGO_HOST = "localhost"; - /** - * The name of the test Mongo database to create. - */ - static final String MONGO_DATABASE = "cyface"; - /** - * The port to run the test Mongo database under. - */ - private int port; - - /** - * Sets up the Mongo database used for the test instance. - * - * @throws IOException Fails the test if anything unexpected goes wrong - */ - public void start() throws IOException { - final var socket = new ServerSocket(0); - port = socket.getLocalPort(); - socket.close(); - final var starter = MongodStarter.getDefaultInstance(); - final var mongodConfig = MongodConfig.builder().version(Version.Main.PRODUCTION) - .net(new Net(MONGO_HOST, port, Network.localhostIsIPv6())).build(); - mongodExecutable = starter.prepare(mongodConfig); - mongo = mongodExecutable.start(); - } - - /** - * Provides the database configuration as required by Vertx. - * - * @return The database configuration - */ - public JsonObject config() { - final JsonObject ret = new JsonObject(); - ret.put("connection_string", "mongodb://" + MONGO_HOST + ":" + port).put("db_name", MONGO_DATABASE); - return ret; - } - - /** - * Stops the test Mongo database after all tests have been finished and waits a little so that a new test may - * restart the database, without interference. - */ - public void stop() { - mongo.stop(); - mongodExecutable.stop(); - } -} diff --git a/api-test-environment/src/main/java/de/cyface/apitestutils/TestParameters.java b/api-test-environment/src/main/java/de/cyface/apitestutils/TestParameters.java deleted file mode 100644 index 030468f..0000000 --- a/api-test-environment/src/main/java/de/cyface/apitestutils/TestParameters.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2019-2022 Cyface GmbH - * - * This file is part of the Cyface API Library. - * - * The Cyface API Library is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Cyface API Library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the Cyface API Library. If not, see . - */ -package de.cyface.apitestutils; - -import org.apache.commons.lang3.Validate; - -import de.cyface.apitestutils.fixture.TestFixture; -import io.vertx.core.MultiMap; - -/** - * Parameters used for a single run of the API test - * - * @author Klemens Muthmann - * @author Armin Schnabel - * @version 2.0.1 - * @since 1.0.0 - */ -@SuppressWarnings("unused") // Part of the API -public final class TestParameters { - - /** - * The fixture with the data required to run the test. - */ - private final TestFixture testFixture; - /** - * The expected result. - */ - private final String expectedResult; - /** - * The API endpoint used to ask for a data access. - */ - private final String endpoint; - /** - * The header fields to attach to the request. - */ - private final MultiMap headers; - - /** - * Creates a new completely initialized instance of this class. All attributes are read only. - * - * @param testFixture The fixture with the data required to run the test - * @param expectedResult The expected export - * @param endpoint The API endpoint used to ask for a data export - */ - @SuppressWarnings("unused") // Part of the API - public TestParameters(final TestFixture testFixture, final String expectedResult, final String endpoint) { - this(testFixture, expectedResult, endpoint, MultiMap.caseInsensitiveMultiMap()); - } - - /** - * Creates a new completely initialized instance of this class. All attributes are read only. - * - * @param testFixture The fixture with the data required to run the test - * @param expectedResult The expected export - * @param endpoint The API endpoint used to ask for a data export - * @param headers The header fields to attach to the request. - */ - public TestParameters(final TestFixture testFixture, final String expectedResult, final String endpoint, - final MultiMap headers) { - this.testFixture = Validate.notNull(testFixture); - this.expectedResult = Validate.notEmpty(expectedResult); - this.endpoint = Validate.notEmpty(endpoint); - this.headers = headers; - } - - /** - * @return The fixture with the data required to run the test - */ - @SuppressWarnings("unused") // Part of the API - public String getExpectedResult() { - return expectedResult; - } - - /** - * @return The expected result - */ - @SuppressWarnings("unused") // Part of the API - public TestFixture getTestFixture() { - return testFixture; - } - - /** - * @return The API endpoint used to ask for a data access - */ - @SuppressWarnings("unused") // Part of the API - public String getEndpoint() { - return endpoint; - } - - /** - * @return The header fields to attach to the request. - */ - @SuppressWarnings("unused") // Part of the API - public MultiMap getHeaders() { - return headers; - } - - @Override - public String toString() { - return "TestParameters{" + - "testFixture=" + testFixture + - ", expectedResult='" + expectedResult + '\'' + - ", endpoint='" + endpoint + '\'' + - ", headers=" + headers + - '}'; - } -} diff --git a/api-test-environment/src/main/java/de/cyface/apitestutils/fixture/DatabaseConstants.java b/api-test-environment/src/main/java/de/cyface/apitestutils/fixture/DatabaseConstants.java deleted file mode 100644 index 9c8f5ed..0000000 --- a/api-test-environment/src/main/java/de/cyface/apitestutils/fixture/DatabaseConstants.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2019-2023 Cyface GmbH - * - * This file is part of the Cyface API Library. - * - * The Cyface API Library is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Cyface API Library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the Cyface API Library. If not, see . - */ -package de.cyface.apitestutils.fixture; - -/** - * Constants used in the database containing the compressed serialized data received from clients. - * - * @author Armin Schnabel - * @version 1.3.0 - * @since 1.0.0 - */ -public class DatabaseConstants { - - /** - * The prefix for user roles which defines an user with "manager" permissions. - *

- * The current semantic of the manager role is the following: - * The users with the role "myGroup_manager" can access data of all users with role - * "myGroup"+{@code #USER_GROUP_ROLE_PREFIX} - */ - public static final String GROUP_MANAGER_ROLE_SUFFIX = "_manager"; - /** - * The prefix for user roles which define a user "group" as there is no such thing in the vertx mongo auth provider. - *

- * The current semantic of the user role is the following: - * The user data of all users with the role "myGroup_user" can be accessed by users with role - * "myGroup"+{@code #GROUP_MANAGER_ROLE_PREFIX} - */ - public static final String USER_GROUP_ROLE_SUFFIX = "_user"; - /** - * The database collection name. - */ - public static final String COLLECTION_FILES = "fs.files"; - /** - * The database collection name. - */ - public static final String COLLECTION_CHUNKS = "fs.chunks"; - /** - * The database field name used to annotate the owner of data by its user id. - */ - public static final String USER_ID_FIELD = "userId"; - /** - * The database field name. - */ - public static final String METADATA_FIELD = "metaData"; - /** - * The database field name. - */ - public static final String METADATA_DEVICE_ID_FIELD = "deviceId"; - /** - * The database field name used to annotate the device type in the metadata. - */ - public static final String METADATA_DEVICE_TYPE_FIELD = "deviceType"; - /** - * The database field name used to annotate the os version in the metadata. - */ - public static final String METADATA_OS_VERSION_FIELD = "osVersion"; - /** - * The database field name used to annotate the app version in the metadata. - */ - public static final String METADATA_APP_VERSION_FIELD = "appVersion"; - /** - * The database field name used to annotate the length of the measurement in the metadata. - */ - public static final String METADATA_LENGTH_FIELD = "length"; - /** - * The database field name used to annotate the version of the metadata format. - */ - public static final String METADATA_VERSION_FIELD = "version"; - /** - * The database field name. - */ - public static final String METADATA_MEASUREMENT_ID_FIELD = "measurementId"; - /** - * The database field name used to annotate the track bucket of a measurement in the deserialized collection. - */ - public static final String DESERIALIZED_TRACK_FIELD = "track"; - /** - * The database field name. - */ - public static final String ID_FIELD = "_id"; - /** - * The database field name. - */ - public static final String CHUNKS_FILES_ID_FIELD = "files_id"; - /** - * The database field name. - */ - public static final String CHUNKS_DATA_FIELD = "data"; - /** - * The database field name. - */ - public static final String CHUNKS_DATA_BINARY_FIELD = "$binary"; - /** - * The file extension of Compressed Cyface "Events" binary files. - */ - public static final String METADATA_FILE_TYPE_CCYF = "ccyf"; -} diff --git a/api-test-environment/src/main/java/de/cyface/apitestutils/fixture/GeoLocationTestFixture.java b/api-test-environment/src/main/java/de/cyface/apitestutils/fixture/GeoLocationTestFixture.java deleted file mode 100644 index f8abb8b..0000000 --- a/api-test-environment/src/main/java/de/cyface/apitestutils/fixture/GeoLocationTestFixture.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2020-2023 Cyface GmbH - * - * This file is part of the Cyface API Library. - * - * The Cyface API Library is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Cyface API Library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the Cyface API Library. If not, see . - */ -package de.cyface.apitestutils.fixture; - -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import de.cyface.model.MeasurementIdentifier; -import io.vertx.core.CompositeFuture; -import io.vertx.core.Future; -import io.vertx.core.Promise; -import io.vertx.ext.mongo.MongoClient; - -/** - * A fixture providing data to use for testing the raw geographical location export. - *

- * Inserts a test {@link DatabaseConstants#GROUP_MANAGER_ROLE_SUFFIX} user and a test - * {@link DatabaseConstants#USER_GROUP_ROLE_SUFFIX} user and references the group user as data owner in the created - * data fixtures. - *

- * {@link #insertTestData(MongoClient)} returns the user identifier of that data owner. - * - * @author Klemens Muthmann - * @author Armin Schnabel - * @version 5.0.0 - * @since 1.0.0 - */ -@SuppressWarnings("unused") // API -public final class GeoLocationTestFixture implements TestFixture { - /** - * The name of the test group to export test data of. - */ - private static final String TEST_GROUP = "testGroup"; - /** - * The name of the user to add test data for in group-data accessing tests. - */ - public static final String TEST_GROUP_USER_USERNAME = TEST_GROUP + "1"; - /** - * The user which is used for authentication in the test. - */ - public static final String TEST_USER_NAME = "admin"; - /** - * The identifiers of the measurements to be used during the test. - */ - private final List testMeasurementIdentifiers; - - /** - * Creates a new completely initialized fixture for the test. - * - * @param testMeasurementIdentifiers The identifiers of the measurements to be used during the test. - */ - @SuppressWarnings("unused") // API - public GeoLocationTestFixture(final List testMeasurementIdentifiers) { - this.testMeasurementIdentifiers = testMeasurementIdentifiers; - } - - @Override - public Future insertTestData(MongoClient mongoClient) { - - // Insert of test group manager and -user removed after switching to OAuth - final var userId = UUID.randomUUID(); - - final Promise promise = Promise.promise(); - final var testDocuments = testMeasurementIdentifiers.stream().map( - id -> new TestMeasurementDocument(userId, id.getMeasurementIdentifier(), id.getDeviceIdentifier())) - .collect(Collectors.toList()); - - // noinspection rawtypes - final var futures = testDocuments.stream().map(d -> (Future)d.insert(mongoClient)) - .collect(Collectors.toList()); - - final CompositeFuture composition = CompositeFuture.all(futures); - composition.onSuccess(succeeded -> promise.complete(userId)); - composition.onFailure(promise::fail); - - return promise.future(); - } -} diff --git a/api-test-environment/src/main/java/de/cyface/apitestutils/fixture/MongoTestData.java b/api-test-environment/src/main/java/de/cyface/apitestutils/fixture/MongoTestData.java deleted file mode 100644 index fde1f0c..0000000 --- a/api-test-environment/src/main/java/de/cyface/apitestutils/fixture/MongoTestData.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2020-2022 Cyface GmbH - * - * This file is part of the Cyface API Library. - * - * The Cyface API Library is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Cyface API Library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the Cyface API Library. If not, see . - */ -package de.cyface.apitestutils.fixture; - -import io.vertx.core.Future; -import io.vertx.ext.mongo.MongoClient; - -/** - * Some data that can be inserted as test data into the Cyface Mongo database. - * - * @author Klemens Muthmann - * @author Armin Schnabel - * @version 2.0.1 - * @since 1.0.0 - */ -public interface MongoTestData { - - /** - * Inserts the data via the provided client and calls the provided resultHandler after completion. - * - * @param mongoClient The client to use to insert the data into the Mongo database - * @return a {@code Future} which resolves to the id of the created entry if successful. - */ - Future insert(final MongoClient mongoClient); -} diff --git a/api-test-environment/src/main/java/de/cyface/apitestutils/fixture/TestFixture.java b/api-test-environment/src/main/java/de/cyface/apitestutils/fixture/TestFixture.java deleted file mode 100644 index 83d7946..0000000 --- a/api-test-environment/src/main/java/de/cyface/apitestutils/fixture/TestFixture.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2020-2022 Cyface GmbH - * - * This file is part of the Cyface API Library. - * - * The Cyface API Library is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Cyface API Library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the Cyface API Library. If not, see . - */ -package de.cyface.apitestutils.fixture; - -import de.cyface.apitestutils.TestEnvironment; -import io.vertx.core.Future; -import io.vertx.ext.mongo.MongoClient; - -import java.util.UUID; - -/** - * A provider for test fixture data. Such a provider is required by {@link TestEnvironment} instances. - * - * @author Klemens Muthmann - * @version 2.0.1 - * @since 1.0.0 - * @see TestEnvironment - */ -public interface TestFixture { - /** - * Insert some test data into a test Mongo database via the provided mongoClient. - * - * @param mongoClient The client to access the Mongo database hosting the test data - * @return A {@code Future} which is resolved after inserting the data has completed - */ - Future insertTestData(final MongoClient mongoClient); -} diff --git a/api-test-environment/src/main/java/de/cyface/apitestutils/fixture/TestMeasurementDocument.java b/api-test-environment/src/main/java/de/cyface/apitestutils/fixture/TestMeasurementDocument.java deleted file mode 100644 index ecd2b1c..0000000 --- a/api-test-environment/src/main/java/de/cyface/apitestutils/fixture/TestMeasurementDocument.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright 2020-2022 Cyface GmbH - * - * This file is part of the Cyface API Library. - * - * The Cyface API Library is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Cyface API Library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the Cyface API Library. If not, see . - */ -package de.cyface.apitestutils.fixture; - -import static de.cyface.apitestutils.fixture.DatabaseConstants.DESERIALIZED_TRACK_FIELD; -import static de.cyface.apitestutils.fixture.DatabaseConstants.METADATA_APP_VERSION_FIELD; -import static de.cyface.apitestutils.fixture.DatabaseConstants.METADATA_DEVICE_ID_FIELD; -import static de.cyface.apitestutils.fixture.DatabaseConstants.METADATA_DEVICE_TYPE_FIELD; -import static de.cyface.apitestutils.fixture.DatabaseConstants.METADATA_FIELD; -import static de.cyface.apitestutils.fixture.DatabaseConstants.METADATA_LENGTH_FIELD; -import static de.cyface.apitestutils.fixture.DatabaseConstants.METADATA_MEASUREMENT_ID_FIELD; -import static de.cyface.apitestutils.fixture.DatabaseConstants.METADATA_OS_VERSION_FIELD; -import static de.cyface.apitestutils.fixture.DatabaseConstants.METADATA_VERSION_FIELD; -import static de.cyface.apitestutils.fixture.DatabaseConstants.USER_ID_FIELD; - -import org.apache.commons.lang3.Validate; - -import de.cyface.model.Modality; -import io.vertx.core.Future; -import io.vertx.core.Promise; -import io.vertx.core.json.JsonArray; -import io.vertx.core.json.JsonObject; -import io.vertx.ext.mongo.MongoClient; - -import java.util.UUID; - -/** - * A test document inside the Mongo database which contains an unpacked (deserialized) measurement. - * - * @author Armin Schnabel - * @version 4.0.0 - * @since 1.0.0 - */ -public final class TestMeasurementDocument implements MongoTestData { - - /** - * The id of the user who uploaded the file. - */ - private final UUID ownerUserId; - /** - * The identifier of the measurement encoded in the file. - */ - private final long measurementIdentifier; - /** - * The worldwide unique identifier of the device the document comes from. - */ - private final String deviceIdentifier; - /** - * The database collection name which contains deserialized measurements. - */ - private static final String COLLECTION_DESERIALIZED = "deserialized"; - - /** - * Creates a new completely initialized document. You may insert it into a Mongo database by calling - * {@link #insert(MongoClient)}. - * - * @param ownerUserId The id of the user who uploaded the file. - * @param measurementIdentifier The identifier of the measurement encoded in the file - * @param deviceIdentifier The worldwide unique identifier of the device the document comes from - */ - public TestMeasurementDocument(final UUID ownerUserId, final Long measurementIdentifier, - final String deviceIdentifier) { - this.ownerUserId = Validate.notNull(ownerUserId); - this.measurementIdentifier = Validate.notNull(measurementIdentifier); - this.deviceIdentifier = Validate.notEmpty(deviceIdentifier); - } - - @Override - public Future insert(final MongoClient mongoClient) { - - final var metaData = new JsonObject() - .put(METADATA_DEVICE_ID_FIELD, deviceIdentifier) - .put(METADATA_MEASUREMENT_ID_FIELD, measurementIdentifier) - .put(METADATA_DEVICE_TYPE_FIELD, "Pixel 3") - .put(METADATA_OS_VERSION_FIELD, "Android 9.0.0") - .put(METADATA_APP_VERSION_FIELD, "1.2.0") - .put(METADATA_LENGTH_FIELD, 1500.2) - .put(USER_ID_FIELD, ownerUserId.toString()) - .put(METADATA_VERSION_FIELD, "3.0.0"); - - final JsonArray geoLocations = new JsonArray(); - final var geometry1 = new JsonObject() - .put("type", "Point") - .put("coordinates", new JsonArray().add(13.1).add(51.1)); - final JsonObject geoLocation = new JsonObject() - .put("geometry", geometry1) - .put("timestamp", 1L) - .putNull("elevation") - .put("speed", 5.0) - .put("accuracy", 0.13) - .put("modality", Modality.UNKNOWN.getDatabaseIdentifier()); - final var geometry2 = new JsonObject() - .put("type", "Point") - .put("coordinates", new JsonArray().add(13.2).add(51.2)); - final JsonObject geoLocation2 = new JsonObject() - .put("geometry", geometry2) - .put("timestamp", 2L) - .putNull("elevation") - .put("speed", 5.0) - .put("accuracy", 0.13) - .put("modality", Modality.BICYCLE.getDatabaseIdentifier()); - geoLocations.add(geoLocation); - geoLocations.add(geoLocation2); - - final JsonArray accelerations = new JsonArray(); - final JsonObject point3D = new JsonObject() - .put("timestamp", 1L) - .put("x", 5.0) - .put("y", -5.0) - .put("z", 0.0); - final JsonObject point3D2 = new JsonObject() - .put("timestamp", 2L) - .put("x", 5.0) - .put("y", -5.0) - .put("z", 0.0); - accelerations.add(point3D); - accelerations.add(point3D2); - final JsonArray rotations = new JsonArray(); - rotations.add(point3D); - final JsonArray directions = new JsonArray(); - directions.add(point3D2); - - final JsonObject trackBucket = new JsonObject() - .put("trackId", 0) - .put("bucket", new JsonObject().put("$date", "2020-12-22T15:13:00.000+00:00")) - .put("geoLocations", geoLocations) - .put("accelerations", accelerations) - .put("rotations", rotations) - .put("directions", directions); - - final var measurementDocument = new JsonObject() - .put(METADATA_FIELD, metaData) - .put(DESERIALIZED_TRACK_FIELD, trackBucket); - - final Promise promise = Promise.promise(); - final var insert = mongoClient.insert(COLLECTION_DESERIALIZED, measurementDocument); - insert.onSuccess(promise::complete); - insert.onFailure(promise::fail); - return promise.future(); - } -} diff --git a/api-test-environment/src/main/java/de/cyface/apitestutils/fixture/package-info.java b/api-test-environment/src/main/java/de/cyface/apitestutils/fixture/package-info.java deleted file mode 100644 index 0e2b4f8..0000000 --- a/api-test-environment/src/main/java/de/cyface/apitestutils/fixture/package-info.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2020-2022 Cyface GmbH - * - * This file is part of the Cyface API Library. - * - * The Cyface API Library is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Cyface API Library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the Cyface API Library. If not, see . - */ -/** - * This package contains all classes required to set up a test fixture for a Cyface api test. - * - * @author Klemens Muthmann - * @author Armin Schnabel - * @version 1.0.1 - * @since 1.0.0 - */ -package de.cyface.apitestutils.fixture; diff --git a/api/build.gradle b/api/build.gradle index 7b77583..44fde07 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -35,7 +35,6 @@ dependencies { implementation "io.vertx:vertx-auth-jwt:$vertxVersion" // Api // Test Dependencies - testImplementation project(':api-test-environment') testImplementation "io.vertx:vertx-junit5:$vertxVersion" testImplementation "org.junit.jupiter:junit-jupiter:$junitVersion" } diff --git a/settings.gradle b/settings.gradle index 96a8562..d951355 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,5 +1,5 @@ /* - * Copyright 2022 Cyface GmbH + * Copyright 2022-2023 Cyface GmbH * * This file is part of the Cyface API Library. * @@ -18,6 +18,5 @@ */ include ':api' -include ':api-test-environment' rootProject.name = 'api'