summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/test/java
diff options
context:
space:
mode:
authorRishi.Chail <rishi.chail@est.tech>2021-01-06 13:09:34 +0000
committerRishi.Chail <rishi.chail@est.tech>2021-01-15 14:32:35 +0000
commita16c3fb5f7f0bbe7bda9e4f21f71a3e958ed523f (patch)
treeb1e700f5c9915a38fc85af82df799072f3dd7035 /cps-ri/src/test/java
parent4118d94f71a4e5f5a4aef038f51c66fd2c1b8b60 (diff)
Retrieve the SchemaSet resources for an Anchor
Issue-ID: CPS-135 Signed-off-by: Rishi.Chail <rishi.chail@est.tech> Change-Id: Ib7c17c5180212c7dd3b96cf27797c84166041cf9
Diffstat (limited to 'cps-ri/src/test/java')
-rwxr-xr-x[-rw-r--r--]cps-ri/src/test/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceTest.java32
-rwxr-xr-x[-rw-r--r--]cps-ri/src/test/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceTest.java20
2 files changed, 43 insertions, 9 deletions
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 02487078d0..981f065282 100644..100755
--- 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,13 +32,13 @@ import org.onap.cps.spi.CpsAdminPersistenceService;
import org.onap.cps.spi.entities.AnchorEntity;
import org.onap.cps.spi.entities.DataspaceEntity;
import org.onap.cps.spi.exceptions.AnchorAlreadyDefinedException;
+import org.onap.cps.spi.exceptions.AnchorNotFoundException;
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;
import org.onap.cps.spi.repository.AnchorRepository;
import org.onap.cps.spi.repository.DataspaceRepository;
-import org.onap.cps.spi.repository.SchemaSetRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.jdbc.Sql;
@@ -61,6 +61,7 @@ public class CpsAdminPersistenceServiceTest {
private static final String ANCHOR_NAME1 = "ANCHOR-001";
private static final String ANCHOR_NAME2 = "ANCHOR-002";
private static final String ANCHOR_NAME_NEW = "ANCHOR-NEW";
+ private static final String NON_EXISTING_ANCHOR_NAME = "NON EXISTING ANCHOR";
@ClassRule
public static DatabaseTestContainer databaseTestContainer = DatabaseTestContainer.getInstance();
@@ -74,9 +75,6 @@ public class CpsAdminPersistenceServiceTest {
@Autowired
private DataspaceRepository dataspaceRepository;
- @Autowired
- private SchemaSetRepository schemaSetRepository;
-
@Test
@SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
public void testCreateDataspace() {
@@ -138,10 +136,10 @@ public class CpsAdminPersistenceServiceTest {
assertEquals(2, anchors.size());
assertTrue(anchors.contains(
Anchor.builder().name(ANCHOR_NAME1).schemaSetName(SCHEMA_SET_NAME1).dataspaceName(DATASPACE_NAME).build()
- ));
+ ));
assertTrue(anchors.contains(
Anchor.builder().name(ANCHOR_NAME2).schemaSetName(SCHEMA_SET_NAME2).dataspaceName(DATASPACE_NAME).build()
- ));
+ ));
}
@Test(expected = DataspaceNotFoundException.class)
@@ -159,4 +157,26 @@ public class CpsAdminPersistenceServiceTest {
assertTrue(anchors.isEmpty());
}
+ @Test
+ @SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
+ public void testGetAnchorByDataspaceAndAnchorName() {
+ final Anchor anchor = cpsAdminPersistenceService.getAnchor(DATASPACE_NAME, ANCHOR_NAME1);
+
+ assertNotNull(anchor);
+ assertEquals(ANCHOR_NAME1, anchor.getName());
+ assertEquals(DATASPACE_NAME, anchor.getDataspaceName());
+ }
+
+ @Test(expected = DataspaceNotFoundException.class)
+ @SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
+ public void testGetAnchorFromNonExistingDataspace() {
+ cpsAdminPersistenceService.getAnchor(NON_EXISTING_DATASPACE_NAME, ANCHOR_NAME1);
+ }
+
+ @Test(expected = AnchorNotFoundException.class)
+ @SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
+ public void testGetAnchorByNonExistingAnchorName() {
+ cpsAdminPersistenceService.getAnchor(DATASPACE_NAME, NON_EXISTING_ANCHOR_NAME);
+ }
+
}
diff --git a/cps-ri/src/test/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceTest.java b/cps-ri/src/test/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceTest.java
index e813d26bf5..8455e57517 100644..100755
--- a/cps-ri/src/test/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceTest.java
+++ b/cps-ri/src/test/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceTest.java
@@ -29,6 +29,7 @@ import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.cps.DatabaseTestContainer;
+import org.onap.cps.spi.CpsAdminPersistenceService;
import org.onap.cps.spi.CpsModulePersistenceService;
import org.onap.cps.spi.entities.DataspaceEntity;
import org.onap.cps.spi.entities.SchemaSetEntity;
@@ -37,7 +38,6 @@ import org.onap.cps.spi.exceptions.DataspaceNotFoundException;
import org.onap.cps.spi.exceptions.SchemaSetAlreadyDefinedException;
import org.onap.cps.spi.repository.DataspaceRepository;
import org.onap.cps.spi.repository.SchemaSetRepository;
-import org.onap.cps.spi.repository.YangResourceRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.jdbc.Sql;
@@ -52,6 +52,7 @@ public class CpsModulePersistenceServiceTest {
private static final String CLEAR_DATA = "/data/clear-all.sql";
private static final String SET_DATA = "/data/schemaset.sql";
+ private static final String ANCHOR_NAME = "ANCHOR-001";
private static final String DATASPACE_NAME = "DATASPACE-001";
private static final String DATASPACE_NAME_INVALID = "DATASPACE-X";
private static final String SCHEMA_SET_NAME = "SCHEMA-SET-001";
@@ -74,10 +75,10 @@ public class CpsModulePersistenceServiceTest {
private CpsModulePersistenceService cpsModulePersistenceService;
@Autowired
- private DataspaceRepository dataspaceRepository;
+ private CpsAdminPersistenceService cpsAdminPersistenceService;
@Autowired
- private YangResourceRepository yangResourceRepository;
+ private DataspaceRepository dataspaceRepository;
@Autowired
private SchemaSetRepository schemaSetRepository;
@@ -111,6 +112,19 @@ public class CpsModulePersistenceServiceTest {
@Test
@SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
+ public void testGetYangResourcesWithAnchorName() {
+ final Map<String, String> yangResourcesNameToContentMap =
+ toMap(NEW_RESOURCE_NAME, NEW_RESOURCE_CONTENT);
+ cpsModulePersistenceService.storeSchemaSet(DATASPACE_NAME, SCHEMA_SET_NAME_NEW,
+ yangResourcesNameToContentMap);
+
+ cpsAdminPersistenceService.createAnchor(DATASPACE_NAME, SCHEMA_SET_NAME_NEW, ANCHOR_NAME);
+ assertEquals(yangResourcesNameToContentMap,
+ cpsModulePersistenceService.getYangSchemaSetResources(DATASPACE_NAME, ANCHOR_NAME));
+ }
+
+ @Test
+ @SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
public void testStoreSchemaSetWithExistingYangResourceReuse() {
cpsModulePersistenceService.storeSchemaSet(DATASPACE_NAME, SCHEMA_SET_NAME_NEW,
toMap(NEW_RESOURCE_NAME, EXISTING_RESOURCE_CONTENT));