use of com.enonic.xp.repository.EditableRepository in project xp by enonic.
the class ModifyRepositoryHandlerTest method modifyScoped.
@Test
void modifyScoped() throws Exception {
runScript("/lib/xp/examples/repo/modifyScoped.js");
ArgumentCaptor<UpdateRepositoryParams> captor = ArgumentCaptor.forClass(UpdateRepositoryParams.class);
Mockito.verify(this.repositoryService, Mockito.times(1)).updateRepository(captor.capture());
final UpdateRepositoryParams capturedParams = captor.getValue();
final EditableRepository edited = new EditableRepository(MOCK_REPO);
capturedParams.getEditor().accept(edited);
assertEquals("toBeModified", edited.source.getData().getString("myScopedObject.myScopedString"), "Test is invalid");
assertEquals("modified", edited.data.getString("myScopedObject.myScopedString"));
assertEquals("toBeKeptValue", edited.data.getString("toBeKept"));
final BinaryAttachment attachment = edited.binaryAttachments.get(0);
assertEquals(BinaryReference.from("myFile"), attachment.getReference());
assertTrue(attachment.getByteSource().contentEquals(ByteSource.wrap("Hello World".getBytes())));
}
use of com.enonic.xp.repository.EditableRepository in project xp by enonic.
the class ModifyRepositoryHandlerTest method modifyRemoveProperty.
@Test
void modifyRemoveProperty() {
runScript("/lib/xp/examples/repo/modifyRemoveProperty.js");
ArgumentCaptor<UpdateRepositoryParams> captor = ArgumentCaptor.forClass(UpdateRepositoryParams.class);
Mockito.verify(this.repositoryService, Mockito.times(1)).updateRepository(captor.capture());
final UpdateRepositoryParams capturedParams = captor.getValue();
final EditableRepository edited = new EditableRepository(MOCK_REPO);
capturedParams.getEditor().accept(edited);
assertTrue(edited.source.getData().hasProperty("myScopedObject"), "Test is invalid");
assertFalse(edited.data.hasProperty("myScopedObject"));
}
use of com.enonic.xp.repository.EditableRepository in project xp by enonic.
the class RepositoryServiceImpl method doUpdateRepository.
private Repository doUpdateRepository(final UpdateRepositoryParams updateRepositoryParams, Repository previousRepository) {
RepositoryId repositoryId = updateRepositoryParams.getRepositoryId();
previousRepository = previousRepository == null ? repositoryEntryService.getRepositoryEntry(repositoryId) : previousRepository;
if (previousRepository == null) {
throw new RepositoryNotFoundException(repositoryId);
}
final EditableRepository editableRepository = new EditableRepository(previousRepository);
updateRepositoryParams.getEditor().accept(editableRepository);
UpdateRepositoryEntryParams params = UpdateRepositoryEntryParams.create().repositoryId(repositoryId).repositoryData(editableRepository.data).attachments(ImmutableList.copyOf(editableRepository.binaryAttachments)).build();
return repositoryEntryService.updateRepositoryEntry(params);
}
use of com.enonic.xp.repository.EditableRepository 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