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) {
}
}
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);
}
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());
}
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;
}
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());
}
Aggregations