@Test public void migrate() throws Exception { Query query = mock(Query.class); when(queryManager.createQuery(anyString(), anyString())).thenReturn(query); when(query.setWiki("xwiki")).thenReturn(query); when(query.execute()).thenReturn(Arrays.asList("XWiki.UserA")); WikiReference wikiReference = new WikiReference("xwiki"); when(xwikicontext.getWikiReference()).thenReturn(wikiReference); DocumentReference userA = new DocumentReference("xwiki", "XWiki", "UserA"); when(referenceResolver.resolve("XWiki.UserA", wikiReference)).thenReturn(userA); XWikiDocument userAdoc = mock(XWikiDocument.class); when(xwiki.getDocument(userA, xwikicontext)).thenReturn(userAdoc); List<BaseObject> objects = Arrays.asList( mockObject(Arrays.asList("alert"), "filter1", true, "inclusive", new Date(100L), Arrays.asList("update", "create"), Arrays.asList("page1", "page2"), Arrays.asList("space1", "space2"), Arrays.asList("wiki1", "wiki2"), Arrays.asList("user1", "user2")), null, mockObject(Arrays.asList("alert", "email"), "filter2", false, "exclusive", new Date(90L), Arrays.asList("comment"), Arrays.asList("page3"), Arrays.asList(), Arrays.asList(), Arrays.asList()) ); DocumentReference classReference = new DocumentReference("xwiki", Arrays.asList("XWiki", "Notifications", "Code"), "NotificationFilterPreferenceClass"); when(userAdoc.getXObjects(classReference)).thenReturn(objects); DocumentReference notificationFilterPreferenceClass = new DocumentReference("xwiki", Arrays.asList("XWiki", "Notifications", "Code"), "NotificationFilterPreferenceClass"); XWikiDocument oldClass = mock(XWikiDocument.class); when(xwiki.getDocument(notificationFilterPreferenceClass, xwikicontext)).thenReturn(oldClass); when(oldClass.isNew()).thenReturn(false); when(xwiki.exists(notificationFilterPreferenceClass, xwikicontext)).thenReturn(true); mocker.getComponentUnderTest().onEvent(new ApplicationReadyEvent(), null, null); verify(xwiki).deleteDocument(oldClass, false, xwikicontext); verify(userAdoc).removeXObjects(classReference); verify(xwiki).saveDocument(userAdoc, "Migrate notification filter preferences to the new store.", xwikicontext); verify(modelBridge).saveFilterPreferences(userA, Arrays.asList( createExpectedPreference(Sets.newHashSet("update", "create"), Sets.newHashSet(NotificationFormat.ALERT), NotificationFilterType.INCLUSIVE, "filter1", true, new Date(100L), "", "", "page1", ""), createExpectedPreference(Sets.newHashSet("update", "create"), Sets.newHashSet(NotificationFormat.ALERT), NotificationFilterType.INCLUSIVE, "filter1", true, new Date(100L), "", "", "page2", ""), createExpectedPreference(Sets.newHashSet("update", "create"), Sets.newHashSet(NotificationFormat.ALERT), NotificationFilterType.INCLUSIVE, "filter1", true, new Date(100L), "", "space1", "", ""), createExpectedPreference(Sets.newHashSet("update", "create"), Sets.newHashSet(NotificationFormat.ALERT), NotificationFilterType.INCLUSIVE, "filter1", true, new Date(100L), "", "space2", "", ""), createExpectedPreference(Sets.newHashSet("update", "create"), Sets.newHashSet(NotificationFormat.ALERT), NotificationFilterType.INCLUSIVE, "filter1", true, new Date(100L), "wiki1", "", "", ""), createExpectedPreference(Sets.newHashSet("update", "create"), Sets.newHashSet(NotificationFormat.ALERT), NotificationFilterType.INCLUSIVE, "filter1", true, new Date(100L), "wiki2", "", "", ""), createExpectedPreference(Sets.newHashSet("update", "create"), Sets.newHashSet(NotificationFormat.ALERT), NotificationFilterType.INCLUSIVE, "filter1", true, new Date(100L), "", "", "", "user1"), createExpectedPreference(Sets.newHashSet("update", "create"), Sets.newHashSet(NotificationFormat.ALERT), NotificationFilterType.INCLUSIVE, "filter1", true, new Date(100L), "", "", "", "user2"), createExpectedPreference(Sets.newHashSet("comment"), Sets.newHashSet(NotificationFormat.ALERT, NotificationFormat.EMAIL), NotificationFilterType.EXCLUSIVE, "filter2", false, new Date(90L), "", "", "page3", "") )); }
@Override public void onEvent(Event event, Object source, Object data) { try { for (String wikiId : this.wikiDescriptorManager.getAllIds()) { migrateWiki(wikiId); } } catch (Exception e) { this.logger.error("Failed to migrate notification filter preferences.", e); } }
NotificationFilterPreferencesMigrator extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { try { for (String wikiId : this.wikiDescriptorManager.getAllIds()) { migrateWiki(wikiId); } } catch (Exception e) { this.logger.error("Failed to migrate notification filter preferences.", e); } } }
NotificationFilterPreferencesMigrator extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { try { for (String wikiId : this.wikiDescriptorManager.getAllIds()) { migrateWiki(wikiId); } } catch (Exception e) { this.logger.error("Failed to migrate notification filter preferences.", e); } } NotificationFilterPreferencesMigrator(); }
NotificationFilterPreferencesMigrator extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { try { for (String wikiId : this.wikiDescriptorManager.getAllIds()) { migrateWiki(wikiId); } } catch (Exception e) { this.logger.error("Failed to migrate notification filter preferences.", e); } } NotificationFilterPreferencesMigrator(); @Override void onEvent(Event event, Object source, Object data); }
NotificationFilterPreferencesMigrator extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { try { for (String wikiId : this.wikiDescriptorManager.getAllIds()) { migrateWiki(wikiId); } } catch (Exception e) { this.logger.error("Failed to migrate notification filter preferences.", e); } } NotificationFilterPreferencesMigrator(); @Override void onEvent(Event event, Object source, Object data);  }