Search in sources :

Example 1 with NoShareEntity

use of example.NoShareEntity in project elide by yahoo.

the class PersistentResourceTest method testTransferPermissionSuccessOnUpdateManyRelationship.

@Test
public void testTransferPermissionSuccessOnUpdateManyRelationship() {
    example.User userModel = new example.User();
    userModel.setId(1);
    NoShareEntity noShare1 = new NoShareEntity();
    noShare1.setId(1);
    NoShareEntity noShare2 = new NoShareEntity();
    noShare2.setId(2);
    HashSet<NoShareEntity> noshares = Sets.newHashSet(noShare1, noShare2);
    /* The no shares already exist so no exception should be thrown */
    userModel.setNoShares(noshares);
    List<Resource> idList = new ArrayList<>();
    idList.add(new ResourceIdentifier("noshare", "1").castToResource());
    Relationship ids = new Relationship(null, new Data<>(idList));
    when(tx.loadObject(any(), eq(1L), any())).thenReturn(noShare1);
    when(tx.getToManyRelation(any(), eq(userModel), any(), any())).thenReturn(new DataStoreIterableBuilder(noshares).build());
    RequestScope goodScope = buildRequestScope(tx, goodUser);
    PersistentResource<example.User> userResource = new PersistentResource<>(userModel, goodScope.getUUIDFor(userModel), goodScope);
    boolean returnVal = userResource.updateRelation("noShares", ids.toPersistentResources(goodScope));
    assertTrue(returnVal);
    assertEquals(1, userModel.getNoShares().size());
    assertTrue(userModel.getNoShares().contains(noShare1));
}
Also used : TestUser(com.yahoo.elide.core.security.TestUser) User(com.yahoo.elide.core.security.User) DataStoreIterableBuilder(com.yahoo.elide.core.datastore.DataStoreIterableBuilder) Resource(com.yahoo.elide.jsonapi.models.Resource) ArrayList(java.util.ArrayList) PatchRequestScope(com.yahoo.elide.jsonapi.extensions.PatchRequestScope) ResourceIdentifier(com.yahoo.elide.jsonapi.models.ResourceIdentifier) Relationship(com.yahoo.elide.jsonapi.models.Relationship) NoShareEntity(example.NoShareEntity) Test(org.junit.jupiter.api.Test)

Example 2 with NoShareEntity

use of example.NoShareEntity in project elide by yahoo.

the class PersistentResourceTest method testTransferPermissionErrorOnUpdateManyRelationship.

@Test
public void testTransferPermissionErrorOnUpdateManyRelationship() {
    example.User userModel = new example.User();
    userModel.setId(1);
    NoShareEntity noShare1 = new NoShareEntity();
    noShare1.setId(1);
    NoShareEntity noShare2 = new NoShareEntity();
    noShare2.setId(2);
    List<Resource> idList = new ArrayList<>();
    idList.add(new ResourceIdentifier("noshare", "1").castToResource());
    idList.add(new ResourceIdentifier("noshare", "2").castToResource());
    Relationship ids = new Relationship(null, new Data<>(idList));
    when(tx.loadObject(any(), eq(1L), any())).thenReturn(noShare1);
    when(tx.loadObject(any(), eq(2L), any())).thenReturn(noShare2);
    RequestScope goodScope = buildRequestScope(tx, goodUser);
    PersistentResource<example.User> userResource = new PersistentResource<>(userModel, goodScope.getUUIDFor(userModel), goodScope);
    assertThrows(ForbiddenAccessException.class, () -> userResource.updateRelation("noShares", ids.toPersistentResources(goodScope)));
}
Also used : TestUser(com.yahoo.elide.core.security.TestUser) User(com.yahoo.elide.core.security.User) Resource(com.yahoo.elide.jsonapi.models.Resource) ArrayList(java.util.ArrayList) PatchRequestScope(com.yahoo.elide.jsonapi.extensions.PatchRequestScope) ResourceIdentifier(com.yahoo.elide.jsonapi.models.ResourceIdentifier) Relationship(com.yahoo.elide.jsonapi.models.Relationship) NoShareEntity(example.NoShareEntity) Test(org.junit.jupiter.api.Test)

Example 3 with NoShareEntity

use of example.NoShareEntity in project elide by yahoo.

the class PersistentResourceTest method testTransferPermissionSuccessOnClearSingularRelationship.

