From 95e087ce46412a680f31ae421482e0b35653f899 Mon Sep 17 00:00:00 2001 From: Joss Armstrong Date: Tue, 5 Mar 2019 17:12:41 +0000 Subject: Test coverage in ArtifactHandlerProvider Increase coverage from 51% to 96% Fix assertions and Sonar major branch coverage problem Issue-ID: APPC-1335 Change-Id: I1edb662db199dda46972fdf37820aa1de1ad46fc Signed-off-by: Joss Armstrong --- .../utils/ArtifactHandlerProviderUtilTest.java | 49 +++++++++------------- 1 file changed, 20 insertions(+), 29 deletions(-) (limited to 'appc-inbound/appc-artifact-handler/provider') diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java index 552d81104..cf27dce63 100644 --- a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java +++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java @@ -25,6 +25,7 @@ package org.onap.appc.artifact.handler.utils; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.IOException; @@ -36,9 +37,10 @@ import org.junit.Ignore; import org.mockito.Mockito; import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.UploadartifactInput; import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.UploadartifactInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.UploadartifactOutput; import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.document.parameters.DocumentParameters; +import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.document.parameters.DocumentParametersBuilder; import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.request.information.RequestInformation; +import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.request.information.RequestInformationBuilder; import org.powermock.reflect.Whitebox; public class ArtifactHandlerProviderUtilTest { @@ -65,29 +67,20 @@ public class ArtifactHandlerProviderUtilTest { obj.put("artifact-version", "0.01"); obj.put("artifact-contents", artifact_conetent); ArtifactHandlerProviderUtil ahprovider = new ArtifactHandlerProviderUtil(); - String requestInfo = ahprovider.createDummyRequestData(); + ahprovider.createDummyRequestData(); } @Test public void testEscapeSql() throws Exception { String testStr = "Test String is 'test'"; ArtifactHandlerProviderUtil ahprovider = new ArtifactHandlerProviderUtil(); - ahprovider.escapeSql(testStr); - assertTrue(true); - } - - @Test - public void testGetRandom() throws Exception { - ArtifactHandlerProviderUtil ahprovider = new ArtifactHandlerProviderUtil(); - Whitebox.invokeMethod(ahprovider, "getRandom"); - assertTrue(true); + assertEquals("Test String is ''test''", ahprovider.escapeSql(testStr)); } @Test public void testEscapeUtils() throws Exception { String str = "The Test string is 'test'"; - EscapeUtils.escapeSql(str); - assertTrue(true); + assertEquals("The Test string is ''test''", EscapeUtils.escapeSql(str)); } @Test @@ -116,22 +109,20 @@ public class ArtifactHandlerProviderUtilTest { } @Test - public void testRequestData() throws IOException { - String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() - .getResourceAsStream("templates/reference_template.json"), Charset.defaultCharset()); - ArtifactHandlerProviderUtil ahprovider = Mockito.spy(new ArtifactHandlerProviderUtil()); - UploadartifactInputBuilder builder = new UploadartifactInputBuilder(); - DocumentParameters mockDocumentParameters = Mockito.mock(DocumentParameters.class); - Mockito.doReturn(artifactContent).when(mockDocumentParameters).getArtifactContents(); - Mockito.doReturn("ARTIFACT NAME").when(mockDocumentParameters).getArtifactName(); - builder.setDocumentParameters(mockDocumentParameters); - RequestInformation mockRequestInformation = Mockito.mock(RequestInformation.class); - Mockito.doReturn("REQUEST ID").when(mockRequestInformation).getRequestId(); - Mockito.doReturn(SdcArtifactHandlerConstants.DESIGN_TOOL).when(mockRequestInformation).getSource(); - builder.setRequestInformation(mockRequestInformation); - UploadartifactInput uploadArtifactInput = builder.build(); - Whitebox.setInternalState(ahprovider, "templateData", uploadArtifactInput); - assertTrue(ahprovider.createDummyRequestData().startsWith("{\"input\": {\"document-parameters\":{\"service-uuid\":\"TLSUUIDREQUEST ID\"")); + public void testCreateRequestData() throws IOException { + DocumentParameters documentParameters = new DocumentParametersBuilder().setResourceUuid("UUID") + .setDistributionId("DistributionID").setServiceName("SERVICE_NAME").setArtifactName("ARTIFACT_NAME") + .setArtifactType("ARTIFACT_TYPE").setArtifactUuid("ARTIFACT_UUID").build(); + RequestInformation requestInformation = new RequestInformationBuilder().setRequestId("REQUEST_ID") + .setSource("SOURCE").build(); + UploadartifactInput artifactInput = new UploadartifactInputBuilder().setDocumentParameters(documentParameters) + .setRequestInformation(requestInformation).build(); + ArtifactHandlerProviderUtil ahProvider = Mockito.spy(new ArtifactHandlerProviderUtil(artifactInput)); + assertEquals("{\"input\": {\"document-parameters\":{\"service-name\":\"SERVICE_NAME\",\"service-uuid\":\"UUID\"," + + "\"artifact-uuid\":\"ARTIFACT_UUID\",\"artifact-name\":\"ARTIFACT_NAME\",\"artifact-type\":\"ARTIFACT_TYPE\"," + + "\"resource-uuid\":\"UUID\",\"distribution-id\":\"DistributionID\"},\"request-information\":{\"request-action\"" + + ":\"StoreSdcDocumentRequest\",\"source\":\"SOURCE\",\"request-id\":\"REQUEST_ID\"}}}", + ahProvider.createRequestData()); } } -- cgit 1.2.3-korg