Search in sources :

Example 26 with EntityType

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]");
}
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) Attribute(org.molgenis.data.meta.model.Attribute) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Iterator(java.util.Iterator) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 27 with EntityType

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());
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) OutputStream(java.io.OutputStream) AttributeFactory(org.molgenis.data.meta.model.AttributeFactory) EntityWriteMode(org.molgenis.data.support.AbstractWritable.EntityWriteMode) Set(java.util.Set) AttributeWriteMode(org.molgenis.data.support.AbstractWritable.AttributeWriteMode) IOException(java.io.IOException) Streams(com.google.common.collect.Streams) Attribute(org.molgenis.data.meta.model.Attribute) EntityType(org.molgenis.data.meta.model.EntityType) FileFormat(org.molgenis.data.excel.ExcelWriter.FileFormat) UnexpectedEnumException(org.molgenis.util.UnexpectedEnumException) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Objects.requireNonNull(java.util.Objects.requireNonNull) DataService(org.molgenis.data.DataService) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) ExcelWriter(org.molgenis.data.excel.ExcelWriter) ExcelSheetWriter(org.molgenis.data.excel.ExcelSheetWriter) MolgenisDataException(org.molgenis.data.MolgenisDataException) DataRequest(org.molgenis.dataexplorer.controller.DataRequest) CsvWriter(org.molgenis.data.csv.CsvWriter)

Example 28 with EntityType

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();
        }
    });
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Entity(org.molgenis.data.Entity) Attribute(org.molgenis.data.meta.model.Attribute) RepositoryCapability(org.molgenis.data.RepositoryCapability) BeforeTest(org.testng.annotations.BeforeTest)

Example 29 with EntityType

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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) FieldMapping(org.molgenis.data.elasticsearch.generator.model.FieldMapping) Mapping(org.molgenis.data.elasticsearch.generator.model.Mapping) FieldMapping(org.molgenis.data.elasticsearch.generator.model.FieldMapping) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 30 with EntityType

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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) Test(org.testng.annotations.Test)

Aggregations

EntityType (org.molgenis.data.meta.model.EntityType)581 Test (org.testng.annotations.Test)367 Attribute (org.molgenis.data.meta.model.Attribute)315 Entity (org.molgenis.data.Entity)98 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)71 DynamicEntity (org.molgenis.data.support.DynamicEntity)61 Stream (java.util.stream.Stream)44 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)43 WithMockUser (org.springframework.security.test.context.support.WithMockUser)40 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)36 QueryImpl (org.molgenis.data.support.QueryImpl)33 Package (org.molgenis.data.meta.model.Package)32 Objects.requireNonNull (java.util.Objects.requireNonNull)22 Collectors.toList (java.util.stream.Collectors.toList)22 BeforeMethod (org.testng.annotations.BeforeMethod)20 AttributeType (org.molgenis.data.meta.AttributeType)19 List (java.util.List)17 String.format (java.lang.String.format)16 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)16 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)15