From a3b8a562f6f1730dd84fd59fe2dd577a07a95edc Mon Sep 17 00:00:00 2001 From: Eduardo Corazon Date: Tue, 10 Oct 2023 17:57:05 -0500 Subject: [PATCH] Full refactor for ConfigV7Test Signed-off-by: Eduardo Corazon --- build.gradle | 3 +- .../securityconf/impl/v7/ConfigV7Test.java | 28 +++++++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index cd9dbf2ec5..400d3ec4bd 100644 --- a/build.gradle +++ b/build.gradle @@ -654,8 +654,7 @@ dependencies { exclude group: 'com.google.guava' } - //test - testImplementation 'org.assertj:assertj-core:3.21.0' + } jar { diff --git a/src/test/java/org/opensearch/security/securityconf/impl/v7/ConfigV7Test.java b/src/test/java/org/opensearch/security/securityconf/impl/v7/ConfigV7Test.java index fa4d79910c..784547a6af 100644 --- a/src/test/java/org/opensearch/security/securityconf/impl/v7/ConfigV7Test.java +++ b/src/test/java/org/opensearch/security/securityconf/impl/v7/ConfigV7Test.java @@ -16,9 +16,13 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import static org.assertj.core.api.Assertions.assertThat; + import org.opensearch.security.DefaultObjectMapper; +import static org.hamcrest.MatcherAssert.assertThat; + +import static org.hamcrest.CoreMatchers.is; + @RunWith(Parameterized.class) public class ConfigV7Test { private final boolean omitDefaults; @@ -28,25 +32,25 @@ public static Iterable omitDefaults() { return ImmutableList.of(Boolean.FALSE, Boolean.TRUE); } - public void assertEquals(ConfigV7.Kibana expected, JsonNode node) { - assertThat(node.get("multitenancy_enabled").asBoolean()).as("Multitenancy Enabled").isEqualTo(expected.multitenancy_enabled); + public void assertKibanaProperties(ConfigV7.Kibana expected, JsonNode node) { + assertThat(node.get("multitenancy_enabled").asBoolean(), is(expected.multitenancy_enabled)); if (expected.server_username == null) { - assertThat(node.get("server_username")).isNull(); + assertThat(node.has("server_username"), is(false)); } else { - assertThat(node.get("server_username").asText()).as("Server Username").isEqualTo(expected.server_username); + assertThat(node.get("server_username").asText(), is(expected.server_username)); } if (expected.index == null) { - assertThat(node.get("index")).isNull(); + assertThat(node.has("index"), is(false)); } else { - assertThat(node.get("index").asText()).as("Index").isEqualTo(expected.index); + assertThat(node.get("index").asText(), is(expected.index)); } if (expected.opendistro_role == null) { - assertThat(node.get("opendistro_role")).isNull(); + assertThat(node.has("opendistro_role"), is(false)); } else { - assertThat(node.get("opendistro_role").asText()).as("OpenDistro Role").isEqualTo(expected.opendistro_role); + assertThat(node.get("opendistro_role").asText(), is(expected.opendistro_role)); } } @@ -61,21 +65,21 @@ public void testDashboards() throws Exception { kibana = new ConfigV7.Kibana(); json = DefaultObjectMapper.writeValueAsString(kibana, omitDefaults); - assertEquals(kibana, DefaultObjectMapper.readTree(json)); + assertKibanaProperties(kibana, DefaultObjectMapper.readTree(json)); kibana.multitenancy_enabled = false; kibana.server_username = null; kibana.opendistro_role = null; kibana.index = null; json = DefaultObjectMapper.writeValueAsString(kibana, omitDefaults); - assertEquals(kibana, DefaultObjectMapper.readTree(json)); + assertKibanaProperties(kibana, DefaultObjectMapper.readTree(json)); kibana.multitenancy_enabled = true; kibana.server_username = "user"; kibana.opendistro_role = "role"; kibana.index = "index"; json = DefaultObjectMapper.writeValueAsString(kibana, omitDefaults); - assertEquals(kibana, DefaultObjectMapper.readTree(json)); + assertKibanaProperties(kibana, DefaultObjectMapper.readTree(json)); } }