diff options
2 files changed, 55 insertions, 4 deletions
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java index 5f249ad0..22988cf4 100755 --- a/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java @@ -68,7 +68,7 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService { public String updateAlarmsHeader2018(String status, Timestamp date, String startEpochMicrosecCleared, String lastEpochMicroSecCleared, String eventName, String reportingEntityName, String specificProblem) {
try(Session session = getSession()){
logger.info("AlarmsInformationServiceImpl updateAlarmsInformation: alarmsInformation={}");
- session.beginTransaction();
+ Transaction tx = session.beginTransaction();
Query q=session.createQuery("update AlarmsHeader set status=:status, updateTime=:date, startEpochMicrosecCleared=:startEpochMicrosecCleared ,lastEpochMicroSecCleared=:lastEpochMicroSecCleared where eventName=:eventName and reportingEntityName=:reportingEntityName and specificProblem =:specificProblem");
q.setString("status",status);
@@ -79,7 +79,8 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService { q.setString("reportingEntityName",reportingEntityName);
q.setString("specificProblem",specificProblem);
q.executeUpdate();
- session.getTransaction().commit();
+ tx = session.getTransaction();
+ tx.commit();
session.flush();
return "1";
} catch (Exception e) {
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 f7be8c09..7afc0ecd 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 @@ -48,14 +48,13 @@ import mockit.MockUp; */ public class AlarmsHeaderServiceImplTest { @Before - public void before() throws Exception { + public void before() throws Exception { } @After public void after() throws Exception { } - AlarmsHeaderServiceImpl alarmsHeaderServiceImpl = new AlarmsHeaderServiceImpl(); private Session session; private Transaction transaction; private Query query; @@ -85,14 +84,65 @@ public class AlarmsHeaderServiceImplTest { return mockedSession.getMockInstance(); } }; + AlarmsHeaderServiceImpl alarmsHeaderServiceImpl = new AlarmsHeaderServiceImpl(); AlarmsHeader alarmsHeader = null; alarmsHeaderServiceImpl.saveAlarmsHeader(alarmsHeader); } @Test(expected = Exception.class) public void testSaveAlarmsHeaderError(){ + AlarmsHeaderServiceImpl alarmsHeaderServiceImpl = new AlarmsHeaderServiceImpl(); alarmsHeaderServiceImpl.saveAlarmsHeader(new AlarmsHeader()); } + @Test + public void testUpdateAlarmsHeader2018() throws Exception { + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public void setString(String str) { + } + @Mock + public void setDate(Timestamp date) { + } + @Mock + public void executeUpdate() { + } + }; + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + @Mock + public Transaction beginTransaction() { + return transaction; + } + @Mock + public void flush() { + } + }; + new MockUp<Transaction>() { + @Mock + public void getTransaction() { + } + @Mock + public void commit() { + } + }; + new MockUp<AlarmsHeaderServiceImpl>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + AlarmsHeaderServiceImpl alarmsHeaderServiceImpl = new AlarmsHeaderServiceImpl(); + alarmsHeaderServiceImpl.updateAlarmsHeader2018(null, null, null, null, null, null, null); + } + + @Test(expected = Exception.class) + public void testUpdateAlarmsHeader2018Error(){ + AlarmsHeaderServiceImpl alarmsHeaderServiceImpl = new AlarmsHeaderServiceImpl(); + alarmsHeaderServiceImpl.updateAlarmsHeader2018(null, null, null, null, null, null, null); + } } |