Search in sources :

Example 1 with XWikiStoreInterface

use of com.xpn.xwiki.store.XWikiStoreInterface in project xwiki-platform by xwiki.

the class XWiki method flushCache.

public void flushCache(XWikiContext context) {
    // We need to flush the virtual wiki list
    this.initializedWikis = new ConcurrentHashMap<>();
    // We need to flush the group service cache
    if (this.groupService != null) {
        this.groupService.flushCache();
    }
    // If we use the Cache Store layer.. we need to flush it
    XWikiStoreInterface store = getStore();
    if ((store != null) && (store instanceof XWikiCacheStoreInterface)) {
        ((XWikiCacheStoreInterface) getStore()).flushCache();
    }
    // Flush renderers.. Groovy renderer has a cache
    getOldRendering().flushCache();
    getParseGroovyFromString().flushCache();
    XWikiPluginManager pmanager = getPluginManager();
    if (pmanager != null) {
        pmanager.flushCache(context);
    }
    // Make sure we call all classes flushCache function
    try {
        List<String> classes = getClassList(context);
        for (int i = 0; i < classes.size(); i++) {
            String className = classes.get(i);
            try {
                getClass(className, context).flushCache();
            } catch (Exception e) {
            }
        }
    } catch (Exception e) {
    }
}
Also used : XWikiCacheStoreInterface(com.xpn.xwiki.store.XWikiCacheStoreInterface) XWikiPluginManager(com.xpn.xwiki.plugin.XWikiPluginManager) ParseGroovyFromString(com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString) IncludeServletAsString(com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString) XWikiStoreInterface(com.xpn.xwiki.store.XWikiStoreInterface) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) IOException(java.io.IOException) JobException(org.xwiki.job.JobException) ParseException(org.xwiki.rendering.parser.ParseException) QueryException(org.xwiki.query.QueryException) URIException(org.apache.commons.httpclient.URIException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HibernateException(org.hibernate.HibernateException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) NamingException(javax.naming.NamingException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException)

Example 2 with XWikiStoreInterface

use of com.xpn.xwiki.store.XWikiStoreInterface in project xwiki-platform by xwiki.

the class XWikiMockitoTest method deleteAllDocumentsAndWithoutSendingToTrash.

@Test
public void deleteAllDocumentsAndWithoutSendingToTrash() throws Exception {
    XWiki xwiki = new XWiki();
    XWikiDocument document = mock(XWikiDocument.class);
    DocumentReference reference = new DocumentReference("wiki", "space", "page");
    when(document.getDocumentReference()).thenReturn(reference);
    // Make sure we have a trash for the test.
    XWikiRecycleBinStoreInterface recycleBinStoreInterface = mock(XWikiRecycleBinStoreInterface.class);
    xwiki.setRecycleBinStore(recycleBinStoreInterface);
    when(xwikiCfgConfigurationSource.getProperty("xwiki.recyclebin", "1")).thenReturn("1");
    // Configure the mocked Store to later verify if it's called
    XWikiStoreInterface storeInterface = mock(XWikiStoreInterface.class);
    xwiki.setStore(storeInterface);
    XWikiContext xwikiContext = mock(XWikiContext.class);
    xwiki.deleteAllDocuments(document, false, xwikiContext);
    // Verify that saveToRecycleBin is never called since otherwise it would mean the doc has been saved in the
    // trash
    verify(recycleBinStoreInterface, never()).saveToRecycleBin(any(XWikiDocument.class), any(String.class), any(Date.class), any(XWikiContext.class), any(Boolean.class));
    // Verify that deleteXWikiDoc() is called
    verify(storeInterface).deleteXWikiDoc(document, xwikiContext);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiRecycleBinStoreInterface(com.xpn.xwiki.store.XWikiRecycleBinStoreInterface) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiStoreInterface(com.xpn.xwiki.store.XWikiStoreInterface) Date(java.util.Date) Test(org.junit.Test)

Example 3 with XWikiStoreInterface

use of com.xpn.xwiki.store.XWikiStoreInterface in project xwiki-platform by xwiki.

the class XWikiTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    this.document = new XWikiDocument(new DocumentReference("Wiki", "MilkyWay", "Fidis"));
    getContext().setRequest(new XWikiServletRequestStub());
    getContext().setURL(new URL("http://localhost:8080/xwiki/bin/view/MilkyWay/Fidis"));
    Mock mockLocalizationContext = registerMockComponent(LocalizationContext.class);
    mockLocalizationContext.stubs().method("getCurrentLocale").will(returnValue(Locale.ROOT));
    this.mockWikiDescriptorManager = registerMockComponent(WikiDescriptorManager.class);
    this.mockWikiDescriptorManager.stubs().method("getCurrentWikiId").will(new CustomStub("Implements WikiDescriptorManager.getCurrentWikiId") {

        @Override
        public Object invoke(Invocation invocation) throws Throwable {
            return getContext().getWikiId();
        }
    });
    this.xwiki = new XWiki(new XWikiConfig(), getContext()) {

        // Avoid all the error at XWiki initialization
        @Override
        public String getXWikiPreference(String prefname, String defaultValue, XWikiContext context) {
            if (prefname.equals("plugins") || prefname.startsWith("macros_")) {
                return defaultValue;
            } else {
                return super.getXWikiPreference(prefname, defaultValue, context);
            }
        }
    };
    getContext().setWiki(this.xwiki);
    // Ensure that no Velocity Templates are going to be used when executing Velocity since otherwise
    // the Velocity init would fail (since by default the macros.vm templates wouldn't be found as we're
    // not providing it in our unit test resources).
    getConfigurationSource().setProperty("xwiki.render.velocity.macrolist", "");
    this.mockXWikiStore = mock(XWikiHibernateStore.class, new Class[] { XWiki.class, XWikiContext.class }, new Object[] { this.xwiki, getContext() });
    this.mockXWikiStore.stubs().method("loadXWikiDoc").will(new CustomStub("Implements XWikiStoreInterface.loadXWikiDoc") {

        @Override
        public 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 Object invoke(Invocation invocation) throws Throwable {
            XWikiDocument document = (XWikiDocument) invocation.parameterValues.get(0);
            document.setNew(false);
            document.setStore((XWikiStoreInterface) XWikiTest.this.mockXWikiStore.proxy());
            XWikiTest.this.docs.put(document.getName(), document);
            return null;
        }
    });
    this.mockXWikiStore.stubs().method("deleteXWikiDoc").will(new CustomStub("Implements XWikiStoreInterface.deleteXWikiDoc") {

        @Override
        public Object invoke(Invocation invocation) throws Throwable {
            XWikiDocument document = (XWikiDocument) invocation.parameterValues.get(0);
            XWikiTest.this.docs.remove(document.getName());
            return null;
        }
    });
    this.mockXWikiStore.stubs().method("getTranslationList").will(returnValue(Collections.EMPTY_LIST));
    this.mockXWikiStore.stubs().method("exists").will(returnValue(true));
    this.mockXWikiVersioningStore = mock(XWikiHibernateVersioningStore.class, new Class[] { XWiki.class, XWikiContext.class }, new Object[] { this.xwiki, getContext() });
    this.mockXWikiVersioningStore.stubs().method("getXWikiDocumentArchive").will(returnValue(null));
    this.mockXWikiVersioningStore.stubs().method("resetRCSArchive").will(returnValue(null));
    this.xwiki.setStore((XWikiStoreInterface) this.mockXWikiStore.proxy());
    this.xwiki.setVersioningStore((XWikiVersioningStoreInterface) this.mockXWikiVersioningStore.proxy());
    this.xwiki.saveDocument(this.document, getContext());
    this.document.setCreator("Condor");
    this.document.setAuthor("Albatross");
    this.xwiki.saveDocument(this.document, getContext());
}
Also used : XWikiServletRequestStub(com.xpn.xwiki.web.XWikiServletRequestStub) Invocation(org.jmock.core.Invocation) XWikiHibernateVersioningStore(com.xpn.xwiki.store.XWikiHibernateVersioningStore) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) URL(java.net.URL) Mock(org.jmock.Mock) XWikiStoreInterface(com.xpn.xwiki.store.XWikiStoreInterface) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiHibernateStore(com.xpn.xwiki.store.XWikiHibernateStore) CustomStub(org.jmock.core.stub.CustomStub) BaseObject(com.xpn.xwiki.objects.BaseObject) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 4 with XWikiStoreInterface

