@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); }
@Override public void store(EntityReference entity, byte[] signature) throws SignatureStoreException { checkArguments(entity); DocumentReference docRef = this.resolver.resolve(entity.getParent()); XWikiContext context = this.contextProvider.get(); try { XWikiDocument document = context.getWiki().getDocument(docRef, context); DocumentReference signatureClass = new DocumentReference(SIGNATURECLASS, docRef.getWikiReference()); String entityReference = entity.getName(); BaseObject object = document.getXObject(signatureClass, SIGNATURECLASS_PROP_REFERENCE, entityReference); if (object == null) { object = document.newXObject(SIGNATURECLASS, context); object.setStringValue(SIGNATURECLASS_PROP_REFERENCE, entityReference); } object.setLargeStringValue(SIGNATURECLASS_PROP_SIGNATURE, this.base64.encode(signature, 64)); context.getWiki().saveDocument(document, context); } catch (XWikiException e) { throw new SignatureStoreException("Error while storing signature for entity [" + entity + "]", e); } catch (IOException e) { throw new SignatureStoreException("Error while encoding signature for entity [" + entity + "]", e); } }
DefaultSignatureStore implements SignatureStore { @Override public void store(EntityReference entity, byte[] signature) throws SignatureStoreException { checkArguments(entity); DocumentReference docRef = this.resolver.resolve(entity.getParent()); XWikiContext context = this.contextProvider.get(); try { XWikiDocument document = context.getWiki().getDocument(docRef, context); DocumentReference signatureClass = new DocumentReference(SIGNATURECLASS, docRef.getWikiReference()); String entityReference = entity.getName(); BaseObject object = document.getXObject(signatureClass, SIGNATURECLASS_PROP_REFERENCE, entityReference); if (object == null) { object = document.newXObject(SIGNATURECLASS, context); object.setStringValue(SIGNATURECLASS_PROP_REFERENCE, entityReference); } object.setLargeStringValue(SIGNATURECLASS_PROP_SIGNATURE, this.base64.encode(signature, 64)); context.getWiki().saveDocument(document, context); } catch (XWikiException e) { throw new SignatureStoreException("Error while storing signature for entity [" + entity + "]", e); } catch (IOException e) { throw new SignatureStoreException("Error while encoding signature for entity [" + entity + "]", e); } } }
DefaultSignatureStore implements SignatureStore { @Override public void store(EntityReference entity, byte[] signature) throws SignatureStoreException { checkArguments(entity); DocumentReference docRef = this.resolver.resolve(entity.getParent()); XWikiContext context = this.contextProvider.get(); try { XWikiDocument document = context.getWiki().getDocument(docRef, context); DocumentReference signatureClass = new DocumentReference(SIGNATURECLASS, docRef.getWikiReference()); String entityReference = entity.getName(); BaseObject object = document.getXObject(signatureClass, SIGNATURECLASS_PROP_REFERENCE, entityReference); if (object == null) { object = document.newXObject(SIGNATURECLASS, context); object.setStringValue(SIGNATURECLASS_PROP_REFERENCE, entityReference); } object.setLargeStringValue(SIGNATURECLASS_PROP_SIGNATURE, this.base64.encode(signature, 64)); context.getWiki().saveDocument(document, context); } catch (XWikiException e) { throw new SignatureStoreException("Error while storing signature for entity [" + entity + "]", e); } catch (IOException e) { throw new SignatureStoreException("Error while encoding signature for entity [" + entity + "]", e); } }  }
DefaultSignatureStore implements SignatureStore { @Override public void store(EntityReference entity, byte[] signature) throws SignatureStoreException { checkArguments(entity); DocumentReference docRef = this.resolver.resolve(entity.getParent()); XWikiContext context = this.contextProvider.get(); try { XWikiDocument document = context.getWiki().getDocument(docRef, context); DocumentReference signatureClass = new DocumentReference(SIGNATURECLASS, docRef.getWikiReference()); String entityReference = entity.getName(); BaseObject object = document.getXObject(signatureClass, SIGNATURECLASS_PROP_REFERENCE, entityReference); if (object == null) { object = document.newXObject(SIGNATURECLASS, context); object.setStringValue(SIGNATURECLASS_PROP_REFERENCE, entityReference); } object.setLargeStringValue(SIGNATURECLASS_PROP_SIGNATURE, this.base64.encode(signature, 64)); context.getWiki().saveDocument(document, context); } catch (XWikiException e) { throw new SignatureStoreException("Error while storing signature for entity [" + entity + "]", e); } catch (IOException e) { throw new SignatureStoreException("Error while encoding signature for entity [" + entity + "]", e); } }  @Override void store(EntityReference entity, byte[] signature); @Override byte[] retrieve(EntityReference entity); }
DefaultSignatureStore implements SignatureStore { @Override public void store(EntityReference entity, byte[] signature) throws SignatureStoreException { checkArguments(entity); DocumentReference docRef = this.resolver.resolve(entity.getParent()); XWikiContext context = this.contextProvider.get(); try { XWikiDocument document = context.getWiki().getDocument(docRef, context); DocumentReference signatureClass = new DocumentReference(SIGNATURECLASS, docRef.getWikiReference()); String entityReference = entity.getName(); BaseObject object = document.getXObject(signatureClass, SIGNATURECLASS_PROP_REFERENCE, entityReference); if (object == null) { object = document.newXObject(SIGNATURECLASS, context); object.setStringValue(SIGNATURECLASS_PROP_REFERENCE, entityReference); } object.setLargeStringValue(SIGNATURECLASS_PROP_SIGNATURE, this.base64.encode(signature, 64)); context.getWiki().saveDocument(document, context); } catch (XWikiException e) { throw new SignatureStoreException("Error while storing signature for entity [" + entity + "]", e); } catch (IOException e) { throw new SignatureStoreException("Error while encoding signature for entity [" + entity + "]", e); } }  @Override void store(EntityReference entity, byte[] signature); @Override byte[] retrieve(EntityReference entity); static final LocalDocumentReference SIGNATURECLASS; static final String SIGNATURECLASS_PROP_REFERENCE; static final String SIGNATURECLASS_PROP_SIGNATURE; }