Search in sources :

Example 6 with XWikiConfig

use of com.xpn.xwiki.XWikiConfig in project xwiki-platform by xwiki.

the class XWikiTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    this.xwiki = new com.xpn.xwiki.XWiki();
    getContext().setWiki(this.xwiki);
    this.xwiki.setConfig(new XWikiConfig());
    this.apiXWiki = new XWiki(this.xwiki, getContext());
    this.mockXWikiStore = mock(XWikiHibernateStore.class, new java.lang.Class[] { com.xpn.xwiki.XWiki.class, XWikiContext.class }, new java.lang.Object[] { this.xwiki, getContext() });
    this.mockXWikiStore.stubs().method("loadXWikiDoc").will(new CustomStub("Implements XWikiStoreInterface.loadXWikiDoc") {

        @Override
        public java.lang.Object invoke(Invocation invocation) throws Throwable {
            XWikiDocument shallowDoc = (XWikiDocument) invocation.parameterValues.get(0);
            if (XWikiTest.this.docs.containsKey(shallowDoc.getName())) {
                return XWikiTest.this.docs.get(shallowDoc.getName());
            } else {
                return shallowDoc;
            }
        }
    });
    this.mockXWikiStore.stubs().method("saveXWikiDoc").will(new CustomStub("Implements XWikiStoreInterface.saveXWikiDoc") {

        @Override
        public java.lang.Object invoke(Invocation invocation) throws Throwable {
            XWikiDocument document = (XWikiDocument) invocation.parameterValues.get(0);
            document.setNew(false);
            document.setStore((XWikiStoreInterface) XWikiTest.this.mockXWikiStore.proxy());
            document.setId(rand.nextLong());
            XWikiTest.this.docs.put(document.getName(), document);
            return null;
        }
    });
    this.mockXWikiStore.stubs().method("getTranslationList").will(returnValue(Collections.EMPTY_LIST));
    this.mockXWikiVersioningStore = mock(XWikiHibernateVersioningStore.class, new java.lang.Class[] { com.xpn.xwiki.XWiki.class, XWikiContext.class }, new java.lang.Object[] { this.xwiki, getContext() });
    this.mockXWikiVersioningStore.stubs().method("getXWikiDocumentArchive").will(returnValue(new XWikiDocumentArchive()));
    this.mockXWikiVersioningStore.stubs().method("saveXWikiDocArchive").will(returnValue(null));
    this.mockXWikiRightService = mock(XWikiRightServiceImpl.class, new java.lang.Class[] {}, new java.lang.Object[] {});
    this.mockXWikiRightService.stubs().method("hasAccessLevel").will(returnValue(true));
    this.mockXWikiRightService.stubs().method("hasProgrammingRights").will(returnValue(true));
    this.xwiki.setStore((XWikiStoreInterface) this.mockXWikiStore.proxy());
    this.xwiki.setVersioningStore((XWikiVersioningStoreInterface) this.mockXWikiVersioningStore.proxy());
    this.xwiki.setRightService((XWikiRightService) this.mockXWikiRightService.proxy());
    getContext().setUser("Redtail");
    this.apiDocument = new Document(new XWikiDocument(new DocumentReference("Wiki", "MilkyWay", "Fidis")), getContext());
    this.apiDocument.getDocument().setCreator("c" + getContext().getUser());
    this.apiDocument.getDocument().setAuthor("a" + getContext().getUser());
    this.apiDocument.save();
    getContext().setUser("Earth");
}
Also used : Invocation(org.jmock.core.Invocation) XWikiHibernateVersioningStore(com.xpn.xwiki.store.XWikiHibernateVersioningStore) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiStoreInterface(com.xpn.xwiki.store.XWikiStoreInterface) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiHibernateStore(com.xpn.xwiki.store.XWikiHibernateStore) XWikiDocumentArchive(com.xpn.xwiki.doc.XWikiDocumentArchive) CustomStub(org.jmock.core.stub.CustomStub) XWikiRightServiceImpl(com.xpn.xwiki.user.impl.xwiki.XWikiRightServiceImpl) XWikiConfig(com.xpn.xwiki.XWikiConfig) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 7 with XWikiConfig

use of com.xpn.xwiki.XWikiConfig in project xwiki-platform by xwiki.

the class AbstractDataMigrationManager method tryToProcceedToMigration.

/**
 * Start migrations if migrations are enabled.
 *
 * @throws DataMigrationException
 */
private void tryToProcceedToMigration() throws DataMigrationException {
    XWikiConfig config = getXWikiConfig();
    if ("1".equals(config.getProperty("xwiki.store.migration", "0")) && !"0".equals(config.getProperty("xwiki.store.hibernate.updateschema"))) {
        // Run migrations
        this.logger.info("Storage schema updates and data migrations are enabled");
        startMigrationsOnlyOnce();
        // TODO: Improve or remove this which is inappropriate in a container environment
        if ("1".equals(config.getProperty("xwiki.store.migration.exitAfterEnd", "0"))) {
            this.logger.error("Exiting because xwiki.store.migration.exitAfterEnd is set");
            System.exit(0);
        }
    }
}
Also used : XWikiConfig(com.xpn.xwiki.XWikiConfig)

Aggregations

XWikiConfig (com.xpn.xwiki.XWikiConfig)7 XWikiContext (com.xpn.xwiki.XWikiContext)5 XWiki (com.xpn.xwiki.XWiki)4 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)4 XWikiStoreInterface (com.xpn.xwiki.store.XWikiStoreInterface)3 Invocation (org.jmock.core.Invocation)3 CustomStub (org.jmock.core.stub.CustomStub)3 XWikiHibernateStore (com.xpn.xwiki.store.XWikiHibernateStore)2 XWikiHibernateVersioningStore (com.xpn.xwiki.store.XWikiHibernateVersioningStore)2 XWikiServletRequestStub (com.xpn.xwiki.web.XWikiServletRequestStub)2 XWikiServletURLFactory (com.xpn.xwiki.web.XWikiServletURLFactory)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 Mock (org.jmock.Mock)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 XWikiException (com.xpn.xwiki.XWikiException)1 XWikiDocumentArchive (com.xpn.xwiki.doc.XWikiDocumentArchive)1 XWikiHibernateRecycleBinStore (com.xpn.xwiki.store.XWikiHibernateRecycleBinStore)1 XWikiRightService (com.xpn.xwiki.user.api.XWikiRightService)1 XWikiRightServiceImpl (com.xpn.xwiki.user.impl.xwiki.XWikiRightServiceImpl)1