@SuppressWarnings("unchecked") @Test void copyData() { setupPredictableIdGeneratorMock(idGenerator); EntityType entityType = mockEntityType("A"); when(entityType.getId()).thenReturn("originalId"); EntityType entityTypeCopy = mock(EntityType.class); when(entityTypeCopy.getId()).thenReturn("id1"); when(entityTypeCopy.isAbstract()).thenReturn(false); Repository<Entity> repository = mock(Repository.class); when(dataService.getRepository("originalId")).thenReturn(repository); Package targetPackage = mock(Package.class); Progress progress = mock(Progress.class); CopyState state = CopyState.create(targetPackage, progress); Entity entity1 = mock(Entity.class); when(entity1.getEntityType()).thenReturn(entityType); Entity entity2 = mock(Entity.class); when(entity2.getEntityType()).thenReturn(entityType); doAnswer( invocation -> { Consumer<List<Entity>> consumer = invocation.getArgument(0); consumer.accept(asList(entity1, entity2)); return null; }) .when(repository) .forEachBatched(any(), eq(1000)); when(entityTypeMetadataCopier.copy(entityType, state)).thenReturn(entityTypeCopy); when(entityTypeDependencyResolver.resolve(singletonList(entityTypeCopy))) .thenReturn(singletonList(entityTypeCopy)); copier.copy(singletonList(entityType), state); ArgumentCaptor<Stream> streamCaptor = ArgumentCaptor.forClass(Stream.class); verify(dataService).add(eq("id1"), streamCaptor.capture()); List<Entity> entities = (List<Entity>) streamCaptor.getValue().collect(Collectors.toList()); assertEquals(entityTypeCopy, entities.get(0).getEntityType()); assertEquals(entityTypeCopy, entities.get(1).getEntityType()); }
public void copy(List<EntityType> entityTypes, CopyState state) { List<EntityType> preparedEntityTypes = prepareEntityTypes(entityTypes, state); List<EntityType> copiedEntityTypes = copyEntityTypes(preparedEntityTypes, state); persist(copiedEntityTypes, state); }
EntityTypeCopier { public void copy(List<EntityType> entityTypes, CopyState state) { List<EntityType> preparedEntityTypes = prepareEntityTypes(entityTypes, state); List<EntityType> copiedEntityTypes = copyEntityTypes(preparedEntityTypes, state); persist(copiedEntityTypes, state); } }
EntityTypeCopier { public void copy(List<EntityType> entityTypes, CopyState state) { List<EntityType> preparedEntityTypes = prepareEntityTypes(entityTypes, state); List<EntityType> copiedEntityTypes = copyEntityTypes(preparedEntityTypes, state); persist(copiedEntityTypes, state); } EntityTypeCopier(
      DataService dataService,
      IdGenerator idGenerator,
      EntityTypeDependencyResolver entityTypeDependencyResolver,
      EntityTypeMetadataCopier entityTypeMetadataCopier); }
EntityTypeCopier { public void copy(List<EntityType> entityTypes, CopyState state) { List<EntityType> preparedEntityTypes = prepareEntityTypes(entityTypes, state); List<EntityType> copiedEntityTypes = copyEntityTypes(preparedEntityTypes, state); persist(copiedEntityTypes, state); } EntityTypeCopier(
      DataService dataService,
      IdGenerator idGenerator,
      EntityTypeDependencyResolver entityTypeDependencyResolver,
      EntityTypeMetadataCopier entityTypeMetadataCopier); void copy(List<EntityType> entityTypes, CopyState state); }
EntityTypeCopier { public void copy(List<EntityType> entityTypes, CopyState state) { List<EntityType> preparedEntityTypes = prepareEntityTypes(entityTypes, state); List<EntityType> copiedEntityTypes = copyEntityTypes(preparedEntityTypes, state); persist(copiedEntityTypes, state); } EntityTypeCopier(
      DataService dataService,
      IdGenerator idGenerator,
      EntityTypeDependencyResolver entityTypeDependencyResolver,
      EntityTypeMetadataCopier entityTypeMetadataCopier); void copy(List<EntityType> entityTypes, CopyState state);  }