improve sonar coverage for uui-server 47/42947/1
authorzhangab <zhanganbing@chinamobile.com>
Mon, 16 Apr 2018 06:38:14 +0000 (14:38 +0800)
committerzhangab <zhanganbing@chinamobile.com>
Mon, 16 Apr 2018 06:38:18 +0000 (14:38 +0800)
Change-Id: I84c132c8b17bfaed9a870a3c6dc6f0876c95a575
Issue-ID: USECASEUI-103
Signed-off-by: zhangab <zhanganbing@chinamobile.com>
server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java
server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java
server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImplTest.java
server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImplTest.java [new file with mode: 0644]
server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImplTest.java [new file with mode: 0644]

index 39828fa..6abc201 100755 (executable)
@@ -1,4 +1,4 @@
-/*\r
+/**\r
  * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
@@ -41,253 +41,251 @@ import org.springframework.stereotype.Service;
 @org.springframework.context.annotation.Configuration\r
 @EnableAspectJAutoProxy\r
 public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {\r
-       \r
-    private static final Logger logger = LoggerFactory.getLogger(PerformanceHeaderServiceImpl.class);\r
 \r
-    @Autowired\r
-    private SessionFactory sessionFactory;\r
+       private static final Logger logger = LoggerFactory.getLogger(PerformanceHeaderServiceImpl.class);\r
 \r
+       @Autowired\r
+       private SessionFactory sessionFactory;\r
+\r
+       private Session getSession() {\r
+               return sessionFactory.openSession();\r
+       }\r
 \r
        @Override\r
        public String savePerformanceHeader(PerformanceHeader performanceHeder) {\r
-                try(Session session = sessionFactory.openSession();){\r
-                   if (null == performanceHeder){\r
-                       logger.error("PerformanceHeaderServiceImpl savePerformanceHeader performanceHeder is null!");\r
-                   }\r
-                   logger.info("PerformanceHeaderServiceImpl savePerformanceHeader: performanceHeder={}", performanceHeder);\r
-                   Transaction tx = session.beginTransaction();     \r
-                   session.save(performanceHeder);\r
-                   tx.commit();\r
-                   session.flush();\r
-                   return "1";\r
-               } catch (Exception e) {\r
-                   logger.error("exception occurred while performing PerformanceHeaderServiceImpl savePerformanceHeader. Details:" + e.getMessage());\r
-                   return "0";\r
-               }\r
-               \r
+                try(Session session = getSession()){\r
+                       if (null == performanceHeder){\r
+                               logger.error("PerformanceHeaderServiceImpl savePerformanceHeader performanceHeder is null!");\r
+                       }\r
+                       logger.info("PerformanceHeaderServiceImpl savePerformanceHeader: performanceHeder={}", performanceHeder);\r
+                       Transaction tx = session.beginTransaction();\r
+                       session.save(performanceHeder);\r
+                       tx.commit();\r
+                       session.flush();\r
+                       return "1";\r
+               } catch (Exception e) {\r
+                       logger.error("exception occurred while performing PerformanceHeaderServiceImpl savePerformanceHeader. Details:" + e.getMessage());\r
+                       return "0";\r
+               }\r
        }\r
 \r
-\r
        @Override\r
        public String updatePerformanceHeader(PerformanceHeader performanceHeder) {\r
-               try(Session session = sessionFactory.openSession();){\r
-            if (null == performanceHeder){\r
-                logger.error("PerformanceHeaderServiceImpl updatePerformanceHeader performanceHeder is null!");\r
-            }\r
-            logger.info("PerformanceHeaderServiceImpl updatePerformanceHeader: performanceHeder={}", performanceHeder);\r
-            Transaction tx = session.beginTransaction();     \r
-            session.update(performanceHeder);\r
-            tx.commit();\r
-            session.flush();\r
-            return "1";\r
-        } catch (Exception e) {\r
-            logger.error("exception occurred while performing PerformanceHeaderServiceImpl updatePerformanceHeader. Details:" + e.getMessage());\r
-            return "0";\r
-        }\r
+               try(Session session = getSession()){\r
+                       if (null == performanceHeder){\r
+                               logger.error("PerformanceHeaderServiceImpl updatePerformanceHeader performanceHeder is null!");\r
+                       }\r
+                       logger.info("PerformanceHeaderServiceImpl updatePerformanceHeader: performanceHeder={}", performanceHeder);\r
+                       Transaction tx = session.beginTransaction();\r
+                       session.update(performanceHeder);\r
+                       tx.commit();\r
+                       session.flush();\r
+                       return "1";\r
+               } catch (Exception e) {\r
+                       logger.error("exception occurred while performing PerformanceHeaderServiceImpl updatePerformanceHeader. Details:" + e.getMessage());\r
+                       return "0";\r
+               }\r
        }\r
 \r
-\r
        public int getAllCount(PerformanceHeader performanceHeder, int currentPage, int pageSize) {\r
-               try(Session session = sessionFactory.openSession();){\r
+               try(Session session = getSession()){\r
                        StringBuffer hql = new StringBuffer("select count(*) from PerformanceHeader a where 1=1");\r
                        if (null == performanceHeder) {\r
-                //logger.error("PerformanceHeaderServiceImpl getAllCount performanceHeder is null!");\r
-            }else {\r
-               if(null!=performanceHeder.getVersion()) {\r
-                       String ver=performanceHeder.getVersion();\r
-                       hql.append(" and a.version like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getEventName()) {\r
-                       String ver=performanceHeder.getEventName();\r
-                       hql.append(" and a.eventName like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getDomain()) {\r
-                       String ver=performanceHeder.getDomain();\r
-                       hql.append(" and a.domain like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getEventId()) {\r
-                       String ver=performanceHeder.getEventId();\r
-                       hql.append(" and a.eventId = '"+ver+"'");\r
-                }\r
-               if(null!=performanceHeder.getNfcNamingCode()) {\r
-                       String ver=performanceHeder.getNfcNamingCode();\r
-                       hql.append(" and a.nfcNamingCode like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getNfNamingCode()) {\r
-                       String ver=performanceHeder.getNfNamingCode();\r
-                       hql.append(" and a.nfNamingCode like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getSourceId()) {\r
-                       String ver =performanceHeder.getSourceId();\r
-                       hql.append(" and a.sourceId like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getSourceName()) {\r
-                       String ver =performanceHeder.getSourceName();\r
-                       hql.append(" and a.sourceName like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getReportingEntityId()) {\r
-                       String ver =performanceHeder.getReportingEntityId();\r
-                       hql.append(" and a.reportingEntityId like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getReportingEntityName()) {\r
-                       String ver =performanceHeder.getReportingEntityName();\r
-                       hql.append(" and a.reportingEntityName like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getPriority()) {\r
-                       String ver =performanceHeder.getPriority();\r
-                       hql.append(" and a.priority like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getStartEpochMicrosec()) {\r
-                       String ver =performanceHeder.getStartEpochMicrosec();\r
-                       hql.append(" and a.startEpochMicrosec like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getLastEpochMicroSec()) {\r
-                       String ver =performanceHeder.getLastEpochMicroSec();\r
-                       hql.append(" and a.lastEpochMicroSec like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getSequence()) {\r
-                       String ver =performanceHeder.getSequence();\r
-                       hql.append(" and a.sequence like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getMeasurementsForVfScalingVersion()) {\r
-                       String ver =performanceHeder.getMeasurementsForVfScalingVersion();\r
-                       hql.append(" and a.measurementsForVfScalingVersion like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getMeasurementInterval()) {\r
-                       String ver =performanceHeder.getMeasurementInterval();\r
-                       hql.append(" and a.measurementInterval like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getEventType()) {\r
-                       String ver =performanceHeder.getEventType();\r
-                       hql.append(" and a.eventType like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getCreateTime() && null!=performanceHeder.getUpdateTime()) {\r
-                       hql.append(" and a.createTime between :startTime and :endTime ");\r
-                }\r
-            }\r
-            Query query = session.createQuery(hql.toString());\r
+                               logger.error("PerformanceHeaderServiceImpl getAllCount performanceHeder is null!");\r
+                       }else {\r
+                               if(null!=performanceHeder.getVersion()) {\r
+                                       String ver=performanceHeder.getVersion();\r
+                                       hql.append(" and a.version like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getEventName()) {\r
+                                       String ver=performanceHeder.getEventName();\r
+                                       hql.append(" and a.eventName like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getDomain()) {\r
+                                       String ver=performanceHeder.getDomain();\r
+                                       hql.append(" and a.domain like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getEventId()) {\r
+                                       String ver=performanceHeder.getEventId();\r
+                                       hql.append(" and a.eventId = '"+ver+"'");\r
+                               }\r
+                               if(null!=performanceHeder.getNfcNamingCode()) {\r
+                                       String ver=performanceHeder.getNfcNamingCode();\r
+                                       hql.append(" and a.nfcNamingCode like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getNfNamingCode()) {\r
+                                       String ver=performanceHeder.getNfNamingCode();\r
+                                       hql.append(" and a.nfNamingCode like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getSourceId()) {\r
+                                       String ver =performanceHeder.getSourceId();\r
+                                       hql.append(" and a.sourceId like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getSourceName()) {\r
+                                       String ver =performanceHeder.getSourceName();\r
+                                       hql.append(" and a.sourceName like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getReportingEntityId()) {\r
+                                       String ver =performanceHeder.getReportingEntityId();\r
+                                       hql.append(" and a.reportingEntityId like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getReportingEntityName()) {\r
+                                       String ver =performanceHeder.getReportingEntityName();\r
+                                       hql.append(" and a.reportingEntityName like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getPriority()) {\r
+                                       String ver =performanceHeder.getPriority();\r
+                                       hql.append(" and a.priority like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getStartEpochMicrosec()) {\r
+                                       String ver =performanceHeder.getStartEpochMicrosec();\r
+                                       hql.append(" and a.startEpochMicrosec like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getLastEpochMicroSec()) {\r
+                                       String ver =performanceHeder.getLastEpochMicroSec();\r
+                                       hql.append(" and a.lastEpochMicroSec like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getSequence()) {\r
+                                       String ver =performanceHeder.getSequence();\r
+                                       hql.append(" and a.sequence like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getMeasurementsForVfScalingVersion()) {\r
+                                       String ver =performanceHeder.getMeasurementsForVfScalingVersion();\r
+                                       hql.append(" and a.measurementsForVfScalingVersion like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getMeasurementInterval()) {\r
+                                       String ver =performanceHeder.getMeasurementInterval();\r
+                                       hql.append(" and a.measurementInterval like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getEventType()) {\r
+                                       String ver =performanceHeder.getEventType();\r
+                                       hql.append(" and a.eventType like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getCreateTime() && null!=performanceHeder.getUpdateTime()) {\r
+                                       hql.append(" and a.createTime between :startTime and :endTime ");\r
+                               }\r
+                       }\r
+                       Query query = session.createQuery(hql.toString());\r
                        if(null!=performanceHeder.getCreateTime() && null!=performanceHeder.getUpdateTime()) {\r
                                query.setDate("startTime",performanceHeder.getCreateTime()).setDate("endTime",performanceHeder.getUpdateTime());\r
                        }\r
-            long q=(long)query.uniqueResult();\r
-            session.flush();\r
-            return (int)q;\r
-        } catch (Exception e) {\r
-            logger.error("exception occurred while performing PerformanceHeaderServiceImpl getAllCount. Details:" + e.getMessage());\r
-            return 0;\r
-        }\r
+                       long q=(long)query.uniqueResult();\r
+                       session.flush();\r
+                       return (int)q;\r
+               } catch (Exception e) {\r
+                       logger.error("exception occurred while performing PerformanceHeaderServiceImpl getAllCount. Details:" + e.getMessage());\r
+                       return 0;\r
+               }\r
        }\r
 \r
        @SuppressWarnings("unchecked")\r
        @Override\r
-       public Page<PerformanceHeader> queryPerformanceHeader(PerformanceHeader performanceHeder, int currentPage,\r
-                       int pageSize) {\r
+       public Page<PerformanceHeader> queryPerformanceHeader(PerformanceHeader performanceHeder, int currentPage, int pageSize) {\r
                Page<PerformanceHeader> page = new Page<PerformanceHeader>();\r
                int allRow =this.getAllCount(performanceHeder,currentPage,pageSize);\r
                int offset = page.countOffset(currentPage, pageSize);\r
-               \r
-               try(Session session = sessionFactory.openSession();){\r
+\r
+               try(Session session = getSession()){\r
                        StringBuffer hql =new StringBuffer("from PerformanceHeader a where 1=1");\r
-            if (null == performanceHeder) {\r
-                //logger.error("PerformanceHeaderServiceImpl queryPerformanceHeader performanceHeder is null!");\r
-            }else {\r
-               if(null!=performanceHeder.getVersion()) {\r
-                       String ver=performanceHeder.getVersion();\r
-                       hql.append(" and a.version like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getEventName()) {\r
-                       String ver=performanceHeder.getEventName();\r
-                       hql.append(" and a.eventName like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getDomain()) {\r
-                       String ver=performanceHeder.getDomain();\r
-                       hql.append(" and a.domain like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getEventId()) {\r
-                       String ver=performanceHeder.getEventId();\r
-                       hql.append(" and a.eventId = '"+ver+"'");\r
-                }\r
-               if(null!=performanceHeder.getNfcNamingCode()) {\r
-                       String ver=performanceHeder.getNfcNamingCode();\r
-                       hql.append(" and a.nfcNamingCode like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getNfNamingCode()) {\r
-                       String ver=performanceHeder.getNfNamingCode();\r
-                       hql.append(" and a.nfNamingCode like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getSourceId()) {\r
-                       String ver =performanceHeder.getSourceId();\r
-                       hql.append(" and a.sourceId = '"+ver+"'");\r
-                }\r
-               if(null!=performanceHeder.getSourceName()) {\r
-                       String ver =performanceHeder.getSourceName();\r
-                       hql.append(" and a.sourceName like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getReportingEntityId()) {\r
-                       String ver =performanceHeder.getReportingEntityId();\r
-                       hql.append(" and a.reportingEntityId like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getReportingEntityName()) {\r
-                       String ver =performanceHeder.getReportingEntityName();\r
-                       hql.append(" and a.reportingEntityName like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getPriority()) {\r
-                       String ver =performanceHeder.getPriority();\r
-                       hql.append(" and a.priority like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getStartEpochMicrosec()) {\r
-                       String ver =performanceHeder.getStartEpochMicrosec();\r
-                       hql.append(" and a.startEpochMicrosec like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getLastEpochMicroSec()) {\r
-                       String ver =performanceHeder.getLastEpochMicroSec();\r
-                       hql.append(" and a.lastEpochMicroSec like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getSequence()) {\r
-                       String ver =performanceHeder.getSequence();\r
-                       hql.append(" and a.sequence like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getMeasurementsForVfScalingVersion()) {\r
-                       String ver =performanceHeder.getMeasurementsForVfScalingVersion();\r
-                       hql.append(" and a.measurementsForVfScalingVersion like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getMeasurementInterval()) {\r
-                       String ver =performanceHeder.getMeasurementInterval();\r
-                       hql.append(" and a.measurementInterval like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceHeder.getEventType()) {\r
-                       String ver =performanceHeder.getEventType();\r
-                       hql.append(" and a.eventType like '%"+ver+"%'");\r
-                }\r
+                       if (null == performanceHeder) {\r
+                               //logger.error("PerformanceHeaderServiceImpl queryPerformanceHeader performanceHeder is null!");\r
+                       }else {\r
+                               if(null!=performanceHeder.getVersion()) {\r
+                                       String ver=performanceHeder.getVersion();\r
+                                       hql.append(" and a.version like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getEventName()) {\r
+                                       String ver=performanceHeder.getEventName();\r
+                                       hql.append(" and a.eventName like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getDomain()) {\r
+                                       String ver=performanceHeder.getDomain();\r
+                                       hql.append(" and a.domain like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getEventId()) {\r
+                                       String ver=performanceHeder.getEventId();\r
+                                       hql.append(" and a.eventId = '"+ver+"'");\r
+                               }\r
+                               if(null!=performanceHeder.getNfcNamingCode()) {\r
+                                       String ver=performanceHeder.getNfcNamingCode();\r
+                                       hql.append(" and a.nfcNamingCode like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getNfNamingCode()) {\r
+                                       String ver=performanceHeder.getNfNamingCode();\r
+                                       hql.append(" and a.nfNamingCode like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getSourceId()) {\r
+                                       String ver =performanceHeder.getSourceId();\r
+                                       hql.append(" and a.sourceId = '"+ver+"'");\r
+                               }\r
+                               if(null!=performanceHeder.getSourceName()) {\r
+                                       String ver =performanceHeder.getSourceName();\r
+                                       hql.append(" and a.sourceName like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getReportingEntityId()) {\r
+                                       String ver =performanceHeder.getReportingEntityId();\r
+                                       hql.append(" and a.reportingEntityId like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getReportingEntityName()) {\r
+                                       String ver =performanceHeder.getReportingEntityName();\r
+                                       hql.append(" and a.reportingEntityName like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getPriority()) {\r
+                                       String ver =performanceHeder.getPriority();\r
+                                       hql.append(" and a.priority like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getStartEpochMicrosec()) {\r
+                                       String ver =performanceHeder.getStartEpochMicrosec();\r
+                                       hql.append(" and a.startEpochMicrosec like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getLastEpochMicroSec()) {\r
+                                       String ver =performanceHeder.getLastEpochMicroSec();\r
+                                       hql.append(" and a.lastEpochMicroSec like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getSequence()) {\r
+                                       String ver =performanceHeder.getSequence();\r
+                                       hql.append(" and a.sequence like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getMeasurementsForVfScalingVersion()) {\r
+                                       String ver =performanceHeder.getMeasurementsForVfScalingVersion();\r
+                                       hql.append(" and a.measurementsForVfScalingVersion like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getMeasurementInterval()) {\r
+                                       String ver =performanceHeder.getMeasurementInterval();\r
+                                       hql.append(" and a.measurementInterval like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceHeder.getEventType()) {\r
+                                       String ver =performanceHeder.getEventType();\r
+                                       hql.append(" and a.eventType like '%"+ver+"%'");\r
+                               }\r
                                if(null!=performanceHeder.getCreateTime() && null!=performanceHeder.getUpdateTime()) {\r
                                        hql.append(" and a.createTime between :startTime and :endTime ");\r
                                }\r
-            }\r
-            logger.info("PerformanceHeaderServiceImpl queryPerformanceHeader: performanceHeder={}", performanceHeder);\r
-            Query query = session.createQuery(hql.toString());\r
+                       }\r
+                       logger.info("PerformanceHeaderServiceImpl queryPerformanceHeader: performanceHeder={}", performanceHeder);\r
+                       Query query = session.createQuery(hql.toString());\r
                        if(null!=performanceHeder.getCreateTime() && null!=performanceHeder.getUpdateTime()) {\r
                                query.setDate("startTime",performanceHeder.getCreateTime()).setDate("endTime",performanceHeder.getUpdateTime());\r
                        }\r
-            query.setFirstResult(offset);\r
-            query.setMaxResults(pageSize);\r
-            List<PerformanceHeader> 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 PerformanceHeaderServiceImpl queryPerformanceHeader. Details:" + e.getMessage());\r
-            return null;\r
-        }\r
+                       query.setFirstResult(offset);\r
+                       query.setMaxResults(pageSize);\r
+                       List<PerformanceHeader> 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 PerformanceHeaderServiceImpl queryPerformanceHeader. Details:" + e.getMessage());\r
+                       return null;\r
+               }\r
        }\r
 \r
-\r
        @SuppressWarnings("unchecked")\r
        @Override\r
        public List<PerformanceHeader> queryId(String[] id) {\r
-               try(Session session = sessionFactory.openSession();) {\r
+               try(Session session = getSession()) {\r
                        if(id.length==0) {\r
                                logger.error("PerformanceHeaderServiceImpl queryId is null!");\r
                        }\r
@@ -301,10 +299,9 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
                }\r
        }\r
 \r
-\r
        @Override\r
        public List<String> queryAllSourceId() {\r
-               try(Session session = sessionFactory.openSession();) {\r
+               try(Session session = getSession()) {\r
                        Query query = session.createQuery("select a.sourceId from PerformanceHeader a");\r
                        return query.list();\r
                } catch (Exception e) {\r
index 9ab975a..ae8e048 100755 (executable)
@@ -41,146 +41,146 @@ import org.springframework.stereotype.Service;
 @org.springframework.context.annotation.Configuration\r
 @EnableAspectJAutoProxy\r
 public class PerformanceInformationServiceImpl implements PerformanceInformationService {\r
-    private static final Logger logger = LoggerFactory.getLogger(PerformanceInformationServiceImpl.class);\r
 \r
-    @Autowired\r
-    private SessionFactory sessionFactory;\r
+       private static final Logger logger = LoggerFactory.getLogger(PerformanceInformationServiceImpl.class);\r
 \r
+       @Autowired\r
+       private SessionFactory sessionFactory;\r
+\r
+       private Session getSession() {\r
+               return sessionFactory.openSession();\r
+       }\r
 \r
        @Override\r
        public String savePerformanceInformation(PerformanceInformation performanceInformation) {\r
-                try(Session session = sessionFactory.openSession();) {\r
-                   if (null == performanceInformation) {\r
-                       logger.error("performanceInformation savePerformanceInformation performanceInformation is null!");\r
-                   }\r
-                   logger.info("PerformanceInformationServiceImpl savePerformanceInformation: performanceInformation={}", performanceInformation);\r
-                   Transaction tx = session.beginTransaction();     \r
-                   session.save(performanceInformation);\r
-                   tx.commit();\r
-                   session.flush();\r
-                   return "1";\r
-               } catch (Exception e) {\r
-                   logger.error("exception occurred while performing PerformanceInformationServiceImpl savePerformanceInformation. Details:" + e.getMessage());\r
-                   return "0";\r
-               }\r
-               \r
+       try(Session session = getSession()) {\r
+                       if (null == performanceInformation) {\r
+                               logger.error("performanceInformation savePerformanceInformation performanceInformation is null!");\r
+                       }\r
+                       logger.info("PerformanceInformationServiceImpl savePerformanceInformation: performanceInformation={}", performanceInformation);\r
+                       Transaction tx = session.beginTransaction();\r
+                       session.save(performanceInformation);\r
+                       tx.commit();\r
+                       session.flush();\r
+                       return "1";\r
+               } catch (Exception e) {\r
+                       logger.error("exception occurred while performing PerformanceInformationServiceImpl savePerformanceInformation. Details:" + e.getMessage());\r
+                       return "0";\r
+               }\r
        }\r
 \r
-\r
        @Override\r
        public String updatePerformanceInformation(PerformanceInformation performanceInformation) {\r
-               try(Session session = sessionFactory.openSession();) {\r
-            if (null == performanceInformation) {\r
-                logger.error("performanceInformation updatePerformanceInformation performanceInformation is null!");\r
-            }\r
-            logger.info("PerformanceInformationServiceImpl updatePerformanceInformation: performanceInformation={}", performanceInformation);\r
-            Transaction tx = session.beginTransaction();     \r
-            session.update(performanceInformation);\r
-            tx.commit();\r
-            session.flush();\r
-            return "1";\r
-        } catch (Exception e) {\r
-            logger.error("exception occurred while performing PerformanceInformationServiceImpl updatePerformanceInformation. Details:" + e.getMessage());\r
-            return "0";\r
-        }\r
+               try(Session session = getSession()) {\r
+                       if (null == performanceInformation) {\r
+                               logger.error("performanceInformation updatePerformanceInformation performanceInformation is null!");\r
+                       }\r
+                       logger.info("PerformanceInformationServiceImpl updatePerformanceInformation: performanceInformation={}", performanceInformation);\r
+                       Transaction tx = session.beginTransaction();\r
+                       session.update(performanceInformation);\r
+                       tx.commit();\r
+                       session.flush();\r
+                       return "1";\r
+               } catch (Exception e) {\r
+                       logger.error("exception occurred while performing PerformanceInformationServiceImpl updatePerformanceInformation. Details:" + e.getMessage());\r
+                       return "0";\r
+               }\r
        }\r
 \r
-\r
        public int getAllCount(PerformanceInformation performanceInformation, int currentPage, int pageSize) {\r
-               try(Session session = sessionFactory.openSession();){\r
+               try(Session session = getSession()){\r
                        StringBuffer hql = new StringBuffer("select count(*) from PerformanceInformation a where 1=1");\r
                        if (null == performanceInformation) {\r
-                //logger.error("AlarmsInformationServiceImpl getAllCount performanceInformation is null!");\r
-            }else {\r
-               if(null!=performanceInformation.getName()) {\r
-                       String ver=performanceInformation.getName();\r
-                       hql.append(" and a.name like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceInformation.getValue()) {\r
-                       String ver=performanceInformation.getValue();\r
-                       hql.append(" and a.value like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceInformation.getEventId()) {\r
-                       String ver=performanceInformation.getEventId();\r
-                       hql.append(" and a.eventId = '"+ver+"'");\r
-                }\r
-               if(null!=performanceInformation.getCreateTime()) {\r
-                       Date ver =performanceInformation.getCreateTime();\r
-                       hql.append(" and a.createTime > '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceInformation.getUpdateTime()) {\r
-                       Date ver =performanceInformation.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 PerformanceInformationServiceImpl getAllCount. Details:" + e.getMessage());\r
-            return 0;\r
-        }\r
+                               logger.error("AlarmsInformationServiceImpl getAllCount performanceInformation is null!");\r
+                       }else {\r
+                               if(null!=performanceInformation.getName()) {\r
+                                       String ver=performanceInformation.getName();\r
+                                       hql.append(" and a.name like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceInformation.getValue()) {\r
+                                       String ver=performanceInformation.getValue();\r
+                                       hql.append(" and a.value like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceInformation.getEventId()) {\r
+                                       String ver=performanceInformation.getEventId();\r
+                                       hql.append(" and a.eventId = '"+ver+"'");\r
+                               }\r
+                               if(null!=performanceInformation.getCreateTime()) {\r
+                                       Date ver =performanceInformation.getCreateTime();\r
+                                       hql.append(" and a.createTime > '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceInformation.getUpdateTime()) {\r
+                                       Date ver =performanceInformation.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 PerformanceInformationServiceImpl getAllCount. Details:" + e.getMessage());\r
+                       return 0;\r
+               }\r
        }\r
 \r
-       @SuppressWarnings("unchecked")  \r
+       @SuppressWarnings("unchecked")\r
        @Override\r
        public Page<PerformanceInformation> queryPerformanceInformation(PerformanceInformation performanceInformation,\r
-                       int currentPage, int pageSize) {\r
+               int currentPage, int pageSize) {\r
                Page<PerformanceInformation> page = new Page<PerformanceInformation>();\r
                int allRow =this.getAllCount(performanceInformation,currentPage,pageSize);\r
                int offset = page.countOffset(currentPage, pageSize);\r
-               \r
-               try(Session session = sessionFactory.openSession();){\r
+\r
+               try(Session session = getSession()){\r
                        StringBuffer hql =new StringBuffer("from PerformanceInformation a where 1=1 ");\r
-            if (null == performanceInformation) {\r
-                //logger.error("AlarmsInformationServiceImpl queryPerformanceInformation performanceInformation is null!");\r
-            }else {\r
-               if(null!=performanceInformation.getName()) {\r
-                       String ver=performanceInformation.getName();\r
-                       hql.append(" and a.name like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceInformation.getValue()) {\r
-                       String ver=performanceInformation.getValue();\r
-                       hql.append(" and a.value like '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceInformation.getEventId()) {\r
-                       String ver=performanceInformation.getEventId();\r
-                       hql.append(" and a.eventId = '"+ver+"'");\r
-                }\r
-               if(null!=performanceInformation.getCreateTime()) {\r
-                       Date ver =performanceInformation.getCreateTime();\r
-                       hql.append(" and a.createTime > '%"+ver+"%'");\r
-                }\r
-               if(null!=performanceInformation.getUpdateTime()) {\r
-                       Date ver =performanceInformation.getUpdateTime();\r
-                       hql.append(" and a.updateTime like '%"+ver+"%'");\r
-                }\r
-            } \r
-            logger.info("PerformanceInformationServiceImpl queryPerformanceInformation: performanceInformation={}", performanceInformation);\r
-            Query query = session.createQuery(hql.toString());\r
-            query.setFirstResult(offset);\r
-            query.setMaxResults(pageSize);\r
-            List<PerformanceInformation> list= query.list();\r
+                       if (null == performanceInformation) {\r
+                               logger.error("AlarmsInformationServiceImpl queryPerformanceInformation performanceInformation is null!");\r
+                       }else {\r
+                               if(null!=performanceInformation.getName()) {\r
+                                       String ver=performanceInformation.getName();\r
+                                       hql.append(" and a.name like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceInformation.getValue()) {\r
+                                       String ver=performanceInformation.getValue();\r
+                                       hql.append(" and a.value like '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceInformation.getEventId()) {\r
+                                       String ver=performanceInformation.getEventId();\r
+                                       hql.append(" and a.eventId = '"+ver+"'");\r
+                               }\r
+                               if(null!=performanceInformation.getCreateTime()) {\r
+                                       Date ver =performanceInformation.getCreateTime();\r
+                                       hql.append(" and a.createTime > '%"+ver+"%'");\r
+                               }\r
+                               if(null!=performanceInformation.getUpdateTime()) {\r
+                                       Date ver =performanceInformation.getUpdateTime();\r
+                                       hql.append(" and a.updateTime like '%"+ver+"%'");\r
+                               }\r
+                       }\r
+                       logger.info("PerformanceInformationServiceImpl queryPerformanceInformation: performanceInformation={}", performanceInformation);\r
+                       Query query = session.createQuery(hql.toString());\r
+                       query.setFirstResult(offset);\r
+                       query.setMaxResults(pageSize);\r
+                       List<PerformanceInformation> list= query.list();\r
 \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 PerformanceInformationServiceImpl queryPerformanceInformation. Details:" + e.getMessage());\r
-            return null;\r
-        }\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 PerformanceInformationServiceImpl queryPerformanceInformation. Details:" + e.getMessage());\r
+                       return null;\r
+               }\r
        }\r
 \r
-\r
        @SuppressWarnings("unchecked")\r
        @Override\r
        public List<PerformanceInformation> queryId(String[] id) {\r
-               try(Session session = sessionFactory.openSession();) {\r
+               try(Session session = getSession()) {\r
                        if(id.length==0) {\r
-                               //logger.error("PerformanceInformationServiceImpl queryId is null!");\r
+                               logger.error("PerformanceInformationServiceImpl queryId is null!");\r
                        }\r
                        List<PerformanceInformation> list = new ArrayList<>();\r
                        Query query = session.createQuery("from PerformanceInformation a where a.eventId IN (:alist)");\r
@@ -193,11 +193,10 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
                }\r
        }\r
 \r
-\r
        @SuppressWarnings("unchecked")\r
        @Override\r
-       public List<PerformanceInformation> queryDateBetween(String eventId,Date startDate, Date endDate) {\r
-               try(Session session = sessionFactory.openSession();) {\r
+       public List<PerformanceInformation> queryDateBetween(String eventId, Date startDate, Date endDate) {\r
+               try(Session session = getSession()) {\r
                        List<PerformanceInformation> list = new ArrayList<>();\r
                        Query query = session.createQuery("from PerformanceInformation a where a.eventId = :eventId and a.createTime BETWEEN :startDate and :endDate");\r
                        list = query.setParameter("eventId",eventId).setParameter("startDate", startDate).setParameter("endDate",endDate).list();\r
@@ -209,12 +208,10 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
                }\r
        }\r
 \r
-\r
        @SuppressWarnings("unchecked")\r
        @Override\r
        public int queryDataBetweenSum(String eventId, String name, Date startDate, Date endDate){\r
-\r
-               try(Session session = sessionFactory.openSession();) {\r
+               try(Session session = getSession()) {\r
                        int sum = 0;\r
                        Query query = session.createQuery("select sum(a.value) from PerformanceInformation a where a.eventId = :eventId and a.name = :name and a.createTime BETWEEN :startDate and :endDate");\r
                        sum = Integer.parseInt(query.setParameter("eventId",eventId).setParameter("name",name).setParameter("startDate", startDate).setParameter("endDate",endDate).uniqueResult().toString());\r
@@ -228,7 +225,7 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
 \r
        @Override\r
        public List<PerformanceInformation> queryDateBetween(String resourceId, String name, String startTime, String endTime) {\r
-               try(Session session = sessionFactory.openSession();) {\r
+               try(Session session = getSession()) {\r
                        String hql = "from PerformanceInformation a where 1=1 ";\r
                        if (resourceId != null && !"".equals(resourceId)){\r
                                hql += " and a.eventId = :resourceId";\r
@@ -256,5 +253,4 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
                        return null;\r
                }\r
        }\r
-\r
 }\r
index 7cc8c75..72b2caf 100644 (file)
@@ -165,22 +165,22 @@ public class AlarmsInformationServiceImplTest {
                        }
                };
                AlarmsInformation ai = new AlarmsInformation();
-               ai.getName();
-               ai.getValue();
-               ai.getEventId();
-               ai.getCreateTime();
-               ai.getUpdateTime();
+               ai.setName("");
+               ai.setValue("");
+               ai.setEventId("");
+               ai.setCreateTime(DateUtils.now());
+               ai.setUpdateTime(DateUtils.now());
                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();
+               ai.setName("");
+               ai.setValue("");
+               ai.setEventId("");
+               ai.setCreateTime(DateUtils.now());
+               ai.setUpdateTime(DateUtils.now());
                alarmsInformationServiceImpl.queryAlarmsInformation(ai, 1, 1);
        }
 
diff --git a/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImplTest.java b/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImplTest.java
new file mode 100644 (file)
index 0000000..cbdcd92
--- /dev/null
@@ -0,0 +1,296 @@
+/**
+ * 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.PerformanceHeader;
+import org.onap.usecaseui.server.service.impl.PerformanceHeaderServiceImpl;
+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;
+
+/** 
+* PerformanceHeaderServiceImpl Tester. 
+* 
+* @author <Authors name> 
+* @since <pre>8, 2018</pre>
+* @version 1.0 
+*/
+public class PerformanceHeaderServiceImplTest {
+       PerformanceHeaderServiceImpl performanceHeaderServiceImpl = null;
+       private static final long serialVersionUID = 1L;
+
+       @Before
+       public void before() throws Exception {
+               performanceHeaderServiceImpl = new PerformanceHeaderServiceImpl();
+
+               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<PerformanceHeader> list() {
+                               PerformanceHeader ph = new PerformanceHeader();
+                               return Arrays.asList(ph);
+                       }
+                       @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<PerformanceHeaderServiceImpl>() {
+                       @Mock
+                       private Session getSession() {
+                               return mockedSession.getMockInstance();
+                       }
+               };
+       }
+
+       @After
+       public void after() throws Exception {
+       }
+
+       @Test
+       public void testSavePerformanceHeader() throws Exception {
+               PerformanceHeader ph = null;
+               performanceHeaderServiceImpl.savePerformanceHeader(ph);
+       }
+
+       @Test
+       public void testUpdatePerformanceHeader() throws Exception {
+               PerformanceHeader ph = null;
+               performanceHeaderServiceImpl.updatePerformanceHeader(ph);
+       }
+
+       @Test
+       public void testGetAllCount() throws Exception {
+               new MockUp<Query>() {
+                       @Mock
+                       public Object uniqueResult() {
+                               return "1";
+                       }
+               };
+               PerformanceHeader ph = new PerformanceHeader();
+               ph.setVersion("");
+               ph.setEventName("");
+               ph.setDomain("");
+               ph.setEventId("");
+               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.setEventType("");
+               ph.setCreateTime(DateUtils.now());
+               ph.setUpdateTime(DateUtils.now());
+               performanceHeaderServiceImpl.getAllCount(ph, 1, 1);
+       }
+
+       @Test
+       public void testQueryPerformanceHeader() throws Exception {
+               PerformanceHeader ph = new PerformanceHeader();
+               ph.setVersion("");
+               ph.setEventName("");
+               ph.setDomain("");
+               ph.setEventId("");
+               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.setEventType("");
+               ph.setCreateTime(DateUtils.now());
+               ph.setUpdateTime(DateUtils.now());
+               performanceHeaderServiceImpl.queryPerformanceHeader(ph, 1, 1);
+       }
+
+       @Test
+       public void testQueryId() throws Exception {
+               String[] id = {"1", "2", "3"};
+               performanceHeaderServiceImpl.queryId(id);
+       }
+
+       @Test
+       public void testQueryAllSourceId() throws Exception {
+               performanceHeaderServiceImpl.queryAllSourceId();
+       }
+
+       @Test(expected = Exception.class)
+       public void testSavePerformanceHeaderException() throws Exception {
+               new MockUp<PerformanceHeaderServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               PerformanceHeader ph = new PerformanceHeader();
+               performanceHeaderServiceImpl.savePerformanceHeader(ph);
+       }
+
+       @Test(expected = Exception.class)
+       public void testUpdatePerformanceHeaderException() throws Exception {
+               new MockUp<PerformanceHeaderServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               PerformanceHeader ph = new PerformanceHeader();
+               performanceHeaderServiceImpl.updatePerformanceHeader(ph);
+       }
+
+       @Test(expected = Exception.class)
+       public void testGetAllCountException() throws Exception {
+               new MockUp<PerformanceHeaderServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               PerformanceHeader ph = new PerformanceHeader();
+               performanceHeaderServiceImpl.getAllCount(ph, 1, 1);
+       }
+
+       @Test(expected = Exception.class)
+       public void testQueryPerformanceHeaderException() throws Exception {
+               new MockUp<PerformanceHeaderServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               PerformanceHeader ph = new PerformanceHeader();
+               performanceHeaderServiceImpl.queryPerformanceHeader(ph, 1, 1);
+       }
+
+       @Test(expected = Exception.class)
+       public void testQueryIdException() throws Exception {
+               new MockUp<PerformanceHeaderServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               String[] id = {"1", "2", "3"};
+               performanceHeaderServiceImpl.queryId(id);
+       }
+
+       @Test(expected = Exception.class)
+       public void testQueryAllSourceIdException() throws Exception {
+               new MockUp<PerformanceHeaderServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               performanceHeaderServiceImpl.queryAllSourceId();
+       }
+}
diff --git a/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImplTest.java b/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImplTest.java
new file mode 100644 (file)
index 0000000..5690dfe
--- /dev/null
@@ -0,0 +1,286 @@
+/**
+ * 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.PerformanceInformation;
+import org.onap.usecaseui.server.service.impl.PerformanceInformationServiceImpl;
+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;
+
+/** 
+* PerformanceInformationServiceImpl Tester. 
+* 
+* @author <Authors name> 
+* @since <pre>8, 2018</pre>
+* @version 1.0 
+*/
+public class PerformanceInformationServiceImplTest {
+       PerformanceInformationServiceImpl performanceInformationServiceImpl = null;
+       private static final long serialVersionUID = 1L;
+
+       @Before
+       public void before() throws Exception {
+               performanceInformationServiceImpl = new PerformanceInformationServiceImpl();
+
+               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<PerformanceInformation> list() {
+                               PerformanceInformation pi = new PerformanceInformation();
+                               return Arrays.asList(pi);
+                       }
+                       @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<PerformanceInformationServiceImpl>() {
+                       @Mock
+                       private Session getSession() {
+                               return mockedSession.getMockInstance();
+                       }
+               };
+       }
+
+       @After
+       public void after() throws Exception {
+       }
+
+       @Test
+       public void testSavePerformanceInformation() throws Exception {
+               PerformanceInformation pi = null;
+               performanceInformationServiceImpl.savePerformanceInformation(pi);
+       }
+
+       @Test
+       public void testUpdatePerformanceInformation() throws Exception {
+               PerformanceInformation pi = null;
+               performanceInformationServiceImpl.updatePerformanceInformation(pi);
+       }
+
+       @Test
+       public void testGetAllCount() throws Exception {
+               new MockUp<Query>() {
+                       @Mock
+                       public Object uniqueResult() {
+                               return "1";
+                       }
+               };
+               PerformanceInformation pi = new PerformanceInformation();
+               pi.setName("");
+               pi.setValue("");
+               pi.setEventId("");
+               pi.setCreateTime(DateUtils.now());
+               pi.setUpdateTime(DateUtils.now());
+               performanceInformationServiceImpl.getAllCount(pi, 1, 1);
+       }
+
+       @Test
+       public void testQueryPerformanceInformation() throws Exception {
+               PerformanceInformation pi = new PerformanceInformation();
+               pi.setName("");
+               pi.setValue("");
+               pi.setEventId("");
+               pi.setCreateTime(DateUtils.now());
+               pi.setUpdateTime(DateUtils.now());
+               performanceInformationServiceImpl.queryPerformanceInformation(pi, 1, 1);
+       }
+
+       @Test
+       public void testQueryId() throws Exception {
+               String[] id = {"1", "2", "3"};
+               performanceInformationServiceImpl.queryId(id);
+       }
+
+       @Test
+       public void testQueryDateBetween() throws Exception {
+               performanceInformationServiceImpl.queryDateBetween("eventId", DateUtils.now(), DateUtils.now());
+               performanceInformationServiceImpl.queryDateBetween("resourceId", "name", "startTime", "endTime");
+       }
+
+       @Test
+       public void testQueryDataBetweenSum() throws Exception {
+               performanceInformationServiceImpl.queryDataBetweenSum("eventId", "name", DateUtils.now(), DateUtils.now());
+       }
+
+       @Test(expected = Exception.class)
+       public void testSavePerformanceInformationException() throws Exception {
+               new MockUp<PerformanceInformationServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               PerformanceInformation pi = new PerformanceInformation();
+               performanceInformationServiceImpl.savePerformanceInformation(pi);
+       }
+
+       @Test(expected = Exception.class)
+       public void testUpdatePerformanceInformationException() throws Exception {
+               new MockUp<PerformanceInformationServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               PerformanceInformation pi = new PerformanceInformation();
+               performanceInformationServiceImpl.updatePerformanceInformation(pi);
+       }
+
+       @Test(expected = Exception.class)
+       public void testGetAllCountException() throws Exception {
+               new MockUp<PerformanceInformationServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               PerformanceInformation pi = new PerformanceInformation();
+               performanceInformationServiceImpl.getAllCount(pi, 1, 1);
+       }
+
+       @Test(expected = Exception.class)
+       public void testQueryPerformanceInformationException() throws Exception {
+               new MockUp<PerformanceInformationServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               PerformanceInformation pi = new PerformanceInformation();
+               performanceInformationServiceImpl.queryPerformanceInformation(pi, 1, 1);
+       }
+
+       @Test(expected = Exception.class)
+       public void testQueryIdException() throws Exception {
+               new MockUp<PerformanceInformationServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               String[] id = {"1", "2", "3"};
+               performanceInformationServiceImpl.queryId(id);
+       }
+
+       @Test(expected = Exception.class)
+       public void testQueryDateBetweenException() throws Exception {
+               new MockUp<PerformanceInformationServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               performanceInformationServiceImpl.queryDateBetween("eventId", DateUtils.now(), DateUtils.now());
+               performanceInformationServiceImpl.queryDateBetween("resourceId", "name", "startTime", "endTime");
+       }
+
+       @Test(expected = Exception.class)
+       public void testQueryDataBetweenSumException() throws Exception {
+               new MockUp<PerformanceInformationServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               performanceInformationServiceImpl.queryDataBetweenSum("eventId", "name", DateUtils.now(), DateUtils.now());
+       }
+}