summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlizi00164331 <li.zi30@zte.com.cn>2017-09-23 14:31:17 +0800
committerlizi00164331 <li.zi30@zte.com.cn>2017-09-23 14:31:17 +0800
commite5810e581bfb1fa7fb7783e16a41eb79564e9934 (patch)
treed09bd09b5f8de7cef4cf32b67ddb70b868bda4d3
parent6011cbc9b4031f3ce25a82ccb1c0fedf4a2bf57a (diff)
Add unit test case for VIM register utils.
Add unit test case for VIM register utils. Clean the unused code. Change-Id: I2b097d566f2f7ddebe8f107bf51e78aad194b5a3 Issue-ID: AAI-375 Signed-off-by: lizi00164331 <li.zi30@zte.com.cn>
-rw-r--r--esr-mgr/src/main/java/org/onap/aai/esr/common/HibernateSession.java74
-rw-r--r--esr-mgr/src/test/java/org/onap/aai/esr/ExtsysAppTest.java6
-rw-r--r--esr-mgr/src/test/java/org/onap/aai/esr/util/ThirdpartySdncManagerUtilTest.java1
-rw-r--r--esr-mgr/src/test/java/org/onap/aai/esr/util/VimManagerUtilTest.java125
4 files changed, 125 insertions, 81 deletions
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/common/HibernateSession.java b/esr-mgr/src/main/java/org/onap/aai/esr/common/HibernateSession.java
deleted file mode 100644
index 963ccc7..0000000
--- a/esr-mgr/src/main/java/org/onap/aai/esr/common/HibernateSession.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * Copyright 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 java.io.File;
-import java.net.URISyntaxException;
-
-import org.hibernate.SessionFactory;
-import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.service.ServiceRegistry;
-
-public class HibernateSession {
- private static File cfgfile = null;
-
- private static ServiceRegistry serviceRegistry = null;
- private static Configuration configuration = null;
- private static SessionFactory sessionFactory = null;
- private static String resourcePath;
-
- /**
- * Get a hibernate sessionFactory.
- */
- public static SessionFactory init() {
- initConfigure();
- configuration = new Configuration().configure(cfgfile);
- configuration.setProperty("hibernate.connection.url", "jdbc:h2:tcp://localhost:8205/"
- + resourcePath + "db/catalog");
- serviceRegistry =
- new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
- sessionFactory = configuration.buildSessionFactory(serviceRegistry);
- return sessionFactory;
- }
-
- private static void initConfigure() {
- try {
- resourcePath = HibernateSession.class.getResource("/").toURI().getPath();
- } catch (URISyntaxException e1) {
- e1.printStackTrace();
- }
- final String filename = "Hibernate.cfg.xml";
- cfgfile = new File(resourcePath + filename);
- }
-
- /**
- * Destory a hibernate sessionFactory.
- */
- public static void destory() {
- if (sessionFactory != null && !sessionFactory.isClosed()) {
- sessionFactory.close();
- }
- }
-
- /**
- * test.
- * @param args param
- */
- public static void main(String[] args) {
-
- }
-}
diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/ExtsysAppTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/ExtsysAppTest.java
index 8682dfa..7f7adb0 100644
--- a/esr-mgr/src/test/java/org/onap/aai/esr/ExtsysAppTest.java
+++ b/esr-mgr/src/test/java/org/onap/aai/esr/ExtsysAppTest.java
@@ -19,7 +19,6 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.onap.aai.esr.common.Config;
-import org.onap.aai.esr.common.HibernateSession;
public class ExtsysAppTest {
static {
@@ -32,9 +31,4 @@ public class ExtsysAppTest {
ExtsysApp app = new ExtsysApp();
assertEquals(app.getName(),"ONAP-ESR");
}
-
- public static void main(String[] args) throws Exception {
- String filePath = HibernateSession.class.getResource("/").toURI().getPath()+"extsys.yml";
- new ExtsysApp().run(new String[]{"server", filePath});
- }
}
diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/util/ThirdpartySdncManagerUtilTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/util/ThirdpartySdncManagerUtilTest.java
index ca45eaf..8c616b6 100644
--- a/esr-mgr/src/test/java/org/onap/aai/esr/util/ThirdpartySdncManagerUtilTest.java
+++ b/esr-mgr/src/test/java/org/onap/aai/esr/util/ThirdpartySdncManagerUtilTest.java
@@ -18,7 +18,6 @@ package org.onap.aai.esr.util;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
-import org.onap.aai.esr.entity.aai.EsrEmsDetail;
import org.onap.aai.esr.entity.aai.EsrThirdpartySdncDetail;
import org.onap.aai.esr.entity.rest.ThirdpartySdncRegisterInfo;
diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/util/VimManagerUtilTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/util/VimManagerUtilTest.java
new file mode 100644
index 0000000..7ec84ed
--- /dev/null
+++ b/esr-mgr/src/test/java/org/onap/aai/esr/util/VimManagerUtilTest.java
@@ -0,0 +1,125 @@
+/**
+ * Copyright 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.util;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+
+import org.junit.Test;
+import org.onap.aai.esr.entity.aai.CloudRegionDetail;
+import org.onap.aai.esr.entity.rest.VimAuthInfo;
+import org.onap.aai.esr.entity.rest.VimRegisterInfo;
+
+import com.google.gson.Gson;
+
+public class VimManagerUtilTest {
+
+ @Test
+ public void vimRegisterInfo2CloudRegionTest() {
+ VimManagerUtil vimManagerUtil = new VimManagerUtil();
+ CloudRegionDetail cloudRegionDetail = new CloudRegionDetail();
+ VimRegisterInfo vimRegisterInfo = new VimRegisterInfo();
+ ArrayList<VimAuthInfo> vimAuthInfos = new ArrayList<VimAuthInfo>();
+ VimAuthInfo vimAuthInfo = new VimAuthInfo();
+ vimAuthInfo.setAuthUrl("http://10.11.22.33:5000/v3");
+ vimAuthInfo.setCloudDomain("default");
+ vimAuthInfo.setPassword("123456");
+ vimAuthInfo.setSslCacert("test");
+ vimAuthInfo.setSslInsecure(true);
+ vimAuthInfo.setUserName("onap");
+ vimRegisterInfo.setCloudExtraInfo("{}");
+ vimRegisterInfo.setCloudOwner("zte");
+ vimRegisterInfo.setCloudRegionId("RegionOne");
+ vimRegisterInfo.setCloudRegionVersion("mitaca");
+ vimRegisterInfo.setCloudType("openstack");
+ vimRegisterInfo.setCloudZone("default");
+ vimRegisterInfo.setComplexName("complex");
+ vimRegisterInfo.setOwnerDefinedType("test");
+ vimRegisterInfo.setStatus("normal");
+ vimAuthInfos.add(vimAuthInfo);
+ vimRegisterInfo.setVimAuthInfos(vimAuthInfos);
+ cloudRegionDetail = vimManagerUtil.vimRegisterInfo2CloudRegion(vimRegisterInfo);
+ cloudRegionDetail.getEsrSystemInfoList().getEsrSystemInfo().get(0).setEsrSystemInfoId("123456");
+ String cloudRegionDetailStr = new ExtsysUtil().objectToString(cloudRegionDetail);
+ String expectResult = "{\"cloud-owner\":\"zte\","
+ + "\"cloud-region-id\":\"RegionOne\","
+ + "\"cloud-type\":\"openstack\","
+ + "\"cloud-region-version\":\"mitaca\","
+ + "\"owner-defined-type\":\"test\","
+ + "\"cloud-zone\":\"default\","
+ + "\"complex-name\":\"complex\","
+ + "\"cloud-extra-info\":\"{}\","
+ + "\"esr-system-info-list\":{"
+ + "\"esr-system-info\":[{"
+ + "\"esr-system-info-id\":\"123456\","
+ + "\"service-url\":\"http://10.11.22.33:5000/v3\","
+ + "\"user-name\":\"onap\","
+ + "\"password\":\"123456\","
+ + "\"system-type\":\"VIM\","
+ + "\"ssl-cassert\":\"test\","
+ + "\"ssl-insecure\":true,"
+ + "\"cloud-domain\":\"default\","
+ + "\"system-status\":\"normal\"}]}}";
+ assertEquals(expectResult, cloudRegionDetailStr);
+ }
+
+ @Test
+ public void cloudRegion2VimRegisterInfoTest() {
+ VimManagerUtil vimManagerUtil = new VimManagerUtil();
+ CloudRegionDetail cloudRegionDetail = new CloudRegionDetail();
+ VimRegisterInfo vimRegisterInfo = new VimRegisterInfo();
+ String cloudRegionDetailStr = "{\"cloud-owner\":\"zte\","
+ + "\"cloud-region-id\":\"RegionOne\","
+ + "\"cloud-type\":\"openstack\","
+ + "\"cloud-region-version\":\"mitaca\","
+ + "\"owner-defined-type\":\"test\","
+ + "\"cloud-zone\":\"default\","
+ + "\"complex-name\":\"complex\","
+ + "\"cloud-extra-info\":\"{}\","
+ + "\"esr-system-info-list\":{"
+ + "\"esr-system-info\":[{"
+ + "\"esr-system-info-id\":\"123456\","
+ + "\"service-url\":\"http://10.11.22.33:5000/v3\","
+ + "\"user-name\":\"onap\","
+ + "\"password\":\"123456\","
+ + "\"system-type\":\"VIM\","
+ + "\"ssl-cassert\":\"test\","
+ + "\"ssl-insecure\":true,"
+ + "\"cloud-domain\":\"default\","
+ + "\"system-status\":\"normal\"}]}}";
+ cloudRegionDetail = new Gson().fromJson(cloudRegionDetailStr, CloudRegionDetail.class);
+ vimRegisterInfo = vimManagerUtil.cloudRegion2VimRegisterInfo(cloudRegionDetail);
+ String vimRegisterInfoStr = new ExtsysUtil().objectToString(vimRegisterInfo);
+ String expectResult = "{\"cloudOwner\":\"zte\","
+ + "\"cloudRegionId\":\"RegionOne\","
+ + "\"cloudType\":\"openstack\","
+ + "\"cloudRegionVersion\":\"mitaca\","
+ + "\"ownerDefinedType\":\"test\","
+ + "\"cloudZone\":\"default\","
+ + "\"complexName\":\"complex\","
+ + "\"cloudExtraInfo\":\"{}\","
+ + "\"status\":\"normal\","
+ + "\"vimAuthInfos\":[{"
+ + "\"cloudDomain\":\"default\","
+ + "\"userName\":\"onap\","
+ + "\"password\":\"123456\","
+ + "\"authUrl\":\"http://10.11.22.33:5000/v3\","
+ + "\"sslCacert\":\"test\","
+ + "\"sslInsecure\":true}]}";
+ assertEquals(expectResult, vimRegisterInfoStr);
+ }
+}