From fcf5ab8738a4681301130a0b66ee64a7c0af264d Mon Sep 17 00:00:00 2001 From: Joss Armstrong Date: Mon, 18 Feb 2019 12:23:23 +0000 Subject: Test coverage in design-services-provider Add test cases to ArtifactHandlerClient Issue-ID: APPC-1436 Change-Id: I0893526b6f3a532ec422b998bb9cc266850a52a7 Signed-off-by: Joss Armstrong --- .../services/util/ArtifactHandlerClientTest.java | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'appc-inbound/appc-design-services/provider/src/test') diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/services/util/ArtifactHandlerClientTest.java b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/services/util/ArtifactHandlerClientTest.java index b5f219067..a23956f18 100644 --- a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/services/util/ArtifactHandlerClientTest.java +++ b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/services/util/ArtifactHandlerClientTest.java @@ -21,19 +21,65 @@ package org.onap.appc.design.services.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.io.IOException; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.util.Properties; +import javax.net.ssl.KeyManager; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.reflect.Whitebox; +@RunWith(PowerMockRunner.class) +@PrepareForTest({DesignServiceConstants.class}) public class ArtifactHandlerClientTest { @Rule public ExpectedException expectedEx = ExpectedException.none(); + @Before + public void setup() throws NoSuchAlgorithmException, KeyManagementException { + PowerMockito.mockStatic(DesignServiceConstants.class); + } + @Test public void testConstructorException() throws IOException { expectedEx.expect(IOException.class); new ArtifactHandlerClient(); } + + @Test + public void testConstructor() throws IOException { + PowerMockito.when(DesignServiceConstants.getEnvironmentVariable(ArtifactHandlerClient.SDNC_CONFIG_DIR_VAR)) + .thenReturn("src/test/resources"); + ArtifactHandlerClient client = new ArtifactHandlerClient(); + assertTrue(client instanceof ArtifactHandlerClient); + Properties props = Whitebox.getInternalState(client, "props"); + assertTrue(props.containsKey("appc.upload.provider.url")); + } + + @Test + public void testCreateArtifactData() throws IOException { + PowerMockito.when(DesignServiceConstants.getEnvironmentVariable(ArtifactHandlerClient.SDNC_CONFIG_DIR_VAR)) + .thenReturn("src/test/resources"); + ArtifactHandlerClient client = new ArtifactHandlerClient(); + assertEquals("{\"input\": {\"request-information\":{\"request-id\":\"\",\"request-action\":" + + "\"StoreSdcDocumentRequest\",\"source\":\"Design-tool\"},\"document-parameters\":" + + "{\"artifact-version\":\"TEST\",\"artifact-name\":\"TEST\",\"artifact-contents\":" + + "\"TEST\"}}}", client.createArtifactData("{\"" + DesignServiceConstants.ARTIFACT_NAME + + "\":\"TEST\", \"" + DesignServiceConstants.ARTIFACT_VERSOIN + "\":\"TEST\", \"" + + DesignServiceConstants.ARTIFACT_CONTENTS + "\":\"TEST\"}", "")); + } } -- cgit 1.2.3-korg