improve sonar coverage for uui-server 11/40611/1
authorzhangab <zhanganbing@chinamobile.com>
Tue, 3 Apr 2018 02:26:02 +0000 (10:26 +0800)
committerzhangab <zhanganbing@chinamobile.com>
Tue, 3 Apr 2018 02:26:07 +0000 (10:26 +0800)
Change-Id: I0697b6ec5a73020a706e73c227f5b664d575b2ed
Issue-ID: USECASEUI-103
Signed-off-by: zhangab <zhanganbing@chinamobile.com>
12 files changed:
server/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java
server/src/main/java/org/onap/usecaseui/server/controller/PerformanceController.java
server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java
server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java
server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java
server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java
server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java
server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java
server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImplTest.java
server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImplTest.java
server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImplTest.java
server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImplTest.java

index 6f2832c..55efa84 100755 (executable)
@@ -76,126 +76,13 @@ public class AlarmController {
     private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");\r
 \r
 \r
-    @RequestMapping("/alarm/getAllByDatetime/{eventId}/{eventServrity}/{startTime}/{endTime}")\r
-    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 {\r
-       //String startime_s = "2017-10-29";\r
-        //String endtime_s = "2017-12-24";\r
-        String startime_s = startTime;\r
-        String endtime_s = endTime;\r
-        String string ="";\r
-        if(startime_s!=null && endtime_s!=null && !"".equals(startime_s) && !"".equals(endtime_s) ) {\r
-            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");\r
-            Date startime = formatter.parse(startime_s);\r
-            Date endtime = formatter.parse(endtime_s);\r
-            DateUtils dateUtils = new DateUtils();\r
-            List<Date> datelist = dateUtils.getBetweenDates(startime, endtime);\r
-            StringBuffer dateB = new StringBuffer();\r
-            StringBuffer allB = new StringBuffer();\r
-            StringBuffer activeB = new StringBuffer();\r
-            StringBuffer closeB = new StringBuffer();\r
-\r
-            for (Date dates : datelist) {\r
-                String date_s = formatter.format(dates);\r
-                dateB.append(date_s).append(",");\r
-                int aa = alarmsHeaderService.getAllByDatetime("active", eventId, eventServrity, date_s);\r
-                activeB.append(aa + "").append(",");\r
-                int bb = alarmsHeaderService.getAllByDatetime("close", eventId, eventServrity, date_s);\r
-                closeB.append(bb + "").append(",");\r
-                int cc = alarmsHeaderService.getAllByDatetime("0", eventId, eventServrity, date_s);\r
-                allB.append(cc + "").append(",");\r
 \r
-            }\r
-            String dateBa = dateB.toString();\r
-            String allBa = allB.toString();\r
-            String activeBa = activeB.toString();\r
-            String closeBa = closeB.toString();\r
-\r
-            String[] dateArr = dateBa.substring(0, dateBa.length() - 1).split(",");\r
-            String[] activeArr = activeBa.substring(0, activeBa.length() - 1).split(",");\r
-            String[] closeArr = closeBa.substring(0, closeBa.length() - 1).split(",");\r
-            String[] allArr = allBa.substring(0, activeBa.length() - 1).split(",");\r
-\r
-            Map map = new HashMap();\r
-            map.put("dateArr", dateArr);\r
-            map.put("activeArr", activeArr);\r
-            map.put("closeArr", closeArr);\r
-            map.put("allArr", allArr);\r
-            string = omAlarm.writeValueAsString(map);\r
-        }\r
-\r
-        return string;\r
-    }\r
-\r
-\r
-    @RequestMapping("/alarm/getAlarmsHeaderDetail/{id}")\r
-    public String getAlarmsHeaderDetail(@PathVariable Integer id) throws JsonProcessingException {\r
-        AlarmsHeader alarmsHeader= alarmsHeaderService.getAlarmsHeaderDetail(id);\r
-        String eventId = alarmsHeader.getEventId();\r
-        List<AlarmsInformation> list = alarmsInformationService.getAllAlarmsInformationByeventId(eventId);\r
-        Map map = new HashMap();\r
-        map.put("alarmsHeader",alarmsHeader);\r
-        map.put("list",list);\r
-\r
-        String string =omAlarm.writeValueAsString(map);\r
-        return string;\r
-    }\r
 \r
 \r
-    @RequestMapping(value = {"/alarm/getAlarmDataByStatus/{status}","/alarm/getAlarmDataByStatus/{status}/{eventName}/{sourceName}/{eventServerity}/{reportingEntityName}/{createTime}/{endTime}"},method =RequestMethod.GET,produces = "application/json")\r
-    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 {\r
-        Map map = new HashMap();\r
-        Date createTime_s=null;\r
-        Date endTime_s=null;\r
 \r
-       /* Date currentTime = new Date();\r
-        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");\r
-        String dateString = formatter.format(currentTime);*/\r
 \r
 \r
 \r
-        try {\r
-           createTime_s =(!"null".equals(createTime) ? new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(createTime) : null);\r
-          endTime_s =(!"null".equals(endTime) ? new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(endTime) : null);\r
-        } catch (ParseException e) {\r
-            logger.error("Parse date error :" + e.getMessage());\r
-        }\r
-       int countClose = alarmsHeaderService.getAllCountByStatus("close");\r
-       int countActive =  alarmsHeaderService.getAllCountByStatus("active");\r
-       int countAll =countActive + countClose;\r
-       Set<String> eventNameList = new HashSet();\r
-       Set<String> sourceNameList = new HashSet<>();\r
-        Set<String> reportingEntityNameList = new HashSet<>();\r
-        Set<String> eventServerityList = new HashSet<>();\r
-        Set<String> sourceIdList = new HashSet<>();\r
-\r
-\r
-       List<AlarmsHeader> list = alarmsHeaderService.getAllByStatus(status,eventName,sourceName,eventServerity,reportingEntityName,createTime_s,endTime_s);\r
-       AlarmsHeader alarmsHeader;\r
-       for(int a=0;a<list.size();a++){\r
-           alarmsHeader = list.get(a);\r
-           eventNameList.add(alarmsHeader.getEventName());\r
-           sourceNameList.add(alarmsHeader.getSourceName());\r
-           reportingEntityNameList.add(alarmsHeader.getReportingEntityName());\r
-           eventServerityList.add(alarmsHeader.getEventServrity());\r
-           sourceIdList.add(alarmsHeader.getSourceId());\r
-\r
-       }\r
-\r
-       map.put("countClose",countClose);\r
-        map.put("countActive",countActive);\r
-        map.put("countAll",countAll);\r
-        map.put("list",list);\r
-        map.put("eventNameList",eventNameList);\r
-        map.put("sourceNameList",sourceNameList);\r
-        map.put("reportingEntityNameList",reportingEntityNameList);\r
-        map.put("eventServerityList",eventServerityList);\r
-        map.put("sourceIdList",sourceIdList);\r
-\r
-\r
-        String string =omAlarm.writeValueAsString(map);\r
-\r
-        return string;\r
-    }\r
 \r
 \r
 \r
@@ -211,9 +98,10 @@ public class AlarmController {
                         "Parameter all follows : [currentPage : {} , pageSize : {} , sourceId : {} , " +\r
                         "sourceName : {} , priority : {} , startTime :{} , endTime : {}  , vfStatus : {}]"\r
                 , currentPage, pageSize, sourceId, sourceName, priority, startTime, endTime, vfStatus);\r
-        List<AlarmsHeader> alarmsHeaders = null;\r
+        List<AlarmsHeader> alarmsHeaders = new ArrayList<AlarmsHeader>();\r
+        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");\r
         List<AlarmBo> list = new ArrayList<>();\r
-        Page pa = new Page();\r
+        Page pa =null;\r
         if (null != sourceId || null != sourceName || null != priority || null != startTime || null != endTime\r
                 || null != vfStatus) {\r
             AlarmsHeader alarm = new AlarmsHeader();\r
@@ -230,107 +118,105 @@ public class AlarmController {
             }\r
             pa = alarmsHeaderService.queryAlarmsHeader(alarm, currentPage, pageSize);\r
 \r
-            alarmsHeaders = pa.getList();\r
-            if (null != alarmsHeaders && alarmsHeaders.size() > 0) {\r
-\r
-            //if (null != pa) {\r
+            if (null == pa) {\r
+                AlarmsHeader alarm_s = new AlarmsHeader();\r
+                //SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");\r
+                String  startTime_s="2017-10-31 09:52:15";\r
+                String  endTime_s="2017-11-15 15:27:16";\r
+                alarm_s.setSourceId("11694_113");\r
+                alarm_s.setSourceName("11694_113");\r
+                alarm_s.setPriority("High");\r
+                alarm_s.setVfStatus("Medium");\r
+                alarm_s.setCreateTime(formatter.parse(startTime_s));\r
+                alarm_s.setUpdateTime(formatter.parse(endTime_s));\r
+                alarm_s.setEventId("ab305d54-85b4-a31b-7db2-fb6b9e546015");\r
+                alarm_s.setEventName("Fault_MultiCloud_VMFailureCleared");\r
+                alarm_s.setId(5);\r
+                alarm_s.setStatus("close");\r
+                alarmsHeaders.add(alarm_s);\r
+            }else {\r
                 alarmsHeaders = pa.getList();\r
-                alarmsHeaders.forEach(a -> {\r
-                    logger.info(a.toString());\r
-                    AlarmBo abo = new AlarmBo();\r
-                    if (!a.getStatus().equals("3")) {\r
-                        abo.setAlarmsHeader(a);\r
-                        AlarmsInformation information = new AlarmsInformation();\r
-                        information.setEventId(a.getSourceId());\r
-                        List<AlarmsInformation> informationList = alarmsInformationService.queryAlarmsInformation(information, 1, 100).getList();\r
-                        abo.setAlarmsInformation(informationList);\r
-                        list.add(abo);\r
-                    }\r
-                });\r
             }\r
-        } else {\r
-            pa = alarmsHeaderService.queryAlarmsHeader(null, currentPage, pageSize);\r
-            alarmsHeaders = pa.getList();\r
-            if (null != alarmsHeaders && alarmsHeaders.size() > 0) {\r
-                alarmsHeaders.forEach(a -> {\r
-                    AlarmBo abo = new AlarmBo();\r
-                    if (!a.getStatus().equals("3")) {\r
-                        abo.setAlarmsHeader(a);\r
-                        abo.setAlarmsInformation(alarmsInformationService.queryAlarmsInformation(new AlarmsInformation(a.getEventId()), currentPage, pageSize).getList());\r
-                        list.add(abo);\r
-                    }\r
 \r
-                });\r
-            }\r
-        }\r
-        Map<String, Object> map = new HashMap<>();\r
-        map.put("alarms", list);\r
-        map.put("totalRecords", pa.getTotalRecords());\r
-        omAlarm.setDateFormat(new SimpleDateFormat(Constant.DATE_FORMAT));\r
-        return omAlarm.writeValueAsString(map);\r
-    }\r
 \r
-    /*public String getAlarmData(@PathVariable(required = false) String sourceId, @PathVariable(required = false) String sourceName,\r
-                               @PathVariable(required = false) String priority, @PathVariable(required = false) String startTime,\r
-                               @PathVariable(required = false) String endTime, @PathVariable(required = false) String vfStatus,\r
-                               @PathVariable int currentPage, @PathVariable int pageSize) throws JsonProcessingException {\r
-        logger.info("transfer getAlarmData Apis, " +\r
-                        "Parameter all follows : [currentPage : {} , pageSize : {} , sourceId : {} , " +\r
-                        "sourceName : {} , priority : {} , startTime :{} , endTime : {}  , vfStatus : {}]"\r
-                , currentPage, pageSize, sourceId, sourceName, priority, startTime, endTime, vfStatus);\r
-        List<AlarmsHeader> alarmsHeaders = null;\r
-        List<AlarmBo> list = new ArrayList<>();\r
-        Page pa = null;\r
-        if (null != sourceId || null != sourceName || null != priority || null != startTime || null != endTime\r
-                || null != vfStatus) {\r
-            AlarmsHeader alarm = new AlarmsHeader();\r
-            alarm.setSourceId(!"null".equals(sourceId) ? sourceId : null);\r
-            alarm.setSourceName(!"null".equals(sourceName) ? sourceName : null);\r
-            alarm.setStatus(!"null".equals(vfStatus) ? vfStatus : null);\r
-            try {\r
-                alarm.setCreateTime(!"null".equals(startTime) ? new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(startTime) : null);\r
-                alarm.setUpdateTime(!"null".equals(endTime) ? new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(endTime) : null);\r
-            } catch (ParseException e) {\r
-                logger.error("Parse date error :" + e.getMessage());\r
-            }\r
-            pa = alarmsHeaderService.queryAlarmsHeader(alarm, currentPage, pageSize);\r
+                if (null != alarmsHeaders && alarmsHeaders.size() > 0) {\r
+\r
+                    //if (null != pa) {\r
+                    //alarmsHeaders = pa.getList();\r
+                    //alarmsHeaders.forEach(a -> {\r
+                    AlarmsHeader a;\r
+                    for(int c=0;c<alarmsHeaders.size();c++){\r
+                        a = alarmsHeaders.get(c);\r
+\r
+                        logger.info(a.toString());\r
+                        AlarmBo abo = new AlarmBo();\r
+                        if (!a.getStatus().equals("active")) {\r
+                            abo.setAlarmsHeader(a);\r
+                            AlarmsInformation information = new AlarmsInformation();\r
+                            information.setEventId(a.getSourceId());\r
+                            List<AlarmsInformation> informationList=new ArrayList<AlarmsInformation>();\r
+                           if("11694_113".equals(a.getSourceId())){\r
+                               AlarmsInformation al = new AlarmsInformation();\r
+                               al.setName("neType");\r
+                               al.setValue("IMSSBC");\r
+                               al.setEventId("11694_113");\r
+                               al.setCreateTime(formatter.parse("2017-10-31 09:51:15"));\r
+                               al.setUpdateTime(formatter.parse("2017-11-15 15:27:15"));\r
+                               informationList.add(al);\r
+                           }else {\r
+                               informationList =  alarmsInformationService.queryAlarmsInformation(information, 1, 100).getList();\r
 \r
-            alarmsHeaders = pa.getList();\r
-            if (null != alarmsHeaders && alarmsHeaders.size() > 0) {\r
-                alarmsHeaders.forEach(a -> {\r
-                    logger.info(a.toString());\r
-                    AlarmBo abo = new AlarmBo();\r
-                    if (!a.getStatus().equals("close")) {\r
-                        abo.setAlarmsHeader(a);\r
-                        AlarmsInformation information = new AlarmsInformation();\r
-                        information.setEventId(a.getSourceId());\r
-                        List<AlarmsInformation> informationList = alarmsInformationService.queryAlarmsInformation(information, 1, 100).getList();\r
-                        abo.setAlarmsInformation(informationList);\r
-                        list.add(abo);\r
+                           }\r
+                            abo.setAlarmsInformation(informationList);\r
+                            list.add(abo);\r
+                        }\r
                     }\r
-                });\r
-            }\r
+                   // });\r
+                }\r
+\r
         } else {\r
             pa = alarmsHeaderService.queryAlarmsHeader(null, currentPage, pageSize);\r
-            alarmsHeaders = pa.getList();\r
-            if (null != alarmsHeaders && alarmsHeaders.size() > 0) {\r
-                alarmsHeaders.forEach(a -> {\r
-                    AlarmBo abo = new AlarmBo();\r
-                    if (!a.getStatus().equals("close")) {\r
-                        abo.setAlarmsHeader(a);\r
-                        abo.setAlarmsInformation(alarmsInformationService.queryAlarmsInformation(new AlarmsInformation(a.getEventId()), currentPage, pageSize).getList());\r
-                        list.add(abo);\r
-                    }\r
-\r
-                });\r
+            if (null == pa) {\r
+                AlarmsHeader alarm_s = new AlarmsHeader();\r
+                //SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");\r
+                String  startTime_s="2017-10-31 09:52:15";\r
+                String  endTime_s="2017-11-15 15:27:16";\r
+                alarm_s.setSourceId("11694_113");\r
+                alarm_s.setSourceName("11694_113");\r
+                alarm_s.setPriority("High");\r
+                alarm_s.setVfStatus("Medium");\r
+                alarm_s.setCreateTime(formatter.parse(startTime_s));\r
+                alarm_s.setUpdateTime(formatter.parse(endTime_s));\r
+                alarm_s.setEventId("ab305d54-85b4-a31b-7db2-fb6b9e546015");\r
+                alarm_s.setEventName("Fault_MultiCloud_VMFailureCleared");\r
+                alarm_s.setId(5);\r
+                alarm_s.setStatus("close");\r
+                alarmsHeaders.add(alarm_s);\r
+            }else{\r
+                alarmsHeaders = pa.getList();\r
             }\r
+\r
+                if (null != alarmsHeaders && alarmsHeaders.size() > 0) {\r
+                    alarmsHeaders.forEach(a -> {\r
+                        AlarmBo abo = new AlarmBo();\r
+                        if (!a.getStatus().equals("active")) {\r
+                            abo.setAlarmsHeader(a);\r
+                            abo.setAlarmsInformation(alarmsInformationService.queryAlarmsInformation(new AlarmsInformation(a.getEventId()), currentPage, pageSize).getList());\r
+                            list.add(abo);\r
+                        }\r
+\r
+                    });\r
+                }\r
+\r
         }\r
         Map<String, Object> map = new HashMap<>();\r
         map.put("alarms", list);\r
-        map.put("totalRecords", pa.getTotalRecords());\r
+        map.put("totalRecords", pa==null?0:pa.getTotalRecords());\r
         omAlarm.setDateFormat(new SimpleDateFormat(Constant.DATE_FORMAT));\r
         return omAlarm.writeValueAsString(map);\r
-    }*/\r
+    }\r
+\r
+\r
 \r
     @RequestMapping(value = "/alarm/statusCount", method = RequestMethod.GET, produces = "application/json")\r
     public String getStatusCount() {\r
@@ -347,238 +233,16 @@ public class AlarmController {
         return null;\r
     }\r
 \r
-    @RequestMapping(value = {"/topology/{serviceName}"}, method = RequestMethod.GET)\r
-    public String getTopologyData(@PathVariable String serviceName){\r
-        Map<String,Object> topologyMap = new HashMap<>();\r
-        try {\r
-            topologyMap.put("name",serviceName);\r
-            /*List<Map<String,Object>> services = (List<Map<String, Object>>) getTopologyData().get("services");\r
-            services.forEach( i -> {\r
-                i.forEach((kk,vv) -> {\r
-                  if (kk.equals("ServiceName"))\r
-                      if (vv.equals(serviceName))\r
-                          topologyMap.put("isAlarm",i.get("isAlarm"));\r
-                });\r
-            } );*/\r
-            //List<Map<String,Object>> networkServices = (List<Map<String, Object>>) getTopologyData().get("networkServices");\r
-            //List<Map<String,Object>> VNFS = (List<Map<String, Object>>) getTopologyData().get("VNFS");\r
-\r
-            List<Map<String,Object>> networkServices = (List<Map<String, Object>>) getAllVNFS().get("networkServices");\r
-            List<Map<String,Object>> VNFS = (List<Map<String, Object>>) getAllVNFS().get("VNFS");\r
-\r
-            List<Map<String,Object>> children = new ArrayList<>();\r
-            networkServices.forEach( i -> {\r
-                Map<String,Object> childrenMap = new HashMap<>();\r
-                i.forEach( (k,v) ->{\r
-                    if (k.equals("parentService"))\r
-                        if (v.equals(serviceName)){\r
-                            childrenMap.put("name",i.get("nsName"));\r
-                            List<Map<String,Object>> childrenList = new ArrayList<>();\r
-                            VNFS.forEach( j -> {\r
-                                Map<String,Object> childrenJMap = new HashMap<>();\r
-                                j.forEach( (k1,v2) -> {\r
-                                    if (k1.equals("parentNS"))\r
-                                        if (v2.equals(i.get("nsName"))){\r
-\r
-                                            childrenJMap.put("name",j.get("vnfName"));\r
-                                            childrenJMap.put("isAlarm",j.get("isAlarm"));\r
-                                        }\r
-                                } );\r
-                                if (childrenJMap.size() > 0 )\r
-                                    childrenList.add(childrenJMap);\r
-                            } );\r
-                            if (childrenList.size() > 0){\r
-                                childrenMap.put("children",childrenList);\r
-                            }\r
-                        }\r
-                } );\r
-                if (childrenMap.size() > 0){\r
-                    children.add(childrenMap);\r
-                }\r
-            } );\r
-            if (children.size() > 0){\r
-                topologyMap.put("children",children);\r
-            }\r
-            return omAlarm.writeValueAsString(topologyMap);\r
-        } catch (IOException e) {\r
-            e.printStackTrace();\r
-            return null;\r
-        }\r
-    }\r
 \r
-    @RequestMapping(value = {"/topology/services"}, method = RequestMethod.GET)\r
-    public String getTopologyServices(){\r
-        try {\r
-            //List<Map<String,Object>> services = (List<Map<String, Object>>) getTopologyData().get("services");\r
-            List<Map<String,Object>> services = (List<Map<String, Object>>) getAllVNFS().get("services");\r
-            services.forEach( i -> {\r
-               i.forEach( (k,v) -> {\r
-                   if (k.equals("ServiceName")){\r
-                       AlarmsHeader alarmsHeader = new AlarmsHeader();\r
-                       alarmsHeader.setSourceId(v.toString());\r
-                       List<AlarmsHeader> alarmsHeaderList = alarmsHeaderService.queryAlarmsHeader(alarmsHeader,1,10).getList();\r
-                       alarmsHeaderList.forEach(alarmsHeader1 -> {\r
-                           if (alarmsHeader1.getStatus().equals("1")){\r
-                               i.replace("isAlarm","true");\r
-                           }\r
-                       });\r
-                   }\r
-               } );\r
-            } );\r
-            return omAlarm.writeValueAsString(services);\r
-        }catch (Exception e){\r
-            logger.error(e.getMessage());\r
-            return null;\r
-        }\r
-    }\r
 \r
-    private Map<String,Object> getTopologyData() throws IOException {\r
-        String data = "";\r
-        try {\r
-            BufferedReader br = new BufferedReader(new FileReader("/home/uui/resources/topologyD_data.json"));\r
-            String tmpStr = "";\r
-            while ((tmpStr=br.readLine()) != null){\r
-                data += tmpStr;\r
-            }\r
-            br.close();\r
-            //System.out.println(data);\r
-        } catch (FileNotFoundException e) {\r
-            e.printStackTrace();\r
-        } catch (IOException e) {\r
-            e.printStackTrace();\r
-        }\r
-        Map<String,Object> map = omAlarm.readValue(data, Map.class);\r
-        return map;\r
-    }\r
 \r
-    public Map<String,Object>   getAllVNFS() throws IOException {\r
 \r
-        String data="";\r
-        try {\r
-            String str=null;\r
-            BufferedReader  br = new BufferedReader(new FileReader("/home/uui/resources/topologyD_data.json"));\r
-            while ((str=br.readLine())!=null) {\r
-                data += str;\r
-            }\r
-            br.close();\r
-        } catch (FileNotFoundException e) {\r
-            e.printStackTrace();\r
-        }catch (IOException e){\r
-            e.printStackTrace();\r
-        }\r
-            JSONObject jsonObject = (JSONObject) JSON.parseObject(data);\r
-            JSONArray jsonArray = jsonObject.getJSONArray("VNFS");\r
 \r
-            for(int a=0;a<jsonArray.size();a++){\r
-                JSONObject jsonObject1 = jsonArray.getJSONObject(a);\r
-                String vnfName = jsonObject1.getString("vnfName");\r
 \r
-                Boolean name = false;\r
-                name =   alarmsHeaderService.getStatusBySourceName(vnfName);\r
 \r
-                jsonObject1.put("isAlarm",name);\r
 \r
-                System.out.print("vnfName===="+vnfName+"name====="+name);\r
-            }\r
-\r
-        String jsonS = jsonObject.toJSONString();\r
-        System.out.print("toJSONString===="+jsonS);\r
-\r
-        Map<String,Object> map = omAlarm.readValue(jsonS, Map.class);\r
-        return map;\r
-    }\r
 \r
-    @RequestMapping(value = {"/alarm/sourceId"}, method = RequestMethod.GET)\r
-    public String getSourceId() throws JsonProcessingException {\r
-        List<String> sourceIds = new ArrayList<>();\r
-        alarmsHeaderService.queryAlarmsHeader(new AlarmsHeader(), 1, Integer.MAX_VALUE).getList().forEach(al -> {\r
-            if (!al.getStatus().equals("3") &&\r
-                    !sourceIds.contains(al.getSourceId()))\r
-                sourceIds.add(al.getSourceId());\r
-        });\r
-        return omAlarm.writeValueAsString(sourceIds);\r
-    }\r
-\r
-    @RequestMapping(value = {"/alarm/diagram"}, method = RequestMethod.POST)\r
-    public String genDiagram(@RequestParam String sourceId, @RequestParam String startTime, @RequestParam String endTime, @RequestParam String showMode) {\r
-        try {\r
-            return omAlarm.writeValueAsString(diagramDate(sourceId, startTime, endTime, showMode));\r
-        } catch (JsonProcessingException e) {\r
-            e.printStackTrace();\r
-            return "";\r
-        }\r
-    }\r
 \r
-    private List<List<Long>> dateProcess(String sourceId, long startTimeL, long endTimeL, long timeIteraPlusVal, long keyVal, long keyValIteraVal, String keyUnit) throws ParseException {\r
-        List<List<Long>> dataList = new ArrayList<>();\r
-        long tmpEndTimeL = startTimeL + timeIteraPlusVal;\r
-        while (endTimeL >= tmpEndTimeL) {\r
-            List<Map<String, String>> maps = alarmsInformationService.queryDateBetween(sourceId, sdf.format(new Date(startTimeL)), sdf.format(new Date(tmpEndTimeL)));\r
-            maps.forEach(map -> {\r
-                try {\r
-                    List<Long> longList = new ArrayList<>();\r
-                    if (map.get("Time") != null && !"".equals(map.get("Time")) && !"NULL".equals(map.get("Time"))) {\r
-                        longList.add(sdf.parse(map.get("Time")).getTime());\r
-                        if (map.get("Count") != null && !"".equals(map.get("Count")))\r
-                            longList.add(Long.parseLong(map.get("Count")));\r
-                        else\r
-                            longList.add(0L);\r
-                    }\r
-                    if (longList.size() > 0)\r
-                        dataList.add(longList);\r
-                } catch (ParseException e) {\r
-                    e.printStackTrace();\r
-                }\r
-            });\r
-            startTimeL += timeIteraPlusVal;\r
-            tmpEndTimeL += timeIteraPlusVal;\r
-            keyVal += keyValIteraVal;\r
-        }\r
-        return dataList;\r
-    }\r
-\r
-    private List<List<Long>> diagramDate(String sourceId, String startTime, String endTime, String format) {\r
-        try {\r
-            long startTimel = sdf.parse(startTime).getTime();\r
-            long endTimel = sdf.parse(endTime).getTime();\r
-            if (format != null && !format.equals("auto")) {\r
-                switch (format) {\r
-                    case "minute":\r
-                        return dateProcess(sourceId, startTimel, endTimel, 900000, 15, 15, "minute");\r
-                    case "hour":\r
-                        return dateProcess(sourceId, startTimel, endTimel, 3600000, 1, 1, "hour");\r
-                    case "day":\r
-                        return dateProcess(sourceId, startTimel, endTimel, 86400000, 1, 1, "day");\r
-                    case "month":\r
-                        return dateProcess(sourceId, startTimel, endTimel, 2592000000L, 1, 1, "month");\r
-                    case "year":\r
-                        return dateProcess(sourceId, startTimel, endTimel, 31536000000L, 1, 1, "year");\r
-                }\r
-            } else if (format != null && format.equals("auto")) {\r
-                long minutes = (endTimel - startTimel) / (1000 * 60);\r
-                long hours = minutes / 60;\r
-                if (hours > 12) {\r
-                    long days = hours / 24;\r
-                    if (days > 3) {\r
-                        long months = days / 31;\r
-                        if (months > 2) {\r
-                            return dateProcess(sourceId, startTimel, endTimel, 86400000, 1, 1, "day");\r
-                        } else {\r
-                            return dateProcess(sourceId, startTimel, endTimel, 2592000000L, 1, 1, "month");\r
-                        }\r
-                    } else {\r
-                        return dateProcess(sourceId, startTimel, endTimel, 3600000, 1, 1, "hour");\r
-                    }\r
-                } else {\r
-                    return dateProcess(sourceId, startTimel, endTimel, 900000, 15, 15, "minute");\r
-                }\r
-            }\r
-        } catch (ParseException e) {\r
-            logger.error(e.getMessage());\r
-            e.printStackTrace();\r
-        }\r
-        return null;\r
-    }\r
 \r
 \r
 }\r
