@Test public void restoreAuthor() throws XWikiException { assertNull(this.oldcore.getXWikiContext().getAuthorReference()); assertNull(this.oldcore.getXWikiContext().get(XWikiDocument.CKEY_SDOC)); assertNull(this.oldcore.getXWikiContext().getUserReference()); DocumentReference authorReference = new DocumentReference("authorwiki", "authorspace", "author"); Map<String, Serializable> contextStore = new HashMap<>(); contextStore.put(XWikiContextContextStore.PROP_SECURE_AUTHOR, authorReference); this.store.restore(contextStore); assertEquals(this.oldcore.getXWikiContext().getUserReference(), authorReference); XWikiDocument secureDocument1 = (XWikiDocument) this.oldcore.getXWikiContext().get(XWikiDocument.CKEY_SDOC); assertNotNull(secureDocument1); assertEquals(new DocumentReference("authorwiki", "SUSpace", "SUPage"), secureDocument1.getDocumentReference()); assertEquals(authorReference, secureDocument1.getContentAuthorReference()); assertEquals(authorReference, this.oldcore.getXWikiContext().getAuthorReference()); this.store.restore(contextStore); assertEquals(this.oldcore.getXWikiContext().getUserReference(), authorReference); XWikiDocument secureDocument2 = (XWikiDocument) this.oldcore.getXWikiContext().get(XWikiDocument.CKEY_SDOC); assertNotNull(secureDocument2); assertNotSame(secureDocument1, secureDocument2); assertEquals(new DocumentReference("authorwiki", "SUSpace", "SUPage"), secureDocument2.getDocumentReference()); assertEquals(authorReference, secureDocument2.getContentAuthorReference()); assertEquals(authorReference, this.oldcore.getXWikiContext().getAuthorReference()); DocumentReference secureDocumentReference = new DocumentReference("securewiki", "securespace", "securedocument"); contextStore.put(XWikiContextContextStore.PROP_SECURE_DOCUMENT, secureDocumentReference); this.store.restore(contextStore); assertEquals(this.oldcore.getXWikiContext().getUserReference(), authorReference); XWikiDocument secureDocument3 = (XWikiDocument) this.oldcore.getXWikiContext().get(XWikiDocument.CKEY_SDOC); assertNotNull(secureDocument3); assertEquals(secureDocumentReference, secureDocument3.getDocumentReference()); assertEquals(authorReference, secureDocument3.getContentAuthorReference()); assertEquals(authorReference, this.oldcore.getXWikiContext().getAuthorReference()); assertNotSame(this.oldcore.getSpyXWiki().getDocument(secureDocumentReference, this.oldcore.getXWikiContext()), secureDocument3); }
private void restoreAuthor(Map<String, Serializable> contextStore, XWikiContext xcontext) { if (contextStore.containsKey(PROP_SECURE_AUTHOR)) { DocumentReference authorReference = (DocumentReference) contextStore.get(PROP_SECURE_AUTHOR); restoreAuthor(contextStore, authorReference, xcontext); } }
XWikiContextContextStore extends AbstractContextStore { private void restoreAuthor(Map<String, Serializable> contextStore, XWikiContext xcontext) { if (contextStore.containsKey(PROP_SECURE_AUTHOR)) { DocumentReference authorReference = (DocumentReference) contextStore.get(PROP_SECURE_AUTHOR); restoreAuthor(contextStore, authorReference, xcontext); } } }
XWikiContextContextStore extends AbstractContextStore { private void restoreAuthor(Map<String, Serializable> contextStore, XWikiContext xcontext) { if (contextStore.containsKey(PROP_SECURE_AUTHOR)) { DocumentReference authorReference = (DocumentReference) contextStore.get(PROP_SECURE_AUTHOR); restoreAuthor(contextStore, authorReference, xcontext); } } XWikiContextContextStore(); }
XWikiContextContextStore extends AbstractContextStore { private void restoreAuthor(Map<String, Serializable> contextStore, XWikiContext xcontext) { if (contextStore.containsKey(PROP_SECURE_AUTHOR)) { DocumentReference authorReference = (DocumentReference) contextStore.get(PROP_SECURE_AUTHOR); restoreAuthor(contextStore, authorReference, xcontext); } } XWikiContextContextStore(); @Override void save(Map<String, Serializable> contextStore, Collection<String> entries); @Override void restore(Map<String, Serializable> contextStore); }
XWikiContextContextStore extends AbstractContextStore { private void restoreAuthor(Map<String, Serializable> contextStore, XWikiContext xcontext) { if (contextStore.containsKey(PROP_SECURE_AUTHOR)) { DocumentReference authorReference = (DocumentReference) contextStore.get(PROP_SECURE_AUTHOR); restoreAuthor(contextStore, authorReference, xcontext); } } XWikiContextContextStore(); @Override void save(Map<String, Serializable> contextStore, Collection<String> entries); @Override void restore(Map<String, Serializable> contextStore); static final String PROP_WIKI; static final String PROP_USER; static final String PROP_SECURE_AUTHOR; static final String PROP_SECURE_DOCUMENT; static final String PROP_LOCALE; static final String PREFIX_PROP_REQUEST; static final String SUFFIX_PROP_REQUEST_BASE; static final String SUFFIX_PROP_REQUEST_URL; static final String SUFFIX_PROP_REQUEST_CONTEXTPATH; static final String SUFFIX_PROP_REQUEST_PARAMETERS; static final String SUFFIX_PROP_REQUEST_WIKI; static final String PROP_REQUEST_BASE; static final String PROP_REQUEST_URL; static final String PROP_REQUEST_CONTEXTPATH; static final String PROP_REQUEST_PARAMETERS; static final String PROP_REQUEST_WIKI; static final String PREFIX_PROP_DOCUMENT; static final String SUFFIX_PROP_DOCUMENT_REFERENCE; static final String PROP_DOCUMENT_REFERENCE; }