@Test public void hibernateMigrate() throws Exception { this.mocker.registerMockComponent(ComponentManager.class); ComponentManager cm = this.mocker.getInstance(ComponentManager.class); XWikiHibernateStore store = mock(XWikiHibernateStore.class); when(cm.getInstance(XWikiStoreInterface.class, "hibernate")).thenReturn(store); Execution e = this.mocker.getInstance(Execution.class); ExecutionContext ec = mock(ExecutionContext.class); when(e.getContext()).thenReturn(ec); XWikiContext xc = mock(XWikiContext.class); when(ec.getProperty("xwikicontext")).thenReturn(xc); @SuppressWarnings("deprecation") ArgumentCaptor<HibernateCallback<Object>> callbackCaptor = new ArgumentCaptor<>(); this.mocker.getComponentUnderTest().migrate(); Mockito.verify(store).executeWrite(Matchers.same(xc), callbackCaptor.capture()); XWiki xwiki = mock(XWiki.class); when(xc.getWiki()).thenReturn(xwiki); HibernateCallback<Object> callback = callbackCaptor.getValue(); Assert.assertNotNull(callback); Session session = mock(Session.class); Query q = mock(Query.class); when(session.createQuery(Matchers.anyString())).thenReturn(q); List<String> docs = new ArrayList<>(); docs.add("data.ProperCreator"); docs.add("data.NullDoc"); docs.add("data.ThrowsException"); docs.add("data.ThrowsDME"); docs.add("data.GuestCreator"); when(q.list()).thenReturn(docs); DocumentReferenceResolver<String> resolver = this.mocker.getInstance(DocumentReferenceResolver.TYPE_STRING, "current"); EntityReferenceSerializer<String> serializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING); DocumentReference r1 = new DocumentReference("xwiki", "data", "ProperCreator"); when(resolver.resolve("data.ProperCreator")).thenReturn(r1); XWikiDocument p1 = mock(XWikiDocument.class); when(xwiki.getDocument(r1, xc)).thenReturn(p1); BaseObject o1 = mock(BaseObject.class); when(p1.newXObject(Owner.CLASS_REFERENCE, xc)).thenReturn(o1); DocumentReference a1 = new DocumentReference("xwiki", "XWiki", "jdoe"); when(p1.getCreatorReference()).thenReturn(a1); when(serializer.serialize(a1)).thenReturn("xwiki:XWiki.jdoe"); callback.doInHibernate(session); verify(o1).setStringValue(Owner.PROPERTY_NAME, "xwiki:XWiki.jdoe"); DocumentReference r2 = new DocumentReference("xwiki", "data", "NullDoc"); when(resolver.resolve("data.NullDoc")).thenReturn(r2); when(xwiki.getDocument(r2, xc)).thenReturn(null); DocumentReference r3 = new DocumentReference("xwiki", "data", "ThrowsException"); when(resolver.resolve("data.ThrowsException")).thenReturn(r3); when(xwiki.getDocument(r3, xc)).thenThrow(new XWikiException(4, 2, "Failure")); callback.doInHibernate(session); verify(this.mocker.getMockedLogger()).warn(Matchers.anyString(), Matchers.eq("data.ThrowsException"), Matchers.eq("Error number 2 in 4: Failure")); DocumentReference r4 = new DocumentReference("xwiki", "data", "ThrowsDME"); when(resolver.resolve("data.ThrowsDME")).thenReturn(r4); XWikiDocument p4 = mock(XWikiDocument.class); when(xwiki.getDocument(r4, xc)).thenReturn(p4); BaseObject o4 = mock(BaseObject.class); when(p4.newXObject(Owner.CLASS_REFERENCE, xc)).thenReturn(o4); when(p4.getCreatorReference()).thenReturn(a1); when(cm.getInstance(XWikiStoreInterface.class, "hibernate")).thenThrow(new ComponentLookupException("Nope")) .thenReturn(store); callback.doInHibernate(session); DocumentReference r5 = new DocumentReference("xwiki", "data", "GuestCreator"); when(resolver.resolve("data.GuestCreator")).thenReturn(r5); XWikiDocument p5 = mock(XWikiDocument.class); when(xwiki.getDocument(r5, xc)).thenReturn(p5); BaseObject o5 = mock(BaseObject.class); when(p5.newXObject(Owner.CLASS_REFERENCE, xc)).thenReturn(o5); when(p5.getCreatorReference()).thenReturn(null); callback.doInHibernate(session); verify(o5).setStringValue(Owner.PROPERTY_NAME, ""); }
@Override public void hibernateMigrate() throws DataMigrationException, XWikiException { getStore().executeWrite(getXWikiContext(), new AddOwnerCallback()); }
R54590PhenoTips931DataMigration extends AbstractHibernateDataMigration { @Override public void hibernateMigrate() throws DataMigrationException, XWikiException { getStore().executeWrite(getXWikiContext(), new AddOwnerCallback()); } }
R54590PhenoTips931DataMigration extends AbstractHibernateDataMigration { @Override public void hibernateMigrate() throws DataMigrationException, XWikiException { getStore().executeWrite(getXWikiContext(), new AddOwnerCallback()); }  }
R54590PhenoTips931DataMigration extends AbstractHibernateDataMigration { @Override public void hibernateMigrate() throws DataMigrationException, XWikiException { getStore().executeWrite(getXWikiContext(), new AddOwnerCallback()); }  @Override String getDescription(); @Override XWikiDBVersion getVersion(); @Override void hibernateMigrate(); }
R54590PhenoTips931DataMigration extends AbstractHibernateDataMigration { @Override public void hibernateMigrate() throws DataMigrationException, XWikiException { getStore().executeWrite(getXWikiContext(), new AddOwnerCallback()); }  @Override String getDescription(); @Override XWikiDBVersion getVersion(); @Override void hibernateMigrate();  }