From 520bbf1218a5b7b492614acc4ae9b42f4e8f4e70 Mon Sep 17 00:00:00 2001 From: Owais Kazi Date: Thu, 14 Jul 2022 11:45:01 -0700 Subject: [PATCH] Created ObjectMapper object to test the extenions.yml Signed-off-by: Owais Kazi --- .../org/opensearch/sdk/ExtensionSettings.java | 8 ++------ .../org/opensearch/sdk/TestExtensionSettings.java | 15 +++++++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/opensearch/sdk/ExtensionSettings.java b/src/main/java/org/opensearch/sdk/ExtensionSettings.java index 96cb0aaeb..77eee50f8 100644 --- a/src/main/java/org/opensearch/sdk/ExtensionSettings.java +++ b/src/main/java/org/opensearch/sdk/ExtensionSettings.java @@ -19,14 +19,10 @@ public class ExtensionSettings { // Change the location to extension.yml file of the extension public static final String EXTENSION_DESCRIPTOR = "src/test/resources/extension.yml"; - public ExtensionSettings(String extensionname, String hostaddress, String hostport) { - this.extensionname = extensionname; - this.hostaddress = hostaddress; - this.hostport = hostport; + public ExtensionSettings() { + super(); } - public ExtensionSettings() {} - public String getExtensionname() { return extensionname; } diff --git a/src/test/java/org/opensearch/sdk/TestExtensionSettings.java b/src/test/java/org/opensearch/sdk/TestExtensionSettings.java index c37e022b1..978b3ebf0 100644 --- a/src/test/java/org/opensearch/sdk/TestExtensionSettings.java +++ b/src/test/java/org/opensearch/sdk/TestExtensionSettings.java @@ -1,21 +1,28 @@ package org.opensearch.sdk; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.opensearch.test.OpenSearchTestCase; +import java.io.File; +import java.io.IOException; + public class TestExtensionSettings extends OpenSearchTestCase { private ExtensionSettings extensionSettings; @BeforeEach - public void setUp() { - extensionSettings = new ExtensionSettings("test-extension", "127.0.0.1", "1234"); + public void setUp() throws IOException { + File file = new File(ExtensionSettings.EXTENSION_DESCRIPTOR); + ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()); + extensionSettings = objectMapper.readValue(file, ExtensionSettings.class); } @Test public void testExtensionName() { - assertEquals(extensionSettings.getExtensionname(), "test-extension"); + assertEquals(extensionSettings.getExtensionname(), "extension"); } @Test @@ -25,6 +32,6 @@ public void testHostAddress() { @Test public void testHostPort() { - assertEquals(extensionSettings.getHostport(), "1234"); + assertEquals(extensionSettings.getHostport(), "4532"); } }