Search in sources :

Example 1 with ContainerWithPackageShare

use of example.nontransferable.ContainerWithPackageShare in project elide by yahoo.

the class PersistentResourceTest method testTransferPermissionSuccessOnUpdateManyRelationshipPackageLevel.

@Test
public void testTransferPermissionSuccessOnUpdateManyRelationshipPackageLevel() {
    ContainerWithPackageShare containerWithPackageShare = new ContainerWithPackageShare();
    ShareableWithPackageShare shareableWithPackageShare = new ShareableWithPackageShare();
    shareableWithPackageShare.setContainerWithPackageShare(containerWithPackageShare);
    List<Resource> shareableList = new ArrayList<>();
    shareableList.add(new ResourceIdentifier("shareableWithPackageShare", "1").castToResource());
    Relationship shareables = new Relationship(null, new Data<>(shareableList));
    when(tx.loadObject(any(), eq(1L), any())).thenReturn(shareableWithPackageShare);
    RequestScope goodScope = buildRequestScope(tx, goodUser);
    PersistentResource<ContainerWithPackageShare> containerResource = new PersistentResource<>(containerWithPackageShare, goodScope.getUUIDFor(containerWithPackageShare), goodScope);
    containerResource.updateRelation("shareableWithPackageShares", shareables.toPersistentResources(goodScope));
    assertEquals(1, containerWithPackageShare.getShareableWithPackageShares().size());
    assertTrue(containerWithPackageShare.getShareableWithPackageShares().contains(shareableWithPackageShare));
}
Also used : ResourceIdentifier(com.yahoo.elide.jsonapi.models.ResourceIdentifier) ShareableWithPackageShare(example.nontransferable.ShareableWithPackageShare) Relationship(com.yahoo.elide.jsonapi.models.Relationship) Resource(com.yahoo.elide.jsonapi.models.Resource) ArrayList(java.util.ArrayList) PatchRequestScope(com.yahoo.elide.jsonapi.extensions.PatchRequestScope) ContainerWithPackageShare(example.nontransferable.ContainerWithPackageShare) Test(org.junit.jupiter.api.Test)

Example 2 with ContainerWithPackageShare

use of example.nontransferable.ContainerWithPackageShare in project elide by yahoo.

the class PersistentResourceTest method testTransferPermissionErrorOnUpdateRelationshipPackageLevel.

@Test
public void testTransferPermissionErrorOnUpdateRelationshipPackageLevel() {
    ContainerWithPackageShare containerWithPackageShare = new ContainerWithPackageShare();
    Untransferable untransferable = new Untransferable();
    untransferable.setContainerWithPackageShare(containerWithPackageShare);
    List<Resource> unShareableList = new ArrayList<>();
    unShareableList.add(new ResourceIdentifier("untransferable", "1").castToResource());
    Relationship unShareales = new Relationship(null, new Data<>(unShareableList));
    when(tx.loadObject(any(), eq(1L), any())).thenReturn(untransferable);
    RequestScope goodScope = buildRequestScope(tx, goodUser);
    PersistentResource<ContainerWithPackageShare> containerResource = new PersistentResource<>(containerWithPackageShare, goodScope.getUUIDFor(containerWithPackageShare), goodScope);
    assertThrows(ForbiddenAccessException.class, () -> containerResource.updateRelation("untransferables", unShareales.toPersistentResources(goodScope)));
}
Also used : ResourceIdentifier(com.yahoo.elide.jsonapi.models.ResourceIdentifier) Relationship(com.yahoo.elide.jsonapi.models.Relationship) Resource(com.yahoo.elide.jsonapi.models.Resource) ArrayList(java.util.ArrayList) Untransferable(example.nontransferable.Untransferable) PatchRequestScope(com.yahoo.elide.jsonapi.extensions.PatchRequestScope) ContainerWithPackageShare(example.nontransferable.ContainerWithPackageShare) Test(org.junit.jupiter.api.Test)

Aggregations

PatchRequestScope (com.yahoo.elide.jsonapi.extensions.PatchRequestScope)2 Relationship (com.yahoo.elide.jsonapi.models.Relationship)2 Resource (com.yahoo.elide.jsonapi.models.Resource)2 ResourceIdentifier (com.yahoo.elide.jsonapi.models.ResourceIdentifier)2 ContainerWithPackageShare (example.nontransferable.ContainerWithPackageShare)2 ArrayList (java.util.ArrayList)2 Test (org.junit.jupiter.api.Test)2 ShareableWithPackageShare (example.nontransferable.ShareableWithPackageShare)1 Untransferable (example.nontransferable.Untransferable)1