@Test public void onApplicationReady() throws Exception { when(this.wikiDescriptorManagerProvider.get().getCurrentWikiId()).thenReturn("test"); XarInstalledExtension xarInstalledExtension = mock(XarInstalledExtension.class); when(this.xarRepositoryProvider.get().getInstalledExtensions("wiki:test")) .thenReturn(Collections.singleton(xarInstalledExtension)); XarPackage xarPackage = mock(XarPackage.class); when(xarInstalledExtension.getXarPackage()).thenReturn(xarPackage); XarEntry xarEntry = mock(XarEntry.class); when(xarPackage.getEntries()).thenReturn(Collections.singleton(xarEntry)); DocumentReference documentReference = new DocumentReference("test", "Some", "Page"); DocumentReference documentReferenceWithLocale = new DocumentReference(documentReference, Locale.FRENCH); when(this.packagerProvider.get().getDocumentReferences(eq(Collections.singleton(xarEntry)), any(PackageConfiguration.class))).thenReturn(Collections.singletonList(documentReferenceWithLocale)); when(this.customizationDetectorProvider.get().isCustomized(documentReferenceWithLocale)).thenReturn(true); this.listener.onEvent(new ApplicationReadyEvent(), null, null); verify(this.tree).addExtensionPage(documentReference); verify(this.tree).setCustomizedExtensionPage(documentReferenceWithLocale, true); }
@SuppressWarnings("unchecked") @Override public void onEvent(Event event, Object source, Object data) { if (event instanceof DocumentUpdatedEvent) { XWikiDocument document = (XWikiDocument) source; if (this.tree.isExtensionPage(document.getDocumentReference())) { updateCustomizedFlag(document.getDocumentReferenceWithLocale()); } } else if (event instanceof ApplicationReadyEvent) { addExtensionDocuments(this.wikiDescriptorManagerProvider.get().getCurrentWikiId()); } else if (event instanceof WikiReadyEvent) { addExtensionDocuments((String) source); } else if (event instanceof XarExtensionInstalledEvent) { addExtensionDocuments((ExtensionEvent) event, (InstalledExtension) source); } else if (event instanceof XarExtensionUninstalledEvent) { removeExtensionDocuments((ExtensionEvent) event, (InstalledExtension) source); } else if (event instanceof XarExtensionUpgradedEvent) { ((Collection<InstalledExtension>) data).stream().forEach( oldInstalledExtension -> removeExtensionDocuments((ExtensionEvent) event, oldInstalledExtension)); addExtensionDocuments((ExtensionEvent) event, (InstalledExtension) source); } }
InstalledExtensionDocumentListener extends AbstractEventListener { @SuppressWarnings("unchecked") @Override public void onEvent(Event event, Object source, Object data) { if (event instanceof DocumentUpdatedEvent) { XWikiDocument document = (XWikiDocument) source; if (this.tree.isExtensionPage(document.getDocumentReference())) { updateCustomizedFlag(document.getDocumentReferenceWithLocale()); } } else if (event instanceof ApplicationReadyEvent) { addExtensionDocuments(this.wikiDescriptorManagerProvider.get().getCurrentWikiId()); } else if (event instanceof WikiReadyEvent) { addExtensionDocuments((String) source); } else if (event instanceof XarExtensionInstalledEvent) { addExtensionDocuments((ExtensionEvent) event, (InstalledExtension) source); } else if (event instanceof XarExtensionUninstalledEvent) { removeExtensionDocuments((ExtensionEvent) event, (InstalledExtension) source); } else if (event instanceof XarExtensionUpgradedEvent) { ((Collection<InstalledExtension>) data).stream().forEach( oldInstalledExtension -> removeExtensionDocuments((ExtensionEvent) event, oldInstalledExtension)); addExtensionDocuments((ExtensionEvent) event, (InstalledExtension) source); } } }
InstalledExtensionDocumentListener extends AbstractEventListener { @SuppressWarnings("unchecked") @Override public void onEvent(Event event, Object source, Object data) { if (event instanceof DocumentUpdatedEvent) { XWikiDocument document = (XWikiDocument) source; if (this.tree.isExtensionPage(document.getDocumentReference())) { updateCustomizedFlag(document.getDocumentReferenceWithLocale()); } } else if (event instanceof ApplicationReadyEvent) { addExtensionDocuments(this.wikiDescriptorManagerProvider.get().getCurrentWikiId()); } else if (event instanceof WikiReadyEvent) { addExtensionDocuments((String) source); } else if (event instanceof XarExtensionInstalledEvent) { addExtensionDocuments((ExtensionEvent) event, (InstalledExtension) source); } else if (event instanceof XarExtensionUninstalledEvent) { removeExtensionDocuments((ExtensionEvent) event, (InstalledExtension) source); } else if (event instanceof XarExtensionUpgradedEvent) { ((Collection<InstalledExtension>) data).stream().forEach( oldInstalledExtension -> removeExtensionDocuments((ExtensionEvent) event, oldInstalledExtension)); addExtensionDocuments((ExtensionEvent) event, (InstalledExtension) source); } } InstalledExtensionDocumentListener(); }
InstalledExtensionDocumentListener extends AbstractEventListener { @SuppressWarnings("unchecked") @Override public void onEvent(Event event, Object source, Object data) { if (event instanceof DocumentUpdatedEvent) { XWikiDocument document = (XWikiDocument) source; if (this.tree.isExtensionPage(document.getDocumentReference())) { updateCustomizedFlag(document.getDocumentReferenceWithLocale()); } } else if (event instanceof ApplicationReadyEvent) { addExtensionDocuments(this.wikiDescriptorManagerProvider.get().getCurrentWikiId()); } else if (event instanceof WikiReadyEvent) { addExtensionDocuments((String) source); } else if (event instanceof XarExtensionInstalledEvent) { addExtensionDocuments((ExtensionEvent) event, (InstalledExtension) source); } else if (event instanceof XarExtensionUninstalledEvent) { removeExtensionDocuments((ExtensionEvent) event, (InstalledExtension) source); } else if (event instanceof XarExtensionUpgradedEvent) { ((Collection<InstalledExtension>) data).stream().forEach( oldInstalledExtension -> removeExtensionDocuments((ExtensionEvent) event, oldInstalledExtension)); addExtensionDocuments((ExtensionEvent) event, (InstalledExtension) source); } } InstalledExtensionDocumentListener(); @SuppressWarnings("unchecked") @Override void onEvent(Event event, Object source, Object data); }
InstalledExtensionDocumentListener extends AbstractEventListener { @SuppressWarnings("unchecked") @Override public void onEvent(Event event, Object source, Object data) { if (event instanceof DocumentUpdatedEvent) { XWikiDocument document = (XWikiDocument) source; if (this.tree.isExtensionPage(document.getDocumentReference())) { updateCustomizedFlag(document.getDocumentReferenceWithLocale()); } } else if (event instanceof ApplicationReadyEvent) { addExtensionDocuments(this.wikiDescriptorManagerProvider.get().getCurrentWikiId()); } else if (event instanceof WikiReadyEvent) { addExtensionDocuments((String) source); } else if (event instanceof XarExtensionInstalledEvent) { addExtensionDocuments((ExtensionEvent) event, (InstalledExtension) source); } else if (event instanceof XarExtensionUninstalledEvent) { removeExtensionDocuments((ExtensionEvent) event, (InstalledExtension) source); } else if (event instanceof XarExtensionUpgradedEvent) { ((Collection<InstalledExtension>) data).stream().forEach( oldInstalledExtension -> removeExtensionDocuments((ExtensionEvent) event, oldInstalledExtension)); addExtensionDocuments((ExtensionEvent) event, (InstalledExtension) source); } } InstalledExtensionDocumentListener(); @SuppressWarnings("unchecked") @Override void onEvent(Event event, Object source, Object data); static final String HINT; }