Search in sources :

Example 1 with BlockReference

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));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BlockReference(org.xwiki.model.reference.BlockReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 2 with BlockReference

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);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BlockReference(org.xwiki.model.reference.BlockReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 3 with BlockReference

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);
}
Also used : BlockReference(org.xwiki.model.reference.BlockReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 4 with BlockReference

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;
}
Also used : BlockReference(org.xwiki.model.reference.BlockReference) Digest(org.xwiki.crypto.Digest) EntityReference(org.xwiki.model.reference.EntityReference) IOException(java.io.IOException)

Example 5 with BlockReference

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);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BlockReference(org.xwiki.model.reference.BlockReference) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Aggregations

BlockReference (org.xwiki.model.reference.BlockReference)6 Test (org.junit.Test)5 DocumentReference (org.xwiki.model.reference.DocumentReference)5 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)4 BaseObject (com.xpn.xwiki.objects.BaseObject)3 WikiReference (org.xwiki.model.reference.WikiReference)3 IOException (java.io.IOException)1 Digest (org.xwiki.crypto.Digest)1 EntityReference (org.xwiki.model.reference.EntityReference)1