diff options
author | zhangab <zhanganbing@chinamobile.com> | 2018-03-28 16:48:21 +0800 |
---|---|---|
committer | zhangab <zhanganbing@chinamobile.com> | 2018-03-28 16:48:26 +0800 |
commit | c9d2bfb66db6b2539193d42acb141e9cf5a33b6e (patch) | |
tree | 657f651ec74c5653b03a20b60b6739bdebb339d0 | |
parent | 407ed4524b1799c8c911935085b91b0f889d3f3c (diff) |
improve sonar coverage for uui-server
Change-Id: I116812a5dfb312498ab979fffd512029d2e9507c
Issue-ID: USECASEUI-103
Signed-off-by: zhangab <zhanganbing@chinamobile.com>
-rw-r--r-- | server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImplTest.java | 218 |
1 files changed, 171 insertions, 47 deletions
diff --git a/server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImplTest.java b/server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImplTest.java index 70b2bad0..0d2e13be 100644 --- a/server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImplTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImplTest.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"); @@ -32,8 +32,11 @@ import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Date; +import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; +import org.hibernate.Transaction; + import mockit.Mock; import mockit.MockUp; /** @@ -53,52 +56,173 @@ public class AlarmsHeaderServiceImplTest { } private Session session; -/** -* -* Method: saveAlarmsHeader(AlarmsHeader alarmsHeader) -* -*/ -@Test -public void testSaveAlarmsHeader() throws Exception { -//TODO: Test goes here... - AlarmsHeader a = new AlarmsHeader(); - a.setEventName("a"); - a.setStatus("1"); - a.setVfStatus("1"); - a.setEventId("1119"); - a.setDomain("asb"); - a.setEventCategory("s"); - a.setAlarmCondition("ea"); - a.setAlarmInterfaceA("cs"); - a.setCreateTime(DateUtils.now()); - a.setEventServrity("s"); - a.setEventSourceType("q"); - a.setEventType("q"); - a.setFaultFieldsVersion("v1"); - a.setLastEpochMicroSec("csa"); - a.setNfcNamingCode("std"); - a.setNfNamingCode("cout"); - a.setPriority("cs"); - a.setReportingEntityId("112"); - a.setReportingEntityName("asfs"); - a.setSequence("cgg"); - a.setSourceId("123"); - a.setSourceName("eggs"); - a.setSpecificProblem("especially"); - a.setStartEpochMicrosec("wallet"); - a.setUpdateTime(DateUtils.now()); - a.setVersion("va2"); - - new MockUp<SessionFactory>() { - @Mock - public Session openSession() { - return session; - } - }; - - AlarmsHeaderServiceImpl alarmsHeaderServiceImpl = new AlarmsHeaderServiceImpl(); - System.out.println(alarmsHeaderServiceImpl.saveAlarmsHeader(a)); -} + private Transaction transaction; + private Query query; + + /** + * + * Method: saveAlarmsHeader(AlarmsHeader alarmsHeader) + * + */ + @Test + public void testSaveAlarmsHeader() throws Exception { + //TODO: Test goes here... + AlarmsHeader a = new AlarmsHeader(); + a.setEventName("a"); + a.setStatus("1"); + a.setVfStatus("1"); + a.setEventId("1119"); + a.setDomain("asb"); + a.setEventCategory("s"); + a.setAlarmCondition("ea"); + a.setAlarmInterfaceA("cs"); + a.setCreateTime(DateUtils.now()); + a.setEventServrity("s"); + a.setEventSourceType("q"); + a.setEventType("q"); + a.setFaultFieldsVersion("v1"); + a.setLastEpochMicroSec("csa"); + a.setNfcNamingCode("std"); + a.setNfNamingCode("cout"); + a.setPriority("cs"); + a.setReportingEntityId("112"); + a.setReportingEntityName("asfs"); + a.setSequence("cgg"); + a.setSourceId("123"); + a.setSourceName("eggs"); + a.setSpecificProblem("especially"); + a.setStartEpochMicrosec("wallet"); + a.setUpdateTime(DateUtils.now()); + a.setVersion("va2"); + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Transaction beginTransaction() { + return transaction; + } + @Mock + public void save(AlarmsHeader alarmsHeader) { + } + @Mock + public void flush() { + } + }; + new MockUp<SessionFactory>() { + @Mock + public Session openSession() { + return mockedSession.getMockInstance(); + } + }; + new MockUp<Transaction>() { + @Mock + public void commit() { + } + }; + + AlarmsHeaderServiceImpl alarmsHeaderServiceImpl = new AlarmsHeaderServiceImpl(); + alarmsHeaderServiceImpl.saveAlarmsHeader(a); + } + + /** + * + * Method: updateAlarmsHeader2018(String status, String date, String eventNameCleared, String eventName, String reportingEntityName, String specificProblem) + * + */ + @Test + public void testUpdateAlarmsHeader2018() throws Exception { + new MockUp<SessionFactory>() { + @Mock + public Session openSession() { + return session; + } + }; + new MockUp<Session>() { + @Mock + public Transaction beginTransaction() { + return transaction; + } + @Mock + public void save(AlarmsHeader alarmsHeader) { + } + @Mock + public void flush() { + } + @Mock + public Query createQuery() { + return query; + } + }; + new MockUp<Transaction>() { + @Mock + public void commit() { + } + }; + new MockUp<Query>() { + @Mock + public void executeUpdate() { + } + }; + + Long l = System.currentTimeMillis(); + Timestamp date_get = new Timestamp(l); + AlarmsHeaderServiceImpl alarmsHeaderServiceImpl = new AlarmsHeaderServiceImpl(); + alarmsHeaderServiceImpl.updateAlarmsHeader2018("active",date_get,"112","112","Fault_MultiCloud_VMFailureCleared","Multi-Cloud","Fault_MultiCloud_VMFailure"); + } + + /** + * + * Method: getStatusBySourceName(String sourceName) + * + */ + @Test + public void testGetStatusBySourceName() throws Exception { + new MockUp<SessionFactory>() { + @Mock + public Session openSession() { + return session; + } + }; + new MockUp<Session>() { + @Mock + public Transaction beginTransaction() { + return transaction; + } + @Mock + public void save(AlarmsHeader alarmsHeader) { + } + @Mock + public void flush() { + } + @Mock + public Query createQuery() { + return query; + } + }; + new MockUp<Transaction>() { + @Mock + public void commit() { + } + }; + new MockUp<Query>() { + @Mock + public void executeUpdate() { + } + @Mock + public void setMaxResults() { + } + @Mock + public String uniqueResult() { + return "active"; + } + }; + AlarmsHeaderServiceImpl alarmsHeaderServiceImpl = new AlarmsHeaderServiceImpl(); + Boolean bl = alarmsHeaderServiceImpl.getStatusBySourceName("vnf_a_3"); + System.out.println("boolean="+bl); + } + + + + } |