Search in sources :

Example 31 with CreateNodeParams

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());
}
Also used : 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)

Example 32 with CreateNodeParams

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());
}
Also used : 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)

Example 33 with CreateNodeParams

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());
}
Also used : NodeVersion(com.enonic.xp.node.NodeVersion) Node(com.enonic.xp.node.Node) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 34 with CreateNodeParams

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"));
    }
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) MemoryBlobRecord(com.enonic.xp.internal.blobstore.MemoryBlobRecord) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) Node(com.enonic.xp.node.Node) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Segment(com.enonic.xp.blob.Segment) MemoryBlobRecord(com.enonic.xp.internal.blobstore.MemoryBlobRecord) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 35 with CreateNodeParams

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);
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) MemoryBlobRecord(com.enonic.xp.internal.blobstore.MemoryBlobRecord) NodeVersion(com.enonic.xp.node.NodeVersion) CachedBlobStore(com.enonic.xp.internal.blobstore.cache.CachedBlobStore) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) Node(com.enonic.xp.node.Node) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Segment(com.enonic.xp.blob.Segment) MemoryBlobRecord(com.enonic.xp.internal.blobstore.MemoryBlobRecord) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Aggregations

CreateNodeParams (com.enonic.xp.node.CreateNodeParams)46 Node (com.enonic.xp.node.Node)32 Test (org.junit.jupiter.api.Test)28 PropertyTree (com.enonic.xp.data.PropertyTree)18 BinaryReference (com.enonic.xp.util.BinaryReference)9 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)8 NodeAlreadyExistAtPathException (com.enonic.xp.node.NodeAlreadyExistAtPathException)7 NodeId (com.enonic.xp.node.NodeId)4 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)4 AccessControlList (com.enonic.xp.security.acl.AccessControlList)4 ByteSource (com.google.common.io.ByteSource)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 NodeBinaryReferenceException (com.enonic.xp.node.NodeBinaryReferenceException)3 NodeIdExistsException (com.enonic.xp.node.NodeIdExistsException)3 NodePath (com.enonic.xp.node.NodePath)3 PrincipalAlreadyExistsException (com.enonic.xp.security.PrincipalAlreadyExistsException)3 ByteStreams (com.google.common.io.ByteStreams)3 StandardCharsets (java.nio.charset.StandardCharsets)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)3