@Test public void testListAllEvents() { setSecuirtyContext(TEAMNAME, USERNAME); EventRecorder eventRecorder = createEvent(TEAMNAME); TeamUser teamUser = createTeamUserObject(USERNAME, TEAMNAME); List<EventRecorder> events = new ArrayList<>(); events.add(eventRecorder); Page<EventRecorder> eventRecorderPage = new PageImpl<>(events); when(teamUserRepository.findByUserNameAndDefaultFlag(USERNAME, "Y")).thenReturn(teamUser); when(eventRepository.findByTeamName(TEAMNAME, new PageRequest(0, 9999))).thenReturn(eventRecorderPage); @SuppressWarnings("unchecked") List<EventRecorder> eventList = (List<EventRecorder>) eventController.listAllEvents(req).getBody(); assertEquals(1, eventList.size()); assertEquals(EventStatus.COMPLETED, eventList.get(0).getEventStatusType()); assertEquals(TEAMNAME, eventList.get(0).getTeamName()); teamUser.setTeamName(ALPHATEAMNAME); setSecuirtyContext(ALPHATEAMNAME, USERNAME); events = new ArrayList<>(); events.add(createEvent(ALPHATEAMNAME)); when(eventRepository.findAll()).thenReturn(events); @SuppressWarnings("unchecked") List<EventRecorder> alphaEventList = (List<EventRecorder>) eventController.listAllEvents(req).getBody(); assertEquals(1, alphaEventList.size()); assertEquals(ALPHATEAMNAME, alphaEventList.get(0).getTeamName()); }
@ApiOperation(value = "This API returns list of all Event objects present in Elastic Search for given team", response = ResponseEntity.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Returned all Application Event for given team"), @ApiResponse(code = 401, message = "User is not authorized to view requested object"), @ApiResponse(code = 404, message = "No Event object found for given team") }) @RequestMapping(value = "/api/events/team/", method = RequestMethod.GET, produces = "application/json") public ResponseEntity<Object> listAllEvents(HttpServletRequest request) { final String teamName = userDetailsService.getCurrentTeamForUser(request).getTeamName(); List<EventRecorder> events = Lists.newArrayList(eventService.findAllByTeamName(teamName)); if (events.isEmpty()) { final String error = "No events found for team " + teamName; final MessageWrapper apiError = new MessageWrapper(HttpStatus.NOT_FOUND, error, error); return new ResponseEntity<>(apiError, new HttpHeaders(), apiError.getStatus()); } Map<String, List<EventRecorder>> eventListMap = new HashMap<>(); for (EventRecorder eventRecorder : events) { org.joda.time.DateTime dt = new org.joda.time.DateTime(eventRecorder.field(TIMESTAMP)); eventRecorder.fields().put(TIMESTAMP, dt.toString("yyyy-MM-dd HH:mm:ss.SSS")); String eventTimestamp = eventRecorder.field(TIMESTAMP); if (eventListMap.containsKey(eventTimestamp)) { eventListMap.get(eventTimestamp).add(eventRecorder); } else { List<EventRecorder> eventRecorderList = new ArrayList<>(); eventRecorderList.add(eventRecorder); eventListMap.put(eventTimestamp, eventRecorderList); } } eventListMap.forEach((k, v) -> { v.forEach(eventRecorder -> { eventRecorder.setExecSequence( (null == eventRecorder.getExecSequence() || eventRecorder.getExecSequence().isEmpty()) ? "0" : eventRecorder.getExecSequence()); }); }); eventListMap.forEach((k, v) -> v.sort(Comparator.comparing(EventRecorder::getExecSequence))); List<EventRecorder> finalEventRecorderList = new ArrayList<>(); eventListMap.forEach((k, v) -> { EventRecorder newEvent = new EventRecorder(); int i = 0; for (EventRecorder eventRecorder : v) { String eventStatus = "*** Script Execution O/P for Monkey Strategy: " + eventRecorder.field("monkeyStrategy") + " *** \n"; if (i == 0) { newEvent = eventRecorder; newEvent.setEventStatus(eventStatus + eventRecorder.getEventStatus() + "\n\n"); } else { newEvent.setEventStatus(newEvent.getEventStatus() + eventStatus + eventRecorder.getEventStatus()+ "\n\n"); newEvent.fields().put("monkeyStrategy", newEvent.field("monkeyStrategy") + ", " + eventRecorder.field("monkeyStrategy")); newEvent.fields().put("monkeyType", newEvent.field("monkeyType") + ", " + eventRecorder.field("monkeyType")); newEvent.setExecStatus("Failed".equalsIgnoreCase(eventRecorder.getExecStatus()) ? "Failed" : newEvent.getExecStatus()); } i++; } finalEventRecorderList.add(newEvent); }); return new ResponseEntity<>(finalEventRecorderList, HttpStatus.OK); }
EventRestController { @ApiOperation(value = "This API returns list of all Event objects present in Elastic Search for given team", response = ResponseEntity.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Returned all Application Event for given team"), @ApiResponse(code = 401, message = "User is not authorized to view requested object"), @ApiResponse(code = 404, message = "No Event object found for given team") }) @RequestMapping(value = "/api/events/team/", method = RequestMethod.GET, produces = "application/json") public ResponseEntity<Object> listAllEvents(HttpServletRequest request) { final String teamName = userDetailsService.getCurrentTeamForUser(request).getTeamName(); List<EventRecorder> events = Lists.newArrayList(eventService.findAllByTeamName(teamName)); if (events.isEmpty()) { final String error = "No events found for team " + teamName; final MessageWrapper apiError = new MessageWrapper(HttpStatus.NOT_FOUND, error, error); return new ResponseEntity<>(apiError, new HttpHeaders(), apiError.getStatus()); } Map<String, List<EventRecorder>> eventListMap = new HashMap<>(); for (EventRecorder eventRecorder : events) { org.joda.time.DateTime dt = new org.joda.time.DateTime(eventRecorder.field(TIMESTAMP)); eventRecorder.fields().put(TIMESTAMP, dt.toString("yyyy-MM-dd HH:mm:ss.SSS")); String eventTimestamp = eventRecorder.field(TIMESTAMP); if (eventListMap.containsKey(eventTimestamp)) { eventListMap.get(eventTimestamp).add(eventRecorder); } else { List<EventRecorder> eventRecorderList = new ArrayList<>(); eventRecorderList.add(eventRecorder); eventListMap.put(eventTimestamp, eventRecorderList); } } eventListMap.forEach((k, v) -> { v.forEach(eventRecorder -> { eventRecorder.setExecSequence( (null == eventRecorder.getExecSequence() || eventRecorder.getExecSequence().isEmpty()) ? "0" : eventRecorder.getExecSequence()); }); }); eventListMap.forEach((k, v) -> v.sort(Comparator.comparing(EventRecorder::getExecSequence))); List<EventRecorder> finalEventRecorderList = new ArrayList<>(); eventListMap.forEach((k, v) -> { EventRecorder newEvent = new EventRecorder(); int i = 0; for (EventRecorder eventRecorder : v) { String eventStatus = "*** Script Execution O/P for Monkey Strategy: " + eventRecorder.field("monkeyStrategy") + " *** \n"; if (i == 0) { newEvent = eventRecorder; newEvent.setEventStatus(eventStatus + eventRecorder.getEventStatus() + "\n\n"); } else { newEvent.setEventStatus(newEvent.getEventStatus() + eventStatus + eventRecorder.getEventStatus()+ "\n\n"); newEvent.fields().put("monkeyStrategy", newEvent.field("monkeyStrategy") + ", " + eventRecorder.field("monkeyStrategy")); newEvent.fields().put("monkeyType", newEvent.field("monkeyType") + ", " + eventRecorder.field("monkeyType")); newEvent.setExecStatus("Failed".equalsIgnoreCase(eventRecorder.getExecStatus()) ? "Failed" : newEvent.getExecStatus()); } i++; } finalEventRecorderList.add(newEvent); }); return new ResponseEntity<>(finalEventRecorderList, HttpStatus.OK); } }
EventRestController { @ApiOperation(value = "This API returns list of all Event objects present in Elastic Search for given team", response = ResponseEntity.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Returned all Application Event for given team"), @ApiResponse(code = 401, message = "User is not authorized to view requested object"), @ApiResponse(code = 404, message = "No Event object found for given team") }) @RequestMapping(value = "/api/events/team/", method = RequestMethod.GET, produces = "application/json") public ResponseEntity<Object> listAllEvents(HttpServletRequest request) { final String teamName = userDetailsService.getCurrentTeamForUser(request).getTeamName(); List<EventRecorder> events = Lists.newArrayList(eventService.findAllByTeamName(teamName)); if (events.isEmpty()) { final String error = "No events found for team " + teamName; final MessageWrapper apiError = new MessageWrapper(HttpStatus.NOT_FOUND, error, error); return new ResponseEntity<>(apiError, new HttpHeaders(), apiError.getStatus()); } Map<String, List<EventRecorder>> eventListMap = new HashMap<>(); for (EventRecorder eventRecorder : events) { org.joda.time.DateTime dt = new org.joda.time.DateTime(eventRecorder.field(TIMESTAMP)); eventRecorder.fields().put(TIMESTAMP, dt.toString("yyyy-MM-dd HH:mm:ss.SSS")); String eventTimestamp = eventRecorder.field(TIMESTAMP); if (eventListMap.containsKey(eventTimestamp)) { eventListMap.get(eventTimestamp).add(eventRecorder); } else { List<EventRecorder> eventRecorderList = new ArrayList<>(); eventRecorderList.add(eventRecorder); eventListMap.put(eventTimestamp, eventRecorderList); } } eventListMap.forEach((k, v) -> { v.forEach(eventRecorder -> { eventRecorder.setExecSequence( (null == eventRecorder.getExecSequence() || eventRecorder.getExecSequence().isEmpty()) ? "0" : eventRecorder.getExecSequence()); }); }); eventListMap.forEach((k, v) -> v.sort(Comparator.comparing(EventRecorder::getExecSequence))); List<EventRecorder> finalEventRecorderList = new ArrayList<>(); eventListMap.forEach((k, v) -> { EventRecorder newEvent = new EventRecorder(); int i = 0; for (EventRecorder eventRecorder : v) { String eventStatus = "*** Script Execution O/P for Monkey Strategy: " + eventRecorder.field("monkeyStrategy") + " *** \n"; if (i == 0) { newEvent = eventRecorder; newEvent.setEventStatus(eventStatus + eventRecorder.getEventStatus() + "\n\n"); } else { newEvent.setEventStatus(newEvent.getEventStatus() + eventStatus + eventRecorder.getEventStatus()+ "\n\n"); newEvent.fields().put("monkeyStrategy", newEvent.field("monkeyStrategy") + ", " + eventRecorder.field("monkeyStrategy")); newEvent.fields().put("monkeyType", newEvent.field("monkeyType") + ", " + eventRecorder.field("monkeyType")); newEvent.setExecStatus("Failed".equalsIgnoreCase(eventRecorder.getExecStatus()) ? "Failed" : newEvent.getExecStatus()); } i++; } finalEventRecorderList.add(newEvent); }); return new ResponseEntity<>(finalEventRecorderList, HttpStatus.OK); }  }
EventRestController { @ApiOperation(value = "This API returns list of all Event objects present in Elastic Search for given team", response = ResponseEntity.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Returned all Application Event for given team"), @ApiResponse(code = 401, message = "User is not authorized to view requested object"), @ApiResponse(code = 404, message = "No Event object found for given team") }) @RequestMapping(value = "/api/events/team/", method = RequestMethod.GET, produces = "application/json") public ResponseEntity<Object> listAllEvents(HttpServletRequest request) { final String teamName = userDetailsService.getCurrentTeamForUser(request).getTeamName(); List<EventRecorder> events = Lists.newArrayList(eventService.findAllByTeamName(teamName)); if (events.isEmpty()) { final String error = "No events found for team " + teamName; final MessageWrapper apiError = new MessageWrapper(HttpStatus.NOT_FOUND, error, error); return new ResponseEntity<>(apiError, new HttpHeaders(), apiError.getStatus()); } Map<String, List<EventRecorder>> eventListMap = new HashMap<>(); for (EventRecorder eventRecorder : events) { org.joda.time.DateTime dt = new org.joda.time.DateTime(eventRecorder.field(TIMESTAMP)); eventRecorder.fields().put(TIMESTAMP, dt.toString("yyyy-MM-dd HH:mm:ss.SSS")); String eventTimestamp = eventRecorder.field(TIMESTAMP); if (eventListMap.containsKey(eventTimestamp)) { eventListMap.get(eventTimestamp).add(eventRecorder); } else { List<EventRecorder> eventRecorderList = new ArrayList<>(); eventRecorderList.add(eventRecorder); eventListMap.put(eventTimestamp, eventRecorderList); } } eventListMap.forEach((k, v) -> { v.forEach(eventRecorder -> { eventRecorder.setExecSequence( (null == eventRecorder.getExecSequence() || eventRecorder.getExecSequence().isEmpty()) ? "0" : eventRecorder.getExecSequence()); }); }); eventListMap.forEach((k, v) -> v.sort(Comparator.comparing(EventRecorder::getExecSequence))); List<EventRecorder> finalEventRecorderList = new ArrayList<>(); eventListMap.forEach((k, v) -> { EventRecorder newEvent = new EventRecorder(); int i = 0; for (EventRecorder eventRecorder : v) { String eventStatus = "*** Script Execution O/P for Monkey Strategy: " + eventRecorder.field("monkeyStrategy") + " *** \n"; if (i == 0) { newEvent = eventRecorder; newEvent.setEventStatus(eventStatus + eventRecorder.getEventStatus() + "\n\n"); } else { newEvent.setEventStatus(newEvent.getEventStatus() + eventStatus + eventRecorder.getEventStatus()+ "\n\n"); newEvent.fields().put("monkeyStrategy", newEvent.field("monkeyStrategy") + ", " + eventRecorder.field("monkeyStrategy")); newEvent.fields().put("monkeyType", newEvent.field("monkeyType") + ", " + eventRecorder.field("monkeyType")); newEvent.setExecStatus("Failed".equalsIgnoreCase(eventRecorder.getExecStatus()) ? "Failed" : newEvent.getExecStatus()); } i++; } finalEventRecorderList.add(newEvent); }); return new ResponseEntity<>(finalEventRecorderList, HttpStatus.OK); }  @ApiOperation(value = "This API returns all Event Objects present in Elastic Search", response = ResponseEntity.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Returned all Event Objects"), @ApiResponse(code = 401, message = "User is not authorized to view requested object"), @ApiResponse(code = 404, message = "No Event object found") }) @RequestMapping(value = "/api/events/", method = RequestMethod.GET, produces = "application/json") ResponseEntity<Object> listEvents(); @ApiOperation(value = "This API returns list of all Event objects present in Elastic Search for given team", response = ResponseEntity.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Returned all Application Event for given team"), @ApiResponse(code = 401, message = "User is not authorized to view requested object"), @ApiResponse(code = 404, message = "No Event object found for given team") }) @RequestMapping(value = "/api/events/team/", method = RequestMethod.GET, produces = "application/json") ResponseEntity<Object> listAllEvents(HttpServletRequest request); @ApiOperation(value = "This API returns single Event Objects present in Elastic Search for given Event ID", response = ResponseEntity.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Returned single Event Object for given Event ID"), @ApiResponse(code = 401, message = "User is not authorized to view requested object"), @ApiResponse(code = 404, message = "No Event object found for given Event ID") }) @RequestMapping(value = "/api/events/{id}", method = RequestMethod.GET, produces = "application/json") ResponseEntity<Object> listEvent(HttpServletRequest request, @PathVariable("id") String id); @ApiOperation(value = "This API returns Event Status Objects present in Elastic Search for given Event ID", response = ResponseEntity.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Returned Event Status Object for given Event ID"), @ApiResponse(code = 401, message = "User is not authorized to view requested object"), @ApiResponse(code = 404, message = "No Event Status object found for given Event ID") }) @RequestMapping(value = "/api/events/status/{id}", method = RequestMethod.GET, produces = "application/json") ResponseEntity<Object> getstatusupdateforevent(HttpServletRequest request, @PathVariable("id") String id); @ApiOperation(value = "This API returns count of Event objects available in Elastic Search for given team name", response = ResponseEntity.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Returned count of Event objects for given team name"), @ApiResponse(code = 401, message = "User is not authorized to view requested object"), @ApiResponse(code = 404, message = "The resource trying to reach is not found") }) @RequestMapping(value = "/api/events/count/", method = RequestMethod.GET, produces = "application/json") ResponseEntity<Object> countByTeamName(HttpServletRequest request); @ApiOperation(value = "This API returns Latest Events per Scenario present in Elastic Search for given App Name", response = ResponseEntity.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Returned Latest Events per Scenario for given App Name"), @ApiResponse(code = 401, message = "User is not authorized to view requested object"), @ApiResponse(code = 404, message = "No Event object found for given App Name") }) @RequestMapping(value = "/api/events/latestevent/{applicationName}", method = RequestMethod.GET, produces = "application/json") ResponseEntity<Object> listLatestEventsByAppName(HttpServletRequest request,
			@PathVariable("applicationName") String applicationName); }
