@SuppressWarnings("unchecked") @Test void testDeleteAttributesQuery() { String entityTypeId = "test_entity1"; EntityType entityType = mock(EntityType.class); when(metadataService.getEntityType(entityTypeId)).thenReturn(Optional.of(entityType)); Query query = Query.create("identifier", IN, asList("attr1", "attr2")); org.molgenis.data.Query<Attribute> dataServiceQuery = mock(org.molgenis.data.Query.class); when(dataServiceQuery.eq(AttributeMetadata.ENTITY, entityTypeId)).thenReturn(dataServiceQuery); Attribute attribute1 = mock(Attribute.class); Attribute attribute2 = mock(Attribute.class); when(dataServiceQuery.findAll()).thenReturn(Stream.of(attribute1, attribute2)); Repository<Attribute> attributeRepository = mock(Repository.class); when(metadataService.getRepository(ATTRIBUTE_META_DATA, Attribute.class)) .thenReturn(Optional.of(attributeRepository)); when(queryMapper.map(query, attributeRepository)).thenReturn(dataServiceQuery); metadataApiService.deleteAttributesAsync(entityTypeId, query); assertAll( () -> verify(entityType).removeAttribute(attribute1), () -> verify(entityType).removeAttribute(attribute2), () -> metadataApiJobService.scheduleUpdate(entityType)); }
@Override public MetadataUpsertJobExecution deleteAttributesAsync(String entityTypeId, Query query) { EntityType entityType = findEntityType(entityTypeId); findAttributes(entityTypeId, query).forEach(entityType::removeAttribute); return metadataApiJobService.scheduleUpdate(entityType); }
MetadataApiServiceImpl implements MetadataApiService { @Override public MetadataUpsertJobExecution deleteAttributesAsync(String entityTypeId, Query query) { EntityType entityType = findEntityType(entityTypeId); findAttributes(entityTypeId, query).forEach(entityType::removeAttribute); return metadataApiJobService.scheduleUpdate(entityType); } }
MetadataApiServiceImpl implements MetadataApiService { @Override public MetadataUpsertJobExecution deleteAttributesAsync(String entityTypeId, Query query) { EntityType entityType = findEntityType(entityTypeId); findAttributes(entityTypeId, query).forEach(entityType::removeAttribute); return metadataApiJobService.scheduleUpdate(entityType); } MetadataApiServiceImpl(
      MetaDataService metadataService,
      QueryMapper queryMapperV3,
      SortMapper sortMapper,
      MetadataApiJobService metadataApiJobService); }
MetadataApiServiceImpl implements MetadataApiService { @Override public MetadataUpsertJobExecution deleteAttributesAsync(String entityTypeId, Query query) { EntityType entityType = findEntityType(entityTypeId); findAttributes(entityTypeId, query).forEach(entityType::removeAttribute); return metadataApiJobService.scheduleUpdate(entityType); } MetadataApiServiceImpl(
      MetaDataService metadataService,
      QueryMapper queryMapperV3,
      SortMapper sortMapper,
      MetadataApiJobService metadataApiJobService); EntityTypes findEntityTypes(
      @Nullable @CheckForNull Query query, Sort sort, int size, int number); @Override EntityType findEntityType(String identifier); @Override Attributes findAttributes(
      String entityTypeId, @Nullable @CheckForNull Query query, Sort sort, int size, int number); @Override Attribute findAttribute(String entityTypeId, String attributeId); @Override MetadataUpsertJobExecution deleteAttributeAsync(String entityTypeId, String attributeId); @Override MetadataUpsertJobExecution deleteAttributesAsync(String entityTypeId, Query query); @Override void createEntityType(EntityType entityType); @Override MetadataUpsertJobExecution updateEntityTypeAsync(EntityType entityType); @Override MetadataDeleteJobExecution deleteEntityTypeAsync(String entityTypeId); @Override MetadataDeleteJobExecution deleteEntityTypesAsync(Query query); }
MetadataApiServiceImpl implements MetadataApiService { @Override public MetadataUpsertJobExecution deleteAttributesAsync(String entityTypeId, Query query) { EntityType entityType = findEntityType(entityTypeId); findAttributes(entityTypeId, query).forEach(entityType::removeAttribute); return metadataApiJobService.scheduleUpdate(entityType); } MetadataApiServiceImpl(
      MetaDataService metadataService,
      QueryMapper queryMapperV3,
      SortMapper sortMapper,
      MetadataApiJobService metadataApiJobService); EntityTypes findEntityTypes(
      @Nullable @CheckForNull Query query, Sort sort, int size, int number); @Override EntityType findEntityType(String identifier); @Override Attributes findAttributes(
      String entityTypeId, @Nullable @CheckForNull Query query, Sort sort, int size, int number); @Override Attribute findAttribute(String entityTypeId, String attributeId); @Override MetadataUpsertJobExecution deleteAttributeAsync(String entityTypeId, String attributeId); @Override MetadataUpsertJobExecution deleteAttributesAsync(String entityTypeId, Query query); @Override void createEntityType(EntityType entityType); @Override MetadataUpsertJobExecution updateEntityTypeAsync(EntityType entityType); @Override MetadataDeleteJobExecution deleteEntityTypeAsync(String entityTypeId); @Override MetadataDeleteJobExecution deleteEntityTypesAsync(Query query);  }