aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzhangab <zhanganbing@chinamobile.com>2018-04-13 16:12:47 +0800
committerzhangab <zhanganbing@chinamobile.com>2018-04-13 16:12:51 +0800
commit2d85274e10a6a95dd8b0e2604638c87d90a3958f (patch)
tree27b5b18b1398b0d87f9eebc2fc476e418605d549
parent92f6adb90e3c5e9bf7c8f844964a9bdf1a4da6df (diff)
improve sonar coverage for uui-server
Change-Id: Iecb4f6b938c91f7ba7a335cbb04369efba8e5744 Issue-ID: USECASEUI-103 Signed-off-by: zhangab <zhanganbing@chinamobile.com>
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java20
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java161
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImplTest.java9
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImplTest.java458
4 files changed, 362 insertions, 286 deletions
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java
index f0ac9c39..980a3a61 100755
--- a/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java
@@ -52,7 +52,7 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
@Override
public String saveAlarmsInformation(AlarmsInformation alarmsInformation) {
- try(Session session = getSession();){
+ try(Session session = getSession()){
if (null == alarmsInformation) {
logger.error("alarmsInformation saveAlarmsInformation alarmsInformation is null!");
}
@@ -71,7 +71,7 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
@Override
public String updateAlarmsInformation(AlarmsInformation alarmsInformation) {
- try(Session session = getSession();){
+ try(Session session = getSession()){
if (null == alarmsInformation) {
logger.error("alarmsInformation updateAlarmsInformation alarmsInformation is null!");
}
@@ -89,7 +89,7 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
public int getAllCount(AlarmsInformation alarmsInformation, int currentPage, int pageSize) {
- try(Session session = getSession();){
+ try(Session session = getSession()){
StringBuffer hql = new StringBuffer("select count(*) from AlarmsInformation a where 1=1");
if (null == alarmsInformation) {
//logger.error("AlarmsInformationServiceImpl getAllCount alarmsInformation is null!");
@@ -114,11 +114,13 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
Date ver =alarmsInformation.getUpdateTime();
hql.append(" and a.updateTime like '%"+ver+"%'");
}
- }
- long q=(long)session.createQuery(hql.toString()).uniqueResult();
- session.flush();
- return (int)q;
- } catch (Exception e) {
+ }
+
+ Query query = session.createQuery(hql.toString());
+ Object obj = query.uniqueResult();
+ session.flush();
+ return Integer.parseInt(obj.toString());
+ } catch (Exception e) {
logger.error("exception occurred while performing AlarmsInformationServiceImpl getAllCount. Details:" + e.getMessage());
return 0;
}
@@ -132,7 +134,7 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
int allRow =this.getAllCount(alarmsInformation,currentPage,pageSize);
int offset = page.countOffset(currentPage, pageSize);
- try(Session session = getSession();){
+ try(Session session = getSession()){
StringBuffer hql =new StringBuffer("from AlarmsInformation a where 1=1");
if (null == alarmsInformation) {
//logger.error("AlarmsInformationServiceImpl queryAlarmsInformation alarmsInformation is null!");
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 77810b9d..705112d8 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
@@ -41,44 +41,37 @@ 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 Session getSessionFactory(){
+ private Session getSession(){
return sessionFactory.openSession();
}
-
-
-
@Override
public String savePerformanceHeader(PerformanceHeader performanceHeder) {
- try(Session session = getSessionFactory();){
- 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 = getSessionFactory();){
+ try(Session session = getSession()){
if (null == performanceHeder){
logger.error("PerformanceHeaderServiceImpl updatePerformanceHeader performanceHeder is null!");
}
@@ -94,49 +87,30 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
}
}
-
-
-
-
-
-
@Override
public int getAllCountByEventType(){
- try (Session session = getSessionFactory()){
+ try (Session session = getSession()){
StringBuffer count = new StringBuffer("select count(*) from PerformanceHeader a where 1=1");
- /*if(!"0".equals(status)){
- count.append(" and a.status=:status");
- }*/
Query query =session.createQuery(count.toString());
- /*query.setString("status",status);*/
- //int q = (int)query.uniqueResult();
- long q=(long)query.uniqueResult();
+ Object obj = query.uniqueResult();
session.flush();
- return (int)q;
+ return Integer.parseInt(obj.toString());
}catch (Exception e){
logger.error("exception occurred while performing PerformanceHeaderServiceImpl getAllCount."+e.getMessage());
return 0;
}
}
-
-
-
-
@Override
public List<PerformanceHeader> getAllByEventType(String eventName,String sourceName,String reportingEntityName, Date createTime, Date endTime){
- try (Session session = getSessionFactory()){
+ try (Session session = getSession()){
StringBuffer string = new StringBuffer("from PerformanceHeader a where 1=1");
- /*if(!"0".equals(status)){
- string.append(" and a.status=:status");
- }*/
if(!"0".equals(eventName) && eventName!=null){
string.append(" and a.eventName=:eventName");
}
if(!"0".equals(sourceName) && sourceName!=null){
string.append(" and a.sourceName=:sourceName");
}
-
if(!"0".equals(reportingEntityName) && reportingEntityName!=null){
string.append(" and a.reportingEntityName=:reportingEntityName");
}
@@ -144,54 +118,36 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
string.append(" and a.createTime between :startTime and :endTime");
}
Query query = session.createQuery(string.toString());
- /*if(!"0".equals(status)) {
- query.setString("status", status);
- }*/
if(!"0".equals(eventName) && eventName!=null) {
query.setString("eventName", eventName);
}
if(!"0".equals(sourceName) && sourceName!=null) {
query.setString("sourceName", sourceName);
}
-
if(!"0".equals(reportingEntityName) && reportingEntityName!=null) {
query.setString("reportingEntityName", reportingEntityName);
}
if( null!=createTime && endTime!= null) {
query.setDate("startTime",createTime);
query.setDate("endTime",endTime);
-
}
-
List<PerformanceHeader> list =query.list();
-
return list;
-
}catch (Exception e){
-
logger.error("exception occurred while performing PerformanceHeaderServiceImpl getAllCount."+e.getMessage());
return null;
}
-
-
-
}
-
-
-
-
@Override
public PerformanceHeader getPerformanceHeaderDetail(Integer id) {
- try(Session session = getSessionFactory()) {
-
+ try(Session session = getSession()) {
String string = "from PerformanceHeader a where 1=1 and a.id=:id";
Query q = session.createQuery(string);
q.setInteger("id",id);
PerformanceHeader performanceHeader =(PerformanceHeader)q.uniqueResult();
session.flush();
return performanceHeader;
-
}catch (Exception e){
logger.error("exception occurred while performing PerformanceHeaderServiceImpl getPerformanceHeaderDetail."+e.getMessage());
return null;
@@ -200,63 +156,29 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
@Override
public int getAllByDatetime(String eventId, String createTime) {
- try (Session session = getSessionFactory();){
+ try (Session session = getSession()){
StringBuffer string = new StringBuffer("select count(*) as count from PerformanceHeader a where 1=1");
-
- /*if(!"0".equals(status) && status!=null){
- string.append(" and a.status=:status");
- }*/
if(!"0".equals(eventId) && eventId!=null){
string.append(" and a.eventId=:eventId");
}
-
-
-
- /*if( null!=createTime && endTime!= null) {
- string.append(" and a.createTime between :startTime and :endTime");
- }*/
if( null!=createTime) {
string.append(" and to_days(a.createTime) = to_days('"+createTime+"')");
}
-
- /*string.append(" group by DATE_FORMAT(a.createTime,'%y-%m-%d')");*/
Query query = session.createQuery(string.toString());
- /*if(!"0".equals(status) && status!=null) {
- query.setString("status", status);
- }*/
- if(!"0".equals(eventId) && eventId!=null) {
- query.setString("eventId", eventId);
- }
-
- //query.setDate("createTime",createTime);
-
- /*if( null!=createTime && endTime!= null) {
- query.setDate("startTime",createTime);
- query.setDate("endTime",endTime);
-
- }*/
- long l = (long)query.uniqueResult();
- int a = (int) l;
- //List<PerformanceHeader> list =query.list();
+ if(!"0".equals(eventId) && eventId!=null) {
+ query.setString("eventId", eventId);
+ }
+ Object obj = query.uniqueResult();
session.flush();
- return a;
-
+ return Integer.parseInt(obj.toString());
}catch (Exception e){
-
logger.error("exception occurred while performing PerformanceHeaderServiceImpl getAllCount."+e.getMessage());
return 0;
}
-
}
-
-
-
-
-
-
public int getAllCount(PerformanceHeader performanceHeder, int currentPage, int pageSize) {
- try(Session session = getSessionFactory();){
+ 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!");
@@ -334,13 +256,14 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
}
}
Query query = session.createQuery(hql.toString());
- if (null != performanceHeder)
+ if (null != performanceHeder) {
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;
+ }
+ Object obj = query.uniqueResult();
+ session.flush();
+ return Integer.parseInt(obj.toString());
} catch (Exception e) {
logger.error("exception occurred while performing PerformanceHeaderServiceImpl getAllCount. Details:" + e.getMessage());
return 0;
@@ -349,13 +272,12 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
@SuppressWarnings("unchecked")
@Override
- public Page<PerformanceHeader> queryPerformanceHeader(PerformanceHeader performanceHeder, int currentPage,
- int pageSize) {
+ public Page<PerformanceHeader> queryPerformanceHeader(PerformanceHeader performanceHeder, int currentPage, int pageSize) {
Page<PerformanceHeader> page = new Page<PerformanceHeader>();
int allRow =this.getAllCount(performanceHeder,currentPage,pageSize);
int offset = page.countOffset(currentPage, pageSize);
-
- try(Session session = getSessionFactory();){
+
+ try(Session session = getSession()){
StringBuffer hql =new StringBuffer("from PerformanceHeader a where 1=1");
if (null == performanceHeder) {
//logger.error("PerformanceHeaderServiceImpl queryPerformanceHeader performanceHeder is null!");
@@ -434,10 +356,11 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
}
logger.info("PerformanceHeaderServiceImpl queryPerformanceHeader: performanceHeder={}", performanceHeder);
Query query = session.createQuery(hql.toString());
- if (null != performanceHeder)
+ if (null != performanceHeder) {
if(null!=performanceHeder.getCreateTime() && null!=performanceHeder.getUpdateTime()) {
query.setDate("startTime",performanceHeder.getCreateTime()).setDate("endTime",performanceHeder.getUpdateTime());
}
+ }
query.setFirstResult(offset);
query.setMaxResults(pageSize);
List<PerformanceHeader> list= query.list();
@@ -453,11 +376,10 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
}
}
-
@SuppressWarnings("unchecked")
@Override
public List<PerformanceHeader> queryId(String[] id) {
- try(Session session = getSessionFactory();) {
+ try(Session session = getSession()) {
if(id.length==0) {
logger.error("PerformanceHeaderServiceImpl queryId is null!");
}
@@ -471,10 +393,9 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
}
}
-
@Override
public List<String> queryAllSourceId() {
- try(Session session = getSessionFactory();) {
+ 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/test/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImplTest.java b/server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImplTest.java
index d6dcc1b9..9cc926d0 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
@@ -193,6 +193,15 @@ public class AlarmsInformationServiceImplTest {
@Test
public void testQueryDateBetween() throws Exception {
+ new MockUp<Query>() {
+ @Mock
+ public List<Object[]> list() {
+ List<Object[]> resultlist = new ArrayList<Object[]>();
+ Object[] objs = {"name", "value"};
+ resultlist.add(objs);
+ return resultlist;
+ }
+ };
new MockUp<List>() {
@Mock
private Iterator iterator() {
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
index 4271c498..b2fe2b47 100644
--- 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
@@ -24,7 +24,7 @@ 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.PerformanceHeaderService;
+import org.onap.usecaseui.server.service.impl.PerformanceHeaderServiceImpl;
import org.onap.usecaseui.server.util.DateUtils;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -32,6 +32,10 @@ import org.springframework.test.context.web.WebAppConfiguration;
import javax.annotation.Resource;
+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;
@@ -39,7 +43,6 @@ import org.hibernate.Transaction;
import mockit.Mock;
import mockit.MockUp;
-
import static org.mockito.Mockito.mock;
/**
@@ -50,35 +53,82 @@ import static org.mockito.Mockito.mock;
* @version 1.0
*/
public class PerformanceHeaderServiceImplTest {
- /* @Resource(name = "PerformanceHeaderService")
- PerformanceHeaderService performanceHeaderService;*/
- PerformanceHeaderServiceImpl service;
-@Before
-public void before() throws Exception {
- service = mock(PerformanceHeaderServiceImpl.class);
-}
-
-@After
-public void after() throws Exception {
-}
-
-private Session session;
-private Transaction transaction;
-private Query query;
-/**
- * mockupUtil
- */
-public void mockupUtil(){
- MockUp<Query> mockUpQuery = new MockUp<Query>() {
- };
+
+ 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 Query createQuery(String sql) {
+ return mockUpQuery.getMockInstance();
+ }
@Mock
public Transaction beginTransaction() {
- return transaction;
+ 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>() {
@@ -87,144 +137,238 @@ public void mockupUtil(){
return mockedSession.getMockInstance();
}
};
- new MockUp<Transaction>() {
+ new MockUp<PerformanceHeaderServiceImpl>() {
@Mock
- public void commit() {
+ private Session getSession() {
+ return mockedSession.getMockInstance();
}
};
- new MockUp<AlarmsInformationServiceImpl>() {
- @Mock
- private Session getSession() {
- return mockedSession.getMockInstance();
- }
- };
-}
+ }
-/**
-*
-* Method: savePerformanceHeader(PerformanceHeader performanceHeder)
-*
-*/
-@Test
-public void testSavePerformanceHeader() throws Exception {
-//TODO: Test goes here...
- PerformanceHeader p = new PerformanceHeader();
- p.setCreateTime(DateUtils.now());
- p.setEventId("2202");
- p.setEventName("fxc");
- p.setDomain("asb");
- p.setCreateTime(DateUtils.now());
- p.setEventType("q");
- p.setLastEpochMicroSec("csa");
- p.setNfcNamingCode("std");
- p.setNfNamingCode("cout");
- p.setPriority("cs");
- p.setReportingEntityId("112");
- p.setReportingEntityName("asfs");
- p.setSequence("cgg");
- p.setSourceId("123");
- p.setSourceName("eggs");
- p.setStartEpochMicrosec("wallet");
- p.setUpdateTime(DateUtils.now());
- p.setVersion("va2");
- p.setMeasurementInterval("12");
- p.setMeasurementsForVfScalingVersion("12");
- mockupUtil();
- service.savePerformanceHeader(p);
-}
+ @After
+ public void after() throws Exception {
+ }
-/**
-*
-* Method: updatePerformanceHeader(PerformanceHeader performanceHeder)
-*
-*/
-@Test
-public void testUpdatePerformanceHeader() throws Exception {
-//TODO: Test goes here...
- PerformanceHeader p = new PerformanceHeader();
- p.setCreateTime(DateUtils.now());
- p.setEventId("110");
- p.setEventName("fxc");
- p.setDomain("asb");
- p.setCreateTime(DateUtils.now());
- p.setEventType("q");
- p.setLastEpochMicroSec("csa");
- p.setNfcNamingCode("std");
- p.setNfNamingCode("cout");
- p.setPriority("cs");
- p.setReportingEntityId("112");
- p.setReportingEntityName("asfs");
- p.setSequence("cgg");
- p.setSourceId("123");
- p.setSourceName("eggs");
- p.setStartEpochMicrosec("wallet");
- p.setUpdateTime(DateUtils.now());
- p.setVersion("va2");
- p.setMeasurementInterval("12");
- p.setMeasurementsForVfScalingVersion("12");
- mockupUtil();
- service.updatePerformanceHeader(p);
-}
+ @Test
+ public void testSavePerformanceHeader() throws Exception {
+ PerformanceHeader ph = null;
+ performanceHeaderServiceImpl.savePerformanceHeader(ph);
+ }
-/**
-*
-* Method: getAllCount(PerformanceHeader performanceHeder, int currentPage, int pageSize)
-*
-*/
-@Test
-public void testGetAllCount() throws Exception {
-//TODO: Test goes here...
+ @Test
+ public void testUpdatePerformanceHeader() throws Exception {
+ PerformanceHeader ph = null;
+ performanceHeaderServiceImpl.updatePerformanceHeader(ph);
+ }
- PerformanceHeader performanceHeader = new PerformanceHeader();
- performanceHeader.setSourceName("vnf_a_3");
+ @Test
+ public void testGetAllCountByEventType() throws Exception {
+ performanceHeaderServiceImpl.getAllCountByEventType();
+ }
- mockupUtil();
- service.getAllCount(performanceHeader,0,12);
+ @Test
+ public void testGetAllByEventType() throws Exception {
+ new MockUp<Query>() {
+ @Mock
+ public List<PerformanceHeader> list() {
+ PerformanceHeader ph = new PerformanceHeader();
+ return Arrays.asList(ph);
+ }
+ };
+ performanceHeaderServiceImpl.getAllByEventType("eventName", "sourceName", "reportingEntityName", DateUtils.now(), DateUtils.now());
+ }
-}
+ @Test
+ public void testGetPerformanceHeaderDetail() throws Exception {
+ performanceHeaderServiceImpl.getPerformanceHeaderDetail(1);
+ }
-/**
-*
-* Method: queryPerformanceHeader(PerformanceHeader performanceHeder, int currentPage, int pageSize)
-*
-*/
-@Test
-public void testQueryPerformanceHeader() throws Exception {
-//TODO: Test goes here...
- PerformanceHeader p = new PerformanceHeader();
- p.setEventId("110");
- mockupUtil();
- service.queryPerformanceHeader(p,1,100);
- // .getList().forEach(per -> System.out.println(per));
-}
+ @Test
+ public void testGetAllByDatetime() throws Exception {
+ performanceHeaderServiceImpl.getAllByDatetime("eventId", "createTime");
+ }
-/**
-*
-* Method: queryId(String[] id)
-*
-*/
-@Test
-public void testQueryId() throws Exception {
-//TODO: Test goes here...
- mockupUtil();
- service.queryId(new String[]{"110"});
- // .forEach(pe -> System.out.println(pe.getCreateTime()));
-}
+ @Test
+ public void testGetAllCount() throws Exception {
+ PerformanceHeader ph = new PerformanceHeader();
+ ph.setVersion("version");
+ ph.setEventName("eventName");
+ ph.setDomain("domain");
+ ph.setEventId("eventId");
+ ph.setNfcNamingCode("nfcNamingCode");
+ ph.setNfNamingCode("nfNamingCode");
+ ph.setSourceId("sourceId");
+ ph.setSourceName("sourceName");
+ ph.setReportingEntityId("reportingEntityId");
+ ph.setReportingEntityName("reportingEntityName");
+ ph.setPriority("priority");
+ ph.setStartEpochMicrosec("startEpochMicrosec");
+ ph.setLastEpochMicroSec("lastEpochMicroSec");
+ ph.setSequence("sequence");
+ ph.setMeasurementsForVfScalingVersion("measurementsForVfScalingVersion");
+ ph.setMeasurementInterval("measurementInterval");
+ ph.setEventType("eventType");
+ ph.setCreateTime(DateUtils.now());
+ ph.setUpdateTime(DateUtils.now());
+ performanceHeaderServiceImpl.getAllCount(ph, 1, 10);
+ }
-/**
-*
-* Method: queryAllSourceId()
-*
-*/
-@Test
-public void testQueryAllSourceId() throws Exception {
-//TODO: Test goes here...
- PerformanceHeader p = new PerformanceHeader();
- p.setSourceId("123");
- mockupUtil();
- service.queryPerformanceHeader(p,1,100);
- //.getList().forEach(per -> System.out.println(per));
-}
-
-
-}
+ @Test
+ public void testQueryPerformanceHeader() throws Exception {
+ new MockUp<PerformanceHeaderServiceImpl>() {
+ @Mock
+ private int getAllCount(PerformanceHeader performanceHeader, int currentPage, int pageSize) {
+ return 10;
+ }
+ };
+ PerformanceHeader ph = new PerformanceHeader();
+ ph.setVersion("version");
+ ph.setEventName("eventName");
+ ph.setDomain("domain");
+ ph.setEventId("eventId");
+ ph.setNfcNamingCode("nfcNamingCode");
+ ph.setNfNamingCode("nfNamingCode");
+ ph.setSourceId("sourceId");
+ ph.setSourceName("sourceName");
+ ph.setReportingEntityId("reportingEntityId");
+ ph.setReportingEntityName("reportingEntityName");
+ ph.setPriority("priority");
+ ph.setStartEpochMicrosec("startEpochMicrosec");
+ ph.setLastEpochMicroSec("lastEpochMicroSec");
+ ph.setSequence("sequence");
+ ph.setMeasurementsForVfScalingVersion("measurementsForVfScalingVersion");
+ ph.setMeasurementInterval("measurementInterval");
+ ph.setEventType("eventType");
+ ph.setCreateTime(DateUtils.now());
+ ph.setUpdateTime(DateUtils.now());
+ performanceHeaderServiceImpl.queryPerformanceHeader(ph, 1, 10);
+ }
+
+ @Test
+ public void testQueryId() throws Exception {
+ String[] id = {};
+ performanceHeaderServiceImpl.queryId(id);
+ }
+
+ @Test
+ public void testQueryAllSourceId() throws Exception {
+ String[] id = {};
+ 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 = null;
+ 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 = null;
+ performanceHeaderServiceImpl.updatePerformanceHeader(ph);
+ }
+
+ @Test(expected = Exception.class)
+ public void testGetAllCountByEventTypeException() throws Exception {
+ new MockUp<PerformanceHeaderServiceImpl>() {
+ @Mock
+ private Session getSession() throws Exception {
+ throw new Exception();
+ }
+ };
+ performanceHeaderServiceImpl.getAllCountByEventType();
+ }
+
+ @Test(expected = Exception.class)
+ public void testGetAllByEventTypeException() throws Exception {
+ new MockUp<PerformanceHeaderServiceImpl>() {
+ @Mock
+ private Session getSession() throws Exception {
+ throw new Exception();
+ }
+ };
+ performanceHeaderServiceImpl.getAllByEventType("eventName", "sourceName", "reportingEntityName", DateUtils.now(), DateUtils.now());
+ }
+
+ @Test(expected = Exception.class)
+ public void testGetPerformanceHeaderDetailException() throws Exception {
+ new MockUp<PerformanceHeaderServiceImpl>() {
+ @Mock
+ private Session getSession() throws Exception {
+ throw new Exception();
+ }
+ };
+ performanceHeaderServiceImpl.getPerformanceHeaderDetail(1);
+ }
+
+ @Test(expected = Exception.class)
+ public void testGetAllByDatetimeException() throws Exception {
+ new MockUp<PerformanceHeaderServiceImpl>() {
+ @Mock
+ private Session getSession() throws Exception {
+ throw new Exception();
+ }
+ };
+ performanceHeaderServiceImpl.getAllByDatetime("eventId", "createTime");
+ }
+
+ @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, 10);
+ }
+
+ @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, 10);
+ }
+
+ @Test(expected = Exception.class)
+ public void testQueryIdException() throws Exception {
+ new MockUp<PerformanceHeaderServiceImpl>() {
+ @Mock
+ private Session getSession() throws Exception {
+ throw new Exception();
+ }
+ };
+ String[] id = {};
+ performanceHeaderServiceImpl.queryId(id);
+ }
+
+ @Test(expected = Exception.class)
+ public void testQueryAllSourceIdException() throws Exception {
+ new MockUp<PerformanceHeaderServiceImpl>() {
+ @Mock
+ private Session getSession() throws Exception {
+ throw new Exception();
+ }
+ };
+ String[] id = {};
+ performanceHeaderServiceImpl.queryAllSourceId();
+ }
+} \ No newline at end of file