@SuppressWarnings("unchecked") @Test void testApplyMappingsUpdate() { String entityTypeId = "updateEntity"; @SuppressWarnings("unchecked") Repository<Entity> updateEntityRepo = mock(Repository.class); when(updateEntityRepo.getName()).thenReturn(entityTypeId); EntityType targetMeta = entityTypeFactory.create(TARGET_HOP_ENTITY).setPackage(package_); targetMeta.addAttribute(attrMetaFactory.create().setName("identifier"), ROLE_ID); targetMeta.addAttribute( attrMetaFactory.create().setName("height").setDataType(DECIMAL).setNillable(false)); targetMeta.addAttribute(attrMetaFactory.create().setName("source")); when(dataService.hasRepository(entityTypeId)).thenReturn(true); when(dataService.getRepository(entityTypeId)).thenReturn(updateEntityRepo); when(metaDataService.getEntityType(entityTypeId)).thenReturn(Optional.of(targetMeta)); when(updateEntityRepo.getEntityType()).thenReturn(targetMeta); when(metaDataService.createRepository(argThat(obj -> obj.getLabel().equals(entityTypeId)))) .thenReturn(updateEntityRepo); List<Entity> sourceGeneEntities = newArrayList(); List<Entity> expectedEntities = newArrayList(); createEntities(targetMeta, sourceGeneEntities, expectedEntities); when(updateEntityRepo.count()).thenReturn(4L); when(updateEntityRepo.findAll(ArgumentMatchers.any(), ArgumentMatchers.any())) .thenReturn(expectedEntities.stream()); Mockito.doAnswer( invocationOnMock -> { @SuppressWarnings("unchecked") Consumer<List<Entity>> consumer = (Consumer<List<Entity>>) invocationOnMock.<Consumer>getArgument(0); consumer.accept(sourceGeneEntities); return null; }) .when(geneRepo) .forEachBatched(ArgumentMatchers.any(Consumer.class), eq(MAPPING_BATCH_SIZE)); createMappingProjectWithMappings(); when(entityManager.create(targetMeta, EntityManager.CreationMode.POPULATE)) .thenAnswer(invocation -> new DynamicEntity(targetMeta)); assertEquals( 4, mappingService.applyMappings( "TestRun", entityTypeId, false, "packageId", "label", progress)); Mockito.verify(geneRepo) .forEachBatched(ArgumentMatchers.any(Consumer.class), ArgumentMatchers.any(Integer.class)); Mockito.verify(updateEntityRepo).upsertBatch(batchCaptor.capture()); assertTrue(EntityUtils.equalsEntities(batchCaptor.getValue(), expectedEntities)); Mockito.verify(progress).status("Applying mappings to repository [HopEntity]"); Mockito.verify(progress).status("Mapping source [Genes]..."); Mockito.verify(progress).increment(1); Mockito.verify(progress).status("Mapped 4 [Genes] entities."); Mockito.verify(progress).status("Done applying mappings to repository [HopEntity]"); Mockito.verifyZeroInteractions(permissionSystemService); }
@Override @Transactional public long applyMappings( String mappingProjectId, String entityTypeId, Boolean addSourceAttribute, String packageId, String label, Progress progress) { MappingProject mappingProject = getMappingProject(mappingProjectId); MappingTarget mappingTarget = mappingProject.getMappingTargets().get(0); progress.setProgressMax(calculateMaxProgress(mappingTarget)); progress.progress(0, format("Checking target repository [%s]...", entityTypeId)); EntityType targetMetadata = createTargetMetadata(mappingTarget, entityTypeId, packageId, label, addSourceAttribute); Repository<Entity> targetRepo = getTargetRepository(entityTypeId, targetMetadata); return applyMappingsInternal(mappingTarget, targetRepo, progress, mappingProject.getDepth()); }
MappingServiceImpl implements MappingService { @Override @Transactional public long applyMappings( String mappingProjectId, String entityTypeId, Boolean addSourceAttribute, String packageId, String label, Progress progress) { MappingProject mappingProject = getMappingProject(mappingProjectId); MappingTarget mappingTarget = mappingProject.getMappingTargets().get(0); progress.setProgressMax(calculateMaxProgress(mappingTarget)); progress.progress(0, format("Checking target repository [%s]...", entityTypeId)); EntityType targetMetadata = createTargetMetadata(mappingTarget, entityTypeId, packageId, label, addSourceAttribute); Repository<Entity> targetRepo = getTargetRepository(entityTypeId, targetMetadata); return applyMappingsInternal(mappingTarget, targetRepo, progress, mappingProject.getDepth()); } }
MappingServiceImpl implements MappingService { @Override @Transactional public long applyMappings( String mappingProjectId, String entityTypeId, Boolean addSourceAttribute, String packageId, String label, Progress progress) { MappingProject mappingProject = getMappingProject(mappingProjectId); MappingTarget mappingTarget = mappingProject.getMappingTargets().get(0); progress.setProgressMax(calculateMaxProgress(mappingTarget)); progress.progress(0, format("Checking target repository [%s]...", entityTypeId)); EntityType targetMetadata = createTargetMetadata(mappingTarget, entityTypeId, packageId, label, addSourceAttribute); Repository<Entity> targetRepo = getTargetRepository(entityTypeId, targetMetadata); return applyMappingsInternal(mappingTarget, targetRepo, progress, mappingProject.getDepth()); } MappingServiceImpl(
      DataService dataService,
      AlgorithmService algorithmService,
      MappingProjectRepository mappingProjectRepository,
      PermissionSystemService permissionSystemService,
      AttributeFactory attrMetaFactory,
      EntityManager entityManager); }
