summaryrefslogtreecommitdiffstats
path: root/cps-ri
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ri')
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java10
-rw-r--r--cps-ri/src/test/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceTest.java19
2 files changed, 29 insertions, 0 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java
index 5093ba5899..d6579bdbb5 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java
@@ -28,6 +28,7 @@ import org.onap.cps.spi.entities.Dataspace;
import org.onap.cps.spi.entities.Fragment;
import org.onap.cps.spi.entities.SchemaSet;
import org.onap.cps.spi.exceptions.AnchorAlreadyDefinedException;
+import org.onap.cps.spi.exceptions.DataspaceAlreadyDefinedException;
import org.onap.cps.spi.model.Anchor;
import org.onap.cps.spi.repository.DataspaceRepository;
import org.onap.cps.spi.repository.FragmentRepository;
@@ -49,6 +50,15 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
private SchemaSetRepository schemaSetRepository;
@Override
+ public void createDataspace(final String dataspaceName) {
+ try {
+ dataspaceRepository.save(new Dataspace(dataspaceName));
+ } catch (final DataIntegrityViolationException e) {
+ throw new DataspaceAlreadyDefinedException(dataspaceName, e);
+ }
+ }
+
+ @Override
public void createAnchor(final String dataspaceName, final String schemaSetName, final String anchorName) {
final Dataspace dataspace = dataspaceRepository.getByName(dataspaceName);
final SchemaSet schemaSet = schemaSetRepository.getByDataspaceAndName(dataspace, schemaSetName);
diff --git a/cps-ri/src/test/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceTest.java b/cps-ri/src/test/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceTest.java
index 455369d2cf..7497526f9a 100644
--- a/cps-ri/src/test/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceTest.java
+++ b/cps-ri/src/test/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceTest.java
@@ -32,6 +32,7 @@ import org.onap.cps.spi.CpsAdminPersistenceService;
import org.onap.cps.spi.entities.Dataspace;
import org.onap.cps.spi.entities.Fragment;
import org.onap.cps.spi.exceptions.AnchorAlreadyDefinedException;
+import org.onap.cps.spi.exceptions.DataspaceAlreadyDefinedException;
import org.onap.cps.spi.exceptions.DataspaceNotFoundException;
import org.onap.cps.spi.exceptions.SchemaSetNotFoundException;
import org.onap.cps.spi.model.Anchor;
@@ -78,6 +79,24 @@ public class CpsAdminPersistenceServiceTest {
@Test
@SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
+ public void testCreateDataspace() {
+ final String dataspaceName = "DATASPACE-NEW";
+ cpsAdminPersistenceService.createDataspace(dataspaceName);
+
+ final Dataspace dataspace = dataspaceRepository.findByName(dataspaceName).orElseThrow();
+ assertNotNull(dataspace);
+ assertNotNull(dataspace.getId());
+ assertEquals(dataspaceName, dataspace.getName());
+ }
+
+ @Test(expected = DataspaceAlreadyDefinedException.class)
+ @SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
+ public void testCreateDataspaceWithNameAlreadyDefined() {
+ cpsAdminPersistenceService.createDataspace(DATASPACE_NAME);
+ }
+
+ @Test
+ @SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
public void testCreateAnchor() {
cpsAdminPersistenceService.createAnchor(DATASPACE_NAME, SCHEMA_SET_NAME2, ANCHOR_NAME_NEW);