improve sonar coverage for uui-server 59/40959/1
authorzhangab <zhanganbing@chinamobile.com>
Wed, 4 Apr 2018 13:02:11 +0000 (21:02 +0800)
committerzhangab <zhanganbing@chinamobile.com>
Wed, 4 Apr 2018 13:02:15 +0000 (21:02 +0800)
Change-Id: I6875768f1ba2427d4896f11cdd2e7cda7ccbb714
Issue-ID: USECASEUI-103
Signed-off-by: zhangab <zhanganbing@chinamobile.com>
server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImplTest.java
server/src/test/java/org/onap/usecaseui/server/service/impl/InitializationServiceImplTest.java

index c674d19..6b19d78 100644 (file)
@@ -318,4 +318,152 @@ public class AlarmsHeaderServiceImplTest {
        public void testQueryStatusCount() throws Exception {
                alarmsHeaderServiceImpl.queryStatusCount("status");
        }
+
+       @Test(expected = Exception.class)
+       public void testSaveAlarmsHeaderException() {
+               new MockUp<AlarmsHeaderServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               AlarmsHeader ah = new AlarmsHeader();
+               alarmsHeaderServiceImpl.saveAlarmsHeader(ah);
+       }
+
+       @Test(expected = Exception.class)
+       public void testUpdateAlarmsHeader2018Exception() {
+               new MockUp<AlarmsHeaderServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               alarmsHeaderServiceImpl.updateAlarmsHeader2018("status", new Timestamp(System.currentTimeMillis()), "startEpochMicrosecCleared", "lastEpochMicroSecCleared", "eventName", "reportingEntityName", "specificProblem");
+       }
+
+       @Test(expected = Exception.class)
+       public void testGetStatusBySourceNameException() {
+               new MockUp<AlarmsHeaderServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               alarmsHeaderServiceImpl.getStatusBySourceName("sourceName");
+       }
+
+       @Test(expected = Exception.class)
+       public void testGetIdByStatusSourceNameException() {
+               new MockUp<AlarmsHeaderServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               alarmsHeaderServiceImpl.getIdByStatusSourceName("sourceName");
+       }
+
+       @Test(expected = Exception.class)
+       public void testUpdateAlarmsHeaderException() {
+               new MockUp<AlarmsHeaderServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               AlarmsHeader ah = new AlarmsHeader();
+               alarmsHeaderServiceImpl.updateAlarmsHeader(ah);
+       }
+
+       @Test(expected = Exception.class)
+       public void testGetAllCountByStatusException() {
+               new MockUp<AlarmsHeaderServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               alarmsHeaderServiceImpl.getAllCountByStatus("status");
+       }
+
+       @Test(expected = Exception.class)
+       public void testGetAllByStatusException() {
+               new MockUp<AlarmsHeaderServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               alarmsHeaderServiceImpl.getAllByStatus("status", "eventName", "sourceName", "eventServrity", "reportingEntityName", new Timestamp(System.currentTimeMillis()), new Timestamp(System.currentTimeMillis()));
+       }
+
+       @Test(expected = Exception.class)
+       public void testGetAlarmsHeaderDetailException() {
+               new MockUp<AlarmsHeaderServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               alarmsHeaderServiceImpl.getAlarmsHeaderDetail(1);
+       }
+
+       @Test(expected = Exception.class)
+       public void testGetAllByDatetimeException() {
+               new MockUp<AlarmsHeaderServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               alarmsHeaderServiceImpl.getAllByDatetime("status", "eventId", "eventServrity", "createTime");
+       }
+
+       @Test(expected = Exception.class)
+       public void testGetAllCountException() {
+               new MockUp<AlarmsHeaderServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               AlarmsHeader ah = new AlarmsHeader();
+               alarmsHeaderServiceImpl.getAllCount(ah, 1, 1);
+       }
+
+       @Test(expected = Exception.class)
+       public void testQueryAlarmsHeaderException() {
+               new MockUp<AlarmsHeaderServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               AlarmsHeader ah = new AlarmsHeader();
+               alarmsHeaderServiceImpl.queryAlarmsHeader(ah, 1, 1);
+       }
+
+       @Test(expected = Exception.class)
+       public void testQueryIdException() {
+               new MockUp<AlarmsHeaderServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               String[] id = {"1", "2", "3"};
+               alarmsHeaderServiceImpl.queryId(id);
+       }
+
+       @Test(expected = Exception.class)
+       public void testQueryStatusCountException() {
+               new MockUp<AlarmsHeaderServiceImpl>() {
+                       @Mock
+                       private Session getSession() throws Exception {
+                               throw new Exception();
+                       }
+               };
+               alarmsHeaderServiceImpl.queryStatusCount("status");
+       }
 }
index 7362ac3..903047f 100644 (file)
@@ -25,8 +25,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 import org.springframework.test.context.web.WebAppConfiguration;
+import org.onap.usecaseui.server.service.impl.InitializationServiceImpl;
 
-import static org.mockito.Mockito.mock;
+import mockit.Mock;
+import mockit.MockUp;
 
 /** 
 * InitializationServiceImpl Tester. 
@@ -35,33 +37,19 @@ import static org.mockito.Mockito.mock;
 * @since <pre>���� 15, 2018</pre> 
 * @version 1.0 
 */
-@RunWith(SpringJUnit4ClassRunner.class)
-@SpringBootTest(classes = UsecaseuiServerApplication.class)
-@WebAppConfiguration
-public class InitializationServiceImplTest { 
+public class InitializationServiceImplTest {
+       InitializationServiceImpl initializationServiceImpl = null;
 
-   /* @Autowired
-    private InitializationService initializationService;*/
-
-@Before
-public void before() throws Exception { 
-} 
-
-@After
-public void after() throws Exception { 
-} 
-
-/** 
-* 
-* Method: initialize() 
-* 
-*/ 
-@Test
-public void testInitialize() throws Exception { 
-//TODO: Test goes here...
-    InitializationServiceImpl service = mock(InitializationServiceImpl.class);
-    service.initialize();
-} 
+       @Before
+       public void before() throws Exception {
+       }
 
+       @After
+       public void after() throws Exception {
+       }
 
+       @Test
+       public void testInitialize() throws Exception {
+               initializationServiceImpl.initialize();
+       }
 }