use of com.xpn.xwiki.store.XWikiStoreInterface in project xwiki-platform by xwiki.

the class DatabasePingDataProvider method getDatabaseMetaData.

private DatabaseMetaData getDatabaseMetaData() {
    DatabaseMetaData metaData = null;
    XWikiContext xcontext = (XWikiContext) this.execution.getContext().getProperty(XWikiContext.EXECUTIONCONTEXT_KEY);
    if (xcontext != null) {
        XWikiStoreInterface storeInterface = xcontext.getWiki().getStore();
        if (storeInterface instanceof XWikiCacheStoreInterface) {
            storeInterface = ((XWikiCacheStoreInterface) storeInterface).getStore();
        }
        if (XWikiHibernateBaseStore.class.isAssignableFrom(storeInterface.getClass())) {
            XWikiHibernateBaseStore baseStore = (XWikiHibernateBaseStore) storeInterface;
            metaData = baseStore.getDatabaseMetaData();
        }
    }
    return metaData;
}
Also used : XWikiCacheStoreInterface(com.xpn.xwiki.store.XWikiCacheStoreInterface) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiHibernateBaseStore(com.xpn.xwiki.store.XWikiHibernateBaseStore) DatabaseMetaData(java.sql.DatabaseMetaData) XWikiStoreInterface(com.xpn.xwiki.store.XWikiStoreInterface)

