Add unit tests to increase sonar coverage 39/26339/1
authoraditya <ag282f@att.com>
Thu, 14 Dec 2017 17:51:17 +0000 (11:51 -0600)
committeraditya <ag282f@att.com>
Thu, 14 Dec 2017 17:51:17 +0000 (11:51 -0600)
Add units to common, exception and externalservice packages

Issue-ID: AAI-500

Change-Id: Ie14a8d88c3ec99d362ac49ac30ee92c653409ae8
Signed-off-by: Aditya Gajulapalli <ag282f@att.com>
esr-mgr/src/test/java/org/onap/aai/esr/common/MsbConfigTest.java [new file with mode: 0644]
esr-mgr/src/test/java/org/onap/aai/esr/exception/ExceptionUtilTest.java [new file with mode: 0644]
esr-mgr/src/test/java/org/onap/aai/esr/exception/ExtsysExceptionTest.java [new file with mode: 0644]
esr-mgr/src/test/java/org/onap/aai/esr/externalservice/aai/AaiCommonTest.java [new file with mode: 0644]
esr-mgr/src/test/java/org/onap/aai/esr/externalservice/aai/CloudRegionProxyTest.java [new file with mode: 0644]
esr-mgr/src/test/java/org/onap/aai/esr/externalservice/aai/ExternalSystemProxyTest.java [new file with mode: 0644]
esr-mgr/src/test/java/org/onap/aai/esr/externalservice/cloud/VimManagerProxyTest.java [new file with mode: 0644]
esr-mgr/src/test/java/org/onap/aai/esr/externalservice/msb/MsbHelperTest.java [new file with mode: 0644]

diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/common/MsbConfigTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/common/MsbConfigTest.java
new file mode 100644 (file)
index 0000000..5203ee4
--- /dev/null
@@ -0,0 +1,54 @@
+/**\r
+ * Copyright 2016-2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.onap.aai.esr.common;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.onap.aai.esr.ExtsysAppConfiguration;\r
+\r
+public class MsbConfigTest {\r
+\r
+    @Test\r
+    public void testAllMethods(){\r
+        MsbConfig.setMsbServerAddr("msb-server");\r
+        Assert.assertEquals(MsbConfig.getMsbServerAddr(), "msb-server");\r
+\r
+        MsbConfig.setCloudInfrastructureAddr("cloud-1");\r
+        Assert.assertEquals(MsbConfig.cloudInfrastructureAddr, "cloud-1");\r
+        Assert.assertEquals(MsbConfig.getCloudInfrastructureAddr(), "msb-server/api/aai-cloudInfrastructure/v11");\r
+\r
+        MsbConfig.setExternalSystemAddr("external-addr");\r
+        Assert.assertEquals(MsbConfig.externalSystemAddr, "external-addr");\r
+        Assert.assertEquals(MsbConfig.getExternalSystemAddr(), "msb-server/api/aai-externalSystem/v11");\r
+\r
+        MsbConfig.setMultiCloudAddr("multicloud-address");\r
+        Assert.assertEquals(MsbConfig.multiCloudAddr, "multicloud-address");\r
+        Assert.assertEquals(MsbConfig.getMultiCloudAddr(), "msb-server/api/multicloud/v0");\r
+\r
+        MsbConfig.setMsbDiscoveryIp("discovery://1111");\r
+        Assert.assertEquals(MsbConfig.getMsbDiscoveryIp(), "discovery://1111");\r
+\r
+        MsbConfig.setMsbDiscoveryPort("4040");\r
+        Assert.assertEquals(MsbConfig.getMsbDiscoveryPort(), "4040");\r
+    }\r
+\r
+    @Test\r
+    public void testConfigClass(){\r
+        ExtsysAppConfiguration configur = new ExtsysAppConfiguration();\r
+        Config.setConfigration(configur);\r
+        Assert.assertEquals(Config.getConfigration(), configur);\r
+    }\r
+}\r
diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/exception/ExceptionUtilTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/exception/ExceptionUtilTest.java
new file mode 100644 (file)
index 0000000..38f8fa2
--- /dev/null
@@ -0,0 +1,32 @@
+/**\r
+ * Copyright 2016-2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.onap.aai.esr.exception;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+\r
+import javax.ws.rs.WebApplicationException;\r
+\r
+public class ExceptionUtilTest {\r
+\r
+    @Test\r
+    public void testBuildExceptionResponse(){\r
+        WebApplicationException exp = ExceptionUtil.buildExceptionResponse("Exception from JUnit");\r
+        Assert.assertNotNull(exp);\r
+        Assert.assertNotNull(exp.getResponse());\r
+        Assert.assertTrue(exp.getMessage().contains("498"));\r
+    }\r
+}\r
diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/exception/ExtsysExceptionTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/exception/ExtsysExceptionTest.java
new file mode 100644 (file)
index 0000000..e448f50
--- /dev/null
@@ -0,0 +1,38 @@
+/**\r
+ * Copyright 2016-2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.onap.aai.esr.exception;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+\r
+public class ExtsysExceptionTest {\r
+\r
+    @Test\r
+    public void testAllMethods(){\r
+        ExtsysException esExp = new ExtsysException();\r
+        esExp.setErrorCode("498");\r
+        Assert.assertEquals(esExp.getErrorCode(), "498");\r
+\r
+        esExp.setErrorMsg("Exception from JUnit");\r
+        Assert.assertEquals(esExp.getErrorMsg(), "Exception from JUnit");\r
+\r
+        ExtsysException oneArgExp = new ExtsysException("Exception from JUnit");\r
+        Assert.assertEquals(oneArgExp.getMessage(), "Exception from JUnit");\r
+\r
+        ExtsysException twoArgExp = new ExtsysException("Exception from JUnit", new ExtsysException());\r
+        Assert.assertNotNull(twoArgExp);\r
+    }\r
+}\r
diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/externalservice/aai/AaiCommonTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/externalservice/aai/AaiCommonTest.java
new file mode 100644 (file)
index 0000000..1940c79
--- /dev/null
@@ -0,0 +1,29 @@
+/**\r
+ * Copyright 2016-2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.onap.aai.esr.externalservice.aai;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+\r
+public class AaiCommonTest {\r
+\r
+    @Test\r
+    public void testGetAuthenticationCredentials(){\r
+        String cred = AaiCommon.getAuthenticationCredentials();\r
+        Assert.assertNotNull(cred);\r
+        Assert.assertTrue(cred.contains("Basic"));\r
+    }\r
+}\r
diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/externalservice/aai/CloudRegionProxyTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/externalservice/aai/CloudRegionProxyTest.java
new file mode 100644 (file)
index 0000000..22c9524
--- /dev/null
@@ -0,0 +1,54 @@
+/**\r
+ * Copyright 2016-2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.onap.aai.esr.externalservice.aai;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.onap.aai.esr.common.MsbConfig;\r
+import org.onap.aai.esr.entity.aai.CloudRegionDetail;\r
+import org.onap.aai.esr.exception.ExtsysException;\r
+\r
+public class CloudRegionProxyTest {\r
+\r
+    CloudRegionProxy proxy;\r
+\r
+    @Before\r
+    public void init(){\r
+        MsbConfig.setMsbServerAddr("http://msb-server");\r
+        proxy = new CloudRegionProxy();\r
+    }\r
+\r
+    @Test(expected = ExtsysException.class)\r
+    public void testRegisterVim() throws ExtsysException {\r
+        CloudRegionDetail cloudRegion = new CloudRegionDetail();\r
+        proxy.registerVim("owner-1", "region-1", cloudRegion);\r
+    }\r
+\r
+    @Test(expected = ExtsysException.class)\r
+    public void testQueryVimDetail() throws ExtsysException {\r
+        proxy.queryVimDetail("owner-1", "region-1");\r
+    }\r
+\r
+    @Test(expected = ExtsysException.class)\r
+    public void testQueryVimList() throws ExtsysException{\r
+        proxy.qureyVimList();\r
+    }\r
+\r
+    @Test(expected = ExtsysException.class)\r
+    public void testDeleteVim() throws ExtsysException{\r
+        proxy.deleteVim("owner-1", "region-1", "version-1");\r
+    }\r
+}\r
diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/externalservice/aai/ExternalSystemProxyTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/externalservice/aai/ExternalSystemProxyTest.java
new file mode 100644 (file)
index 0000000..8f7cc92
--- /dev/null
@@ -0,0 +1,98 @@
+/**\r
+ * Copyright 2016-2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.onap.aai.esr.externalservice.aai;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.onap.aai.esr.common.MsbConfig;\r
+import org.onap.aai.esr.entity.aai.EsrEmsDetail;\r
+import org.onap.aai.esr.entity.aai.EsrThirdpartySdncDetail;\r
+import org.onap.aai.esr.entity.aai.EsrVnfmDetail;\r
+import org.onap.aai.esr.exception.ExtsysException;\r
+\r
+public class ExternalSystemProxyTest {\r
+\r
+    ExternalSystemProxy externalSystemProxy;\r
+\r
+    @Before\r
+    public void init() {\r
+        MsbConfig.setMsbServerAddr("http://msb-server");\r
+        externalSystemProxy = new ExternalSystemProxy();\r
+    }\r
+\r
+    @Test(expected = ExtsysException.class)\r
+    public void testRegisterVnfm() throws ExtsysException{\r
+        EsrVnfmDetail detail = new EsrVnfmDetail();\r
+        ExternalSystemProxy.registerVnfm("vnfm-1", detail);\r
+    }\r
+\r
+    @Test(expected = ExtsysException.class)\r
+    public void testQueryVnfmDetail() throws ExtsysException{\r
+        ExternalSystemProxy.queryVnfmDetail("vnfm-1");\r
+    }\r
+\r
+    @Test(expected = ExtsysException.class)\r
+    public void testQueryVnfmList() throws ExtsysException{\r
+        ExternalSystemProxy.queryVnfmList();\r
+    }\r
+\r
+    @Test(expected = ExtsysException.class)\r
+    public void testDeleteVnfm() throws ExtsysException{\r
+        ExternalSystemProxy.deleteVnfm("vnfm-1", "version-1");\r
+    }\r
+\r
+    @Test(expected = ExtsysException.class)\r
+    public void testRegisterSdnc() throws ExtsysException{\r
+        EsrThirdpartySdncDetail detail = new EsrThirdpartySdncDetail();\r
+        ExternalSystemProxy.registerSdnc("sdnc-1", detail);\r
+    }\r
+\r
+    @Test(expected = ExtsysException.class)\r
+    public void testQueryThirdpartySdncDetail() throws ExtsysException{\r
+        ExternalSystemProxy.queryThirdpartySdncDetail("sdnc-1");\r
+    }\r
+\r
+    @Test(expected = ExtsysException.class)\r
+    public void testQuerySdncList() throws ExtsysException{\r
+        ExternalSystemProxy.querySdncList();\r
+    }\r
+\r
+    @Test(expected = ExtsysException.class)\r
+    public void testDeleteThirdpartySdnc() throws ExtsysException{\r
+        ExternalSystemProxy.deleteThirdpartySdnc("sdnc-1", "version-1");\r
+    }\r
+\r
+    @Test(expected = ExtsysException.class)\r
+    public void testRegisterEms() throws ExtsysException{\r
+        EsrEmsDetail detail = new EsrEmsDetail();\r
+        ExternalSystemProxy.registerEms("ems-1",detail);\r
+    }\r
+\r
+    @Test(expected = ExtsysException.class)\r
+    public void testQueryEmsDetail() throws ExtsysException{\r
+        ExternalSystemProxy.queryEmsDetail("ems-1");\r
+    }\r
+\r
+    @Test(expected = ExtsysException.class)\r
+    public void testQueryEmsList() throws ExtsysException{\r
+        ExternalSystemProxy.queryEmsList();\r
+    }\r
+\r
+    @Test(expected = ExtsysException.class)\r
+    public void testDeleteEms() throws ExtsysException{\r
+        ExternalSystemProxy.deleteEms("ems-1", "version-1");\r
+    }\r
+}\r
diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/externalservice/cloud/VimManagerProxyTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/externalservice/cloud/VimManagerProxyTest.java
new file mode 100644 (file)
index 0000000..5637783
--- /dev/null
@@ -0,0 +1,41 @@
+/**\r
+ * Copyright 2016-2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.onap.aai.esr.externalservice.cloud;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.onap.aai.esr.common.MsbConfig;\r
+import org.onap.aai.esr.exception.ExtsysException;\r
+\r
+public class VimManagerProxyTest {\r
+\r
+    VimManagerProxy proxy;\r
+\r
+    @Before\r
+    public void init() {\r
+        MsbConfig.setMsbServerAddr("http://msb-server");\r
+        proxy = new VimManagerProxy();\r
+    }\r
+\r
+    @Test(expected = ExtsysException.class)\r
+    public void testUpdateVim() throws ExtsysException{\r
+        Tenant tenant = new Tenant();\r
+        tenant.setDefaultTenant("defaultTenant");\r
+        Assert.assertEquals(tenant.getDefaultTenant(), "defaultTenant");\r
+        VimManagerProxy.updateVim("owner-1", "region-1", tenant);\r
+    }\r
+}\r
diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/externalservice/msb/MsbHelperTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/externalservice/msb/MsbHelperTest.java
new file mode 100644 (file)
index 0000000..28a22c5
--- /dev/null
@@ -0,0 +1,51 @@
+/**\r
+ * Copyright 2016-2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.onap.aai.esr.externalservice.msb;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.mockito.Mock;\r
+import org.mockito.Mockito;\r
+import org.mockito.MockitoAnnotations;\r
+import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;\r
+import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;\r
+import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;\r
+\r
+public class MsbHelperTest {\r
+\r
+    MsbHelper helper;\r
+\r
+    @Mock\r
+    MSBServiceClient client;\r
+\r
+    @Mock\r
+    MicroServiceFullInfo serviceInfo;\r
+\r
+    @Before\r
+    public void init(){\r
+        MockitoAnnotations.initMocks(this);\r
+        helper = new MsbHelper(client);\r
+    }\r
+\r
+    @Test\r
+    public void testRegisterMsb() throws Exception {\r
+        Mockito.when(client.registerMicroServiceInfo(Mockito.any(MicroServiceInfo.class),\r
+                Mockito.anyBoolean())).thenReturn(serviceInfo);\r
+        helper.registerMsb();\r
+        Mockito.verify(client, Mockito.times(1)).\r
+                registerMicroServiceInfo(Mockito.any(MicroServiceInfo.class), Mockito.anyBoolean());\r
+    }\r
+}\r