Test coverage in ArtifactHandlerProvider 25/79725/3
authorJoss Armstrong <joss.armstrong@ericsson.com>
Tue, 5 Mar 2019 17:12:41 +0000 (17:12 +0000)
committerTakamune Cho <takamune.cho@att.com>
Wed, 6 Mar 2019 15:28:41 +0000 (15:28 +0000)
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 <joss.armstrong@ericsson.com>
appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java

index 552d811..cf27dce 100644 (file)
@@ -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());
     }
 }