use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class EntityModelWriterTest method testCreateRfdModelNullValuePlusHyperlink.
@Test
public void testCreateRfdModelNullValuePlusHyperlink() {
// public Model createRdfModel(String subjectIRI, Entity objectEntity)
Entity objectEntity = mock(Entity.class);
EntityType entityType = mock(EntityType.class);
Attribute attribute1 = mock(Attribute.class);
Attribute attribute2 = mock(Attribute.class);
List<Attribute> attributeList = Arrays.asList(attribute1, attribute2);
when(objectEntity.getEntityType()).thenReturn(entityType);
when(objectEntity.get("attribute1Name")).thenReturn(null);
String value = "http://molgenis.org/index.html";
doReturn(value).when(objectEntity).get("attribute2Name");
when(objectEntity.getString("attribute2Name")).thenReturn(value);
when(entityType.getAtomicAttributes()).thenReturn(attributeList);
when(attribute1.getName()).thenReturn("attribute1Name");
when(attribute2.getName()).thenReturn("attribute2Name");
when(attribute2.getDataType()).thenReturn(AttributeType.HYPERLINK);
LabeledResource tag2 = new LabeledResource("http://IRI1.nl", "tag1 label");
Multimap<Relation, LabeledResource> tags2 = ImmutableMultimap.of(Relation.isAssociatedWith, tag2);
doReturn(tags2).when(tagService).getTagsForAttribute(entityType, attribute2);
Model result = writer.createRdfModel("http://molgenis01.gcc.rug.nl/fdp/catolog/test/this", objectEntity);
assertEquals(result.size(), 1);
Iterator results = result.iterator();
assertEquals(results.next().toString(), "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://IRI1.nl, http://molgenis.org/index.html) [null]");
}
use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class DataExplorerDownloadHandler method filterAttributes.
private List<Attribute> filterAttributes(DataRequest dataRequest) {
EntityType entityType = dataService.getEntityType(dataRequest.getEntityName());
final Set<String> attributeNames = newHashSet(dataRequest.getAttributeNames());
return Streams.stream(entityType.getAtomicAttributes()).filter(attribute -> attributeNames.contains(attribute.getName())).collect(toList());
}
use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class AbstractRepositoryTest method beforeTest.
@BeforeTest
public void beforeTest() {
MockitoAnnotations.initMocks(this);
Attribute idAttr = when(mock(Attribute.class).getName()).thenReturn("id").getMock();
entityType = when(mock(EntityType.class).getId()).thenReturn("entity").getMock();
when(entityType.getIdAttribute()).thenReturn(idAttr);
abstractRepository = Mockito.spy(new AbstractRepository() {
@Override
public Iterator<Entity> iterator() {
return null;
}
public EntityType getEntityType() {
return entityType;
}
@Override
public Set<RepositoryCapability> getCapabilities() {
return Collections.emptySet();
}
});
}
use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class MappingGeneratorTest method testCreateMappingProviderNested.
@Test(dataProvider = "createMappingProviderNested")
public void testCreateMappingProviderNested(AttributeType attributeType) {
String refAttrIdentifier = "refAttr";
EntityType refEntityType = createEntityType(refAttrIdentifier, AttributeType.LONG);
String attrIdentifier = "attr";
EntityType entityType = createEntityType(attrIdentifier, attributeType, refEntityType);
Mapping mapping = mappingGenerator.createMapping(entityType);
FieldMapping fieldMapping = FieldMapping.builder().setName(attrIdentifier).setType(MappingType.NESTED).setNestedFieldMappings(singletonList(FieldMapping.builder().setName(refAttrIdentifier).setType(MappingType.LONG).build())).build();
Mapping expectedMapping = createMapping(fieldMapping);
assertEquals(mapping, expectedMapping);
}
use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class DocumentIdGeneratorTest method testGenerateIdAttribute.
@Test(dataProvider = "generateIdAttributeTypeProvider")
public void testGenerateIdAttribute(String entityTypeId, String attrId, String attrName, String expectedId) {
EntityType entityType = mock(EntityType.class);
when(entityType.getId()).thenReturn(entityTypeId);
Attribute attr = mock(Attribute.class);
when(attr.getEntity()).thenReturn(entityType);
when(attr.getIdentifier()).thenReturn(attrId);
when(attr.getName()).thenReturn(attrName);
String id = documentIdGenerator.generateId(attr);
assertEquals(id, expectedId);
}
Aggregations