aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java24
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java6
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImplTest.java42
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImplTest.java10
4 files changed, 66 insertions, 16 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 6f8904a5..4812589e 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
@@ -158,9 +158,9 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
}
Query query = session.createQuery(count.toString());
query.setString("status",status);
- String num = query.uniqueResult().toString();
+ Object obj = query.uniqueResult();
session.flush();
- return Integer.parseInt(num);
+ return Integer.parseInt(obj.toString());
}catch (Exception e){
logger.error("exception occurred while performing AlarmsHeaderServiceImpl getAllCount."+e.getMessage());
return 0;
@@ -261,9 +261,9 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
query.setString("eventServrity", eventServrity);
}
- String num = query.uniqueResult().toString();
+ Object obj = query.uniqueResult();
session.flush();
- return Integer.parseInt(num);
+ return Integer.parseInt(obj.toString());
}catch (Exception e){
logger.error("exception occurred while performing AlarmsHeaderServiceImpl getAllCount."+e.getMessage());
return 0;
@@ -379,9 +379,9 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
query.setDate("endTime",alarmsHeader.getUpdateTime());
}
- String num = query.uniqueResult().toString();
+ Object obj = query.uniqueResult();
session.flush();
- return Integer.parseInt(num);
+ return Integer.parseInt(obj.toString());
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsHeaderServiceImpl getAllCount. Details:" + e.getMessage());
return -1;
@@ -530,7 +530,8 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
}
List<AlarmsHeader> list = new ArrayList<AlarmsHeader>();
Query query = session.createQuery("from AlarmsHeader a where a.eventName IN (:alist)");
- list = query.setParameterList("alist", id).list();
+ query = query.setParameterList("alist", id);
+ list = query.list();
return list;
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsHeaderServiceImpl queryId. Details:" + e.getMessage());
@@ -542,12 +543,15 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
public String queryStatusCount(String status) {
try(Session session = getSession()){
String hql = "select count(status) from AlarmsHeader a";
- if (!status.equals("0"))
+ if (!status.equals("0")) {
hql+=" where a.status = :status";
+ }
Query query = session.createQuery(hql);
- if (!status.equals("0"))
+ if (!status.equals("0")){
query.setString("status",status);
- return query.uniqueResult().toString();
+ }
+ Object obj = query.uniqueResult();
+ return obj.toString();
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsHeaderServiceImpl queryStatusCount. Details:" + e.getMessage());
return null;
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java
index c099e1f1..f0ac9c39 100755
--- a/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java
@@ -185,7 +185,8 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
List<AlarmsInformation> list = new ArrayList<AlarmsInformation>();
Session session = getSession();
Query query = session.createQuery("from AlarmsInformation a where a.eventId IN (:alist)");
- list = query.setParameterList("alist", id).list();
+ query = query.setParameterList("alist", id);
+ list = query.list();
session.close();
return list;
} catch (Exception e) {
@@ -216,7 +217,8 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
if (startTime != null && !"".equals(startTime) && endTime != null && !"".equals(endTime)){
query.setString("startTime", startTime).setString("endTime", endTime);
}
- Iterator it= query.list().iterator();
+ List<Object[]> queryResult = query.list();
+ Iterator it= queryResult.iterator();
while(it.hasNext()){
Object[] res=(Object[]) it.next();
Map<String,String> map = new HashMap<>();
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 a3fc7197..bb769e22 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
@@ -157,11 +157,23 @@ public class AlarmsHeaderServiceImplTest {
@Test
public void testGetStatusBySourceName() throws Exception {
+ new MockUp<Query>() {
+ @Mock
+ public Object uniqueResult() {
+ return "active";
+ }
+ };
alarmsHeaderServiceImpl.getStatusBySourceName("sourceName");
}
@Test
public void testGetIdByStatusSourceName() throws Exception {
+ new MockUp<Query>() {
+ @Mock
+ public Object uniqueResult() {
+ return "AlarmsHeader";
+ }
+ };
alarmsHeaderServiceImpl.getIdByStatusSourceName("sourceName");
}
@@ -173,6 +185,12 @@ public class AlarmsHeaderServiceImplTest {
@Test
public void testGetAllCountByStatus() throws Exception {
+ new MockUp<Query>() {
+ @Mock
+ public Object uniqueResult() {
+ return "1";
+ }
+ };
alarmsHeaderServiceImpl.getAllCountByStatus("status");
}
@@ -183,17 +201,35 @@ public class AlarmsHeaderServiceImplTest {
@Test
public void testGetAlarmsHeaderDetail() throws Exception {
+ new MockUp<Query>() {
+ @Mock
+ public Object uniqueResult() {
+ return "AlarmsHeader";
+ }
+ };
alarmsHeaderServiceImpl.getAlarmsHeaderDetail(1);
}
@Test
public void testGetAllByDatetime() throws Exception {
+ new MockUp<Query>() {
+ @Mock
+ public Object uniqueResult() {
+ return "1";
+ }
+ };
alarmsHeaderServiceImpl.getAllCountByStatus("status");
alarmsHeaderServiceImpl.getAllByDatetime("status", "eventId", "eventServrity", "createTime");
}
@Test
public void testGetAllCount() throws Exception {
+ new MockUp<Query>() {
+ @Mock
+ public Object uniqueResult() {
+ return "1";
+ }
+ };
AlarmsHeader ah = new AlarmsHeader();
ah.setVersion("va2");
ah.setEventName("a");
@@ -264,6 +300,12 @@ public class AlarmsHeaderServiceImplTest {
@Test
public void testQueryStatusCount() throws Exception {
+ new MockUp<Query>() {
+ @Mock
+ public Object uniqueResult() {
+ return "1";
+ }
+ };
alarmsHeaderServiceImpl.queryStatusCount("status");
}
diff --git a/server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImplTest.java b/server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImplTest.java
index 0993f677..d6dcc1b9 100644
--- a/server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImplTest.java
+++ b/server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImplTest.java
@@ -138,10 +138,6 @@ public class AlarmsInformationServiceImplTest {
private Session getSession() {
return mockedSession.getMockInstance();
}
- @Mock
- private int getAllCount(AlarmsInformation alarmsInformation, int currentPage, int pageSize) {
- return 10;
- }
};
}
@@ -174,6 +170,12 @@ public class AlarmsInformationServiceImplTest {
@Test
public void testQueryAlarmsInformation() throws Exception {
+ new MockUp<AlarmsInformationServiceImpl>() {
+ @Mock
+ private int getAllCount(AlarmsInformation alarmsInformation, int currentPage, int pageSize) {
+ return 10;
+ }
+ };
AlarmsInformation ai = new AlarmsInformation();
ai.setName("name");
ai.setValue("value");