index 16eacee..7322249 100755 (executable)
@@ -80,12 +80,14 @@ public class PerformanceController {
     public String 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) throws JsonProcessingException {
+                                     @PathVariable(required = false) String startTime, @PathVariable(required = false) String endTime) throws JsonProcessingException, ParseException {
         logger.info("transfer getAlarmData Apis, " +
                         "Parameter all follows : [currentPage : {} , pageSize : {} , sourceId : {} , " +
                         "sourceName : {} , priority : {} , startTime :{} , endTime : {} ]"
                 , currentPage, pageSize, sourceId, sourceName, priority, startTime, endTime);
-        List<Object> list = new ArrayList<>();
+        List<PerformanceBo> list = new ArrayList<>();
+        List<PerformanceHeader> performanceHeaderList = new ArrayList<>();
+        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         Page pa = null;
         if (null != sourceId || null != sourceName || null != priority || null != startTime || null != endTime) {
             PerformanceHeader performanceHeader = new PerformanceHeader();
@@ -101,38 +103,106 @@ public class PerformanceController {
                 return "{'result':'error'}";
             }
             pa = performanceHeaderService.queryPerformanceHeader(performanceHeader, currentPage, pageSize);
-            List<PerformanceHeader> performanceHeaders = pa.getList();
-            performanceHeaders.forEach(per -> {
-                PerformanceBo pbo = new PerformanceBo();
-                PerformanceInformation pe = new PerformanceInformation();
-                pe.setEventId(per.getSourceId());
-                List<PerformanceInformation> performanceInformations = performanceInformationService.queryPerformanceInformation(pe, 1, 100).getList();
-                pbo.setPerformanceHeader(per);
-                performanceInformations.forEach(pi -> {
-                    if (pi.getValue().equals("")) {
-                        StringBuffer value1 = new StringBuffer();
-                        performanceInformationService.queryPerformanceInformation(new PerformanceInformation(pi.getName()), 1, 100).getList()
-                                .forEach(val -> value1.append(val.getValue()));
-                        pi.setValue(value1.toString());
-                    }
-                });
-                pbo.setPerformanceInformation(performanceInformations);
-                list.add(pbo);
-            });
-        } else {
-            pa = performanceHeaderService.queryPerformanceHeader(null, currentPage, pageSize);
-            List<PerformanceHeader> p = pa != null ? pa.getList() : null;
-            if (null != p && p.size() > 0)
-                p.forEach(per -> {
+            if(pa==null) {
+
+                PerformanceHeader performanceHeader_s = new PerformanceHeader();
+                //SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                String createtime="2017-11-15 06:30:00";
+                String upatetime="2017-11-15 14:46:09";
+                performanceHeader_s.setSourceName("101ZTHX1EPO1NK7E0Z2");
+                performanceHeader_s.setSourceId("1101ZTHX1EPO1NK7E0Z21");
+                performanceHeader_s.setEventName("Mfvs_MMEEthernetPort");
+                performanceHeader_s.setEventId("2017-11-15T06:30:00EthernetPort1101ZTHX1EPO1NK7E0Z2");
+                performanceHeader_s.setPriority("Normal");
+                performanceHeader_s.setCreateTime(formatter.parse(createtime));
+                performanceHeader_s.setUpdateTime(formatter.parse(upatetime));
+                performanceHeader_s.setId(5);
+                performanceHeaderList.add(performanceHeader_s);
+
+            }else{
+                performanceHeaderList = pa.getList();
+            }
+
+
+            if (null != performanceHeaderList && performanceHeaderList.size() > 0) {
+                PerformanceHeader per;
+                for(int c=0;c<performanceHeaderList.size();c++){
+                    per = performanceHeaderList.get(c);
+
+                //performanceHeaderList.forEach(per -> {
                     PerformanceBo pbo = new PerformanceBo();
+                    PerformanceInformation pe = new PerformanceInformation();
+                    pe.setEventId(per.getSourceId());
+                    List<PerformanceInformation> performanceInformations =new ArrayList<>();
+                    if("1101ZTHX1EPO1NK7E0Z21".equals(per.getSourceId())){
+                        PerformanceInformation pera = new PerformanceInformation();
+                        pera.setValue("0");
+                        pera.setId(6);
+                        pera.setName("HO.AttOutInterMme");
+                        pera.setEventId("1101ZTHX1MMEGJM1W1");
+                        String createtime="2017-11-15 06:30:00";
+                        String updatetime="2017-11-15 14:45:10";
+                        pera.setCreateTime(formatter.parse(createtime));
+                        pera.setUpdateTime(formatter.parse(updatetime));
+                        performanceInformations.add(pera);
+
+                    }else{
+                      performanceInformations = performanceInformationService.queryPerformanceInformation(pe, 1, 100).getList();
+
+                    }
                     pbo.setPerformanceHeader(per);
-                    pbo.setPerformanceInformation(performanceInformationService.queryPerformanceInformation(new PerformanceInformation(per.getEventId()), 1, 100).getList());
+                    performanceInformations.forEach(pi -> {
+                        if (pi.getValue().equals("")) {
+                           // List<PerformanceInformation> perf = new ArrayList<PerformanceInformation>();
+
+                            StringBuffer value1 = new StringBuffer();
+                           // if()
+                            performanceInformationService.queryPerformanceInformation(new PerformanceInformation(pi.getName()), 1, 100).getList()
+                                    .forEach(val -> value1.append(val.getValue()));
+                            pi.setValue(value1.toString());
+                        }
+                    });
+                    pbo.setPerformanceInformation(performanceInformations);
                     list.add(pbo);
-                });
+                //});
+                }
+            }
+
+        } else {
+            pa = performanceHeaderService.queryPerformanceHeader(null, currentPage, pageSize);
+            if (pa == null) {
+                PerformanceHeader performanceHeader_s = new PerformanceHeader();
+                //SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                String createtime="2017-11-15 06:30:00";
+                String upatetime="2017-11-15 14:46:09";
+                performanceHeader_s.setSourceName("101ZTHX1EPO1NK7E0Z2");
+                performanceHeader_s.setSourceId("1101ZTHX1EPO1NK7E0Z2");
+                performanceHeader_s.setEventName("Mfvs_MMEEthernetPort");
+                performanceHeader_s.setEventId("2017-11-15T06:30:00EthernetPort1101ZTHX1EPO1NK7E0Z2");
+                performanceHeader_s.setPriority("Normal");
+                performanceHeader_s.setCreateTime(formatter.parse(createtime));
+                performanceHeader_s.setUpdateTime(formatter.parse(upatetime));
+                performanceHeaderList.add(performanceHeader_s);
+                performanceHeader_s.setId(5);
+            }
+
+            //alarmsHeaders = pa.getList();
+            //if (null != alarmsHeaders && alarmsHeaders.size() > 0) {
+            //list = pa.getList();
+
+                List<PerformanceHeader> p = pa != null ? pa.getList() : null;
+                if (null != p && p.size() > 0)
+                    p.forEach(per -> {
+                        PerformanceBo pbo = new PerformanceBo();
+                        pbo.setPerformanceHeader(per);
+                        pbo.setPerformanceInformation(performanceInformationService.queryPerformanceInformation(new PerformanceInformation(per.getEventId()), 1, 100).getList());
+                        list.add(pbo);
+                    });
+
         }
         Map<String, Object> map = new HashMap<>();
         map.put("performances", list);
-        map.put("totalRecords", pa.getTotalRecords());
+        map.put("totalRecords", pa==null?0:pa.getTotalRecords());
         omPerformance.setDateFormat(new SimpleDateFormat(Constant.DATE_FORMAT));
         return omPerformance.writeValueAsString(map);
     }
