summaryrefslogtreecommitdiffstats
path: root/esr-mgr/src/test
diff options
context:
space:
mode:
authoraditya <ag282f@att.com>2017-12-14 11:51:17 -0600
committeraditya <ag282f@att.com>2017-12-14 11:51:17 -0600
commit6362b35e771e397cb9b49fb73a003cad38a5e0cb (patch)
tree061852c8fc10009ed020a8e4755d54488daa5949 /esr-mgr/src/test
parent47c1d039207d81c0edd5768ac9a40a525ad796d4 (diff)
Add unit tests to increase sonar coverage
Add units to common, exception and externalservice packages Issue-ID: AAI-500 Change-Id: Ie14a8d88c3ec99d362ac49ac30ee92c653409ae8 Signed-off-by: Aditya Gajulapalli <ag282f@att.com>
Diffstat (limited to 'esr-mgr/src/test')
-rw-r--r--esr-mgr/src/test/java/org/onap/aai/esr/common/MsbConfigTest.java54
-rw-r--r--esr-mgr/src/test/java/org/onap/aai/esr/exception/ExceptionUtilTest.java32
-rw-r--r--esr-mgr/src/test/java/org/onap/aai/esr/exception/ExtsysExceptionTest.java38
-rw-r--r--esr-mgr/src/test/java/org/onap/aai/esr/externalservice/aai/AaiCommonTest.java29
-rw-r--r--esr-mgr/src/test/java/org/onap/aai/esr/externalservice/aai/CloudRegionProxyTest.java54
-rw-r--r--esr-mgr/src/test/java/org/onap/aai/esr/externalservice/aai/ExternalSystemProxyTest.java98
-rw-r--r--esr-mgr/src/test/java/org/onap/aai/esr/externalservice/cloud/VimManagerProxyTest.java41
-rw-r--r--esr-mgr/src/test/java/org/onap/aai/esr/externalservice/msb/MsbHelperTest.java51
8 files changed, 397 insertions, 0 deletions
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
index 0000000..5203ee4
--- /dev/null
+++ b/esr-mgr/src/test/java/org/onap/aai/esr/common/MsbConfigTest.java
@@ -0,0 +1,54 @@
+/**
+ * Copyright 2016-2017 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.aai.esr.common;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.aai.esr.ExtsysAppConfiguration;
+
+public class MsbConfigTest {
+
+ @Test
+ public void testAllMethods(){
+ MsbConfig.setMsbServerAddr("msb-server");
+ Assert.assertEquals(MsbConfig.getMsbServerAddr(), "msb-server");
+
+ MsbConfig.setCloudInfrastructureAddr("cloud-1");
+ Assert.assertEquals(MsbConfig.cloudInfrastructureAddr, "cloud-1");
+ Assert.assertEquals(MsbConfig.getCloudInfrastructureAddr(), "msb-server/api/aai-cloudInfrastructure/v11");
+
+ MsbConfig.setExternalSystemAddr("external-addr");
+ Assert.assertEquals(MsbConfig.externalSystemAddr, "external-addr");
+ Assert.assertEquals(MsbConfig.getExternalSystemAddr(), "msb-server/api/aai-externalSystem/v11");
+
+ MsbConfig.setMultiCloudAddr("multicloud-address");
+ Assert.assertEquals(MsbConfig.multiCloudAddr, "multicloud-address");
+ Assert.assertEquals(MsbConfig.getMultiCloudAddr(), "msb-server/api/multicloud/v0");
+
+ MsbConfig.setMsbDiscoveryIp("discovery://1111");
+ Assert.assertEquals(MsbConfig.getMsbDiscoveryIp(), "discovery://1111");
+
+ MsbConfig.setMsbDiscoveryPort("4040");
+ Assert.assertEquals(MsbConfig.getMsbDiscoveryPort(), "4040");
+ }
+
+ @Test
+ public void testConfigClass(){
+ ExtsysAppConfiguration configur = new ExtsysAppConfiguration();
+ Config.setConfigration(configur);
+ Assert.assertEquals(Config.getConfigration(), configur);
+ }
+}
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
index 0000000..38f8fa2
--- /dev/null
+++ b/esr-mgr/src/test/java/org/onap/aai/esr/exception/ExceptionUtilTest.java
@@ -0,0 +1,32 @@
+/**
+ * Copyright 2016-2017 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.aai.esr.exception;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.ws.rs.WebApplicationException;
+
+public class ExceptionUtilTest {
+
+ @Test
+ public void testBuildExceptionResponse(){
+ WebApplicationException exp = ExceptionUtil.buildExceptionResponse("Exception from JUnit");
+ Assert.assertNotNull(exp);
+ Assert.assertNotNull(exp.getResponse());
+ Assert.assertTrue(exp.getMessage().contains("498"));
+ }
+}
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
index 0000000..e448f50
--- /dev/null
+++ b/esr-mgr/src/test/java/org/onap/aai/esr/exception/ExtsysExceptionTest.java
@@ -0,0 +1,38 @@
+/**
+ * Copyright 2016-2017 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.aai.esr.exception;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ExtsysExceptionTest {
+
+ @Test
+ public void testAllMethods(){
+ ExtsysException esExp = new ExtsysException();
+ esExp.setErrorCode("498");
+ Assert.assertEquals(esExp.getErrorCode(), "498");
+
+ esExp.setErrorMsg("Exception from JUnit");
+ Assert.assertEquals(esExp.getErrorMsg(), "Exception from JUnit");
+
+ ExtsysException oneArgExp = new ExtsysException("Exception from JUnit");
+ Assert.assertEquals(oneArgExp.getMessage(), "Exception from JUnit");
+
+ ExtsysException twoArgExp = new ExtsysException("Exception from JUnit", new ExtsysException());
+ Assert.assertNotNull(twoArgExp);
+ }
+}
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
index 0000000..1940c79
--- /dev/null
+++ b/esr-mgr/src/test/java/org/onap/aai/esr/externalservice/aai/AaiCommonTest.java
@@ -0,0 +1,29 @@
+/**
+ * Copyright 2016-2017 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.aai.esr.externalservice.aai;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class AaiCommonTest {
+
+ @Test
+ public void testGetAuthenticationCredentials(){
+ String cred = AaiCommon.getAuthenticationCredentials();
+ Assert.assertNotNull(cred);
+ Assert.assertTrue(cred.contains("Basic"));
+ }
+}
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
index 0000000..22c9524
--- /dev/null
+++ b/esr-mgr/src/test/java/org/onap/aai/esr/externalservice/aai/CloudRegionProxyTest.java
@@ -0,0 +1,54 @@
+/**
+ * Copyright 2016-2017 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.aai.esr.externalservice.aai;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.aai.esr.common.MsbConfig;
+import org.onap.aai.esr.entity.aai.CloudRegionDetail;
+import org.onap.aai.esr.exception.ExtsysException;
+
+public class CloudRegionProxyTest {
+
+ CloudRegionProxy proxy;
+
+ @Before
+ public void init(){
+ MsbConfig.setMsbServerAddr("http://msb-server");
+ proxy = new CloudRegionProxy();
+ }
+
+ @Test(expected = ExtsysException.class)
+ public void testRegisterVim() throws ExtsysException {
+ CloudRegionDetail cloudRegion = new CloudRegionDetail();
+ proxy.registerVim("owner-1", "region-1", cloudRegion);
+ }
+
+ @Test(expected = ExtsysException.class)
+ public void testQueryVimDetail() throws ExtsysException {
+ proxy.queryVimDetail("owner-1", "region-1");
+ }
+
+ @Test(expected = ExtsysException.class)
+ public void testQueryVimList() throws ExtsysException{
+ proxy.qureyVimList();
+ }
+
+ @Test(expected = ExtsysException.class)
+ public void testDeleteVim() throws ExtsysException{
+ proxy.deleteVim("owner-1", "region-1", "version-1");
+ }
+}
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
index 0000000..8f7cc92
--- /dev/null
+++ b/esr-mgr/src/test/java/org/onap/aai/esr/externalservice/aai/ExternalSystemProxyTest.java
@@ -0,0 +1,98 @@
+/**
+ * Copyright 2016-2017 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.aai.esr.externalservice.aai;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.aai.esr.common.MsbConfig;
+import org.onap.aai.esr.entity.aai.EsrEmsDetail;
+import org.onap.aai.esr.entity.aai.EsrThirdpartySdncDetail;
+import org.onap.aai.esr.entity.aai.EsrVnfmDetail;
+import org.onap.aai.esr.exception.ExtsysException;
+
+public class ExternalSystemProxyTest {
+
+ ExternalSystemProxy externalSystemProxy;
+
+ @Before
+ public void init() {
+ MsbConfig.setMsbServerAddr("http://msb-server");
+ externalSystemProxy = new ExternalSystemProxy();
+ }
+
+ @Test(expected = ExtsysException.class)
+ public void testRegisterVnfm() throws ExtsysException{
+ EsrVnfmDetail detail = new EsrVnfmDetail();
+ ExternalSystemProxy.registerVnfm("vnfm-1", detail);
+ }
+
+ @Test(expected = ExtsysException.class)
+ public void testQueryVnfmDetail() throws ExtsysException{
+ ExternalSystemProxy.queryVnfmDetail("vnfm-1");
+ }
+
+ @Test(expected = ExtsysException.class)
+ public void testQueryVnfmList() throws ExtsysException{
+ ExternalSystemProxy.queryVnfmList();
+ }
+
+ @Test(expected = ExtsysException.class)
+ public void testDeleteVnfm() throws ExtsysException{
+ ExternalSystemProxy.deleteVnfm("vnfm-1", "version-1");
+ }
+
+ @Test(expected = ExtsysException.class)
+ public void testRegisterSdnc() throws ExtsysException{
+ EsrThirdpartySdncDetail detail = new EsrThirdpartySdncDetail();
+ ExternalSystemProxy.registerSdnc("sdnc-1", detail);
+ }
+
+ @Test(expected = ExtsysException.class)
+ public void testQueryThirdpartySdncDetail() throws ExtsysException{
+ ExternalSystemProxy.queryThirdpartySdncDetail("sdnc-1");
+ }
+
+ @Test(expected = ExtsysException.class)
+ public void testQuerySdncList() throws ExtsysException{
+ ExternalSystemProxy.querySdncList();
+ }
+
+ @Test(expected = ExtsysException.class)
+ public void testDeleteThirdpartySdnc() throws ExtsysException{
+ ExternalSystemProxy.deleteThirdpartySdnc("sdnc-1", "version-1");
+ }
+
+ @Test(expected = ExtsysException.class)
+ public void testRegisterEms() throws ExtsysException{
+ EsrEmsDetail detail = new EsrEmsDetail();
+ ExternalSystemProxy.registerEms("ems-1",detail);
+ }
+
+ @Test(expected = ExtsysException.class)
+ public void testQueryEmsDetail() throws ExtsysException{
+ ExternalSystemProxy.queryEmsDetail("ems-1");
+ }
+
+ @Test(expected = ExtsysException.class)
+ public void testQueryEmsList() throws ExtsysException{
+ ExternalSystemProxy.queryEmsList();
+ }
+
+ @Test(expected = ExtsysException.class)
+ public void testDeleteEms() throws ExtsysException{
+ ExternalSystemProxy.deleteEms("ems-1", "version-1");
+ }
+}
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
index 0000000..5637783
--- /dev/null
+++ b/esr-mgr/src/test/java/org/onap/aai/esr/externalservice/cloud/VimManagerProxyTest.java
@@ -0,0 +1,41 @@
+/**
+ * Copyright 2016-2017 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.aai.esr.externalservice.cloud;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.aai.esr.common.MsbConfig;
+import org.onap.aai.esr.exception.ExtsysException;
+
+public class VimManagerProxyTest {
+
+ VimManagerProxy proxy;
+
+ @Before
+ public void init() {
+ MsbConfig.setMsbServerAddr("http://msb-server");
+ proxy = new VimManagerProxy();
+ }
+
+ @Test(expected = ExtsysException.class)
+ public void testUpdateVim() throws ExtsysException{
+ Tenant tenant = new Tenant();
+ tenant.setDefaultTenant("defaultTenant");
+ Assert.assertEquals(tenant.getDefaultTenant(), "defaultTenant");
+ VimManagerProxy.updateVim("owner-1", "region-1", tenant);
+ }
+}
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
index 0000000..28a22c5
--- /dev/null
+++ b/esr-mgr/src/test/java/org/onap/aai/esr/externalservice/msb/MsbHelperTest.java
@@ -0,0 +1,51 @@
+/**
+ * Copyright 2016-2017 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.aai.esr.externalservice.msb;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;
+import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
+import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
+
+public class MsbHelperTest {
+
+ MsbHelper helper;
+
+ @Mock
+ MSBServiceClient client;
+
+ @Mock
+ MicroServiceFullInfo serviceInfo;
+
+ @Before
+ public void init(){
+ MockitoAnnotations.initMocks(this);
+ helper = new MsbHelper(client);
+ }
+
+ @Test
+ public void testRegisterMsb() throws Exception {
+ Mockito.when(client.registerMicroServiceInfo(Mockito.any(MicroServiceInfo.class),
+ Mockito.anyBoolean())).thenReturn(serviceInfo);
+ helper.registerMsb();
+ Mockito.verify(client, Mockito.times(1)).
+ registerMicroServiceInfo(Mockito.any(MicroServiceInfo.class), Mockito.anyBoolean());
+ }
+}