From: zhangab Date: Mon, 16 Apr 2018 06:38:14 +0000 (+0800) Subject: improve sonar coverage for uui-server X-Git-Tag: v1.1.1~27 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F47%2F42947%2F1;p=usecase-ui%2Fserver.git improve sonar coverage for uui-server Change-Id: I84c132c8b17bfaed9a870a3c6dc6f0876c95a575 Issue-ID: USECASEUI-103 Signed-off-by: zhangab --- diff --git a/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java index 39828fab..6abc2012 100755 --- a/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java @@ -1,4 +1,4 @@ -/* +/** * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -41,253 +41,251 @@ import org.springframework.stereotype.Service; @org.springframework.context.annotation.Configuration @EnableAspectJAutoProxy public class PerformanceHeaderServiceImpl implements PerformanceHeaderService { - - private static final Logger logger = LoggerFactory.getLogger(PerformanceHeaderServiceImpl.class); - @Autowired - private SessionFactory sessionFactory; + private static final Logger logger = LoggerFactory.getLogger(PerformanceHeaderServiceImpl.class); + @Autowired + private SessionFactory sessionFactory; + + private Session getSession() { + return sessionFactory.openSession(); + } @Override public String savePerformanceHeader(PerformanceHeader performanceHeder) { - try(Session session = sessionFactory.openSession();){ - if (null == performanceHeder){ - logger.error("PerformanceHeaderServiceImpl savePerformanceHeader performanceHeder is null!"); - } - logger.info("PerformanceHeaderServiceImpl savePerformanceHeader: performanceHeder={}", performanceHeder); - Transaction tx = session.beginTransaction(); - session.save(performanceHeder); - tx.commit(); - session.flush(); - return "1"; - } catch (Exception e) { - logger.error("exception occurred while performing PerformanceHeaderServiceImpl savePerformanceHeader. Details:" + e.getMessage()); - return "0"; - } - + try(Session session = getSession()){ + if (null == performanceHeder){ + logger.error("PerformanceHeaderServiceImpl savePerformanceHeader performanceHeder is null!"); + } + logger.info("PerformanceHeaderServiceImpl savePerformanceHeader: performanceHeder={}", performanceHeder); + Transaction tx = session.beginTransaction(); + session.save(performanceHeder); + tx.commit(); + session.flush(); + return "1"; + } catch (Exception e) { + logger.error("exception occurred while performing PerformanceHeaderServiceImpl savePerformanceHeader. Details:" + e.getMessage()); + return "0"; + } } - @Override public String updatePerformanceHeader(PerformanceHeader performanceHeder) { - try(Session session = sessionFactory.openSession();){ - if (null == performanceHeder){ - logger.error("PerformanceHeaderServiceImpl updatePerformanceHeader performanceHeder is null!"); - } - logger.info("PerformanceHeaderServiceImpl updatePerformanceHeader: performanceHeder={}", performanceHeder); - Transaction tx = session.beginTransaction(); - session.update(performanceHeder); - tx.commit(); - session.flush(); - return "1"; - } catch (Exception e) { - logger.error("exception occurred while performing PerformanceHeaderServiceImpl updatePerformanceHeader. Details:" + e.getMessage()); - return "0"; - } + try(Session session = getSession()){ + if (null == performanceHeder){ + logger.error("PerformanceHeaderServiceImpl updatePerformanceHeader performanceHeder is null!"); + } + logger.info("PerformanceHeaderServiceImpl updatePerformanceHeader: performanceHeder={}", performanceHeder); + Transaction tx = session.beginTransaction(); + session.update(performanceHeder); + tx.commit(); + session.flush(); + return "1"; + } catch (Exception e) { + logger.error("exception occurred while performing PerformanceHeaderServiceImpl updatePerformanceHeader. Details:" + e.getMessage()); + return "0"; + } } - public int getAllCount(PerformanceHeader performanceHeder, int currentPage, int pageSize) { - try(Session session = sessionFactory.openSession();){ + try(Session session = getSession()){ StringBuffer hql = new StringBuffer("select count(*) from PerformanceHeader a where 1=1"); if (null == performanceHeder) { - //logger.error("PerformanceHeaderServiceImpl getAllCount performanceHeder is null!"); - }else { - if(null!=performanceHeder.getVersion()) { - String ver=performanceHeder.getVersion(); - hql.append(" and a.version like '%"+ver+"%'"); - } - if(null!=performanceHeder.getEventName()) { - String ver=performanceHeder.getEventName(); - hql.append(" and a.eventName like '%"+ver+"%'"); - } - if(null!=performanceHeder.getDomain()) { - String ver=performanceHeder.getDomain(); - hql.append(" and a.domain like '%"+ver+"%'"); - } - if(null!=performanceHeder.getEventId()) { - String ver=performanceHeder.getEventId(); - hql.append(" and a.eventId = '"+ver+"'"); - } - if(null!=performanceHeder.getNfcNamingCode()) { - String ver=performanceHeder.getNfcNamingCode(); - hql.append(" and a.nfcNamingCode like '%"+ver+"%'"); - } - if(null!=performanceHeder.getNfNamingCode()) { - String ver=performanceHeder.getNfNamingCode(); - hql.append(" and a.nfNamingCode like '%"+ver+"%'"); - } - if(null!=performanceHeder.getSourceId()) { - String ver =performanceHeder.getSourceId(); - hql.append(" and a.sourceId like '%"+ver+"%'"); - } - if(null!=performanceHeder.getSourceName()) { - String ver =performanceHeder.getSourceName(); - hql.append(" and a.sourceName like '%"+ver+"%'"); - } - if(null!=performanceHeder.getReportingEntityId()) { - String ver =performanceHeder.getReportingEntityId(); - hql.append(" and a.reportingEntityId like '%"+ver+"%'"); - } - if(null!=performanceHeder.getReportingEntityName()) { - String ver =performanceHeder.getReportingEntityName(); - hql.append(" and a.reportingEntityName like '%"+ver+"%'"); - } - if(null!=performanceHeder.getPriority()) { - String ver =performanceHeder.getPriority(); - hql.append(" and a.priority like '%"+ver+"%'"); - } - if(null!=performanceHeder.getStartEpochMicrosec()) { - String ver =performanceHeder.getStartEpochMicrosec(); - hql.append(" and a.startEpochMicrosec like '%"+ver+"%'"); - } - if(null!=performanceHeder.getLastEpochMicroSec()) { - String ver =performanceHeder.getLastEpochMicroSec(); - hql.append(" and a.lastEpochMicroSec like '%"+ver+"%'"); - } - if(null!=performanceHeder.getSequence()) { - String ver =performanceHeder.getSequence(); - hql.append(" and a.sequence like '%"+ver+"%'"); - } - if(null!=performanceHeder.getMeasurementsForVfScalingVersion()) { - String ver =performanceHeder.getMeasurementsForVfScalingVersion(); - hql.append(" and a.measurementsForVfScalingVersion like '%"+ver+"%'"); - } - if(null!=performanceHeder.getMeasurementInterval()) { - String ver =performanceHeder.getMeasurementInterval(); - hql.append(" and a.measurementInterval like '%"+ver+"%'"); - } - if(null!=performanceHeder.getEventType()) { - String ver =performanceHeder.getEventType(); - hql.append(" and a.eventType like '%"+ver+"%'"); - } - if(null!=performanceHeder.getCreateTime() && null!=performanceHeder.getUpdateTime()) { - hql.append(" and a.createTime between :startTime and :endTime "); - } - } - Query query = session.createQuery(hql.toString()); + logger.error("PerformanceHeaderServiceImpl getAllCount performanceHeder is null!"); + }else { + if(null!=performanceHeder.getVersion()) { + String ver=performanceHeder.getVersion(); + hql.append(" and a.version like '%"+ver+"%'"); + } + if(null!=performanceHeder.getEventName()) { + String ver=performanceHeder.getEventName(); + hql.append(" and a.eventName like '%"+ver+"%'"); + } + if(null!=performanceHeder.getDomain()) { + String ver=performanceHeder.getDomain(); + hql.append(" and a.domain like '%"+ver+"%'"); + } + if(null!=performanceHeder.getEventId()) { + String ver=performanceHeder.getEventId(); + hql.append(" and a.eventId = '"+ver+"'"); + } + if(null!=performanceHeder.getNfcNamingCode()) { + String ver=performanceHeder.getNfcNamingCode(); + hql.append(" and a.nfcNamingCode like '%"+ver+"%'"); + } + if(null!=performanceHeder.getNfNamingCode()) { + String ver=performanceHeder.getNfNamingCode(); + hql.append(" and a.nfNamingCode like '%"+ver+"%'"); + } + if(null!=performanceHeder.getSourceId()) { + String ver =performanceHeder.getSourceId(); + hql.append(" and a.sourceId like '%"+ver+"%'"); + } + if(null!=performanceHeder.getSourceName()) { + String ver =performanceHeder.getSourceName(); + hql.append(" and a.sourceName like '%"+ver+"%'"); + } + if(null!=performanceHeder.getReportingEntityId()) { + String ver =performanceHeder.getReportingEntityId(); + hql.append(" and a.reportingEntityId like '%"+ver+"%'"); + } + if(null!=performanceHeder.getReportingEntityName()) { + String ver =performanceHeder.getReportingEntityName(); + hql.append(" and a.reportingEntityName like '%"+ver+"%'"); + } + if(null!=performanceHeder.getPriority()) { + String ver =performanceHeder.getPriority(); + hql.append(" and a.priority like '%"+ver+"%'"); + } + if(null!=performanceHeder.getStartEpochMicrosec()) { + String ver =performanceHeder.getStartEpochMicrosec(); + hql.append(" and a.startEpochMicrosec like '%"+ver+"%'"); + } + if(null!=performanceHeder.getLastEpochMicroSec()) { + String ver =performanceHeder.getLastEpochMicroSec(); + hql.append(" and a.lastEpochMicroSec like '%"+ver+"%'"); + } + if(null!=performanceHeder.getSequence()) { + String ver =performanceHeder.getSequence(); + hql.append(" and a.sequence like '%"+ver+"%'"); + } + if(null!=performanceHeder.getMeasurementsForVfScalingVersion()) { + String ver =performanceHeder.getMeasurementsForVfScalingVersion(); + hql.append(" and a.measurementsForVfScalingVersion like '%"+ver+"%'"); + } + if(null!=performanceHeder.getMeasurementInterval()) { + String ver =performanceHeder.getMeasurementInterval(); + hql.append(" and a.measurementInterval like '%"+ver+"%'"); + } + if(null!=performanceHeder.getEventType()) { + String ver =performanceHeder.getEventType(); + hql.append(" and a.eventType like '%"+ver+"%'"); + } + if(null!=performanceHeder.getCreateTime() && null!=performanceHeder.getUpdateTime()) { + hql.append(" and a.createTime between :startTime and :endTime "); + } + } + Query query = session.createQuery(hql.toString()); if(null!=performanceHeder.getCreateTime() && null!=performanceHeder.getUpdateTime()) { query.setDate("startTime",performanceHeder.getCreateTime()).setDate("endTime",performanceHeder.getUpdateTime()); } - long q=(long)query.uniqueResult(); - session.flush(); - return (int)q; - } catch (Exception e) { - logger.error("exception occurred while performing PerformanceHeaderServiceImpl getAllCount. Details:" + e.getMessage()); - return 0; - } + long q=(long)query.uniqueResult(); + session.flush(); + return (int)q; + } catch (Exception e) { + logger.error("exception occurred while performing PerformanceHeaderServiceImpl getAllCount. Details:" + e.getMessage()); + return 0; + } } @SuppressWarnings("unchecked") @Override - public Page queryPerformanceHeader(PerformanceHeader performanceHeder, int currentPage, - int pageSize) { + public Page queryPerformanceHeader(PerformanceHeader performanceHeder, int currentPage, int pageSize) { Page page = new Page(); int allRow =this.getAllCount(performanceHeder,currentPage,pageSize); int offset = page.countOffset(currentPage, pageSize); - - try(Session session = sessionFactory.openSession();){ + + try(Session session = getSession()){ StringBuffer hql =new StringBuffer("from PerformanceHeader a where 1=1"); - if (null == performanceHeder) { - //logger.error("PerformanceHeaderServiceImpl queryPerformanceHeader performanceHeder is null!"); - }else { - if(null!=performanceHeder.getVersion()) { - String ver=performanceHeder.getVersion(); - hql.append(" and a.version like '%"+ver+"%'"); - } - if(null!=performanceHeder.getEventName()) { - String ver=performanceHeder.getEventName(); - hql.append(" and a.eventName like '%"+ver+"%'"); - } - if(null!=performanceHeder.getDomain()) { - String ver=performanceHeder.getDomain(); - hql.append(" and a.domain like '%"+ver+"%'"); - } - if(null!=performanceHeder.getEventId()) { - String ver=performanceHeder.getEventId(); - hql.append(" and a.eventId = '"+ver+"'"); - } - if(null!=performanceHeder.getNfcNamingCode()) { - String ver=performanceHeder.getNfcNamingCode(); - hql.append(" and a.nfcNamingCode like '%"+ver+"%'"); - } - if(null!=performanceHeder.getNfNamingCode()) { - String ver=performanceHeder.getNfNamingCode(); - hql.append(" and a.nfNamingCode like '%"+ver+"%'"); - } - if(null!=performanceHeder.getSourceId()) { - String ver =performanceHeder.getSourceId(); - hql.append(" and a.sourceId = '"+ver+"'"); - } - if(null!=performanceHeder.getSourceName()) { - String ver =performanceHeder.getSourceName(); - hql.append(" and a.sourceName like '%"+ver+"%'"); - } - if(null!=performanceHeder.getReportingEntityId()) { - String ver =performanceHeder.getReportingEntityId(); - hql.append(" and a.reportingEntityId like '%"+ver+"%'"); - } - if(null!=performanceHeder.getReportingEntityName()) { - String ver =performanceHeder.getReportingEntityName(); - hql.append(" and a.reportingEntityName like '%"+ver+"%'"); - } - if(null!=performanceHeder.getPriority()) { - String ver =performanceHeder.getPriority(); - hql.append(" and a.priority like '%"+ver+"%'"); - } - if(null!=performanceHeder.getStartEpochMicrosec()) { - String ver =performanceHeder.getStartEpochMicrosec(); - hql.append(" and a.startEpochMicrosec like '%"+ver+"%'"); - } - if(null!=performanceHeder.getLastEpochMicroSec()) { - String ver =performanceHeder.getLastEpochMicroSec(); - hql.append(" and a.lastEpochMicroSec like '%"+ver+"%'"); - } - if(null!=performanceHeder.getSequence()) { - String ver =performanceHeder.getSequence(); - hql.append(" and a.sequence like '%"+ver+"%'"); - } - if(null!=performanceHeder.getMeasurementsForVfScalingVersion()) { - String ver =performanceHeder.getMeasurementsForVfScalingVersion(); - hql.append(" and a.measurementsForVfScalingVersion like '%"+ver+"%'"); - } - if(null!=performanceHeder.getMeasurementInterval()) { - String ver =performanceHeder.getMeasurementInterval(); - hql.append(" and a.measurementInterval like '%"+ver+"%'"); - } - if(null!=performanceHeder.getEventType()) { - String ver =performanceHeder.getEventType(); - hql.append(" and a.eventType like '%"+ver+"%'"); - } + if (null == performanceHeder) { + //logger.error("PerformanceHeaderServiceImpl queryPerformanceHeader performanceHeder is null!"); + }else { + if(null!=performanceHeder.getVersion()) { + String ver=performanceHeder.getVersion(); + hql.append(" and a.version like '%"+ver+"%'"); + } + if(null!=performanceHeder.getEventName()) { + String ver=performanceHeder.getEventName(); + hql.append(" and a.eventName like '%"+ver+"%'"); + } + if(null!=performanceHeder.getDomain()) { + String ver=performanceHeder.getDomain(); + hql.append(" and a.domain like '%"+ver+"%'"); + } + if(null!=performanceHeder.getEventId()) { + String ver=performanceHeder.getEventId(); + hql.append(" and a.eventId = '"+ver+"'"); + } + if(null!=performanceHeder.getNfcNamingCode()) { + String ver=performanceHeder.getNfcNamingCode(); + hql.append(" and a.nfcNamingCode like '%"+ver+"%'"); + } + if(null!=performanceHeder.getNfNamingCode()) { + String ver=performanceHeder.getNfNamingCode(); + hql.append(" and a.nfNamingCode like '%"+ver+"%'"); + } + if(null!=performanceHeder.getSourceId()) { + String ver =performanceHeder.getSourceId(); + hql.append(" and a.sourceId = '"+ver+"'"); + } + if(null!=performanceHeder.getSourceName()) { + String ver =performanceHeder.getSourceName(); + hql.append(" and a.sourceName like '%"+ver+"%'"); + } + if(null!=performanceHeder.getReportingEntityId()) { + String ver =performanceHeder.getReportingEntityId(); + hql.append(" and a.reportingEntityId like '%"+ver+"%'"); + } + if(null!=performanceHeder.getReportingEntityName()) { + String ver =performanceHeder.getReportingEntityName(); + hql.append(" and a.reportingEntityName like '%"+ver+"%'"); + } + if(null!=performanceHeder.getPriority()) { + String ver =performanceHeder.getPriority(); + hql.append(" and a.priority like '%"+ver+"%'"); + } + if(null!=performanceHeder.getStartEpochMicrosec()) { + String ver =performanceHeder.getStartEpochMicrosec(); + hql.append(" and a.startEpochMicrosec like '%"+ver+"%'"); + } + if(null!=performanceHeder.getLastEpochMicroSec()) { + String ver =performanceHeder.getLastEpochMicroSec(); + hql.append(" and a.lastEpochMicroSec like '%"+ver+"%'"); + } + if(null!=performanceHeder.getSequence()) { + String ver =performanceHeder.getSequence(); + hql.append(" and a.sequence like '%"+ver+"%'"); + } + if(null!=performanceHeder.getMeasurementsForVfScalingVersion()) { + String ver =performanceHeder.getMeasurementsForVfScalingVersion(); + hql.append(" and a.measurementsForVfScalingVersion like '%"+ver+"%'"); + } + if(null!=performanceHeder.getMeasurementInterval()) { + String ver =performanceHeder.getMeasurementInterval(); + hql.append(" and a.measurementInterval like '%"+ver+"%'"); + } + if(null!=performanceHeder.getEventType()) { + String ver =performanceHeder.getEventType(); + hql.append(" and a.eventType like '%"+ver+"%'"); + } if(null!=performanceHeder.getCreateTime() && null!=performanceHeder.getUpdateTime()) { hql.append(" and a.createTime between :startTime and :endTime "); } - } - logger.info("PerformanceHeaderServiceImpl queryPerformanceHeader: performanceHeder={}", performanceHeder); - Query query = session.createQuery(hql.toString()); + } + logger.info("PerformanceHeaderServiceImpl queryPerformanceHeader: performanceHeder={}", performanceHeder); + Query query = session.createQuery(hql.toString()); if(null!=performanceHeder.getCreateTime() && null!=performanceHeder.getUpdateTime()) { query.setDate("startTime",performanceHeder.getCreateTime()).setDate("endTime",performanceHeder.getUpdateTime()); } - query.setFirstResult(offset); - query.setMaxResults(pageSize); - List list= query.list(); - page.setPageNo(currentPage); - page.setPageSize(pageSize); - page.setTotalRecords(allRow); - page.setList(list); - session.flush(); - return page; - } catch (Exception e) { - logger.error("exception occurred while performing PerformanceHeaderServiceImpl queryPerformanceHeader. Details:" + e.getMessage()); - return null; - } + query.setFirstResult(offset); + query.setMaxResults(pageSize); + List list= query.list(); + page.setPageNo(currentPage); + page.setPageSize(pageSize); + page.setTotalRecords(allRow); + page.setList(list); + session.flush(); + return page; + } catch (Exception e) { + logger.error("exception occurred while performing PerformanceHeaderServiceImpl queryPerformanceHeader. Details:" + e.getMessage()); + return null; + } } - @SuppressWarnings("unchecked") @Override public List queryId(String[] id) { - try(Session session = sessionFactory.openSession();) { + try(Session session = getSession()) { if(id.length==0) { logger.error("PerformanceHeaderServiceImpl queryId is null!"); } @@ -301,10 +299,9 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService { } } - @Override public List queryAllSourceId() { - try(Session session = sessionFactory.openSession();) { + try(Session session = getSession()) { Query query = session.createQuery("select a.sourceId from PerformanceHeader a"); return query.list(); } catch (Exception e) { diff --git a/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java index 9ab975a6..ae8e0480 100755 --- a/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java @@ -41,146 +41,146 @@ import org.springframework.stereotype.Service; @org.springframework.context.annotation.Configuration @EnableAspectJAutoProxy public class PerformanceInformationServiceImpl implements PerformanceInformationService { - private static final Logger logger = LoggerFactory.getLogger(PerformanceInformationServiceImpl.class); - @Autowired - private SessionFactory sessionFactory; + private static final Logger logger = LoggerFactory.getLogger(PerformanceInformationServiceImpl.class); + @Autowired + private SessionFactory sessionFactory; + + private Session getSession() { + return sessionFactory.openSession(); + } @Override public String savePerformanceInformation(PerformanceInformation performanceInformation) { - try(Session session = sessionFactory.openSession();) { - if (null == performanceInformation) { - logger.error("performanceInformation savePerformanceInformation performanceInformation is null!"); - } - logger.info("PerformanceInformationServiceImpl savePerformanceInformation: performanceInformation={}", performanceInformation); - Transaction tx = session.beginTransaction(); - session.save(performanceInformation); - tx.commit(); - session.flush(); - return "1"; - } catch (Exception e) { - logger.error("exception occurred while performing PerformanceInformationServiceImpl savePerformanceInformation. Details:" + e.getMessage()); - return "0"; - } - + try(Session session = getSession()) { + if (null == performanceInformation) { + logger.error("performanceInformation savePerformanceInformation performanceInformation is null!"); + } + logger.info("PerformanceInformationServiceImpl savePerformanceInformation: performanceInformation={}", performanceInformation); + Transaction tx = session.beginTransaction(); + session.save(performanceInformation); + tx.commit(); + session.flush(); + return "1"; + } catch (Exception e) { + logger.error("exception occurred while performing PerformanceInformationServiceImpl savePerformanceInformation. Details:" + e.getMessage()); + return "0"; + } } - @Override public String updatePerformanceInformation(PerformanceInformation performanceInformation) { - try(Session session = sessionFactory.openSession();) { - if (null == performanceInformation) { - logger.error("performanceInformation updatePerformanceInformation performanceInformation is null!"); - } - logger.info("PerformanceInformationServiceImpl updatePerformanceInformation: performanceInformation={}", performanceInformation); - Transaction tx = session.beginTransaction(); - session.update(performanceInformation); - tx.commit(); - session.flush(); - return "1"; - } catch (Exception e) { - logger.error("exception occurred while performing PerformanceInformationServiceImpl updatePerformanceInformation. Details:" + e.getMessage()); - return "0"; - } + try(Session session = getSession()) { + if (null == performanceInformation) { + logger.error("performanceInformation updatePerformanceInformation performanceInformation is null!"); + } + logger.info("PerformanceInformationServiceImpl updatePerformanceInformation: performanceInformation={}", performanceInformation); + Transaction tx = session.beginTransaction(); + session.update(performanceInformation); + tx.commit(); + session.flush(); + return "1"; + } catch (Exception e) { + logger.error("exception occurred while performing PerformanceInformationServiceImpl updatePerformanceInformation. Details:" + e.getMessage()); + return "0"; + } } - public int getAllCount(PerformanceInformation performanceInformation, int currentPage, int pageSize) { - try(Session session = sessionFactory.openSession();){ + try(Session session = getSession()){ StringBuffer hql = new StringBuffer("select count(*) from PerformanceInformation a where 1=1"); if (null == performanceInformation) { - //logger.error("AlarmsInformationServiceImpl getAllCount performanceInformation is null!"); - }else { - if(null!=performanceInformation.getName()) { - String ver=performanceInformation.getName(); - hql.append(" and a.name like '%"+ver+"%'"); - } - if(null!=performanceInformation.getValue()) { - String ver=performanceInformation.getValue(); - hql.append(" and a.value like '%"+ver+"%'"); - } - if(null!=performanceInformation.getEventId()) { - String ver=performanceInformation.getEventId(); - hql.append(" and a.eventId = '"+ver+"'"); - } - if(null!=performanceInformation.getCreateTime()) { - Date ver =performanceInformation.getCreateTime(); - hql.append(" and a.createTime > '%"+ver+"%'"); - } - if(null!=performanceInformation.getUpdateTime()) { - Date ver =performanceInformation.getUpdateTime(); - hql.append(" and a.updateTime like '%"+ver+"%'"); - } - } - long q=(long)session.createQuery(hql.toString()).uniqueResult(); - session.flush(); - return (int)q; - } catch (Exception e) { - logger.error("exception occurred while performing PerformanceInformationServiceImpl getAllCount. Details:" + e.getMessage()); - return 0; - } + logger.error("AlarmsInformationServiceImpl getAllCount performanceInformation is null!"); + }else { + if(null!=performanceInformation.getName()) { + String ver=performanceInformation.getName(); + hql.append(" and a.name like '%"+ver+"%'"); + } + if(null!=performanceInformation.getValue()) { + String ver=performanceInformation.getValue(); + hql.append(" and a.value like '%"+ver+"%'"); + } + if(null!=performanceInformation.getEventId()) { + String ver=performanceInformation.getEventId(); + hql.append(" and a.eventId = '"+ver+"'"); + } + if(null!=performanceInformation.getCreateTime()) { + Date ver =performanceInformation.getCreateTime(); + hql.append(" and a.createTime > '%"+ver+"%'"); + } + if(null!=performanceInformation.getUpdateTime()) { + Date ver =performanceInformation.getUpdateTime(); + hql.append(" and a.updateTime like '%"+ver+"%'"); + } + } + long q=(long)session.createQuery(hql.toString()).uniqueResult(); + session.flush(); + return (int)q; + } catch (Exception e) { + logger.error("exception occurred while performing PerformanceInformationServiceImpl getAllCount. Details:" + e.getMessage()); + return 0; + } } - @SuppressWarnings("unchecked") + @SuppressWarnings("unchecked") @Override public Page queryPerformanceInformation(PerformanceInformation performanceInformation, - int currentPage, int pageSize) { + int currentPage, int pageSize) { Page page = new Page(); int allRow =this.getAllCount(performanceInformation,currentPage,pageSize); int offset = page.countOffset(currentPage, pageSize); - - try(Session session = sessionFactory.openSession();){ + + try(Session session = getSession()){ StringBuffer hql =new StringBuffer("from PerformanceInformation a where 1=1 "); - if (null == performanceInformation) { - //logger.error("AlarmsInformationServiceImpl queryPerformanceInformation performanceInformation is null!"); - }else { - if(null!=performanceInformation.getName()) { - String ver=performanceInformation.getName(); - hql.append(" and a.name like '%"+ver+"%'"); - } - if(null!=performanceInformation.getValue()) { - String ver=performanceInformation.getValue(); - hql.append(" and a.value like '%"+ver+"%'"); - } - if(null!=performanceInformation.getEventId()) { - String ver=performanceInformation.getEventId(); - hql.append(" and a.eventId = '"+ver+"'"); - } - if(null!=performanceInformation.getCreateTime()) { - Date ver =performanceInformation.getCreateTime(); - hql.append(" and a.createTime > '%"+ver+"%'"); - } - if(null!=performanceInformation.getUpdateTime()) { - Date ver =performanceInformation.getUpdateTime(); - hql.append(" and a.updateTime like '%"+ver+"%'"); - } - } - logger.info("PerformanceInformationServiceImpl queryPerformanceInformation: performanceInformation={}", performanceInformation); - Query query = session.createQuery(hql.toString()); - query.setFirstResult(offset); - query.setMaxResults(pageSize); - List list= query.list(); + if (null == performanceInformation) { + logger.error("AlarmsInformationServiceImpl queryPerformanceInformation performanceInformation is null!"); + }else { + if(null!=performanceInformation.getName()) { + String ver=performanceInformation.getName(); + hql.append(" and a.name like '%"+ver+"%'"); + } + if(null!=performanceInformation.getValue()) { + String ver=performanceInformation.getValue(); + hql.append(" and a.value like '%"+ver+"%'"); + } + if(null!=performanceInformation.getEventId()) { + String ver=performanceInformation.getEventId(); + hql.append(" and a.eventId = '"+ver+"'"); + } + if(null!=performanceInformation.getCreateTime()) { + Date ver =performanceInformation.getCreateTime(); + hql.append(" and a.createTime > '%"+ver+"%'"); + } + if(null!=performanceInformation.getUpdateTime()) { + Date ver =performanceInformation.getUpdateTime(); + hql.append(" and a.updateTime like '%"+ver+"%'"); + } + } + logger.info("PerformanceInformationServiceImpl queryPerformanceInformation: performanceInformation={}", performanceInformation); + Query query = session.createQuery(hql.toString()); + query.setFirstResult(offset); + query.setMaxResults(pageSize); + List list= query.list(); - page.setPageNo(currentPage); - page.setPageSize(pageSize); - page.setTotalRecords(allRow); - page.setList(list); - session.flush(); - return page; - } catch (Exception e) { - logger.error("exception occurred while performing PerformanceInformationServiceImpl queryPerformanceInformation. Details:" + e.getMessage()); - return null; - } + page.setPageNo(currentPage); + page.setPageSize(pageSize); + page.setTotalRecords(allRow); + page.setList(list); + session.flush(); + return page; + } catch (Exception e) { + logger.error("exception occurred while performing PerformanceInformationServiceImpl queryPerformanceInformation. Details:" + e.getMessage()); + return null; + } } - @SuppressWarnings("unchecked") @Override public List queryId(String[] id) { - try(Session session = sessionFactory.openSession();) { + try(Session session = getSession()) { if(id.length==0) { - //logger.error("PerformanceInformationServiceImpl queryId is null!"); + logger.error("PerformanceInformationServiceImpl queryId is null!"); } List list = new ArrayList<>(); Query query = session.createQuery("from PerformanceInformation a where a.eventId IN (:alist)"); @@ -193,11 +193,10 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation } } - @SuppressWarnings("unchecked") @Override - public List queryDateBetween(String eventId,Date startDate, Date endDate) { - try(Session session = sessionFactory.openSession();) { + public List queryDateBetween(String eventId, Date startDate, Date endDate) { + try(Session session = getSession()) { List list = new ArrayList<>(); Query query = session.createQuery("from PerformanceInformation a where a.eventId = :eventId and a.createTime BETWEEN :startDate and :endDate"); list = query.setParameter("eventId",eventId).setParameter("startDate", startDate).setParameter("endDate",endDate).list(); @@ -209,12 +208,10 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation } } - @SuppressWarnings("unchecked") @Override public int queryDataBetweenSum(String eventId, String name, Date startDate, Date endDate){ - - try(Session session = sessionFactory.openSession();) { + try(Session session = getSession()) { int sum = 0; 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"); sum = Integer.parseInt(query.setParameter("eventId",eventId).setParameter("name",name).setParameter("startDate", startDate).setParameter("endDate",endDate).uniqueResult().toString()); @@ -228,7 +225,7 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation @Override public List queryDateBetween(String resourceId, String name, String startTime, String endTime) { - try(Session session = sessionFactory.openSession();) { + try(Session session = getSession()) { String hql = "from PerformanceInformation a where 1=1 "; if (resourceId != null && !"".equals(resourceId)){ hql += " and a.eventId = :resourceId"; @@ -256,5 +253,4 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation return null; } } - } 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 index 7cc8c750..72b2cafd 100644 --- 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 @@ -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 index 00000000..cbdcd925 --- /dev/null +++ b/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImplTest.java @@ -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 +* @since
8, 2018
+* @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 mockUpTransaction = new MockUp() { + @Mock + public void commit() { + } + }; + MockUp mockUpQuery = new MockUp() { + }; + new MockUp() { + @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 list() { + PerformanceHeader ph = new PerformanceHeader(); + return Arrays.asList(ph); + } + @Mock + public Object uniqueResult() { + return "0"; + } + }; + MockUp mockedSession = new MockUp() { + @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() { + @Mock + public Session openSession() { + return mockedSession.getMockInstance(); + } + }; + new MockUp() { + @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() { + @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() { + @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() { + @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() { + @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() { + @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() { + @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() { + @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 index 00000000..5690dfed --- /dev/null +++ b/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImplTest.java @@ -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 +* @since
8, 2018
+* @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 mockUpTransaction = new MockUp() { + @Mock + public void commit() { + } + }; + MockUp mockUpQuery = new MockUp() { + }; + new MockUp() { + @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 list() { + PerformanceInformation pi = new PerformanceInformation(); + return Arrays.asList(pi); + } + @Mock + public Object uniqueResult() { + return "0"; + } + }; + MockUp mockedSession = new MockUp() { + @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() { + @Mock + public Session openSession() { + return mockedSession.getMockInstance(); + } + }; + new MockUp() { + @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() { + @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() { + @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() { + @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() { + @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() { + @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() { + @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() { + @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() { + @Mock + private Session getSession() throws Exception { + throw new Exception(); + } + }; + performanceInformationServiceImpl.queryDataBetweenSum("eventId", "name", DateUtils.now(), DateUtils.now()); + } +}