@Test public void onDocumentDeletedEvent() throws Exception { XWikiDocument document = mock(XWikiDocument.class); XWikiDocument originalDocument = mock(XWikiDocument.class); when(document.getOriginalDocument()).thenReturn(originalDocument); Event event = new DocumentDeletedEvent(); List<BaseObject> objects = new ArrayList<>(); BaseObject object = mock(BaseObject.class); objects.add(object); when(originalDocument.getXObjects(WikiDescriptorListener.SERVER_CLASS)).thenReturn(objects); DocumentReference documentReference = new DocumentReference("mainWiki", "XWiki", "XWikiServerSubwikiA"); when(originalDocument.getDocumentReference()).thenReturn(documentReference); when(wikiDescriptorDocumentHelper.getWikiIdFromDocumentReference(documentReference)).thenReturn("subwikia"); DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("subwikia", "alias"); when(cache.getFromId("subwikia")).thenReturn(descriptor); mocker.getComponentUnderTest().onEvent(event, document, null); verify(cache).remove(descriptor.getId(), descriptor.getAliases()); verify(cache, never()).add(any(DefaultWikiDescriptor.class)); }
@Override public void onEvent(Event event, Object source, Object data) { XWikiDocument document = (XWikiDocument) source; if (event instanceof DocumentDeletedEvent || event instanceof DocumentUpdatedEvent) { removeExistingDescriptor(document.getOriginalDocument()); } List<BaseObject> serverClassObjects = document.getXObjects(SERVER_CLASS); if (serverClassObjects != null && !serverClassObjects.isEmpty()) { DefaultWikiDescriptor descriptor = this.builder.buildDescriptorObject(serverClassObjects, document); if (descriptor != null) { this.cache.add(descriptor); this.cache.setWikiIds(null); } } }
WikiDescriptorListener implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument document = (XWikiDocument) source; if (event instanceof DocumentDeletedEvent || event instanceof DocumentUpdatedEvent) { removeExistingDescriptor(document.getOriginalDocument()); } List<BaseObject> serverClassObjects = document.getXObjects(SERVER_CLASS); if (serverClassObjects != null && !serverClassObjects.isEmpty()) { DefaultWikiDescriptor descriptor = this.builder.buildDescriptorObject(serverClassObjects, document); if (descriptor != null) { this.cache.add(descriptor); this.cache.setWikiIds(null); } } } }
WikiDescriptorListener implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument document = (XWikiDocument) source; if (event instanceof DocumentDeletedEvent || event instanceof DocumentUpdatedEvent) { removeExistingDescriptor(document.getOriginalDocument()); } List<BaseObject> serverClassObjects = document.getXObjects(SERVER_CLASS); if (serverClassObjects != null && !serverClassObjects.isEmpty()) { DefaultWikiDescriptor descriptor = this.builder.buildDescriptorObject(serverClassObjects, document); if (descriptor != null) { this.cache.add(descriptor); this.cache.setWikiIds(null); } } }  }
WikiDescriptorListener implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument document = (XWikiDocument) source; if (event instanceof DocumentDeletedEvent || event instanceof DocumentUpdatedEvent) { removeExistingDescriptor(document.getOriginalDocument()); } List<BaseObject> serverClassObjects = document.getXObjects(SERVER_CLASS); if (serverClassObjects != null && !serverClassObjects.isEmpty()) { DefaultWikiDescriptor descriptor = this.builder.buildDescriptorObject(serverClassObjects, document); if (descriptor != null) { this.cache.add(descriptor); this.cache.setWikiIds(null); } } }  @Override String getName(); @Override List<Event> getEvents(); @Override void onEvent(Event event, Object source, Object data); }
WikiDescriptorListener implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument document = (XWikiDocument) source; if (event instanceof DocumentDeletedEvent || event instanceof DocumentUpdatedEvent) { removeExistingDescriptor(document.getOriginalDocument()); } List<BaseObject> serverClassObjects = document.getXObjects(SERVER_CLASS); if (serverClassObjects != null && !serverClassObjects.isEmpty()) { DefaultWikiDescriptor descriptor = this.builder.buildDescriptorObject(serverClassObjects, document); if (descriptor != null) { this.cache.add(descriptor); this.cache.setWikiIds(null); } } }  @Override String getName(); @Override List<Event> getEvents(); @Override void onEvent(Event event, Object source, Object data);  }