use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class RestServiceTest method toEntityValueMrefToStringAttr.
@Test(dataProvider = "toEntityValueMrefProvider")
public void toEntityValueMrefToStringAttr(AttributeType attrType) {
Entity entity0 = mock(Entity.class);
Entity entity1 = mock(Entity.class);
String refEntityName = "refEntity";
Attribute refIdAttr = mock(Attribute.class);
when(refIdAttr.getDataType()).thenReturn(STRING);
EntityType refEntityType = mock(EntityType.class);
when(refEntityType.getId()).thenReturn(refEntityName);
when(refEntityType.getIdAttribute()).thenReturn(refIdAttr);
Attribute attr = mock(Attribute.class);
when(attr.getDataType()).thenReturn(attrType);
when(attr.getRefEntity()).thenReturn(refEntityType);
when(entityManager.getReference(refEntityType, "0")).thenReturn(entity0);
when(entityManager.getReference(refEntityType, "1")).thenReturn(entity1);
// string
Object entityValue = restService.toEntityValue(attr, "0,1", "test");
assertEquals(entityValue, Arrays.asList(entity0, entity1));
}
use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class RestServiceTest method updateMappedByEntitiesEntityEntity.
@Test
public void updateMappedByEntitiesEntityEntity() {
String refEntityName = "refEntityName";
EntityType refEntityMeta = mock(EntityType.class);
when(refEntityMeta.getId()).thenReturn(refEntityName);
String mappedByAttrName = "mappedByAttr";
Attribute mappedByAttr = mock(Attribute.class);
when(mappedByAttr.getName()).thenReturn(mappedByAttrName);
EntityType entityMeta = mock(EntityType.class);
Attribute oneToManyAttr = mock(Attribute.class);
String oneToManyAttrName = "oneToManyAttr";
when(oneToManyAttr.getName()).thenReturn(oneToManyAttrName);
when(oneToManyAttr.getDataType()).thenReturn(ONE_TO_MANY);
when(oneToManyAttr.isMappedBy()).thenReturn(true);
when(oneToManyAttr.getMappedBy()).thenReturn(mappedByAttr);
when(oneToManyAttr.getRefEntity()).thenReturn(refEntityMeta);
when(entityMeta.getMappedByAttributes()).thenReturn(Stream.of(oneToManyAttr));
Entity refEntity0 = when(mock(Entity.class).getIdValue()).thenReturn("refEntity0").getMock();
Entity refEntity1 = when(mock(Entity.class).getIdValue()).thenReturn("refEntity1").getMock();
Entity refEntity2 = when(mock(Entity.class).getIdValue()).thenReturn("refEntity2").getMock();
Entity entity = mock(Entity.class);
when(entity.getEntities(oneToManyAttrName)).thenReturn(newArrayList(refEntity0, refEntity1));
when(entity.getEntityType()).thenReturn(entityMeta);
Entity existingEntity = mock(Entity.class);
when(existingEntity.getEntities(oneToManyAttrName)).thenReturn(newArrayList(refEntity1, refEntity2));
when(existingEntity.getEntityType()).thenReturn(entityMeta);
restService.updateMappedByEntities(entity, existingEntity);
@SuppressWarnings("unchecked") ArgumentCaptor<Stream<Entity>> captor = ArgumentCaptor.forClass(Stream.class);
verify(dataService).update(eq(refEntityName), captor.capture());
List<Entity> refEntities = captor.getValue().collect(toList());
assertEquals(refEntities, newArrayList(refEntity0, refEntity2));
verify(refEntity0).set(mappedByAttrName, entity);
verify(refEntity2).set(mappedByAttrName, null);
verifyNoMoreInteractions(dataService);
}
use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class RepositorySecurityDecoratorTest method initPermissionServiceMock.
private void initPermissionServiceMock(EntityTypePermission permission, boolean hasPermission) {
EntityType entityType = mock(EntityType.class);
String entityTypeId = "entityTypeId";
when(entityType.getId()).thenReturn(entityTypeId);
if (!hasPermission) {
String entityTypeLabel = "Entity type";
when(entityType.getLabel()).thenReturn(entityTypeLabel);
}
when(delegateRepository.getEntityType()).thenReturn(entityType);
when(permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), permission)).thenReturn(hasPermission);
}
use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class AttributeRepositorySecurityDecoratorTest method findAllQueryUser.
@WithMockUser(username = USERNAME)
@Test
public void findAllQueryUser() throws Exception {
String entityType0Name = "entity0";
EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
String entityType1Name = "entity1";
EntityType entityType1 = when(mock(EntityType.class).getId()).thenReturn(entityType1Name).getMock();
String attr0Name = "entity0attr0";
Attribute attr0 = when(mock(Attribute.class).getName()).thenReturn(attr0Name).getMock();
when(attr0.getEntity()).thenReturn(entityType0);
String attr1Name = "entity1attr0";
Attribute attr1 = when(mock(Attribute.class).getName()).thenReturn(attr1Name).getMock();
when(attr1.getEntity()).thenReturn(entityType1);
Query<Attribute> q = new QueryImpl<>();
@SuppressWarnings("unchecked") ArgumentCaptor<Query<Attribute>> queryCaptor = forClass(Query.class);
when(delegateRepository.findAll(queryCaptor.capture())).thenReturn(Stream.of(attr0, attr1));
when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(false);
when(permissionService.hasPermission(new EntityTypeIdentity(entityType1Name), EntityTypePermission.COUNT)).thenReturn(true);
assertEquals(repo.findAll(q).collect(toList()), singletonList(attr1));
assertEquals(queryCaptor.getValue().getOffset(), 0);
assertEquals(queryCaptor.getValue().getPageSize(), Integer.MAX_VALUE);
}
use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class AttributeRepositorySecurityDecoratorTest method findOneByIdUserPermissionAllowedAttrInCompoundWithOneAttr.
@WithMockUser(username = USERNAME)
@Test
public void findOneByIdUserPermissionAllowedAttrInCompoundWithOneAttr() throws Exception {
String entityType0Name = "entity0";
EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
String attr0Name = "entity0attrCompoundattr0";
Attribute attr0 = when(mock(Attribute.class).getName()).thenReturn(attr0Name).getMock();
when(attr0.getEntity()).thenReturn(entityType0);
String attrCompoundName = "entity0attrCompound";
Attribute attrCompound = when(mock(Attribute.class).getName()).thenReturn(attrCompoundName).getMock();
when(attrCompound.getEntity()).thenReturn(entityType0);
Object id = mock(Object.class);
when(delegateRepository.findOneById(id)).thenReturn(attr0);
when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(true);
assertEquals(repo.findOneById(id), attr0);
}
Aggregations