diff options
22 files changed, 603 insertions, 545 deletions
diff --git a/server/pom.xml b/server/pom.xml index 121e3adb..9c68cffd 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -210,7 +210,7 @@ <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito</artifactId> - <version>1.5.4</version> + <version>1.6.5</version> </dependency> <dependency> <groupId>org.mockito</groupId> @@ -220,7 +220,7 @@ <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-module-junit4</artifactId> - <version>1.5.4</version> + <version>1.6.5</version> <type>jar</type> <scope>compile</scope> </dependency> 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 8904db55..79b8d174 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 @@ -33,11 +33,6 @@ public class AlarmBo implements Serializable { public AlarmBo() { } - public AlarmBo(AlarmsHeader alarmsHeader, List<AlarmsInformation> alarmsInformation) { - this.alarmsHeader = alarmsHeader; - this.alarmsInformation = alarmsInformation; - } - 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 b3bd5965..375c25b3 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 @@ -32,10 +32,6 @@ public class PerformanceBo implements Serializable { public PerformanceBo() { } - public PerformanceBo(PerformanceHeader performanceHeader, List<PerformanceInformation> performanceInformation) { - this.performanceHeader = performanceHeader; - this.performanceInformation = performanceInformation; - } public PerformanceHeader getPerformanceHeader() { return performanceHeader; 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 5c971037..502bd7b2 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 @@ -42,6 +42,9 @@ import java.io.InputStream; import java.io.OutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
import java.util.*;
@@ -60,17 +63,10 @@ public class AlarmController @Resource(name = "AlarmsInformationService")
private AlarmsInformationService alarmsInformationService;
- private String[] AlarmCSVHeaders = new String[]{"version",
- "eventName","domain","eventId","eventType","nfcNamingCode",
- "nfNamingCode","sourceId","sourceName","reportingEntityId",
- "reportingEntityName","priority","startEpochMicrosec","lastEpochMicroSec",
- "sequence","faultFieldsVersion","eventServrity","eventSourceType",
- "eventCategory","alarmCondition","specificProblem","vfStatus",
- "alarmInterfaceA","status",
- "createTime","updateTime","name","value"};
-
private ObjectMapper omAlarm = new ObjectMapper();
+ private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+
@RequestMapping(value = {"/alarm/{currentPage}/{pageSize}",
"/alarm/{currentPage}/{pageSize}/{sourceId}/{sourceName}/{priority}/{startTime}/{endTime}/{vfStatus}"},
method = RequestMethod.GET , produces = "application/json")
@@ -102,6 +98,7 @@ public class AlarmController alarmsHeaders = pa.getList();
if (null != alarmsHeaders && alarmsHeaders.size() > 0) {
alarmsHeaders.forEach(a ->{
+ logger.info(a.toString());
AlarmBo abo = new AlarmBo();
if (!a.getStatus().equals("3")){
abo.setAlarmsHeader(a);
@@ -140,52 +137,27 @@ public class AlarmController }
}
- @RequestMapping(value = { "/alarm/genCsv/{eventId}" } , method = RequestMethod.GET , produces = "application/json")
- public String generateCsvFile(HttpServletResponse response, @PathVariable String[] eventId) throws JsonProcessingException {
- logger.info("transfer generateCsvFile Apis, " +
- "Parameter all follows : [eventId : {}]",eventId);
- String csvFile = "csvFiles/vnf_alarm_"+new SimpleDateFormat("yy-MM-ddHH:mm:ss").format(new Date())+".csv";
- List<AlarmsHeader> alarmsHeaders = alarmsHeaderService.queryId(eventId);
- List<String[]> csvData = new ArrayList<>();
- try{
- alarmsHeaders.forEach(ala ->{
- List<AlarmsInformation> information = alarmsInformationService.queryAlarmsInformation(new AlarmsInformation(ala.getEventId()),1,100).getList();
- String names = "";
- String values = "";
- if (0 < information.size() && null != information){
- for (AlarmsInformation a : information){
- names += a.getName()+",";
- values += a.getValue()+",";
- }
- names = names.substring(0,names.lastIndexOf(','));
- values = values.substring(0,values.lastIndexOf(','));
- }
- csvData.add(new String[]{
- ala.getVersion(),ala.getEventName(),ala.getDomain(),ala.getEventId(),ala.getEventType(),
- ala.getNfcNamingCode(),ala.getNfNamingCode(),ala.getSourceId(),ala.getSourceName(),
- ala.getReportingEntityId(),ala.getReportingEntityName(),ala.getPriority(),ala.getStartEpochMicrosec(),
- ala.getLastEpochMicroSec(),ala.getSequence(),ala.getFaultFieldsVersion(),ala.getEventServrity(),
- ala.getEventSourceType(),ala.getEventCategory(),ala.getAlarmCondition(),ala.getSpecificProblem(),
- ala.getVfStatus(),ala.getAlarmInterfaceA(),ala.getStatus(),DateUtils.dateToString(ala.getCreateTime()),
- DateUtils.dateToString(ala.getUpdateTime()),names,values
- });
- });
- CSVUtils.writeCsv(AlarmCSVHeaders,csvData,csvFile);
- }catch (Exception e){
+ @RequestMapping(value = "/alarm/statusCount",method = RequestMethod.GET , produces = "application/json")
+ public String getStatusCount(){
+ List<String> statusCount = new ArrayList<>();
+ try {
+ statusCount.add(alarmsHeaderService.queryStatusCount("0"));
+ statusCount.add(alarmsHeaderService.queryStatusCount("1"));
+ statusCount.add(alarmsHeaderService.queryStatusCount("2"));
+ return omAlarm.writeValueAsString(statusCount);
+ } catch (JsonProcessingException e) {
+ e.printStackTrace();
logger.error(e.getMessage());
}
- if (ResponseUtil.responseDownload(csvFile,response)){
- return omAlarm.writeValueAsString("success");
- }else{
- return omAlarm.writeValueAsString("failed");
- }
+ return null;
}
@RequestMapping(value = {"/alarm/sourceId"},method = RequestMethod.GET)
public String getSourceId(){
List<String> sourceIds = new ArrayList<>();
alarmsHeaderService.queryAlarmsHeader(new AlarmsHeader(),1,Integer.MAX_VALUE).getList().forEach( al ->{
- if (!al.getStatus().equals("3") || !sourceIds.contains(al.getSourceId()))
+ if (!al.getStatus().equals("3") &&
+ !sourceIds.contains(al.getSourceId()))
sourceIds.add(al.getSourceId());
} );
try {
@@ -197,13 +169,85 @@ public class AlarmController }
@RequestMapping(value = {"/alarm/diagram"},method = RequestMethod.POST)
- public String genDiagram(@RequestParam String sourceId,@RequestParam String startTime,@RequestParam String endTime){
+ public String genDiagram(@RequestParam String sourceId,@RequestParam String startTime,@RequestParam String endTime,@RequestParam String showMode){
try {
- return omAlarm.writeValueAsString(alarmsInformationService.queryDateBetween(sourceId,startTime,endTime));
+ return omAlarm.writeValueAsString(diagramDate(sourceId,startTime,endTime,showMode));
} catch (JsonProcessingException e) {
e.printStackTrace();
return "";
}
}
+ private List<List<Long>> dateProcess(String sourceId,long startTimeL,long endTimeL,long timeIteraPlusVal,long keyVal,long keyValIteraVal,String keyUnit) throws ParseException {
+ List<List<Long>> dataList = new ArrayList<>();
+ long tmpEndTimeL = startTimeL + timeIteraPlusVal;
+ while (endTimeL >= tmpEndTimeL){
+ List<Map<String,String>> maps = alarmsInformationService.queryDateBetween(sourceId,sdf.format(new Date(startTimeL)),sdf.format(new Date(tmpEndTimeL)));
+ maps.forEach( map -> {
+ try {
+ List<Long> longList = new ArrayList<>();
+ if (map.get("Time") != null && !"".equals(map.get("Time")) && !"NULL".equals(map.get("Time")) ){
+ longList.add(sdf.parse(map.get("Time")).getTime());
+ if (map.get("Count") != null && !"".equals(map.get("Count")))
+ longList.add(Long.parseLong(map.get("Count")));
+ else
+ longList.add(0L);
+ }
+ if (longList.size() > 0)
+ dataList.add(longList);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+
+ } );
+ startTimeL += timeIteraPlusVal;
+ tmpEndTimeL += timeIteraPlusVal;
+ keyVal += keyValIteraVal;
+ }
+ return dataList;
+ }
+
+ private List<List<Long>> diagramDate(String sourceId,String startTime,String endTime,String format){
+ try {
+ long startTimel = sdf.parse(startTime).getTime();
+ long endTimel = sdf.parse(endTime).getTime();
+ if (format != null && !format.equals("auto")){
+ switch (format){
+ case "minute":
+ return dateProcess(sourceId,startTimel,endTimel,900000,15,15,"minute");
+ case "hour":
+ return dateProcess(sourceId,startTimel,endTimel,3600000,1,1,"hour");
+ case "day":
+ return dateProcess(sourceId,startTimel,endTimel,86400000,1,1,"day");
+ case "month":
+ return dateProcess(sourceId,startTimel,endTimel,2592000000L,1,1,"month");
+ case "year":
+ return dateProcess(sourceId,startTimel,endTimel,31536000000L,1,1,"year");
+ }
+ }else if (format != null && format.equals("auto")){
+ long minutes = (endTimel - startTimel) / (1000 * 60);
+ long hours = minutes / 60;
+ if (hours > 12){
+ long days = hours / 24;
+ if (days > 3){
+ long months = days / 31;
+ if (months > 2){
+ return dateProcess(sourceId,startTimel,endTimel,86400000,1,1,"day");
+ }else {
+ return dateProcess(sourceId,startTimel,endTimel,2592000000L,1,1,"month");
+ }
+ }else {
+ return dateProcess(sourceId,startTimel,endTimel,3600000,1,1,"hour");
+ }
+ }else {
+ return dateProcess(sourceId,startTimel,endTimel,900000,15,15,"minute");
+ }
+ }
+ } catch (ParseException e) {
+ logger.error(e.getMessage());
+ e.printStackTrace();
+ }
+ return null;
+ }
+
}
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 fe67c7a9..f534264b 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 @@ -64,6 +64,8 @@ public class PerformanceController { private ObjectMapper omPerformance = new ObjectMapper(); + private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + @RequestMapping(value = {"/performance/{currentPage}/{pageSize}", "/performance/{currentPage}/{pageSize}/{sourceId}/{sourceName}/{priority}/{startTime}/{endTime}"}, method = RequestMethod.GET, produces = "application/json") public String getPerformanceData(HttpServletResponse response, @PathVariable int currentPage, @PathVariable int pageSize, @PathVariable(required = false) String sourceId, @@ -130,7 +132,7 @@ public class PerformanceController { } } - @RequestMapping(value = {"/performance/genCsv/{eventId}"}, method = RequestMethod.GET, produces = "application/json") + /*@RequestMapping(value = {"/performance/genCsv/{eventId}"}, method = RequestMethod.GET, produces = "application/json") public String generateCsvFile(HttpServletResponse response, @PathVariable String[] eventId) throws JsonProcessingException { String csvFile = "csvFiles/vnf_performance_" + new SimpleDateFormat("yy-MM-ddHH:mm:ss").format(new Date()) + ".csv"; List<PerformanceHeader> performanceHeaders = performanceHeaderService.queryId(eventId); @@ -163,9 +165,9 @@ public class PerformanceController { } else { return omPerformance.writeValueAsString("failed"); } - } + }*/ - @RequestMapping(value = {"/performance/genDiaCsv/{dataJson}"}, method = RequestMethod.GET, produces = "application/json") + /*@RequestMapping(value = {"/performance/genDiaCsv/{dataJson}"}, method = RequestMethod.GET, produces = "application/json") public String generateDiaCsvFile(HttpServletResponse response, @PathVariable String dataJson) throws IOException { List<Map<String, Object>> dataList = omPerformance.readValue(dataJson, List.class); String csvFileName = "csvFiles/" + dataList.get(0).get("name") + "_" + new SimpleDateFormat("yy-MM-ddHH:mm:ss").format(new Date()) + ".csv"; @@ -191,100 +193,19 @@ public class PerformanceController { } else { return omPerformance.writeValueAsString("failed"); } - } - - @ResponseBody - @RequestMapping(value = {"/performance/diagram/{unit}/{eventId}"}, method = RequestMethod.GET, produces = "application/json") - public String generateDiagram(@PathVariable String unit, @PathVariable String eventId) throws ParseException, JsonProcessingException { - Map<String, List<Integer>> diagramSource = new HashMap<>(); - String[] names = {"cpu", "network", "disk", "memory"}; - switch (unit) { - case "hour": - for (int i = 0; i < 4; i++) { - Date startDateHour = DateUtils.stringToDate(DateUtils.initDate(new Date(), 1, 1, 1, -1, 0, 0)); - Date endDateHour = DateUtils.stringToDate(DateUtils.initDate(new Date(), 1, 1, 1, -1, 0, 0)); - endDateHour = DateUtils.stringToDate(DateUtils.addDate(endDateHour, "minute", 15)); - List<Integer> values = new ArrayList<>(); - for (int j = 0; j < 4; j++) { - logger.info(DateUtils.dateToString(startDateHour)); - logger.info(DateUtils.dateToString(endDateHour)); - values.add(performanceInformationService.queryDataBetweenSum(eventId, names[i], startDateHour, endDateHour)); - startDateHour = DateUtils.stringToDate(DateUtils.addDate(startDateHour, "minute", 15)); - endDateHour = DateUtils.stringToDate(DateUtils.addDate(endDateHour, "minute", 15)); - } - diagramSource.put(names[i], values); - } - break; - case "day": - for (int i = 0; i < 4; i++) { - Date startDateDay = DateUtils.stringToDate(DateUtils.initDate(new Date(), 1, 1, -1, 0, 0, 0)); - Date endDateDay = DateUtils.stringToDate(DateUtils.initDate(new Date(), 1, 1, -1, 0, 0, 0)); - endDateDay = DateUtils.stringToDate(DateUtils.addDate(endDateDay, "hour", 1)); - List<Integer> values = new ArrayList<>(); - for (int j = 0; j < 24; j++) { - values.add(performanceInformationService.queryDataBetweenSum(eventId, names[i], startDateDay, endDateDay)); - startDateDay = DateUtils.stringToDate(DateUtils.addDate(startDateDay, "hour", 1)); - endDateDay = DateUtils.stringToDate(DateUtils.addDate(endDateDay, "hour", 1)); - } - diagramSource.put(names[i], values); - } - break; - case "month": - for (int i = 0; i < 4; i++) { - Date startDateMonth = DateUtils.stringToDate(DateUtils.initDate(new Date(), 1, -1, 0, 0, 0, 0)); - Date endDateMonth = DateUtils.stringToDate(DateUtils.initDate(new Date(), 1, -1, 0, 0, 0, 0)); - endDateMonth = DateUtils.stringToDate(DateUtils.addDate(endDateMonth, "day", 1)); - List<Integer> values = new ArrayList<>(); - for (int j = 0; j < 31; j++) { - values.add(performanceInformationService.queryDataBetweenSum(eventId, names[i], startDateMonth, endDateMonth)); - startDateMonth = DateUtils.stringToDate(DateUtils.addDate(startDateMonth, "day", 1)); - endDateMonth = DateUtils.stringToDate(DateUtils.addDate(endDateMonth, "day", 1)); - } - diagramSource.put(names[i], values); - } - break; - case "year": - for (int i = 0; i < 4; i++) { - Date startDateYear = DateUtils.stringToDate(DateUtils.initDate(new Date(), -1, 0, 0, 0, 0, 0)); - Date endDateYear = DateUtils.stringToDate(DateUtils.initDate(new Date(), -1, 0, 0, 0, 0, 0)); - endDateYear = DateUtils.stringToDate(DateUtils.addDate(endDateYear, "month", 1)); - List<Integer> values = new ArrayList<>(); - for (int j = 0; j < 12; j++) { - values.add(performanceInformationService.queryDataBetweenSum(eventId, names[i], startDateYear, endDateYear)); - startDateYear = DateUtils.stringToDate(DateUtils.addDate(startDateYear, "month", 1)); - endDateYear = DateUtils.stringToDate(DateUtils.addDate(endDateYear, "month", 1)); - } - diagramSource.put(names[i], values); - } - break; - } - omPerformance.setDateFormat(new SimpleDateFormat(Constant.DATE_FORMAT)); - return omPerformance.writeValueAsString(diagramSource); - } + }*/ @RequestMapping(value = {"/performance/diagram"}, method = RequestMethod.POST, produces = "application/json") - public String generateDiagram(@RequestParam String sourceId, @RequestParam String startTime, @RequestParam String endTime, @RequestParam String nameParent, @RequestParam(required = false) String nameChild) { - List<Integer> diagramSource = new ArrayList<>(); - try { - logger.info(sourceId + ":" + startTime + ":" + endTime + ":" + nameParent + ":" + nameChild); - if (performanceHeaderService.queryPerformanceHeader(new PerformanceHeader(sourceId), 1, 10).getList() != null) { - if (nameChild != null && !"".equals(nameChild)) { - sourceId = nameParent; - nameParent = nameChild; - } - performanceInformationService.queryDateBetween(sourceId, nameParent, startTime, endTime) - .forEach(per -> { - diagramSource.add(Integer.parseInt(per.getValue())); - }); - } - } catch (Exception e) { - e.printStackTrace(); - } + public String generateDiagram(@RequestParam String sourceId, @RequestParam String startTime, @RequestParam String endTime, @RequestParam String nameParent, @RequestParam String format) { try { - return omPerformance.writeValueAsString(diagramSource); + return omPerformance.writeValueAsString(diagramDate(sourceId,nameParent,startTime,endTime,format)); } catch (JsonProcessingException e) { logger.error("JsonProcessingException:" + e.getMessage()); - return ""; + return null; + } catch (Exception e) { + logger.error(e.getMessage()); + e.printStackTrace(); + return null; } } @@ -309,7 +230,8 @@ public class PerformanceController { List<String> names = new ArrayList<>(); performanceInformationService.queryDateBetween(sourceId.toString(), null, null, null).forEach(per -> { if (!names.contains(per.getName()) && per.getValue().matches("[0-9]*")) - names.add(per.getName()); + if (Double.parseDouble(per.getValue()) > 0 && !per.getName().equals("Period")) + names.add(per.getName()); }); return omPerformance.writeValueAsString(names); @@ -319,5 +241,75 @@ public class PerformanceController { } } + private List<List<Long>> dateProcess(String sourceId,String name,long startTimeL,long endTimeL,long timeIteraPlusVal,long keyVal,long keyValIteraVal,String keyUnit) throws ParseException { + List<List<Long>> dataList = new ArrayList<>(); + long tmpEndTimeL = startTimeL + timeIteraPlusVal; + while (endTimeL >= tmpEndTimeL){ + List<Map<String,String>> maps = performanceInformationService.queryMaxValueByBetweenDate(sourceId,name,sdf.format(new Date(startTimeL)),sdf.format(new Date(tmpEndTimeL))); + maps.forEach( map -> { + try { + List<Long> longList = new ArrayList<>(); + if (map.get("Time") != null && !"".equals(map.get("Time")) && !"NULL".equals(map.get("Time")) ){ + longList.add(sdf.parse(map.get("Time")).getTime()); + if (map.get("Max") != null && !"".equals(map.get("Max"))) + longList.add(Long.parseLong(map.get("Max"))); + else + longList.add(0L); + } + if (longList.size() > 0) + dataList.add(longList); + } catch (ParseException e) { + e.printStackTrace(); + } + }); + startTimeL += timeIteraPlusVal; + tmpEndTimeL += timeIteraPlusVal; + keyVal += keyValIteraVal; + } + return dataList; + } + + private List<List<Long>> diagramDate(String sourceId,String name,String startTime,String endTime,String format){ + try { + long startTimel = sdf.parse(startTime).getTime(); + long endTimel = sdf.parse(endTime).getTime(); + if (format != null && !format.equals("auto")){ + switch (format){ + case "minute": + return dateProcess(sourceId,name,startTimel,endTimel,900000,15,15,"minute"); + case "hour": + return dateProcess(sourceId,name,startTimel,endTimel,3600000,1,1,"hour"); + case "day": + return dateProcess(sourceId,name,startTimel,endTimel,86400000,1,1,"day"); + case "month": + return dateProcess(sourceId,name,startTimel,endTimel,2592000000L,1,1,"month"); + case "year": + return dateProcess(sourceId,name,startTimel,endTimel,31536000000L,1,1,"year"); + } + }else if (format != null && format.equals("auto")){ + long minutes = (endTimel - startTimel) / (1000 * 60); + long hours = minutes / 60; + if (hours > 12){ + long days = hours / 24; + if (days > 3){ + long months = days / 31; + if (months > 2){ + return dateProcess(sourceId,name,startTimel,endTimel,86400000,1,1,"day"); + }else { + return dateProcess(sourceId,name,startTimel,endTimel,2592000000L,1,1,"month"); + } + }else { + return dateProcess(sourceId,name,startTimel,endTimel,3600000,1,1,"hour"); + } + }else { + return dateProcess(sourceId,name,startTimel,endTimel,900000,15,15,"minute"); + } + } + } catch (ParseException e) { + logger.error(e.getMessage()); + e.printStackTrace(); + } + return null; + } } diff --git a/server/src/main/java/org/onap/usecaseui/server/hibernate/HibernateConfiguration.java b/server/src/main/java/org/onap/usecaseui/server/hibernate/HibernateConfiguration.java index b47b2dfd..591f08c1 100755 --- a/server/src/main/java/org/onap/usecaseui/server/hibernate/HibernateConfiguration.java +++ b/server/src/main/java/org/onap/usecaseui/server/hibernate/HibernateConfiguration.java @@ -45,7 +45,7 @@ public class HibernateConfiguration private Properties hibernateProperties() {
Properties properties = new Properties();
properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
- properties.put("hibernate.show_sql", "true");
+ properties.put("hibernate.show_sql", "false");
return properties;
}
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 6bb8e6f7..b487f2b4 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 @@ -32,4 +32,6 @@ public interface AlarmsHeaderService { Page<AlarmsHeader> queryAlarmsHeader(AlarmsHeader alarmsHeader, int currentPage, int pageSize); List<AlarmsHeader> queryId(String[] id); + + String queryStatusCount(String status); } diff --git a/server/src/main/java/org/onap/usecaseui/server/service/PerformanceInformationService.java b/server/src/main/java/org/onap/usecaseui/server/service/PerformanceInformationService.java index 58932f15..a29ec2df 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/PerformanceInformationService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/PerformanceInformationService.java @@ -17,8 +17,8 @@ package org.onap.usecaseui.server.service; import java.util.Date; import java.util.List; +import java.util.Map; -import org.onap.usecaseui.server.bean.AlarmsInformation; import org.onap.usecaseui.server.bean.PerformanceInformation; import org.onap.usecaseui.server.util.Page; @@ -37,8 +37,7 @@ public interface PerformanceInformationService { List<PerformanceInformation> queryDateBetween(String eventId, Date startDate, Date endDate); - int queryDataBetweenSum(String eventId, String name, Date startDate, Date endDate); - List<PerformanceInformation> queryDateBetween(String resourceId, String name, String startTime, String endTime); + List<Map<String,String>> queryMaxValueByBetweenDate(String sourceId, String name, String startTime, String 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 a627f1f3..17886074 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 @@ -88,7 +88,7 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService { }
public int getAllCount(AlarmsHeader alarmsHeader,int currentPage,int pageSize) {
- try(Session session = sessionFactory.openSession();){
+ try(Session session = sessionFactory.openSession()){
StringBuffer count=new StringBuffer("select count(*) from AlarmsHeader a where 1=1");
if (null == alarmsHeader) {
//logger.error("AlarmsHeaderServiceImpl getAllCount alarmsHeader is null!");
@@ -193,11 +193,13 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService { count.append(" and a.createTime between :startTime and :endTime");
}
}
+ count.append(" and a.status != 3");
Query query = session.createQuery(count.toString());
- if(null!=alarmsHeader.getCreateTime() || alarmsHeader.getUpdateTime()!= null) {
- query.setDate("startTime",alarmsHeader.getCreateTime());
- query.setDate("endTime",alarmsHeader.getUpdateTime());
- }
+ if (null != alarmsHeader)
+ if(null!=alarmsHeader.getCreateTime() || alarmsHeader.getUpdateTime()!= null) {
+ query.setDate("startTime",alarmsHeader.getCreateTime());
+ query.setDate("endTime",alarmsHeader.getUpdateTime());
+ }
long q=(long)query.uniqueResult();
session.flush();
return (int)q;
@@ -319,12 +321,14 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService { hql.append(" and a.createTime between :startTime and :endTime");
}
}
+ hql.append(" and a.status != 3");
logger.info("AlarmsHeaderServiceImpl queryAlarmsHeader: alarmsHeader={}", alarmsHeader);
Query query = session.createQuery(hql.toString());
- if(null!=alarmsHeader.getCreateTime() || alarmsHeader.getUpdateTime()!= null) {
- query.setDate("startTime",alarmsHeader.getCreateTime());
- query.setDate("endTime",alarmsHeader.getUpdateTime());
- }
+ if (null != alarmsHeader)
+ if(null!=alarmsHeader.getCreateTime() || alarmsHeader.getUpdateTime()!= null) {
+ query.setDate("startTime",alarmsHeader.getCreateTime());
+ query.setDate("endTime",alarmsHeader.getUpdateTime());
+ }
query.setFirstResult(offset);
query.setMaxResults(pageSize);
List<AlarmsHeader> list= query.list();
@@ -344,7 +348,7 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService { @SuppressWarnings("unchecked")
@Override
public List<AlarmsHeader> queryId(String[] id) {
- try(Session session = sessionFactory.openSession();){
+ try(Session session = sessionFactory.openSession()){
if(id.length==0) {
logger.error("AlarmsHeaderServiceImpl queryId is null!");
}
@@ -358,8 +362,22 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService { }
}
-
-
-
-
+
+ @Override
+ public String queryStatusCount(String status) {
+ try(Session session = sessionFactory.openSession()){
+ String hql = "select count(status) from AlarmsHeader a";
+ if (!status.equals("0"))
+ hql+=" where a.status = :status";
+ else
+ hql+=" where a.status != 3";
+ Query query = session.createQuery(hql);
+ if (!status.equals("0"))
+ query.setString("status",status);
+ return query.uniqueResult().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 32eec76e..e06c7610 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 @@ -192,11 +192,11 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService { @Override
public List<Map<String,String>> queryDateBetween(String sourceId, String startTime, String endTime) {
- try(Session session = sessionFactory.openSession();) {
+ try(Session session = sessionFactory.openSession()) {
List<Map<String,String>> mapList = new ArrayList<>();
- String hql = "select a.createTime,count(*) from AlarmsInformation a where 1=1 ";
+ String hql = "select a.createTime,count(*) from AlarmsHeader a where 1=1 ";
if (sourceId != null && !"".equals(sourceId)){
- hql += " and a.eventId = :sourceId";
+ hql += " and a.sourceId = :sourceId";
}
if (startTime != null && !"".equals(startTime) && endTime != null && !"".equals(endTime)){
hql += " and a.createTime between :startTime and :endTime ";
@@ -224,4 +224,6 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService { 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 39828fab..996ec46b 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 @@ -166,9 +166,10 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService { }
}
Query query = session.createQuery(hql.toString());
- if(null!=performanceHeder.getCreateTime() && null!=performanceHeder.getUpdateTime()) {
- query.setDate("startTime",performanceHeder.getCreateTime()).setDate("endTime",performanceHeder.getUpdateTime());
- }
+ if (null != performanceHeder)
+ if(null!=performanceHeder.getCreateTime() && null!=performanceHeder.getUpdateTime()) {
+ query.setDate("startTime",performanceHeder.getCreateTime()).setDate("endTime",performanceHeder.getUpdateTime());
+ }
long q=(long)query.uniqueResult();
session.flush();
return (int)q;
@@ -265,9 +266,10 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService { }
logger.info("PerformanceHeaderServiceImpl queryPerformanceHeader: performanceHeder={}", performanceHeder);
Query query = session.createQuery(hql.toString());
- if(null!=performanceHeder.getCreateTime() && null!=performanceHeder.getUpdateTime()) {
- query.setDate("startTime",performanceHeder.getCreateTime()).setDate("endTime",performanceHeder.getUpdateTime());
- }
+ if (null != performanceHeder)
+ if(null!=performanceHeder.getCreateTime() && null!=performanceHeder.getUpdateTime()) {
+ query.setDate("startTime",performanceHeder.getCreateTime()).setDate("endTime",performanceHeder.getUpdateTime());
+ }
query.setFirstResult(offset);
query.setMaxResults(pageSize);
List<PerformanceHeader> list= query.list();
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java index 9ab975a6..c329f45b 100755 --- a/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java @@ -17,9 +17,7 @@ package org.onap.usecaseui.server.service.impl; import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
import javax.persistence.Id;
import javax.transaction.Transactional;
@@ -130,10 +128,10 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation int allRow =this.getAllCount(performanceInformation,currentPage,pageSize);
int offset = page.countOffset(currentPage, pageSize);
- try(Session session = sessionFactory.openSession();){
+ try(Session session = sessionFactory.openSession()){
StringBuffer hql =new StringBuffer("from PerformanceInformation a where 1=1 ");
if (null == performanceInformation) {
- //logger.error("AlarmsInformationServiceImpl queryPerformanceInformation performanceInformation is null!");
+
}else {
if(null!=performanceInformation.getName()) {
String ver=performanceInformation.getName();
@@ -179,10 +177,7 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation @Override
public List<PerformanceInformation> queryId(String[] id) {
try(Session session = sessionFactory.openSession();) {
- if(id.length==0) {
- //logger.error("PerformanceInformationServiceImpl queryId is null!");
- }
- List<PerformanceInformation> list = new ArrayList<>();
+ List<PerformanceInformation> list;
Query query = session.createQuery("from PerformanceInformation a where a.eventId IN (:alist)");
list = query.setParameterList("alist", id).list();
return list;
@@ -197,8 +192,8 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation @SuppressWarnings("unchecked")
@Override
public List<PerformanceInformation> queryDateBetween(String eventId,Date startDate, Date endDate) {
- try(Session session = sessionFactory.openSession();) {
- List<PerformanceInformation> list = new ArrayList<>();
+ try(Session session = sessionFactory.openSession()) {
+ List<PerformanceInformation> list ;
Query query = session.createQuery("from PerformanceInformation a where a.eventId = :eventId and a.createTime BETWEEN :startDate and :endDate");
list = query.setParameter("eventId",eventId).setParameter("startDate", startDate).setParameter("endDate",endDate).list();
logger.info("PerformanceInformationServiceImpl queryDateBetween: list={}", list);
@@ -210,25 +205,10 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation }
- @SuppressWarnings("unchecked")
- @Override
- public int queryDataBetweenSum(String eventId, String name, Date startDate, Date endDate){
-
- try(Session session = sessionFactory.openSession();) {
- int sum = 0;
- Query query = session.createQuery("select sum(a.value) from PerformanceInformation a where a.eventId = :eventId and a.name = :name and a.createTime BETWEEN :startDate and :endDate");
- sum = Integer.parseInt(query.setParameter("eventId",eventId).setParameter("name",name).setParameter("startDate", startDate).setParameter("endDate",endDate).uniqueResult().toString());
- logger.info("PerformanceInformationServiceImpl queryDataBetweenSum: sum={}", sum);
- return sum;
- } catch (Exception e) {
- logger.error("exception occurred while performing PerformanceInformationServiceImpl queryDataBetweenSum. Details:" + e.getMessage());
- return 0;
- }
- }
@Override
public List<PerformanceInformation> queryDateBetween(String resourceId, String name, String startTime, String endTime) {
- try(Session session = sessionFactory.openSession();) {
+ try(Session session = sessionFactory.openSession()) {
String hql = "from PerformanceInformation a where 1=1 ";
if (resourceId != null && !"".equals(resourceId)){
hql += " and a.eventId = :resourceId";
@@ -257,4 +237,45 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation }
}
+ @Override
+ public List<Map<String,String>> queryMaxValueByBetweenDate(String sourceId, String name, String startTime, String endTime) {
+ try(Session session = sessionFactory.openSession()) {
+ List<Map<String,String>> mapList = new ArrayList<>();
+ String hql = "select a.createTime,max(a.value) from PerformanceInformation a where 1=1 ";
+ if (sourceId != null && !"".equals(sourceId)){
+ hql += " and a.eventId = :resourceId";
+ }
+ if (name != null && !"".equals(name)){
+ hql += " and a.name = :name ";
+ }
+ if (startTime != null && !"".equals(startTime) && endTime != null && !"".equals(endTime)){
+ hql += " and a.createTime between :startTime and :endTime ";
+ }
+ hql += " group by a.createTime";
+ Query query = session.createQuery(hql);
+ if (sourceId != null && !"".equals(sourceId)){
+ query.setString("resourceId",sourceId);
+ }
+ if (name != null && !"".equals(name)){
+ query.setString("name",name);
+ }
+ if (startTime != null && !"".equals(startTime) && endTime != null && !"".equals(endTime)){
+ query.setString("startTime", startTime).setString("endTime", endTime);
+ }
+ Iterator it= query.list().iterator();
+ while(it.hasNext()){
+ Object[] res=(Object[]) it.next();
+ Map<String,String> map = new HashMap<>();
+ map.put("Time",res[0].toString());
+ map.put("Max",res[1].toString());
+ mapList.add(map);
+ }
+ logger.info("PerformanceInformationServiceImpl queryMaxValueByBetweenDate: maxValue={}", mapList.size());
+ return mapList;
+ } catch (Exception e) {
+ e.printStackTrace();
+ logger.error("exception occurred while performing PerformanceInformationServiceImpl queryMaxValueByBetweenDate. Details:" + e.getMessage());
+ return null;
+ }
+ }
}
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 0d294d1a..f4ac5263 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 @@ -31,95 +31,6 @@ public class DateUtils { - public static String initDate(Date d,int year,int month,int day,int hour,int minute,int second) throws ParseException { - Instant instant = d.toInstant(); - ZoneId zone = ZoneId.systemDefault(); - LocalDateTime ldt = LocalDateTime.ofInstant(instant,zone); - if(year >= 0){ - if(year == 0) - ldt = ldt.withYear(1); - } else - ldt = ldt.withYear(ldt.getYear()-1); - if(month >= 0){ - if(month == 0) - ldt = ldt.withMonth(1); - } else - ldt = ldt.withMonth(ldt.getMonthValue()-1); - if(day >= 0){ - if(day == 0) - ldt = ldt.withDayOfMonth(1); - } else - ldt = ldt.withDayOfMonth(ldt.getDayOfMonth()-1<1?ldt.getDayOfMonth():ldt.getDayOfMonth()+-1); - if(hour >= 0){ - if(hour == 0) - ldt = ldt.withHour(0); - } else - ldt = ldt.withHour(ldt.getHour()-1); - if(minute >= 0){ - if(minute == 0) - ldt = ldt.withMinute(0); - } else - ldt = ldt.withMinute(ldt.getMinute()-1); - if(second >= 0){ - if(second == 0) - ldt = ldt.withSecond(0); - } else - ldt = ldt.withMinute(ldt.getSecond()-1); - return ldt.format(DateTimeFormatter.ofPattern(Constant.DATE_FORMAT)); - } - - - - - /** - * param except data ,if int equal 0 then cleared zero, - * if equal -1 then minus 1 ,else unchanging - * @param d - * @param year - * @param month - * @param hour - * @param minute - * @param second - * @return - * @throws ParseException - */ - public static Date initProcessDate(Date d,int year,int month,int day,int hour,int minute,int second) throws ParseException { - SimpleDateFormat sdf = new SimpleDateFormat(Constant.DATE_FORMAT); - Calendar c = Calendar.getInstance(); - c.setTime(d); - if(year >= 0){ - if(year == 0) - c.set(Calendar.YEAR,0); - } else - c.set(Calendar.YEAR,c.get(Calendar.YEAR)-1); - if(month >= 0){ - if(month == 0) - c.set(Calendar.MONTH,0); - } else - c.set(Calendar.MONTH,c.get(Calendar.MONTH)-1); - if(day >= 0){ - if(day == 0) - c.set(Calendar.DAY_OF_MONTH,0); - } else - c.set(Calendar.DAY_OF_MONTH,c.get(Calendar.DAY_OF_MONTH)-1); - if(hour >= 0){ - if(hour == 0) - c.set(Calendar.HOUR_OF_DAY,0); - } else - c.set(Calendar.HOUR_OF_DAY,c.get(Calendar.HOUR_OF_DAY)-1); - if(minute >= 0){ - if(minute == 0) - c.set(Calendar.MINUTE,0); - } else - c.set(Calendar.MINUTE,c.get(Calendar.MINUTE)-1); - if(second >= 0){ - if(second == 0) - c.set(Calendar.SECOND,0); - } else - c.set(Calendar.SECOND,c.get(Calendar.SECOND)-1); - return sdf.parse(sdf.format(c.getTime())); - } - /** * * @param d 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 9a6b14fd..7ae9e414 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 @@ -26,26 +26,17 @@ 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.impl.AlarmsHeaderServiceImpl; -import org.onap.usecaseui.server.service.impl.AlarmsInformationServiceImpl; -import org.onap.usecaseui.server.service.impl.PerformanceHeaderServiceImpl; -import org.onap.usecaseui.server.service.impl.PerformanceInformationServiceImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.stereotype.Component; -import org.springframework.stereotype.Controller; -import org.springframework.stereotype.Repository; -import org.springframework.stereotype.Service; import javax.annotation.Resource; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Response; -import java.io.*; +import java.io.IOException; +import java.io.InputStream; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; @@ -228,40 +219,43 @@ public class DmaapSubscriber implements Runnable { } } }); - alarm_informations.forEach(ai -> { - ai.setCreateTime(alarm_header.getCreateTime()); - ai.setUpdateTime(new Date()); - }); - if (alarm_header.getEventName().contains("Cleared")) { - alarm_header.setStatus("3"); - logger.info("alarmCleared data header insert is starting......"); - alarmsHeaderService.saveAlarmsHeader(alarm_header); - logger.info("alarmCleared data header insert has finished."); - logger.info("alarmCleared data detail insert is starting......"); - alarm_informations.forEach(information -> - alarmsInformationService.saveAlarmsInformation(information)); - logger.info("alarmCleared data detail insert has finished. " + alarm_informations.size() + " records have been inserted."); - AlarmsHeader header1 = new AlarmsHeader(); - header1.setEventName(alarm_header.getEventName().substring(0, alarm_header.getEventName().indexOf("Cleared"))); - List<AlarmsHeader> alarmsHeaders = alarmsHeaderService.queryAlarmsHeader(header1, 1, 10).getList(); - alarmsHeaders.forEach(alarms -> { - alarms.setStatus("2"); - alarms.setUpdateTime(new Date()); - alarmsHeaderService.updateAlarmsHeader(alarms); - }); - } else { - alarm_header.setUpdateTime(new Date()); - alarm_header.setStatus("1"); - 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......"); - alarm_informations.forEach(information -> - alarmsInformationService.saveAlarmsInformation(information)); - logger.info("alarm data detail insert has finished. " + alarm_informations.size() + " records have been inserted."); - } + } }); + if (alarm_header.getEventName() != null && alarm_informations.size() > 0){ + alarm_informations.forEach(ai -> { + ai.setCreateTime(alarm_header.getCreateTime()); + ai.setUpdateTime(new Date()); + }); + if (alarm_header.getEventName().contains("Cleared")) { + alarm_header.setStatus("3"); + logger.info("alarmCleared data header insert is starting......"); + alarmsHeaderService.saveAlarmsHeader(alarm_header); + logger.info("alarmCleared data header insert has finished."); + logger.info("alarmCleared data detail insert is starting......"); + alarm_informations.forEach(information -> + alarmsInformationService.saveAlarmsInformation(information)); + logger.info("alarmCleared data detail insert has finished. " + alarm_informations.size() + " records have been inserted."); + AlarmsHeader header1 = new AlarmsHeader(); + header1.setEventName(alarm_header.getEventName().substring(0, alarm_header.getEventName().indexOf("Cleared"))); + List<AlarmsHeader> alarmsHeaders = alarmsHeaderService.queryAlarmsHeader(header1, 1, 10).getList(); + alarmsHeaders.forEach(alarms -> { + alarms.setStatus("2"); + alarms.setUpdateTime(new Date()); + alarmsHeaderService.updateAlarmsHeader(alarms); + }); + } else { + alarm_header.setUpdateTime(new Date()); + alarm_header.setStatus("1"); + 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......"); + alarm_informations.forEach(information -> + alarmsInformationService.saveAlarmsInformation(information)); + logger.info("alarm data detail insert has finished. " + alarm_informations.size() + " records have been inserted."); + } + } } private void performanceProcess(Map<String, Object> eventMap) { @@ -340,19 +334,19 @@ public class DmaapSubscriber implements Runnable { } } }); - - logger.info("performance data header insert is starting......"); - performanceHeaderService.savePerformanceHeader(performance_header); - logger.info("performance data header insert has finished."); - logger.info("performance data detail insert is starting......"); - performance_informations.forEach(ai -> { - ai.setCreateTime(performance_header.getCreateTime()); - performanceInformationService.savePerformanceInformation(ai); - }); - logger.info("performance data detail insert has finished. " + performance_informations.size() + " records have been inserted."); } }); + if (performance_header.getSourceId() !=null && performance_informations.size() > 0 ){ + logger.info("performance data header insert is starting......"); + performanceHeaderService.savePerformanceHeader(performance_header); + logger.info("performance data header insert has finished."); + logger.info("performance data detail insert is starting......"); + performance_informations.forEach(ai -> { + ai.setCreateTime(performance_header.getCreateTime()); + performanceInformationService.savePerformanceInformation(ai); + }); + logger.info("performance data detail insert has finished. " + performance_informations.size() + " records have been inserted."); - + } } }
\ No newline at end of file diff --git a/server/src/main/java/org/onap/usecaseui/server/wrapper/AlarmWrapper.java b/server/src/main/java/org/onap/usecaseui/server/wrapper/AlarmWrapper.java deleted file mode 100644 index 17997116..00000000 --- a/server/src/main/java/org/onap/usecaseui/server/wrapper/AlarmWrapper.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.usecaseui.server.wrapper; - -import org.onap.usecaseui.server.bean.AlarmsHeader; -import org.onap.usecaseui.server.bean.AlarmsInformation; - -public class AlarmWrapper { - - private AlarmsHeader alarmsHeader; - - private AlarmsInformation alarmsInformation; - - private int currentPage = 1; - - private int pageSize = 100; - - - public AlarmsHeader getAlarmsHeader() { - return alarmsHeader; - } - - public void setAlarmsHeader(AlarmsHeader alarmsHeader) { - this.alarmsHeader = alarmsHeader; - } - - public AlarmsInformation getAlarmsInformation() { - return alarmsInformation; - } - - public void setAlarmsInformation(AlarmsInformation alarmsInformation) { - this.alarmsInformation = alarmsInformation; - } - - public int getCurrentPage() { - return currentPage; - } - - public void setCurrentPage(int currentPage) { - this.currentPage = currentPage; - } - - public int getPageSize() { - return pageSize; - } - - public void setPageSize(int pageSize) { - this.pageSize = pageSize; - } -} diff --git a/server/src/test/java/org/onap/usecaseui/server/UsecaseuiServerApplicationTests.java b/server/src/test/java/org/onap/usecaseui/server/UsecaseuiServerApplicationTests.java index ae1e2990..8cc6d17f 100644 --- a/server/src/test/java/org/onap/usecaseui/server/UsecaseuiServerApplicationTests.java +++ b/server/src/test/java/org/onap/usecaseui/server/UsecaseuiServerApplicationTests.java @@ -16,12 +16,19 @@ package org.onap.usecaseui.server; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.Test; import org.junit.runner.RunWith; +import org.onap.usecaseui.server.util.DateUtils; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +import java.io.IOException; import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.Map; @RunWith(SpringRunner.class) @SpringBootTest @@ -31,7 +38,7 @@ public class UsecaseuiServerApplicationTests { @Test - public void contextLoads() throws JsonProcessingException, ParseException { + public void contextLoads() throws IOException, ParseException { /*ObjectMapper objectMapper = new ObjectMapper(); AlarmsHeader alarmsHeader = new AlarmsHeader(); alarmsHeader.setAlarmCondition("send to my phone"); @@ -48,5 +55,10 @@ public class UsecaseuiServerApplicationTests { String jsonStr = objectMapper.writeValueAsString(map); System.out.println(jsonStr);*/ //System.out.println(alarmsInformationService.saveAlarmsInformation(new AlarmsInformation("11","22","123",new Date(),new Date()))); + long interval = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse("2017-11-18 11:00").getTime() - new SimpleDateFormat("yyyy-MM-dd HH:mm").parse("2017-11-18 12:00").getTime(); + long hour = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse("2017-11-18 11:00").getTime() - (1000 * 60 * 15); + System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date(hour))); + //System.out.println(ss.replaceAll("\"\\{\"","{\"")); + } } 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 ead47ef3..5148ac43 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,46 +15,123 @@ */ package org.onap.usecaseui.server.controller; -import com.fasterxml.jackson.core.JsonProcessingException; + +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.onap.usecaseui.server.bean.AlarmsHeader; -import org.onap.usecaseui.server.bean.AlarmsInformation; -import org.onap.usecaseui.server.service.AlarmsHeaderService; -import org.onap.usecaseui.server.service.AlarmsInformationService; -import org.onap.usecaseui.server.util.CSVUtils; -import org.onap.usecaseui.server.util.DateUtils; +import org.onap.usecaseui.server.UsecaseuiServerApplication; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import javax.annotation.Resource; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +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(SpringRunner.class) -@SpringBootTest +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = UsecaseuiServerApplication.class) +@WebAppConfiguration public class AlarmControllerTest { @Autowired - AlarmController alarmController; + private WebApplicationContext context; + + private MockMvc mvc; + + @Before + public void setup(){ + mvc = MockMvcBuilders.webAppContextSetup(context).build(); + } @Test - public void getDataNotParam() throws JsonProcessingException { - System.out.println(alarmController.getAlarmData(null,null,null,null,null,null,1,100)); + 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 getDataCarryParam() throws JsonProcessingException { - System.out.println(alarmController.getAlarmData("110","a","drop","down","1506331166000","2",1,100)); + 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()); } @Test - public void csvFile() throws JsonProcessingException { - System.out.println(alarmController.generateCsvFile(null,new String[]{"110"})); + 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()); + } } 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 65ef8708..f6649327 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,78 +15,141 @@ */ package org.onap.usecaseui.server.controller; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -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 org.onap.usecaseui.server.util.CSVUtils; -import org.onap.usecaseui.server.util.DateUtils; +import org.onap.usecaseui.server.UsecaseuiServerApplication; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; +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; -import javax.annotation.Resource; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.*; - -@RunWith(SpringRunner.class) -@SpringBootTest +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = UsecaseuiServerApplication.class) +@WebAppConfiguration public class PerformanceControllerTest { @Autowired - private PerformanceController performanceController; + private WebApplicationContext context; - @Test - public void getPerformanceData() throws JsonProcessingException { - System.out.println(performanceController.getPerformanceData(null,1,100,null,null,null,null,null)); + private MockMvc mvc; + + @Before + public void setup(){ + mvc = MockMvcBuilders.webAppContextSetup(context).build(); } @Test - public void generateCsvFile() throws JsonProcessingException { - System.out.println(performanceController.getPerformanceData(null,1,100,"110","fxc","efw","fre","2017-09-28 10:00:00")); - System.out.println(performanceController.getPerformanceData(null,1,100,"110","fxc","efw","fre","null")); - System.out.println(performanceController.getPerformanceData(null,1,100,"110","fxc","efw","null","null")); - System.out.println(performanceController.getPerformanceData(null,1,100,"110","fxc","null","null","null")); - System.out.println(performanceController.getPerformanceData(null,1,100,"110","null","null","null","null")); - System.out.println(performanceController.getPerformanceData(null,1,100,"null","null","null","null","null")); - System.out.println(performanceController.getPerformanceData(null,1,100,"110","fxc","efw","null","asdasdasda")); - + 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()); } @Test - public void generateDiaCsvFile() throws JsonProcessingException { - Map<String,String> p = new HashMap<>(); - p.put("eventId","110"); - p.put("name","110"); - p.put("value","110"); - p.put("createTime","110"); - p.put("updateTime","110"); - //System.out.println(performanceController.generateDiaCsvFile(null,p)); + 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 generateDiagram(){ - try { - System.out.println(performanceController.generateDiagram("hour","110")); - System.out.println(performanceController.generateDiagram("day","110")); - System.out.println(performanceController.generateDiagram("month","110")); - System.out.println(performanceController.generateDiagram("year","110")); - } catch (ParseException e) { - e.printStackTrace(); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } + 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 diff --git a/server/src/test/java/org/onap/usecaseui/server/service/AlarmsHeaderServiceTest.java b/server/src/test/java/org/onap/usecaseui/server/service/AlarmsHeaderServiceTest.java index 5616ef23..7e080d03 100755 --- a/server/src/test/java/org/onap/usecaseui/server/service/AlarmsHeaderServiceTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/service/AlarmsHeaderServiceTest.java @@ -15,21 +15,38 @@ */ package org.onap.usecaseui.server.service; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.usecaseui.server.UsecaseuiServerApplication; import org.onap.usecaseui.server.bean.AlarmsHeader; import org.onap.usecaseui.server.util.DateUtils; +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.junit4.SpringRunner; +import org.springframework.test.context.web.WebAppConfiguration; import javax.annotation.Resource; import java.text.ParseException; -@RunWith(SpringRunner.class) -@SpringBootTest + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = UsecaseuiServerApplication.class) +@WebAppConfiguration public class AlarmsHeaderServiceTest { - @Resource(name = "AlarmsHeaderService") + @Autowired private AlarmsHeaderService alarmsHeaderService; @Test diff --git a/server/src/test/java/org/onap/usecaseui/server/service/PerformanceInformationServiceTest.java b/server/src/test/java/org/onap/usecaseui/server/service/PerformanceInformationServiceTest.java index 1a8522ad..5d8d52b4 100755 --- a/server/src/test/java/org/onap/usecaseui/server/service/PerformanceInformationServiceTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/service/PerformanceInformationServiceTest.java @@ -124,8 +124,5 @@ public class PerformanceInformationServiceTest { 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)); } - @Test - public void sum() throws ParseException { - System.out.println(performanceInformationService.queryDataBetweenSum("2202", "cpu", DateUtils.stringToDate("2017-10-18 09:00:00"), DateUtils.stringToDate("2017-10-18 10:00:00"))); - } + } diff --git a/server/src/test/java/org/onap/usecaseui/server/util/CSVUtilsTest.java b/server/src/test/java/org/onap/usecaseui/server/util/CSVUtilsTest.java index 50ee6e48..46cd1f92 100755 --- a/server/src/test/java/org/onap/usecaseui/server/util/CSVUtilsTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/util/CSVUtilsTest.java @@ -15,6 +15,7 @@ */ package org.onap.usecaseui.server.util; +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; @@ -24,8 +25,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -@RunWith(SpringRunner.class) -@SpringBootTest public class CSVUtilsTest { @Test diff --git a/server/src/test/java/org/onap/usecaseui/server/util/DateUtilsTest.java b/server/src/test/java/org/onap/usecaseui/server/util/DateUtilsTest.java index c4b363df..3c3ff813 100755 --- a/server/src/test/java/org/onap/usecaseui/server/util/DateUtilsTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/util/DateUtilsTest.java @@ -15,9 +15,18 @@ */ package org.onap.usecaseui.server.util; +import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.onap.usecaseui.server.constant.Constant; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringRunner; import java.text.ParseException; @@ -28,63 +37,34 @@ import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Date; -@RunWith(SpringRunner.class) -@SpringBootTest public class DateUtilsTest { - @Test - public void stringToDate(){ - try { - System.out.println(DateUtils.stringToDate("2017-09-28 16:00:00")); - } catch (ParseException e) { - e.printStackTrace(); - } + public void stringToDate() throws ParseException { + Date result = DateUtils.stringToDate("2017-08-12 13:12:12"); + Assert.assertEquals(result,new SimpleDateFormat(Constant.DATE_FORMAT).parse("2017-08-12 13:12:12")); } @Test public void dateToString(){ - System.out.println(DateUtils.dateToString(new Date())); - } - - @Test - public void initDate(){ - try { - System.out.println(DateUtils.initDate(new Date(),0,0,0,0,0,0)); - } catch (ParseException e) { - e.printStackTrace(); - } - } - - @Test - public void initProcessDate(){ - try { - System.out.println(DateUtils.initProcessDate(new Date(),0,0,0,0,0,0)); - } catch (ParseException e) { - e.printStackTrace(); - } - } + Assert.assertEquals(DateUtils.dateToString(new Date()),new SimpleDateFormat(Constant.DATE_FORMAT).format(new Date())); + } @Test - public void now(){ - try { - System.out.println(DateUtils.now()); - } catch (ParseException e) { - e.printStackTrace(); - } + public void now() throws ParseException { + Assert.assertNotNull(DateUtils.now()); } @Test - public void addDate(){ - try { - LocalDateTime localDateTime = LocalDateTime.now(); - System.out.println(localDateTime.withDayOfMonth(0)); - System.out.println(DateUtils.addDate(new Date(),"day",1)); - /*System.out.println(DateUtils.addDate(new Date(),"month",1)); - System.out.println(DateUtils.addDate(new Date(),"year",-1));*/ - } catch (ParseException e) { - e.printStackTrace(); - } + public void addDate() throws ParseException { + Assert.assertNotNull(DateUtils.addDate(new Date(),"year",1)); + Assert.assertNotNull(DateUtils.addDate(new Date(),"month",1)); + Assert.assertNotNull(DateUtils.addDate(new Date(),"month",13)); + Assert.assertNotNull(DateUtils.addDate(new Date(),"day",1)); + Assert.assertNotNull(DateUtils.addDate(new Date(),"day",10)); + Assert.assertNotNull(DateUtils.addDate(new Date(),"hour",1)); + Assert.assertNotNull(DateUtils.addDate(new Date(),"hour",24)); + Assert.assertNotNull(DateUtils.addDate(new Date(),"minute",1)); } |