@Test @SuppressWarnings("unchecked") void testApplyMappingsAdd() { String entityTypeId = "addEntity"; @SuppressWarnings("unchecked") Repository<Entity> addEntityRepo = mock(Repository.class); when(addEntityRepo.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(addEntityRepo.getEntityType()).thenReturn(targetMeta); when(metaDataService.createRepository(argThat(obj -> obj.getId().equals(entityTypeId)))) .thenReturn(addEntityRepo); List<Entity> sourceGeneEntities = newArrayList(); List<Entity> expectedEntities = newArrayList(); createEntities(targetMeta, sourceGeneEntities, expectedEntities); 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(); Entity mappedEntity = mock(Entity.class); when(entityManager.create(targetMeta, EntityManager.CreationMode.POPULATE)) .thenReturn(mappedEntity); String packageId = "packageId"; Package aPackage = mock(Package.class); when(metaDataService.getPackage(packageId)).thenReturn(Optional.of(aPackage)); assertEquals( 4, mappingService.applyMappings("TestRun", entityTypeId, true, packageId, "label", progress)); Mockito.verify(geneRepo) .forEachBatched(ArgumentMatchers.any(Consumer.class), ArgumentMatchers.any(Integer.class)); ArgumentCaptor<EntityType> entityTypeCaptor = ArgumentCaptor.forClass(EntityType.class); Mockito.verify(permissionSystemService) .giveUserWriteMetaPermissions(entityTypeCaptor.capture()); assertEquals(entityTypeId, entityTypeCaptor.getValue().getId()); Mockito.verify(progress).setProgressMax(ArgumentMatchers.anyInt()); Mockito.verify(progress).progress(0, "Checking target repository [addEntity]..."); 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.verifyNoMoreInteractions(progress); }
@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; }