@SuppressWarnings("unchecked") @Test void testPersistMetaUpdateDataAdd() { EntityType existingEntityType0 = mock(EntityType.class); when(existingEntityType0.getId()).thenReturn("entityTypeId0"); EntityType existingEntityType1 = mock(EntityType.class); when(existingEntityType1.getId()).thenReturn("entityTypeId1"); EntityType existingEntityType2 = mock(EntityType.class); when(existingEntityType2.getId()).thenReturn("entityTypeId2"); when(dataService.findOneById(ENTITY_TYPE_META_DATA, entityType0.getId(), EntityType.class)) .thenReturn(existingEntityType0); when(dataService.findOneById(ENTITY_TYPE_META_DATA, entityType1.getId(), EntityType.class)) .thenReturn(existingEntityType1); when(dataService.findOneById(ENTITY_TYPE_META_DATA, entityType2.getId(), EntityType.class)) .thenReturn(existingEntityType2); Query<EntityType> query = mock(Query.class, RETURNS_SELF); when(dataService.query(ENTITY_TYPE_META_DATA, EntityType.class)).thenReturn(query); when(query .in( EntityTypeMetadata.ID, Sets.newHashSet(entityType2.getId(), entityType1.getId(), entityType0.getId())) .findAll()) .thenReturn(Stream.of(existingEntityType2, existingEntityType1, existingEntityType0)); PersistResult persistResult = dataPersisterImpl.persist(dataProvider, MetadataMode.UPDATE, DataMode.ADD); assertEquals(create(of(entityType0.getId(), 2L, entityType1.getId(), 3L)), persistResult); InOrder inOrder = inOrder(metaDataService, dataService); inOrder.verify(metaDataService).updateEntityType(entityType2); inOrder.verify(metaDataService).updateEntityType(entityType1); inOrder.verify(dataService).add(eq(entityType1.getId()), any(Stream.class)); inOrder.verify(metaDataService).updateEntityType(entityType0); inOrder.verify(dataService).add(eq(entityType0.getId()), any(Stream.class)); verifyNoMoreInteractions(metaDataService); }
@Transactional @Override public PersistResult persist( DataProvider dataProvider, MetadataMode metadataMode, DataMode dataMode) { List<EntityType> sortedEntityTypes = getTopologicalSortedEntityTypes(dataProvider.getEntityTypes()); preProcessEntityTypes(sortedEntityTypes, metadataMode); PersistResult persistResult = persistFirstPass(dataProvider, metadataMode, dataMode, sortedEntityTypes); persistSecondPass(dataProvider, sortedEntityTypes, metadataMode); return persistResult; }
DataPersisterImpl implements DataPersister { @Transactional @Override public PersistResult persist( DataProvider dataProvider, MetadataMode metadataMode, DataMode dataMode) { List<EntityType> sortedEntityTypes = getTopologicalSortedEntityTypes(dataProvider.getEntityTypes()); preProcessEntityTypes(sortedEntityTypes, metadataMode); PersistResult persistResult = persistFirstPass(dataProvider, metadataMode, dataMode, sortedEntityTypes); persistSecondPass(dataProvider, sortedEntityTypes, metadataMode); return persistResult; } }
DataPersisterImpl implements DataPersister { @Transactional @Override public PersistResult persist( DataProvider dataProvider, MetadataMode metadataMode, DataMode dataMode) { List<EntityType> sortedEntityTypes = getTopologicalSortedEntityTypes(dataProvider.getEntityTypes()); preProcessEntityTypes(sortedEntityTypes, metadataMode); PersistResult persistResult = persistFirstPass(dataProvider, metadataMode, dataMode, sortedEntityTypes); persistSecondPass(dataProvider, sortedEntityTypes, metadataMode); return persistResult; } DataPersisterImpl(
      MetaDataService metaDataService,
      DataService dataService,
      EntityTypeDependencyResolver entityTypeDependencyResolver); }
DataPersisterImpl implements DataPersister { @Transactional @Override public PersistResult persist( DataProvider dataProvider, MetadataMode metadataMode, DataMode dataMode) { List<EntityType> sortedEntityTypes = getTopologicalSortedEntityTypes(dataProvider.getEntityTypes()); preProcessEntityTypes(sortedEntityTypes, metadataMode); PersistResult persistResult = persistFirstPass(dataProvider, metadataMode, dataMode, sortedEntityTypes); persistSecondPass(dataProvider, sortedEntityTypes, metadataMode); return persistResult; } DataPersisterImpl(
      MetaDataService metaDataService,
      DataService dataService,
      EntityTypeDependencyResolver entityTypeDependencyResolver); @Transactional @Override PersistResult persist(
      DataProvider dataProvider, MetadataMode metadataMode, DataMode dataMode); }
DataPersisterImpl implements DataPersister { @Transactional @Override public PersistResult persist( DataProvider dataProvider, MetadataMode metadataMode, DataMode dataMode) { List<EntityType> sortedEntityTypes = getTopologicalSortedEntityTypes(dataProvider.getEntityTypes()); preProcessEntityTypes(sortedEntityTypes, metadataMode); PersistResult persistResult = persistFirstPass(dataProvider, metadataMode, dataMode, sortedEntityTypes); persistSecondPass(dataProvider, sortedEntityTypes, metadataMode); return persistResult; } DataPersisterImpl(
      MetaDataService metaDataService,
      DataService dataService,
      EntityTypeDependencyResolver entityTypeDependencyResolver); @Transactional @Override PersistResult persist(
      DataProvider dataProvider, MetadataMode metadataMode, DataMode dataMode);  }