Search in sources :

Example 11 with BinaryReference

use of com.enonic.xp.util.BinaryReference in project xp by enonic.

the class RepoDumperTest method binaries_with_versions.

@Test
public void binaries_with_versions() throws Exception {
    final BinaryReference ref1 = BinaryReference.from("fisk");
    final BinaryReference ref2 = BinaryReference.from("fisk2");
    final PropertyTree data = new PropertyTree();
    data.addBinaryReference("myBinaryRef", ref1);
    final Node node1 = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("myName").data(data).attachBinary(ref1, ByteSource.wrap("myBinaryData".getBytes())).build());
    final AttachedBinary originalBinary = node1.getAttachedBinaries().getByBinaryReference(ref1);
    final Node updatedNode = updateNode(UpdateNodeParams.create().id(node1.id()).editor((e) -> {
    }).attachBinary(ref2, ByteSource.wrap("myOtherBinaryData".getBytes())).build());
    final AttachedBinary updateBinary = updatedNode.getAttachedBinaries().getByBinaryReference(ref1);
    final TestDumpWriter writer = new TestDumpWriter();
    doDump(writer);
    assertTrue(writer.getBinaries().contains(BlobKey.from(originalBinary.getBlobKey())));
    assertTrue(writer.getBinaries().contains(BlobKey.from(updateBinary.getBlobKey())));
}
Also used : BinaryReference(com.enonic.xp.util.BinaryReference) BeforeEach(org.junit.jupiter.api.BeforeEach) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) BranchDumpEntry(com.enonic.xp.repo.impl.dump.model.BranchDumpEntry) Node(com.enonic.xp.node.Node) NodePath(com.enonic.xp.node.NodePath) BlobKey(com.enonic.xp.blob.BlobKey) AttachedBinary(com.enonic.xp.node.AttachedBinary) NodeHelper(com.enonic.xp.repo.impl.node.NodeHelper) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Test(org.junit.jupiter.api.Test) List(java.util.List) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) BinaryReference(com.enonic.xp.util.BinaryReference) AttachedBinary(com.enonic.xp.node.AttachedBinary) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 12 with BinaryReference

use of com.enonic.xp.util.BinaryReference in project xp by enonic.

the class DuplicateNodeCommandTest method attachments_duplicated.

@Test
public void attachments_duplicated() throws Exception {
    final String nodeName = "my-node";
    final PropertyTree data = new PropertyTree();
    final BinaryReference binaryRef1 = BinaryReference.from("image1.jpg");
    final BinaryReference binaryRef2 = BinaryReference.from("image2.jpg");
    data.addBinaryReference("my-image-1", binaryRef1);
    data.addBinaryReference("my-image-2", binaryRef2);
    final Node createdNode = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name(nodeName).data(data).attachBinary(binaryRef1, ByteSource.wrap("this-is-the-binary-data-for-image1".getBytes())).attachBinary(binaryRef2, ByteSource.wrap("this-is-the-binary-data-for-image2".getBytes())).build());
    final Node duplicatedNode = duplicateNode(createdNode).getNode();
    assertDuplicatedTree(createdNode.path(), createdNode, duplicatedNode);
    assertEquals(nodeName + "-" + DuplicateValueResolver.COPY_TOKEN, duplicatedNode.name().toString());
    assertEquals(2, duplicatedNode.getAttachedBinaries().getSize());
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) BinaryReference(com.enonic.xp.util.BinaryReference) Test(org.junit.jupiter.api.Test)

Example 13 with BinaryReference

use of com.enonic.xp.util.BinaryReference in project xp by enonic.

the class GetBinaryByVersionCommandTest method testExecute.

@Test
public void testExecute() {
    final PropertyTree data = new PropertyTree();
    final BinaryReference imageRef = BinaryReference.from("myImage");
    data.addBinaryReferences("myBinary", imageRef);
    final Node node = createNode(CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).data(data).attachBinary(imageRef, ByteSource.wrap("thisIsMyImage".getBytes())).build());
    final ByteSource myImage = GetBinaryByVersionCommand.create().nodeId(node.id()).nodeVersionId(node.getNodeVersionId()).binaryReference(imageRef).indexServiceInternal(this.indexServiceInternal).binaryService(this.binaryService).storageService(this.storageService).searchService(this.searchService).build().execute();
    assertNotNull(myImage);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) ByteSource(com.google.common.io.ByteSource) BinaryReference(com.enonic.xp.util.BinaryReference) Test(org.junit.jupiter.api.Test)

