Search in sources :

Example 1 with MetaDataService

use of org.molgenis.data.meta.MetaDataService in project molgenis by molgenis.

the class DataExplorerControllerTest method initTrackingIdNotPresent.

@Test
public void initTrackingIdNotPresent() {
    String selectedEntityname = "selectedEntityname";
    String selectedEntityId = "selectedEntityId";
    MetaDataService metaDataService = mock(MetaDataService.class);
    when(dataService.getMeta()).thenReturn(metaDataService);
    when(metaDataService.getEntityTypes()).thenReturn(Stream.empty());
    controller.init(selectedEntityname, selectedEntityId, model);
    verify(model).addAttribute("hasTrackingId", false);
    verify(model).addAttribute("hasMolgenisTrackingId", false);
}
Also used : MetaDataService(org.molgenis.data.meta.MetaDataService) Test(org.testng.annotations.Test)

Example 2 with MetaDataService

use of org.molgenis.data.meta.MetaDataService in project molgenis by molgenis.

the class DataExplorerControllerTest method initSetNavigatorMenuPathNoNavigator.

@Test
public void initSetNavigatorMenuPathNoNavigator() {
    String selectedEntityname = "selectedEntityname";
    String selectedEntityId = "selectedEntityId";
    String navigatorPath = "path/to-navigator";
    MetaDataService metaDataService = mock(MetaDataService.class);
    when(dataService.getMeta()).thenReturn(metaDataService);
    when(metaDataService.getEntityTypes()).thenReturn(Stream.empty());
    controller.init(selectedEntityname, selectedEntityId, model);
    verify(model, never()).addAttribute("navigatorBaseUrl", navigatorPath);
}
Also used : MetaDataService(org.molgenis.data.meta.MetaDataService) Test(org.testng.annotations.Test)

Example 3 with MetaDataService

use of org.molgenis.data.meta.MetaDataService in project molgenis by molgenis.

the class EntityTypeValidatorTest method setUpBeforeMethod.

