Search in sources :

Example 6 with XWikiStoreInterface

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

the class ImportTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    this.pack = new Package();
    this.xwiki = new XWiki();
    getContext().setWiki(this.xwiki);
    this.xwiki.setConfig(new XWikiConfig());
    Mock mockLocalizationContext = registerMockComponent(LocalizationContext.class);
    mockLocalizationContext.stubs().method("getCurrentLocale").will(returnValue(Locale.ROOT));
    // mock a store that would also handle translations
    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);
            String documentKey = shallowDoc.getFullName();
            if (!shallowDoc.getLanguage().equals("")) {
                documentKey += "." + shallowDoc.getLanguage();
            }
            if (docs.containsKey(documentKey)) {
                return docs.get(documentKey);
            } 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) mockXWikiStore.proxy());
            // if this is a translated document, append a language prefix
            String documentKey = document.getFullName();
            if (!document.getLanguage().equals("")) {
                documentKey += "." + document.getLanguage();
            }
            docs.put(documentKey, 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);
            // delete the document from the map
            String documentKey = document.getFullName();
            if (!document.getLanguage().equals("")) {
                documentKey += "." + document.getLanguage();
            }
            docs.remove(documentKey);
            return null;
        }
    });
    this.mockXWikiStore.stubs().method("getTranslationList").will(new CustomStub("Implements XWikiStoreInterface.getTranslationList") {

        @Override
        public Object invoke(Invocation invocation) throws Throwable {
            XWikiDocument document = (XWikiDocument) invocation.parameterValues.get(0);
            // search for this document in the map and return it's translations
            List translationList = new ArrayList();
            for (Iterator pairsIt = docs.entrySet().iterator(); pairsIt.hasNext(); ) {
                Map.Entry currentEntry = (Map.Entry) pairsIt.next();
                if (((String) currentEntry.getKey()).startsWith(document.getFullName()) && !((XWikiDocument) currentEntry.getValue()).getLanguage().equals("")) {
                    // yeeey, it's a translation
                    translationList.add(((XWikiDocument) currentEntry.getValue()).getLanguage());
                }
            }
            return translationList;
        }
    });
    this.mockXWikiStore.stubs().method("injectCustomMapping").will(returnValue(false));
    this.mockRecycleBinStore = mock(XWikiHibernateRecycleBinStore.class, new Class[] { XWikiContext.class }, new Object[] { getContext() });
    this.mockRecycleBinStore.stubs().method("saveToRecycleBin").will(VoidStub.INSTANCE);
    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) mockXWikiStore.proxy());
    this.xwiki.setRecycleBinStore((XWikiHibernateRecycleBinStore) this.mockRecycleBinStore.proxy());
    this.xwiki.setVersioningStore((XWikiVersioningStoreInterface) mockXWikiVersioningStore.proxy());
    // mock the right service
    this.mockRightService = mock(XWikiRightService.class);
    this.mockRightService.stubs().method("checkAccess").will(returnValue(true));
    this.mockRightService.stubs().method("hasWikiAdminRights").will(returnValue(true));
    this.mockRightService.stubs().method("hasProgrammingRights").will(returnValue(true));
    this.xwiki.setRightService((XWikiRightService) this.mockRightService.proxy());
}
Also used : Invocation(org.jmock.core.Invocation) XWikiHibernateVersioningStore(com.xpn.xwiki.store.XWikiHibernateVersioningStore) ArrayList(java.util.ArrayList) XWiki(com.xpn.xwiki.XWiki) XWikiContext(com.xpn.xwiki.XWikiContext) 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) Iterator(java.util.Iterator) XWikiHibernateRecycleBinStore(com.xpn.xwiki.store.XWikiHibernateRecycleBinStore) XWikiRightService(com.xpn.xwiki.user.api.XWikiRightService) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) XWikiConfig(com.xpn.xwiki.XWikiConfig)

Example 7 with XWikiStoreInterface

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