EventRestController { @ApiOperation(value = "This API returns list of all Event objects present in Elastic Search for given team", response = ResponseEntity.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Returned all Application Event for given team"), @ApiResponse(code = 401, message = "User is not authorized to view requested object"), @ApiResponse(code = 404, message = "No Event object found for given team") }) @RequestMapping(value = "/api/events/team/", method = RequestMethod.GET, produces = "application/json") public ResponseEntity<Object> listAllEvents(HttpServletRequest request) { final String teamName = userDetailsService.getCurrentTeamForUser(request).getTeamName(); List<EventRecorder> events = Lists.newArrayList(eventService.findAllByTeamName(teamName)); if (events.isEmpty()) { final String error = "No events found for team " + teamName; final MessageWrapper apiError = new MessageWrapper(HttpStatus.NOT_FOUND, error, error); return new ResponseEntity<>(apiError, new HttpHeaders(), apiError.getStatus()); } Map<String, List<EventRecorder>> eventListMap = new HashMap<>(); for (EventRecorder eventRecorder : events) { org.joda.time.DateTime dt = new org.joda.time.DateTime(eventRecorder.field(TIMESTAMP)); eventRecorder.fields().put(TIMESTAMP, dt.toString("yyyy-MM-dd HH:mm:ss.SSS")); String eventTimestamp = eventRecorder.field(TIMESTAMP); if (eventListMap.containsKey(eventTimestamp)) { eventListMap.get(eventTimestamp).add(eventRecorder); } else { List<EventRecorder> eventRecorderList = new ArrayList<>(); eventRecorderList.add(eventRecorder); eventListMap.put(eventTimestamp, eventRecorderList); } } eventListMap.forEach((k, v) -> { v.forEach(eventRecorder -> { eventRecorder.setExecSequence( (null == eventRecorder.getExecSequence() || eventRecorder.getExecSequence().isEmpty()) ? "0" : eventRecorder.getExecSequence()); }); }); eventListMap.forEach((k, v) -> v.sort(Comparator.comparing(EventRecorder::getExecSequence))); List<EventRecorder> finalEventRecorderList = new ArrayList<>(); eventListMap.forEach((k, v) -> { EventRecorder newEvent = new EventRecorder(); int i = 0; for (EventRecorder eventRecorder : v) { String eventStatus = "*** Script Execution O/P for Monkey Strategy: " + eventRecorder.field("monkeyStrategy") + " *** \n"; if (i == 0) { newEvent = eventRecorder; newEvent.setEventStatus(eventStatus + eventRecorder.getEventStatus() + "\n\n"); } else { newEvent.setEventStatus(newEvent.getEventStatus() + eventStatus + eventRecorder.getEventStatus()+ "\n\n"); newEvent.fields().put("monkeyStrategy", newEvent.field("monkeyStrategy") + ", " + eventRecorder.field("monkeyStrategy")); newEvent.fields().put("monkeyType", newEvent.field("monkeyType") + ", " + eventRecorder.field("monkeyType")); newEvent.setExecStatus("Failed".equalsIgnoreCase(eventRecorder.getExecStatus()) ? "Failed" : newEvent.getExecStatus()); } i++; } finalEventRecorderList.add(newEvent); }); return new ResponseEntity<>(finalEventRecorderList, HttpStatus.OK); }  @ApiOperation(value = "This API returns all Event Objects present in Elastic Search", response = ResponseEntity.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Returned all Event Objects"), @ApiResponse(code = 401, message = "User is not authorized to view requested object"), @ApiResponse(code = 404, message = "No Event object found") }) @RequestMapping(value = "/api/events/", method = RequestMethod.GET, produces = "application/json") ResponseEntity<Object> listEvents(); @ApiOperation(value = "This API returns list of all Event objects present in Elastic Search for given team", response = ResponseEntity.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Returned all Application Event for given team"), @ApiResponse(code = 401, message = "User is not authorized to view requested object"), @ApiResponse(code = 404, message = "No Event object found for given team") }) @RequestMapping(value = "/api/events/team/", method = RequestMethod.GET, produces = "application/json") ResponseEntity<Object> listAllEvents(HttpServletRequest request); @ApiOperation(value = "This API returns single Event Objects present in Elastic Search for given Event ID", response = ResponseEntity.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Returned single Event Object for given Event ID"), @ApiResponse(code = 401, message = "User is not authorized to view requested object"), @ApiResponse(code = 404, message = "No Event object found for given Event ID") }) @RequestMapping(value = "/api/events/{id}", method = RequestMethod.GET, produces = "application/json") ResponseEntity<Object> listEvent(HttpServletRequest request, @PathVariable("id") String id); @ApiOperation(value = "This API returns Event Status Objects present in Elastic Search for given Event ID", response = ResponseEntity.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Returned Event Status Object for given Event ID"), @ApiResponse(code = 401, message = "User is not authorized to view requested object"), @ApiResponse(code = 404, message = "No Event Status object found for given Event ID") }) @RequestMapping(value = "/api/events/status/{id}", method = RequestMethod.GET, produces = "application/json") ResponseEntity<Object> getstatusupdateforevent(HttpServletRequest request, @PathVariable("id") String id); @ApiOperation(value = "This API returns count of Event objects available in Elastic Search for given team name", response = ResponseEntity.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Returned count of Event objects for given team name"), @ApiResponse(code = 401, message = "User is not authorized to view requested object"), @ApiResponse(code = 404, message = "The resource trying to reach is not found") }) @RequestMapping(value = "/api/events/count/", method = RequestMethod.GET, produces = "application/json") ResponseEntity<Object> countByTeamName(HttpServletRequest request); @ApiOperation(value = "This API returns Latest Events per Scenario present in Elastic Search for given App Name", response = ResponseEntity.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Returned Latest Events per Scenario for given App Name"), @ApiResponse(code = 401, message = "User is not authorized to view requested object"), @ApiResponse(code = 404, message = "No Event object found for given App Name") }) @RequestMapping(value = "/api/events/latestevent/{applicationName}", method = RequestMethod.GET, produces = "application/json") ResponseEntity<Object> listLatestEventsByAppName(HttpServletRequest request,
			@PathVariable("applicationName") String applicationName);  }