diff options
author | kurczews <krzysztof.kurczewski@nokia.com> | 2018-01-19 11:22:47 +0100 |
---|---|---|
committer | Patrick Brady <pb071s@att.com> | 2018-01-19 21:55:03 +0000 |
commit | 18bb0ee6a5865f65be15374813ecb88672fc1c28 (patch) | |
tree | 249c683e5d79d6f0031624490a98c2fffcbcd634 /appc-inbound/appc-artifact-handler/provider/src/test/java | |
parent | 090b660ced8a44b65bc66ea0b2fbfaeaf90f2b5f (diff) |
Refactor ArtifactHandlerNode
* replace user-mock with Mockito mock
* fix typos
Change-Id: Ibc86177c024e5a5e7eec8cf8dd3e49d9a6d1ede4
Issue-ID: APPC-397
Signed-off-by: kurczews <krzysztof.kurczewski@nokia.com>
Diffstat (limited to 'appc-inbound/appc-artifact-handler/provider/src/test/java')
2 files changed, 25 insertions, 82 deletions
diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java index 6a90a7e77..c7f18d777 100644 --- a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java +++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java @@ -24,31 +24,43 @@ package org.onap.appc.artifact.handler.node; -import java.nio.charset.Charset; - import org.apache.commons.io.IOUtils; import org.json.JSONObject; +import org.junit.Before; import org.junit.Ignore; import org.junit.Test; +import org.mockito.Mockito; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.powermock.reflect.Whitebox; -import static org.junit.Assert.assertTrue; - import org.onap.appc.artifact.handler.dbservices.MockDBService; import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants; import org.onap.appc.artifact.handler.utils.ArtifactHandlerProviderUtilTest; - import java.util.Map; import java.util.HashMap; +import java.nio.charset.Charset; + +import static org.junit.Assert.assertTrue; public class ArtifactHandlerNodeTest { + private ArtifactHandlerNode artifactHandlerNode; + + @Before + public void setUp() throws Exception { + artifactHandlerNode = Mockito.spy(ArtifactHandlerNode.class); + Mockito.doReturn(true) + .when(artifactHandlerNode) + .updateStoreArtifacts(Mockito.any(JSONObject.class), Mockito.any(JSONObject.class)); + Mockito.doReturn(true) + .when(artifactHandlerNode) + .storeReferenceData(Mockito.any(JSONObject.class), Mockito.any(JSONObject.class)); + } + @Test public void testProcessArtifact() throws Exception { SvcLogicContext ctx = new SvcLogicContext(); ctx.setAttribute("test", "test"); - MockArtifactHandlerNode ah = new MockArtifactHandlerNode(); - Map<String, String> inParams = new HashMap<String, String>(); + Map<String, String> inParams = new HashMap<>(); JSONObject postData = new JSONObject(); JSONObject input = new JSONObject(); inParams.put("response_prefix", "prefix"); @@ -63,13 +75,12 @@ public class ArtifactHandlerNodeTest { input.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo); postData.put("input", input); inParams.put("postData", postData.toString()); - ah.processArtifact(inParams, ctx); + artifactHandlerNode.processArtifact(inParams, ctx); } @Ignore("Test is taking 60 seconds") @Test(expected = Exception.class) public void testStoreReferenceData() throws Exception { - MockArtifactHandlerNode ah = new MockArtifactHandlerNode(); JSONObject documentInfo = new JSONObject(); String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() .getResourceAsStream("templates/reference_template"), Charset.defaultCharset()); @@ -77,7 +88,7 @@ public class ArtifactHandlerNodeTest { documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "reference_Junit.json"); JSONObject requestInfo = new JSONObject(); requestInfo.put("RequestInfo", "testStoreReferenceData"); - ah.storeReferenceData(requestInfo, documentInfo); + artifactHandlerNode.storeReferenceData(requestInfo, documentInfo); } @Test @@ -107,7 +118,7 @@ public class ArtifactHandlerNodeTest { documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_UUID, "testArtifactUuid"); documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_VERSION, "testArtifactVers"); documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, "testArtifactDesc"); - Whitebox.invokeMethod(ah, "processAndStoreCapablitiesArtifact", dbService, documentInfo, capabilities, + Whitebox.invokeMethod(ah, "processAndStoreCapabilitiesArtifact", dbService, documentInfo, capabilities, "artifactName", "someVnf"); } @@ -140,7 +151,6 @@ public class ArtifactHandlerNodeTest { @Ignore("Test is taking 60 seconds") @Test(expected = Exception.class) public void testUpdateStoreArtifacts() throws Exception { - MockArtifactHandlerNode ah = new MockArtifactHandlerNode(); JSONObject documentInfo = new JSONObject(); String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() .getResourceAsStream("templates/reference_template"), Charset.defaultCharset()); @@ -148,23 +158,21 @@ public class ArtifactHandlerNodeTest { documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "reference_Junit.json"); JSONObject requestInfo = new JSONObject(); requestInfo.put("RequestInfo", "testupdateStoreArtifacts"); - ah.updateStoreArtifacts(requestInfo, documentInfo); + artifactHandlerNode.updateStoreArtifacts(requestInfo, documentInfo); } @Test public void testCleanArtifactInstanceData() throws Exception { - MockArtifactHandlerNode ah = new MockArtifactHandlerNode(); SvcLogicContext ctx = new SvcLogicContext(); - Whitebox.invokeMethod(ah, "cleanArtifactInstanceData", ctx); + Whitebox.invokeMethod(artifactHandlerNode, "cleanArtifactInstanceData", ctx); } @Ignore("Test is taking 60 seconds") @Test(expected = Exception.class) public void testUpdateYangContents() throws Exception { - MockArtifactHandlerNode ah = new MockArtifactHandlerNode(); String artifactId = "1"; String yangContents = "SomeContent"; - Whitebox.invokeMethod(ah, "updateYangContents", artifactId, yangContents); + Whitebox.invokeMethod(artifactHandlerNode, "updateYangContents", artifactId, yangContents); } } diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/MockArtifactHandlerNode.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/MockArtifactHandlerNode.java deleted file mode 100644 index 39706a282..000000000 --- a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/MockArtifactHandlerNode.java +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.artifact.handler.node; - -import org.json.JSONObject; -import org.onap.appc.artifact.handler.dbservices.MockDBService; -import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -public class MockArtifactHandlerNode extends ArtifactHandlerNode { - - @Override - public boolean updateStoreArtifacts(JSONObject request_information, JSONObject document_information) - throws Exception { - if (request_information != null && request_information.get("RequestInfo").equals("testupdateStoreArtifacts")) { - super.updateStoreArtifacts(request_information, document_information); - } - SvcLogicContext context = new SvcLogicContext(); - MockDBService dbservice = MockDBService.initialise(); - int intversion = 0; - context.setAttribute("artifact_name", - document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME)); - String internal_version = dbservice.getInternalVersionNumber(context, - document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME), null); - if (internal_version != null) { - intversion = Integer.parseInt(internal_version); - intversion++; - } - - return true; - - } - - @Override - public boolean storeReferenceData(JSONObject request_information, JSONObject document_information) - throws Exception { - if (request_information != null && request_information.get("RequestInfo").equals("testStoreReferenceData")) { - super.storeReferenceData(request_information, document_information); - } - return true; - } - -} |