diff options
author | Lizi <li.zi30@zte.com.cn> | 2018-01-12 02:20:56 +0000 |
---|---|---|
committer | Lizi <li.zi30@zte.com.cn> | 2018-01-12 02:21:07 +0000 |
commit | 486ed42762fedbc7cd0cc43704389ed41434eacd (patch) | |
tree | ff77b4dd4af47d10d33f678292b0ad64e50a9785 | |
parent | ed26992f976741031237ead3a5dc0565d4318b05 (diff) |
Add unit test for ems management.
Change-Id: I21baa89e1517e0f5f208e2ed64d86c4b9c47c6b8
Issue-ID: AAI-637
Signed-off-by: Lizi <li.zi30@zte.com.cn>
5 files changed, 238 insertions, 34 deletions
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/ExternalSystemProxy.java b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/ExternalSystemProxy.java index 0361747..2e19f7d 100644 --- a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/ExternalSystemProxy.java +++ b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/ExternalSystemProxy.java @@ -150,17 +150,34 @@ public class ExternalSystemProxy { } public static void registerEms(String emsId, EsrEmsDetail emsDetail) throws ExtsysException { - ClientConfig config = new ClientConfig(new EmsRegisterProvider()); - IExternalSystem registerEmsServiceproxy = - ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class); - try { - registerEmsServiceproxy.registerEMS(transactionId, fromAppId, authorization, emsId, emsDetail); - } catch (Exception e) { - throw new ExtsysException("PUT EMS to A&AI failed.", e); + if (!isTest) { + ClientConfig config = new ClientConfig(new EmsRegisterProvider()); + IExternalSystem registerEmsServiceproxy = + ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class); + try { + registerEmsServiceproxy.registerEMS(transactionId, fromAppId, authorization, emsId, emsDetail); + } catch (Exception e) { + throw new ExtsysException("PUT EMS to A&AI failed.", e); + } } } public static String queryEmsDetail(String emsId) throws ExtsysException { + if (isTest) { + String emsDetailStr = "{\"ems-id\":\"123456\"," + "\"esr-system-info-list\":" + "{\"esr-system-info\":" + + "[{\"esr-system-info-id\":\"234567\"," + "\"system-name\":\"EMS_TEST\"," + "\"type\":\"sftp\"," + + "\"vendor\":\"ZTE\"," + "\"version\":\"V1\"," + "\"user-name\":\"nancy\"," + "\"password\":\"asdf\"," + + "\"system-type\":\"EMS_RESOUCE\"," + "\"ip-address\":\"127.0.0.1\"," + "\"port\":\"5000\"," + + "\"passive\":true," + "\"remote-path\":\"/home/per\"}," + "{\"esr-system-info-id\":\"345678\"," + + "\"system-name\":\"EMS_TEST\"," + "\"type\":\"sftp\"," + "\"vendor\":\"ZTE\"," + "\"version\":\"V1\"," + + "\"user-name\":\"nancy\"," + "\"password\":\"asdf\"," + "\"system-type\":\"EMS_PERFORMANCE\"," + + "\"ip-address\":\"127.0.0.1\"," + "\"port\":\"5000\"," + "\"passive\":true," + + "\"remote-path\":\"/home/per\"}," + "{\"esr-system-info-id\":\"456789\"," + + "\"system-name\":\"EMS_TEST\"," + "\"vendor\":\"ZTE\"," + "\"version\":\"V1\"," + + "\"user-name\":\"nancy\"," + "\"password\":\"987654\"," + "\"system-type\":\"EMS_ALARM\"," + + "\"ip-address\":\"127.0.0.1\"," + "\"port\":\"5000\"}]}}"; + return emsDetailStr; + } try { return externalSystemproxy.queryEMSDetail(transactionId, fromAppId, authorization, emsId); } catch (Exception e) { @@ -169,6 +186,9 @@ public class ExternalSystemProxy { } public static String queryEmsList() throws ExtsysException { + if (isTest) { + return "{\"esr-ems\": [ {\"ems-id\": \"123456\",\"resource-version\": \"1\"}]}"; + } try { return externalSystemproxy.queryEMSList(transactionId, fromAppId, authorization); } catch (Exception e) { @@ -177,10 +197,12 @@ public class ExternalSystemProxy { } public static void deleteEms(String emsId, String resourceVersion) throws ExtsysException { - try { - externalSystemproxy.deleteEMS(transactionId, fromAppId, authorization, emsId, resourceVersion); - } catch (Exception e) { - throw new ExtsysException("Delete EMS from A&AI failed.", e); + if (!isTest) { + try { + externalSystemproxy.deleteEMS(transactionId, fromAppId, authorization, emsId, resourceVersion); + } catch (Exception e) { + throw new ExtsysException("Delete EMS from A&AI failed.", e); + } } } } diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/EmsManagerWrapper.java b/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/EmsManagerWrapper.java index 571afbc..fb85333 100644 --- a/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/EmsManagerWrapper.java +++ b/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/EmsManagerWrapper.java @@ -93,8 +93,7 @@ public class EmsManagerWrapper { } public Response queryEmsById(String emsId) { - EmsRegisterInfo ems; - ems = queryEmsDetail(emsId); + EmsRegisterInfo ems = queryEmsDetail(emsId); if (ems != null) { return Response.ok(ems).build(); } else { diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/EmsManagerWrapperTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/EmsManagerWrapperTest.java index 78237d7..affd66f 100644 --- a/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/EmsManagerWrapperTest.java +++ b/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/EmsManagerWrapperTest.java @@ -15,9 +15,21 @@ */ package org.onap.aai.esr.wrapper; +import static org.junit.Assert.assertEquals; +import java.util.ArrayList; +import java.util.List; +import javax.ws.rs.core.Response; +import org.junit.AfterClass; +import org.junit.Assert; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.onap.aai.esr.common.MsbConfig; +import org.onap.aai.esr.entity.rest.AlarmAddr; +import org.onap.aai.esr.entity.rest.EmsRegisterInfo; +import org.onap.aai.esr.entity.rest.FtpAddr; +import org.onap.aai.esr.externalservice.aai.ExternalSystemProxy; +import org.onap.aai.esr.util.ExtsysUtil; public class EmsManagerWrapperTest { private static EmsManagerWrapper emsManagerWrapper; @@ -25,6 +37,16 @@ public class EmsManagerWrapperTest { MsbConfig.setMsbServerAddr("http://127.0.0.1:80"); } + @BeforeClass + public static void beforeClass() { + ExternalSystemProxy.isTest = true; + }; + + @AfterClass + public static void afterClass() { + ExternalSystemProxy.isTest = false; + }; + @Before public void setUp() throws Exception { emsManagerWrapper = EmsManagerWrapper.getInstance(); @@ -32,6 +54,163 @@ public class EmsManagerWrapperTest { @Test public void test_registerEms() { - + + EmsRegisterInfo emsRegisterInfo = new EmsRegisterInfo(); + AlarmAddr alarmAddr = new AlarmAddr(); + FtpAddr resourceAddr = new FtpAddr(); + FtpAddr performanceAddr = new FtpAddr(); + alarmAddr.setIp("127.0.0.1"); + alarmAddr.setPassword("987654"); + alarmAddr.setPort("5000"); + alarmAddr.setUser("nancy"); + resourceAddr.setFtptype("sftp"); + resourceAddr.setIp("127.0.0.1"); + resourceAddr.setPassive(true); + resourceAddr.setPassword("asdf"); + resourceAddr.setPort("5000"); + resourceAddr.setRemotepath("/home/per"); + resourceAddr.setUser("nancy"); + performanceAddr.setFtptype("sftp"); + performanceAddr.setIp("127.0.0.1"); + performanceAddr.setPassive(true); + performanceAddr.setPassword("asdf"); + performanceAddr.setPort("5000"); + performanceAddr.setRemotepath("/home/per"); + performanceAddr.setUser("nancy"); + emsRegisterInfo.setName("EMS_TEST"); + emsRegisterInfo.setVendor("ZTE"); + emsRegisterInfo.setVersion("V1"); + emsRegisterInfo.setAlarmAddr(alarmAddr); + emsRegisterInfo.setResourceAddr(resourceAddr); + emsRegisterInfo.setPerformanceAddr(performanceAddr); + Response response = emsManagerWrapper.registerEms(emsRegisterInfo); + if (response != null) { + Assert.assertTrue(response.getStatus() == 200); + } + } + + @Test + public void test_queryEmsById() { + ExtsysUtil extsysUtil = new ExtsysUtil(); + EmsRegisterInfo emsRegisterInfo = new EmsRegisterInfo(); + AlarmAddr alarmAddr = new AlarmAddr(); + FtpAddr resourceAddr = new FtpAddr(); + FtpAddr performanceAddr = new FtpAddr(); + alarmAddr.setIp("127.0.0.1"); + alarmAddr.setPassword("987654"); + alarmAddr.setPort("5000"); + alarmAddr.setUser("nancy"); + resourceAddr.setFtptype("sftp"); + resourceAddr.setIp("127.0.0.1"); + resourceAddr.setPassive(true); + resourceAddr.setPassword("asdf"); + resourceAddr.setPort("5000"); + resourceAddr.setRemotepath("/home/per"); + resourceAddr.setUser("nancy"); + performanceAddr.setFtptype("sftp"); + performanceAddr.setIp("127.0.0.1"); + performanceAddr.setPassive(true); + performanceAddr.setPassword("asdf"); + performanceAddr.setPort("5000"); + performanceAddr.setRemotepath("/home/per"); + performanceAddr.setUser("nancy"); + emsRegisterInfo.setName("EMS_TEST"); + emsRegisterInfo.setVendor("ZTE"); + emsRegisterInfo.setVersion("V1"); + emsRegisterInfo.setAlarmAddr(alarmAddr); + emsRegisterInfo.setResourceAddr(resourceAddr); + emsRegisterInfo.setPerformanceAddr(performanceAddr); + emsRegisterInfo.setEmsId("123456"); + Response response = emsManagerWrapper.queryEmsById("123456"); + if (response != null) { + Assert.assertTrue(response.getStatus() == 200); + assertEquals(extsysUtil.objectToString(emsRegisterInfo), extsysUtil.objectToString(response.getEntity())); + } + } + + @Test + public void test_queryEmsList() { + ExtsysUtil extsysUtil = new ExtsysUtil(); + List<EmsRegisterInfo> emsList = new ArrayList<>(); + EmsRegisterInfo emsRegisterInfo = new EmsRegisterInfo(); + AlarmAddr alarmAddr = new AlarmAddr(); + FtpAddr resourceAddr = new FtpAddr(); + FtpAddr performanceAddr = new FtpAddr(); + alarmAddr.setIp("127.0.0.1"); + alarmAddr.setPassword("987654"); + alarmAddr.setPort("5000"); + alarmAddr.setUser("nancy"); + resourceAddr.setFtptype("sftp"); + resourceAddr.setIp("127.0.0.1"); + resourceAddr.setPassive(true); + resourceAddr.setPassword("asdf"); + resourceAddr.setPort("5000"); + resourceAddr.setRemotepath("/home/per"); + resourceAddr.setUser("nancy"); + performanceAddr.setFtptype("sftp"); + performanceAddr.setIp("127.0.0.1"); + performanceAddr.setPassive(true); + performanceAddr.setPassword("asdf"); + performanceAddr.setPort("5000"); + performanceAddr.setRemotepath("/home/per"); + performanceAddr.setUser("nancy"); + emsRegisterInfo.setName("EMS_TEST"); + emsRegisterInfo.setVendor("ZTE"); + emsRegisterInfo.setVersion("V1"); + emsRegisterInfo.setAlarmAddr(alarmAddr); + emsRegisterInfo.setResourceAddr(resourceAddr); + emsRegisterInfo.setPerformanceAddr(performanceAddr); + emsRegisterInfo.setEmsId("123456"); + emsList.add(emsRegisterInfo); + Response response = emsManagerWrapper.queryEmsList(); + if (response != null) { + Assert.assertTrue(response.getStatus() == 200); + assertEquals(extsysUtil.objectToString(emsList), extsysUtil.objectToString(response.getEntity())); + } + } + + @Test + public void test_updateEms() { + EmsRegisterInfo emsRegisterInfo = new EmsRegisterInfo(); + AlarmAddr alarmAddr = new AlarmAddr(); + FtpAddr resourceAddr = new FtpAddr(); + FtpAddr performanceAddr = new FtpAddr(); + alarmAddr.setIp("127.0.0.1"); + alarmAddr.setPassword("987654"); + alarmAddr.setPort("5000"); + alarmAddr.setUser("nancy"); + resourceAddr.setFtptype("sftp"); + resourceAddr.setIp("127.0.0.1"); + resourceAddr.setPassive(true); + resourceAddr.setPassword("asdf"); + resourceAddr.setPort("5000"); + resourceAddr.setRemotepath("/home/per"); + resourceAddr.setUser("nancy"); + performanceAddr.setFtptype("sftp"); + performanceAddr.setIp("127.0.0.1"); + performanceAddr.setPassive(true); + performanceAddr.setPassword("asdf"); + performanceAddr.setPort("5000"); + performanceAddr.setRemotepath("/home/per"); + performanceAddr.setUser("nancy"); + emsRegisterInfo.setName("EMS_TEST"); + emsRegisterInfo.setVendor("ZTE"); + emsRegisterInfo.setVersion("V1"); + emsRegisterInfo.setAlarmAddr(alarmAddr); + emsRegisterInfo.setResourceAddr(resourceAddr); + emsRegisterInfo.setPerformanceAddr(performanceAddr); + emsRegisterInfo.setEmsId("123456"); + Response response = emsManagerWrapper.updateEms(emsRegisterInfo, "123456"); + if (response != null) { + Assert.assertTrue(response.getStatus() == 200); + } + } + + @Test + public void test_delEms() { + Response response = emsManagerWrapper.delEms("123456"); + if (response != null) { + Assert.assertTrue(response.getStatus() == 204); + } } } diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/ThirdpartySdncWrapperTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/ThirdpartySdncWrapperTest.java index e39adc7..0ece8a0 100644 --- a/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/ThirdpartySdncWrapperTest.java +++ b/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/ThirdpartySdncWrapperTest.java @@ -19,8 +19,10 @@ import static org.junit.Assert.assertEquals; import java.util.ArrayList; import java.util.List; import javax.ws.rs.core.Response; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.onap.aai.esr.common.MsbConfig; import org.onap.aai.esr.entity.rest.ThirdpartySdncRegisterInfo; @@ -34,6 +36,16 @@ public class ThirdpartySdncWrapperTest { MsbConfig.setMsbServerAddr("http://127.0.0.1:80"); } + @BeforeClass + public static void beforeClass() { + ExternalSystemProxy.isTest = true; + }; + + @AfterClass + public static void afterClass() { + ExternalSystemProxy.isTest = false; + }; + @Before public void setUp() throws Exception { thirdpartySdncWrapper = ThirdpartySdncWrapper.getInstance(); @@ -41,7 +53,6 @@ public class ThirdpartySdncWrapperTest { @Test public void test_registerThirdpartySdnc() { - ExternalSystemProxy.isTest = true; ThirdpartySdncRegisterInfo sdncRegisterInfo = new ThirdpartySdncRegisterInfo(); sdncRegisterInfo.setLocation("edge"); sdncRegisterInfo.setName("SDNC_TEST"); @@ -58,22 +69,18 @@ public class ThirdpartySdncWrapperTest { if (response != null) { Assert.assertTrue(response.getStatus() == 200); } - ExternalSystemProxy.isTest = false; } @Test public void test_delThirdpartySdnc() { - ExternalSystemProxy.isTest = true; Response response = thirdpartySdncWrapper.delThirdpartySdnc("123456"); if (response != null) { Assert.assertTrue(response.getStatus() == 204); } - ExternalSystemProxy.isTest = false; } @Test public void test_queryThirdpartySdncById() { - ExternalSystemProxy.isTest = true; ExtsysUtil extsysUtil = new ExtsysUtil(); ThirdpartySdncRegisterInfo sdncRegisterInfo = new ThirdpartySdncRegisterInfo(); sdncRegisterInfo.setLocation("edge"); @@ -92,12 +99,10 @@ public class ThirdpartySdncWrapperTest { Assert.assertTrue(response.getStatus() == 200); assertEquals(extsysUtil.objectToString(sdncRegisterInfo), extsysUtil.objectToString(response.getEntity())); } - ExternalSystemProxy.isTest = false; } @Test public void test_queryThirdpartySdncList() { - ExternalSystemProxy.isTest = true; ExtsysUtil extsysUtil = new ExtsysUtil(); List<ThirdpartySdncRegisterInfo> sdncList = new ArrayList<>(); ThirdpartySdncRegisterInfo sdncRegisterInfo = new ThirdpartySdncRegisterInfo(); @@ -118,12 +123,10 @@ public class ThirdpartySdncWrapperTest { Assert.assertTrue(response.getStatus() == 200); assertEquals(extsysUtil.objectToString(sdncList), extsysUtil.objectToString(response.getEntity())); } - ExternalSystemProxy.isTest = false; } @Test public void test_updateThirdpartySdnc() { - ExternalSystemProxy.isTest = true; ThirdpartySdncRegisterInfo sdncRegisterInfo = new ThirdpartySdncRegisterInfo(); sdncRegisterInfo.setLocation("edge"); sdncRegisterInfo.setName("SDNC_TEST"); @@ -140,6 +143,5 @@ public class ThirdpartySdncWrapperTest { if (response != null) { Assert.assertTrue(response.getStatus() == 200); } - ExternalSystemProxy.isTest = false; } } diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/VnfmManagerWrapperTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/VnfmManagerWrapperTest.java index bfc9afd..1e2abed 100644 --- a/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/VnfmManagerWrapperTest.java +++ b/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/VnfmManagerWrapperTest.java @@ -19,8 +19,10 @@ import static org.junit.Assert.assertEquals; import java.util.ArrayList; import java.util.List; import javax.ws.rs.core.Response; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.onap.aai.esr.common.MsbConfig; import org.onap.aai.esr.entity.rest.VnfmRegisterInfo; @@ -34,6 +36,16 @@ public class VnfmManagerWrapperTest { MsbConfig.setMsbServerAddr("http://127.0.0.1:80"); } + @BeforeClass + public static void beforeClass() { + ExternalSystemProxy.isTest = true; + }; + + @AfterClass + public static void afterClass() { + ExternalSystemProxy.isTest = false; + }; + @Before public void setUp() throws Exception { vnfmManagerWrapper = VnfmManagerWrapper.getInstance(); @@ -41,7 +53,6 @@ public class VnfmManagerWrapperTest { @Test public void test_registerVnfm() { - ExternalSystemProxy.isTest = true; VnfmRegisterInfo vnfmRegisterInfo = new VnfmRegisterInfo(); vnfmRegisterInfo.setVimId("987654"); vnfmRegisterInfo.setVersion("v1"); @@ -56,12 +67,10 @@ public class VnfmManagerWrapperTest { if (response != null) { Assert.assertTrue(response.getStatus() == 200); } - ExternalSystemProxy.isTest = false; } @Test public void test_queryVnfmById() { - ExternalSystemProxy.isTest = true; ExtsysUtil extsysUtil = new ExtsysUtil(); VnfmRegisterInfo vnfmRegisterInfo = new VnfmRegisterInfo(); vnfmRegisterInfo.setVimId("987654"); @@ -79,12 +88,10 @@ public class VnfmManagerWrapperTest { Assert.assertTrue(response.getStatus() == 200); assertEquals(extsysUtil.objectToString(vnfmRegisterInfo), extsysUtil.objectToString(response.getEntity())); } - ExternalSystemProxy.isTest = false; } @Test public void test_queryVnfmList() { - ExternalSystemProxy.isTest = true; ExtsysUtil extsysUtil = new ExtsysUtil(); List<VnfmRegisterInfo> vnfmList = new ArrayList<>(); VnfmRegisterInfo vnfmRegisterInfo = new VnfmRegisterInfo(); @@ -104,22 +111,18 @@ public class VnfmManagerWrapperTest { Assert.assertTrue(response.getStatus() == 200); assertEquals(extsysUtil.objectToString(vnfmList), extsysUtil.objectToString(response.getEntity())); } - ExternalSystemProxy.isTest = false; } @Test public void test_delVnfm() { - ExternalSystemProxy.isTest = true; Response response = vnfmManagerWrapper.delVnfm("123456"); if (response != null) { Assert.assertTrue(response.getStatus() == 204); } - ExternalSystemProxy.isTest = false; } @Test public void test_updateVnfm() { - ExternalSystemProxy.isTest = true; VnfmRegisterInfo vnfmRegisterInfo = new VnfmRegisterInfo(); vnfmRegisterInfo.setVimId("987654"); vnfmRegisterInfo.setVersion("v1"); @@ -135,6 +138,5 @@ public class VnfmManagerWrapperTest { if (response != null) { Assert.assertTrue(response.getStatus() == 200); } - ExternalSystemProxy.isTest = false; } } |