From 05a7673489d86402d0e6c3225414158f2035410c Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sun, 1 Oct 2023 07:13:35 +0100 Subject: [PATCH] test: update test in the microprofile settings Signed-off-by: Otavio Santana --- .../config/MicroProfileSettingsTest.java | 117 +++++------------- 1 file changed, 33 insertions(+), 84 deletions(-) diff --git a/jnosql-mapping/jnosql-mapping-core/src/test/java/org/eclipse/jnosql/mapping/config/MicroProfileSettingsTest.java b/jnosql-mapping/jnosql-mapping-core/src/test/java/org/eclipse/jnosql/mapping/config/MicroProfileSettingsTest.java index 21a36be16..cacb14418 100644 --- a/jnosql-mapping/jnosql-mapping-core/src/test/java/org/eclipse/jnosql/mapping/config/MicroProfileSettingsTest.java +++ b/jnosql-mapping/jnosql-mapping-core/src/test/java/org/eclipse/jnosql/mapping/config/MicroProfileSettingsTest.java @@ -15,7 +15,9 @@ package org.eclipse.jnosql.mapping.config; import org.eclipse.jnosql.communication.Settings; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -33,18 +35,28 @@ import static org.junit.jupiter.api.Assertions.*; class MicroProfileSettingsTest { - @BeforeEach - public void beforeEach() { - System.clearProperty("jnosql.jnosql.key"); - System.clearProperty("jnosql.jnosql.host"); - System.clearProperty("jnosql.host.1"); - System.clearProperty("jnosql.host.2"); - System.clearProperty("jnosql.host.3"); - System.clearProperty("jnosql.server"); - System.clearProperty("jnosql.server.1"); - System.clearProperty("jnosql.server.2"); + @AfterAll + public static void afterAll() { + + } + + @BeforeAll + public static void beforeAll() { + System.setProperty("jnosql.jnosql.key", "value"); + System.setProperty("jnosql.jnosql.host", "host"); + System.setProperty("key.jnosql", "value"); + System.setProperty("jnosql.key", "value"); + System.setProperty("jnosql.key-number", "12"); + System.setProperty("jnosql.host", "host"); + System.setProperty("jnosql.host.1", "host-1"); + System.setProperty("jnosql.host.2", "host-2"); + System.setProperty("jnosql.host.3", "host-3"); + System.setProperty("jnosql.server", "server"); + System.setProperty("jnosql.server.1", "server-1"); + System.setProperty("jnosql.server.2", "server-2"); } + @Test public void shouldReturnNPEWhenInstanceIsNull() { assertThrows(NullPointerException.class, () -> Settings.of((Map) null)); @@ -65,7 +77,6 @@ public void shouldCreateFromMap() { @Test public void shouldContainsKeys() { - setProperty(singletonMap("jnosql.key", "value")); Settings settings = MicroProfileSettings.INSTANCE; assertTrue(settings.containsKey("jnosql.key")); assertFalse(settings.containsKey("key2")); @@ -74,7 +85,6 @@ public void shouldContainsKeys() { @Test public void shouldGetKeys() { - setProperty(singletonMap("key.jnosql", "value")); Settings settings = MicroProfileSettings.INSTANCE; assertThat(settings.keySet()).contains("jnosql.key"); } @@ -95,25 +105,22 @@ public void shouldIsEmpty() { @Test public void shouldGet() { - setProperty(singletonMap("jnosql.key", "12")); Settings settings = MicroProfileSettings.INSTANCE; - Optional value = settings.get("jnosql.key"); + Optional value = settings.get("jnosql.key-number"); Assertions.assertNotNull(value); Assertions.assertEquals("12", value.get()); } @Test public void shouldGetSupplier() { - setProperty(singletonMap("jnosql.key", "12")); Settings settings = MicroProfileSettings.INSTANCE; - Optional value = settings.get(() -> "jnosql.key"); + Optional value = settings.get(() -> "jnosql.key-number"); Assertions.assertNotNull(value); Assertions.assertEquals("12", value.get()); } @Test public void shouldNPEGet() { - setProperty(singletonMap("jnosql.key", "12")); Settings settings = MicroProfileSettings.INSTANCE; Assertions.assertThrows(NullPointerException.class, () -> settings.get((String) null)); Assertions.assertThrows(NullPointerException.class, () -> settings.get((Supplier) null)); @@ -121,25 +128,22 @@ public void shouldNPEGet() { @Test public void shouldGetIterable() { - setProperty(singletonMap("jnosql.key", "12")); Settings settings = MicroProfileSettings.INSTANCE; - Optional value = settings.get(Collections.singleton("jnosql.key")); + Optional value = settings.get(Collections.singleton("jnosql.key-number")); Assertions.assertNotNull(value); Assertions.assertEquals("12", value.get()); } @Test public void shouldGetIterableSupplier() { - setProperty(singletonMap("jnosql.key", "12")); Settings settings = MicroProfileSettings.INSTANCE; - Optional value = settings.getSupplier(Collections.singleton(() -> "jnosql.key")); + Optional value = settings.getSupplier(Collections.singleton(() -> "jnosql.key-number")); Assertions.assertNotNull(value); Assertions.assertEquals("12", value.get()); } @Test public void shouldNPEGetIterable() { - setProperty(singletonMap("jnosql.key", "12")); Settings settings = MicroProfileSettings.INSTANCE; Assertions.assertThrows(NullPointerException.class, () -> settings.get((Iterable) null)); Assertions.assertThrows(NullPointerException.class, () -> settings.getSupplier(null)); @@ -147,49 +151,39 @@ public void shouldNPEGetIterable() { @Test public void shouldGetValueClass() { - setProperty(singletonMap("jnosql.key", "12")); Settings settings = MicroProfileSettings.INSTANCE; - Integer value = settings.get("jnosql.key", Integer.class).get(); + Integer value = settings.get("jnosql.key-number", Integer.class).get(); assertEquals(Integer.valueOf(12), value); assertFalse(settings.get("jnosql.key2", Integer.class).isPresent()); } @Test public void shouldGetValueClassSupplier() { - setProperty(singletonMap("jnosql.key", "12")); Settings settings = MicroProfileSettings.INSTANCE; - Integer value = settings.get(() -> "jnosql.key", Integer.class).get(); + Integer value = settings.get(() -> "jnosql.key-number", Integer.class).get(); assertEquals(Integer.valueOf(12), value); assertFalse(settings.get(() -> "key2", Integer.class).isPresent()); } @Test public void shouldGetOrDefault() { - setProperty(singletonMap("jnosql.key", "12")); Settings settings = MicroProfileSettings.INSTANCE; - assertEquals("12", settings.getOrDefault("jnosql.key", "13")); + assertEquals("12", settings.getOrDefault("jnosql.key-number", "13")); assertEquals("13", settings.getOrDefault("key-1", "13")); } @Test public void shouldGetOrDefaultSupplier() { - setProperty(singletonMap("jnosql.key", "12")); Settings settings = MicroProfileSettings.INSTANCE; - assertEquals("12", settings.getOrDefault(() -> "jnosql.key", "13")); + assertEquals("12", settings.getOrDefault(() -> "jnosql.key-number", "13")); assertEquals("13", settings.getOrDefault(() -> "key-1", "13")); } @Test public void shouldReturnErrorWhenPrefixIsNull() { - Map params = Map.of( - "jnosql.host", "host", - "jnosql.host.1", "host-1", - "jnosql.host.2", "host-2", - "jnosql.host.3", "host-3"); - setProperty(params); Settings settings = MicroProfileSettings.INSTANCE; assertThrows(NullPointerException.class, () -> settings.prefix((String) null)); @@ -197,12 +191,6 @@ public void shouldReturnErrorWhenPrefixIsNull() { @Test public void shouldFindPrefix() { - Map params = Map.of( - "jnosql.host", "host", - "jnosql.host.1", "host-1", - "jnosql.host.2", "host-2", - "jnosql.host.3", "host-3"); - setProperty(params); Settings settings = MicroProfileSettings.INSTANCE; List hosts = settings.prefix("jnosql.host"); @@ -213,12 +201,6 @@ public void shouldFindPrefix() { @Test public void shouldFindPrefixSupplier() { - Map params = Map.of( - "jnosql.host", "host", - "jnosql.host.1", "host-1", - "jnosql.host.2", "host-2", - "jnosql.host.3", "host-3"); - setProperty(params); Settings settings = MicroProfileSettings.INSTANCE; List hosts = settings.prefix(() -> "jnosql.host"); @@ -229,12 +211,6 @@ public void shouldFindPrefixSupplier() { @Test public void shouldFindPrefixWithOrder() { - Map params = Map.of( - "jnosql.host", "host", - "jnosql.host.1", "host-1", - "jnosql.host.2", "host-2", - "jnosql.host.3", "host-3"); - setProperty(params); Settings settings = MicroProfileSettings.INSTANCE; List hosts = settings.prefix("jnosql.host"); assertThat(hosts).hasSize(4).contains("host", "host-1", "host-2", "host-3"); @@ -243,12 +219,6 @@ public void shouldFindPrefixWithOrder() { @Test public void shouldReturnErrorWhenPrefixesIsNull() { - Map params = Map.of( - "jnosql.host", "host", - "jnosql.host.1", "host-1", - "jnosql.host.2", "host-2", - "jnosql.host.3", "host-3"); - setProperty(params); Settings settings = MicroProfileSettings.INSTANCE; assertThrows(NullPointerException.class, () -> settings.prefix((Collection) null)); @@ -257,50 +227,29 @@ public void shouldReturnErrorWhenPrefixesIsNull() { @Test public void shouldFindPrefixes() { - Map params = Map.of( - "jnosql.host", "host", - "jnosql.host.1", "host-1", - "jnosql.server", "server", - "jnosql.server.1", "server-1"); - setProperty(params); Settings settings = MicroProfileSettings.INSTANCE; List hosts = settings.prefix(Arrays.asList("jnosql.host", "jnosql.server")); - assertThat(hosts).hasSize(4).contains("host", "host-1", "server", "server-1"); + assertThat(hosts).hasSize(7).contains("host", "host-1", "server", "server-1"); } @Test public void shouldFindPrefixesSupplier() { - Map params = Map.of( - "jnosql.host", "host", - "jnosql.host.1", "host-1", - "jnosql.server", "server", - "jnosql.server.1", "server-1"); - setProperty(params); Settings settings = MicroProfileSettings.INSTANCE; List hosts = settings.prefixSupplier(Arrays.asList(() -> "jnosql.host", () -> "jnosql.server")); - assertThat(hosts).hasSize(4).contains("host", "host-1", "server", "server-1"); + assertThat(hosts).hasSize(7).contains("host", "host-1", "server", "server-1"); } @Test public void shouldFindPrefixesSort() { - Map params = Map.of( - "jnosql.host", "host", - "jnosql.host.1", "host-1", - "jnosql.server", "server", - "jnosql.server.1", "server-1"); - setProperty(params); Settings settings = MicroProfileSettings.INSTANCE; List hosts = settings.prefix(Arrays.asList("jnosql.host", "jnosql.server")); - assertThat(hosts).hasSize(4).contains("host", "host-1", "server", "server-1"); + assertThat(hosts).hasSize(7).contains("host", "host-1", "server", "server-1"); } - private void setProperty(Map params) { - params.forEach((k, v) -> System.setProperty(k, v.toString())); - } } \ No newline at end of file