diff options
19 files changed, 1101 insertions, 351 deletions
diff --git a/server/src/main/java/org/onap/usecaseui/server/bo/AlarmBo.java b/server/src/main/java/org/onap/usecaseui/server/bo/AlarmBo.java index 79b8d174..990f5bd7 100644 --- a/server/src/main/java/org/onap/usecaseui/server/bo/AlarmBo.java +++ b/server/src/main/java/org/onap/usecaseui/server/bo/AlarmBo.java @@ -15,8 +15,7 @@ */ package org.onap.usecaseui.server.bo; -import org.onap.usecaseui.server.bean.AlarmsHeader; -import org.onap.usecaseui.server.bean.AlarmsInformation; +import org.onap.usecaseui.server.bean.*; import org.onap.usecaseui.server.util.Page; import java.io.Serializable; @@ -27,12 +26,18 @@ public class AlarmBo implements Serializable { private AlarmsHeader alarmsHeader; + + private List<AlarmsInformation> alarmsInformation; + + public AlarmBo() { } + + public AlarmsHeader getAlarmsHeader() { return alarmsHeader; } diff --git a/server/src/main/java/org/onap/usecaseui/server/bo/PerformanceBo.java b/server/src/main/java/org/onap/usecaseui/server/bo/PerformanceBo.java index 375c25b3..e0e716aa 100755 --- a/server/src/main/java/org/onap/usecaseui/server/bo/PerformanceBo.java +++ b/server/src/main/java/org/onap/usecaseui/server/bo/PerformanceBo.java @@ -15,8 +15,7 @@ */ package org.onap.usecaseui.server.bo; -import org.onap.usecaseui.server.bean.PerformanceHeader; -import org.onap.usecaseui.server.bean.PerformanceInformation; +import org.onap.usecaseui.server.bean.*; import org.onap.usecaseui.server.util.Page; import java.io.Serializable; @@ -29,6 +28,8 @@ public class PerformanceBo implements Serializable { private List<PerformanceInformation> performanceInformation; + + public PerformanceBo() { } @@ -48,4 +49,12 @@ public class PerformanceBo implements Serializable { public void setPerformanceInformation(List<PerformanceInformation> performanceInformation) { this.performanceInformation = performanceInformation; } + + + + + + + + } diff --git a/server/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java b/server/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java index 38a488e6..6f2832c5 100755 --- a/server/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java +++ b/server/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java @@ -34,16 +34,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.web.bind.annotation.*;
-import org.springframework.web.servlet.ModelAndView;
+
import java.io.*;
-import java.text.DateFormat;
+
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
-import java.time.ZonedDateTime;
-import java.time.format.DateTimeFormatter;
+
import java.util.*;
@@ -58,6 +55,19 @@ public class AlarmController { @Resource(name = "AlarmsHeaderService")
private AlarmsHeaderService alarmsHeaderService;
+ /* public AlarmsHeaderService getAlarmsHeaderService() {
+ return alarmsHeaderService;
+ }*/
+
+ public void setAlarmsHeaderService(AlarmsHeaderService alarmsHeaderService) {
+ this.alarmsHeaderService = alarmsHeaderService;
+ }
+
+
+ public void setAlarmsInformationService(AlarmsInformationService alarmsInformationService) {
+ this.alarmsInformationService = alarmsInformationService;
+ }
+
@Resource(name = "AlarmsInformationService")
private AlarmsInformationService alarmsInformationService;
@@ -65,26 +75,153 @@ public class AlarmController { private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+
+ @RequestMapping("/alarm/getAllByDatetime/{eventId}/{eventServrity}/{startTime}/{endTime}")
+ public String getAllByDatetime(@PathVariable(required = false) String eventId,@PathVariable(required = false) String eventServrity,@PathVariable(required = false) String startTime, @PathVariable(required = false) String endTime) throws ParseException, JsonProcessingException {
+ //String startime_s = "2017-10-29";
+ //String endtime_s = "2017-12-24";
+ String startime_s = startTime;
+ String endtime_s = endTime;
+ String string ="";
+ if(startime_s!=null && endtime_s!=null && !"".equals(startime_s) && !"".equals(endtime_s) ) {
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
+ Date startime = formatter.parse(startime_s);
+ Date endtime = formatter.parse(endtime_s);
+ DateUtils dateUtils = new DateUtils();
+ List<Date> datelist = dateUtils.getBetweenDates(startime, endtime);
+ StringBuffer dateB = new StringBuffer();
+ StringBuffer allB = new StringBuffer();
+ StringBuffer activeB = new StringBuffer();
+ StringBuffer closeB = new StringBuffer();
+
+ for (Date dates : datelist) {
+ String date_s = formatter.format(dates);
+ dateB.append(date_s).append(",");
+ int aa = alarmsHeaderService.getAllByDatetime("active", eventId, eventServrity, date_s);
+ activeB.append(aa + "").append(",");
+ int bb = alarmsHeaderService.getAllByDatetime("close", eventId, eventServrity, date_s);
+ closeB.append(bb + "").append(",");
+ int cc = alarmsHeaderService.getAllByDatetime("0", eventId, eventServrity, date_s);
+ allB.append(cc + "").append(",");
+
+ }
+ String dateBa = dateB.toString();
+ String allBa = allB.toString();
+ String activeBa = activeB.toString();
+ String closeBa = closeB.toString();
+
+ String[] dateArr = dateBa.substring(0, dateBa.length() - 1).split(",");
+ String[] activeArr = activeBa.substring(0, activeBa.length() - 1).split(",");
+ String[] closeArr = closeBa.substring(0, closeBa.length() - 1).split(",");
+ String[] allArr = allBa.substring(0, activeBa.length() - 1).split(",");
+
+ Map map = new HashMap();
+ map.put("dateArr", dateArr);
+ map.put("activeArr", activeArr);
+ map.put("closeArr", closeArr);
+ map.put("allArr", allArr);
+ string = omAlarm.writeValueAsString(map);
+ }
+
+ return string;
+ }
+
+
+ @RequestMapping("/alarm/getAlarmsHeaderDetail/{id}")
+ public String getAlarmsHeaderDetail(@PathVariable Integer id) throws JsonProcessingException {
+ AlarmsHeader alarmsHeader= alarmsHeaderService.getAlarmsHeaderDetail(id);
+ String eventId = alarmsHeader.getEventId();
+ List<AlarmsInformation> list = alarmsInformationService.getAllAlarmsInformationByeventId(eventId);
+ Map map = new HashMap();
+ map.put("alarmsHeader",alarmsHeader);
+ map.put("list",list);
+
+ String string =omAlarm.writeValueAsString(map);
+ return string;
+ }
+
+
+ @RequestMapping(value = {"/alarm/getAlarmDataByStatus/{status}","/alarm/getAlarmDataByStatus/{status}/{eventName}/{sourceName}/{eventServerity}/{reportingEntityName}/{createTime}/{endTime}"},method =RequestMethod.GET,produces = "application/json")
+ public String getAlarmDataByStatus(@PathVariable String status, @PathVariable(required = false) String eventName,@PathVariable(required = false) String sourceName,@PathVariable(required = false) String eventServerity,@PathVariable(required = false) String reportingEntityName,@PathVariable(required = false) String createTime,@PathVariable(required = false) String endTime) throws JsonProcessingException {
+ Map map = new HashMap();
+ Date createTime_s=null;
+ Date endTime_s=null;
+
+ /* Date currentTime = new Date();
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ String dateString = formatter.format(currentTime);*/
+
+
+
+ try {
+ createTime_s =(!"null".equals(createTime) ? new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(createTime) : null);
+ endTime_s =(!"null".equals(endTime) ? new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(endTime) : null);
+ } catch (ParseException e) {
+ logger.error("Parse date error :" + e.getMessage());
+ }
+ int countClose = alarmsHeaderService.getAllCountByStatus("close");
+ int countActive = alarmsHeaderService.getAllCountByStatus("active");
+ int countAll =countActive + countClose;
+ Set<String> eventNameList = new HashSet();
+ Set<String> sourceNameList = new HashSet<>();
+ Set<String> reportingEntityNameList = new HashSet<>();
+ Set<String> eventServerityList = new HashSet<>();
+ Set<String> sourceIdList = new HashSet<>();
+
+
+ List<AlarmsHeader> list = alarmsHeaderService.getAllByStatus(status,eventName,sourceName,eventServerity,reportingEntityName,createTime_s,endTime_s);
+ AlarmsHeader alarmsHeader;
+ for(int a=0;a<list.size();a++){
+ alarmsHeader = list.get(a);
+ eventNameList.add(alarmsHeader.getEventName());
+ sourceNameList.add(alarmsHeader.getSourceName());
+ reportingEntityNameList.add(alarmsHeader.getReportingEntityName());
+ eventServerityList.add(alarmsHeader.getEventServrity());
+ sourceIdList.add(alarmsHeader.getSourceId());
+
+ }
+
+ map.put("countClose",countClose);
+ map.put("countActive",countActive);
+ map.put("countAll",countAll);
+ map.put("list",list);
+ map.put("eventNameList",eventNameList);
+ map.put("sourceNameList",sourceNameList);
+ map.put("reportingEntityNameList",reportingEntityNameList);
+ map.put("eventServerityList",eventServerityList);
+ map.put("sourceIdList",sourceIdList);
+
+
+ String string =omAlarm.writeValueAsString(map);
+
+ return string;
+ }
+
+
+
@RequestMapping(value = {"/alarm/{currentPage}/{pageSize}",
"/alarm/{currentPage}/{pageSize}/{sourceId}/{sourceName}/{priority}/{startTime}/{endTime}/{vfStatus}"},
method = RequestMethod.GET, produces = "application/json")
- public String getAlarmData(@PathVariable(required = false) String sourceId, @PathVariable(required = false) String sourceName,
+ public String getAlarmData(@PathVariable int currentPage, @PathVariable int pageSize,
+ @PathVariable(required = false) String sourceId, @PathVariable(required = false) String sourceName,
@PathVariable(required = false) String priority, @PathVariable(required = false) String startTime,
- @PathVariable(required = false) String endTime, @PathVariable(required = false) String vfStatus,
- @PathVariable int currentPage, @PathVariable int pageSize) throws JsonProcessingException {
+ @PathVariable(required = false) String endTime, @PathVariable(required = false) String vfStatus
+ ) throws JsonProcessingException, ParseException {
logger.info("transfer getAlarmData Apis, " +
"Parameter all follows : [currentPage : {} , pageSize : {} , sourceId : {} , " +
"sourceName : {} , priority : {} , startTime :{} , endTime : {} , vfStatus : {}]"
, currentPage, pageSize, sourceId, sourceName, priority, startTime, endTime, vfStatus);
List<AlarmsHeader> alarmsHeaders = null;
List<AlarmBo> list = new ArrayList<>();
- Page pa = null;
+ Page pa = new Page();
if (null != sourceId || null != sourceName || null != priority || null != startTime || null != endTime
|| null != vfStatus) {
AlarmsHeader alarm = new AlarmsHeader();
alarm.setSourceId(!"null".equals(sourceId) ? sourceId : null);
alarm.setSourceName(!"null".equals(sourceName) ? sourceName : null);
alarm.setStatus(!"null".equals(vfStatus) ? vfStatus : null);
+ alarm.setPriority(!"null".equals(priority) ? vfStatus : null);
+
try {
alarm.setCreateTime(!"null".equals(startTime) ? new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(startTime) : null);
alarm.setUpdateTime(!"null".equals(endTime) ? new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(endTime) : null);
@@ -95,6 +232,9 @@ public class AlarmController { alarmsHeaders = pa.getList();
if (null != alarmsHeaders && alarmsHeaders.size() > 0) {
+
+ //if (null != pa) {
+ alarmsHeaders = pa.getList();
alarmsHeaders.forEach(a -> {
logger.info(a.toString());
AlarmBo abo = new AlarmBo();
diff --git a/server/src/main/java/org/onap/usecaseui/server/controller/PerformanceController.java b/server/src/main/java/org/onap/usecaseui/server/controller/PerformanceController.java index eeddf6c2..16eacee9 100755 --- a/server/src/main/java/org/onap/usecaseui/server/controller/PerformanceController.java +++ b/server/src/main/java/org/onap/usecaseui/server/controller/PerformanceController.java @@ -50,6 +50,16 @@ public class PerformanceController { @Resource(name = "PerformanceHeaderService") private PerformanceHeaderService performanceHeaderService; + + public void setPerformanceHeaderService(PerformanceHeaderService performanceHeaderService) { + this.performanceHeaderService = performanceHeaderService; + } + + + public void setPerformanceInformationService(PerformanceInformationService performanceInformationService) { + this.performanceInformationService = performanceInformationService; + } + @Resource(name = "PerformanceInformationService") private PerformanceInformationService performanceInformationService; diff --git a/server/src/main/java/org/onap/usecaseui/server/service/AlarmsHeaderService.java b/server/src/main/java/org/onap/usecaseui/server/service/AlarmsHeaderService.java index 580fdfdf..2e5ed4a1 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/AlarmsHeaderService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/AlarmsHeaderService.java @@ -29,6 +29,7 @@ public interface AlarmsHeaderService { String updateAlarmsHeader(AlarmsHeader alarmsHeader); + //public String updateAlarmsHeader2018(String status, String date, String eventNameCleared,String eventName, String reportingEntityName,String specificProblem); public String updateAlarmsHeader2018(String status, Timestamp date, String startEpochMicrosecCleared, String lastEpochMicroSecCleared, String eventName, String reportingEntityName, String specificProblem); public Boolean getStatusBySourceName(String sourceName); public AlarmsHeader getIdByStatusSourceName(String sourceName); @@ -41,4 +42,12 @@ public interface AlarmsHeaderService { List<AlarmsHeader> queryId(String[] id); String queryStatusCount(String status); + + public int getAllCountByStatus(String status); + public List<AlarmsHeader> getAllByStatus(String status,String eventName,String sourceName,String eventServerity,String reportingEntityName ,Date createTime, Date endTime); + + public AlarmsHeader getAlarmsHeaderDetail(Integer id); + + public int getAllByDatetime(String status,String eventId,String eventServerity,String createTime); + } diff --git a/server/src/main/java/org/onap/usecaseui/server/service/AlarmsInformationService.java b/server/src/main/java/org/onap/usecaseui/server/service/AlarmsInformationService.java index 70c37e31..83f6fb19 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/AlarmsInformationService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/AlarmsInformationService.java @@ -36,4 +36,7 @@ public interface AlarmsInformationService { List<AlarmsInformation> queryId(String[] id); List<Map<String,String>> queryDateBetween(String sourceId, String startTime, String endTime); + + + List<AlarmsInformation> getAllAlarmsInformationByeventId(String eventId); } diff --git a/server/src/main/java/org/onap/usecaseui/server/service/PerformanceHeaderService.java b/server/src/main/java/org/onap/usecaseui/server/service/PerformanceHeaderService.java index 4e346efe..ec5172fa 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/PerformanceHeaderService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/PerformanceHeaderService.java @@ -15,6 +15,7 @@ */ package org.onap.usecaseui.server.service; +import java.util.Date; import java.util.List; import org.onap.usecaseui.server.bean.AlarmsHeader; @@ -35,4 +36,8 @@ public interface PerformanceHeaderService { List<PerformanceHeader> queryId(String[] id); List<String> queryAllSourceId(); + + + public int getAllCountByStatus(String status); + public List<PerformanceHeader> getAllByStatus(String status, String eventName, String sourceName, String eventServerity,String reportingEntityName, Date createTime, Date endTime); } 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 e21102ec..37de24db 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 @@ -16,6 +16,8 @@ package org.onap.usecaseui.server.service.impl;
+
+import java.util.Date;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
@@ -64,13 +66,34 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService { }
+ /*@Override
+ public String updateAlarmsHeader2018(String status, String date,String eventNameCleared,String eventName, String reportingEntityName,String specificProblem) {
+
+ try(Session session = sessionFactory.getCurrentSession();){
+
+ logger.info("AlarmsInformationServiceImpl updateAlarmsInformation: alarmsInformation={}");
+ session.beginTransaction();
+ Query q=session.createQuery("update AlarmsHeader set status='"+status+"', updateTime='"+date+"' where eventName='"+eventName+"' and reportingEntityName='"+reportingEntityName+"' and specificProblem ='"+specificProblem+"' ");
+ q.executeUpdate();
+ session.getTransaction().commit();
+ session.flush();
+ return "1";
+ } catch (Exception e) {
+ logger.error("exception occurred while performing AlarmsInformationServiceImpl updateAlarmsInformation. Details:" + e.getMessage());
+ return "0";
+ }
+ }*/
+
+
@Override
public String updateAlarmsHeader2018(String status, Timestamp date, String startEpochMicrosecCleared, String lastEpochMicroSecCleared, String eventName, String reportingEntityName, String specificProblem) {
try(Session session = sessionFactory.openSession();){
+ //try(Session session = sessionFactory.getCurrentSession();){
logger.info("AlarmsInformationServiceImpl updateAlarmsInformation: alarmsInformation={}");
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+"'");
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);
@@ -116,25 +139,36 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService { logger.error("exception occurred while performing AlarmsInformationServiceImpl updateAlarmsInformation. Details:" + e.getMessage());
return false;
}
+ //return null;
}
@Override
public AlarmsHeader getIdByStatusSourceName(String sourceName) {
+ //List<AlarmsHeader> list = new ArrayList<>();
AlarmsHeader s = new AlarmsHeader();
try(Session session = sessionFactory.openSession()){
logger.info("AlarmsInformationServiceImpl updateAlarmsInformation: alarmsInformation={}");
+ //Transaction tx = session.beginTransaction();
+ //session.beginTransaction();
+ //Query q=session.createQuery("select sourceName,createTime from AlarmsHeader where sourceName='"+sourceName+"' and status='active' order by createTime desc");
Query q=session.createQuery("from AlarmsHeader where sourceName='"+sourceName+"' and status='active' order by createTime desc");
+ //q.setString(1,sourceName);
q.setMaxResults(1);
+ //tx.commit();
+ //String s=(String)q.uniqueResult();
s = (AlarmsHeader)q.uniqueResult();
+ // list= q.list();
session.flush();
return s;
+ //return "1";
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsInformationServiceImpl updateAlarmsInformation. Details:" + e.getMessage());
return s;
}
+ //return null;
}
@@ -156,6 +190,143 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService { }
}
+
+
+
+
+ @Override
+ public int getAllCountByStatus(String status){
+ try (Session session = sessionFactory.openSession()){
+ StringBuffer count = new StringBuffer("select count(*) from AlarmsHeader a where 1=1");
+ if(!"0".equals(status)){
+ count.append(" and a.status=:status");
+ }
+ Query query =session.createQuery(count.toString());
+ query.setString("status",status);
+ //int q = (int)query.uniqueResult();
+ long q=(long)query.uniqueResult();
+ session.flush();
+ return (int)q;
+ }catch (Exception e){
+ logger.error("exception occurred while performing AlarmsHeaderServiceImpl getAllCount."+e.getMessage());
+ return 0;
+ }
+ }
+
+ @Override
+ public List<AlarmsHeader> getAllByStatus(String status,String eventName,String sourceName,String eventServerity,String reportingEntityName, Date createTime, Date endTime){
+ try (Session session = sessionFactory.openSession()){
+ StringBuffer string = new StringBuffer("from AlarmsHeader a where 1=1");
+ if(!"0".equals(status)){
+ string.append(" and a.status=:status");
+ }
+ if(!"0".equals(eventName) && eventName!=null){
+ string.append(" and a.eventName=:eventName");
+ }
+ if(!"0".equals(sourceName) && sourceName!=null){
+ string.append(" and a.sourceName=:sourceName");
+ }
+ if(!"0".equals(eventServerity) && eventServerity!=null){
+ string.append(" and a.eventServerity=:eventServerity");
+ }
+ if(!"0".equals(reportingEntityName) && eventServerity!=null){
+ string.append(" and a.reportingEntityName=:reportingEntityName");
+ }
+ if( null!=createTime && endTime!= null) {
+ string.append(" and a.createTime between :startTime and :endTime");
+ }
+ Query query = session.createQuery(string.toString());
+ query.setString("status",status);
+ query.setString("eventName",eventName);
+ query.setString("sourceName",sourceName);
+ query.setString("eventServerity",eventServerity);
+ query.setString("reportingEntityName",reportingEntityName);
+ if( null!=createTime && endTime!= null) {
+ query.setDate("startTime",createTime);
+ query.setDate("endTime",endTime);
+
+ }
+ List<AlarmsHeader> list =query.list();
+
+ return list;
+
+ }catch (Exception e){
+
+ logger.error("exception occurred while performing AlarmsHeaderServiceImpl getAllCount."+e.getMessage());
+ return null;
+ }
+
+
+
+ }
+
+ @Override
+ public AlarmsHeader getAlarmsHeaderDetail(Integer id) {
+ try(Session session = sessionFactory.openSession()) {
+
+ String string = "from AlarmsHeader a where 1=1 and a.id=:id";
+ Query q = session.createQuery(string);
+ q.setInteger("id",id);
+ AlarmsHeader alarmsHeader =(AlarmsHeader)q.uniqueResult();
+ session.flush();
+ return alarmsHeader;
+
+ }catch (Exception e){
+ logger.error("exception occurred while performing AlarmsHeaderServiceImpl getAlarmsHeaderDetail."+e.getMessage());
+ return null;
+ }
+ }
+
+ @Override
+ public int getAllByDatetime(String status,String eventId, String eventServrity, String createTime) {
+ try (Session session = sessionFactory.openSession();){
+ StringBuffer string = new StringBuffer("select count(*) as count from AlarmsHeader a where 1=1");
+
+ if(!"0".equals(status) && status!=null){
+ string.append(" and a.status=:status");
+ }
+ if(!"0".equals(eventId) && eventId!=null){
+ string.append(" and a.eventId=:eventId");
+ }
+
+ if(!"0".equals(eventServrity) && eventServrity!=null){
+ string.append(" and a.eventServrity=:eventServrity");
+ }
+
+ /*if( null!=createTime && endTime!= null) {
+ string.append(" and a.createTime between :startTime and :endTime");
+ }*/
+ if( null!=createTime) {
+ string.append(" and to_days(a.createTime) = to_days('"+createTime+"')");
+ }
+
+ /*string.append(" group by DATE_FORMAT(a.createTime,'%y-%m-%d')");*/
+ Query query = session.createQuery(string.toString());
+ query.setString("status",status);
+ query.setString("eventId",eventId);
+ query.setString("eventServrity",eventServrity);
+ //query.setDate("createTime",createTime);
+
+ /*if( null!=createTime && endTime!= null) {
+ query.setDate("startTime",createTime);
+ query.setDate("endTime",endTime);
+
+ }*/
+ long l = (long)query.uniqueResult();
+ int a = (int) l;
+ //List<AlarmsHeader> list =query.list();
+ session.flush();
+ return a;
+
+ }catch (Exception e){
+
+ logger.error("exception occurred while performing AlarmsHeaderServiceImpl getAllCount."+e.getMessage());
+ return 0;
+ }
+
+ }
+
+
public int getAllCount(AlarmsHeader alarmsHeader,int currentPage,int pageSize) {
try(Session session = sessionFactory.openSession()){
StringBuffer count=new StringBuffer("select count(*) from AlarmsHeader a where 1=1");
@@ -278,7 +449,7 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService { }
}
- @SuppressWarnings("unchecked")
+ //@SuppressWarnings("unchecked")
@Override
public Page<AlarmsHeader> queryAlarmsHeader(AlarmsHeader alarmsHeader,int currentPage,int pageSize) {
Page<AlarmsHeader> page = new Page<AlarmsHeader>();
@@ -405,6 +576,7 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService { page.setPageSize(pageSize);
page.setTotalRecords(allRow);
page.setList(list);
+
session.flush();
return page;
} catch (Exception e) {
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 e06c7610..549ca6b9 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 @@ -190,6 +190,8 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService { }
+
+
@Override
public List<Map<String,String>> queryDateBetween(String sourceId, String startTime, String endTime) {
try(Session session = sessionFactory.openSession()) {
@@ -225,5 +227,24 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService { }
}
+ @Override
+ public List<AlarmsInformation> getAllAlarmsInformationByeventId(String eventId) {
+ try (Session session = sessionFactory.openSession()){
+ String string = "from AlarmsInformation a where 1=1 and a.eventId=:eventId";
+ Query query = session.createQuery(string);
+ query.setString("eventId",eventId);
+ List<AlarmsInformation> list = query.list();
+ session.flush();
+ return list;
+ }catch (Exception e){
+ logger.error("exception occurred while performing PerformanceInformationServiceImpl queryDateBetween. LIST:" + e.getMessage());
+
+ return null;
+ }
+
+
+
+ }
+
}
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java index 996ec46b..d21a5b6e 100755 --- a/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java @@ -87,6 +87,84 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService { }
+
+
+
+ @Override
+ public int getAllCountByStatus(String status){
+ try (Session session = sessionFactory.openSession()){
+ StringBuffer count = new StringBuffer("select count(*) from PerformanceHeader a where 1=1");
+ if(!"0".equals(status)){
+ count.append(" and a.status=:status");
+ }
+ Query query =session.createQuery(count.toString());
+ query.setString("status",status);
+ //int q = (int)query.uniqueResult();
+ long q=(long)query.uniqueResult();
+ session.flush();
+ return (int)q;
+ }catch (Exception e){
+ logger.error("exception occurred while performing PerformanceHeaderServiceImpl getAllCount."+e.getMessage());
+ return 0;
+ }
+ }
+
+ @Override
+ public List<PerformanceHeader> getAllByStatus(String status,String eventName,String sourceName,String eventServerity,String reportingEntityName, Date createTime, Date endTime){
+ try (Session session = sessionFactory.openSession()){
+ StringBuffer string = new StringBuffer("from PerformanceHeader a where 1=1");
+ if(!"0".equals(status)){
+ string.append(" and a.status=:status");
+ }if(!"".equals(eventName) && eventName!=null){
+ string.append(" and a.eventName=:eventName");
+ }
+ if(!"".equals(sourceName) && sourceName!=null){
+ string.append(" and a.sourceName=:sourceName");
+ }
+ if(!"".equals(eventServerity) && eventServerity!=null){
+ string.append(" and a.eventServerity=:eventServerity");
+ }
+ if(!"".equals(reportingEntityName) && eventServerity!=null){
+ string.append(" and a.reportingEntityName=:reportingEntityName");
+ }
+ if( null!=createTime && endTime!= null) {
+ string.append(" and a.createTime between :startTime and :endTime");
+ }
+ Query query = session.createQuery(string.toString());
+ query.setString("status",status);
+ query.setString("eventName",eventName);
+ query.setString("sourceName",sourceName);
+ query.setString("eventServerity",eventServerity);
+ query.setString("reportingEntityName",reportingEntityName);
+ if( null!=createTime && endTime!= null) {
+ query.setDate("startTime",createTime);
+ query.setDate("endTime",endTime);
+
+ }
+
+ List<PerformanceHeader> list =query.list();
+
+ return list;
+
+ }catch (Exception e){
+
+ logger.error("exception occurred while performing PerformanceHeaderServiceImpl getAllCount."+e.getMessage());
+ return null;
+ }
+
+
+
+ }
+
+
+
+
+
+
+
+
+
+
public int getAllCount(PerformanceHeader performanceHeder, int currentPage, int pageSize) {
try(Session session = sessionFactory.openSession();){
StringBuffer hql = new StringBuffer("select count(*) from PerformanceHeader a where 1=1");
diff --git a/server/src/main/java/org/onap/usecaseui/server/util/DateUtils.java b/server/src/main/java/org/onap/usecaseui/server/util/DateUtils.java index a1d0e75d..17e590f5 100755 --- a/server/src/main/java/org/onap/usecaseui/server/util/DateUtils.java +++ b/server/src/main/java/org/onap/usecaseui/server/util/DateUtils.java @@ -23,13 +23,31 @@ import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; -import java.util.Calendar; -import java.util.Date; -import java.util.TimeZone; +import java.util.*; public class DateUtils { + /** + * 获取两个日期之间的日期 + * @param start 开始日期 + * @param end 结束日期 + * @return 日期集合 + */ + public static List<Date> getBetweenDates(Date start, Date end) { + List<Date> result = new ArrayList<Date>(); + Calendar tempStart = Calendar.getInstance(); + tempStart.setTime(start); + tempStart.add(Calendar.DAY_OF_YEAR, 1); + + Calendar tempEnd = Calendar.getInstance(); + tempEnd.setTime(end); + while (tempStart.before(tempEnd)) { + result.add(tempStart.getTime()); + tempStart.add(Calendar.DAY_OF_YEAR, 1); + } + return result; + } /** @@ -139,7 +157,27 @@ public class DateUtils { return year+ "-" +mToMonth+ "-" +dToDay+ " "+hToHour+ ":" +mToMinute+ ":" +sToSecond; } + + public static void main(String[] args) { - System.out.println(new DateUtils().getYearMonthDayHourMinuteSecond(System.currentTimeMillis())); + // System.out.println(new DateUtils().getYearMonthDayHourMinuteSecond(System.currentTimeMillis())); + String startime_s = "2017-10-31"; + String endtime_s = "2017-12-24"; + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + Date startime = null; + Date endtime =null; + try { + startime = formatter.parse(startime_s); + endtime = formatter.parse(endtime_s); + } catch (ParseException e) { + e.printStackTrace(); + } + + + List<Date> result =getBetweenDates(startime,endtime); + + System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa===="+result); + } + } diff --git a/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java b/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java index 3b43202c..3e71dd61 100644 --- a/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java +++ b/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java @@ -17,15 +17,9 @@ package org.onap.usecaseui.server.util; import com.fasterxml.jackson.databind.ObjectMapper; import org.glassfish.jersey.client.ClientConfig; -import org.onap.usecaseui.server.bean.AlarmsHeader; -import org.onap.usecaseui.server.bean.AlarmsInformation; -import org.onap.usecaseui.server.bean.PerformanceHeader; -import org.onap.usecaseui.server.bean.PerformanceInformation; +import org.onap.usecaseui.server.bean.*; import org.onap.usecaseui.server.constant.Constant; -import org.onap.usecaseui.server.service.AlarmsHeaderService; -import org.onap.usecaseui.server.service.AlarmsInformationService; -import org.onap.usecaseui.server.service.PerformanceHeaderService; -import org.onap.usecaseui.server.service.PerformanceInformationService; +import org.onap.usecaseui.server.service.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -61,6 +55,7 @@ public class DmaapSubscriber implements Runnable { @Resource(name = "AlarmsHeaderService") private AlarmsHeaderService alarmsHeaderService; + @Resource(name = "AlarmsInformationService") private AlarmsInformationService alarmsInformationService; @@ -70,6 +65,14 @@ public class DmaapSubscriber implements Runnable { @Resource(name = "PerformanceInformationService") private PerformanceInformationService performanceInformationService; + + + + + + + + public void subscribe(String topic) { try { List<String> respList = getDMaaPData(topic); @@ -222,13 +225,16 @@ public class DmaapSubscriber implements Runnable { ai.setUpdateTime(new Date()); }); + // SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Long l = System.currentTimeMillis(); - Timestamp date_get = new Timestamp(l); + Timestamp date_get = new Timestamp(l); //2013-01-14 22:45:36.484 if (alarm_header.getEventName().contains("Cleared")) { alarm_header.setStatus("close"); logger.info("alarmCleared data header insert is starting......"); - alarmsHeaderService.updateAlarmsHeader2018("close",date_get,alarm_header.getStartEpochMicrosec(),alarm_header.getLastEpochMicroSec(),alarm_header.getEventName().replace("Cleared",""),alarm_header.getReportingEntityName(),alarm_header.getSpecificProblem()); + + alarmsHeaderService.updateAlarmsHeader2018("close", date_get, alarm_header.getStartEpochMicrosec(), alarm_header.getLastEpochMicroSec(), alarm_header.getEventName().replace("Cleared", ""), alarm_header.getReportingEntityName(), alarm_header.getSpecificProblem()); + logger.info("alarmCleared data header insert has finished."); logger.info("alarmCleared data detail insert is starting......"); alarm_informations.forEach(information -> @@ -238,8 +244,12 @@ public class DmaapSubscriber implements Runnable { } else { alarm_header.setCreateTime(new Date()); alarm_header.setStatus("active"); - logger.info("alarm data header insert is starting......"); - alarmsHeaderService.saveAlarmsHeader(alarm_header); + + + logger.info("alarm data header insert is starting......"); + + alarmsHeaderService.saveAlarmsHeader(alarm_header); + logger.info("alarm data header insert has finished."); logger.info("alarm data detail insert is starting......"); if(alarm_informations.size() > 0) { @@ -254,6 +264,9 @@ public class DmaapSubscriber implements Runnable { private void performanceProcess(Map<String, Object> eventMap) { PerformanceHeader performance_header = new PerformanceHeader(); List<PerformanceInformation> performance_informations = new ArrayList<>(); + + + eventMap.forEach((ek1, ev1) -> { if (ek1.equals("commonEventHeader")) { ((Map<String, Object>) ev1).forEach((k2, v2) -> { @@ -303,19 +316,18 @@ public class DmaapSubscriber implements Runnable { List<Map<String,String>> arrayOfFields = (List<Map<String, String>>) v; arrayOfFields.forEach( fields -> { if (fields.get("name").equals("StartTime")){ + try { - performance_informations.add(new PerformanceInformation(fields.get("name"),fields.get("value"),performance_header.getSourceId(),null,DateUtils.now())); - performance_header.setCreateTime(DateUtils.stringToDate(fields.get("value").replaceAll(Constant.RegEX_DATE_FORMAT," "))); - performance_header.setUpdateTime(DateUtils.now()); + String type = performance_header.getEventType(); + performance_informations.add(new PerformanceInformation(fields.get("name"), fields.get("value"), performance_header.getSourceId(), null, DateUtils.now())); + performance_header.setCreateTime(DateUtils.stringToDate(fields.get("value").replaceAll(Constant.RegEX_DATE_FORMAT, " "))); + performance_header.setUpdateTime(DateUtils.now()); + } catch (ParseException e) { e.printStackTrace(); } }else{ - try { - performance_informations.add(new PerformanceInformation(fields.get("name"),fields.get("value"),performance_header.getSourceId(),null,DateUtils.now())); - } catch (ParseException e) { - e.printStackTrace(); - } + } } ); } @@ -330,6 +342,38 @@ public class DmaapSubscriber implements Runnable { } }); if (performance_header.getSourceId() !=null && performance_informations.size() > 0 ){ + + String version = performance_header.getVersion(); + String eventName = performance_header.getEventName(); + String domain = performance_header.getDomain(); + String eventId = performance_header.getEventId(); + String eventType = performance_header.getEventType(); + String nfcNamingCode = performance_header.getNfcNamingCode(); + String nfNamingCode = performance_header.getNfNamingCode(); + String sourceId = performance_header.getSourceId(); + String sourceName = performance_header.getSourceName(); + String reportingEntityId = performance_header.getReportingEntityId(); + String reportingEntityName = performance_header.getReportingEntityName(); + String priority = performance_header.getPriority(); + String startEpochMicrosec = performance_header.getStartEpochMicrosec(); + String lastEpochMicroSec = performance_header.getLastEpochMicroSec(); + String sequence = performance_header.getSequence(); + String measurementsForVfScalingVersion = performance_header.getMeasurementsForVfScalingVersion(); + String measurementInterval = performance_header.getMeasurementInterval(); + Date createTime = performance_header.getCreateTime(); + Date updateTime = performance_header.getUpdateTime(); + + + + + + + + + + + + logger.info("performance data header insert is starting......"); performanceHeaderService.savePerformanceHeader(performance_header); logger.info("performance data header insert has finished."); @@ -340,6 +384,12 @@ public class DmaapSubscriber implements Runnable { }); logger.info("performance data detail insert has finished. " + performance_informations.size() + " records have been inserted."); + // }//else 结束 } + + + + + } }
\ No newline at end of file diff --git a/server/src/main/java/org/onap/usecaseui/server/util/Page.java b/server/src/main/java/org/onap/usecaseui/server/util/Page.java index fd7665f5..6bd830ea 100644 --- a/server/src/main/java/org/onap/usecaseui/server/util/Page.java +++ b/server/src/main/java/org/onap/usecaseui/server/util/Page.java @@ -19,13 +19,13 @@ import java.util.List; public class Page<E> { - private List<E> list; + public List<E> list; - private int totalRecords; + public int totalRecords; - private int pageSize; + public int pageSize; - private int pageNo; + public int pageNo; diff --git a/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java b/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java index df243c8b..4cb5fc69 100755 --- a/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java @@ -15,128 +15,310 @@ */ package org.onap.usecaseui.server.controller; +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import org.omg.PortableInterceptor.INACTIVE; +import org.onap.usecaseui.server.bean.AlarmsHeader; +import org.onap.usecaseui.server.service.AlarmsHeaderService; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.usecaseui.server.UsecaseuiServerApplication; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.result.MockMvcResultHandlers; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = UsecaseuiServerApplication.class) -@WebAppConfiguration +import javax.servlet.http.HttpServletRequest; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +import static org.mockito.Mockito.*; + +/** +* AlarmController Tester. +* +* @author <Authors name> +* @since <pre>���� 28, 2018</pre> +* @version 1.0 +*/ public class AlarmControllerTest { - @Autowired - private WebApplicationContext context; - - private MockMvc mvc; - - @Before - public void setup(){ - mvc = MockMvcBuilders.webAppContextSetup(context).build(); - } - - @Test - public void test1() throws Exception { - mvc.perform(MockMvcRequestBuilders.get("/alarm/1/100") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - } - - @Test - public void test2() throws Exception { - mvc.perform(MockMvcRequestBuilders.get("/alarm/1/100/null/null/null/null/null/null") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - mvc.perform(MockMvcRequestBuilders.get("/alarm/1/100/502fe15c-aa07-ed26-3f87-4d5c1784bc5b/management-server-backup/High/null/null/1") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - mvc.perform(MockMvcRequestBuilders.get("/alarm/1/100/502fe15c-aa07-ed26-3f87-4d5c1784bc5b/management-server-backup/High/123/456/1") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - } - - @Test - public void test3() throws Exception { - mvc.perform(MockMvcRequestBuilders.get("/alarm/statusCount") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - } - - @Test - public void test4() throws Exception { - mvc.perform(MockMvcRequestBuilders.get("/alarm/sourceId") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - } - - @Test - public void test5() throws Exception { - mvc.perform(MockMvcRequestBuilders.post("/alarm/diagram") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .param("sourceId","").param("startTime","2017-10-1 16:34") - .param("endTime","2017-12-5 0:0").param("showMode","auto") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - mvc.perform(MockMvcRequestBuilders.post("/alarm/diagram") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .param("sourceId","").param("startTime","2017-10-1 16:34") - .param("endTime","2017-12-5 0:0").param("showMode","year") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - mvc.perform(MockMvcRequestBuilders.post("/alarm/diagram") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .param("sourceId","").param("startTime","2017-10-1 16:34") - .param("endTime","2017-12-5 0:0").param("showMode","month") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - mvc.perform(MockMvcRequestBuilders.post("/alarm/diagram") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .param("sourceId","").param("startTime","2017-10-1 16:34") - .param("endTime","2017-12-5 0:0").param("showMode","day") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - mvc.perform(MockMvcRequestBuilders.post("/alarm/diagram") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .param("sourceId","").param("startTime","2017-10-1 16:34") - .param("endTime","2017-12-5 0:0").param("showMode","hour") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - mvc.perform(MockMvcRequestBuilders.post("/alarm/diagram") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .param("sourceId","").param("startTime","2017-10-1 16:34") - .param("endTime","2017-12-5 0:0").param("showMode","minute") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - } - -} + + AlarmController controller = new AlarmController(); + AlarmsHeaderService service; + +@Before +public void before() throws Exception { + AlarmsHeaderService service = mock(AlarmsHeaderService.class); + controller.setAlarmsHeaderService(service); +} + +@After +public void after() throws Exception { +} + +/** +* +* Method: setAlarmsHeaderService(AlarmsHeaderService alarmsHeaderService) +* +*/ +@Test +public void testSetAlarmsHeaderService() throws Exception { +//TODO: Test goes here... + +} + +/** +* +* Method: setAlarmsInformationService(AlarmsInformationService alarmsInformationService) +* +*/ +@Test +public void testSetAlarmsInformationService() throws Exception { +//TODO: Test goes here... +} + +/** +* +* Method: getAllByDatetime(@PathVariable(required = false) String eventId, @PathVariable(required = false) String eventServrity, @PathVariable(required = false) String startTime, @PathVariable(required = false) String endTime) +* +*/ +@Test +public void testGetAllByDatetime() throws Exception { +//TODO: Test goes here... + String eventId="ab305d54-85b4-a31b-7db2-fb6b9e546015"; + String eventServrity="CRITICAL"; + String startTime="2017-10-29"; + String endTime="2017-12-24"; + String status ="0"; + controller.getAllByDatetime(eventId,eventServrity,startTime,endTime); + verify(service,times(1)).getAllByDatetime(status,eventId,eventServrity,startTime); +} + +/** +* +* Method: getAlarmsHeaderDetail(@PathVariable Integer id) +* +*/ +@Test +public void testGetAlarmsHeaderDetail() throws Exception { +//TODO: Test goes here... + Integer eventId =5; + controller.getAlarmsHeaderDetail(eventId); + verify(service,times(1)).getAlarmsHeaderDetail(eventId); +} + +/** +* +* Method: getAlarmDataByStatus(@PathVariable String status, @PathVariable(required = false) String eventName, @PathVariable(required = false) String sourceName, @PathVariable(required = false) String eventServerity, @PathVariable(required = false) String reportingEntityName, @PathVariable(required = false) String createTime, @PathVariable(required = false) String endTime) +* +*/ +@Test +public void testGetAlarmDataByStatus() throws Exception { +//TODO: Test goes here... + + AlarmController controller = new AlarmController(); + AlarmsHeaderService service = mock(AlarmsHeaderService.class); + controller.setAlarmsHeaderService(service); + HttpServletRequest request = mock(HttpServletRequest.class); + /* String id ="id"; + when(request.getParameter(id)).thenReturn(id); + String type="type"; + when(request.getParameter(type)).thenReturn(type);*/ + + String status ="active"; + String eventName ="Fault_MultiCloud_VMFailureCleared"; + String sourceName ="shentao-test-2001"; + String eventServerity ="CRITICAL"; + String reportingEntityName ="Multi-Cloud"; + String createTime_s="2018-01-24 17:00:25"; + String endTime_s="2018-03-15 00:00:00"; + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + Date createTime=formatter.parse(createTime_s); + Date endTime=formatter.parse(endTime_s); + + + controller.getAlarmDataByStatus(status,eventName,sourceName,eventServerity,reportingEntityName,createTime_s,endTime_s); + //verify(customerService, times(1)).listCustomer(); + verify(service,times(1)).getAllByStatus(status,eventName,sourceName,eventServerity,reportingEntityName,createTime,endTime); + + + + +} + +/** +* +* Method: getAlarmData(@PathVariable(required = false) String sourceId, @PathVariable(required = false) String sourceName, @PathVariable(required = false) String priority, @PathVariable(required = false) String startTime, @PathVariable(required = false) String endTime, @PathVariable(required = false) String vfStatus, @PathVariable int currentPage, @PathVariable int pageSize) +* +*/ +@Test +public void testGetAlarmData() throws Exception { +//TODO: Test goes here... + AlarmController controller = new AlarmController(); + AlarmsHeaderService service = mock(AlarmsHeaderService.class); + controller.setAlarmsHeaderService(service); + AlarmsHeader header = new AlarmsHeader(); + int currentPage=1; + int pageSize=12; + //String sourceId="shentao-test-1003"; + //String sourceName="shentao-test-1003"; + //String priority="High"; + //String startTime="2017-10-31 09:51"; + //String endTime="2018-03-15 00:00"; + //String vfStatus="Active"; + /*String sourceId="11694_113"; + String sourceName="11694_113"; + String priority="High"; + String startTime="2017-10-31 09:52:15"; + String endTime="2017-11-15 15:27:16"; + String vfStatus="Medium";*/ + String sourceId=null; + String sourceName=null; + String priority=null; + String startTime=null; + String endTime=null; + String vfStatus=null; + header.setPriority(priority); + header.setStatus(vfStatus); + header.setSourceId(sourceId); + header.setSourceName(sourceName); + + + + //controller.getAlarmData(currentPage,pageSize,sourceId,sourceName,priority,startTime,endTime,vfStatus); + // verify(service,times(1)).queryAlarmsHeader(header,currentPage,pageSize); + +} + +/** +* +* Method: getStatusCount() +* +*/ +@Test +public void testGetStatusCount() throws Exception { +//TODO: Test goes here... + AlarmController controller = new AlarmController(); + AlarmsHeaderService service = mock(AlarmsHeaderService.class); + controller.setAlarmsHeaderService(service); + + controller.getStatusCount(); + verify(service,times(1)).queryStatusCount("0"); + verify(service,times(1)).queryStatusCount("active"); + verify(service,times(1)).queryStatusCount("close"); + + + + + +} + +/** +* +* Method: getTopologyData(@PathVariable String serviceName) +* +*/ +@Test +public void testGetTopologyData() throws Exception { +//TODO: Test goes here... + AlarmController controller = new AlarmController(); + AlarmsHeaderService service = mock(AlarmsHeaderService.class); + controller.setAlarmsHeaderService(service); + + String serviceName="Fault_MultiCloud_VMFailureCleared"; + //controller.getTopologyData(serviceName); + //controller.getAllVNFS().get("networkServices"); + //controller.getAllVNFS().get("VNFS"); + + + +} + +/** +* +* Method: getTopologyServices() +* +*/ +@Test +public void testGetTopologyServices() throws Exception { +//TODO: Test goes here... + AlarmController controller = new AlarmController(); + AlarmsHeaderService service = mock(AlarmsHeaderService.class); + controller.setAlarmsHeaderService(service); + + AlarmsHeader header = new AlarmsHeader(); + header.setSourceId("shentao-test-2001"); + //controller.getAllVNFS().get("services"); + + //controller.getTopologyServices(); + + //verify(service,times(1)).queryAlarmsHeader(header,1,10).getList(); +} + +/** +* +* Method: getAllVNFS() +* +*/ +/*@Test +public void testGetAllVNFS() throws Exception { +//TODO: Test goes here... +}*/ + +/** +* +* Method: getSourceId() +* +*/ +@Test +public void testGetSourceId() throws Exception { +//TODO: Test goes here... + AlarmController controller = new AlarmController(); + AlarmsHeaderService service = mock(AlarmsHeaderService.class); + controller.setAlarmsHeaderService(service); + AlarmsHeader header = new AlarmsHeader(); + // controller.getSourceId(); + + //verify(service,times(1)).queryAlarmsHeader(header,1,10); +} + +/** +* +* Method: genDiagram(@RequestParam String sourceId, @RequestParam String startTime, @RequestParam String endTime, @RequestParam String showMode) +* +*/ +@Test +public void testGenDiagram() throws Exception { +//TODO: Test goes here... + AlarmController controller = new AlarmController(); + AlarmsHeaderService service = mock(AlarmsHeaderService.class); + controller.setAlarmsHeaderService(service); + String sourceId=""; + String startTime=""; + String endTime=""; + String showMode=""; + controller.genDiagram(sourceId,startTime,endTime,showMode); +} + + +/** +* +* Method: getTopologyData() +* +*/ + +/*@Test +public void testDateProcess() throws Exception { +//TODO: Test goes here... + +} */ + +/** +* +* Method: diagramDate(String sourceId, String startTime, String endTime, String format) +* +*/ +/*@Test +public void testDiagramDate() throws Exception { +//TODO: Test goes here... + +} */ + +} diff --git a/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java b/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java index 21b1aeb7..41640dc1 100755 --- a/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java @@ -1,4 +1,4 @@ - /* +/* * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,146 +15,146 @@ */ package org.onap.usecaseui.server.controller; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.usecaseui.server.UsecaseuiServerApplication; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.result.MockMvcResultHandlers; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = UsecaseuiServerApplication.class) -@WebAppConfiguration -public class PerformanceControllerTest { +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import org.onap.usecaseui.server.bean.PerformanceHeader; +import org.onap.usecaseui.server.bean.PerformanceInformation; +import org.onap.usecaseui.server.service.PerformanceHeaderService; +import org.onap.usecaseui.server.service.PerformanceInformationService; + +import javax.servlet.http.HttpServletResponse; - @Autowired - private WebApplicationContext context; +import static org.mockito.Mockito.*; - private MockMvc mvc; +/** +* PerformanceController Tester. +* +* @author <Authors name> +* @since <pre>���� 28, 2018</pre> +* @version 1.0 +*/ +public class PerformanceControllerTest { + PerformanceController controller = new PerformanceController(); + PerformanceHeaderService service; + PerformanceInformationService perservece; @Before - public void setup(){ - mvc = MockMvcBuilders.webAppContextSetup(context).build(); - } - - @Test - public void test1() throws Exception { - mvc.perform(MockMvcRequestBuilders.get("/performance/1/100") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - } - - @Test - public void test2() throws Exception { - mvc.perform(MockMvcRequestBuilders.get("/performance/1/100/null/null/null/null/null") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - mvc.perform(MockMvcRequestBuilders.get("/performance/1/100/1101ZTHX1MMEGJM1W1/1101ZTHX1MMEGJM1W1/Normal/null/null") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - mvc.perform(MockMvcRequestBuilders.get("/performance/1/100/1101ZTHX1MMEGJM1W1/1101ZTHX1MMEGJM1W1/Normal/123/456") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - } - - @Test - public void test3() throws Exception { - mvc.perform(MockMvcRequestBuilders.get("/performance/resourceIds") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - } - - @Test - public void test4() throws Exception { - mvc.perform(MockMvcRequestBuilders.post("/performance/names") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .param("sourceId","1101ZTHX1SCT3JNRXOOW2") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - } - - @Test - public void test5() throws Exception { - mvc.perform(MockMvcRequestBuilders.post("/performance/diagram") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .param("sourceId","1101ZTHX1SCT3JNRXOOW2") - .param("nameParent","SIG.SctpDataChunkReceived") - .param("startTime","2017-10-1 17:4") - .param("endTime","2017-12-5 17:4") - .param("format","auto") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - mvc.perform(MockMvcRequestBuilders.post("/performance/diagram") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .param("sourceId","1101ZTHX1SCT3JNRXOOW2") - .param("nameParent","SIG.SctpDataChunkReceived") - .param("startTime","2017-10-1 17:4") - .param("endTime","2017-12-5 17:4") - .param("format","year") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - mvc.perform(MockMvcRequestBuilders.post("/performance/diagram") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .param("sourceId","1101ZTHX1SCT3JNRXOOW2") - .param("nameParent","SIG.SctpDataChunkReceived") - .param("startTime","2017-10-1 17:4") - .param("endTime","2017-12-5 17:4") - .param("format","month") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - mvc.perform(MockMvcRequestBuilders.post("/performance/diagram") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .param("sourceId","1101ZTHX1SCT3JNRXOOW2") - .param("nameParent","SIG.SctpDataChunkReceived") - .param("startTime","2017-10-1 17:4") - .param("endTime","2017-12-5 17:4") - .param("format","day") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - mvc.perform(MockMvcRequestBuilders.post("/performance/diagram") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .param("sourceId","1101ZTHX1SCT3JNRXOOW2") - .param("nameParent","SIG.SctpDataChunkReceived") - .param("startTime","2017-10-1 17:4") - .param("endTime","2017-12-5 17:4") - .param("format","hour") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - mvc.perform(MockMvcRequestBuilders.post("/performance/diagram") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .param("sourceId","1101ZTHX1SCT3JNRXOOW2") - .param("nameParent","SIG.SctpDataChunkReceived") - .param("startTime","2017-10-1 17:4") - .param("endTime","2017-12-5 17:4") - .param("format","minute") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()); - } - -}
\ No newline at end of file +public void before() throws Exception { + service = mock(PerformanceHeaderService.class); + controller.setPerformanceHeaderService(service); + controller.setPerformanceInformationService(perservece); +} + +@After +public void after() throws Exception { +} + +/** +* +* Method: getPerformanceData(HttpServletResponse response, @PathVariable int currentPage, @PathVariable int pageSize, @PathVariable(required = false) String sourceId, @PathVariable(required = false) String sourceName, @PathVariable(required = false) String priority, @PathVariable(required = false) String startTime, @PathVariable(required = false) String endTime) +* +*/ +@Test +public void testGetPerformanceData() throws Exception { +//TODO: Test goes here... + HttpServletResponse response = mock(HttpServletResponse.class); + int currentPage = 1; + int pageSize=12; + String sourceId="1101ZTHX1MNE1NK7E0"; + String sourceName="1101ZTHX1MNE1NK7E0"; + String priority="Normal"; + String startTime="2017-11-15 06:30:00"; + String endTime="2017-11-15 14:45:26"; + PerformanceHeader header = new PerformanceHeader(); + + + controller.getPerformanceData(response,currentPage,pageSize,sourceId,sourceName,priority,startTime,endTime); + verify(service,times(1)).queryPerformanceHeader(header,currentPage,pageSize); + +} + +/** +* +* Method: generateDiagram(@RequestParam String sourceId, @RequestParam String startTime, @RequestParam String endTime, @RequestParam String nameParent, @RequestParam String format) +* +*/ +@Test +public void testGenerateDiagram() throws Exception { +//TODO: Test goes here... + + String sourceId=""; + String startTime=""; + String endTime=""; + String nameParent=""; + String format=""; + controller.generateDiagram(sourceId,startTime,endTime,nameParent,format); +} + +/** +* +* Method: getSourceIds() +* +*/ +@Test +public void testGetSourceIds() throws Exception { +//TODO: Test goes here... + controller.getSourceIds(); + verify(service,times(1)).queryAllSourceId(); +} + +/** +* +* Method: getNames(@RequestParam Object sourceId) +* +*/ +@Test +public void testGetNames() throws Exception { +//TODO: Test goes here... +Object sourceId="1101ZTHX1MNE1NK7E0"; + controller.getNames(sourceId); + verify(perservece,times(1)).queryDateBetween(sourceId.toString(),null,null,null); +} + + +/** +* +* Method: dateProcess(String sourceId, String name, long startTimeL, long endTimeL, long timeIteraPlusVal, long keyVal, long keyValIteraVal, String keyUnit) +* +*/ +@Test +public void testDateProcess() throws Exception { +//TODO: Test goes here... +/* +try { + Method method = PerformanceController.getClass().getMethod("dateProcess", String.class, String.class, long.class, long.class, long.class, long.class, long.class, String.class); + method.setAccessible(true); + method.invoke(<Object>, <Parameters>); +} catch(NoSuchMethodException e) { +} catch(IllegalAccessException e) { +} catch(InvocationTargetException e) { +} +*/ +} + +/** +* +* Method: diagramDate(String sourceId, String name, String startTime, String endTime, String format) +* +*/ +@Test +public void testDiagramDate() throws Exception { +//TODO: Test goes here... +/* +try { + Method method = PerformanceController.getClass().getMethod("diagramDate", String.class, String.class, String.class, String.class, String.class); + method.setAccessible(true); + method.invoke(<Object>, <Parameters>); +} catch(NoSuchMethodException e) { +} catch(IllegalAccessException e) { +} catch(InvocationTargetException e) { +} +*/ +} + +} 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 e3cf50ff..68434841 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 @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onap.usecaseui.server.service.impl; +package org.onap.usecaseui.server.service.impl; import org.junit.Test; import org.junit.Before; @@ -30,6 +30,8 @@ import org.springframework.test.context.web.WebAppConfiguration; import javax.annotation.Resource; +import static org.mockito.Mockito.*; + /** * AlarmsInformationServiceImpl Tester. * @@ -37,15 +39,15 @@ import javax.annotation.Resource; * @since <pre> 8, 2018</pre> * @version 1.0 */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = UsecaseuiServerApplication.class) -@WebAppConfiguration + public class AlarmsInformationServiceImplTest { - @Resource(name = "AlarmsInformationService") - AlarmsInformationService alarmsInformationService; + /*@Resource(name = "AlarmsInformationService") + AlarmsInformationService alarmsInformationService;*/ + AlarmsInformationServiceImpl service; @Before -public void before() throws Exception { +public void before() throws Exception { + service = mock(AlarmsInformationServiceImpl.class); } @After @@ -66,7 +68,7 @@ public void testSaveAlarmsInformation() throws Exception { a.setValue("fre"); a.setCreateTime(DateUtils.now()); a.setUpdateTime(DateUtils.now()); - System.out.println(alarmsInformationService.saveAlarmsInformation(a)); + service.saveAlarmsInformation(a); } /** @@ -83,7 +85,7 @@ public void testUpdateAlarmsInformation() throws Exception { a.setValue("fko"); a.setUpdateTime(DateUtils.now()); a.setCreateTime(DateUtils.now()); - System.out.println(alarmsInformationService.updateAlarmsInformation(a)); + service.updateAlarmsInformation(a); } /** @@ -98,7 +100,7 @@ public void testGetAllCount() throws Exception { larmsInformation.setName("vnf_a_3"); - alarmsInformationService.getAllCount(larmsInformation,0,12); + service.getAllCount(larmsInformation,0,12); } /** @@ -111,8 +113,8 @@ public void testQueryAlarmsInformation() throws Exception { //TODO: Test goes here... AlarmsInformation a = new AlarmsInformation(); a.setEventId("110"); - alarmsInformationService.queryAlarmsInformation(a,1,100) - .getList().forEach( al -> System.out.println(al.getEventId())); + service.queryAlarmsInformation(a,1,100); + // .getList().forEach( al -> System.out.println(al.getEventId())); } /** @@ -123,7 +125,8 @@ public void testQueryAlarmsInformation() throws Exception { @Test public void testQueryId() throws Exception { //TODO: Test goes here... - alarmsInformationService.queryId(new String[]{"110"}).forEach(ai -> System.out.println(ai)); + service.queryId(new String[]{"110"}); + //.forEach(ai -> System.out.println(ai)); } /** @@ -134,9 +137,10 @@ public void testQueryId() throws Exception { @Test public void testQueryDateBetween() throws Exception { //TODO: Test goes here... - alarmsInformationService.queryDateBetween("MME40","","").forEach( in -> { + service.queryDateBetween("MME40","",""); + //.forEach( in -> { // System.out.println(in); - }); + // }); } 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 f243e07a..7362ac3f 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 @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onap.usecaseui.server.service.impl; +package org.onap.usecaseui.server.service.impl; import org.junit.Test; import org.junit.Before; @@ -26,6 +26,8 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; +import static org.mockito.Mockito.mock; + /** * InitializationServiceImpl Tester. * @@ -38,8 +40,9 @@ import org.springframework.test.context.web.WebAppConfiguration; @WebAppConfiguration public class InitializationServiceImplTest { - @Autowired - private InitializationService initializationService; + /* @Autowired + private InitializationService initializationService;*/ + @Before public void before() throws Exception { } @@ -56,7 +59,8 @@ public void after() throws Exception { @Test public void testInitialize() throws Exception { //TODO: Test goes here... - initializationService.initialize(); + InitializationServiceImpl service = mock(InitializationServiceImpl.class); + service.initialize(); } diff --git a/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImplTest.java b/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImplTest.java index 68a27361..40fe33d8 100644 --- a/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImplTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImplTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onap.usecaseui.server.service.impl; +package org.onap.usecaseui.server.service.impl; import org.junit.Test; import org.junit.Before; @@ -29,6 +29,8 @@ import org.springframework.test.context.web.WebAppConfiguration; import javax.annotation.Resource; +import static org.mockito.Mockito.mock; + /** * PerformanceHeaderServiceImpl Tester. * @@ -40,10 +42,12 @@ import javax.annotation.Resource; @SpringBootTest(classes = UsecaseuiServerApplication.class) @WebAppConfiguration public class PerformanceHeaderServiceImplTest { - @Resource(name = "PerformanceHeaderService") - PerformanceHeaderService performanceHeaderService; + /* @Resource(name = "PerformanceHeaderService") + PerformanceHeaderService performanceHeaderService;*/ + PerformanceHeaderServiceImpl service; @Before -public void before() throws Exception { +public void before() throws Exception { + service = mock(PerformanceHeaderServiceImpl.class); } @After @@ -80,7 +84,7 @@ public void testSavePerformanceHeader() throws Exception { p.setMeasurementInterval("12"); p.setMeasurementsForVfScalingVersion("12"); - System.out.println(performanceHeaderService.savePerformanceHeader(p)); + service.savePerformanceHeader(p); } /** @@ -112,7 +116,7 @@ public void testUpdatePerformanceHeader() throws Exception { p.setVersion("va2"); p.setMeasurementInterval("12"); p.setMeasurementsForVfScalingVersion("12"); - System.out.println(performanceHeaderService.updatePerformanceHeader(p)); + service.updatePerformanceHeader(p); } /** @@ -128,7 +132,7 @@ public void testGetAllCount() throws Exception { performanceHeader.setSourceName("vnf_a_3"); - performanceHeaderService.getAllCount(performanceHeader,0,12); + service.getAllCount(performanceHeader,0,12); } @@ -142,8 +146,8 @@ public void testQueryPerformanceHeader() throws Exception { //TODO: Test goes here... PerformanceHeader p = new PerformanceHeader(); p.setEventId("110"); - performanceHeaderService.queryPerformanceHeader(p,1,100) - .getList().forEach(per -> System.out.println(per)); + service.queryPerformanceHeader(p,1,100); + // .getList().forEach(per -> System.out.println(per)); } /** @@ -154,8 +158,8 @@ public void testQueryPerformanceHeader() throws Exception { @Test public void testQueryId() throws Exception { //TODO: Test goes here... - performanceHeaderService.queryId(new String[]{"110"}) - .forEach(pe -> System.out.println(pe.getCreateTime())); + service.queryId(new String[]{"110"}); + // .forEach(pe -> System.out.println(pe.getCreateTime())); } /** @@ -168,8 +172,8 @@ public void testQueryAllSourceId() throws Exception { //TODO: Test goes here... PerformanceHeader p = new PerformanceHeader(); p.setSourceId("123"); - performanceHeaderService.queryPerformanceHeader(p,1,100) - .getList().forEach(per -> System.out.println(per)); + service.queryPerformanceHeader(p,1,100); + //.getList().forEach(per -> System.out.println(per)); } diff --git a/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImplTest.java b/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImplTest.java index e6540fcf..34a944ad 100644 --- a/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImplTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImplTest.java @@ -13,7 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onap.usecaseui.server.service.impl; + +package org.onap.usecaseui.server.service.impl; import org.junit.Test; import org.junit.Before; @@ -28,8 +29,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import javax.annotation.Resource; +import java.text.SimpleDateFormat; import java.util.Date; +import static org.mockito.Mockito.mock; + /** * PerformanceInformationServiceImpl Tester. * @@ -41,10 +45,12 @@ import java.util.Date; @SpringBootTest(classes = UsecaseuiServerApplication.class) @WebAppConfiguration public class PerformanceInformationServiceImplTest { - @Resource(name = "PerformanceInformationService") - PerformanceInformationService performanceInformationService; + /*@Resource(name = "PerformanceInformationService") + PerformanceInformationService performanceInformationService;*/ + PerformanceInformationServiceImpl service; @Before -public void before() throws Exception { +public void before() throws Exception { + service = mock(PerformanceInformationServiceImpl.class); } @After @@ -67,7 +73,7 @@ public void testSavePerformanceInformation() throws Exception { a.setValue("40"); a.setCreateTime(DateUtils.now()); a.setUpdateTime(DateUtils.now()); - System.out.println(performanceInformationService.savePerformanceInformation(a)); + service.savePerformanceInformation(a); } @@ -86,7 +92,7 @@ public void testUpdatePerformanceInformation() throws Exception { a.setValue("fko11"); a.setUpdateTime(DateUtils.now()); a.setCreateTime(DateUtils.now()); - System.out.println(performanceInformationService.updatePerformanceInformation(a)); + service.updatePerformanceInformation(a); } /** @@ -102,7 +108,7 @@ public void testGetAllCount() throws Exception { performanceInformation.setName("vnf_a_3"); - performanceInformationService.getAllCount(performanceInformation,0,12); + service.getAllCount(performanceInformation,0,12); } @@ -116,8 +122,8 @@ public void testQueryPerformanceInformation() throws Exception { //TODO: Test goes here... PerformanceInformation a = new PerformanceInformation(); // a.setEventId("2202"); - performanceInformationService.queryPerformanceInformation(a, 1, 100) - .getList().forEach(al -> System.out.println(al.getValue())); + service.queryPerformanceInformation(a, 1, 100); + // .getList().forEach(al -> System.out.println(al.getValue())); } /** @@ -128,8 +134,8 @@ public void testQueryPerformanceInformation() throws Exception { @Test public void testQueryId() throws Exception { //TODO: Test goes here... - performanceInformationService.queryId(new String[]{"2202"}) - .forEach(ai -> System.out.println(ai.getCreateTime())); + service.queryId(new String[]{"2202"}); + // .forEach(ai -> System.out.println(ai.getCreateTime())); } /** @@ -140,7 +146,12 @@ public void testQueryId() throws Exception { @Test public void testQueryDateBetweenForEventIdStartDateEndDate() throws Exception { //TODO: Test goes here... - performanceInformationService.queryDateBetween("1101ZTHX1MMEGJM1W1",new Date("2017-11-15 06:30:00"),new Date("2017-11-15 14:45:10")); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + String star = "2017-11-15 06:30:00"; + String end="2017-11-15 14:45:10"; + Date stard = sdf.parse(star); + Date endd = sdf.parse(end); + service.queryDateBetween("1101ZTHX1MMEGJM1W1",stard,endd); } /** @@ -151,7 +162,12 @@ public void testQueryDateBetweenForEventIdStartDateEndDate() throws Exception { @Test public void testQueryDateBetweenForResourceIdNameStartTimeEndTime() throws Exception { //TODO: Test goes here... - performanceInformationService.queryDateBetween("1101ZTHX1MMEGJM1W1",new Date("2017-11-15 06:30:00"),new Date("2017-11-15 14:45:10")); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + String star = "2017-11-15 06:30:00"; + String end="2017-11-15 14:45:10"; + Date stard = sdf.parse(star); + Date endd = sdf.parse(end); + service.queryDateBetween("1101ZTHX1MMEGJM1W1",stard,endd); } @@ -163,7 +179,7 @@ public void testQueryDateBetweenForResourceIdNameStartTimeEndTime() throws Excep @Test public void testQueryMaxValueByBetweenDate() throws Exception { //TODO: Test goes here... - performanceInformationService.queryDateBetween("2202", DateUtils.stringToDate("2017-10-15 01:00:00"), DateUtils.stringToDate("2017-10-15 02:00:00")).forEach(p -> System.out.println(p)); + service.queryDateBetween("2202", DateUtils.stringToDate("2017-10-15 01:00:00"), DateUtils.stringToDate("2017-10-15 02:00:00")).forEach(p -> System.out.println(p)); } |