use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class UpdateNodeCommandTest method keep_existing_binaries_also_when_new_property_but_equal_BinaryReference.
@Test
public void keep_existing_binaries_also_when_new_property_but_equal_BinaryReference() 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 -> {
toBeEdited.data.removeProperties("my-image");
toBeEdited.data.setBinaryReference("my-image", binaryRef);
}).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 new_binary_ref_to_already_attached_binary.
@Test
public void new_binary_ref_to_already_attached_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;
nodeData.addBinaryReference("my-image-copy", binaryRef);
}).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 NodeVersionServiceImplTest method getVersion.
@Test
public void getVersion() throws Exception {
final CreateNodeParams createNodeParams = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).build();
final Node createdNode = createNode(createNodeParams);
final NodeVersion nodeVersion = nodeDao.get(getNodeVersionKey(createdNode), createInternalContext());
assertEquals(createdNode.id(), nodeVersion.getId());
assertEquals(createdNode.data(), nodeVersion.getData());
}
use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class NodeVersionServiceImplTest method getVersionCorrupted.
@Test
public void getVersionCorrupted() throws Exception {
final CreateNodeParams createNodeParams = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).build();
final Node createdNode = createNode(createNodeParams);
final NodeVersionKey nodeVersionKey = getNodeVersionKey(createdNode);
final Segment segment = createSegment(NODE_SEGMENT_LEVEL);
final BlobRecord blob = this.blobStore.getRecord(segment, nodeVersionKey.getNodeBlobKey());
byte[] blobData = blob.getBytes().read();
blobData = Arrays.copyOf(blobData, blobData.length / 2);
final MemoryBlobRecord corruptedBlob = new MemoryBlobRecord(blob.getKey(), ByteSource.wrap(blobData));
this.blobStore.addRecord(segment, corruptedBlob);
try {
nodeDao.get(nodeVersionKey, createInternalContext());
fail("Expected exception");
} catch (RuntimeException e) {
assertTrue(e.getMessage().startsWith("Failed to load blobs with keys"));
}
}
use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class NodeVersionServiceImplTest method avoidCachingVersionCorrupted.
@Test
public void avoidCachingVersionCorrupted() throws Exception {
final CachedBlobStore cachedBlobStore = CachedBlobStore.create().blobStore(this.blobStore).build();
this.nodeDao.setBlobStore(cachedBlobStore);
final CreateNodeParams createNodeParams = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).build();
final Node createdNode = createNode(createNodeParams);
final NodeVersionKey nodeVersionKey = getNodeVersionKey(createdNode);
final Segment segment = createSegment(NODE_SEGMENT_LEVEL);
final BlobRecord blob = this.blobStore.getRecord(segment, nodeVersionKey.getNodeBlobKey());
final byte[] blobData = blob.getBytes().read();
final byte[] blobDataTruncated = Arrays.copyOf(blobData, blobData.length / 2);
final MemoryBlobRecord corruptedBlob = new MemoryBlobRecord(blob.getKey(), ByteSource.wrap(blobDataTruncated));
this.blobStore.addRecord(segment, corruptedBlob);
cachedBlobStore.invalidate(segment, blob.getKey());
try {
nodeDao.get(nodeVersionKey, createInternalContext());
fail("Expected exception");
} catch (RuntimeException e) {
assertTrue(e.getMessage().startsWith("Failed to load blobs with keys"));
}
// restore original blob in source blob store
this.blobStore.addRecord(segment, blob);
final NodeVersion nodeVersion = nodeDao.get(nodeVersionKey, createInternalContext());
assertNotNull(nodeVersion);
}
Aggregations