diff options
author | Dilip kumar Pampana <dilip.kumar.pampana@ibm.com> | 2018-10-02 09:48:54 -0400 |
---|---|---|
committer | Takamune Cho <takamune.cho@att.com> | 2018-11-28 01:43:41 +0000 |
commit | 3e499b7b1d969159016acc0c77e4f3d06efab94a (patch) | |
tree | f934e03c20507b30ac5779f27229bb06dcc1259d /appc-inbound/appc-design-services/provider/src/test/java | |
parent | 30a82f0fb7e2e702cb528dd98a41a146aba8217d (diff) |
Junits for design services
code coverage for design services in appc-inbound
Issue-ID: APPC-1211
Change-Id: Ie67937b74a83aee5de469687e4ab63685cb5d6aa
Signed-off-by: Dilip kumar Pampana <dilip.kumar.pampana@ibm.com>
Diffstat (limited to 'appc-inbound/appc-design-services/provider/src/test/java')
-rw-r--r-- | appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesignDBServices.java | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesignDBServices.java b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesignDBServices.java index 98414964b..127ca4c2c 100644 --- a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesignDBServices.java +++ b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesignDBServices.java @@ -27,7 +27,9 @@ import java.sql.ResultSet; import java.util.HashMap; import java.util.Map; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -37,12 +39,14 @@ import static org.mockito.Mockito.when; import org.mockito.runners.MockitoJUnitRunner; import org.onap.appc.design.dbervices.DbService; import org.onap.appc.design.dbervices.DesignDBService; +import org.onap.appc.design.dbervices.DesignDBService.ArtifactHandlerFactory; import org.onap.appc.design.services.util.ArtifactHandlerClient; +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(MockitoJUnitRunner.class) -@PrepareForTest(DesignDBService.class) +@RunWith(PowerMockRunner.class) public class TestDesignDBServices { private DesignDBService designDbService; @@ -57,22 +61,39 @@ public class TestDesignDBServices { @Mock private ArtifactHandlerClient artifactHandlerClient; + + private static ArtifactHandlerFactory saveFactory; + + private static ArtifactHandlerFactory factory; + + @BeforeClass + public static void setUpBeforeClass() { + saveFactory = Whitebox.getInternalState(DesignDBService.class, "artifactHandlerFactory"); + } + + @AfterClass + public static void tearDownAfterClass() { + Whitebox.setInternalState(DesignDBService.class, "artifactHandlerFactory", saveFactory); + } + @Before public void setUp() throws Exception { + factory = Mockito.mock(ArtifactHandlerFactory.class); + Whitebox.setInternalState(DesignDBService.class, "artifactHandlerFactory", factory); Map<String, String> outputMessage = new HashMap<>(); designDbService = DesignDBService.initialise(); Whitebox.setInternalState(designDbService, "dbservice", dbservice); - // Whitebox.setInternalState(designDbService, "ac", - // artifactHandlerClient); - Mockito.doReturn(outputMessage).when(artifactHandlerClient).execute(Mockito.anyString(), Mockito.anyString()); + //Whitebox.setInternalState(designDbService, "ac",artifactHandlerClient); + //Mockito.doReturn(outputMessage).when(artifactHandlerClient).execute(Mockito.anyString(), Mockito.anyString()); + when(factory.ahi()).thenReturn(artifactHandlerClient); when(dbservice.getDBData(Mockito.anyString(), Mockito.anyList())).thenReturn(rs); when(rs.next()).thenReturn(true, true, false); Mockito.doReturn(true).when(dbservice).updateDBData(Mockito.anyString(), Mockito.anyList()); - spyDesign = Mockito.spy(designDbService); + spyDesign = PowerMockito.spy(designDbService); } - + @Test public void testSetStatus() throws Exception { String payload = "{\"userID\": \"1234\", \"vnf-type\" : \"DesigTest-VNF\",\"artifact_status\":\"TestArtifactStatus\",\"action_status\":\"TestAction\",\"vnfc-type\":\"TestVnfc\" }"; @@ -108,11 +129,12 @@ public class TestDesignDBServices { assertEquals(true, result.contains("success")); } - @Ignore - @Test(expected = ExceptionInInitializerError.class) + + @Test public void TestUploadArtifact() throws Exception { String payload = " { \"userID\": \"00000\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\": \"TestContents\"} "; - Whitebox.invokeMethod(spyDesign, "uploadArtifact", payload, "1234"); + String result = Whitebox.invokeMethod(spyDesign, "uploadArtifact", payload, "1234"); + assertEquals(true, result.contains("success")); } @Test @@ -177,4 +199,7 @@ public class TestDesignDBServices { String result = Whitebox.invokeMethod(design, "getAppcTimestampUTC",requestId); assertTrue(result.endsWith("Z")); } -}
\ No newline at end of file + + + +} |