MappingServiceImpl implements MappingService { @Override @Transactional public long applyMappings( String mappingProjectId, String entityTypeId, Boolean addSourceAttribute, String packageId, String label, Progress progress) { MappingProject mappingProject = getMappingProject(mappingProjectId); MappingTarget mappingTarget = mappingProject.getMappingTargets().get(0); progress.setProgressMax(calculateMaxProgress(mappingTarget)); progress.progress(0, format("Checking target repository [%s]...", entityTypeId)); EntityType targetMetadata = createTargetMetadata(mappingTarget, entityTypeId, packageId, label, addSourceAttribute); Repository<Entity> targetRepo = getTargetRepository(entityTypeId, targetMetadata); return applyMappingsInternal(mappingTarget, targetRepo, progress, mappingProject.getDepth()); } MappingServiceImpl(
      DataService dataService,
      AlgorithmService algorithmService,
      MappingProjectRepository mappingProjectRepository,
      PermissionSystemService permissionSystemService,
      AttributeFactory attrMetaFactory,
      EntityManager entityManager); @Override @Transactional MappingProject addMappingProject(String projectName, String target, int depth); @Override @Transactional void deleteMappingProject(String mappingProjectId); @Override @Transactional MappingProject cloneMappingProject(String mappingProjectId); @Override @Transactional MappingProject cloneMappingProject(
      String mappingProjectId, String clonedMappingProjectName); @Override List<MappingProject> getAllMappingProjects(); @Override @Transactional void updateMappingProject(MappingProject mappingProject); @Override MappingProject getMappingProject(String identifier); @Override @Transactional long applyMappings(
      String mappingProjectId,
      String entityTypeId,
      Boolean addSourceAttribute,
      String packageId,
      String label,
      Progress progress); Stream<EntityType> getCompatibleEntityTypes(EntityType target); }
MappingServiceImpl implements MappingService { @Override @Transactional public long applyMappings( String mappingProjectId, String entityTypeId, Boolean addSourceAttribute, String packageId, String label, Progress progress) { MappingProject mappingProject = getMappingProject(mappingProjectId); MappingTarget mappingTarget = mappingProject.getMappingTargets().get(0); progress.setProgressMax(calculateMaxProgress(mappingTarget)); progress.progress(0, format("Checking target repository [%s]...", entityTypeId)); EntityType targetMetadata = createTargetMetadata(mappingTarget, entityTypeId, packageId, label, addSourceAttribute); Repository<Entity> targetRepo = getTargetRepository(entityTypeId, targetMetadata); return applyMappingsInternal(mappingTarget, targetRepo, progress, mappingProject.getDepth()); } MappingServiceImpl(
      DataService dataService,
      AlgorithmService algorithmService,
      MappingProjectRepository mappingProjectRepository,
      PermissionSystemService permissionSystemService,
      AttributeFactory attrMetaFactory,
      EntityManager entityManager); @Override @Transactional MappingProject addMappingProject(String projectName, String target, int depth); @Override @Transactional void deleteMappingProject(String mappingProjectId); @Override @Transactional MappingProject cloneMappingProject(String mappingProjectId); @Override @Transactional MappingProject cloneMappingProject(
      String mappingProjectId, String clonedMappingProjectName); @Override List<MappingProject> getAllMappingProjects(); @Override @Transactional void updateMappingProject(MappingProject mappingProject); @Override MappingProject getMappingProject(String identifier); @Override @Transactional long applyMappings(
      String mappingProjectId,
      String entityTypeId,
      Boolean addSourceAttribute,
      String packageId,
      String label,
      Progress progress); Stream<EntityType> getCompatibleEntityTypes(EntityType target); static final int MAPPING_BATCH_SIZE; }