use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class UpdateNodeCommandTest method keep_existing_binaries.
@Test
public void keep_existing_binaries() 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");
}).id(node.id()).build();
final Node updatedNode = updateNode(updateNodeParams);
assertEquals(1, updatedNode.getAttachedBinaries().getSize());
}
use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class UpdateNodeCommandTest method add_new_binary.
@Test
public void add_new_binary() 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;
final BinaryReference newBinaryRef = BinaryReference.from("my-other-car.jpg");
nodeData.addBinaryReferences("new-binary", newBinaryRef);
}).attachBinary(BinaryReference.from("my-other-car.jpg"), ByteSource.wrap("my-new-binary".getBytes())).id(node.id()).build();
final Node updatedNode = updateNode(updateNodeParams);
assertEquals(2, updatedNode.getAttachedBinaries().getSize());
}
use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class UpdateNodeCommandTest method try_add_new_without_source.
@Test
public void try_add_new_without_source() 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.addBinaryReferences("piratedValue", BinaryReference.from("new-binary-ref"));
}).id(node.id()).build();
assertThrows(NodeBinaryReferenceException.class, () -> updateNode(updateNodeParams));
}
use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class UpdateNodeCommandTest method update_existing_binary.
@Test
public void update_existing_binary() 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, originalBinaryData()).build();
final Node node = createNode(params);
// Update the binary source of the binary reference
final ByteSource updatedBinaryData = ByteSource.wrap("my-car-image-updated-source".getBytes());
final UpdateNodeParams updateNodeParams = UpdateNodeParams.create().editor(toBeEdited -> {
}).attachBinary(binaryRef, updatedBinaryData).id(node.id()).build();
final Node updatedNode = updateNode(updateNodeParams);
assertEquals(1, updatedNode.getAttachedBinaries().getSize());
// Verify that the binary source for binary ref in the updated node is the updated version
final ByteSource binary = GetBinaryCommand.create().nodeId(updatedNode.id()).binaryReference(binaryRef).indexServiceInternal(this.indexServiceInternal).binaryService(this.binaryService).storageService(this.storageService).searchService(this.searchService).build().execute();
final byte[] bytes = ByteStreams.toByteArray(binary.openStream());
assertEquals("my-car-image-updated-source", new String(bytes, StandardCharsets.UTF_8));
}
use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class UpdateNodeCommandTest method try_setting_new_binary_into_existing_property.
@Test
public void try_setting_new_binary_into_existing_property() 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.addBinaryReferences("my-image", BinaryReference.from("pirated-reference"));
}).id(node.id()).build();
assertThrows(NodeBinaryReferenceException.class, () -> updateNode(updateNodeParams));
}
Aggregations