aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ri/src/test
diff options
context:
space:
mode:
authorToine Siebelink <toine.siebelink@est.tech>2020-12-14 15:20:58 +0000
committerGerrit Code Review <gerrit@onap.org>2020-12-14 15:20:58 +0000
commitc040bcb4ae61177b1aa691f059d19c96c6cfff7b (patch)
tree7535cf652f46cb0564db24f478575f3eaba99618 /cps-ri/src/test
parenta0da7f6b3e04ee6f06f4580f8a14e60f3438d5e7 (diff)
parent4ab9d0edb5bc0c5251175078a4b8933a29e73744 (diff)
Merge "Yang resource name persistence"
Diffstat (limited to 'cps-ri/src/test')
-rw-r--r--cps-ri/src/test/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceTest.java37
-rw-r--r--cps-ri/src/test/resources/data/schemaset.sql10
2 files changed, 29 insertions, 18 deletions
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 a93d277ea1..46f017bed7 100644
--- 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
@@ -22,7 +22,8 @@ package org.onap.cps.spi.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
import java.util.Set;
import org.junit.ClassRule;
import org.junit.Test;
@@ -55,8 +56,13 @@ public class CpsModulePersistenceServiceTest {
private static final String DATASPACE_NAME_INVALID = "DATASPACE-X";
private static final String SCHEMA_SET_NAME = "SCHEMA-SET-001";
private static final String SCHEMA_SET_NAME_NEW = "SCHEMA-SET-NEW";
- private static final String OLD_RESOURCE_CONTENT = "CONTENT-001";
- private static final String OLD_RESOURCE_CHECKSUM = "877e65a9f36d54e7702c3f073f6bc42b";
+
+ private static final String EXISTING_RESOURCE_NAME = "module1@2020-02-02.yang";
+ private static final String EXISTING_RESOURCE_CONTENT = "CONTENT-001";
+ private static final String EXISTING_RESOURCE_CHECKSUM = "877e65a9f36d54e7702c3f073f6bc42b";
+ private static final Long EXISTING_RESOURCE_ID = 3001L;
+
+ private static final String NEW_RESOURCE_NAME = "new-module@2020-02-02.yang";
private static final String NEW_RESOURCE_CONTENT = "CONTENT-NEW";
private static final String NEW_RESOURCE_CHECKSUM = "c94d40a1350eb1c0b1c1949eac84fc59";
private static final Long NEW_RESOURCE_ABSTRACT_ID = 0L;
@@ -80,34 +86,38 @@ public class CpsModulePersistenceServiceTest {
@Test(expected = DataspaceNotFoundException.class)
@Sql(CLEAR_DATA)
public void testStoreSchemaSetToInvalidDataspace() {
- cpsModulePersistenceService
- .storeSchemaSet(DATASPACE_NAME_INVALID, SCHEMA_SET_NAME_NEW, toSet(NEW_RESOURCE_CONTENT));
+ cpsModulePersistenceService.storeSchemaSet(DATASPACE_NAME_INVALID, SCHEMA_SET_NAME_NEW,
+ toMap(NEW_RESOURCE_NAME, NEW_RESOURCE_CONTENT));
}
@Test(expected = SchemaSetAlreadyDefinedException.class)
@SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
public void testStoreDuplicateSchemaSet() {
- cpsModulePersistenceService.storeSchemaSet(DATASPACE_NAME, SCHEMA_SET_NAME, toSet(NEW_RESOURCE_CONTENT));
+ cpsModulePersistenceService.storeSchemaSet(DATASPACE_NAME, SCHEMA_SET_NAME,
+ toMap(NEW_RESOURCE_NAME, NEW_RESOURCE_CONTENT));
}
@Test
@SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
public void testStoreSchemaSetWithNewYangResource() {
- cpsModulePersistenceService.storeSchemaSet(DATASPACE_NAME, SCHEMA_SET_NAME_NEW, toSet(NEW_RESOURCE_CONTENT));
+ cpsModulePersistenceService.storeSchemaSet(DATASPACE_NAME, SCHEMA_SET_NAME_NEW,
+ toMap(NEW_RESOURCE_NAME, NEW_RESOURCE_CONTENT));
assertSchemaSetPersisted(DATASPACE_NAME, SCHEMA_SET_NAME_NEW,
- NEW_RESOURCE_ABSTRACT_ID, NEW_RESOURCE_CONTENT, NEW_RESOURCE_CHECKSUM);
+ NEW_RESOURCE_ABSTRACT_ID, NEW_RESOURCE_NAME, NEW_RESOURCE_CONTENT, NEW_RESOURCE_CHECKSUM);
}
@Test
@SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
public void testStoreSchemaSetWithExistingYangResourceReuse() {
- cpsModulePersistenceService.storeSchemaSet(DATASPACE_NAME, SCHEMA_SET_NAME_NEW, toSet(OLD_RESOURCE_CONTENT));
+ cpsModulePersistenceService.storeSchemaSet(DATASPACE_NAME, SCHEMA_SET_NAME_NEW,
+ toMap(NEW_RESOURCE_NAME, EXISTING_RESOURCE_CONTENT));
assertSchemaSetPersisted(DATASPACE_NAME, SCHEMA_SET_NAME_NEW,
- 3001L, OLD_RESOURCE_CONTENT, OLD_RESOURCE_CHECKSUM);
+ EXISTING_RESOURCE_ID, EXISTING_RESOURCE_NAME, EXISTING_RESOURCE_CONTENT, EXISTING_RESOURCE_CHECKSUM);
}
private void assertSchemaSetPersisted(final String expectedDataspaceName, final String expectedSchemaSetName,
- final Long expectedYangResourceId, final String expectedYangResourceContent,
+ final Long expectedYangResourceId, final String expectedYangResourceName,
+ final String expectedYangResourceContent,
final String expectedYangResourceChecksum) {
// assert the schema set is persisted
@@ -127,12 +137,13 @@ public class CpsModulePersistenceServiceTest {
// existing resource with known id
assertEquals(expectedYangResourceId, yangResource.getId());
}
+ assertEquals(expectedYangResourceName, yangResource.getName());
assertEquals(expectedYangResourceContent, yangResource.getContent());
assertEquals(expectedYangResourceChecksum, yangResource.getChecksum());
}
- private static Set<String> toSet(final String... elements) {
- return ImmutableSet.<String>builder().add(elements).build();
+ private static Map<String, String> toMap(final String key, final String value) {
+ return ImmutableMap.<String, String>builder().put(key, value).build();
}
private SchemaSet getSchemaSetFromDatabase(final String dataspaceName, final String schemaSetName) {
diff --git a/cps-ri/src/test/resources/data/schemaset.sql b/cps-ri/src/test/resources/data/schemaset.sql
index 23788c3c00..e3fc69b086 100644
--- a/cps-ri/src/test/resources/data/schemaset.sql
+++ b/cps-ri/src/test/resources/data/schemaset.sql
@@ -4,11 +4,11 @@ INSERT INTO DATASPACE (ID, NAME) VALUES
INSERT INTO SCHEMA_SET (ID, NAME, DATASPACE_ID) VALUES
(2001, 'SCHEMA-SET-001', 1001), (2002, 'SCHEMA-SET-002', 1001);
-INSERT INTO YANG_RESOURCE (ID, CONTENT, CHECKSUM) VALUES
- (3001, 'CONTENT-001', '877e65a9f36d54e7702c3f073f6bc42b'),
- (3002, 'CONTENT-002', '88892586b1f23fe8c1595759784a18f8'),
- (3003, 'CONTENT-003', 'fc5740499a09a48e0c95d6fc45d4bde8'),
- (3004, 'CONTENT-004', '3801280fe532f5cbf535695cf6122026');
+INSERT INTO YANG_RESOURCE (ID, NAME, CONTENT, CHECKSUM) VALUES
+ (3001, 'module1@2020-02-02.yang', 'CONTENT-001', '877e65a9f36d54e7702c3f073f6bc42b'),
+ (3002, 'module2@2020-02-02.yang', 'CONTENT-002', '88892586b1f23fe8c1595759784a18f8'),
+ (3003, 'module3@2020-02-02.yang', 'CONTENT-003', 'fc5740499a09a48e0c95d6fc45d4bde8'),
+ (3004, 'module4@2020-02-02.yang', 'CONTENT-004', '3801280fe532f5cbf535695cf6122026');
INSERT INTO SCHEMA_SET_YANG_RESOURCES (SCHEMA_SET_ID, YANG_RESOURCE_ID) VALUES
(2001, 3001), (2001, 3002), (2002, 3003), (2002, 3004);