diff options
author | zhangab <zhanganbing@chinamobile.com> | 2018-03-29 10:17:47 +0800 |
---|---|---|
committer | zhangab <zhanganbing@chinamobile.com> | 2018-03-29 10:17:50 +0800 |
commit | 0844122633cbb441ee7db7125fae35227d0221fe (patch) | |
tree | df419a2c9bab5c3ba3d00f114ca5469cdb5dda3b | |
parent | b1dc61a369f4dd88159948556be735a4c171df5d (diff) |
improve sonar coverage for uui-server
Change-Id: Ibe63df143c1537450edb714cd3cfb58a1b3c0789
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 | 130 |
1 files changed, 55 insertions, 75 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 49544852..3d1c37a2 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 @@ -48,7 +48,7 @@ import mockit.MockUp; */ public class AlarmsHeaderServiceImplTest { @Before - public void before() throws Exception { + public void before() throws Exception { } @After @@ -59,19 +59,56 @@ public class AlarmsHeaderServiceImplTest { 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<Query> mockUpQuery = new MockUp<Query>() { + }; MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String sql) { + return mockUpQuery.getMockInstance(); + } @Mock public Transaction beginTransaction() { return transaction; } - @Mock - public void save(AlarmsHeader alarmsHeader) { - } - @Mock - public void flush() { - } }; new MockUp<SessionFactory>() { @Mock @@ -84,77 +121,20 @@ public class AlarmsHeaderServiceImplTest { public void commit() { } }; - new MockUp<AlarmsHeaderServiceImpl>() { - @Mock - private Session getSession() { - return mockedSession.getMockInstance(); - } - }; - AlarmsHeaderServiceImpl alarmsHeaderServiceImpl = new AlarmsHeaderServiceImpl(); - AlarmsHeader alarmsHeader = null; - alarmsHeaderServiceImpl.saveAlarmsHeader(alarmsHeader); - } + new MockUp<AlarmsHeaderServiceImpl>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; - @Test(expected = Exception.class) - public void testSaveAlarmsHeaderError(){ AlarmsHeaderServiceImpl alarmsHeaderServiceImpl = new AlarmsHeaderServiceImpl(); - alarmsHeaderServiceImpl.saveAlarmsHeader(new AlarmsHeader()); - } + alarmsHeaderServiceImpl.saveAlarmsHeader(a); + } + + + - @Test - public void testUpdateAlarmsHeader2018() throws Exception { - MockUp<Query> mockUpQuery = new MockUp<Query>() { - @Mock - public void setString(String str) { - } - @Mock - public void setDate(Timestamp date) { - } - @Mock - public void executeUpdate() { - } - }; - MockUp<Session> mockedSession = new MockUp<Session>() { - @Mock - public Query createQuery(String hql) { - return mockUpQuery.getMockInstance(); - } - @Mock - public Transaction beginTransaction() { - return transaction; - } - @Mock - public void flush() { - } - }; - new MockUp<SessionFactory>() { - @Mock - public Session openSession() { - return mockedSession.getMockInstance(); - } - }; - new MockUp<Transaction>() { - @Mock - public void getTransaction() { - } - @Mock - public void commit() { - } - }; - new MockUp<AlarmsHeaderServiceImpl>() { - @Mock - private Session getSession() { - return mockedSession.getMockInstance(); - } - }; - AlarmsHeaderServiceImpl alarmsHeaderServiceImpl = new AlarmsHeaderServiceImpl(); - alarmsHeaderServiceImpl.updateAlarmsHeader2018(null, null, null, null, null, null, null); - } - @Test(expected = Exception.class) - public void testUpdateAlarmsHeader2018Error(){ - AlarmsHeaderServiceImpl alarmsHeaderServiceImpl = new AlarmsHeaderServiceImpl(); - alarmsHeaderServiceImpl.updateAlarmsHeader2018(null, null, null, null, null, null, null); - } } |