@Test public void doesntFireWhenPatientTemplateIsDeleted() throws ComponentLookupException { XWikiDocument doc = mock(XWikiDocument.class); XWikiDocument odoc = mock(XWikiDocument.class); when(doc.getOriginalDocument()).thenReturn(odoc); when(odoc.getXObject(Patient.CLASS_REFERENCE)).thenReturn(mock(BaseObject.class)); when(doc.getDocumentReference()).thenReturn(new DocumentReference("instance", "PhenoTips", "PatientTemplate")); 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 DocumentDeletedEvent(), doc, null); Mockito.verifyNoMoreInteractions(repo, um, om); }
@Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; if (doc == null || doc.getOriginalDocument() == null) { return; } XWikiDocument odoc = doc.getOriginalDocument(); BaseObject patientRecordObj = odoc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } Patient patient = this.repo.load(odoc); User user = this.userManager.getCurrentUser(); this.observationManager.notify(new PatientDeletedEvent(patient, user), odoc); }
PatientDeletedEventSource implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; if (doc == null || doc.getOriginalDocument() == null) { return; } XWikiDocument odoc = doc.getOriginalDocument(); BaseObject patientRecordObj = odoc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } Patient patient = this.repo.load(odoc); User user = this.userManager.getCurrentUser(); this.observationManager.notify(new PatientDeletedEvent(patient, user), odoc); } }
PatientDeletedEventSource implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; if (doc == null || doc.getOriginalDocument() == null) { return; } XWikiDocument odoc = doc.getOriginalDocument(); BaseObject patientRecordObj = odoc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } Patient patient = this.repo.load(odoc); User user = this.userManager.getCurrentUser(); this.observationManager.notify(new PatientDeletedEvent(patient, user), odoc); }  }
PatientDeletedEventSource implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; if (doc == null || doc.getOriginalDocument() == null) { return; } XWikiDocument odoc = doc.getOriginalDocument(); BaseObject patientRecordObj = odoc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } Patient patient = this.repo.load(odoc); User user = this.userManager.getCurrentUser(); this.observationManager.notify(new PatientDeletedEvent(patient, user), odoc); }  @Override String getName(); @Override List<Event> getEvents(); @Override void onEvent(Event event, Object source, Object data); }
PatientDeletedEventSource implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; if (doc == null || doc.getOriginalDocument() == null) { return; } XWikiDocument odoc = doc.getOriginalDocument(); BaseObject patientRecordObj = odoc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } Patient patient = this.repo.load(odoc); User user = this.userManager.getCurrentUser(); this.observationManager.notify(new PatientDeletedEvent(patient, user), odoc); }  @Override String getName(); @Override List<Event> getEvents(); @Override void onEvent(Event event, Object source, Object data);  }