Search in sources :

Example 6 with MetadataUpsertJobExecution

use of org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution in project molgenis by molgenis.

the class MetadataApiControllerTest method testDeleteAttributes.

@Test
void testDeleteAttributes() {
    String entityTypeId = "MyEntityTypeId";
    Query query = Query.create("name", IN, asList("name1", "name2"));
    DeleteAttributesRequest deleteAttributesRequest = new DeleteAttributesRequest();
    deleteAttributesRequest.setQ(query);
    MetadataUpsertJobExecution jobExecution = mockUpsertJobExecution();
    when(metadataApiService.deleteAttributesAsync(entityTypeId, query)).thenReturn(jobExecution);
    metadataApiController.deleteAttributes(entityTypeId, deleteAttributesRequest);
    verify(metadataApiService).deleteAttributesAsync(entityTypeId, query);
}
Also used : MetadataUpsertJobExecution(org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution) Query(org.molgenis.api.model.Query) DeleteAttributesRequest(org.molgenis.api.metadata.v3.model.DeleteAttributesRequest) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 7 with MetadataUpsertJobExecution

use of org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution in project molgenis by molgenis.

the class MetadataApiControllerTest method testUpdateEntityType.

@Test
void testUpdateEntityType() throws URISyntaxException {
    String entityTypeId = "MyEntityTypeId";
    CreateEntityTypeRequest createEntityTypeRequest = mock(CreateEntityTypeRequest.class);
    EntityType entityType = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock();
    when(entityTypeRequestMapper.toEntityType(createEntityTypeRequest)).thenReturn(entityType);
    MetadataUpsertJobExecution metadataUpsertJobExecution = mock(MetadataUpsertJobExecution.class);
    when(metadataUpsertJobExecution.getEntityType()).thenReturn(entityType);
    when(metadataApiService.updateEntityTypeAsync(entityType)).thenReturn(metadataUpsertJobExecution);
    ResponseEntity<?> responseEntity = ResponseEntity.accepted().location(new URI("http://localhost/api/data/MyEntityTypeId")).build();
    assertEquals(responseEntity, metadataApiController.updateEntityType(entityTypeId, createEntityTypeRequest));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) MetadataUpsertJobExecution(org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution) CreateEntityTypeRequest(org.molgenis.api.metadata.v3.model.CreateEntityTypeRequest) URI(java.net.URI) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 8 with MetadataUpsertJobExecution

use of org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution in project molgenis by molgenis.

the class MetadataApiControllerTest method testDeleteAttribute.

@Test
void testDeleteAttribute() {
    String entityTypeId = "MyEntityTypeId";
    String attributeId = "attrId";
    MetadataUpsertJobExecution jobExecution = mockUpsertJobExecution();
    when(metadataApiService.deleteAttributeAsync(entityTypeId, attributeId)).thenReturn(jobExecution);
    metadataApiController.deleteAttribute(entityTypeId, attributeId);
    verify(metadataApiService).deleteAttributeAsync(entityTypeId, attributeId);
}
Also used : MetadataUpsertJobExecution(org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 9 with MetadataUpsertJobExecution

use of org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution in project molgenis by molgenis.

the class MetadataApiControllerTest method mockUpsertJobExecution.

private static MetadataUpsertJobExecution mockUpsertJobExecution() {
    EntityType entityType = mock(EntityType.class);
    MetadataUpsertJobExecution jobExecution = mock(MetadataUpsertJobExecution.class);
    when(jobExecution.getEntityType()).thenReturn(entityType);
    return jobExecution;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) MetadataUpsertJobExecution(org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution)

Example 10 with MetadataUpsertJobExecution

use of org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution in project molgenis by molgenis.

the class MetadataApiControllerTest method testCreateAttribute.

@Test
void testCreateAttribute() throws URISyntaxException {
    String entityTypeId = "MyEntityTypeId";
    String attibuteId = "myAttributeId";
    CreateAttributeRequest createAttributeRequest = CreateAttributeRequest.builder().setId(attibuteId).setName("updatedMyAttribute").build();
    EntityType entityType = mock(EntityType.class);
    when(metadataApiService.findEntityType(entityTypeId)).thenReturn(entityType);
    Attribute newAttribute = mock(Attribute.class);
    when(attributeRequestMapper.toAttribute(createAttributeRequest, entityType)).thenReturn(newAttribute);
    EntityType jobEntityType = mock(EntityType.class);
    when(jobEntityType.getId()).thenReturn("MyJobEntityTypeId");
    MetadataUpsertJobExecution metadataUpsertJobExecution = mock(MetadataUpsertJobExecution.class);
    when(metadataUpsertJobExecution.getEntityType()).thenReturn(jobEntityType);
    when(metadataUpsertJobExecution.getIdentifier()).thenReturn("MyJobEntityId");
    when(metadataApiService.updateEntityTypeAsync(entityType)).thenReturn(metadataUpsertJobExecution);
    ResponseEntity<?> responseEntity = ResponseEntity.accepted().location(new URI("http://localhost/api/data/MyJobEntityTypeId/MyJobEntityId")).build();
    assertEquals(responseEntity, metadataApiController.createAttribute(entityTypeId, createAttributeRequest));
    verify(entityType).addAttribute(newAttribute);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) MetadataUpsertJobExecution(org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution) CreateAttributeRequest(org.molgenis.api.metadata.v3.model.CreateAttributeRequest) Attribute(org.molgenis.data.meta.model.Attribute) URI(java.net.URI) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Aggregations

MetadataUpsertJobExecution (org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution)11 Test (org.junit.jupiter.api.Test)9 EntityType (org.molgenis.data.meta.model.EntityType)9 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)9 URI (java.net.URI)4 Attribute (org.molgenis.data.meta.model.Attribute)3 CreateAttributeRequest (org.molgenis.api.metadata.v3.model.CreateAttributeRequest)2 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Action (org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecutionMetadata.Action)1 CreateEntityTypeRequest (org.molgenis.api.metadata.v3.model.CreateEntityTypeRequest)1 DeleteAttributesRequest (org.molgenis.api.metadata.v3.model.DeleteAttributesRequest)1 Query (org.molgenis.api.model.Query)1 MetaDataService (org.molgenis.data.meta.MetaDataService)1 Job (org.molgenis.jobs.Job)1 JobFactory (org.molgenis.jobs.JobFactory)1 UnexpectedEnumException (org.molgenis.util.UnexpectedEnumException)1 Bean (org.springframework.context.annotation.Bean)1 Configuration (org.springframework.context.annotation.Configuration)1