improve sonar coverage for uui-server 21/39521/1
authorzhangab <zhanganbing@chinamobile.com>
Wed, 28 Mar 2018 08:48:21 +0000 (16:48 +0800)
committerzhangab <zhanganbing@chinamobile.com>
Wed, 28 Mar 2018 08:48:26 +0000 (16:48 +0800)
Change-Id: I116812a5dfb312498ab979fffd512029d2e9507c
Issue-ID: USECASEUI-103
Signed-off-by: zhangab <zhanganbing@chinamobile.com>
server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImplTest.java

index 70b2bad..0d2e13b 100644 (file)
@@ -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);
+       }
+
+
+
+
 
 
 }