Search in sources :

Example 6 with SystemEntityType

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

the class SystemEntityTypeRegistryImplTest method testGetSystemEntityTypeNotPermitted.

@Test(expectedExceptions = MolgenisDataAccessException.class)
public void testGetSystemEntityTypeNotPermitted() {
    String entityTypeId = "entityType";
    SystemEntityType systemEntityType = mock(SystemEntityType.class);
    when(systemEntityType.getId()).thenReturn(entityTypeId);
    when(permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.COUNT)).thenReturn(false);
    systemEntityTypeRegistry.addSystemEntityType(systemEntityType);
    systemEntityTypeRegistry.getSystemEntityType(entityTypeId);
}
Also used : SystemEntityType(org.molgenis.data.meta.SystemEntityType) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 7 with SystemEntityType

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

the class SystemEntityTypeRegistryImplTest method testGetSystemAttributeCompoundNotExists.

@Test
public void testGetSystemAttributeCompoundNotExists() {
    String entityTypeId = "entityType";
    SystemEntityType systemEntityType = mock(SystemEntityType.class);
    when(systemEntityType.getId()).thenReturn(entityTypeId);
    Attribute attr = when(mock(Attribute.class).getIdentifier()).thenReturn("attr").getMock();
    when(attr.getDataType()).thenReturn(AttributeType.STRING);
    Attribute compoundAttr = when(mock(Attribute.class).getIdentifier()).thenReturn("compoundAttr").getMock();
    when(compoundAttr.getDataType()).thenReturn(AttributeType.COMPOUND);
    when(compoundAttr.getChildren()).thenReturn(singletonList(attr));
    when(systemEntityType.getAllAttributes()).thenReturn(singletonList(compoundAttr));
    when(permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.COUNT)).thenReturn(true);
    systemEntityTypeRegistry.addSystemEntityType(systemEntityType);
    assertNull(systemEntityTypeRegistry.getSystemAttribute("unknownAttr"));
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) SystemEntityType(org.molgenis.data.meta.SystemEntityType) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 8 with SystemEntityType

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

the class AbstractMolgenisSpringTest method abstractMolgenisSpringTestBeforeClass.

// long method name, because if a method annotated with @BeforeClass and the same method name exists in a subclass then this method is ignored.
@BeforeClass
public void abstractMolgenisSpringTestBeforeClass() {
    // bootstrap meta data
    EntityTypeMetadata entityTypeMeta = applicationContext.getBean(EntityTypeMetadata.class);
    entityTypeMeta.setBackendEnumOptions(newArrayList("test"));
    applicationContext.getBean(AttributeMetadata.class).bootstrap(entityTypeMeta);
    Map<String, SystemEntityType> systemEntityTypeMap = applicationContext.getBeansOfType(SystemEntityType.class);
    new GenericDependencyResolver().resolve(systemEntityTypeMap.values(), SystemEntityType::getDependencies).forEach(systemEntityType -> systemEntityType.bootstrap(entityTypeMeta));
}
Also used : EntityTypeMetadata(org.molgenis.data.meta.model.EntityTypeMetadata) AttributeMetadata(org.molgenis.data.meta.model.AttributeMetadata) SystemEntityType(org.molgenis.data.meta.SystemEntityType) GenericDependencyResolver(org.molgenis.data.util.GenericDependencyResolver) BeforeClass(org.testng.annotations.BeforeClass)

Example 9 with SystemEntityType

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

the class SystemEntityTypeRegistrar method register.

public void register(ContextRefreshedEvent event) {
    ApplicationContext ctx = event.getApplicationContext();
    Map<String, SystemEntityType> systemEntityTypeMap = ctx.getBeansOfType(SystemEntityType.class);
    systemEntityTypeMap.values().forEach(this::register);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) SystemEntityType(org.molgenis.data.meta.SystemEntityType)

Example 10 with SystemEntityType

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

the class SystemEntityTypeRegistryImplTest method testGetSystemAttributePermittedNotExists.

@Test
public void testGetSystemAttributePermittedNotExists() {
    String entityTypeId = "entityType";
    SystemEntityType systemEntityType = mock(SystemEntityType.class);
    when(systemEntityType.getId()).thenReturn(entityTypeId);
    when(systemEntityType.getAllAttributes()).thenReturn(emptyList());
    when(permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.COUNT)).thenReturn(true);
    systemEntityTypeRegistry.addSystemEntityType(systemEntityType);
    assertNull(systemEntityTypeRegistry.getSystemAttribute("attr"));
}
Also used : SystemEntityType(org.molgenis.data.meta.SystemEntityType) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Aggregations

SystemEntityType (org.molgenis.data.meta.SystemEntityType)16 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)13 Test (org.testng.annotations.Test)13 Attribute (org.molgenis.data.meta.model.Attribute)6 AttributeMetadata (org.molgenis.data.meta.model.AttributeMetadata)2 EntityTypeMetadata (org.molgenis.data.meta.model.EntityTypeMetadata)2 ApplicationContext (org.springframework.context.ApplicationContext)2 SystemPackage (org.molgenis.data.meta.SystemPackage)1 RootSystemPackage (org.molgenis.data.system.model.RootSystemPackage)1 GenericDependencyResolver (org.molgenis.data.util.GenericDependencyResolver)1 BeforeClass (org.testng.annotations.BeforeClass)1