@Test
public void testTransferPermissionSuccessOnClearSingularRelationship() {
    example.User userModel = new example.User();
    userModel.setId(1);
    NoShareEntity noShare = new NoShareEntity();
    /* The noshare already exists so no exception should be thrown */
    userModel.setNoShare(noShare);
    List<Resource> empty = new ArrayList<>();
    Relationship ids = new Relationship(null, new Data<>(empty));
    when(tx.getToOneRelation(any(), eq(userModel), any(), any())).thenReturn(noShare);
    RequestScope goodScope = buildRequestScope(tx, goodUser);
    PersistentResource<example.User> userResource = new PersistentResource<>(userModel, goodScope.getUUIDFor(userModel), goodScope);
    boolean returnVal = userResource.updateRelation("noShare", ids.toPersistentResources(goodScope));
    assertTrue(returnVal);
    assertNull(userModel.getNoShare());
}
Also used : TestUser(com.yahoo.elide.core.security.TestUser) User(com.yahoo.elide.core.security.User) Resource(com.yahoo.elide.jsonapi.models.Resource) ArrayList(java.util.ArrayList) PatchRequestScope(com.yahoo.elide.jsonapi.extensions.PatchRequestScope) Relationship(com.yahoo.elide.jsonapi.models.Relationship) NoShareEntity(example.NoShareEntity) Test(org.junit.jupiter.api.Test)

Example 4 with NoShareEntity

use of example.NoShareEntity in project elide by yahoo.

the class PersistentResourceTest method testTransferPermissionErrorOnUpdateSingularRelationship.

@Test
public void testTransferPermissionErrorOnUpdateSingularRelationship() {
    example.User userModel = new example.User();
    userModel.setId(1);
    NoShareEntity noShare = new NoShareEntity();
    noShare.setId(1);
    List<Resource> idList = new ArrayList<>();
    idList.add(new ResourceIdentifier("noshare", "1").castToResource());
    Relationship ids = new Relationship(null, new Data<>(idList));
    EntityProjection collection = EntityProjection.builder().type(NoShareEntity.class).build();
    when(tx.loadObject(eq(collection), eq(1L), any())).thenReturn(noShare);
    RequestScope goodScope = buildRequestScope(tx, goodUser);
    PersistentResource<example.User> userResource = new PersistentResource<>(userModel, goodScope.getUUIDFor(userModel), goodScope);
    assertThrows(ForbiddenAccessException.class, () -> userResource.updateRelation("noShare", ids.toPersistentResources(goodScope)));
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) TestUser(com.yahoo.elide.core.security.TestUser) User(com.yahoo.elide.core.security.User) Resource(com.yahoo.elide.jsonapi.models.Resource) ArrayList(java.util.ArrayList) PatchRequestScope(com.yahoo.elide.jsonapi.extensions.PatchRequestScope) ResourceIdentifier(com.yahoo.elide.jsonapi.models.ResourceIdentifier) Relationship(com.yahoo.elide.jsonapi.models.Relationship) NoShareEntity(example.NoShareEntity) Test(org.junit.jupiter.api.Test)

Example 5 with NoShareEntity

use of example.NoShareEntity in project elide by yahoo.

the class PersistentResourceTest method testTransferPermissionSuccessOnUpdateSingularRelationship.

@Test
public void testTransferPermissionSuccessOnUpdateSingularRelationship() {
    example.User userModel = new example.User();
    userModel.setId(1);
    NoShareEntity noShare = new NoShareEntity();
    /* The noshare already exists so no exception should be thrown */
    userModel.setNoShare(noShare);
    List<Resource> idList = new ArrayList<>();
    idList.add(new ResourceIdentifier("noshare", "1").castToResource());
    Relationship ids = new Relationship(null, new Data<>(idList));
    when(tx.getToOneRelation(any(), eq(userModel), any(), any())).thenReturn(noShare);
    when(tx.loadObject(any(), eq(1L), any())).thenReturn(noShare);
    RequestScope goodScope = buildRequestScope(tx, goodUser);
    PersistentResource<example.User> userResource = new PersistentResource<>(userModel, goodScope.getUUIDFor(userModel), goodScope);
    boolean returnVal = userResource.updateRelation("noShare", ids.toPersistentResources(goodScope));
    assertFalse(returnVal);
    assertEquals(noShare, userModel.getNoShare());
}
Also used : TestUser(com.yahoo.elide.core.security.TestUser) User(com.yahoo.elide.core.security.User) Resource(com.yahoo.elide.jsonapi.models.Resource) ArrayList(java.util.ArrayList) PatchRequestScope(com.yahoo.elide.jsonapi.extensions.PatchRequestScope) ResourceIdentifier(com.yahoo.elide.jsonapi.models.ResourceIdentifier) Relationship(com.yahoo.elide.jsonapi.models.Relationship) NoShareEntity(example.NoShareEntity) Test(org.junit.jupiter.api.Test)

Aggregations

TestUser (com.yahoo.elide.core.security.TestUser)5 User (com.yahoo.elide.core.security.User)5 PatchRequestScope (com.yahoo.elide.jsonapi.extensions.PatchRequestScope)5 Relationship (com.yahoo.elide.jsonapi.models.Relationship)5 Resource (com.yahoo.elide.jsonapi.models.Resource)5 NoShareEntity (example.NoShareEntity)5 ArrayList (java.util.ArrayList)5 Test (org.junit.jupiter.api.Test)5 ResourceIdentifier (com.yahoo.elide.jsonapi.models.ResourceIdentifier)4 DataStoreIterableBuilder (com.yahoo.elide.core.datastore.DataStoreIterableBuilder)1 EntityProjection (com.yahoo.elide.core.request.EntityProjection)1