@SuppressWarnings("unchecked")
@BeforeMethod
public void setUpBeforeMethod() {
    dataService = mock(DataService.class);
    MetaDataService metaDataService = mock(MetaDataService.class);
    when(dataService.getMeta()).thenReturn(metaDataService);
    systemEntityTypeRegistry = mock(SystemEntityTypeRegistry.class);
    entityTypeValidator = new EntityTypeValidator(dataService, systemEntityTypeRegistry);
    String backendName = "backend";
    RepositoryCollection repoCollection = mock(RepositoryCollection.class);
    when(metaDataService.getBackend(backendName)).thenReturn(repoCollection);
    // valid entity meta
    entityType = when(mock(EntityType.class).getId()).thenReturn("entity").getMock();
    idAttr = when(mock(Attribute.class).getName()).thenReturn("idAttr").getMock();
    when(idAttr.getIdentifier()).thenReturn("#idAttr");
    when(idAttr.getDataType()).thenReturn(STRING);
    when(idAttr.isUnique()).thenReturn(true);
    when(idAttr.isNillable()).thenReturn(false);
    labelAttr = when(mock(Attribute.class).getName()).thenReturn("labelAttr").getMock();
    when(labelAttr.getIdentifier()).thenReturn("#labelAttr");
    when(labelAttr.getDataType()).thenReturn(STRING);
    entityQ = mock(Query.class);
    when(dataService.query(ENTITY_TYPE_META_DATA, EntityType.class)).thenReturn(entityQ);
    Query<EntityType> entityQ0 = mock(Query.class);
    Query<EntityType> entityQ1 = mock(Query.class);
    when(entityQ.eq(ATTRIBUTES, idAttr)).thenReturn(entityQ0);
    when(entityQ.eq(ATTRIBUTES, labelAttr)).thenReturn(entityQ1);
    when(entityQ0.findOne()).thenReturn(null);
    when(entityQ1.findOne()).thenReturn(null);
    attrQ = mock(Query.class);
    Query<Attribute> attrQ0 = mock(Query.class);
    Query<Attribute> attrQ1 = mock(Query.class);
    when(dataService.query(ATTRIBUTE_META_DATA, Attribute.class)).thenReturn(attrQ);
    when(attrQ.eq(CHILDREN, idAttr)).thenReturn(attrQ0);
    when(attrQ.eq(CHILDREN, labelAttr)).thenReturn(attrQ1);
    when(attrQ0.findOne()).thenReturn(null);
    when(attrQ1.findOne()).thenReturn(null);
    String packageName = "package";
    Package package_ = when(mock(Package.class).getId()).thenReturn(packageName).getMock();
    when(entityType.getPackage()).thenReturn(package_);
    String name = "name";
    String label = "label";
    when(entityType.getId()).thenReturn(packageName + PACKAGE_SEPARATOR + name);
    when(entityType.getLabel()).thenReturn(label);
    when(entityType.getOwnAllAttributes()).thenReturn(newArrayList(idAttr, labelAttr));
    when(entityType.getAllAttributes()).thenReturn(newArrayList(idAttr, labelAttr));
    when(entityType.getOwnIdAttribute()).thenReturn(idAttr);
    when(entityType.getOwnLabelAttribute()).thenReturn(labelAttr);
    when(entityType.getOwnLookupAttributes()).thenReturn(singletonList(labelAttr));
    when(entityType.isAbstract()).thenReturn(false);
    when(entityType.getExtends()).thenReturn(null);
    when(entityType.getBackend()).thenReturn(backendName);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) SystemEntityTypeRegistry(org.molgenis.data.meta.system.SystemEntityTypeRegistry) RepositoryCollection(org.molgenis.data.RepositoryCollection) MetaDataService(org.molgenis.data.meta.MetaDataService) Query(org.molgenis.data.Query) Attribute(org.molgenis.data.meta.model.Attribute) Package(org.molgenis.data.meta.model.Package) MetaDataService(org.molgenis.data.meta.MetaDataService) DataService(org.molgenis.data.DataService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with MetaDataService

use of org.molgenis.data.meta.MetaDataService in project molgenis by molgenis.

the class GenomeBrowserServiceTest method testGetReferenceTracksAll.

@Test
public void testGetReferenceTracksAll() {
    EntityType entity = mock(EntityType.class);
    when(entity.getLabel()).thenReturn("label");
    GenomeBrowserAttributes genomeBrowserAttributes = getGenomeBrowserAttributes("postion", "chrom", "normal", "mutant");
    GenomeBrowserTrack reference = GenomeBrowserTrack.create("ref_id", "label", "ref_label", entity, GenomeBrowserSettings.TrackType.VARIANT, null, GenomeBrowserSettings.MolgenisReferenceMode.NONE, genomeBrowserAttributes, null, null, null, null);
    EntityType molgenisEntity = mock(EntityType.class);
    when(molgenisEntity.getLabel()).thenReturn("label");
    GenomeBrowserTrack track = GenomeBrowserTrack.create("id", "label", "entityLabel", molgenisEntity, GenomeBrowserSettings.TrackType.VARIANT, Collections.singletonList(reference), GenomeBrowserSettings.MolgenisReferenceMode.ALL, genomeBrowserAttributes, "alert(\"test\")", "attr 1:attr1,reference attribute:REF,position on genome:POS", null, null);
    GenomeBrowserAttributes attrs1 = getGenomeBrowserAttributes("pos", "chr", "ref", "alt");
    GenomeBrowserAttributes attrs2 = getGenomeBrowserAttributes("POS", "CHROM", null, null);
    when(dataService.findAll(GenomeBrowserAttributesMetadata.GENOMEBROWSERATTRIBUTES, new QueryImpl<GenomeBrowserAttributes>().eq(GenomeBrowserAttributesMetadata.DEFAULT, true), GenomeBrowserAttributes.class)).thenReturn(Stream.of(attrs1, attrs2));
    EntityType type1 = mock(EntityType.class);
    EntityType type2 = mock(EntityType.class);
    EntityType type3 = mock(EntityType.class);
    Attribute labelAttr = mock(Attribute.class);
    when(labelAttr.getName()).thenReturn("refLabel");
    List<EntityType> types = new ArrayList<>();
    types.add(type1);
    when(type1.getIdValue()).thenReturn("type1");
    when(type1.getLabel()).thenReturn("label1");
    when(type1.getAttributeNames()).thenReturn(Arrays.asList("POS", "CHROM", "AAP", "NOOT", "MIES"));
    when(type1.getLabelAttribute()).thenReturn(labelAttr);
    types.add(type2);
    when(type2.getIdValue()).thenReturn("type2");
    when(type2.getLabel()).thenReturn("label2");
    when(type2.getAttributeNames()).thenReturn(Arrays.asList("pos", "chr", "ref", "alt", "aap"));
    when(type2.getLabelAttribute()).thenReturn(labelAttr);
    types.add(type3);
    when(type3.getIdValue()).thenReturn("type3");
    when(type3.getLabel()).thenReturn("label3");
    when(type3.getAttributeNames()).thenReturn(Arrays.asList("pos", "chr", "ref", "alternative", "monkey"));
    when(type3.getLabelAttribute()).thenReturn(labelAttr);
    MetaDataService metaDataService = mock(MetaDataService.class);
    when(dataService.getMeta()).thenReturn(metaDataService);
    when(metaDataService.getEntityTypes()).thenReturn(types.stream());
    Map<String, GenomeBrowserTrack> result = genomeBrowserService.getReferenceTracks(track);
    assertEquals(result.size(), 2);
    assertEquals(result.get("type2"), GenomeBrowserTrack.create("type2", "label2", "refLabel", type2, GenomeBrowserSettings.TrackType.VARIANT, Collections.emptyList(), GenomeBrowserSettings.MolgenisReferenceMode.ALL, attrs1, null, null, null, null));
    assertEquals(result.get("type1"), GenomeBrowserTrack.create("type1", "label1", "refLabel", type1, GenomeBrowserSettings.TrackType.VARIANT, Collections.emptyList(), GenomeBrowserSettings.MolgenisReferenceMode.ALL, attrs2, null, null, null, null));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) GenomeBrowserAttributes(org.molgenis.genomebrowser.meta.GenomeBrowserAttributes) QueryImpl(org.molgenis.data.support.QueryImpl) MetaDataService(org.molgenis.data.meta.MetaDataService) Attribute(org.molgenis.data.meta.model.Attribute) GenomeBrowserTrack(org.molgenis.genomebrowser.GenomeBrowserTrack) Test(org.testng.annotations.Test)

Example 5 with MetaDataService

use of org.molgenis.data.meta.MetaDataService in project molgenis by molgenis.

the class PlatformIT method testDeletePackage.

@WithMockUser(username = USERNAME)
@Test(singleThreaded = true)
public void testDeletePackage() {
    populateUserPermissions();
    runAsSystem(() -> {
        MetaDataService metadataService = dataService.getMeta();
        Package parentPackage = packageFactory.create("parent").setLabel("parent");
        Package subPackage = packageFactory.create("parent_sub").setLabel("sub").setParent(parentPackage);
        metadataService.upsertPackages(Stream.of(parentPackage, subPackage));
        EntityType entityTypeInSubPackage = testHarness.createDynamicRefEntityType("entityInSub", subPackage);
        EntityType entityTypeInParentPackage = testHarness.createDynamicTestEntityType("entityInParent", parentPackage, entityTypeInSubPackage);
        metadataService.upsertEntityTypes(asList(entityTypeInSubPackage, entityTypeInParentPackage));
        List<Entity> entities = createAndAdd(entityTypeInParentPackage, entityTypeInSubPackage, 5);
        Set<Entity> refEntities = entities.stream().map(e -> e.getEntity(ATTR_XREF)).collect(toSet());
        assertPresent(entityTypeInParentPackage, entities);
        assertPresent(entityTypeInSubPackage, newArrayList(refEntities));
        dataService.deleteById(PACKAGE, "parent");
        assertNull(metadataService.getPackage("parent"));
        assertNull(metadataService.getPackage("parent_sub"));
        entities.forEach(this::assertNotPresent);
        refEntities.forEach(this::assertNotPresent);
    });
}
Also used : AggregateQueryImpl(org.molgenis.data.support.AggregateQueryImpl) MetaDataServiceImpl(org.molgenis.data.meta.MetaDataServiceImpl) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RunAsSystemAspect.runAsSystem(org.molgenis.security.core.runas.RunAsSystemAspect.runAsSystem) IndexActionRegisterServiceImpl(org.molgenis.data.index.IndexActionRegisterServiceImpl) L10N_STRING(org.molgenis.data.i18n.model.L10nStringMetaData.L10N_STRING) EntityListener(org.molgenis.data.listeners.EntityListener) MetaDataService(org.molgenis.data.meta.MetaDataService) Collections.singletonList(java.util.Collections.singletonList) TestExecutionListeners(org.springframework.test.context.TestExecutionListeners) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays.asList(java.util.Arrays.asList) ElasticsearchService(org.molgenis.data.elasticsearch.ElasticsearchService) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Collectors.toSet(java.util.stream.Collectors.toSet) L10nString(org.molgenis.data.i18n.model.L10nString) AbstractTestNGSpringContextTests(org.springframework.test.context.testng.AbstractTestNGSpringContextTests) EntityTestHarness(org.molgenis.data.EntityTestHarness) LanguageService(org.molgenis.i18n.LanguageService) org.molgenis.data(org.molgenis.data) IndexJobScheduler(org.molgenis.data.index.job.IndexJobScheduler) IndexAction(org.molgenis.data.index.meta.IndexAction) READ(org.molgenis.data.security.EntityTypePermission.READ) PACKAGE(org.molgenis.data.meta.model.PackageMetadata.PACKAGE) Stream(java.util.stream.Stream) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) WithMockUser(org.springframework.security.test.context.support.WithMockUser) LANGUAGE(org.molgenis.data.i18n.model.LanguageMetadata.LANGUAGE) java.util(java.util) org.testng.annotations(org.testng.annotations) QueryImpl(org.molgenis.data.support.QueryImpl) EntityListenersService(org.molgenis.data.listeners.EntityListenersService) EntityTypePermission(org.molgenis.data.security.EntityTypePermission) ENTITY_TYPE_META_DATA(org.molgenis.data.meta.model.EntityTypeMetadata.ENTITY_TYPE_META_DATA) AggregateResult(org.molgenis.data.aggregation.AggregateResult) Assert(org.testng.Assert) WithSecurityContextTestExecutionListener(org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener) Objects.requireNonNull(java.util.Objects.requireNonNull) L10nStringMetaData(org.molgenis.data.i18n.model.L10nStringMetaData) ATTRIBUTE_META_DATA(org.molgenis.data.meta.model.AttributeMetadata.ATTRIBUTE_META_DATA) AttributeType(org.molgenis.data.meta.AttributeType) Logger(org.slf4j.Logger) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) IndexActionMetaData(org.molgenis.data.index.meta.IndexActionMetaData) L10nStringFactory(org.molgenis.data.i18n.model.L10nStringFactory) LanguageFactory(org.molgenis.data.i18n.model.LanguageFactory) Collectors.toList(java.util.stream.Collectors.toList) org.molgenis.data.meta.model(org.molgenis.data.meta.model) ContextConfiguration(org.springframework.test.context.ContextConfiguration) WRITE(org.molgenis.data.security.EntityTypePermission.WRITE) Package(org.molgenis.data.meta.model.Package) Transactional(org.springframework.transaction.annotation.Transactional) MetaDataService(org.molgenis.data.meta.MetaDataService) Package(org.molgenis.data.meta.model.Package) WithMockUser(org.springframework.security.test.context.support.WithMockUser)

Aggregations

MetaDataService (org.molgenis.data.meta.MetaDataService)12 EntityType (org.molgenis.data.meta.model.EntityType)6 Test (org.testng.annotations.Test)5 QueryImpl (org.molgenis.data.support.QueryImpl)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 Stream (java.util.stream.Stream)3 Attribute (org.molgenis.data.meta.model.Attribute)3 Package (org.molgenis.data.meta.model.Package)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)2 java.util (java.util)2 Arrays.asList (java.util.Arrays.asList)2 Collections.singletonList (java.util.Collections.singletonList)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Collectors.toList (java.util.stream.Collectors.toList)2 Collectors.toSet (java.util.stream.Collectors.toSet)2 org.molgenis.data (org.molgenis.data)2 EntityTestHarness (org.molgenis.data.EntityTestHarness)2 AggregateQuery (org.molgenis.data.aggregation.AggregateQuery)2