use of com.enonic.xp.repository.UpdateRepositoryParams in project xp by enonic.
the class ModifyRepositoryHandlerTest method modify.
@Test
void modify() throws Exception {
runScript("/lib/xp/examples/repo/modify.js");
ArgumentCaptor<UpdateRepositoryParams> captor = ArgumentCaptor.forClass(UpdateRepositoryParams.class);
Mockito.verify(this.repositoryService, Mockito.times(1)).updateRepository(captor.capture());
final UpdateRepositoryParams capturedParams = captor.getValue();
assertEquals(RepositoryId.from("my-repo"), capturedParams.getRepositoryId());
final EditableRepository edited = new EditableRepository(MOCK_REPO);
capturedParams.getEditor().accept(edited);
assertSame(MOCK_REPO, edited.source);
assertEquals("modified", edited.data.getString("myString"));
assertTrue(edited.source.getData().hasProperty("toBeRemoved"));
assertFalse(edited.data.hasProperty("toBeRemoved"));
final BinaryAttachment attachment = edited.binaryAttachments.get(0);
assertEquals(BinaryReference.from("myFile"), attachment.getReference());
assertTrue(attachment.getByteSource().contentEquals(ByteSource.wrap("Hello World".getBytes())));
}
Aggregations