diff options
author | Ruslan Kashapov <ruslan.kashapov@pantheon.tech> | 2020-12-10 10:49:59 +0200 |
---|---|---|
committer | Claudio David Gasparini <claudio.gasparini@pantheon.tech> | 2020-12-14 08:23:13 +0000 |
commit | 4ab9d0edb5bc0c5251175078a4b8933a29e73744 (patch) | |
tree | ccf342787a59af944708edcc9e5541c71fc85f41 /cps-ri/src/test | |
parent | e182a6b6cb4a87b4f461adf83fe60a65948fc230 (diff) |
Yang resource name persistence
Issue-ID: CPS-125
Change-Id: I5ee2e893dd7c30abe86287150e8bef62966dd909
Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
Diffstat (limited to 'cps-ri/src/test')
-rw-r--r-- | cps-ri/src/test/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceTest.java | 37 | ||||
-rw-r--r-- | cps-ri/src/test/resources/data/schemaset.sql | 10 |
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); |