the class XWikiDocumentTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    this.defaultEntityReferenceSerializer = getComponentManager().getInstance(EntityReferenceSerializer.TYPE_STRING);
    this.document = new XWikiDocument(new DocumentReference(DOCWIKI, DOCSPACE, DOCNAME));
    this.document.setSyntax(Syntax.XWIKI_2_0);
    this.document.setLanguage("en");
    this.document.setDefaultLanguage("en");
    this.document.setNew(false);
    this.translatedDocument = new XWikiDocument();
    this.translatedDocument.setSyntax(Syntax.XWIKI_2_0);
    this.translatedDocument.setLanguage("fr");
    this.translatedDocument.setNew(false);
    getContext().put("isInRenderingEngine", true);
    this.mockXWiki = mock(XWiki.class);
    this.mockXWikiVersioningStore = mock(XWikiVersioningStoreInterface.class);
    this.mockXWikiVersioningStore.stubs().method("getXWikiDocumentArchive").will(returnValue(null));
    this.mockXWikiStoreInterface = mock(XWikiStoreInterface.class);
    this.document.setStore((XWikiStoreInterface) this.mockXWikiStoreInterface.proxy());
    this.mockXWikiMessageTool = mock(XWikiMessageTool.class, new Class[] { ResourceBundle.class, XWikiContext.class }, new Object[] { null, getContext() });
    this.mockXWikiMessageTool.stubs().method("get").will(returnValue("message"));
    this.mockXWikiRightService = mock(XWikiRightService.class);
    this.mockXWikiRightService.stubs().method("hasProgrammingRights").will(returnValue(true));
    this.mockXWiki.stubs().method("getVersioningStore").will(returnValue(this.mockXWikiVersioningStore.proxy()));
    this.mockXWiki.stubs().method("getStore").will(returnValue(this.mockXWikiStoreInterface.proxy()));
    this.mockXWiki.stubs().method("getDocument").will(returnValue(this.document));
    this.mockXWiki.stubs().method("getLanguagePreference").will(returnValue("en"));
    this.mockXWiki.stubs().method("getSectionEditingDepth").will(returnValue(2L));
    this.mockXWiki.stubs().method("getRightService").will(returnValue(this.mockXWikiRightService.proxy()));
    getContext().setWiki((XWiki) this.mockXWiki.proxy());
    getContext().put("msg", this.mockXWikiMessageTool.proxy());
    this.baseClass = this.document.getxWikiClass();
    this.baseClass.addTextField("string", "String", 30);
    this.baseClass.addTextAreaField("area", "Area", 10, 10);
    this.baseClass.addTextAreaField("puretextarea", "Pure text area", 10, 10);
    // set the text areas an non interpreted content
    ((TextAreaClass) this.baseClass.getField("puretextarea")).setContentType("puretext");
    this.baseClass.addPasswordField("passwd", "Password", 30);
    this.baseClass.addBooleanField("boolean", "Boolean", "yesno");
    this.baseClass.addNumberField("int", "Int", 10, "integer");
    this.baseClass.addStaticListField("stringlist", "StringList", "value1, value2");
    this.mockXWiki.stubs().method("getClass").will(returnValue(this.baseClass));
    this.mockXWiki.stubs().method("getXClass").will(returnValue(this.baseClass));
    this.baseObject = this.document.newObject(CLASSNAME, getContext());
    this.baseObject.setStringValue("string", "string");
    this.baseObject.setLargeStringValue("area", "area");
    this.baseObject.setStringValue("passwd", "passwd");
    this.baseObject.setIntValue("boolean", 1);
    this.baseObject.setIntValue("int", 42);
    this.baseObject.setStringListValue("stringlist", Arrays.asList("VALUE1", "VALUE2"));
    this.mockXWikiStoreInterface.stubs().method("search").will(returnValue(new ArrayList<XWikiDocument>()));
    // Set the default link label generator format to %np for some tests below.
    // We need to do this since we don't depend on xwiki-platform-rendering-configuration-default (which contains
    // an overridden RenderingConfiguration impl that sets the format to %np by default).
    DefaultRenderingConfiguration renderingConfiguration = getComponentManager().getInstance(RenderingConfiguration.class);
    renderingConfiguration.setLinkLabelFormat("%np");
}
Also used : DefaultRenderingConfiguration(org.xwiki.rendering.internal.configuration.DefaultRenderingConfiguration) ArrayList(java.util.ArrayList) XWiki(com.xpn.xwiki.XWiki) XWikiContext(com.xpn.xwiki.XWikiContext) TextAreaClass(com.xpn.xwiki.objects.classes.TextAreaClass) XWikiStoreInterface(com.xpn.xwiki.store.XWikiStoreInterface) XWikiVersioningStoreInterface(com.xpn.xwiki.store.XWikiVersioningStoreInterface) XWikiRightService(com.xpn.xwiki.user.api.XWikiRightService) TextAreaClass(com.xpn.xwiki.objects.classes.TextAreaClass) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) ResourceBundle(java.util.ResourceBundle) BaseObject(com.xpn.xwiki.objects.BaseObject) XWikiMessageTool(com.xpn.xwiki.web.XWikiMessageTool) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 8 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.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 9 with XWikiStoreInterface

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

the class XWiki method initializeStores.

private void initializeStores() throws ComponentLookupException {
    XWikiStoreInterface mainStore = getStoreConfiguration().getXWikiStore();
    // Check if we need to use the cache store..
    if (getStoreConfiguration().isStoreCacheEnabled()) {
        XWikiCacheStoreInterface cachestore = (XWikiCacheStoreInterface) Utils.getComponent(XWikiStoreInterface.class, "cache");
        cachestore.setStore(mainStore);
        setStore(cachestore);
    } else {
        setStore(mainStore);
    }
    setDefaultAttachmentContentStore(getStoreConfiguration().getXWikiAttachmentStore());
    setVersioningStore(getStoreConfiguration().getXWikiVersioningStore());
    setDefaultAttachmentArchiveStore(getStoreConfiguration().getAttachmentVersioningStore());
    setRecycleBinStore(getStoreConfiguration().getXWikiRecycleBinStore());
    setAttachmentRecycleBinStore(getStoreConfiguration().getAttachmentRecycleBinStore());
}
Also used : XWikiCacheStoreInterface(com.xpn.xwiki.store.XWikiCacheStoreInterface) XWikiStoreInterface(com.xpn.xwiki.store.XWikiStoreInterface)

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