aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzhangab <zhanganbing@chinamobile.com>2018-04-16 11:56:13 +0800
committerzhangab <zhanganbing@chinamobile.com>2018-04-16 11:56:17 +0800
commitd7f6e2f760875cb6c66d452a1af24d93abde9824 (patch)
tree28c0c1d8a737d772640f795d1308be812e6f75f6
parent021f2935bf4182b35a3aa7fbc560f2612f92473d (diff)
improve sonar coverage for uui-server
Change-Id: I3c867c1493290e730b6bec7f050cf1e57a0f5cd4 Issue-ID: USECASEUI-103 Signed-off-by: zhangab <zhanganbing@chinamobile.com>
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java214
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/bean/AlarmsHeaderTest.java2
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/bean/AlarmsInformationTest.java75
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/bean/PerformanceHeaderTest.java103
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/bean/PerformanceInformationTest.java75
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInputTest.java79
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/bean/lcm/TemplateInputTest.java70
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/bean/lcm/VfNsPackageInfoTest.java66
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImplTest.java268
9 files changed, 846 insertions, 106 deletions
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java
index 32eec76e..c12576dc 100755
--- a/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java
@@ -40,83 +40,87 @@ import org.springframework.stereotype.Service;
@org.springframework.context.annotation.Configuration
@EnableAspectJAutoProxy
public class AlarmsInformationServiceImpl implements AlarmsInformationService {
- private static final Logger logger = LoggerFactory.getLogger(AlarmsInformationServiceImpl.class);
+ private static final Logger logger = LoggerFactory.getLogger(AlarmsInformationServiceImpl.class);
- @Autowired
- private SessionFactory sessionFactory;
+ @Autowired
+ private SessionFactory sessionFactory;
+
+ private Session getSession() {
+ return sessionFactory.openSession();
+ }
@Override
public String saveAlarmsInformation(AlarmsInformation alarmsInformation) {
- try(Session session = sessionFactory.openSession();){
- if (null == alarmsInformation) {
- logger.error("alarmsInformation saveAlarmsInformation alarmsInformation is null!");
- }
- logger.info("AlarmsInformationServiceImpl saveAlarmsInformation: alarmsInformation={}", alarmsInformation);
- Transaction tx = session.beginTransaction();
- session.save(alarmsInformation);
- tx.commit();
- session.flush();
- return "1";
- } catch (Exception e) {
- logger.error("exception occurred while performing AlarmsInformationServiceImpl saveAlarmsInformation. Details:" + e.getMessage());
- return "0";
- }
-
+ try(Session session = getSession()){
+ if (null == alarmsInformation) {
+ logger.error("alarmsInformation saveAlarmsInformation alarmsInformation is null!");
+ }
+ logger.info("AlarmsInformationServiceImpl saveAlarmsInformation: alarmsInformation={}", alarmsInformation);
+ Transaction tx = session.beginTransaction();
+ session.save(alarmsInformation);
+ tx.commit();
+ session.flush();
+ return "1";
+ } catch (Exception e) {
+ logger.error("exception occurred while performing AlarmsInformationServiceImpl saveAlarmsInformation. Details:" + e.getMessage());
+ return "0";
+ }
+
}
@Override
public String updateAlarmsInformation(AlarmsInformation alarmsInformation) {
- try(Session session = sessionFactory.openSession();){
- if (null == alarmsInformation) {
- logger.error("alarmsInformation updateAlarmsInformation alarmsInformation is null!");
- }
- logger.info("AlarmsInformationServiceImpl updateAlarmsInformation: alarmsInformation={}", alarmsInformation);
- Transaction tx = session.beginTransaction();
- session.update(alarmsInformation);
- tx.commit();
- session.flush();
- return "1";
- } catch (Exception e) {
- logger.error("exception occurred while performing AlarmsInformationServiceImpl updateAlarmsInformation. Details:" + e.getMessage());
- return "0";
- }
+ try(Session session = getSession()){
+ if (null == alarmsInformation) {
+ logger.error("alarmsInformation updateAlarmsInformation alarmsInformation is null!");
+ }
+ logger.info("AlarmsInformationServiceImpl updateAlarmsInformation: alarmsInformation={}", alarmsInformation);
+ Transaction tx = session.beginTransaction();
+ session.update(alarmsInformation);
+ tx.commit();
+ session.flush();
+ return "1";
+ } catch (Exception e) {
+ logger.error("exception occurred while performing AlarmsInformationServiceImpl updateAlarmsInformation. Details:" + e.getMessage());
+ return "0";
+ }
}
public int getAllCount(AlarmsInformation alarmsInformation, int currentPage, int pageSize) {
- try(Session session = sessionFactory.openSession();){
+ try(Session session = getSession()){
StringBuffer hql = new StringBuffer("select count(*) from AlarmsInformation a where 1=1");
if (null == alarmsInformation) {
- //logger.error("AlarmsInformationServiceImpl getAllCount alarmsInformation is null!");
- }else {
- if(null!=alarmsInformation.getName()) {
- String ver=alarmsInformation.getName();
- hql.append(" and a.name like '%"+ver+"%'");
- }
- if(null!=alarmsInformation.getValue()) {
- String ver=alarmsInformation.getValue();
- hql.append(" and a.value like '%"+ver+"%'");
- }
- if(null!=alarmsInformation.getEventId()) {
- String ver=alarmsInformation.getEventId();
- hql.append(" and a.eventId = '"+ver+"'");
- }
- if(null!=alarmsInformation.getCreateTime()) {
- Date ver =alarmsInformation.getCreateTime();
- hql.append(" and a.createTime > '%"+ver+"%'");
- }
- if(null!=alarmsInformation.getUpdateTime()) {
- Date ver =alarmsInformation.getUpdateTime();
- hql.append(" and a.updateTime like '%"+ver+"%'");
- }
- }
- long q=(long)session.createQuery(hql.toString()).uniqueResult();
- session.flush();
- return (int)q;
- } catch (Exception e) {
- logger.error("exception occurred while performing AlarmsInformationServiceImpl getAllCount. Details:" + e.getMessage());
- return 0;
- }
+ logger.error("AlarmsInformationServiceImpl getAllCount alarmsInformation is null!");
+ }else {
+ if(null!=alarmsInformation.getName()) {
+ String ver=alarmsInformation.getName();
+ hql.append(" and a.name like '%"+ver+"%'");
+ }
+ if(null!=alarmsInformation.getValue()) {
+ String ver=alarmsInformation.getValue();
+ hql.append(" and a.value like '%"+ver+"%'");
+ }
+ if(null!=alarmsInformation.getEventId()) {
+ String ver=alarmsInformation.getEventId();
+ hql.append(" and a.eventId = '"+ver+"'");
+ }
+ if(null!=alarmsInformation.getCreateTime()) {
+ Date ver =alarmsInformation.getCreateTime();
+ hql.append(" and a.createTime > '%"+ver+"%'");
+ }
+ if(null!=alarmsInformation.getUpdateTime()) {
+ Date ver =alarmsInformation.getUpdateTime();
+ hql.append(" and a.updateTime like '%"+ver+"%'");
+ }
+ }
+ long q=(long)session.createQuery(hql.toString()).uniqueResult();
+ session.flush();
+ return (int)q;
+ } catch (Exception e) {
+ logger.error("exception occurred while performing AlarmsInformationServiceImpl getAllCount. Details:" + e.getMessage());
+ return 0;
+ }
}
@SuppressWarnings("unchecked")
@@ -127,47 +131,47 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
int allRow =this.getAllCount(alarmsInformation,currentPage,pageSize);
int offset = page.countOffset(currentPage, pageSize);
- try(Session session = sessionFactory.openSession();){
+ try(Session session = getSession()){
StringBuffer hql =new StringBuffer("from AlarmsInformation a where 1=1");
- if (null == alarmsInformation) {
- //logger.error("AlarmsInformationServiceImpl queryAlarmsInformation alarmsInformation is null!");
- }else {
- if(null!=alarmsInformation.getName()) {
- String ver=alarmsInformation.getName();
- hql.append(" and a.name like '%"+ver+"%'");
- }
- if(null!=alarmsInformation.getValue()) {
- String ver=alarmsInformation.getValue();
- hql.append(" and a.value like '%"+ver+"%'");
- }
- if(null!=alarmsInformation.getEventId()) {
- String ver=alarmsInformation.getEventId();
- hql.append(" and a.eventId = '"+ver+"'");
- }
- if(null!=alarmsInformation.getCreateTime()) {
- Date ver =alarmsInformation.getCreateTime();
- hql.append(" and a.createTime > '%"+ver+"%'");
- }
- if(null!=alarmsInformation.getUpdateTime()) {
- Date ver =alarmsInformation.getUpdateTime();
- hql.append(" and a.updateTime like '%"+ver+"%'");
- }
- }
- logger.info("AlarmsInformationServiceImpl queryAlarmsInformation: alarmsInformation={}", alarmsInformation);
- Query query = session.createQuery(hql.toString());
- query.setFirstResult(offset);
- query.setMaxResults(pageSize);
- List<AlarmsInformation> list= query.list();
- page.setPageNo(currentPage);
- page.setPageSize(pageSize);
- page.setTotalRecords(allRow);
- page.setList(list);
- session.flush();
- return page;
- } catch (Exception e) {
- logger.error("exception occurred while performing AlarmsInformationServiceImpl queryAlarmsInformation. Details:" + e.getMessage());
- return null;
- }
+ if (null == alarmsInformation) {
+ //logger.error("AlarmsInformationServiceImpl queryAlarmsInformation alarmsInformation is null!");
+ }else {
+ if(null!=alarmsInformation.getName()) {
+ String ver=alarmsInformation.getName();
+ hql.append(" and a.name like '%"+ver+"%'");
+ }
+ if(null!=alarmsInformation.getValue()) {
+ String ver=alarmsInformation.getValue();
+ hql.append(" and a.value like '%"+ver+"%'");
+ }
+ if(null!=alarmsInformation.getEventId()) {
+ String ver=alarmsInformation.getEventId();
+ hql.append(" and a.eventId = '"+ver+"'");
+ }
+ if(null!=alarmsInformation.getCreateTime()) {
+ Date ver =alarmsInformation.getCreateTime();
+ hql.append(" and a.createTime > '%"+ver+"%'");
+ }
+ if(null!=alarmsInformation.getUpdateTime()) {
+ Date ver =alarmsInformation.getUpdateTime();
+ hql.append(" and a.updateTime like '%"+ver+"%'");
+ }
+ }
+ logger.info("AlarmsInformationServiceImpl queryAlarmsInformation: alarmsInformation={}", alarmsInformation);
+ Query query = session.createQuery(hql.toString());
+ query.setFirstResult(offset);
+ query.setMaxResults(pageSize);
+ List<AlarmsInformation> list= query.list();
+ page.setPageNo(currentPage);
+ page.setPageSize(pageSize);
+ page.setTotalRecords(allRow);
+ page.setList(list);
+ session.flush();
+ return page;
+ } catch (Exception e) {
+ logger.error("exception occurred while performing AlarmsInformationServiceImpl queryAlarmsInformation. Details:" + e.getMessage());
+ return null;
+ }
}
@SuppressWarnings("unchecked")
@@ -178,7 +182,7 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
logger.error("AlarmsInformationServiceImpl queryId is null!");
}
List<AlarmsInformation> list = new ArrayList<AlarmsInformation>();
- Session session = sessionFactory.openSession();
+ Session session = getSession();
Query query = session.createQuery("from AlarmsInformation a where a.eventId IN (:alist)");
list = query.setParameterList("alist", id).list();
session.close();
@@ -192,7 +196,7 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
@Override
public List<Map<String,String>> queryDateBetween(String sourceId, String startTime, String endTime) {
- try(Session session = sessionFactory.openSession();) {
+ try(Session session = getSession()) {
List<Map<String,String>> mapList = new ArrayList<>();
String hql = "select a.createTime,count(*) from AlarmsInformation a where 1=1 ";
if (sourceId != null && !"".equals(sourceId)){
diff --git a/server/src/test/java/org/onap/usecaseui/server/bean/AlarmsHeaderTest.java b/server/src/test/java/org/onap/usecaseui/server/bean/AlarmsHeaderTest.java
index f4bf6e08..1f774b75 100644
--- a/server/src/test/java/org/onap/usecaseui/server/bean/AlarmsHeaderTest.java
+++ b/server/src/test/java/org/onap/usecaseui/server/bean/AlarmsHeaderTest.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onap.usecaseui.server.service.impl;
+package org.onap.usecaseui.server.bean;
import org.junit.Test;
import org.junit.Before;
diff --git a/server/src/test/java/org/onap/usecaseui/server/bean/AlarmsInformationTest.java b/server/src/test/java/org/onap/usecaseui/server/bean/AlarmsInformationTest.java
new file mode 100644
index 00000000..0a66e1e0
--- /dev/null
+++ b/server/src/test/java/org/onap/usecaseui/server/bean/AlarmsInformationTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
+ *
+ * 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.usecaseui.server.bean;
+
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+import org.junit.runner.RunWith;
+import org.onap.usecaseui.server.UsecaseuiServerApplication;
+import org.onap.usecaseui.server.bean.AlarmsInformation;
+import org.onap.usecaseui.server.util.DateUtils;
+import org.onap.usecaseui.server.util.Page;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.io.*;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+public class AlarmsInformationTest implements Serializable {
+
+ @Before
+ public void before() throws Exception {
+ }
+
+ @After
+ public void after() throws Exception {
+ }
+
+ @Test
+ public void testGetAlarmsInformation() throws Exception {
+ AlarmsInformation ai = new AlarmsInformation("name", "value", "eventId", DateUtils.now(), DateUtils.now());
+ ai.getName();
+ ai.getValue();
+ ai.getEventId();
+ ai.getCreateTime();
+ ai.getUpdateTime();
+ ai.getId();
+ ai.toString();
+ }
+
+ @Test
+ public void testSetAlarmsInformation() throws Exception {
+ AlarmsInformation ai = new AlarmsInformation("eventId");
+ ai.setName("");
+ ai.setValue("");
+ ai.setEventId("");
+ ai.setCreateTime(DateUtils.now());
+ ai.setUpdateTime(DateUtils.now());
+ ai.setId(1);
+ }
+}
diff --git a/server/src/test/java/org/onap/usecaseui/server/bean/PerformanceHeaderTest.java b/server/src/test/java/org/onap/usecaseui/server/bean/PerformanceHeaderTest.java
new file mode 100644
index 00000000..e78c01f2
--- /dev/null
+++ b/server/src/test/java/org/onap/usecaseui/server/bean/PerformanceHeaderTest.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
+ *
+ * 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.usecaseui.server.bean;
+
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+import org.junit.runner.RunWith;
+import org.onap.usecaseui.server.UsecaseuiServerApplication;
+import org.onap.usecaseui.server.bean.PerformanceHeader;
+import org.onap.usecaseui.server.util.DateUtils;
+import org.onap.usecaseui.server.util.Page;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.io.*;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+public class PerformanceHeaderTest implements Serializable {
+
+ @Before
+ public void before() throws Exception {
+ }
+
+ @After
+ public void after() throws Exception {
+ }
+
+ @Test
+ public void testGetPerformanceHeader() throws Exception {
+ PerformanceHeader ph = new PerformanceHeader("version", "eventName", "domain", "eventId", "eventType", "nfcNamingCode", "nfNamingCode",
+ "sourceId", "sourceName", "reportingEntityId", "reportingEntityName", "priority",
+ "startEpochMicrosec", "lastEpochMicroSec", "sequence", "measurementsForVfScalingVersion",
+ "measurementInterval", DateUtils.now(), DateUtils.now());
+ ph.getVersion();
+ ph.getEventName();
+ ph.getDomain();
+ ph.getEventId();
+ ph.getEventType();
+ ph.getNfcNamingCode();
+ ph.getNfNamingCode();
+ ph.getSourceId();
+ ph.getSourceName();
+ ph.getReportingEntityId();
+ ph.getReportingEntityName();
+ ph.getPriority();
+ ph.getStartEpochMicrosec();
+ ph.getLastEpochMicroSec();
+ ph.getSequence();
+ ph.getMeasurementsForVfScalingVersion();
+ ph.getMeasurementInterval();
+ ph.getCreateTime();
+ ph.getUpdateTime();
+ }
+
+ @Test
+ public void testSetPerformanceHeader() throws Exception {
+ PerformanceHeader ph = new PerformanceHeader("sourceId");
+ ph.setVersion("");
+ ph.setEventName("");
+ ph.setDomain("");
+ ph.setEventId("");
+ ph.setEventType("");
+ ph.setNfcNamingCode("");
+ ph.setNfNamingCode("");
+ ph.setSourceId("");
+ ph.setSourceName("");
+ ph.setReportingEntityId("");
+ ph.setReportingEntityName("");
+ ph.setPriority("");
+ ph.setStartEpochMicrosec("");
+ ph.setLastEpochMicroSec("");
+ ph.setSequence("");
+ ph.setMeasurementsForVfScalingVersion("");
+ ph.setMeasurementInterval("");
+ ph.setCreateTime(DateUtils.now());
+ ph.setUpdateTime(DateUtils.now());
+ }
+}
diff --git a/server/src/test/java/org/onap/usecaseui/server/bean/PerformanceInformationTest.java b/server/src/test/java/org/onap/usecaseui/server/bean/PerformanceInformationTest.java
new file mode 100644
index 00000000..1d59b156
--- /dev/null
+++ b/server/src/test/java/org/onap/usecaseui/server/bean/PerformanceInformationTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
+ *
+ * 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.usecaseui.server.bean;
+
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+import org.junit.runner.RunWith;
+import org.onap.usecaseui.server.UsecaseuiServerApplication;
+import org.onap.usecaseui.server.bean.PerformanceInformation;
+import org.onap.usecaseui.server.util.DateUtils;
+import org.onap.usecaseui.server.util.Page;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.io.*;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+public class PerformanceInformationTest implements Serializable {
+
+ @Before
+ public void before() throws Exception {
+ }
+
+ @After
+ public void after() throws Exception {
+ }
+
+ @Test
+ public void testGetPerformanceInformation() throws Exception {
+ PerformanceInformation pi = new PerformanceInformation("name", "value", "eventId", DateUtils.now(), DateUtils.now());
+ pi.getName();
+ pi.getValue();
+ pi.getEventId();
+ pi.getCreateTime();
+ pi.getUpdateTime();
+ pi.getId();
+ }
+
+ @Test
+ public void testSetPerformanceInformation() throws Exception {
+ PerformanceInformation pi = new PerformanceInformation("eventId");
+ pi.setName("");
+ pi.setValue("");
+ pi.setEventId("");
+ pi.setCreateTime(DateUtils.now());
+ pi.setUpdateTime(DateUtils.now());
+ pi.setId(1);
+ }
+}
+
diff --git a/server/src/test/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInputTest.java b/server/src/test/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInputTest.java
new file mode 100644
index 00000000..7e19c5b8
--- /dev/null
+++ b/server/src/test/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInputTest.java
@@ -0,0 +1,79 @@
+/**
+ * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
+ *
+ * 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.usecaseui.server.bean.lcm;
+
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+import org.junit.runner.RunWith;
+import org.onap.usecaseui.server.UsecaseuiServerApplication;
+import org.onap.usecaseui.server.bean.lcm.*;
+import org.onap.usecaseui.server.util.DateUtils;
+import org.onap.usecaseui.server.util.Page;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.io.*;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+public class ServiceTemplateInputTest {
+
+ @Before
+ public void before() throws Exception {
+ }
+
+ @After
+ public void after() throws Exception {
+ }
+
+ @Test
+ public void testGetServiceTemplateInput() throws Exception {
+ ServiceTemplateInput sti = new ServiceTemplateInput("invariantUUID", "uuid", "name", "type", "version", "description", "category", "subcategory", null);
+ sti.getInvariantUUID();
+ sti.getUuid();
+ sti.getName();
+ sti.getType();
+ sti.getVersion();
+ sti.getDescription();
+ sti.getCategory();
+ sti.getSubcategory();
+ sti.getInputs();
+ sti.getNestedTemplates();
+ sti.toString();
+ sti.hashCode();
+ }
+
+ @Test
+ public void testSetServiceTemplateInput() throws Exception {
+ ServiceTemplateInput sti = new ServiceTemplateInput("invariantUUID", "uuid", "name", "type", "version", "description", "category", "subcategory", null);
+ sti.addNestedTemplate(null);
+ sti.addInputs(null);
+ sti.addInput(null);
+ sti.setType("type");
+ sti.equals(sti);
+ }
+}
diff --git a/server/src/test/java/org/onap/usecaseui/server/bean/lcm/TemplateInputTest.java b/server/src/test/java/org/onap/usecaseui/server/bean/lcm/TemplateInputTest.java
new file mode 100644
index 00000000..c2ffad8c
--- /dev/null
+++ b/server/src/test/java/org/onap/usecaseui/server/bean/lcm/TemplateInputTest.java
@@ -0,0 +1,70 @@
+/**
+ * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
+ *
+ * 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.usecaseui.server.bean.lcm;
+
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+import org.junit.runner.RunWith;
+import org.onap.usecaseui.server.UsecaseuiServerApplication;
+import org.onap.usecaseui.server.bean.lcm.*;
+import org.onap.usecaseui.server.util.DateUtils;
+import org.onap.usecaseui.server.util.Page;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.io.*;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+public class TemplateInputTest {
+
+ @Before
+ public void before() throws Exception {
+ }
+
+ @After
+ public void after() throws Exception {
+ }
+
+ @Test
+ public void testGetTemplateInput() throws Exception {
+ TemplateInput ti = new TemplateInput("name", "type", "description", "isRequired", "defaultValue");
+ ti.getName();
+ ti.getType();
+ ti.getDescription();
+ ti.getIsRequired();
+ ti.getDefaultValue();
+ ti.toString();
+ ti.hashCode();
+ }
+
+ @Test
+ public void testSetTemplateInput() throws Exception {
+ TemplateInput ti = new TemplateInput("name", "type", "description", "isRequired", "defaultValue");
+ ti.equals(ti);
+ }
+}
diff --git a/server/src/test/java/org/onap/usecaseui/server/bean/lcm/VfNsPackageInfoTest.java b/server/src/test/java/org/onap/usecaseui/server/bean/lcm/VfNsPackageInfoTest.java
new file mode 100644
index 00000000..65c317ea
--- /dev/null
+++ b/server/src/test/java/org/onap/usecaseui/server/bean/lcm/VfNsPackageInfoTest.java
@@ -0,0 +1,66 @@
+/**
+ * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
+ *
+ * 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.usecaseui.server.bean.lcm;
+
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+import org.junit.runner.RunWith;
+import org.onap.usecaseui.server.UsecaseuiServerApplication;
+import org.onap.usecaseui.server.bean.lcm.*;
+import org.onap.usecaseui.server.util.DateUtils;
+import org.onap.usecaseui.server.util.Page;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.io.*;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+public class VfNsPackageInfoTest {
+
+ @Before
+ public void before() throws Exception {
+ }
+
+ @After
+ public void after() throws Exception {
+ }
+
+ @Test
+ public void testGetVfNsPackageInfo() throws Exception {
+ VfNsPackageInfo vpi = new VfNsPackageInfo(null, null);
+ vpi.getNsPackage();
+ vpi.getVnfPackages();
+ vpi.hashCode();
+ }
+
+ @Test
+ public void testSetVfNsPackageInfo() throws Exception {
+ VfNsPackageInfo vpi = new VfNsPackageInfo(null, null);
+ vpi.equals(vpi);
+ }
+}
diff --git a/server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImplTest.java b/server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImplTest.java
new file mode 100644
index 00000000..7cc8c750
--- /dev/null
+++ b/server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImplTest.java
@@ -0,0 +1,268 @@
+/**
+ * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
+ *
+ * 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.usecaseui.server.service.impl;
+
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+import org.junit.runner.RunWith;
+import org.onap.usecaseui.server.UsecaseuiServerApplication;
+import org.onap.usecaseui.server.bean.AlarmsInformation;
+import org.onap.usecaseui.server.service.impl.AlarmsInformationServiceImpl;
+import org.onap.usecaseui.server.util.DateUtils;
+import org.onap.usecaseui.server.util.Page;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.io.*;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+/**
+* AlarmsInformationServiceImpl Tester.
+*
+* @author <Authors name>
+* @since <pre>8, 2018</pre>
+* @version 1.0
+*/
+public class AlarmsInformationServiceImplTest {
+ AlarmsInformationServiceImpl alarmsInformationServiceImpl = null;
+ private static final long serialVersionUID = 1L;
+
+ @Before
+ public void before() throws Exception {
+ alarmsInformationServiceImpl = new AlarmsInformationServiceImpl();
+
+ MockUp<Transaction> mockUpTransaction = new MockUp<Transaction>() {
+ @Mock
+ public void commit() {
+ }
+ };
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+ };
+ new MockUp<Query>() {
+ @Mock
+ public Query setString(String name, String value) {
+ return mockUpQuery.getMockInstance();
+ }
+ @Mock
+ public Query setDate(String name, Date value) {
+ return mockUpQuery.getMockInstance();
+ }
+ @Mock
+ public Query setInteger(String name, int value) {
+ return mockUpQuery.getMockInstance();
+ }
+ @Mock
+ public int executeUpdate() {
+ return 0;
+ }
+ @Mock
+ public Query setMaxResults(int value) {
+ return mockUpQuery.getMockInstance();
+ }
+ @Mock
+ public Query setFirstResult(int firstResult) {
+ return mockUpQuery.getMockInstance();
+ }
+ @Mock
+ public Query setParameterList(String name, Object[] values) {
+ return mockUpQuery.getMockInstance();
+ }
+ @Mock
+ public List<AlarmsInformation> list() {
+ AlarmsInformation ai = new AlarmsInformation();
+ return Arrays.asList(ai);
+ }
+ @Mock
+ public Object uniqueResult() {
+ return "0";
+ }
+ };
+ MockUp<Session> mockedSession = new MockUp<Session>() {
+ @Mock
+ public Query createQuery(String sql) {
+ return mockUpQuery.getMockInstance();
+ }
+ @Mock
+ public Transaction beginTransaction() {
+ return mockUpTransaction.getMockInstance();
+ }
+ @Mock
+ public Transaction getTransaction() {
+ return mockUpTransaction.getMockInstance();
+ }
+ @Mock
+ public Serializable save(Object object) {
+ return (Serializable) serialVersionUID;
+ }
+ @Mock
+ public void flush() {
+ }
+ @Mock
+ public void update(Object object) {
+ }
+ };
+ new MockUp<SessionFactory>() {
+ @Mock
+ public Session openSession() {
+ return mockedSession.getMockInstance();
+ }
+ };
+ new MockUp<AlarmsInformationServiceImpl>() {
+ @Mock
+ private Session getSession() {
+ return mockedSession.getMockInstance();
+ }
+ };
+ }
+
+ @After
+ public void after() throws Exception {
+ }
+
+ @Test
+ public void testSaveAlarmsInformation() throws Exception {
+ AlarmsInformation ai = null;
+ alarmsInformationServiceImpl.saveAlarmsInformation(ai);
+ }
+
+ @Test
+ public void testUpdateAlarmsInformation() throws Exception {
+ AlarmsInformation ai = null;
+ alarmsInformationServiceImpl.updateAlarmsInformation(ai);
+ }
+
+ @Test
+ public void testGetAllCount() throws Exception {
+ new MockUp<Query>() {
+ @Mock
+ public Object uniqueResult() {
+ return "1";
+ }
+ };
+ AlarmsInformation ai = new AlarmsInformation();
+ ai.getName();
+ ai.getValue();
+ ai.getEventId();
+ ai.getCreateTime();
+ ai.getUpdateTime();
+ alarmsInformationServiceImpl.getAllCount(ai, 1, 1);
+ }
+
+ @Test
+ public void testQueryAlarmsInformation() throws Exception {
+ AlarmsInformation ai = new AlarmsInformation();
+ ai.getName();
+ ai.getValue();
+ ai.getEventId();
+ ai.getCreateTime();
+ ai.getUpdateTime();
+ alarmsInformationServiceImpl.queryAlarmsInformation(ai, 1, 1);
+ }
+
+ @Test
+ public void testQueryId() throws Exception {
+ String[] id = {"1", "2", "3"};
+ alarmsInformationServiceImpl.queryId(id);
+ }
+
+ @Test
+ public void testQueryDateBetween() throws Exception {
+ alarmsInformationServiceImpl.queryDateBetween("sourceId", "startTime", "endTime");
+ }
+
+ @Test(expected = Exception.class)
+ public void testSaveAlarmsInformationException() throws Exception {
+ new MockUp<AlarmsInformationServiceImpl>() {
+ @Mock
+ private Session getSession() throws Exception {
+ throw new Exception();
+ }
+ };
+ AlarmsInformation ai = new AlarmsInformation();
+ alarmsInformationServiceImpl.saveAlarmsInformation(ai);
+ }
+
+ @Test(expected = Exception.class)
+ public void testUpdateAlarmsInformationException() throws Exception {
+ new MockUp<AlarmsInformationServiceImpl>() {
+ @Mock
+ private Session getSession() throws Exception {
+ throw new Exception();
+ }
+ };
+ AlarmsInformation ai = new AlarmsInformation();
+ alarmsInformationServiceImpl.updateAlarmsInformation(ai);
+ }
+
+ @Test(expected = Exception.class)
+ public void testGetAllCountException() throws Exception {
+ new MockUp<AlarmsInformationServiceImpl>() {
+ @Mock
+ private Session getSession() throws Exception {
+ throw new Exception();
+ }
+ };
+ AlarmsInformation ai = new AlarmsInformation();
+ alarmsInformationServiceImpl.getAllCount(ai, 1, 1);
+ }
+
+ @Test(expected = Exception.class)
+ public void testQueryAlarmsInformationException() throws Exception {
+ new MockUp<AlarmsInformationServiceImpl>() {
+ @Mock
+ private Session getSession() throws Exception {
+ throw new Exception();
+ }
+ };
+ AlarmsInformation ai = new AlarmsInformation();
+ alarmsInformationServiceImpl.queryAlarmsInformation(ai, 1, 1);
+ }
+
+ @Test(expected = Exception.class)
+ public void testQueryIdException() throws Exception {
+ new MockUp<AlarmsInformationServiceImpl>() {
+ @Mock
+ private Session getSession() throws Exception {
+ throw new Exception();
+ }
+ };
+ String[] id = {"1", "2", "3"};
+ alarmsInformationServiceImpl.queryId(id);
+ }
+
+ @Test(expected = Exception.class)
+ public void testQueryDateBetweenException() throws Exception {
+ new MockUp<AlarmsInformationServiceImpl>() {
+ @Mock
+ private Session getSession() throws Exception {
+ throw new Exception();
+ }
+ };
+ alarmsInformationServiceImpl.queryDateBetween("sourceId", "startTime", "endTime");
+ }
+}