use of org.xwiki.model.reference.BlockReference in project xwiki-platform by xwiki.
the class DefaultSignatureStoreTest method testRetrievingExistingSignature.
@Test
public void testRetrievingExistingSignature() throws Exception {
XWikiDocument sourceDocument = mock(XWikiDocument.class);
when(this.xwiki.getDocument(new DocumentReference("wiki", "space", "document"), this.xcontext)).thenReturn(sourceDocument);
BaseObject signatureObject = mock(BaseObject.class);
when(sourceDocument.getXObject(new DocumentReference(DefaultSignatureStore.SIGNATURECLASS, new WikiReference("wiki")), DefaultSignatureStore.SIGNATURECLASS_PROP_REFERENCE, "block")).thenReturn(signatureObject);
when(signatureObject.getLargeStringValue(DefaultSignatureStore.SIGNATURECLASS_PROP_SIGNATURE)).thenReturn(ENCODED_SIGNATURE);
assertThat(this.store.retrieve(new BlockReference("block", new DocumentReference("wiki", "space", "document"))), equalTo(SIGNATURE));
}
use of org.xwiki.model.reference.BlockReference in project xwiki-platform by xwiki.
the class DefaultSignatureStoreTest method testUpdatingSignature.
@Test
public void testUpdatingSignature() throws Exception {
XWikiDocument sourceDocument = mock(XWikiDocument.class);
when(this.xwiki.getDocument(new DocumentReference("wiki", "space", "document"), this.xcontext)).thenReturn(sourceDocument);
BaseObject signatureObject = mock(BaseObject.class);
when(sourceDocument.getXObject(new DocumentReference(DefaultSignatureStore.SIGNATURECLASS, new WikiReference("wiki")), DefaultSignatureStore.SIGNATURECLASS_PROP_REFERENCE, "block")).thenReturn(signatureObject);
this.store.store(new BlockReference("block", new DocumentReference("wiki", "space", "document")), SIGNATURE);
verify(signatureObject, never()).setStringValue(eq(DefaultSignatureStore.SIGNATURECLASS_PROP_REFERENCE), any(String.class));
verify(signatureObject).setLargeStringValue(DefaultSignatureStore.SIGNATURECLASS_PROP_SIGNATURE, ENCODED_SIGNATURE);
verify(this.xwiki).saveDocument(sourceDocument, this.xcontext);
}
use of org.xwiki.model.reference.BlockReference in project xwiki-platform by xwiki.
the class SignedMacroBlockReferenceResolverTest method testResolveWithParent.
@Test
public void testResolveWithParent() throws Exception {
DocumentReference parent = new DocumentReference("wiki", "space", "name");
assertThat(mocker.getComponentUnderTest().resolve(BLOCK, parent), equalTo(new BlockReference(ENCODED, parent)));
verify(dumper).dump(stream, BLOCK);
}
use of org.xwiki.model.reference.BlockReference in project xwiki-platform by xwiki.
the class SignedMacroBlockReferenceResolver method resolve.
/**
* {@inheritDoc}
*
* This implementation is specific for macro blocks. The block argument could be either
* a {@link org.xwiki.rendering.block.MacroBlock} or a {@link org.xwiki.rendering.block.MacroMarkerBlock}.
*/
@Override
public BlockReference resolve(Block block, Object... parameters) {
EntityReference parent = null;
if (parameters.length > 0 && parameters[0] instanceof EntityReference) {
// Try to extract the type from the passed parameter.
parent = (EntityReference) parameters[0];
}
Digest digest = digestFactory.getInstance();
try {
dumper.dump(digest.getOutputStream(), block);
return new BlockReference(new EntityReference(encoder.encode(digest.digest()), EntityType.BLOCK, parent));
} catch (IOException ignore) {
// Ignored
}
return null;
}
use of org.xwiki.model.reference.BlockReference in project xwiki-platform by xwiki.
the class DefaultSignatureStoreTest method testStoringNewSignature.
@Test
public void testStoringNewSignature() throws Exception {
XWikiDocument sourceDocument = mock(XWikiDocument.class);
when(this.xwiki.getDocument(new DocumentReference("wiki", "space", "document"), this.xcontext)).thenReturn(sourceDocument);
BaseObject signatureObject = mock(BaseObject.class);
when(sourceDocument.newXObject(DefaultSignatureStore.SIGNATURECLASS, this.xcontext)).thenReturn(signatureObject);
this.store.store(new BlockReference("block", new DocumentReference("wiki", "space", "document")), SIGNATURE);
verify(signatureObject).setStringValue(DefaultSignatureStore.SIGNATURECLASS_PROP_REFERENCE, "block");
verify(signatureObject).setLargeStringValue(DefaultSignatureStore.SIGNATURECLASS_PROP_SIGNATURE, ENCODED_SIGNATURE);
verify(this.xwiki).saveDocument(sourceDocument, this.xcontext);
}
Aggregations