@Test public void testRunReportScript() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, ADKException { Map<Class<? extends SIFDataObject>, List<EventAction>> testMap; testMap = new LinkedHashMap<Class<? extends SIFDataObject>, List<EventAction>>(); List<EventAction> addChangeDeleteEventActionList = new ArrayList<EventAction>(); addChangeDeleteEventActionList.add(EventAction.ADD); addChangeDeleteEventActionList.add(EventAction.CHANGE); addChangeDeleteEventActionList.add(EventAction.DELETE); testMap.put(LEAInfo.class, addChangeDeleteEventActionList); testMap.put(SchoolInfo.class, addChangeDeleteEventActionList); testMap.put(StudentPersonal.class, addChangeDeleteEventActionList); testMap.put(StudentLEARelationship.class, addChangeDeleteEventActionList); testMap.put(StudentSchoolEnrollment.class, addChangeDeleteEventActionList); String[] scriptArray = { "LEAInfoAdd", "LEAInfoChange", "LEAInfoDelete", "SchoolInfoAdd", "SchoolInfoChange", "SchoolInfoDelete", "StudentPersonalAdd", "StudentPersonalChange", "StudentPersonalDelete", "StudentLEARelationshipAdd", "StudentLEARelationshipChange", "StudentLEARelationshipDelete", "StudentSchoolEnrollmentAdd", "StudentSchoolEnrollmentChange", "StudentSchoolEnrollmentDelete", "StaffPersonalAdd", "StaffPersonalChange", "StaffPersonalDelete", "EmployeePersonalAdd", "EmployeePersonalChange", "EmployeePersonalDelete", "StaffAssignmentAdd", "StaffAssignmentChange", "StaffAssignmentDelete", "EmploymentRecordAdd", "EmploymentRecordChange", "EmploymentRecordDelete", "EmployeeAssignmentAdd", "EmployeeAssignmentChange", "EmployeeAssignmentDelete" }; String script = ""; for (String item : scriptArray) { script += item + ","; } long waitTime = 0; List<Event> eventsSent = eventReporter.runReportScript(script, waitTime); Mockito.verify(zone, Mockito.times(scriptArray.length)).reportEvent(Mockito.any(Event.class)); Assert.assertEquals(scriptArray.length, eventsSent.size()); int index = 0; for (Class<? extends SIFDataObject> expectedClass : testMap.keySet()) { for (EventAction expectedAction : testMap.get(expectedClass)) { Event event = eventsSent.get(index++); checkScriptedEvent(event, expectedClass, expectedAction); } } }
public List<Event> runReportScript(String script, long waitTime) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { List<Event> eventsSent = new ArrayList<Event>(); LOG.info("Wait time (ms): " + waitTime); String[] eventDescriptors = script.split(","); for (String descriptor : eventDescriptors) { GeneratorScriptMethod scriptMethod = GeneratorScriptMethod.get(descriptor); if (scriptMethod == null) { LOG.error("Error retrieving scriptMethod - " + descriptor); } else { LOG.info("Executing script method - " + scriptMethod.toString()); try { Event eventSent = scriptMethod.execute(this); eventsSent.add(eventSent); Thread.sleep(waitTime); } catch (SecurityException e) { LOG.error("Failed to execute method for descriptor " + descriptor, e); } catch (NoSuchMethodException e) { LOG.error("Failed to execute method for descriptor " + descriptor, e); } catch (InterruptedException e) { LOG.error("Exception while sleeping", e); } } } return eventsSent; }
EventReporter implements Publisher { public List<Event> runReportScript(String script, long waitTime) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { List<Event> eventsSent = new ArrayList<Event>(); LOG.info("Wait time (ms): " + waitTime); String[] eventDescriptors = script.split(","); for (String descriptor : eventDescriptors) { GeneratorScriptMethod scriptMethod = GeneratorScriptMethod.get(descriptor); if (scriptMethod == null) { LOG.error("Error retrieving scriptMethod - " + descriptor); } else { LOG.info("Executing script method - " + scriptMethod.toString()); try { Event eventSent = scriptMethod.execute(this); eventsSent.add(eventSent); Thread.sleep(waitTime); } catch (SecurityException e) { LOG.error("Failed to execute method for descriptor " + descriptor, e); } catch (NoSuchMethodException e) { LOG.error("Failed to execute method for descriptor " + descriptor, e); } catch (InterruptedException e) { LOG.error("Exception while sleeping", e); } } } return eventsSent; } }
EventReporter implements Publisher { public List<Event> runReportScript(String script, long waitTime) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { List<Event> eventsSent = new ArrayList<Event>(); LOG.info("Wait time (ms): " + waitTime); String[] eventDescriptors = script.split(","); for (String descriptor : eventDescriptors) { GeneratorScriptMethod scriptMethod = GeneratorScriptMethod.get(descriptor); if (scriptMethod == null) { LOG.error("Error retrieving scriptMethod - " + descriptor); } else { LOG.info("Executing script method - " + scriptMethod.toString()); try { Event eventSent = scriptMethod.execute(this); eventsSent.add(eventSent); Thread.sleep(waitTime); } catch (SecurityException e) { LOG.error("Failed to execute method for descriptor " + descriptor, e); } catch (NoSuchMethodException e) { LOG.error("Failed to execute method for descriptor " + descriptor, e); } catch (InterruptedException e) { LOG.error("Exception while sleeping", e); } } } return eventsSent; } EventReporter(Zone zone); }
EventReporter implements Publisher { public List<Event> runReportScript(String script, long waitTime) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { List<Event> eventsSent = new ArrayList<Event>(); LOG.info("Wait time (ms): " + waitTime); String[] eventDescriptors = script.split(","); for (String descriptor : eventDescriptors) { GeneratorScriptMethod scriptMethod = GeneratorScriptMethod.get(descriptor); if (scriptMethod == null) { LOG.error("Error retrieving scriptMethod - " + descriptor); } else { LOG.info("Executing script method - " + scriptMethod.toString()); try { Event eventSent = scriptMethod.execute(this); eventsSent.add(eventSent); Thread.sleep(waitTime); } catch (SecurityException e) { LOG.error("Failed to execute method for descriptor " + descriptor, e); } catch (NoSuchMethodException e) { LOG.error("Failed to execute method for descriptor " + descriptor, e); } catch (InterruptedException e) { LOG.error("Exception while sleeping", e); } } } return eventsSent; } EventReporter(Zone zone); static void main(String[] args); List<Event> runReportScript(String script, long waitTime); Event reportLeaInfoEvent(EventAction action); Event reportSchoolInfoEvent(EventAction action); Event reportStudentPersonalEvent(EventAction action); Event reportStudentLeaRelationshipEvent(EventAction action); Event reportStudentSchoolEnrollmentEvent(EventAction action); Event reportStaffPersonalEvent(EventAction action); Event reportEmployeePersonalEvent(EventAction action); Event reportStaffAssignmentEvent(EventAction action); Event reportEmploymentRecordEvent(EventAction action); Event reportEmployeeAssignmentEvent(EventAction action); Event reportEvent(String messageFile, String eventAction); @Override void onRequest(DataObjectOutputStream out, Query query, Zone zone, MessageInfo info); }
EventReporter implements Publisher { public List<Event> runReportScript(String script, long waitTime) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { List<Event> eventsSent = new ArrayList<Event>(); LOG.info("Wait time (ms): " + waitTime); String[] eventDescriptors = script.split(","); for (String descriptor : eventDescriptors) { GeneratorScriptMethod scriptMethod = GeneratorScriptMethod.get(descriptor); if (scriptMethod == null) { LOG.error("Error retrieving scriptMethod - " + descriptor); } else { LOG.info("Executing script method - " + scriptMethod.toString()); try { Event eventSent = scriptMethod.execute(this); eventsSent.add(eventSent); Thread.sleep(waitTime); } catch (SecurityException e) { LOG.error("Failed to execute method for descriptor " + descriptor, e); } catch (NoSuchMethodException e) { LOG.error("Failed to execute method for descriptor " + descriptor, e); } catch (InterruptedException e) { LOG.error("Exception while sleeping", e); } } } return eventsSent; } EventReporter(Zone zone); static void main(String[] args); List<Event> runReportScript(String script, long waitTime); Event reportLeaInfoEvent(EventAction action); Event reportSchoolInfoEvent(EventAction action); Event reportStudentPersonalEvent(EventAction action); Event reportStudentLeaRelationshipEvent(EventAction action); Event reportStudentSchoolEnrollmentEvent(EventAction action); Event reportStaffPersonalEvent(EventAction action); Event reportEmployeePersonalEvent(EventAction action); Event reportStaffAssignmentEvent(EventAction action); Event reportEmploymentRecordEvent(EventAction action); Event reportEmployeeAssignmentEvent(EventAction action); Event reportEvent(String messageFile, String eventAction); @Override void onRequest(DataObjectOutputStream out, Query query, Zone zone, MessageInfo info); static final Logger LOG; }