@Test void copyEntityTypesWithInternalReferences() { setupPredictableIdGeneratorMock(idGenerator); EntityType entityTypeA = mockEntityType("A"); EntityType entityTypeB = mockEntityType("B"); EntityType entityTypeACopy = mock(EntityType.class); EntityType entityTypeBCopy = mock(EntityType.class); Package targetPackage = mock(Package.class); Progress progress = mock(Progress.class); CopyState state = CopyState.create(targetPackage, progress); setupMetadataCopierAnswers( ImmutableMap.of(entityTypeA, entityTypeACopy, entityTypeB, entityTypeBCopy)); when(entityTypeDependencyResolver.resolve(asList(entityTypeACopy, entityTypeBCopy))) .thenReturn(asList(entityTypeBCopy, entityTypeACopy)); Attribute refAttrCopy = mock(Attribute.class); when(entityTypeACopy.getAtomicAttributes()).thenReturn(singletonList(refAttrCopy)); when(refAttrCopy.getDataType()).thenReturn(AttributeType.XREF); when(refAttrCopy.hasRefEntity()).thenReturn(true); when(refAttrCopy.getRefEntity()).thenReturn(entityTypeB); copier.copy(asList(entityTypeA, entityTypeB), state); verify(entityTypeACopy).setId("id1"); verify(entityTypeBCopy).setId("id2"); verify(refAttrCopy).setRefEntity(entityTypeBCopy); assertEquals(of("A", entityTypeACopy, "B", entityTypeBCopy), state.copiedEntityTypes()); assertEquals(of("id1", "A", "id2", "B"), state.originalEntityTypeIds()); assertEquals(emptyMap(), state.referenceDefaultValues()); verify(dataService.getMeta()).addEntityType(entityTypeBCopy); verify(dataService.getMeta()).addEntityType(entityTypeACopy); verify(progress, times(2)).increment(1); }
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);  }