@Test public void testAdd() { when(idGenerator.generateId()).thenReturn("mappingProjectID"); when(mappingTargetRepository.upsert(asList(mappingTarget1, mappingTarget2))) .thenReturn(mappingTargetEntities); mappingProjectRepositoryImpl.add(mappingProject); Mockito.verify(dataService).add(ENTITY_NAME, mappingProjectEntity); assertNull(mappingTarget1.getIdentifier()); assertNull(mappingTarget2.getIdentifier()); }
private Entity upsert(EntityMapping entityMapping) { List<Entity> attributeMappingEntities = attributeMappingRepository.upsert(entityMapping.getAttributeMappings()); Entity entityMappingEntity; if (entityMapping.getIdentifier() == null) { entityMapping.setIdentifier(idGenerator.generateId()); entityMappingEntity = toEntityMappingEntity(entityMapping, attributeMappingEntities); dataService.add(EntityMappingRepositoryImpl.META_DATA.getName(), entityMappingEntity); } else { entityMappingEntity = toEntityMappingEntity(entityMapping, attributeMappingEntities); dataService.update(EntityMappingRepositoryImpl.META_DATA.getName(), entityMappingEntity); } return entityMappingEntity; }