Example 14 with BinaryReference

use of com.enonic.xp.util.BinaryReference in project xp by enonic.

the class NodeServiceImplTest method test_duplicate_binary.

@Test
public void test_duplicate_binary() {
    final PropertyTree data = new PropertyTree();
    final BinaryReference binaryRef1 = BinaryReference.from("binary");
    data.addBinaryReference("my-binary-1", binaryRef1);
    final String binarySource = "binary_source";
    final Node node = this.nodeService.create(CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).data(data).attachBinary(binaryRef1, ByteSource.wrap(binarySource.getBytes())).build());
    this.nodeService.refresh(RefreshMode.SEARCH);
    final Node duplicatedNode = this.nodeService.duplicate(DuplicateNodeParams.create().nodeId(node.id()).build());
    assertNotEquals(node, duplicatedNode);
    assertEquals(node.getAttachedBinaries(), duplicatedNode.getAttachedBinaries());
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) BinaryReference(com.enonic.xp.util.BinaryReference) Test(org.junit.jupiter.api.Test)

Example 15 with BinaryReference

use of com.enonic.xp.util.BinaryReference in project xp by enonic.

the class UpdateNodeCommandTest method unreferred_binary_attachment_ignored.

@Test
public void unreferred_binary_attachment_ignored() throws Exception {
    final PropertyTree data = new PropertyTree();
    final BinaryReference binaryRef = BinaryReference.from("my-car.jpg");
    data.setBinaryReference("my-image", binaryRef);
    final CreateNodeParams params = CreateNodeParams.create().parent(NodePath.ROOT).name("my-node").data(data).attachBinary(binaryRef, ByteSource.wrap("my-car-image-source".getBytes())).build();
    final Node node = createNode(params);
    final UpdateNodeParams updateNodeParams = UpdateNodeParams.create().editor(toBeEdited -> {
        final PropertyTree nodeData = toBeEdited.data;
        nodeData.addString("newValue", "hepp");
    }).attachBinary(BinaryReference.from("unreferred binary"), ByteSource.wrap("nothing to see here".getBytes())).id(node.id()).build();
    final Node updatedNode = updateNode(updateNodeParams);
    assertEquals(1, updatedNode.getAttachedBinaries().getSize());
}
Also used : BinaryReference(com.enonic.xp.util.BinaryReference) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Node(com.enonic.xp.node.Node) NodePath(com.enonic.xp.node.NodePath) StandardCharsets(java.nio.charset.StandardCharsets) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Test(org.junit.jupiter.api.Test) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ByteStreams(com.google.common.io.ByteStreams) NodeBinaryReferenceException(com.enonic.xp.node.NodeBinaryReferenceException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) BinaryReference(com.enonic.xp.util.BinaryReference) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Test(org.junit.jupiter.api.Test)

Aggregations

BinaryReference (com.enonic.xp.util.BinaryReference)37 Test (org.junit.jupiter.api.Test)26 PropertyTree (com.enonic.xp.data.PropertyTree)25 Node (com.enonic.xp.node.Node)23 ByteSource (com.google.common.io.ByteSource)16 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)13 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)12 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)8 AttachedBinary (com.enonic.xp.node.AttachedBinary)7 NodePath (com.enonic.xp.node.NodePath)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 BinaryAttachment (com.enonic.xp.node.BinaryAttachment)5 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)5 Attachment (com.enonic.xp.attachment.Attachment)4 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)4 NodeExportResult (com.enonic.xp.export.NodeExportResult)3 NodeBinaryReferenceException (com.enonic.xp.node.NodeBinaryReferenceException)3 NodeHelper (com.enonic.xp.repo.impl.node.NodeHelper)3 ByteStreams (com.google.common.io.ByteStreams)3