@Test public void onEventWithNonGroup() throws ComponentLookupException, XWikiException { Utils.setComponentManager(this.mocker); DocumentReference docReference = new DocumentReference("xwiki", "Groups", "Group1"); Provider<XWikiContext> contextProvider = this.mocker.getInstance(XWikiContext.TYPE_PROVIDER); XWikiContext context = mock(XWikiContext.class); when(contextProvider.get()).thenReturn(context); XWikiDocument doc = mock(XWikiDocument.class); when(doc.getXObject(Group.CLASS_REFERENCE)).thenReturn(null); XWikiDocument newDoc = mock(XWikiDocument.class); when(newDoc.getOriginalDocument()).thenReturn(doc); this.mocker.getComponentUnderTest().onEvent(new DocumentDeletingEvent(docReference), newDoc, context); Mockito.verifyZeroInteractions(context); Mockito.verify(doc).getXObject(Group.CLASS_REFERENCE); Mockito.verifyNoMoreInteractions(doc); }
@Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = ((XWikiDocument) source).getOriginalDocument(); if (doc == null || doc.getXObject(Group.CLASS_REFERENCE) == null) { return; } XWikiContext context = this.xcontextProvider.get(); DocumentReference docReference = doc.getDocumentReference(); DocumentReference adminsReference = new DocumentReference(docReference.getName() + " Administrators", docReference.getLastSpaceReference()); DocumentReference managersReference = new DocumentReference(docReference.getName() + " Managers", docReference.getLastSpaceReference()); XWiki xwiki = context.getWiki(); try { XWikiDocument adminsDoc = xwiki.getDocument(adminsReference, context); xwiki.deleteDocument(adminsDoc, context); XWikiDocument managersDoc = xwiki.getDocument(managersReference, context); xwiki.deleteDocument(managersDoc, context); } catch (XWikiException ex) { this.logger.error("Failed to delete administrative or managers group for [{}]: {}", docReference, ex.getMessage(), ex); } }
GroupCleanupEventListener implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = ((XWikiDocument) source).getOriginalDocument(); if (doc == null || doc.getXObject(Group.CLASS_REFERENCE) == null) { return; } XWikiContext context = this.xcontextProvider.get(); DocumentReference docReference = doc.getDocumentReference(); DocumentReference adminsReference = new DocumentReference(docReference.getName() + " Administrators", docReference.getLastSpaceReference()); DocumentReference managersReference = new DocumentReference(docReference.getName() + " Managers", docReference.getLastSpaceReference()); XWiki xwiki = context.getWiki(); try { XWikiDocument adminsDoc = xwiki.getDocument(adminsReference, context); xwiki.deleteDocument(adminsDoc, context); XWikiDocument managersDoc = xwiki.getDocument(managersReference, context); xwiki.deleteDocument(managersDoc, context); } catch (XWikiException ex) { this.logger.error("Failed to delete administrative or managers group for [{}]: {}", docReference, ex.getMessage(), ex); } } }
GroupCleanupEventListener implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = ((XWikiDocument) source).getOriginalDocument(); if (doc == null || doc.getXObject(Group.CLASS_REFERENCE) == null) { return; } XWikiContext context = this.xcontextProvider.get(); DocumentReference docReference = doc.getDocumentReference(); DocumentReference adminsReference = new DocumentReference(docReference.getName() + " Administrators", docReference.getLastSpaceReference()); DocumentReference managersReference = new DocumentReference(docReference.getName() + " Managers", docReference.getLastSpaceReference()); XWiki xwiki = context.getWiki(); try { XWikiDocument adminsDoc = xwiki.getDocument(adminsReference, context); xwiki.deleteDocument(adminsDoc, context); XWikiDocument managersDoc = xwiki.getDocument(managersReference, context); xwiki.deleteDocument(managersDoc, context); } catch (XWikiException ex) { this.logger.error("Failed to delete administrative or managers group for [{}]: {}", docReference, ex.getMessage(), ex); } }  }
GroupCleanupEventListener implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = ((XWikiDocument) source).getOriginalDocument(); if (doc == null || doc.getXObject(Group.CLASS_REFERENCE) == null) { return; } XWikiContext context = this.xcontextProvider.get(); DocumentReference docReference = doc.getDocumentReference(); DocumentReference adminsReference = new DocumentReference(docReference.getName() + " Administrators", docReference.getLastSpaceReference()); DocumentReference managersReference = new DocumentReference(docReference.getName() + " Managers", docReference.getLastSpaceReference()); XWiki xwiki = context.getWiki(); try { XWikiDocument adminsDoc = xwiki.getDocument(adminsReference, context); xwiki.deleteDocument(adminsDoc, context); XWikiDocument managersDoc = xwiki.getDocument(managersReference, context); xwiki.deleteDocument(managersDoc, context); } catch (XWikiException ex) { this.logger.error("Failed to delete administrative or managers group for [{}]: {}", docReference, ex.getMessage(), ex); } }  @Override String getName(); @Override List<Event> getEvents(); @Override void onEvent(Event event, Object source, Object data); }
GroupCleanupEventListener implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = ((XWikiDocument) source).getOriginalDocument(); if (doc == null || doc.getXObject(Group.CLASS_REFERENCE) == null) { return; } XWikiContext context = this.xcontextProvider.get(); DocumentReference docReference = doc.getDocumentReference(); DocumentReference adminsReference = new DocumentReference(docReference.getName() + " Administrators", docReference.getLastSpaceReference()); DocumentReference managersReference = new DocumentReference(docReference.getName() + " Managers", docReference.getLastSpaceReference()); XWiki xwiki = context.getWiki(); try { XWikiDocument adminsDoc = xwiki.getDocument(adminsReference, context); xwiki.deleteDocument(adminsDoc, context); XWikiDocument managersDoc = xwiki.getDocument(managersReference, context); xwiki.deleteDocument(managersDoc, context); } catch (XWikiException ex) { this.logger.error("Failed to delete administrative or managers group for [{}]: {}", docReference, ex.getMessage(), ex); } }  @Override String getName(); @Override List<Event> getEvents(); @Override void onEvent(Event event, Object source, Object data);  }