use of com.enonic.xp.blob.NodeVersionKey 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);
}
use of com.enonic.xp.blob.NodeVersionKey in project xp by enonic.
the class NodeVersionServiceImplTest method store.
@Test
public void store() throws Exception {
final PropertyTree data = new PropertyTree();
data.addString("myName", "myValue");
final NodeVersion nodeVersion = NodeVersion.create().nodeType(NodeType.DEFAULT_NODE_COLLECTION).id(new NodeId()).childOrder(ChildOrder.defaultOrder()).data(data).build();
final NodeVersionKey nodeVersionKey = nodeDao.store(nodeVersion, createInternalContext());
assertNotNull(nodeVersionKey);
final BlobRecord nodeBlobRecord = blobStore.getRecord(createSegment(NODE_SEGMENT_LEVEL), nodeVersionKey.getNodeBlobKey());
assertNotNull(nodeBlobRecord);
final BlobRecord indexBlobRecord = blobStore.getRecord(createSegment(INDEX_CONFIG_SEGMENT_LEVEL), nodeVersionKey.getIndexConfigBlobKey());
assertNotNull(indexBlobRecord);
}
use of com.enonic.xp.blob.NodeVersionKey in project xp by enonic.
the class NodeStorageServiceImplTest method testGetNode_NodeVersionNotFound.
@Test
public void testGetNode_NodeVersionNotFound() {
when(versionService.getVersion(any(NodeId.class), any(NodeVersionId.class), any(InternalContext.class))).thenReturn(NodeVersionMetadata.create().nodeVersionKey(versionKey).build());
when(nodeVersionService.get(any(NodeVersionKey.class), any(InternalContext.class))).thenReturn(null);
final Node result = instance.getNode(nodeId, nodeVersionId, context);
assertNull(result);
verify(versionService, times(1)).getVersion(any(NodeId.class), any(NodeVersionId.class), any(InternalContext.class));
verify(nodeVersionService, times(1)).get(any(NodeVersionKey.class), any(InternalContext.class));
verifyNoMoreInteractions(versionService, nodeVersionService);
}
use of com.enonic.xp.blob.NodeVersionKey in project xp by enonic.
the class NodeStorageServiceImplTest method testGetNode_ByPath.
@Test
public void testGetNode_ByPath() {
final NodeBranchEntry nodeBranchEntry = NodeBranchEntry.create().nodeId(nodeId).nodePath(nodePath).nodeState(NodeState.DEFAULT).build();
final NodeVersionMetadata nodeVersionMetadata = NodeVersionMetadata.create().nodeVersionId(nodeVersionId).nodeVersionKey(versionKey).nodePath(nodePath).build();
final NodeVersion nodeVersion = NodeVersion.create().permissions(AccessControlList.create().add(AccessControlEntry.create().principal(RoleKeys.EVERYONE).allow(Permission.READ).build()).build()).build();
when(branchService.get(any(NodePath.class), any(InternalContext.class))).thenReturn(nodeBranchEntry);
when(versionService.getVersion(any(NodeId.class), any(NodeVersionId.class), any(InternalContext.class))).thenReturn(nodeVersionMetadata);
when(nodeVersionService.get(any(NodeVersionKey.class), any(InternalContext.class))).thenReturn(nodeVersion);
final Node result = instance.getNode(nodePath, nodeVersionId, context);
assertNotNull(result);
verify(branchService, times(1)).get(any(NodePath.class), any(InternalContext.class));
verify(versionService, times(1)).getVersion(any(NodeId.class), any(NodeVersionId.class), any(InternalContext.class));
verify(nodeVersionService, times(1)).get(any(NodeVersionKey.class), any(InternalContext.class));
verifyNoMoreInteractions(branchService, versionService, nodeVersionService);
}
Aggregations