Search in sources :

Example 6 with UpdateRepositoryParams

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())));
}
Also used : UpdateRepositoryParams(com.enonic.xp.repository.UpdateRepositoryParams) EditableRepository(com.enonic.xp.repository.EditableRepository) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) Test(org.junit.jupiter.api.Test)

Aggregations

UpdateRepositoryParams (com.enonic.xp.repository.UpdateRepositoryParams)6 BinaryAttachment (com.enonic.xp.node.BinaryAttachment)4 RepositoryId (com.enonic.xp.repository.RepositoryId)3 Attachment (com.enonic.xp.attachment.Attachment)2 AttachmentSerializer (com.enonic.xp.attachment.AttachmentSerializer)2 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)2 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)2 Context (com.enonic.xp.context.Context)2 ContextAccessor (com.enonic.xp.context.ContextAccessor)2 ContextBuilder (com.enonic.xp.context.ContextBuilder)2 ArchiveInitializer (com.enonic.xp.core.impl.project.init.ArchiveInitializer)2 ContentInitializer (com.enonic.xp.core.impl.project.init.ContentInitializer)2 IssueInitializer (com.enonic.xp.core.impl.project.init.IssueInitializer)2 PropertySet (com.enonic.xp.data.PropertySet)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 EventPublisher (com.enonic.xp.event.EventPublisher)2 ImageHelper (com.enonic.xp.image.ImageHelper)2 IndexService (com.enonic.xp.index.IndexService)2 NodeService (com.enonic.xp.node.NodeService)2 CreateProjectParams (com.enonic.xp.project.CreateProjectParams)2