Skip to content

Commit

Permalink
chore: update module tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
credmond-git committed Nov 28, 2024
1 parent aad3846 commit 884f254
Show file tree
Hide file tree
Showing 5 changed files with 338 additions and 61 deletions.
2 changes: 1 addition & 1 deletion benchmark.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#$gestaltVersions = @("0.32.0", "0.31.3", "0.31.2", "0.31.1", "0.31.0", "0.30.0", "0.29.0", "0.28.0", "0.27.0", "0.26.0", "0.25.3", "0.25.2", "0.25.1", "0.25.0", "0.24.6", "0.24.5", "0.24.4", "0.24.3", "0.24.2", "0.24.1", "0.24.0", "0.23.3", "0.23.2", "0.23.1", "0.23.0", "0.22.1", "0.21.0", "0.20.6", "0.20.5", "0.20.4", "0.20.3", "0.20.2", "0.20.1", "0.19.0", "0.18.0", "0.16.6", "0.16.5", "0.16.4", "0.16.3", "0.16.2", "0.16.1", "0.16.0", "0.15.0", "0.14.1", "0.14.0", "0.13.0", "0.12.0")
$gestaltVersions = @("0.34.0", "0.33.1", "0.33.0", "0.32.0", "0.32.2", "0.32.1","0.32.0", "0.31.3", "0.31.2", "0.31.1", "0.31.0")
$gestaltVersions = @("0.35.0", "0.34.0", "0.33.1", "0.33.0", "0.32.0", "0.32.2", "0.32.1","0.32.0", "0.31.3", "0.31.2", "0.31.1", "0.31.0")
#jdkVersions = @(11 17 21)
$jdkVersions = @(11)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.github.gestalt.config.guice.GestaltModule;
import org.github.gestalt.config.guice.InjectConfig;
import org.github.gestalt.config.micrometer.builder.MicrometerModuleConfigBuilder;
import org.github.gestalt.config.node.factory.MapNodeImportFactory;
import org.github.gestalt.config.processor.config.transform.LoadtimeStringSubstitutionConfigNodeProcessor;
import org.github.gestalt.config.processor.config.transform.RandomTransformer;
import org.github.gestalt.config.processor.config.transform.SystemPropertiesTransformer;
Expand All @@ -53,7 +54,9 @@
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
Expand Down Expand Up @@ -896,65 +899,6 @@ public void integrationTestCamelCase() throws GestaltException {
Assertions.assertEquals("usersTable", connection.getDbPath());
}


@Test
public void testSubstitution() throws GestaltException {
Map<String, String> customMap = new HashMap<>();
customMap.put("place", "world");
customMap.put("weather", "sunny");
customMap.put("message", "hello ${place} it is ${weather} today");

GestaltBuilder builder = new GestaltBuilder();
Gestalt gestalt = builder
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(customMap).build())
.build();

gestalt.loadConfigs();

String message = gestalt.getConfig("message", TypeCapture.of(String.class));

Assertions.assertEquals("hello world it is sunny today", message);
}

@Test
public void testNestedSubstitution() throws GestaltException {
Map<String, String> customMap = new HashMap<>();
customMap.put("variable", "place");
customMap.put("place", "world");
customMap.put("weather", "sunny");
customMap.put("message", "hello ${${variable}} it is ${weather} today");

GestaltBuilder builder = new GestaltBuilder();
Gestalt gestalt = builder
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(customMap).build())
.build();

gestalt.loadConfigs();

String message = gestalt.getConfig("message", TypeCapture.of(String.class));

Assertions.assertEquals("hello world it is sunny today", message);
}

@Test
public void testEscapedSubstitution() throws GestaltException {
Map<String, String> customMap = new HashMap<>();
customMap.put("place", "world");
customMap.put("weather", "sunny");
customMap.put("message", "hello \\${place} it is ${weather} today");

GestaltBuilder builder = new GestaltBuilder();
Gestalt gestalt = builder
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(customMap).build())
.build();

gestalt.loadConfigs();

String message = gestalt.getConfig("message", TypeCapture.of(String.class));

Assertions.assertEquals("hello ${place} it is sunny today", message);
}

