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));
}
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)));
}
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());
}
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)));
}
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());
}
Aggregations