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 { ...@@ -143,6 +143,7 @@ public class DatasetServiceImpl implements DatasetService {
datasetVersionsRepository.save(datasetVersions); datasetVersionsRepository.save(datasetVersions);
Dataset dataset = new Dataset(); Dataset dataset = new Dataset();
dataset.setUuid(source.getUuid());
dataset.setVersions(datasetVersions); dataset.setVersions(datasetVersions);
copyValues(dataset, source); copyValues(dataset, source);
dataset.setOwner(source.getOwner()); dataset.setOwner(source.getOwner());
......
...@@ -28,6 +28,7 @@ import org.genesys.catalog.persistence.PartnerRepository; ...@@ -28,6 +28,7 @@ import org.genesys.catalog.persistence.PartnerRepository;
import org.genesys.catalog.persistence.ShortFilterRepository; import org.genesys.catalog.persistence.ShortFilterRepository;
import org.genesys.catalog.persistence.traits.DescriptorListRepository; import org.genesys.catalog.persistence.traits.DescriptorListRepository;
import org.genesys.catalog.persistence.traits.DescriptorRepository; 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.DescriptorListService;
import org.genesys.catalog.service.DescriptorService; import org.genesys.catalog.service.DescriptorService;
import org.genesys.catalog.service.PartnerService; import org.genesys.catalog.service.PartnerService;
...@@ -87,6 +88,9 @@ public abstract class CatalogServiceTest extends AbstractServiceTest { ...@@ -87,6 +88,9 @@ public abstract class CatalogServiceTest extends AbstractServiceTest {
@Autowired @Autowired
protected VocabularyService vocabularyService; protected VocabularyService vocabularyService;
@Autowired
protected VocabularyTermRepository vocabularyTermRepository;
@Autowired @Autowired
protected ShortFilterService shortFilterService; protected ShortFilterService shortFilterService;
......
...@@ -414,6 +414,8 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest { ...@@ -414,6 +414,8 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
final Dataset dataset = buildAndSaveDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.DRAFT); final Dataset dataset = buildAndSaveDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.DRAFT);
dataset.setDescriptors(Lists.newArrayList(descriptor1)); dataset.setDescriptors(Lists.newArrayList(descriptor1));
dataset.setUuid(null); // Clear UUID to create a copy
Dataset savedDataset = datasetService.createDataset(dataset); Dataset savedDataset = datasetService.createDataset(dataset);
assertThat(savedDataset.getDescriptors(), contains(descriptor1)); assertThat(savedDataset.getDescriptors(), contains(descriptor1));
......
...@@ -108,7 +108,8 @@ public class DescriptorServiceTest extends CatalogServiceTest { ...@@ -108,7 +108,8 @@ public class DescriptorServiceTest extends CatalogServiceTest {
assertThat(result, not(nullValue())); assertThat(result, not(nullValue()));
assertThat(result.getId(), 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) @Test(expected = NotFoundElement.class)
...@@ -123,6 +124,21 @@ public class DescriptorServiceTest extends CatalogServiceTest { ...@@ -123,6 +124,21 @@ public class DescriptorServiceTest extends CatalogServiceTest {
descriptorService.getDescriptor(result.getUuid(), result.getVersion()); 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 @Test
public void testUnpublishDescriptorWithDescriptorList() { public void testUnpublishDescriptorWithDescriptorList() {
// create descriptor // 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