From: zhangab Date: Wed, 4 Apr 2018 13:02:11 +0000 (+0800) Subject: improve sonar coverage for uui-server X-Git-Tag: v1.1.1~37 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F59%2F40959%2F1;p=usecase-ui%2Fserver.git improve sonar coverage for uui-server Change-Id: I6875768f1ba2427d4896f11cdd2e7cda7ccbb714 Issue-ID: USECASEUI-103 Signed-off-by: zhangab --- 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 c674d192..6b19d789 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 @@ -318,4 +318,152 @@ public class AlarmsHeaderServiceImplTest { public void testQueryStatusCount() throws Exception { alarmsHeaderServiceImpl.queryStatusCount("status"); } + + @Test(expected = Exception.class) + public void testSaveAlarmsHeaderException() { + new MockUp() { + @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() { + @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() { + @Mock + private Session getSession() throws Exception { + throw new Exception(); + } + }; + alarmsHeaderServiceImpl.getStatusBySourceName("sourceName"); + } + + @Test(expected = Exception.class) + public void testGetIdByStatusSourceNameException() { + new MockUp() { + @Mock + private Session getSession() throws Exception { + throw new Exception(); + } + }; + alarmsHeaderServiceImpl.getIdByStatusSourceName("sourceName"); + } + + @Test(expected = Exception.class) + public void testUpdateAlarmsHeaderException() { + new MockUp() { + @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() { + @Mock + private Session getSession() throws Exception { + throw new Exception(); + } + }; + alarmsHeaderServiceImpl.getAllCountByStatus("status"); + } + + @Test(expected = Exception.class) + public void testGetAllByStatusException() { + new MockUp() { + @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() { + @Mock + private Session getSession() throws Exception { + throw new Exception(); + } + }; + alarmsHeaderServiceImpl.getAlarmsHeaderDetail(1); + } + + @Test(expected = Exception.class) + public void testGetAllByDatetimeException() { + new MockUp() { + @Mock + private Session getSession() throws Exception { + throw new Exception(); + } + }; + alarmsHeaderServiceImpl.getAllByDatetime("status", "eventId", "eventServrity", "createTime"); + } + + @Test(expected = Exception.class) + public void testGetAllCountException() { + new MockUp() { + @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() { + @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() { + @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() { + @Mock + private Session getSession() throws Exception { + throw new Exception(); + } + }; + alarmsHeaderServiceImpl.queryStatusCount("status"); + } } diff --git a/server/src/test/java/org/onap/usecaseui/server/service/impl/InitializationServiceImplTest.java b/server/src/test/java/org/onap/usecaseui/server/service/impl/InitializationServiceImplTest.java index 7362ac3f..903047fa 100644 --- a/server/src/test/java/org/onap/usecaseui/server/service/impl/InitializationServiceImplTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/service/impl/InitializationServiceImplTest.java @@ -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
���� 15, 2018
* @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(); + } }