Search in sources :

Example 1 with SystemEntityTypeRegistry

use of org.molgenis.data.meta.system.SystemEntityTypeRegistry 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)

Aggregations

DataService (org.molgenis.data.DataService)1 Query (org.molgenis.data.Query)1 RepositoryCollection (org.molgenis.data.RepositoryCollection)1 MetaDataService (org.molgenis.data.meta.MetaDataService)1 Attribute (org.molgenis.data.meta.model.Attribute)1 EntityType (org.molgenis.data.meta.model.EntityType)1 Package (org.molgenis.data.meta.model.Package)1 SystemEntityTypeRegistry (org.molgenis.data.meta.system.SystemEntityTypeRegistry)1 BeforeMethod (org.testng.annotations.BeforeMethod)1