Skip to content

Commit 6e2c116

Browse files
authored
CASL-1784 gradle build fix
CASL-1784 gradle build fix
2 parents cd2c481 + e8c1f1d commit 6e2c116

21 files changed

Lines changed: 216 additions & 169 deletions

File tree

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,41 @@ The service will respond with the inserted geo features:
243243
244244
# Testing locally
245245
246-
To run tests locally run Gradle `cleanAndTest` task:
246+
Naksha tests can currently run in two modes:
247+
248+
1. Against a Postgres database that you start yourself (for example the containerized Postgres described above).
249+
2. Against a Postgres container started automatically by the build via [Testcontainers](https://github.com/testcontainers).
250+
251+
Before running Gradle, set the environment variables for the mode you want.
252+
253+
### Option 1: Run tests against a local standalone Postgres
254+
255+
```bash
256+
export NAKSHA_APP_SERVICE_TEST_CONTEXT=LOCAL_STANDALONE
257+
export NAKSHA_TEST_STORAGE_ID=local_psql_test_storage
258+
export HUB_ADMIN_STORAGE_ID=local_psql_test_storage
259+
260+
# For `here-naksha-lib-psql` tests.
261+
export NAKSHA_TEST_PSQL_DB_URL="jdbc:postgresql://localhost:5432/postgres?user=postgres&password=password"
262+
263+
# For `here-naksha-app-service` admin storage tests.
264+
export NAKSHA_TEST_ADMIN_DB_URL="jdbc:postgresql://localhost:5432/postgres?user=postgres&password=password"
265+
266+
# For `here-naksha-app-service` data storage tests.
267+
# Kept separate from the admin DB URL to allow deployment-like test setups,
268+
# where administrative entities are stored in a different database/storage than data entities.
269+
export NAKSHA_TEST_DATA_DB_URL="jdbc:postgresql://localhost:5432/postgres?user=postgres&password=password"
270+
271+
./gradlew cleanAndTest
272+
```
273+
274+
### Option 2: Run tests with Testcontainers-managed Postgres
275+
247276
```bash
277+
export NAKSHA_APP_SERVICE_TEST_CONTEXT=TEST_CONTAINERS
278+
export HUB_ADMIN_STORAGE_ID=local_psql_test_storage
279+
export NAKSHA_TEST_STORAGE_ID=local_psql_test_storage
280+
248281
./gradlew cleanAndTest
249282
```
250283

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ val allModules = mapOf(
7878
Pair("naksha", Pair(CleanAndTest.OFF, PublishModule.CONFIG_ONLY)),
7979
Pair("here-naksha-app-service", Pair(CleanAndTest.KOTLIN, PublishModule.YES)),
8080
Pair("here-naksha-common-http", Pair(CleanAndTest.KOTLIN, PublishModule.YES)),
81+
Pair("here-naksha-common-test", Pair(CleanAndTest.OFF, PublishModule.YES)),
8182
Pair("here-naksha-handler-activitylog", Pair(CleanAndTest.KOTLIN, PublishModule.YES)),
8283
Pair("here-naksha-lib-auth", Pair(CleanAndTest.KOTLIN, PublishModule.YES)),
8384
Pair("here-naksha-lib-base", Pair(CleanAndTest.KOTLIN, PublishModule.YES)),

buildSrc/src/main/kotlin/Descriptions.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.gradle.api.Project
66
private val Descriptions = mapOf(
77
"here-naksha-app-service" to "TBD",
88
"here-naksha-common-http" to "TBD",
9+
"here-naksha-common-test" to "TBD",
910
"here-naksha-handler-activitylog" to "Naksha handler, adds downward compatibility to XYZ-Hub activity-log.",
1011
//"here-naksha-handler-http" to "TBD",
1112
"here-naksha-lib-auth" to "Naksha library, provides helper classes to perform authorization against Wikvaya UPM (User Permission Management) authorization matrix.",

here-naksha-app-service/src/jvmTest/java/com/here/naksha/app/init/TestStorageConfig.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package com.here.naksha.app.init;
22

3-
import static com.here.naksha.lib.hub.NakshaHubAdminStorageIdentifiers.DEFAULT_HUB_ADMIN_STORAGE_ID;
4-
53
import com.here.naksha.lib.core.util.IoHelp;
64
import com.here.naksha.lib.core.util.IoHelp.LoadedBytes;
5+
import com.here.naksha.lib.hub.NakshaHubAdminStorageIdentifiers;
76
import java.nio.charset.StandardCharsets;
87
import naksha.model.NakshaVersion;
98
import naksha.psql.PgConfig;
@@ -34,19 +33,19 @@ public TestStorageConfig(String mapId, PgConfig pgConfig) {
3433
final byte[] bytes = loadedBytes.getBytes();
3534
String url = new String(bytes, StandardCharsets.UTF_8);
3635
if (url.startsWith("jdbc:postgresql://")) {
37-
PgConfig pgConfig = new PgConfig(DEFAULT_HUB_ADMIN_STORAGE_ID).withMasterUri(url);
36+
PgConfig pgConfig = new PgConfig(NakshaHubAdminStorageIdentifiers.getHubAdminStorageId()).withMasterUri(url);
3837
return new TestStorageConfig(mapId, pgConfig);
3938
}
4039
} catch (Exception ignore) {
4140
}
4241
String url = System.getenv(envName);
4342
if (url != null && url.startsWith("jdbc:postgresql://")) {
44-
PgConfig pgConfig = new PgConfig(DEFAULT_HUB_ADMIN_STORAGE_ID).withMasterUri(url);
43+
PgConfig pgConfig = new PgConfig(NakshaHubAdminStorageIdentifiers.getHubAdminStorageId()).withMasterUri(url);
4544
return new TestStorageConfig(mapId, pgConfig);
4645
}
4746
url = System.getenv("TEST_NAKSHA_PSQL_URL");
4847
if (url != null && url.startsWith("jdbc:postgresql://")) {
49-
PgConfig pgConfig = new PgConfig(DEFAULT_HUB_ADMIN_STORAGE_ID).withMasterUri(url);
48+
PgConfig pgConfig = new PgConfig(NakshaHubAdminStorageIdentifiers.getHubAdminStorageId()).withMasterUri(url);
5049
return new TestStorageConfig(mapId, pgConfig);
5150
}
5251

@@ -57,7 +56,7 @@ public TestStorageConfig(String mapId, PgConfig pgConfig) {
5756
url = "jdbc:postgresql://localhost:5432/postgres?user=postgres&password=" + password
5857
+ "&schema=" + mapId
5958
+ "&app=" + "Naksha/v" + NakshaVersion.current;
60-
PgConfig pgConfig = new PgConfig(DEFAULT_HUB_ADMIN_STORAGE_ID).withMasterUri(url);
59+
PgConfig pgConfig = new PgConfig(NakshaHubAdminStorageIdentifiers.getHubAdminStorageId()).withMasterUri(url);
6160
return new TestStorageConfig(mapId, pgConfig);
6261
}
6362
}

here-naksha-cli/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ kotlin {
5050
}
5151
jvmTest {
5252
dependencies {
53+
implementation(project(":here-naksha-common-test"))
5354
implementation(libs.bundles.testing)
5455
implementation(libs.test.containers)
5556
runtimeOnly(libs.junit.platform.launcher) // https://github.com/gradle/gradle/issues/34512

here-naksha-cli/src/jvmTest/java/com/here/naksha/cli/copy/service/psql/PsqlCopyTest.java

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,70 @@
11
package com.here.naksha.cli.copy.service.psql;
22

3-
import com.here.naksha.cli.copy.service.*;
3+
import static naksha.model.RandomFeatures.randomFeatures;
4+
import static naksha.model.util.RequestHelper.createFeaturesRequest;
5+
import static naksha.model.util.RequestHelper.createWriteCollectionsRequest;
6+
import static naksha.model.util.ResultHelper.extractResponseItems;
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
9+
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
10+
11+
import com.here.naksha.cli.copy.service.CopyElement;
12+
import com.here.naksha.cli.copy.service.CopyService;
13+
import com.here.naksha.cli.copy.service.CopyServiceException;
14+
import com.here.naksha.cli.copy.service.CopyServiceSuccessResultPayload;
15+
import com.here.naksha.cli.copy.service.StorageProvider;
416
import com.here.naksha.cli.copy.service.executors.OneShotFeaturesWriteExecutor;
517
import com.here.naksha.cli.copy.service.executors.ParallelFeaturesWriteExecutor;
618
import com.here.naksha.cli.copy.service.executors.model.FeaturesWriteExecutor;
719
import com.here.naksha.cli.results.CommandResult;
820
import com.here.naksha.cli.results.CommandSuccess;
921
import com.here.naksha.cli.storages.GeneratingStorage;
1022
import com.here.naksha.cli.storages.GeneratingStorageConfig;
11-
import com.here.naksha.cli.testcontainers.TestContainersPsqlStorage;
1223
import com.here.naksha.lib.core.models.geojson.WebMercatorTile;
24+
import java.util.List;
25+
import java.util.UUID;
26+
import java.util.stream.Stream;
1327
import naksha.base.StringList;
28+
import naksha.common.test.CommonTestConstants;
1429
import naksha.model.IStorage;
1530
import naksha.model.Naksha;
1631
import naksha.model.NakshaContext;
1732
import naksha.model.SessionOptions;
1833
import naksha.model.objects.NakshaCollection;
1934
import naksha.model.objects.NakshaFeature;
2035
import naksha.model.objects.NakshaMap;
21-
import naksha.model.request.*;
36+
import naksha.model.objects.NakshaStorage;
37+
import naksha.model.request.ReadFeatures;
38+
import naksha.model.request.Request;
39+
import naksha.model.request.RequestQuery;
40+
import naksha.model.request.Response;
41+
import naksha.model.request.SuccessResponse;
42+
import naksha.model.request.Write;
43+
import naksha.model.request.WriteRequest;
2244
import naksha.model.request.query.SpIntersects;
2345
import naksha.model.request.query.SpOr;
2446
import org.junit.jupiter.api.BeforeEach;
2547
import org.junit.jupiter.params.ParameterizedTest;
2648
import org.junit.jupiter.params.provider.Arguments;
2749
import org.junit.jupiter.params.provider.MethodSource;
2850

29-
import java.util.List;
30-
import java.util.UUID;
31-
import java.util.stream.Stream;
32-
33-
import static naksha.model.RandomFeatures.randomFeatures;
34-
import static naksha.model.util.RequestHelper.createFeaturesRequest;
35-
import static naksha.model.util.RequestHelper.createWriteCollectionsRequest;
36-
import static naksha.model.util.ResultHelper.extractResponseItems;
37-
import static org.junit.jupiter.api.Assertions.*;
38-
3951
class PsqlCopyTest {
4052
private final String srcCollectionId = "srccolid";
4153
private final String targetCollectionId = "targetcolid";
4254
private SessionOptions sessionOptions;
55+
private static final NakshaStorage storageConfig = NakshaStorage.fromJSON("""
56+
{
57+
"id": "%s",
58+
"className": "naksha.psql.PsqlTestStorage"
59+
}
60+
""".formatted(CommonTestConstants.getTestStorageId()));
61+
private IStorage psqlStorage;
4362

4463
@BeforeEach
4564
void beforeEach() {
4665
NakshaContext.currentContext().withAppId("testapp");
4766
sessionOptions = SessionOptions.from(NakshaContext.currentContext());
67+
psqlStorage = Naksha.useStorage(storageConfig);
4868
}
4969

5070
@ParameterizedTest
@@ -58,7 +78,7 @@ void shouldCopyFeaturesBetweenGeneratingStorageAndPostgres(FeaturesWriteExecutor
5878
CopyElement source = copyElementForGeneratingStorage(sourceStorage);
5979

6080
// And: prepared target
61-
IStorage targetStorage = TestContainersPsqlStorage.getInstance().getStorage();
81+
IStorage targetStorage = psqlStorage;
6282
CopyElement target = createMapWithEmptyCollection(targetStorage, targetCollectionId);
6383

6484
// And: copy service
@@ -79,7 +99,7 @@ void shouldCopyFeaturesBetweenGeneratingStorageAndPostgres(FeaturesWriteExecutor
7999
@MethodSource("featuresWriteExecutors")
80100
void shouldCopyFeaturesBetweenMapsOnTheSameStorage(FeaturesWriteExecutor featuresWriteExecutor) {
81101
// Given: the same storage for source and target
82-
IStorage storage = TestContainersPsqlStorage.getInstance().getStorage();
102+
IStorage storage = psqlStorage;
83103

84104
// Given: prepared source
85105
CopyElement source = createMapWithEmptyCollection(storage, srcCollectionId);
@@ -110,7 +130,7 @@ void shouldCopyFeaturesBetweenMapsOnTheSameStorage(FeaturesWriteExecutor feature
110130
@MethodSource("featuresWriteExecutors")
111131
void shouldCreateMapAndCollectionThenCopy(FeaturesWriteExecutor featuresWriteExecutor) {
112132
// Given: the same storage for source and target
113-
IStorage storage = TestContainersPsqlStorage.getInstance().getStorage();
133+
IStorage storage = psqlStorage;
114134

115135
// Given: prepared source
116136
CopyElement source = createMapWithEmptyCollection(storage, srcCollectionId);

here-naksha-cli/src/jvmTest/java/com/here/naksha/cli/testcontainers/TestContainersPsqlStorage.java

Lines changed: 0 additions & 100 deletions
This file was deleted.

here-naksha-cli/src/jvmTest/java/com/here/naksha/cli/utils/JsonParserTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.nio.file.Path;
1111

1212
import static org.junit.jupiter.api.Assertions.*;
13+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
1314
import static org.junit.jupiter.api.Assumptions.assumeTrue;
1415

1516
class JsonParserTest {
@@ -33,6 +34,7 @@ void shouldFailWithNoReadable(@TempDir Path dir) throws IOException {
3334
Files.writeString(pathToFile, "{}");
3435
File file = pathToFile.toFile();
3536
assumeTrue(file.setReadable(false), "Can not set file as unreadable!");
37+
assumeFalse(Files.isReadable(pathToFile), "File is still readable by the process, skipping test");
3638
JsonParser jsonParser = new JsonParser();
3739

3840
// When & Then
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
plugins {
2+
alias(libs.plugins.kotlin.multiplatform)
3+
}
4+
5+
description = gatherDescription()
6+
7+
kotlin {
8+
jvm {
9+
compilerOptions {
10+
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11)
11+
}
12+
}
13+
js(IR) {
14+
nodejs()
15+
}
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package naksha.common.test
2+
3+
import kotlin.jvm.JvmStatic
4+
5+
object CommonTestConstants {
6+
private const val DEFAULT_TEST_STORAGE_ID: String = "local_psql_test_storage"
7+
private const val TEST_STORAGE_ID_ENV: String = "NAKSHA_TEST_STORAGE_ID"
8+
9+
@JvmStatic
10+
fun getTestStorageId(): String =
11+
currentEnvironment()[TEST_STORAGE_ID_ENV]?.takeUnless { it.isBlank() } ?: DEFAULT_TEST_STORAGE_ID
12+
}
13+
14+
internal expect fun currentEnvironment(): Map<String, String>

0 commit comments

Comments
 (0)