Search in sources :

Example 16 with UnknownEntityTypeException

use of org.molgenis.data.UnknownEntityTypeException in project molgenis by molgenis.

the class MetaDataServiceIT method testAddAttribute.

@WithMockUser(username = USERNAME)
@Test
@Order(8)
public void testAddAttribute() {
    EntityType entityType = metaDataService.getEntityType(ENTITY_TYPE_ID).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_ID));
    ;
    Attribute attribute = attributeFactory.create().setName("newAttribute");
    attribute.setEntity(entityType);
    metaDataService.addAttribute(attribute);
    EntityType updatedEntityType = metaDataService.getEntityType(ENTITY_TYPE_ID).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_ID));
    ;
    assertTrue(EntityUtils.equals(attribute, updatedEntityType.getAttribute("newAttribute")));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) Attribute(org.molgenis.data.meta.model.Attribute) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 17 with UnknownEntityTypeException

use of org.molgenis.data.UnknownEntityTypeException in project molgenis by molgenis.

the class MetaDataServiceIT method testDeleteAttribute.

@WithMockUser(username = USERNAME)
@Test
@Order(10)
public void testDeleteAttribute() {
    EntityType entityType = metaDataService.getEntityType(ENTITY_TYPE_ID).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_ID));
    ;
    String attributeId = entityType.getAttribute("newAttribute").getIdentifier();
    metaDataService.deleteAttributeById(attributeId);
    EntityType updatedEntityType = metaDataService.getEntityType(ENTITY_TYPE_ID).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_ID));
    ;
    org.junit.jupiter.api.Assertions.assertNull(updatedEntityType.getAttribute("newAttribute"));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 18 with UnknownEntityTypeException

use of org.molgenis.data.UnknownEntityTypeException in project molgenis by molgenis.

the class MetaDataServiceIT method testUpdateEntityTypeNotAllowed.

@SuppressWarnings("deprecation")
@WithMockUser(username = USERNAME)
@Test
@Order(4)
public void testUpdateEntityTypeNotAllowed() {
    EntityType updatedEntityType = metaDataService.getEntityType(ENTITY_TYPE_ID).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_ID));
    updatedEntityType.getAttribute(ATTR_COMPOUND_CHILD_INT).setDataType(DATE_TIME);
    Exception exception = assertThrows(MolgenisDataException.class, () -> metaDataService.updateEntityType(updatedEntityType));
    assertThat(exception.getMessage()).containsPattern("Attribute data type update from \\[INT\\] to \\[DATE_TIME\\] not allowed, allowed types are \\[BOOL, CATEGORICAL, DECIMAL, ENUM, LONG, STRING, TEXT, XREF\\]");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) PackagePermissionDeniedException(org.molgenis.data.security.exception.PackagePermissionDeniedException) NullPackageNotSuException(org.molgenis.data.security.exception.NullPackageNotSuException) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) MolgenisDataException(org.molgenis.data.MolgenisDataException) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 19 with UnknownEntityTypeException

use of org.molgenis.data.UnknownEntityTypeException in project molgenis by molgenis.

the class MetaDataServiceIT method testUpdateAttribute.

@WithMockUser(username = USERNAME)
@Test
@Order(9)
public void testUpdateAttribute() {
    EntityType entityType = metaDataService.getEntityType(ENTITY_TYPE_ID).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_ID));
    Attribute attribute = entityType.getAttribute("newAttribute");
    attribute.setLabel("updated-label");
    attribute.setEntity(entityType);
    dataService.update(ATTRIBUTE_META_DATA, attribute);
    EntityType updatedEntityType = metaDataService.getEntityType(ENTITY_TYPE_ID).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_ID));
    ;
    assertTrue(EntityUtils.equals(attribute, updatedEntityType.getAttribute("newAttribute")));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) Attribute(org.molgenis.data.meta.model.Attribute) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 20 with UnknownEntityTypeException

use of org.molgenis.data.UnknownEntityTypeException in project molgenis by molgenis.

the class RestController method getAttributePostInternal.

private AttributeResponse getAttributePostInternal(String entityTypeId, String attributeName, Set<String> attributeSet, Map<String, Set<String>> attributeExpandSet) {
    EntityType meta = dataService.getEntityType(entityTypeId);
    Attribute attribute = meta.getAttribute(attributeName);
    if (attribute != null) {
        return new AttributeResponse(entityTypeId, meta, attribute, attributeSet, attributeExpandSet, permissionService, dataService);
    } else {
        throw new UnknownEntityTypeException(entityTypeId);
    }
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) Attribute(org.molgenis.data.meta.model.Attribute)

Aggregations

UnknownEntityTypeException (org.molgenis.data.UnknownEntityTypeException)31 EntityType (org.molgenis.data.meta.model.EntityType)21 Test (org.junit.jupiter.api.Test)15 UnknownEntityException (org.molgenis.data.UnknownEntityException)9 MolgenisDataException (org.molgenis.data.MolgenisDataException)8 Attribute (org.molgenis.data.meta.model.Attribute)8 WithMockUser (org.springframework.security.test.context.support.WithMockUser)8 Order (org.junit.jupiter.api.Order)7 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)7 Entity (org.molgenis.data.Entity)7 EntityTypePermissionDeniedException (org.molgenis.data.security.exception.EntityTypePermissionDeniedException)7 NestedServletException (org.springframework.web.util.NestedServletException)7 RepositoryAlreadyExistsException (org.molgenis.data.RepositoryAlreadyExistsException)5 RepositoryNotCapableException (org.molgenis.data.RepositoryNotCapableException)5 Package (org.molgenis.data.meta.model.Package)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 Mockito.anyString (org.mockito.Mockito.anyString)4 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)4 MolgenisValidationException (org.molgenis.data.validation.MolgenisValidationException)4 UnknownAttributeException (org.molgenis.data.UnknownAttributeException)3