diff options
Diffstat (limited to 'asdcApi/provider/src/test/java')
3 files changed, 210 insertions, 0 deletions
diff --git a/asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiSliClientTest.java b/asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiSliClientTest.java new file mode 100644 index 000000000..5e6a9daf7 --- /dev/null +++ b/asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiSliClientTest.java @@ -0,0 +1,59 @@ +package org.onap.ccsdk.sli.northbound.asdcapi; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +import java.util.Properties; + +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService; + +public class AsdcApiSliClientTest { + Properties mockProp; + Properties propReturn; + AsdcApiSliClient testAsdcApiSliClient; + + @Before + public void setup() { + SvcLogicService mockSvcLogic = mock(SvcLogicService.class); + mockProp = new Properties(); + mockProp.setProperty("test-value1", "value1"); + propReturn = new Properties(); + propReturn.setProperty("SvcLogic.status", "Success"); + propReturn.setProperty("Object1", "value1"); + try { + when(mockSvcLogic.hasGraph("TestModule", "TestRPC", "TestVersion", "TestMode")).thenReturn(true); + when(mockSvcLogic.hasGraph("NotExist", "TestRPC", "TestVersion", "TestMode")).thenReturn(false); + when(mockSvcLogic.execute("TestModule", "TestRPC", "TestVersion", "TestMode", mockProp)).thenReturn(propReturn); + } catch (Exception e) { + System.out.println(e); + } + + testAsdcApiSliClient = new AsdcApiSliClient(mockSvcLogic); + } + + @Test + public void testhasGraphGraphExsists() throws SvcLogicException { + assertTrue(testAsdcApiSliClient.hasGraph("TestModule", "TestRPC", "TestVersion", "TestMode")); + } + + @Test + public void testhasGraphnoGraph() throws SvcLogicException { + assertFalse(testAsdcApiSliClient.hasGraph("NotExist", "TestRPC", "TestVersion", "TestMode")); + } + + @Test + public void testExecutewithSvcLogicSuccess() throws SvcLogicException { + Properties result = testAsdcApiSliClient.execute("TestModule", "TestRPC", "TestVersion", "TestMode", mockProp); + assertEquals(result.getProperty("error-code"), "200"); + } + + @Test + public void testExecutewithSvcLogicFailure500() throws SvcLogicException { + propReturn.setProperty("SvcLogic.status", "failure"); + Properties result = testAsdcApiSliClient.execute("TestModule", "TestRPC", "TestVersion", "TestMode", mockProp); + assertEquals(result.getProperty("error-code"), "500"); + } +}
\ No newline at end of file diff --git a/asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiUtilTest.java b/asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiUtilTest.java new file mode 100644 index 000000000..463e5ea0b --- /dev/null +++ b/asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiUtilTest.java @@ -0,0 +1,15 @@ +package org.onap.ccsdk.sli.northbound.asdcapi; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class AsdcApiUtilTest { + + @Test + public void testAsdcApiUtilConstructor() { + AsdcApiUtil asdcApiUtilTest = new AsdcApiUtil(); + assertNotNull(asdcApiUtilTest); + } + +}
\ No newline at end of file diff --git a/asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/TestAsdcApiApi.java b/asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/TestAsdcApiApi.java new file mode 100644 index 000000000..1f266365c --- /dev/null +++ b/asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/TestAsdcApiApi.java @@ -0,0 +1,136 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.northbound.asdcapi; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest; +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.yang.gen.v1.http.xmlns.onap.org.asdc.license.model._1._0.rev160427.vf.license.model.grouping.VfLicenseModelBuilder; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.VfLicenseModelUpdateInputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.VfLicenseModelUpdateOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Properties; + +public class TestAsdcApiApi extends AbstractConcurrentDataBrokerTest { + + private AsdcApiProvider asdcApiProvider; + private static final Logger LOG = LoggerFactory.getLogger(AsdcApiProvider.class); + + @Before + public void setUp() throws Exception { + if (null == asdcApiProvider) { + DataBroker dataBroker = getDataBroker(); + NotificationPublishService mockNotification = mock(NotificationPublishService.class); + RpcProviderRegistry mockRpcRegistry = mock(RpcProviderRegistry.class); + AsdcApiSliClient mockSliClient = mock(AsdcApiSliClient.class); + Properties respProps = new Properties(); + respProps.setProperty("error-code", "200"); + respProps.setProperty("error-message", "Success"); + + when(mockSliClient.hasGraph("ASDC-API", "vf-license-model-update" , null, "sync")).thenReturn(true); + when(mockSliClient.execute("ASDC-API", "vf-license-model-update", null, "sync", respProps)).thenReturn(respProps); + + asdcApiProvider = new AsdcApiProvider(dataBroker, mockNotification, mockRpcRegistry, mockSliClient); + } + } + + //Testcase should return error 503 when No service logic active for ASDC-API. + @Test + public void testVfLicenseModelUpdate() { + + VfLicenseModelUpdateInputBuilder inputBuilder = new VfLicenseModelUpdateInputBuilder(); + + inputBuilder.setArtifactName("abc"); + inputBuilder.setArtifactVersion("1"); + + // TODO: currently initialize SvcLogicServiceClient is failing, need to fix + java.util.concurrent.Future<RpcResult<VfLicenseModelUpdateOutput>> future = asdcApiProvider + .vfLicenseModelUpdate(inputBuilder.build()); + RpcResult<VfLicenseModelUpdateOutput> rpcResult = null; + try { + rpcResult = future.get(); + } catch (Exception e) { + fail("Error : " + e); + } + LOG.info("result: {}", rpcResult); + assertEquals("200", rpcResult.getResult().getAsdcApiResponseCode()); + } + + //Input parameter validation + @Test + public void testVfLicenseModelUpdateInputValidation() { + + VfLicenseModelUpdateInputBuilder inputBuilder = new VfLicenseModelUpdateInputBuilder(); + + inputBuilder.setArtifactName("abc"); + inputBuilder.setArtifactVersion("1"); + + java.util.concurrent.Future<RpcResult<VfLicenseModelUpdateOutput>> future = asdcApiProvider + .vfLicenseModelUpdate(null); + assertNull(future); + } + + @Test + public void testVfLicenseModelUpdateValidation1() { + + VfLicenseModelUpdateInputBuilder inputBuilder = new VfLicenseModelUpdateInputBuilder(); + + inputBuilder.setArtifactName("license1"); + inputBuilder.setArtifactVersion("version1"); + + VfLicenseModelBuilder vfLicenseModelBuilder = new VfLicenseModelBuilder(); + vfLicenseModelBuilder.setVfId("123"); + vfLicenseModelBuilder.setVendorName("acme"); + inputBuilder.setVfLicenseModel(vfLicenseModelBuilder.build()); + + + java.util.concurrent.Future<RpcResult<VfLicenseModelUpdateOutput>> future = asdcApiProvider + .vfLicenseModelUpdate(inputBuilder.build()); + RpcResult<VfLicenseModelUpdateOutput> rpcResult = null; + try { + rpcResult = future.get(); + } catch (Exception e) { + fail("Error : " + e); + } + } + + + + + @Test + public void testAddArtifactVersion() { + asdcApiProvider.addArtifactVersion("artifact1", + "version1"); + } +} |