improve sonar coverage for uui-server 21/42921/1
authorzhangab <zhanganbing@chinamobile.com>
Mon, 16 Apr 2018 03:56:13 +0000 (11:56 +0800)
committerzhangab <zhanganbing@chinamobile.com>
Mon, 16 Apr 2018 03:56:17 +0000 (11:56 +0800)
Change-Id: I3c867c1493290e730b6bec7f050cf1e57a0f5cd4
Issue-ID: USECASEUI-103
Signed-off-by: zhangab <zhanganbing@chinamobile.com>
server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java
server/src/test/java/org/onap/usecaseui/server/bean/AlarmsHeaderTest.java
server/src/test/java/org/onap/usecaseui/server/bean/AlarmsInformationTest.java [new file with mode: 0644]
server/src/test/java/org/onap/usecaseui/server/bean/PerformanceHeaderTest.java [new file with mode: 0644]
server/src/test/java/org/onap/usecaseui/server/bean/PerformanceInformationTest.java [new file with mode: 0644]
server/src/test/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInputTest.java [new file with mode: 0644]
server/src/test/java/org/onap/usecaseui/server/bean/lcm/TemplateInputTest.java [new file with mode: 0644]
server/src/test/java/org/onap/usecaseui/server/bean/lcm/VfNsPackageInfoTest.java [new file with mode: 0644]
server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImplTest.java [new file with mode: 0644]

