use of org.eclipse.rdf4j.rio.WriterConfig in project molgenis by molgenis.
the class EntityModelWriterTest method testCreateRfdModelXREF.
@Test
void testCreateRfdModelXREF() {
when(objectEntity.getEntityType()).thenReturn(entityType);
when(entityType.getId()).thenReturn("fdp_Catalog");
when(objectEntity.getIdValue()).thenReturn("attributeName");
when(objectEntity.get("attributeName")).thenReturn(refEntity);
when(objectEntity.getEntity("attributeName")).thenReturn(refEntity);
when(refEntity.getEntityType()).thenReturn(refEntityType);
when(refEntityType.getAttributeNames()).thenReturn(List.of("IRI"));
when(refEntity.getString("IRI")).thenReturn("http://example.org/refEntity");
when(entityType.getAtomicAttributes()).thenReturn(List.of(attribute));
when(attribute.getName()).thenReturn("attributeName");
when(attribute.getDataType()).thenReturn(XREF);
when(tagService.getTagsForAttribute(entityType, attribute)).thenReturn(ImmutableMultimap.of(isAssociatedWith, labeledResource));
when(labeledResource.getIri()).thenReturn("http://example.org/relation");
Model result = writer.createRdfModel(objectEntity);
assertEquals(1, result.size());
StringWriter writer = new StringWriter();
Rio.write(result, writer, TURTLE, new WriterConfig().set(INLINE_BLANK_NODES, true));
assertThat(writer.toString()).contains("<http://example.org/relation> <http://example.org/refEntity>");
}
use of org.eclipse.rdf4j.rio.WriterConfig in project molgenis by molgenis.
the class EntityModelWriterTest method testCreateRfdModelXREFMultipleTags.
@Test
void testCreateRfdModelXREFMultipleTags() {
when(objectEntity.getEntityType()).thenReturn(entityType);
when(entityType.getId()).thenReturn("fdp_Catalog");
when(objectEntity.getIdValue()).thenReturn("attributeName");
when(objectEntity.get("attributeName")).thenReturn(refEntity);
when(objectEntity.getEntity("attributeName")).thenReturn(refEntity);
when(refEntity.getEntityType()).thenReturn(refEntityType);
when(refEntity.getIdValue()).thenReturn("refEntityId");
when(refEntityType.getId()).thenReturn("refEntityType");
when(refEntityType.getAttributeNames()).thenReturn(new ArrayList<>());
when(entityType.getAtomicAttributes()).thenReturn(List.of(attribute));
when(attribute.getName()).thenReturn("attributeName");
when(attribute.getDataType()).thenReturn(XREF);
when(tagService.getTagsForAttribute(entityType, attribute)).thenReturn(ImmutableMultimap.of(isAssociatedWith, labeledResource, isAssociatedWith, labeledResource2));
when(labeledResource.getIri()).thenReturn("http://example.org/relation");
when(labeledResource2.getIri()).thenReturn("http://example.org/relation2");
Model result = writer.createRdfModel(objectEntity);
assertEquals(2, result.size());
StringWriter writer = new StringWriter();
Rio.write(result, writer, TURTLE, new WriterConfig().set(INLINE_BLANK_NODES, true));
assertThat(writer.toString()).contains("<http://example.org/relation> _:refEntityType_refEntityId").contains("<http://example.org/relation2> _:refEntityType_refEntityId");
}
use of org.eclipse.rdf4j.rio.WriterConfig in project molgenis by molgenis.
the class EntityModelWriterTest method testCreateRfdModelSTRINGKeywords.
@Test
void testCreateRfdModelSTRINGKeywords() {
Entity objectEntity = mock(Entity.class);
EntityType entityType = mock(EntityType.class);
Attribute attribute = mock(Attribute.class);
List<Attribute> attributeList = singletonList(attribute);
when(objectEntity.getEntityType()).thenReturn(entityType);
String value = "molgenis,genetics,fair";
when(objectEntity.getIdValue()).thenReturn("attributeName");
when(objectEntity.get("attributeName")).thenReturn(value);
when(objectEntity.getString("attributeName")).thenReturn(value);
when(entityType.getAtomicAttributes()).thenReturn(attributeList);
when(attribute.getName()).thenReturn("attributeName");
when(attribute.getDataType()).thenReturn(STRING);
LabeledResource tag = new LabeledResource("http://www.w3.org/ns/dcat#keyword", "keywords");
Multimap<Relation, LabeledResource> tags = ImmutableMultimap.of(isAssociatedWith, tag);
when(tagService.getTagsForAttribute(entityType, attribute)).thenReturn(tags);
Model result = writer.createRdfModel(objectEntity);
assertEquals(3, result.size());
StringWriter writer = new StringWriter();
Rio.write(result, writer, TURTLE, new WriterConfig().set(INLINE_BLANK_NODES, true));
assertThat(writer.toString()).contains("dcat:keyword \"molgenis\", \"genetics\", \"fair\"");
}
Aggregations