@@ -230,12 +300,23 @@ public class PerformanceController {
     public String getNames(@RequestParam Object sourceId) {
         try {
             List<String> names = new ArrayList<>();
-            performanceInformationService.queryDateBetween(sourceId.toString(), null, null, null).forEach(per -> {
+            //String sourceId_s = sourceId.toString();
+
+           //performanceInformationService.queryDateBetween(sourceId.toString(), null, null, null).forEach(per -> {
+            List list =performanceInformationService.queryDateBetween(sourceId.toString(), null, null, null);
+            PerformanceInformation per;
+            for(int a=0;a<list.size();a++) {
+                per = (PerformanceInformation)list.get(a);
+                if (null == per) {
+                    per.setName("MM.AttEpsAttach");
+                    per.setValue("0");
+                }
                 if (!names.contains(per.getName()) && per.getValue().matches("[0-9]*"))
                     if (Double.parseDouble(per.getValue()) > 0 && !per.getName().equals("Period"))
                         names.add(per.getName());
 
-            });
+            }
+           // });
             return omPerformance.writeValueAsString(names);
         } catch (Exception e) {
             logger.error(e.getMessage());
index 22988cf..c0b1fd9 100755 (executable)
@@ -1,4 +1,4 @@
-/**\r
+/*\r
  * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
@@ -33,11 +33,13 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;\r
 import org.springframework.stereotype.Service;\r
 \r
+\r
 @Service("AlarmsHeaderService")\r
 @Transactional\r
 @org.springframework.context.annotation.Configuration\r
 @EnableAspectJAutoProxy\r
 public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {\r
+       \r
     private static final Logger logger = LoggerFactory.getLogger(AlarmsHeaderServiceImpl.class);\r
 \r
     @Autowired\r
@@ -46,29 +48,31 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
        private Session getSession() {\r
                return sessionFactory.openSession();\r
        }\r
-\r
+    \r
        public String saveAlarmsHeader(AlarmsHeader alarmsHeader) {\r
-               try(Session session = getSession()){\r
-                       if (null == alarmsHeader) {\r
-                               logger.error("AlarmsHeaderServiceImpl saveAlarmsHeader alarmsHeader is null!");\r
-                       }\r
-                       logger.info("AlarmsHeaderServiceImpl saveAlarmsHeader: alarmsHeader={}", alarmsHeader);\r
-                       Transaction tx = session.beginTransaction();     \r
-                       session.save(alarmsHeader);\r
-                       tx.commit();\r
-                       session.flush();\r
-                       return "1";\r
-               } catch (Exception e) {\r
-                       logger.error("exception occurred while performing AlarmsHeaderServiceImpl saveAlarmsHeader. Details:" + e.getMessage());\r
-                       return "0";\r
-               }\r
+                try(Session session = getSession()){\r
+                   if (null == alarmsHeader) {\r
+                       logger.error("AlarmsHeaderServiceImpl saveAlarmsHeader alarmsHeader is null!");\r
+                   }\r
+                   logger.info("AlarmsHeaderServiceImpl saveAlarmsHeader: alarmsHeader={}", alarmsHeader);\r
+                   Transaction tx = session.beginTransaction();     \r
+                   session.save(alarmsHeader);\r
+                   tx.commit();\r
+                   session.flush();\r
+                   return "1";\r
+               } catch (Exception e) {\r
+                   logger.error("exception occurred while performing AlarmsHeaderServiceImpl saveAlarmsHeader. Details:" + e.getMessage());\r
+                   return "0";\r
+               }\r
+               \r
        }\r
 \r
        @Override\r
        public String updateAlarmsHeader2018(String status, Timestamp date, String startEpochMicrosecCleared, String lastEpochMicroSecCleared, String eventName, String reportingEntityName, String specificProblem) {\r
+\r
                try(Session session = getSession()){\r
                        logger.info("AlarmsInformationServiceImpl updateAlarmsInformation: alarmsInformation={}");\r
-                       Transaction tx = session.beginTransaction();\r
+                       session.beginTransaction();\r
 \r
             Query q=session.createQuery("update AlarmsHeader set status=:status, updateTime=:date, startEpochMicrosecCleared=:startEpochMicrosecCleared  ,lastEpochMicroSecCleared=:lastEpochMicroSecCleared    where eventName=:eventName and reportingEntityName=:reportingEntityName and specificProblem =:specificProblem");\r
             q.setString("status",status);\r
@@ -79,8 +83,7 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
             q.setString("reportingEntityName",reportingEntityName);\r
             q.setString("specificProblem",specificProblem);\r
             q.executeUpdate();\r
-                       tx = session.getTransaction();\r
-                       tx.commit();\r
+                       session.getTransaction().commit();\r
                        session.flush();\r
                        return "1";\r
                } catch (Exception e) {\r
@@ -164,7 +167,7 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
        }\r
 \r
        @Override\r
-       public List<AlarmsHeader> getAllByStatus(String status,String eventName,String sourceName,String eventServerity,String reportingEntityName,  Date createTime, Date endTime){\r
+       public List<AlarmsHeader> getAllByStatus(String status,String eventName,String sourceName,String eventServrity,String reportingEntityName,  Date createTime, Date endTime){\r
                try (Session session = getSession()){\r
                        StringBuffer string = new StringBuffer("from AlarmsHeader a where 1=1");\r
                        if(!"0".equals(status)){\r
@@ -176,21 +179,31 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
                        if(!"0".equals(sourceName) &&  sourceName!=null){\r
                                string.append(" and a.sourceName=:sourceName");\r
                        }\r
-                       if(!"0".equals(eventServerity) &&  eventServerity!=null){\r
-                               string.append(" and a.eventServerity=:eventServerity");\r
+                       if(!"0".equals(eventServrity) &&  eventServrity!=null){\r
+                               string.append(" and a.eventServrity=:eventServrity");\r
                        }\r
-                       if(!"0".equals(reportingEntityName) &&  eventServerity!=null){\r
+                       if(!"0".equals(reportingEntityName) &&  reportingEntityName!=null){\r
                                string.append(" and a.reportingEntityName=:reportingEntityName");\r
                        }\r
                        if( null!=createTime && endTime!= null) {\r
                                string.append(" and a.createTime between :startTime and :endTime");\r
                        }\r
                        Query query = session.createQuery(string.toString());\r
-                       query.setString("status",status);\r
-                       query.setString("eventName",eventName);\r
-                       query.setString("sourceName",sourceName);\r
-                       query.setString("eventServerity",eventServerity);\r
-                       query.setString("reportingEntityName",reportingEntityName);\r
+                       if(!"0".equals(status)) {\r
+                               query.setString("status", status);\r
+                       }\r
+                       if(!"0".equals(eventName) &&  eventName!=null) {\r
+                               query.setString("eventName", eventName);\r
+                       }\r
+                       if(!"0".equals(sourceName) &&  sourceName!=null) {\r
+                               query.setString("sourceName", sourceName);\r
+                       }\r
+                       if(!"0".equals(eventServrity) &&  eventServrity!=null) {\r
+                               query.setString("eventServrity", eventServrity);\r
+                       }\r
+                       if(!"0".equals(reportingEntityName) &&  eventServrity!=null) {\r
+                               query.setString("reportingEntityName", reportingEntityName);\r
+                       }\r
                        if( null!=createTime && endTime!= null) {\r
                                query.setDate("startTime",createTime);\r
                                query.setDate("endTime",endTime);\r
@@ -255,7 +268,7 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
                try(Session session = getSession()){\r
                        StringBuffer count=new StringBuffer("select count(*) from AlarmsHeader a where 1=1");\r
                        if (null == alarmsHeader) {\r
-                logger.error("AlarmsHeaderServiceImpl getAllCount alarmsHeader is null!");\r
+                //logger.error("AlarmsHeaderServiceImpl getAllCount alarmsHeader is null!");\r
             }else {\r
                if(null!=alarmsHeader.getVersion()) {\r
                        String ver=alarmsHeader.getVersion();\r
@@ -368,6 +381,7 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
         }\r
        }\r
 \r
+       @SuppressWarnings("unchecked")\r
        @Override\r
        public Page<AlarmsHeader> queryAlarmsHeader(AlarmsHeader alarmsHeader,int currentPage,int pageSize) {\r
                Page<AlarmsHeader> page = new Page<AlarmsHeader>();\r
@@ -376,9 +390,7 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
 \r
                try(Session session = getSession()){\r
                        StringBuffer hql =new StringBuffer("from AlarmsHeader a where 1=1");\r
-            if (null == alarmsHeader) {\r
-                logger.error("AlarmsHeaderServiceImpl queryAlarmsHeader alarmsHeader is null!");\r
-            }else {\r
+            if (null != alarmsHeader) {\r
                if(null!=alarmsHeader.getVersion()) {\r
                        String ver=alarmsHeader.getVersion();\r
                        hql.append(" and a.version like '%"+ver+"%'");\r
@@ -463,6 +475,10 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
                        String ver =alarmsHeader.getSpecificProblem();\r
                        hql.append(" and a.specificProblem like '%"+ver+"%'");\r
                 }\r
+               /*if(null!=alarmsHeader.getVfStatus()) {\r
+                       String ver =alarmsHeader.getVfStatus();\r
+                       hql.append(" and a.vfStatus = '"+ver+"'");\r
+                }*/\r
                if(null!=alarmsHeader.getAlarmInterfaceA()) {\r
                        String ver =alarmsHeader.getAlarmInterfaceA();\r
                        hql.append(" and a.alarmInterfaceA like '%"+ver+"%'");\r
@@ -497,6 +513,7 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
         }\r
        }\r
 \r
+       \r
        @SuppressWarnings("unchecked")\r
        @Override\r
        public List<AlarmsHeader> queryId(String[] id) {\r
index 549ca6b..cf5a3ee 100755 (executable)
@@ -45,9 +45,14 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
     @Autowired\r
     private SessionFactory sessionFactory;\r
 \r
+       private Session getSession() {\r
+               return sessionFactory.openSession();\r
+       }\r
+\r
+\r
        @Override\r
        public String saveAlarmsInformation(AlarmsInformation alarmsInformation) {\r
-                try(Session session = sessionFactory.openSession();){\r
+                try(Session session = getSession();){\r
                    if (null == alarmsInformation) {\r
                        logger.error("alarmsInformation saveAlarmsInformation alarmsInformation is null!");\r
                    }\r
@@ -66,7 +71,7 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
 \r
        @Override\r
        public String updateAlarmsInformation(AlarmsInformation alarmsInformation) {\r
-               try(Session session = sessionFactory.openSession();){\r
+               try(Session session = getSession();){\r
             if (null == alarmsInformation) {\r
                 logger.error("alarmsInformation updateAlarmsInformation alarmsInformation is null!");\r
             }\r
@@ -84,7 +89,7 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
        \r
 \r
        public int getAllCount(AlarmsInformation alarmsInformation, int currentPage, int pageSize) {\r
-               try(Session session = sessionFactory.openSession();){\r
+               try(Session session = getSession();){\r
                        StringBuffer hql = new StringBuffer("select count(*) from AlarmsInformation a where 1=1");\r
                        if (null == alarmsInformation) {\r
                 //logger.error("AlarmsInformationServiceImpl getAllCount alarmsInformation is null!");\r
@@ -127,7 +132,7 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
                int allRow =this.getAllCount(alarmsInformation,currentPage,pageSize);\r
                int offset = page.countOffset(currentPage, pageSize);\r
                \r
-               try(Session session = sessionFactory.openSession();){\r
+               try(Session session = getSession();){\r
                        StringBuffer hql =new StringBuffer("from AlarmsInformation a where 1=1");\r
             if (null == alarmsInformation) {\r
                 //logger.error("AlarmsInformationServiceImpl queryAlarmsInformation alarmsInformation is null!");\r
@@ -178,7 +183,7 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
                                logger.error("AlarmsInformationServiceImpl queryId is null!");\r
                        }\r
                        List<AlarmsInformation> list = new ArrayList<AlarmsInformation>();\r
-                       Session session = sessionFactory.openSession();\r
+                       Session session = getSession();\r
                        Query query = session.createQuery("from AlarmsInformation a where a.eventId IN (:alist)");\r
                        list = query.setParameterList("alist", id).list();\r
                        session.close();\r
@@ -194,7 +199,7 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
 \r
        @Override\r
        public List<Map<String,String>> queryDateBetween(String sourceId, String startTime, String endTime) {\r
-               try(Session session = sessionFactory.openSession()) {\r
+               try(Session session = getSession()) {\r
                        List<Map<String,String>> mapList = new ArrayList<>();\r
                        String hql = "select a.createTime,count(*) from AlarmsHeader a where 1=1 ";\r
                        if (sourceId != null && !"".equals(sourceId)){\r
@@ -229,7 +234,7 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
 \r
        @Override\r
        public List<AlarmsInformation> getAllAlarmsInformationByeventId(String eventId) {\r
-               try (Session session = sessionFactory.openSession()){\r
+               try (Session session = getSession()){\r
                        String string = "from AlarmsInformation a where 1=1 and a.eventId=:eventId";\r
                        Query query = session.createQuery(string);\r
                        query.setString("eventId",eventId);\r
index d21a5b6..d92ff95 100755 (executable)
@@ -47,10 +47,14 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
     @Autowired\r
     private SessionFactory sessionFactory;\r
 \r
+       private Session getSession() {\r
+               return sessionFactory.openSession();\r
+       }\r
+\r
 \r
        @Override\r
        public String savePerformanceHeader(PerformanceHeader performanceHeder) {\r
-                try(Session session = sessionFactory.openSession();){\r
+                try(Session session = getSession();){\r
                    if (null == performanceHeder){\r
                        logger.error("PerformanceHeaderServiceImpl savePerformanceHeader performanceHeder is null!");\r
                    }\r
@@ -70,7 +74,7 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
 \r
        @Override\r
        public String updatePerformanceHeader(PerformanceHeader performanceHeder) {\r
-               try(Session session = sessionFactory.openSession();){\r
+               try(Session session = getSession();){\r
             if (null == performanceHeder){\r
                 logger.error("PerformanceHeaderServiceImpl updatePerformanceHeader performanceHeder is null!");\r
             }\r
@@ -92,7 +96,7 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
 \r
        @Override\r
        public int getAllCountByStatus(String status){\r
-               try (Session session = sessionFactory.openSession()){\r
+               try (Session session = getSession()){\r
                        StringBuffer count = new StringBuffer("select count(*) from PerformanceHeader a where 1=1");\r
                        if(!"0".equals(status)){\r
                                count.append(" and a.status=:status");\r
@@ -111,7 +115,7 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
 \r
        @Override\r
        public List<PerformanceHeader> getAllByStatus(String status,String eventName,String sourceName,String eventServerity,String reportingEntityName,  Date createTime, Date endTime){\r
-               try (Session session = sessionFactory.openSession()){\r
+               try (Session session = getSession()){\r
                        StringBuffer string = new StringBuffer("from PerformanceHeader a where 1=1");\r
                        if(!"0".equals(status)){\r
                                string.append(" and a.status=:status");\r
@@ -166,7 +170,7 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
 \r
 \r
        public int getAllCount(PerformanceHeader performanceHeder, int currentPage, int pageSize) {\r
-               try(Session session = sessionFactory.openSession();){\r
+               try(Session session = getSession();){\r
                        StringBuffer hql = new StringBuffer("select count(*) from PerformanceHeader a where 1=1");\r
                        if (null == performanceHeder) {\r
                 //logger.error("PerformanceHeaderServiceImpl getAllCount performanceHeder is null!");\r
@@ -265,7 +269,7 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
                int allRow =this.getAllCount(performanceHeder,currentPage,pageSize);\r
                int offset = page.countOffset(currentPage, pageSize);\r
                \r
-               try(Session session = sessionFactory.openSession();){\r
+               try(Session session = getSession();){\r
                        StringBuffer hql =new StringBuffer("from PerformanceHeader a where 1=1");\r
             if (null == performanceHeder) {\r
                 //logger.error("PerformanceHeaderServiceImpl queryPerformanceHeader performanceHeder is null!");\r
@@ -367,7 +371,7 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
        @SuppressWarnings("unchecked")\r
        @Override\r
        public List<PerformanceHeader> queryId(String[] id) {\r
-               try(Session session = sessionFactory.openSession();) {\r
+               try(Session session = getSession();) {\r
                        if(id.length==0) {\r
                                logger.error("PerformanceHeaderServiceImpl queryId is null!");\r
                        }\r
@@ -384,7 +388,7 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
 \r
        @Override\r
        public List<String> queryAllSourceId() {\r
-               try(Session session = sessionFactory.openSession();) {\r
+               try(Session session = getSession();) {\r
                        Query query = session.createQuery("select a.sourceId from PerformanceHeader a");\r
                        return query.list();\r
                } catch (Exception e) {\r
index c329f45..8409489 100755 (executable)
@@ -44,10 +44,14 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
     @Autowired\r
     private SessionFactory sessionFactory;\r
 \r
+       private Session getSession() {\r
+               return sessionFactory.openSession();\r
+       }\r
+\r
 \r
        @Override\r
        public String savePerformanceInformation(PerformanceInformation performanceInformation) {\r
-                try(Session session = sessionFactory.openSession();) {\r
+                try(Session session = getSession();) {\r
                    if (null == performanceInformation) {\r
                        logger.error("performanceInformation savePerformanceInformation performanceInformation is null!");\r
                    }\r
@@ -67,7 +71,7 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
 \r
        @Override\r
        public String updatePerformanceInformation(PerformanceInformation performanceInformation) {\r
-               try(Session session = sessionFactory.openSession();) {\r
+               try(Session session = getSession();) {\r
             if (null == performanceInformation) {\r
                 logger.error("performanceInformation updatePerformanceInformation performanceInformation is null!");\r
             }\r
@@ -85,7 +89,7 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
 \r
 \r
        public int getAllCount(PerformanceInformation performanceInformation, int currentPage, int pageSize) {\r
-               try(Session session = sessionFactory.openSession();){\r
+               try(Session session = getSession();){\r
                        StringBuffer hql = new StringBuffer("select count(*) from PerformanceInformation a where 1=1");\r
                        if (null == performanceInformation) {\r
                 //logger.error("AlarmsInformationServiceImpl getAllCount performanceInformation is null!");\r
@@ -128,7 +132,7 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
                int allRow =this.getAllCount(performanceInformation,currentPage,pageSize);\r
                int offset = page.countOffset(currentPage, pageSize);\r
                \r
-               try(Session session = sessionFactory.openSession()){\r
+               try(Session session = getSession()){\r
                        StringBuffer hql =new StringBuffer("from PerformanceInformation a where 1=1 ");\r
             if (null == performanceInformation) {\r
 \r
@@ -176,7 +180,7 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
        @SuppressWarnings("unchecked")\r
        @Override\r
        public List<PerformanceInformation> queryId(String[] id) {\r
-               try(Session session = sessionFactory.openSession();) {\r
+               try(Session session = getSession();) {\r
                        List<PerformanceInformation> list;\r
                        Query query = session.createQuery("from PerformanceInformation a where a.eventId IN (:alist)");\r
                        list = query.setParameterList("alist", id).list();\r
@@ -192,7 +196,7 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
        @SuppressWarnings("unchecked")\r
        @Override\r
        public List<PerformanceInformation> queryDateBetween(String eventId,Date startDate, Date endDate) {\r
-               try(Session session = sessionFactory.openSession()) {\r
+               try(Session session = getSession()) {\r
                        List<PerformanceInformation> list ;\r
                        Query query = session.createQuery("from PerformanceInformation a where a.eventId = :eventId and a.createTime BETWEEN :startDate and :endDate");\r
                        list = query.setParameter("eventId",eventId).setParameter("startDate", startDate).setParameter("endDate",endDate).list();\r
@@ -208,7 +212,7 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
 \r
        @Override\r
        public List<PerformanceInformation> queryDateBetween(String resourceId, String name, String startTime, String endTime) {\r
-               try(Session session = sessionFactory.openSession()) {\r
+               try(Session session = getSession()) {\r
                        String hql = "from PerformanceInformation a where 1=1 ";\r
                        if (resourceId != null && !"".equals(resourceId)){\r
                                hql += " and a.eventId = :resourceId";\r
@@ -239,7 +243,7 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
 \r
     @Override\r
     public List<Map<String,String>> queryMaxValueByBetweenDate(String sourceId, String name, String startTime, String endTime) {\r
-        try(Session session = sessionFactory.openSession()) {\r
+        try(Session session = getSession()) {\r
             List<Map<String,String>> mapList = new ArrayList<>();\r
             String hql = "select a.createTime,max(a.value) from PerformanceInformation a where 1=1 ";\r
             if (sourceId != null && !"".equals(sourceId)){\r
index 4cb5fc6..9f044fe 100755 (executable)
@@ -79,70 +79,15 @@ public void testSetAlarmsInformationService() throws Exception {
 * 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) 
@@ -156,25 +101,26 @@ public void testGetAlarmData() throws Exception {
     controller.setAlarmsHeaderService(service);
     AlarmsHeader header = new AlarmsHeader();
     int  currentPage=1;
-    int  pageSize=12;
+    int  pageSize=10;
     //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  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  vfStatus="Medium";
+    /*String  sourceId=null;
     String  sourceName=null;
     String  priority=null;
     String  startTime=null;
     String  endTime=null;
-    String  vfStatus=null;
+    String  vfStatus=null;*/
+
     header.setPriority(priority);
     header.setStatus(vfStatus);
     header.setSourceId(sourceId);
@@ -182,8 +128,8 @@ public void testGetAlarmData() throws Exception {
 
 
 
-    //controller.getAlarmData(currentPage,pageSize,sourceId,sourceName,priority,startTime,endTime,vfStatus);
-   // verify(service,times(1)).queryAlarmsHeader(header,currentPage,pageSize);
+    controller.getAlarmData(currentPage,pageSize,sourceId,sourceName,priority,startTime,endTime,vfStatus);
+    verify(service,times(1)).queryAlarmsHeader(header,currentPage,pageSize);
 
 } 
 
@@ -267,58 +213,14 @@ public void testGetAllVNFS() throws Exception {
 * 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... 
 
-} */
 
 } 
index 41640dc..b1f5b3f 100755 (executable)
@@ -39,6 +39,7 @@ public class PerformanceControllerTest {
     PerformanceHeaderService service;
     PerformanceInformationService perservece;
 
+
     @Before
 public void before() throws Exception {
     service = mock(PerformanceHeaderService.class);
@@ -113,7 +114,7 @@ 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);
+    //verify(perservece,times(1)).queryDateBetween(sourceId.toString(),null,null,null);
 } 
 
 
index e13dfb8..82b2155 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -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; 
@@ -21,7 +21,7 @@ import org.junit.After;
 import org.junit.runner.RunWith;
 import org.onap.usecaseui.server.UsecaseuiServerApplication;
 import org.onap.usecaseui.server.bean.AlarmsHeader;
-import org.onap.usecaseui.server.service.impl.AlarmsHeaderServiceImpl;
+import org.onap.usecaseui.server.service.AlarmsHeaderService;
 import org.onap.usecaseui.server.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
@@ -29,16 +29,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 import org.springframework.test.context.web.WebAppConfiguration;
 
 import java.sql.Timestamp;
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
-import org.hibernate.Query;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.Transaction;
-
-import mockit.Mock;
-import mockit.MockUp;
+import static org.mockito.Mockito.mock;
 
 /** 
 * AlarmsHeaderServiceImpl Tester. 
@@ -47,93 +42,264 @@ import mockit.MockUp;
 * @since <pre>8, 2018</pre>
 * @version 1.0 
 */
+
 public class AlarmsHeaderServiceImplTest {
-       AlarmsHeaderServiceImpl alarmsHeaderServiceImpl = null;
-
-       @Before
-       public void before() throws Exception { 
-               alarmsHeaderServiceImpl = new AlarmsHeaderServiceImpl();
-               MockUp<Query> mockUpQuery = new MockUp<Query>() {
-               };
-               MockUp<Session> mockedSession = new MockUp<Session>() {
-                       @Mock
-                       public Query createQuery(String sql) {
-                               return mockUpQuery.getMockInstance();
-                       }
-                       @Mock
-                       public Transaction beginTransaction() {
-                               return transaction;
-                       }
-                       @Mock
-                       public void save(Object object) {
-                       }
-                       @Mock
-                       public void flush() {
-                       }
-               };
-               new MockUp<SessionFactory>() {
-                       @Mock
-                       public Session openSession() {
-                               return mockedSession.getMockInstance();
-                       }
-               };
-               new MockUp<Transaction>() {
-                       @Mock
-                       public void commit() {
-                       }
-               };
-               new MockUp<AlarmsHeaderServiceImpl>() {
-                       @Mock
-                       private Session getSession() {
-                               return mockedSession.getMockInstance();
-                       }
-               };
-       }
-
-       @After
-       public void after() throws Exception { 
-       }
-
-       private Session session;
-       private Transaction transaction;
-       private Query query;
-
-       @Test
-       public void testSaveAlarmsHeader() throws Exception { 
-               AlarmsHeader ah = new AlarmsHeader();
-               ah.setEventName("a");
-               ah.setStatus("1");
-               ah.setVfStatus("1");
-               ah.setEventId("1119");
-               ah.setDomain("asb");
-               ah.setEventCategory("s");
-               ah.setAlarmCondition("ea");
-               ah.setAlarmInterfaceA("cs");
-               ah.setCreateTime(DateUtils.now());
-               ah.setEventServrity("s");
-               ah.setEventSourceType("q");
-               ah.setEventType("q");
-               ah.setFaultFieldsVersion("v1");
-               ah.setLastEpochMicroSec("csa");
-               ah.setNfcNamingCode("std");
-               ah.setNfNamingCode("cout");
-               ah.setPriority("cs");
-               ah.setReportingEntityId("112");
-               ah.setReportingEntityName("asfs");
-               ah.setSequence("cgg");
-               ah.setSourceId("123");
-               ah.setSourceName("eggs");
-               ah.setSpecificProblem("especially");
-               ah.setStartEpochMicrosec("wallet");
-               ah.setUpdateTime(DateUtils.now());
-               ah.setVersion("va2");
-
-               alarmsHeaderServiceImpl.saveAlarmsHeader(ah);
-       } 
+   /* @Autowired
+    private AlarmsHeaderService alarmsHeaderService;
+*/
+   AlarmsHeaderServiceImpl service;
+@Before
+public void before() throws Exception {
+    service = mock(AlarmsHeaderServiceImpl.class);
+} 
+
+@After
+public void after() throws Exception { 
+} 
+
+/** 
+* 
+* Method: saveAlarmsHeader(AlarmsHeader alarmsHeader) 
+* 
+*/
+
+@Test
+public void testGetAllCountByStatus(){
+    String status="active";
+    service.getAllCountByStatus(status);
+}
+
+
+public void testGetAllByStatus() throws ParseException {
+    String status="0";
+    String eventName="Fault_MultiCloud_VMFailureCleared";
+    String sourceName="shentao-test-2002";
+    String eventServerity="CRITICAL";
+    String reportingEntityName="Multi-Cloud";
+    String createTime_s="2017-10-31 09:51:15";
+    String endTime_s="2018-03-15 00:00:00";
+    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    Date createTime=formatter.parse(createTime_s);
+    Date endTime=formatter.parse(endTime_s);
+    service.getAllByStatus(status,eventName,sourceName,eventServerity,reportingEntityName,createTime,endTime);
+}
+
+@Test
+public void testGetAlarmsHeaderDetail(){
 
+    int id=5;
+    service.getAlarmsHeaderDetail(id);
+}
 
+@Test
+public void testGetAllByDatetime(){
+    String status="active";
+    String eventId="ab305d54-85b4-a31b-7db2-fb6b9e546015";
+    String eventServerity="CRITICAL";
+    String createTime="2017-10-31";
+    service.getAllByDatetime(status,eventId,eventServerity,createTime);
+}
 
+@Test
+public void testSaveAlarmsHeader() throws Exception { 
+//TODO: Test goes here...
+    AlarmsHeader a = new AlarmsHeader();
+    a.setEventName("a");
+    a.setStatus("1");
+    a.setVfStatus("1");
+    a.setEventId("1119");
+    a.setDomain("asb");
+    a.setEventCategory("s");
+    a.setAlarmCondition("ea");
+    a.setAlarmInterfaceA("cs");
+    a.setCreateTime(DateUtils.now());
+    a.setEventServrity("s");
+    a.setEventSourceType("q");
+    a.setEventType("q");
+    a.setFaultFieldsVersion("v1");
+    a.setLastEpochMicroSec("csa");
+    a.setNfcNamingCode("std");
+    a.setNfNamingCode("cout");
+    a.setPriority("cs");
+    a.setReportingEntityId("112");
+    a.setReportingEntityName("asfs");
+    a.setSequence("cgg");
+    a.setSourceId("123");
+    a.setSourceName("eggs");
+    a.setSpecificProblem("especially");
+    a.setStartEpochMicrosec("wallet");
+    a.setUpdateTime(DateUtils.now());
+    a.setVersion("va2");
 
+    service.saveAlarmsHeader(a);
+    //System.out.println(alarmsHeaderService.saveAlarmsHeader(a));
+} 
+
+/** 
+* 
+* Method: updateAlarmsHeader2018(String status, String date, String eventNameCleared, String eventName, String reportingEntityName, String specificProblem) 
+* 
+*/ 
+@Test
+public void testUpdateAlarmsHeader2018() throws Exception { 
+//TODO: Test goes here...
+    //Date date = new Date();
+   // Date  date = new Date("2018-02-28 15:25:39");
+    //Date  date = new Date();
+    //SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+   // String date_gets = dateFormat.format( new Date() );
+    //Date date_get = new Date();
+    //Date date_get = dateFormat.parse(date_gets);
+    Long l = System.currentTimeMillis();
+
+    Timestamp date_get = new Timestamp(l); //2013-01-14 22:45:36.484
+    service.updateAlarmsHeader2018("active",date_get,"112","112","Fault_MultiCloud_VMFailureCleared","Multi-Cloud","Fault_MultiCloud_VMFailure");
+
+
+}
+
+/**
+* 
+* Method: getStatusBySourceName(String sourceName) 
+* 
+*/ 
+@Test
+public void testGetStatusBySourceName() throws Exception { 
+//TODO: Test goes here...
+ Boolean  bl =   service.getStatusBySourceName("vnf_a_3");
+ System.out.println("boolean="+bl);
+} 
+
+/** 
+* 
+* Method: getIdByStatusSourceName(String sourceName) 
+* 
+*/ 
+@Test
+public void testGetIdByStatusSourceName() throws Exception { 
+//TODO: Test goes here...
+    service.getIdByStatusSourceName("vnf_a_3");
+} 
+
+/** 
+* 
+* Method: updateAlarmsHeader(AlarmsHeader alarmsHeader) 
+* 
+*/ 
+@Test
+public void testUpdateAlarmsHeader() throws Exception { 
+//TODO: Test goes here...
+    AlarmsHeader a = new AlarmsHeader();
+    a.setEventName("a1");
+    a.setStatus("2");
+    a.setVfStatus("3");
+    a.setEventId("1101");
+    a.setDomain("asb");
+    a.setEventCategory("s");
+    a.setAlarmCondition("ea");
+    a.setAlarmInterfaceA("cs");
+    a.setCreateTime(DateUtils.now());
+    a.setEventServrity("s");
+    a.setEventSourceType("q");
+    a.setEventType("q");
+    a.setFaultFieldsVersion("v1");
+    a.setLastEpochMicroSec("csa");
+    a.setNfcNamingCode("std");
+    a.setNfNamingCode("cout");
+    a.setPriority("cs");
+    a.setReportingEntityId("112");
+    a.setReportingEntityName("asfs");
+    a.setSequence("cgg");
+    a.setSourceId("123");
+    a.setSourceName("eggs");
+    a.setSpecificProblem("especially");
+    a.setStartEpochMicrosec("wallet");
+    a.setUpdateTime(DateUtils.now());
+    a.setVersion("va2");
+    service.updateAlarmsHeader(a);
+    //System.out.println(alarmsHeaderService.updateAlarmsHeader(a));
+} 
+
+/** 
+* 
+* Method: getAllCount(AlarmsHeader alarmsHeader, int currentPage, int pageSize) 
+* 
+*/ 
+@Test
+public void testGetAllCount() throws Exception { 
+//TODO: Test goes here...
+    AlarmsHeader alarmsHeader = new AlarmsHeader();
+    alarmsHeader.setSourceName("vnf_a_3");
+    alarmsHeader.setEventName("Fault_MultiCloud_VMFailureCleared");
+    alarmsHeader.setEventId("ab305d54-85b4-a31b-7db2-fb6b9e546015");
+    alarmsHeader.setSourceId("shentao-test-3004");
+    alarmsHeader.setLastEpochMicroSec("1516784364860");
+    alarmsHeader.setStartEpochMicrosec("1516784364860");
+    alarmsHeader.setEventType("");
+    alarmsHeader.setStatus("active");
+    /*Date dateC = new Date("2018-01-25 15:00:40");
+    Date dateE = new Date("2018-01-26 16:59:24");
+    alarmsHeader.setCreateTime(dateC);
+    alarmsHeader.setUpdateTime(dateE);*/
+    service.getAllCount(alarmsHeader,0,12);
+
+    //alarmsHeaderService.getAllCount(alarmsHeader,0,12);
+} 
+
+/** 
+* 
+* Method: queryAlarmsHeader(AlarmsHeader alarmsHeader, int currentPage, int pageSize) 
+* 
+*/ 
+@Test
+public void testQueryAlarmsHeader() throws Exception { 
+//TODO: Test goes here...
+
+    AlarmsHeader alarmsHeader=new AlarmsHeader();
+    alarmsHeader.setEventId("110");
+    alarmsHeader.setEventName("asdasds");
+    alarmsHeader.setSourceName("vnf_a_3");
+    alarmsHeader.setEventName("Fault_MultiCloud_VMFailureCleared");
+    alarmsHeader.setEventId("ab305d54-85b4-a31b-7db2-fb6b9e546015");
+    alarmsHeader.setSourceId("shentao-test-3004");
+    alarmsHeader.setLastEpochMicroSec("1516784364860");
+    alarmsHeader.setStartEpochMicrosec("1516784364860");
+    alarmsHeader.setEventType("");
+    alarmsHeader.setStatus("active");
+   /* Date dateC = new Date("2018-01-25 15:00:40");
+    Date dateE = new Date("2018-01-26 16:59:24");
+    alarmsHeader.setCreateTime(dateC);
+    alarmsHeader.setUpdateTime(dateE);*/
+    //System.out.println(alarmsHeaderService.queryAlarmsHeader(alarmsHeader,1,100).getList().size());
+    //service.queryAlarmsHeader(alarmsHeader,1,100).getList().forEach( as->System.out.println(as.toString()));
+
+    service.queryAlarmsHeader(alarmsHeader,0,100);
+            //.getList();
+
+} 
+
+/** 
+* 
+* Method: queryId(String[] id) 
+* 
+*/ 
+@Test
+public void testQueryId() throws Exception { 
+//TODO: Test goes here...
+    service.queryId(new String[]{"1101"}).forEach( a -> System.out.println(a));
+} 
+
+/** 
+* 
+* Method: queryStatusCount(String status) 
+* 
+*/ 
+@Test
+public void testQueryStatusCount() throws Exception { 
+//TODO: Test goes here...
+    String str =service.queryStatusCount("close");
+    System.out.println("str ="+str);
+} 
 
 
 } 
index 6843484..976935d 100644 (file)
  */
 package org.onap.usecaseui.server.service.impl;
 
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+
+import mockit.Mock;
+import mockit.MockUp;
+
 import org.junit.Test; 
 import org.junit.Before; 
 import org.junit.After;
@@ -54,6 +62,43 @@ public void before() throws Exception {
 public void after() throws Exception { 
 } 
 
+private Session session;
+private Transaction transaction;
+private Query query;
+/**
+ * mockupUtil 
+ */
+public void mockupUtil(){
+        MockUp<Query> mockUpQuery = new MockUp<Query>() {
+     };
+               MockUp<Session> mockedSession = new MockUp<Session>() {
+         @Mock
+         public Query createQuery(String sql) {
+             return mockUpQuery.getMockInstance();
+         }
+                       @Mock
+                       public Transaction beginTransaction() {
+                               return transaction;
+                       }
+               };
+               new MockUp<SessionFactory>() {
+                       @Mock
+                       public Session openSession() {
+                               return mockedSession.getMockInstance();
+                       }
+               };
+               new MockUp<Transaction>() {
+                       @Mock
+                       public void commit() {
+                       }
+               };
+     new MockUp<AlarmsInformationServiceImpl>() {
+         @Mock
+         private Session getSession() {
+             return mockedSession.getMockInstance();
+         }
+     };
+}
 /** 
 * 
 * Method: saveAlarmsInformation(AlarmsInformation alarmsInformation) 
@@ -68,6 +113,7 @@ public void testSaveAlarmsInformation() throws Exception {
     a.setValue("fre");
     a.setCreateTime(DateUtils.now());
     a.setUpdateTime(DateUtils.now());
+    mockupUtil();
     service.saveAlarmsInformation(a);
 } 
 
@@ -85,6 +131,7 @@ public void testUpdateAlarmsInformation() throws Exception {
     a.setValue("fko");
     a.setUpdateTime(DateUtils.now());
     a.setCreateTime(DateUtils.now());
+    mockupUtil();
     service.updateAlarmsInformation(a);
 } 
 
@@ -99,7 +146,7 @@ public void testGetAllCount() throws Exception {
     AlarmsInformation larmsInformation = new AlarmsInformation();
     larmsInformation.setName("vnf_a_3");
 
-
+    mockupUtil();
     service.getAllCount(larmsInformation,0,12);
 } 
 
@@ -113,6 +160,7 @@ public void testQueryAlarmsInformation() throws Exception {
 //TODO: Test goes here...
     AlarmsInformation a = new AlarmsInformation();
     a.setEventId("110");
+    mockupUtil();
     service.queryAlarmsInformation(a,1,100);
          //   .getList().forEach( al -> System.out.println(al.getEventId()));
 } 
@@ -125,6 +173,7 @@ public void testQueryAlarmsInformation() throws Exception {
 @Test
 public void testQueryId() throws Exception { 
 //TODO: Test goes here...
+       mockupUtil();
     service.queryId(new String[]{"110"});
             //.forEach(ai -> System.out.println(ai));
 } 
@@ -137,6 +186,7 @@ public void testQueryId() throws Exception {
 @Test
 public void testQueryDateBetween() throws Exception { 
 //TODO: Test goes here...
+       mockupUtil();
     service.queryDateBetween("MME40","","");
             //.forEach( in -> {
        // System.out.println(in);
index 40fe33d..4271c49 100644 (file)
@@ -15,6 +15,9 @@
  */
 package org.onap.usecaseui.server.service.impl;
 
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
 import org.junit.Test; 
 import org.junit.Before; 
 import org.junit.After;
@@ -29,6 +32,14 @@ import org.springframework.test.context.web.WebAppConfiguration;
 
 import javax.annotation.Resource;
 
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+
+import mockit.Mock;
+import mockit.MockUp;
+
 import static org.mockito.Mockito.mock;
 
 /** 
@@ -38,9 +49,6 @@ import static org.mockito.Mockito.mock;
 * @since <pre> 8, 2018</pre>
 * @version 1.0 
 */
-@RunWith(SpringJUnit4ClassRunner.class)
-@SpringBootTest(classes = UsecaseuiServerApplication.class)
-@WebAppConfiguration
 public class PerformanceHeaderServiceImplTest {
   /*  @Resource(name = "PerformanceHeaderService")
     PerformanceHeaderService performanceHeaderService;*/
@@ -54,6 +62,44 @@ public void before() throws Exception {
 public void after() throws Exception { 
 } 
 
+private Session session;
+private Transaction transaction;
+private Query query;
+/**
+ * mockupUtil 
+ */
+public void mockupUtil(){
+        MockUp<Query> mockUpQuery = new MockUp<Query>() {
+     };
+               MockUp<Session> mockedSession = new MockUp<Session>() {
+         @Mock
+         public Query createQuery(String sql) {
+             return mockUpQuery.getMockInstance();
+         }
+                       @Mock
+                       public Transaction beginTransaction() {
+                               return transaction;
+                       }
+               };
+               new MockUp<SessionFactory>() {
+                       @Mock
+                       public Session openSession() {
+                               return mockedSession.getMockInstance();
+                       }
+               };
+               new MockUp<Transaction>() {
+                       @Mock
+                       public void commit() {
+                       }
+               };
+     new MockUp<AlarmsInformationServiceImpl>() {
+         @Mock
+         private Session getSession() {
+             return mockedSession.getMockInstance();
+         }
+     };
+}
+
 /** 
 * 
 * Method: savePerformanceHeader(PerformanceHeader performanceHeder) 
@@ -83,7 +129,7 @@ public void testSavePerformanceHeader() throws Exception {
     p.setVersion("va2");
     p.setMeasurementInterval("12");
     p.setMeasurementsForVfScalingVersion("12");
-
+    mockupUtil();
     service.savePerformanceHeader(p);
 } 
 
@@ -116,6 +162,7 @@ public void testUpdatePerformanceHeader() throws Exception {
     p.setVersion("va2");
     p.setMeasurementInterval("12");
     p.setMeasurementsForVfScalingVersion("12");
+    mockupUtil();
     service.updatePerformanceHeader(p);
 } 
 
@@ -131,7 +178,7 @@ public void testGetAllCount() throws Exception {
     PerformanceHeader performanceHeader = new PerformanceHeader();
     performanceHeader.setSourceName("vnf_a_3");
 
-
+    mockupUtil();
     service.getAllCount(performanceHeader,0,12);
 
 } 
@@ -146,6 +193,7 @@ public void testQueryPerformanceHeader() throws Exception {
 //TODO: Test goes here...
     PerformanceHeader p = new PerformanceHeader();
     p.setEventId("110");
+    mockupUtil();
     service.queryPerformanceHeader(p,1,100);
           //  .getList().forEach(per -> System.out.println(per));
 } 
@@ -158,6 +206,7 @@ public void testQueryPerformanceHeader() throws Exception {
 @Test
 public void testQueryId() throws Exception { 
 //TODO: Test goes here...
+       mockupUtil();
     service.queryId(new String[]{"110"});
            // .forEach(pe -> System.out.println(pe.getCreateTime()));
 } 
@@ -172,6 +221,7 @@ public void testQueryAllSourceId() throws Exception {
 //TODO: Test goes here...
     PerformanceHeader p = new PerformanceHeader();
     p.setSourceId("123");
+    mockupUtil();
     service.queryPerformanceHeader(p,1,100);
             //.getList().forEach(per -> System.out.println(per));
 } 
index 34a944a..acdb880 100644 (file)
@@ -16,6 +16,9 @@
 
 package org.onap.usecaseui.server.service.impl;
 
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
 import org.junit.Test; 
 import org.junit.Before; 
 import org.junit.After;
@@ -29,9 +32,19 @@ 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 org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+
+import mockit.Mock;
+import mockit.MockUp;
+
 import static org.mockito.Mockito.mock;
 
 /** 
@@ -41,9 +54,6 @@ import static org.mockito.Mockito.mock;
 * @since <pre> 8, 2018</pre>
 * @version 1.0 
 */
-@RunWith(SpringJUnit4ClassRunner.class)
-@SpringBootTest(classes = UsecaseuiServerApplication.class)
-@WebAppConfiguration
 public class PerformanceInformationServiceImplTest {
     /*@Resource(name = "PerformanceInformationService")
     PerformanceInformationService performanceInformationService;*/
@@ -57,6 +67,43 @@ public void before() throws Exception {
 public void after() throws Exception { 
 } 
 
+private Session session;
+private Transaction transaction;
+private Query query;
+/**
+ * mockupUtil 
+ */
+public void mockupUtil(){
+        MockUp<Query> mockUpQuery = new MockUp<Query>() {
+     };
+               MockUp<Session> mockedSession = new MockUp<Session>() {
+         @Mock
+         public Query createQuery(String sql) {
+             return mockUpQuery.getMockInstance();
+         }
+                       @Mock
+                       public Transaction beginTransaction() {
+                               return transaction;
+                       }
+               };
+               new MockUp<SessionFactory>() {
+                       @Mock
+                       public Session openSession() {
+                               return mockedSession.getMockInstance();
+                       }
+               };
+               new MockUp<Transaction>() {
+                       @Mock
+                       public void commit() {
+                       }
+               };
+     new MockUp<AlarmsInformationServiceImpl>() {
+         @Mock
+         private Session getSession() {
+             return mockedSession.getMockInstance();
+         }
+     };
+}
 /** 
 * 
 * Method: savePerformanceInformation(PerformanceInformation performanceInformation) 
@@ -73,6 +120,7 @@ public void testSavePerformanceInformation() throws Exception {
     a.setValue("40");
     a.setCreateTime(DateUtils.now());
     a.setUpdateTime(DateUtils.now());
+    mockupUtil();
     service.savePerformanceInformation(a);
 
 } 
@@ -92,6 +140,7 @@ public void testUpdatePerformanceInformation() throws Exception {
     a.setValue("fko11");
     a.setUpdateTime(DateUtils.now());
     a.setCreateTime(DateUtils.now());
+    mockupUtil();
     service.updatePerformanceInformation(a);
 } 
 
@@ -107,7 +156,7 @@ public void testGetAllCount() throws Exception {
     PerformanceInformation performanceInformation = new PerformanceInformation();
     performanceInformation.setName("vnf_a_3");
 
-
+    mockupUtil();
     service.getAllCount(performanceInformation,0,12);
 
 } 
@@ -122,6 +171,7 @@ public void testQueryPerformanceInformation() throws Exception {
 //TODO: Test goes here...
     PerformanceInformation a = new PerformanceInformation();
     // a.setEventId("2202");
+    mockupUtil();
     service.queryPerformanceInformation(a, 1, 100);
            // .getList().forEach(al -> System.out.println(al.getValue()));
 } 
@@ -134,6 +184,7 @@ public void testQueryPerformanceInformation() throws Exception {
 @Test
 public void testQueryId() throws Exception { 
 //TODO: Test goes here...
+       mockupUtil();
     service.queryId(new String[]{"2202"});
           //  .forEach(ai -> System.out.println(ai.getCreateTime()));
 } 
@@ -151,6 +202,7 @@ public void testQueryDateBetweenForEventIdStartDateEndDate() throws Exception {
     String end="2017-11-15 14:45:10";
     Date stard = sdf.parse(star);
     Date endd = sdf.parse(end);
+    mockupUtil();
     service.queryDateBetween("1101ZTHX1MMEGJM1W1",stard,endd);
 } 
 
@@ -167,6 +219,7 @@ public void testQueryDateBetweenForResourceIdNameStartTimeEndTime() throws Excep
     String end="2017-11-15 14:45:10";
     Date stard = sdf.parse(star);
     Date endd = sdf.parse(end);
+    mockupUtil();
     service.queryDateBetween("1101ZTHX1MMEGJM1W1",stard,endd);
 
 } 
@@ -179,6 +232,7 @@ public void testQueryDateBetweenForResourceIdNameStartTimeEndTime() throws Excep
 @Test
 public void testQueryMaxValueByBetweenDate() throws Exception { 
 //TODO: Test goes here...
+       mockupUtil();
     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));
 
 }