Commit aeb3084b authored by Matija Obreza's avatar Matija Obreza

Fix: Respect incoming Dataset#uuid when creating a new record

- Test that VocabularyTerms are deleted with Descriptor
parent 9111ee6e
......@@ -143,6 +143,7 @@ public class DatasetServiceImpl implements DatasetService {
datasetVersionsRepository.save(datasetVersions);
Dataset dataset = new Dataset();
dataset.setUuid(source.getUuid());
dataset.setVersions(datasetVersions);
copyValues(dataset, source);
dataset.setOwner(source.getOwner());
......
......@@ -28,6 +28,7 @@ import org.genesys.catalog.persistence.PartnerRepository;
import org.genesys.catalog.persistence.ShortFilterRepository;
import org.genesys.catalog.persistence.traits.DescriptorListRepository;
import org.genesys.catalog.persistence.traits.DescriptorRepository;
import org.genesys.catalog.persistence.vocab.VocabularyTermRepository;
import org.genesys.catalog.service.DescriptorListService;
import org.genesys.catalog.service.DescriptorService;
import org.genesys.catalog.service.PartnerService;
......@@ -87,6 +88,9 @@ public abstract class CatalogServiceTest extends AbstractServiceTest {
@Autowired
protected VocabularyService vocabularyService;
@Autowired
protected VocabularyTermRepository vocabularyTermRepository;
@Autowired
protected ShortFilterService shortFilterService;
......
......@@ -414,6 +414,8 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
final Dataset dataset = buildAndSaveDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.DRAFT);
dataset.setDescriptors(Lists.newArrayList(descriptor1));
dataset.setUuid(null); // Clear UUID to create a copy
Dataset savedDataset = datasetService.createDataset(dataset);
assertThat(savedDataset.getDescriptors(), contains(descriptor1));
......
......@@ -108,7 +108,8 @@ public class DescriptorServiceTest extends CatalogServiceTest {
assertThat(result, not(nullValue()));
assertThat(result.getId(), not(nullValue()));
assertThat(result.getTerms(), not(hasSize(0)));
assertThat(result.getTerms(), hasSize(2));
assertThat(vocabularyTermRepository.count(), is(2l));
}
@Test(expected = NotFoundElement.class)
......@@ -123,6 +124,21 @@ public class DescriptorServiceTest extends CatalogServiceTest {
descriptorService.getDescriptor(result.getUuid(), result.getVersion());
}
@Test(expected = NotFoundElement.class)
public void testRemoveDescriptorWithTerms() {
final UUID uuid = UUID.randomUUID();
final Descriptor input = setupDescriptor(uuid, DESCRIPTOR_TITLE_1, Category.PASSPORT, DataType.CODED, VERSION_1_0, PublishState.DRAFT);
input.setTerms(Lists.newArrayList(VocabularyTerm.fromData(TERM_CODE_1, TERM_TITLE_1), VocabularyTerm.fromData(TERM_CODE_2, TERM_TITLE_2)));
Descriptor result = descriptorService.createDescriptor(input);
assertThat(result.getTerms(), not(hasSize(0)));
result = descriptorService.removeDescriptor(result);
descriptorService.getDescriptor(result.getUuid(), result.getVersion());
assertThat(vocabularyTermRepository.count(), is(0l));
}
@Test
public void testUnpublishDescriptorWithDescriptorList() {
// create descriptor
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment