@Test public void doesntFireWhenPatientTemplateIsDeleted() throws ComponentLookupException { XWikiDocument doc = mock(XWikiDocument.class); when(doc.getDocumentReference()).thenReturn(new DocumentReference("instance", "PhenoTips", "PatientTemplate")); DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class); PatientRepository repo = this.mocker.getInstance(PatientRepository.class); UserManager um = this.mocker.getInstance(UserManager.class); ObservationManager om = this.mocker.getInstance(ObservationManager.class); this.mocker.getComponentUnderTest().onEvent(new DocumentDeletingEvent(), doc, null); Mockito.verifyNoMoreInteractions(dab, repo, um, om); }
@Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; if (doc == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } XWikiDocument odoc; try { odoc = (XWikiDocument) this.dab.getDocument(doc.getDocumentReference()); } catch (Exception e) { return; } BaseObject patientRecordObj = odoc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null) { return; } Patient patient = this.repo.load(odoc); User user = this.userManager.getCurrentUser(); CancelableEvent patientEvent = new PatientDeletingEvent(patient, user); this.observationManager.notify(patientEvent, odoc); if (patientEvent.isCanceled()) { } }
PatientDeletingEventSource implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; if (doc == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } XWikiDocument odoc; try { odoc = (XWikiDocument) this.dab.getDocument(doc.getDocumentReference()); } catch (Exception e) { return; } BaseObject patientRecordObj = odoc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null) { return; } Patient patient = this.repo.load(odoc); User user = this.userManager.getCurrentUser(); CancelableEvent patientEvent = new PatientDeletingEvent(patient, user); this.observationManager.notify(patientEvent, odoc); if (patientEvent.isCanceled()) { } } }
PatientDeletingEventSource implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; if (doc == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } XWikiDocument odoc; try { odoc = (XWikiDocument) this.dab.getDocument(doc.getDocumentReference()); } catch (Exception e) { return; } BaseObject patientRecordObj = odoc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null) { return; } Patient patient = this.repo.load(odoc); User user = this.userManager.getCurrentUser(); CancelableEvent patientEvent = new PatientDeletingEvent(patient, user); this.observationManager.notify(patientEvent, odoc); if (patientEvent.isCanceled()) { } }  }
PatientDeletingEventSource implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; if (doc == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } XWikiDocument odoc; try { odoc = (XWikiDocument) this.dab.getDocument(doc.getDocumentReference()); } catch (Exception e) { return; } BaseObject patientRecordObj = odoc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null) { return; } Patient patient = this.repo.load(odoc); User user = this.userManager.getCurrentUser(); CancelableEvent patientEvent = new PatientDeletingEvent(patient, user); this.observationManager.notify(patientEvent, odoc); if (patientEvent.isCanceled()) { } }  @Override String getName(); @Override List<Event> getEvents(); @Override void onEvent(Event event, Object source, Object data); }
PatientDeletingEventSource implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; if (doc == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } XWikiDocument odoc; try { odoc = (XWikiDocument) this.dab.getDocument(doc.getDocumentReference()); } catch (Exception e) { return; } BaseObject patientRecordObj = odoc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null) { return; } Patient patient = this.repo.load(odoc); User user = this.userManager.getCurrentUser(); CancelableEvent patientEvent = new PatientDeletingEvent(patient, user); this.observationManager.notify(patientEvent, odoc); if (patientEvent.isCanceled()) { } }  @Override String getName(); @Override List<Event> getEvents(); @Override void onEvent(Event event, Object source, Object data);  }