diff options
author | zhangab <zhanganbing@chinamobile.com> | 2018-04-04 21:02:11 +0800 |
---|---|---|
committer | zhangab <zhanganbing@chinamobile.com> | 2018-04-04 21:02:15 +0800 |
commit | d109c69f40a43892e1060eb1e352f439f59d41cb (patch) | |
tree | 81970b9b0a3810e94c9ae56d30bf721b984a4858 | |
parent | 6c48136f595d14b3698b2f158bdfa29077dc527d (diff) |
improve sonar coverage for uui-server
Change-Id: I6875768f1ba2427d4896f11cdd2e7cda7ccbb714
Issue-ID: USECASEUI-103
Signed-off-by: zhangab <zhanganbing@chinamobile.com>
2 files changed, 163 insertions, 27 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 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<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"); + } } 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 <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(); + } } |