improve sonar coverage for uui-server 99/40899/1
authorzhangab <zhanganbing@chinamobile.com>
Wed, 4 Apr 2018 07:09:50 +0000 (15:09 +0800)
committerzhangab <zhanganbing@chinamobile.com>
Wed, 4 Apr 2018 07:09:54 +0000 (15:09 +0800)
Change-Id: I58d8530748289421d79f0fd4ae2c303f13a2e813
Issue-ID: USECASEUI-103
Signed-off-by: zhangab <zhanganbing@chinamobile.com>
server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImplTest.java

index db3d385..1255398 100644 (file)
@@ -50,12 +50,41 @@ import mockit.MockUp;
 */
 public class AlarmsHeaderServiceImplTest {
        AlarmsHeaderServiceImpl alarmsHeaderServiceImpl = null;
+       private static final long serialVersionUID = 1L;
 
        @Before
        public void before() throws Exception { 
                alarmsHeaderServiceImpl = new AlarmsHeaderServiceImpl();
+
+               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 int executeUpdate(String name, Date value) {
+                               return 0;
+                       }
+                       @Mock
+                       public Query setMaxResults(int value) {
+                               return mockUpQuery.getMockInstance();
+                       }
+                       @Mock
+                       public Object uniqueResult() {
+                               return "result";
+                       }
+               };
                MockUp<Session> mockedSession = new MockUp<Session>() {
                        @Mock
                        public Query createQuery(String sql) {
@@ -63,7 +92,11 @@ public class AlarmsHeaderServiceImplTest {
                        }
                        @Mock
                        public Transaction beginTransaction() {
-                               return transaction;
+                               return mockUpTransaction.getMockInstance();
+                       }
+                       @Mock
+                       public Transaction getTransaction() {
+                               return mockUpTransaction.getMockInstance();
                        }
                        @Mock
                        public Serializable save(Object object) {
@@ -91,23 +124,47 @@ public class AlarmsHeaderServiceImplTest {
        public void after() throws Exception { 
        }
 
-       private static final long serialVersionUID = 1L;
-       private Session session;
-       private Transaction transaction;
-       private Query query;
-
        @Test
        public void testSaveAlarmsHeader() throws Exception { 
-               new MockUp<Transaction>() {
-                       @Mock
-                       public void commit() {
-                       }
-               };
-               AlarmsHeader ah = null;
+               AlarmsHeader ah = new AlarmsHeader();
+               ah.setEventName("a");
+               ah.setStatus("1");
+               ah.setVfStatus("1");
+               ah.setEventId("1119");
+               ah.setDomain("asb");
+               ah.setEventCategory("s");
+               ah.setAlarmCondition("ea");
+               ah.setAlarmInterfaceA("cs");
+               ah.setCreateTime(DateUtils.now());
+               ah.setEventServrity("s");
+               ah.setEventSourceType("q");
+               ah.setEventType("q");
+               ah.setFaultFieldsVersion("v1");
+               ah.setLastEpochMicroSec("csa");
+               ah.setNfcNamingCode("std");
+               ah.setNfNamingCode("cout");
+               ah.setPriority("cs");
+               ah.setReportingEntityId("112");
+               ah.setReportingEntityName("asfs");
+               ah.setSequence("cgg");
+               ah.setSourceId("123");
+               ah.setSourceName("eggs");
+               ah.setSpecificProblem("especially");
+               ah.setStartEpochMicrosec("wallet");
+               ah.setUpdateTime(DateUtils.now());
+               ah.setVersion("va2");
                alarmsHeaderServiceImpl.saveAlarmsHeader(ah);
        } 
 
+       @Test
+       public void testUpdateAlarmsHeader2018() throws Exception { 
+               alarmsHeaderServiceImpl.updateAlarmsHeader2018("status", new Timestamp(System.currentTimeMillis()), "startEpochMicrosecCleared", "lastEpochMicroSecCleared", "eventName", "reportingEntityName", "specificProblem");
+       } 
 
+       @Test
+       public void testGetStatusBySourceName() throws Exception { 
+               alarmsHeaderServiceImpl.getStatusBySourceName("sourceName");
+       }