use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class RestServiceTest method toEntityValueMrefToIntAttr.
@Test(dataProvider = "toEntityValueMrefProvider")
public void toEntityValueMrefToIntAttr(AttributeType attrType) {
Entity entity0 = mock(Entity.class);
Entity entity1 = mock(Entity.class);
String refEntityName = "refEntity";
Attribute refIdAttr = mock(Attribute.class);
when(refIdAttr.getDataType()).thenReturn(INT);
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.Attribute in project molgenis by molgenis.
the class RestServiceTest method toEntityFileValueValid.
@Test
public void toEntityFileValueValid() throws ParseException {
String generatedId = "id";
String downloadUriAsString = "http://somedownloaduri";
ServletUriComponentsBuilder mockBuilder = mock(ServletUriComponentsBuilder.class);
UriComponents downloadUri = mock(UriComponents.class);
FileMeta fileMeta = mock(FileMeta.class);
Attribute fileAttr = when(mock(Attribute.class).getName()).thenReturn("fileAttr").getMock();
when(fileAttr.getDataType()).thenReturn(FILE);
when(idGenerator.generateId()).thenReturn(generatedId);
when(fileMetaFactory.create(generatedId)).thenReturn(fileMeta);
when(mockBuilder.replacePath(anyString())).thenReturn(mockBuilder);
when(mockBuilder.replaceQuery(null)).thenReturn(mockBuilder);
when(downloadUri.toUriString()).thenReturn(downloadUriAsString);
when(mockBuilder.build()).thenReturn(downloadUri);
when(servletUriComponentsBuilderFactory.fromCurrentRequest()).thenReturn(mockBuilder);
byte[] content = { 'a', 'b' };
MockMultipartFile mockMultipartFile = new MockMultipartFile("name", "fileName", "contentType", content);
assertEquals(restService.toEntityValue(fileAttr, mockMultipartFile, null), fileMeta);
}
use of org.molgenis.data.meta.model.Attribute 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.Attribute 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.Attribute 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);
}
Aggregations