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())));
}
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());
}
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);
}
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());
}
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());
}
Aggregations