Skip to content

Commit

Permalink
Test: add a sample for the nullable annotation support.
Browse files Browse the repository at this point in the history
  • Loading branch information
credmond-git committed Jul 2, 2024
1 parent 7333c5c commit 28762d7
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions gestalt-examples/gestalt-sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ testing {
implementation(libs.hibernate.validator)

implementation(libs.expressly)
implementation(libs.jakarta.annotation)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.github.jopenlibs.vault.VaultException;
import io.github.jopenlibs.vault.response.LogicalResponse;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import jakarta.annotation.Nullable;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;
Expand Down Expand Up @@ -1880,6 +1881,34 @@ public void temporaryNode() throws GestaltException {
Assertions.assertEquals("", gestalt.getConfigOptional("db.password", String.class).get());
}

@Test
public void testNullableAnnotation() throws GestaltException {
Map<String, String> configs = new HashMap<>();
configs.put("db.password", "test");
//configs.put("db.port", "123");
configs.put("db.uri", "my.sql.com");

SimpleMeterRegistry registry = new SimpleMeterRegistry();

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

gestalt.loadConfigs();

var hostAnnotations = gestalt.getConfig("db", HostNullableAnnotations.class);
Assertions.assertEquals("test", hostAnnotations.getPassword());
Assertions.assertNull(hostAnnotations.getPort());
Assertions.assertEquals("my.sql.com", hostAnnotations.getUri());

var hostMethodAnnotations = gestalt.getConfig("db", HostNullableMethodAnnotations.class);
Assertions.assertEquals("test", hostMethodAnnotations.getPassword());
Assertions.assertNull(hostMethodAnnotations.getPort());
Assertions.assertEquals("my.sql.com", hostMethodAnnotations.getUri());

}

public enum Role {
LEVEL0, LEVEL1
}
Expand Down Expand Up @@ -2075,6 +2104,47 @@ public String getPassword() {
}
}

public static class HostNullableAnnotations {
private String password;
private String uri;
@Nullable
private Integer port;

public HostNullableAnnotations() {
}

public String getPassword() {
return password;
}
public String getUri() {
return uri;
}
public Integer getPort() {
return port;
}
}

public static class HostNullableMethodAnnotations {
private String password;

private String uri;
private Integer port;

public HostNullableMethodAnnotations() {
}

public String getPassword() {
return password;
}
public String getUri() {
return uri;
}
@Nullable
public Integer getPort() {
return port;
}
}

public static class DataBase {
public List<Host> hosts;
public int connectionTimeout;
Expand Down

0 comments on commit 28762d7

Please sign in to comment.