From a66771ece8eb7c7dce4ff4da35df6e4faf94d8f0 Mon Sep 17 00:00:00 2001
From: lizi00164331
Date: Wed, 20 Sep 2017 10:09:24 +0800
Subject: [PATCH] Add the unit test for ExtsysAppTest.
Change-Id: I8ec279cfff9f1f11fac53cc82a555dc719be29a0
Issue-ID: AAI-340
Signed-off-by: lizi00164331
---
.../org/onap/aai/esr/common/HibernateSession.java | 74 +++++++++++++++++++++
.../org/onap/aai/esr/resource/ServiceTest.java | 1 -
.../test/java/org/onap/aai/esr/ExtsysAppTest.java | 40 +++++++++++
esr-mgr/src/test/resources/db/extsys.mv.db | Bin 12288 -> 0 bytes
esr-mgr/src/test/resources/extsys.yml | 68 +++++++++++++++++++
.../sql/extsys-resource-createObj-mysql.sql | 71 --------------------
6 files changed, 182 insertions(+), 72 deletions(-)
create mode 100644 esr-mgr/src/main/java/org/onap/aai/esr/common/HibernateSession.java
create mode 100644 esr-mgr/src/test/java/org/onap/aai/esr/ExtsysAppTest.java
delete mode 100644 esr-mgr/src/test/resources/db/extsys.mv.db
create mode 100644 esr-mgr/src/test/resources/extsys.yml
delete mode 100644 esr-mgr/src/test/resources/sql/extsys-resource-createObj-mysql.sql
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
new file mode 100644
index 0000000..963ccc7
--- /dev/null
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/common/HibernateSession.java
@@ -0,0 +1,74 @@
+/**
+ * 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/main/java/org/onap/aai/esr/resource/ServiceTest.java b/esr-mgr/src/main/java/org/onap/aai/esr/resource/ServiceTest.java
index 0549304..d92d40b 100644
--- a/esr-mgr/src/main/java/org/onap/aai/esr/resource/ServiceTest.java
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/resource/ServiceTest.java
@@ -22,7 +22,6 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.eclipse.jetty.http.HttpStatus;
-import org.onap.aai.esr.wrapper.EmsManagerWrapper;
import com.codahale.metrics.annotation.Timed;
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
new file mode 100644
index 0000000..8682dfa
--- /dev/null
+++ b/esr-mgr/src/test/java/org/onap/aai/esr/ExtsysAppTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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;
+
+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 {
+ ExtsysAppConfiguration configuration = new ExtsysAppConfiguration();
+ Config.setConfigration(configuration);
+ }
+
+ @Test
+ public void getName() throws Exception {
+ 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/resources/db/extsys.mv.db b/esr-mgr/src/test/resources/db/extsys.mv.db
deleted file mode 100644
index facfeac56df50bc9d2fe2a914b5795d8f0df4359..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 12288
zcmeI2&vV;E6vwS%b%;|#ec-+gv`N4i{kEl>EGf09EqNq4Bo{KWezch;cE)ibz!8Q&
zh!cNAuUz?Cc;1yQIkAmtW|+=&b$IgAzTJKA`_a#2JDN}*UW}vH{`t>|#&aB3k0wbt
zO=69g6-AX(QB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