Search in sources :

Example 6 with WriterConfig

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>");
}
Also used : StringWriter(java.io.StringWriter) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) WriterConfig(org.eclipse.rdf4j.rio.WriterConfig) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with WriterConfig

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");
}
Also used : StringWriter(java.io.StringWriter) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) WriterConfig(org.eclipse.rdf4j.rio.WriterConfig) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with WriterConfig

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\"");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Entity(org.molgenis.data.Entity) Relation(org.molgenis.data.semantic.Relation) LabeledResource(org.molgenis.data.semantic.LabeledResource) StringWriter(java.io.StringWriter) Attribute(org.molgenis.data.meta.model.Attribute) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) WriterConfig(org.eclipse.rdf4j.rio.WriterConfig) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

WriterConfig (org.eclipse.rdf4j.rio.WriterConfig)8 StringWriter (java.io.StringWriter)7 Model (org.eclipse.rdf4j.model.Model)7 LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Test (org.junit.jupiter.api.Test)6 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)6 Attribute (org.molgenis.data.meta.model.Attribute)3 LabeledResource (org.molgenis.data.semantic.LabeledResource)3 Relation (org.molgenis.data.semantic.Relation)3 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)1 SPARQLResultsJSONWriter (org.eclipse.rdf4j.query.resultio.sparqljson.SPARQLResultsJSONWriter)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 Entity (org.molgenis.data.Entity)1 EntityType (org.molgenis.data.meta.model.EntityType)1