Example 5 with XWikiStoreInterface

use of com.xpn.xwiki.store.XWikiStoreInterface in project xwiki-platform by xwiki.

the class SyndEntryDocumentSourceTest method mockUp.

private void mockUp() throws Exception {
    final Map<String, XWikiDocument> docs = new HashMap<String, XWikiDocument>();
    final XWikiContext context = getContext();
    // Set URL/Request
    context.setRequest(new XWikiServletRequestStub());
    context.setURL(new URL("http://localhost:8080/xwiki/bin/view/MilkyWay/Fidis"));
    final XWiki xwiki = new XWiki(new XWikiConfig(), context) {

        @Override
        public String getXWikiPreference(String prefname, String defaultValue, XWikiContext context) {
            return defaultValue;
        }
    };
    context.setURLFactory(new XWikiServletURLFactory(new URL("http://www.xwiki.org/"), "xwiki/", "bin/"));
    final Mock mockXWikiStore = mock(XWikiHibernateStore.class, new Class[] { XWiki.class, XWikiContext.class }, new Object[] { xwiki, context });
    mockXWikiStore.stubs().method("loadXWikiDoc").will(new CustomStub("Implements XWikiStoreInterface.loadXWikiDoc") {

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

        @Override
        public Object invoke(Invocation invocation) throws Throwable {
            XWikiDocument document = (XWikiDocument) invocation.parameterValues.get(0);
            document.setNew(false);
            document.setStore((XWikiStoreInterface) mockXWikiStore.proxy());
            docs.put(document.getName(), document);
            return null;
        }
    });
    mockXWikiStore.stubs().method("getTranslationList").will(returnValue(Collections.EMPTY_LIST));
    mockXWikiStore.stubs().method("exists").will(returnValue(false));
    final Mock mockXWikiVersioningStore = mock(XWikiHibernateVersioningStore.class, new Class[] { XWiki.class, XWikiContext.class }, new Object[] { xwiki, context });
    mockXWikiVersioningStore.stubs().method("getXWikiDocumentArchive").will(returnValue(null));
    mockXWikiVersioningStore.stubs().method("resetRCSArchive").will(returnValue(null));
    xwiki.setStore((XWikiStoreInterface) mockXWikiStore.proxy());
    xwiki.setVersioningStore((XWikiVersioningStoreInterface) mockXWikiVersioningStore.proxy());
    final Mock mockXWikiRightsService = mock(XWikiRightServiceImpl.class, new Class[] {}, new Object[] {});
    mockXWikiRightsService.stubs().method("hasAccessLevel").will(new CustomStub("Implements XWikiRightService.hasAccessLevel") {

        @Override
        public Object invoke(Invocation invocation) throws Throwable {
            // String right = (String) invocation.parameterValues.get(0);
            String user = (String) invocation.parameterValues.get(1);
            // we give access to all the users with an even name length
            return new Boolean(user.length() % 2 == 0);
        }
    });
    xwiki.setRightService((XWikiRightService) mockXWikiRightsService.proxy());
}
Also used : XWikiServletRequestStub(com.xpn.xwiki.web.XWikiServletRequestStub) XWikiServletURLFactory(com.xpn.xwiki.web.XWikiServletURLFactory) Invocation(org.jmock.core.Invocation) HashMap(java.util.HashMap) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) URL(java.net.URL) Mock(org.jmock.Mock) XWikiStoreInterface(com.xpn.xwiki.store.XWikiStoreInterface) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) CustomStub(org.jmock.core.stub.CustomStub) XWikiConfig(com.xpn.xwiki.XWikiConfig)

Aggregations

XWikiStoreInterface (com.xpn.xwiki.store.XWikiStoreInterface)9 XWikiContext (com.xpn.xwiki.XWikiContext)5 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 Invocation (org.jmock.core.Invocation)4 CustomStub (org.jmock.core.stub.CustomStub)4 DocumentReference (org.xwiki.model.reference.DocumentReference)4 XWiki (com.xpn.xwiki.XWiki)3 XWikiConfig (com.xpn.xwiki.XWikiConfig)3 XWikiCacheStoreInterface (com.xpn.xwiki.store.XWikiCacheStoreInterface)3 XWikiHibernateStore (com.xpn.xwiki.store.XWikiHibernateStore)3 XWikiHibernateVersioningStore (com.xpn.xwiki.store.XWikiHibernateVersioningStore)3 Mock (org.jmock.Mock)3 BaseObject (com.xpn.xwiki.objects.BaseObject)2 PropertyClass (com.xpn.xwiki.objects.classes.PropertyClass)2 XWikiRightService (com.xpn.xwiki.user.api.XWikiRightService)2 XWikiServletRequestStub (com.xpn.xwiki.web.XWikiServletRequestStub)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2