@Test public void upgradeWorkspace() throws Exception { when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("workspace"); XWikiDocument oldDescriptorDocument = mock(XWikiDocument.class); when(xwiki.getDocument(eq(new DocumentReference("mainWiki", XWiki.SYSTEM_SPACE, "XWikiServerWorkspace")), any(XWikiContext.class))).thenReturn(oldDescriptorDocument); BaseObject oldObject = mock(BaseObject.class); when(oldDescriptorDocument.getXObject(eq(new DocumentReference("mainWiki", "WorkspaceManager", "WorkspaceClass") ))).thenReturn(oldObject); when(oldObject.getStringValue("membershipType")).thenReturn("request"); DocumentReference memberGroupRef = new DocumentReference("workspace", XWiki.SYSTEM_SPACE, "XWikiAllGroup"); XWikiDocument memberGroupDoc = mock(XWikiDocument.class); when(xwiki.getDocument(eq(memberGroupRef), any(XWikiContext.class))).thenReturn(memberGroupDoc); DocumentReference candidacyOldClass = new DocumentReference("workspace", "XWiki", "WorkspaceCandidateMemberClass"); List<BaseObject> oldCandidacies = new ArrayList<>(); BaseObject oldCandidacy = mock(BaseObject.class); oldCandidacies.add(oldCandidacy); when(memberGroupDoc.getXObjects(eq(candidacyOldClass))).thenReturn(oldCandidacies); LocalDocumentReference newCandidacyClassRef = WikiCandidateMemberClassInitializer.REFERENCE; BaseObject newCandidacyObject = mock(BaseObject.class); when(memberGroupDoc.newXObject(eq(newCandidacyClassRef), any(XWikiContext.class))) .thenReturn(newCandidacyObject); when(oldCandidacy.getStringValue("type")).thenReturn("aa"); when(oldCandidacy.getStringValue("status")).thenReturn("bb"); when(oldCandidacy.getStringValue("userName")).thenReturn("cc"); when(oldCandidacy.getLargeStringValue("userComment")).thenReturn("dd"); when(oldCandidacy.getStringValue("reviewer")).thenReturn("ee"); when(oldCandidacy.getLargeStringValue("reviewerComment")).thenReturn("ff"); when(oldCandidacy.getLargeStringValue("reviewerPrivateComment")).thenReturn("gg"); when(oldCandidacy.getDateValue("date")).thenReturn(new Date(2000)); when(oldCandidacy.getDateValue("resolutionDate")).thenReturn(new Date(8000)); mocker.getComponentUnderTest().hibernateMigrate(); WikiUserConfiguration expectedConfiguration = new WikiUserConfiguration(); expectedConfiguration.setUserScope(UserScope.GLOBAL_ONLY); expectedConfiguration.setMembershipType(MembershipType.REQUEST); verify(wikiUserConfigurationHelper).saveConfiguration(eq(expectedConfiguration), eq("workspace")); verify(oldDescriptorDocument).removeXObject(oldObject); verify(xwiki, times(1)).saveDocument(oldDescriptorDocument, "[UPGRADE] Remove the old WorkspaceManager.WorkspaceClass" + " object.", xcontext); verify(newCandidacyObject).setStringValue(WikiCandidateMemberClassInitializer.FIELD_TYPE, "aa"); verify(newCandidacyObject).setStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS, "bb"); verify(newCandidacyObject).setStringValue(WikiCandidateMemberClassInitializer.FIELD_USER, "cc"); verify(newCandidacyObject).setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_USER_COMMENT, "dd"); verify(newCandidacyObject).setStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN, "ee"); verify(newCandidacyObject).setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_COMMENT, "ff"); verify(newCandidacyObject).setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_PRIVATE_COMMENT, "gg"); verify(newCandidacyObject).setDateValue(eq(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CREATION), eq(new Date(2000))); verify(newCandidacyObject).setDateValue(eq(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CLOSURE), eq(new Date(8000))); verify(memberGroupDoc).removeXObject(oldCandidacy); verify(xwiki, times(1)).saveDocument(memberGroupDoc, "Upgrade candidacies from the old Workspace Application" + " to the new Wiki Application.", xcontext); }
private void upgradeWorkspace(BaseObject oldObject, String wikiId, XWikiDocument oldWikiDescriptor) throws DataMigrationException, XWikiException { upgradeWorkspaceConfiguration(oldObject, wikiId, oldWikiDescriptor); try { upgradeWorkspaceCandidacies(wikiId); } catch (XWikiException e) { throw new DataMigrationException("Unable to upgrade candidacies from the old Workspace Application to " + "the new Wiki Application."); } if (oldObject != null) { deleteOldWorkspaceObject(oldObject, oldWikiDescriptor); } }
WikiUserFromXEMMigration extends AbstractHibernateDataMigration { private void upgradeWorkspace(BaseObject oldObject, String wikiId, XWikiDocument oldWikiDescriptor) throws DataMigrationException, XWikiException { upgradeWorkspaceConfiguration(oldObject, wikiId, oldWikiDescriptor); try { upgradeWorkspaceCandidacies(wikiId); } catch (XWikiException e) { throw new DataMigrationException("Unable to upgrade candidacies from the old Workspace Application to " + "the new Wiki Application."); } if (oldObject != null) { deleteOldWorkspaceObject(oldObject, oldWikiDescriptor); } } }
WikiUserFromXEMMigration extends AbstractHibernateDataMigration { private void upgradeWorkspace(BaseObject oldObject, String wikiId, XWikiDocument oldWikiDescriptor) throws DataMigrationException, XWikiException { upgradeWorkspaceConfiguration(oldObject, wikiId, oldWikiDescriptor); try { upgradeWorkspaceCandidacies(wikiId); } catch (XWikiException e) { throw new DataMigrationException("Unable to upgrade candidacies from the old Workspace Application to " + "the new Wiki Application."); } if (oldObject != null) { deleteOldWorkspaceObject(oldObject, oldWikiDescriptor); } }  }
WikiUserFromXEMMigration extends AbstractHibernateDataMigration { private void upgradeWorkspace(BaseObject oldObject, String wikiId, XWikiDocument oldWikiDescriptor) throws DataMigrationException, XWikiException { upgradeWorkspaceConfiguration(oldObject, wikiId, oldWikiDescriptor); try { upgradeWorkspaceCandidacies(wikiId); } catch (XWikiException e) { throw new DataMigrationException("Unable to upgrade candidacies from the old Workspace Application to " + "the new Wiki Application."); } if (oldObject != null) { deleteOldWorkspaceObject(oldObject, oldWikiDescriptor); } }  @Override String getDescription(); @Override XWikiDBVersion getVersion(); @Override boolean shouldExecute(XWikiDBVersion startupVersion); }
WikiUserFromXEMMigration extends AbstractHibernateDataMigration { private void upgradeWorkspace(BaseObject oldObject, String wikiId, XWikiDocument oldWikiDescriptor) throws DataMigrationException, XWikiException { upgradeWorkspaceConfiguration(oldObject, wikiId, oldWikiDescriptor); try { upgradeWorkspaceCandidacies(wikiId); } catch (XWikiException e) { throw new DataMigrationException("Unable to upgrade candidacies from the old Workspace Application to " + "the new Wiki Application."); } if (oldObject != null) { deleteOldWorkspaceObject(oldObject, oldWikiDescriptor); } }  @Override String getDescription(); @Override XWikiDBVersion getVersion(); @Override boolean shouldExecute(XWikiDBVersion startupVersion);  }