index 32eec76..c12576d 100755 (executable)
@@ -40,83 +40,87 @@ import org.springframework.stereotype.Service;
 @org.springframework.context.annotation.Configuration\r
 @EnableAspectJAutoProxy\r
 public class AlarmsInformationServiceImpl implements AlarmsInformationService {\r
-    private static final Logger logger = LoggerFactory.getLogger(AlarmsInformationServiceImpl.class);\r
+       private static final Logger logger = LoggerFactory.getLogger(AlarmsInformationServiceImpl.class);\r
 \r
-    @Autowired\r
-    private SessionFactory sessionFactory;\r
+       @Autowired\r
+       private SessionFactory sessionFactory;\r
+\r
+       private Session getSession() {\r
+               return sessionFactory.openSession();\r
+       }\r
 \r
        @Override\r
        public String saveAlarmsInformation(AlarmsInformation alarmsInformation) {\r
-                try(Session session = sessionFactory.openSession();){\r
-                   if (null == alarmsInformation) {\r
-                       logger.error("alarmsInformation saveAlarmsInformation alarmsInformation is null!");\r
-                   }\r
-                   logger.info("AlarmsInformationServiceImpl saveAlarmsInformation: alarmsInformation={}", alarmsInformation);\r
-                   Transaction tx = session.beginTransaction();     \r
-                   session.save(alarmsInformation);\r
-                   tx.commit();\r
-                   session.flush();\r
-                   return "1";\r
-               } catch (Exception e) {\r
-                   logger.error("exception occurred while performing AlarmsInformationServiceImpl saveAlarmsInformation. Details:" + e.getMessage());\r
-                   return "0";\r
-               }\r
-               \r
+                try(Session session = getSession()){\r
+                               if (null == alarmsInformation) {\r
+                                       logger.error("alarmsInformation saveAlarmsInformation alarmsInformation is null!");\r
+                               }\r
+                               logger.info("AlarmsInformationServiceImpl saveAlarmsInformation: alarmsInformation={}", alarmsInformation);\r
+                               Transaction tx = session.beginTransaction();\r
+                               session.save(alarmsInformation);\r
+                               tx.commit();\r
+                               session.flush();\r
+                               return "1";\r
+                       } catch (Exception e) {\r
+                               logger.error("exception occurred while performing AlarmsInformationServiceImpl saveAlarmsInformation. Details:" + e.getMessage());\r
+                               return "0";\r
+                       }\r
+                       \r
        }\r
 \r
        @Override\r
        public String updateAlarmsInformation(AlarmsInformation alarmsInformation) {\r
-               try(Session session = sessionFactory.openSession();){\r
-            if (null == alarmsInformation) {\r
-                logger.error("alarmsInformation updateAlarmsInformation alarmsInformation is null!");\r
-            }\r
-            logger.info("AlarmsInformationServiceImpl updateAlarmsInformation: alarmsInformation={}", alarmsInformation);\r
-            Transaction tx = session.beginTransaction();     \r
-            session.update(alarmsInformation);\r
-            tx.commit();\r
-            session.flush();\r
-            return "1";\r
-        } catch (Exception e) {\r
-            logger.error("exception occurred while performing AlarmsInformationServiceImpl updateAlarmsInformation. Details:" + e.getMessage());\r
-            return "0";\r
-        }\r
+               try(Session session = getSession()){\r
+                       if (null == alarmsInformation) {\r
+                               logger.error("alarmsInformation updateAlarmsInformation alarmsInformation is null!");\r
+                       }\r
+                       logger.info("AlarmsInformationServiceImpl updateAlarmsInformation: alarmsInformation={}", alarmsInformation);\r
+                       Transaction tx = session.beginTransaction();\r
+                       session.update(alarmsInformation);\r
+                       tx.commit();\r
+                       session.flush();\r
+                       return "1";\r
+               } catch (Exception e) {\r
+                       logger.error("exception occurred while performing AlarmsInformationServiceImpl updateAlarmsInformation. Details:" + e.getMessage());\r
+                       return "0";\r
+               }\r
        }\r
        \r
 \r
        public int getAllCount(AlarmsInformation alarmsInformation, int currentPage, int pageSize) {\r
-               try(Session session = sessionFactory.openSession();){\r
+               try(Session session = getSession()){\r
                        StringBuffer hql = new StringBuffer("select count(*) from AlarmsInformation a where 1=1");\r
                        if (null == alarmsInformation) {\r
-                //logger.error("AlarmsInformationServiceImpl getAllCount alarmsInformation is null!");\r
-            }else {\r
-               if(null!=alarmsInformation.getName()) {\r
-                       String ver=alarmsInformation.getName();\r
-                       hql.append(" and a.name like '%"+ver+"%'");\r
-                }\r
-               if(null!=alarmsInformation.getValue()) {\r
-                       String ver=alarmsInformation.getValue();\r
-                       hql.append(" and a.value like '%"+ver+"%'");\r
-                }\r
-               if(null!=alarmsInformation.getEventId()) {\r
-                       String ver=alarmsInformation.getEventId();\r
-                       hql.append(" and a.eventId = '"+ver+"'");\r
-                }\r
-               if(null!=alarmsInformation.getCreateTime()) {\r
-                       Date ver =alarmsInformation.getCreateTime();\r
-                       hql.append(" and a.createTime > '%"+ver+"%'");\r
-                }\r
-               if(null!=alarmsInformation.getUpdateTime()) {\r
-                       Date ver =alarmsInformation.getUpdateTime();\r
-                       hql.append(" and a.updateTime like '%"+ver+"%'");\r
-                }\r
-            } \r
-            long q=(long)session.createQuery(hql.toString()).uniqueResult();\r
-            session.flush();\r
-            return (int)q;\r
-        } catch (Exception e) {\r
-            logger.error("exception occurred while performing AlarmsInformationServiceImpl getAllCount. Details:" + e.getMessage());\r
-            return 0;\r
-        }\r
+                               logger.error("AlarmsInformationServiceImpl getAllCount alarmsInformation is null!");\r
+                       }else {\r
+                               if(null!=alarmsInformation.getName()) {\r
+                                       String ver=alarmsInformation.getName();\r
+                                       hql.append(" and a.name like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=alarmsInformation.getValue()) {\r
+                                       String ver=alarmsInformation.getValue();\r
+                                       hql.append(" and a.value like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=alarmsInformation.getEventId()) {\r
+                                       String ver=alarmsInformation.getEventId();\r
+                                       hql.append(" and a.eventId = '"+ver+"'");\r
+                               }\r
+                               if(null!=alarmsInformation.getCreateTime()) {\r
+                                       Date ver =alarmsInformation.getCreateTime();\r
+                                       hql.append(" and a.createTime > '%"+ver+"%'");\r
+                               }\r
+                               if(null!=alarmsInformation.getUpdateTime()) {\r
+                                       Date ver =alarmsInformation.getUpdateTime();\r
+                                       hql.append(" and a.updateTime like '%"+ver+"%'");\r
+                               }\r
+                       \r
+                       long q=(long)session.createQuery(hql.toString()).uniqueResult();\r
+                       session.flush();\r
+                       return (int)q;\r
+               } catch (Exception e) {\r
+                       logger.error("exception occurred while performing AlarmsInformationServiceImpl getAllCount. Details:" + e.getMessage());\r
+                       return 0;\r
+               }\r
        }\r
 \r
        @SuppressWarnings("unchecked")\r
@@ -127,47 +131,47 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
                int allRow =this.getAllCount(alarmsInformation,currentPage,pageSize);\r
                int offset = page.countOffset(currentPage, pageSize);\r
                \r
-               try(Session session = sessionFactory.openSession();){\r
+               try(Session session = getSession()){\r
                        StringBuffer hql =new StringBuffer("from AlarmsInformation a where 1=1");\r
-            if (null == alarmsInformation) {\r
-                //logger.error("AlarmsInformationServiceImpl queryAlarmsInformation alarmsInformation is null!");\r
-            }else {\r
-               if(null!=alarmsInformation.getName()) {\r
-                       String ver=alarmsInformation.getName();\r
-                       hql.append(" and a.name like '%"+ver+"%'");\r
-                }\r
-               if(null!=alarmsInformation.getValue()) {\r
-                       String ver=alarmsInformation.getValue();\r
-                       hql.append(" and a.value like '%"+ver+"%'");\r
-                }\r
-               if(null!=alarmsInformation.getEventId()) {\r
-                       String ver=alarmsInformation.getEventId();\r
-                       hql.append(" and a.eventId = '"+ver+"'");\r
-                }\r
-               if(null!=alarmsInformation.getCreateTime()) {\r
-                       Date ver =alarmsInformation.getCreateTime();\r
-                       hql.append(" and a.createTime > '%"+ver+"%'");\r
-                }\r
-               if(null!=alarmsInformation.getUpdateTime()) {\r
-                       Date ver =alarmsInformation.getUpdateTime();\r
-                       hql.append(" and a.updateTime like '%"+ver+"%'");\r
-                }\r
-            }\r
-            logger.info("AlarmsInformationServiceImpl queryAlarmsInformation: alarmsInformation={}", alarmsInformation);\r
-            Query query = session.createQuery(hql.toString());\r
-            query.setFirstResult(offset);\r
-            query.setMaxResults(pageSize);\r
-            List<AlarmsInformation> list= query.list();\r
-            page.setPageNo(currentPage);\r
-            page.setPageSize(pageSize);\r
-            page.setTotalRecords(allRow);\r
-            page.setList(list);\r
-            session.flush();\r
-            return page;\r
-        } catch (Exception e) {\r
-            logger.error("exception occurred while performing AlarmsInformationServiceImpl queryAlarmsInformation. Details:" + e.getMessage());\r
-            return null;\r
-        }\r
+                       if (null == alarmsInformation) {\r
+                               //logger.error("AlarmsInformationServiceImpl queryAlarmsInformation alarmsInformation is null!");\r
+                       }else {\r
+                               if(null!=alarmsInformation.getName()) {\r
+                                       String ver=alarmsInformation.getName();\r
+                                       hql.append(" and a.name like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=alarmsInformation.getValue()) {\r
+                                       String ver=alarmsInformation.getValue();\r
+                                       hql.append(" and a.value like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=alarmsInformation.getEventId()) {\r
+                                       String ver=alarmsInformation.getEventId();\r
+                                       hql.append(" and a.eventId = '"+ver+"'");\r
+                               }\r
+                               if(null!=alarmsInformation.getCreateTime()) {\r
+                                       Date ver =alarmsInformation.getCreateTime();\r
+                                       hql.append(" and a.createTime > '%"+ver+"%'");\r
+                               }\r
+                               if(null!=alarmsInformation.getUpdateTime()) {\r
+                                       Date ver =alarmsInformation.getUpdateTime();\r
+                                       hql.append(" and a.updateTime like '%"+ver+"%'");\r
+                               }\r
+                       }\r
+                       logger.info("AlarmsInformationServiceImpl queryAlarmsInformation: alarmsInformation={}", alarmsInformation);\r
+                       Query query = session.createQuery(hql.toString());\r
+                       query.setFirstResult(offset);\r
+                       query.setMaxResults(pageSize);\r
+                       List<AlarmsInformation> list= query.list();\r
+                       page.setPageNo(currentPage);\r
+                       page.setPageSize(pageSize);\r
+                       page.setTotalRecords(allRow);\r
+                       page.setList(list);\r
+                       session.flush();\r
+                       return page;\r
+               } catch (Exception e) {\r
+                       logger.error("exception occurred while performing AlarmsInformationServiceImpl queryAlarmsInformation. Details:" + e.getMessage());\r
+                       return null;\r
+               }\r
        }\r
 \r
        @SuppressWarnings("unchecked")\r
@@ -178,7 +182,7 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
                                logger.error("AlarmsInformationServiceImpl queryId is null!");\r
                        }\r
                        List<AlarmsInformation> list = new ArrayList<AlarmsInformation>();\r
-                       Session session = sessionFactory.openSession();\r
+                       Session session = getSession();\r
                        Query query = session.createQuery("from AlarmsInformation a where a.eventId IN (:alist)");\r
                        list = query.setParameterList("alist", id).list();\r
                        session.close();\r
@@ -192,7 +196,7 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
 \r
        @Override\r
        public List<Map<String,String>> queryDateBetween(String sourceId, String startTime, String endTime) {\r
-               try(Session session = sessionFactory.openSession();) {\r
+               try(Session session = getSession()) {\r
                        List<Map<String,String>> mapList = new ArrayList<>();\r
                        String hql = "select a.createTime,count(*) from AlarmsInformation a where 1=1 ";\r
                        if (sourceId != null && !"".equals(sourceId)){\r
index f4bf6e0..1f774b7 100644 (file)
@@ -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 (file)
index 0000000..0a66e1e
--- /dev/null
@@ -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 (file)
index 0000000..e78c01f
--- /dev/null
@@ -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 (file)
index 0000000..1d59b15
--- /dev/null
@@ -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 (file)
index 0000000..7e19c5b
--- /dev/null
@@ -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 (file)
index 0000000..c2ffad8
--- /dev/null
@@ -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 (file)
index 0000000..65c317e
--- /dev/null
@@ -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 (file)
index 0000000..7cc8c75
--- /dev/null
@@ -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");
+       }
+}