@Test
public void testObservations() throws GestaltException {
Map<String, String> configs = new HashMap<>();
Expand Down Expand Up @@ -1155,6 +1099,127 @@ public void encryptedPasswordAndTemporaryNode() throws GestaltException {
"name=LeafNode{value='test2'}}}", gestalt.debugPrint());
}

@Test
public void testImportSubPath() throws GestaltException {

Map<String, String> configs = new HashMap<>();
configs.put("a", "a");
configs.put("b", "b");
configs.put("sub.$include:1", "source=mapNode1");

Map<String, String> configs2 = new HashMap<>();
configs2.put("b", "b changed");
configs2.put("c", "c");

Gestalt gestalt = new GestaltBuilder()
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(configs).build())
.addConfigSourceFactory(new MapNodeImportFactory("mapNode1", configs2))
.build();

gestalt.loadConfigs();

Assertions.assertEquals("a", gestalt.getConfig("a", String.class));
Assertions.assertEquals("b", gestalt.getConfig("b", String.class));
Assertions.assertEquals("c", gestalt.getConfig("sub.c", String.class));
Assertions.assertEquals("b changed", gestalt.getConfig("sub.b", String.class));
}

@Test
public void testImportNested() throws GestaltException {

Map<String, String> configs = new HashMap<>();
configs.put("a", "a");
configs.put("b", "b");
configs.put("$include", "source=mapNode1");

Map<String, String> configs2 = new HashMap<>();
configs2.put("b", "b changed");
configs2.put("c", "c");
configs2.put("$include:1", "source=mapNode2");

Map<String, String> configs3 = new HashMap<>();
configs3.put("c", "c changed");
configs3.put("d", "d");


Gestalt gestalt = new GestaltBuilder()
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(configs).build())
.addConfigSourceFactory(new MapNodeImportFactory("mapNode1", configs2))
.addConfigSourceFactory(new MapNodeImportFactory("mapNode2", configs3))
.build();

gestalt.loadConfigs();

Assertions.assertEquals("a", gestalt.getConfig("a", String.class));
Assertions.assertEquals("b", gestalt.getConfig("b", String.class));
Assertions.assertEquals("c changed", gestalt.getConfig("c", String.class));
Assertions.assertEquals("d", gestalt.getConfig("d", String.class));
}

@Test
public void testImportNode() throws GestaltException {

Map<String, String> configs = new HashMap<>();
configs.put("a", "a");
configs.put("b", "b");
configs.put("path.b", "b changed");
configs.put("path.c", "c");
configs.put("$include:1", "source=node,path=path");


Gestalt gestalt = new GestaltBuilder()
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(configs).build())
.build();

gestalt.loadConfigs();

Assertions.assertEquals("a", gestalt.getConfig("a", String.class));
Assertions.assertEquals("b changed", gestalt.getConfig("b", String.class));
Assertions.assertEquals("c", gestalt.getConfig("c", String.class));
}

@Test
public void testImportNodeClasspath() throws GestaltException {

Map<String, String> configs = new HashMap<>();
configs.put("a", "a");
configs.put("b", "b");
configs.put("$include:-1", "source=classPath,resource=include.properties");

Gestalt gestalt = new GestaltBuilder()
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(configs).build())
.build();

gestalt.loadConfigs();

Assertions.assertEquals("a", gestalt.getConfig("a", String.class));
Assertions.assertEquals("b", gestalt.getConfig("b", String.class));
Assertions.assertEquals("c", gestalt.getConfig("c", String.class));
}

@Test
public void testImportFile() throws GestaltException {

// Load the default property files from resources.
URL fileNode = GestaltConfigTest.class.getClassLoader().getResource("include.properties");
File devFile = new File(fileNode.getFile());

Map<String, String> configs = new HashMap<>();
configs.put("a", "a");
configs.put("b", "b");
configs.put("$include:1", "source=file,file=" + devFile.getAbsolutePath());

Gestalt gestalt = new GestaltBuilder()
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(configs).build())
.build();

gestalt.loadConfigs();

Assertions.assertEquals("a", gestalt.getConfig("a", String.class));
Assertions.assertEquals("b changed", gestalt.getConfig("b", String.class));
Assertions.assertEquals("c", gestalt.getConfig("c", String.class));
}

public enum Role {
LEVEL0, LEVEL1
}
Expand Down
Loading

0 comments on commit 884f254

Please sign in to comment.