aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2019-03-05 17:12:41 +0000
committerTakamune Cho <takamune.cho@att.com>2019-03-06 15:28:41 +0000
commit95e087ce46412a680f31ae421482e0b35653f899 (patch)
tree2b044f77b9b4b42e33d7fef5585f153b1d51dcd8
parent6a8f90bef17488d91519b1bb8bb102dbd4707c80 (diff)
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 <joss.armstrong@ericsson.com>
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java49
1 files changed, 20 insertions, 29 deletions
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());
}
}