summaryrefslogtreecommitdiffstats
path: root/cps-ri
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ri')
-rw-r--r--cps-ri/pom.xml7
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java29
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java33
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java28
-rwxr-xr-xcps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy22
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy40
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy45
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy1
-rw-r--r--cps-ri/src/test/resources/data/schemaset.sql28
9 files changed, 179 insertions, 54 deletions
diff --git a/cps-ri/pom.xml b/cps-ri/pom.xml
index 273cb2e72f..00911f83f6 100644
--- a/cps-ri/pom.xml
+++ b/cps-ri/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.cps</groupId>
<artifactId>cps-parent</artifactId>
- <version>1.1.0-SNAPSHOT</version>
+ <version>2.0.1-SNAPSHOT</version>
<relativePath>../cps-parent/pom.xml</relativePath>
</parent>
@@ -96,6 +96,10 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </dependency>
<!-- T E S T D E P E N D E N C I E S -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
@@ -140,6 +144,7 @@
</dependency>
</dependencies>
+
<build>
<plugins>
<plugin>
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
index af010f4fcd..c57723d322 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
@@ -24,12 +24,15 @@ package org.onap.cps.spi.impl;
import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -50,6 +53,7 @@ import org.onap.cps.spi.exceptions.AlreadyDefinedException;
import org.onap.cps.spi.exceptions.ConcurrencyException;
import org.onap.cps.spi.exceptions.CpsPathException;
import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
+import org.onap.cps.spi.exceptions.DataValidationException;
import org.onap.cps.spi.model.DataNode;
import org.onap.cps.spi.model.DataNodeBuilder;
import org.onap.cps.spi.repository.AnchorRepository;
@@ -68,6 +72,8 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
private FragmentRepository fragmentRepository;
+ private final ObjectMapper objectMapper;
+
/**
* Constructor.
*
@@ -80,11 +86,12 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
this.dataspaceRepository = dataspaceRepository;
this.anchorRepository = anchorRepository;
this.fragmentRepository = fragmentRepository;
+ this.objectMapper = new ObjectMapper();
}
private static final Gson GSON = new GsonBuilder().create();
private static final String REG_EX_FOR_OPTIONAL_LIST_INDEX = "(\\[@[\\s\\S]+?]){0,1})";
- private static final String REG_EX_FOR_LIST_NODE_KEY = "\\[(\\@([^/]*?))+( and)*\\]$";
+ private static final String REG_EX_FOR_LIST_NODE_KEY = "\\[(\\@([^/]*?)){0,99}( and)*\\]$";
@Override
public void addChildDataNode(final String dataspaceName, final String anchorName, final String parentXpath,
@@ -236,17 +243,27 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
return ancestorXpath;
}
- private static DataNode toDataNode(final FragmentEntity fragmentEntity,
+ private DataNode toDataNode(final FragmentEntity fragmentEntity,
final FetchDescendantsOption fetchDescendantsOption) {
- final Map<String, Object> leaves = GSON.fromJson(fragmentEntity.getAttributes(), Map.class);
final List<DataNode> childDataNodes = getChildDataNodes(fragmentEntity, fetchDescendantsOption);
+ Map<String, Object> leaves = new HashMap<>();
+ if (fragmentEntity.getAttributes() != null) {
+ try {
+ leaves = objectMapper.readValue(fragmentEntity.getAttributes(), Map.class);
+ } catch (final JsonProcessingException jsonProcessingException) {
+ final String message = "Parsing error occurred while processing fragmentEntity attributes.";
+ log.error(message);
+ throw new DataValidationException(message,
+ jsonProcessingException.getMessage(), jsonProcessingException);
+ }
+ }
return new DataNodeBuilder()
.withXpath(fragmentEntity.getXpath())
.withLeaves(leaves)
.withChildDataNodes(childDataNodes).build();
}
- private static List<DataNode> getChildDataNodes(final FragmentEntity fragmentEntity,
+ private List<DataNode> getChildDataNodes(final FragmentEntity fragmentEntity,
final FetchDescendantsOption fetchDescendantsOption) {
if (fetchDescendantsOption == INCLUDE_ALL_DESCENDANTS) {
return fragmentEntity.getChildFragments().stream()
@@ -327,10 +344,10 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
final Matcher descendantNodeHasListNodeKey = Pattern.compile(REG_EX_FOR_LIST_NODE_KEY).matcher(descendantNode);
final boolean xpathPointsToAValidChildNodeWithKey = parentEntity.getChildFragments().stream().anyMatch(
- (fragment) -> fragment.getXpath().equals(listNodeXpath));
+ fragment -> fragment.getXpath().equals(listNodeXpath));
final boolean xpathPointsToAValidChildNodeWithoutKey = parentEntity.getChildFragments().stream().anyMatch(
- (fragment) -> fragment.getXpath().replaceAll(REG_EX_FOR_LIST_NODE_KEY, "").equals(listNodeXpath));
+ fragment -> fragment.getXpath().replaceAll(REG_EX_FOR_LIST_NODE_KEY, "").equals(listNodeXpath));
if ((descendantNodeHasListNodeKey.find() && xpathPointsToAValidChildNodeWithKey)
||
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
index 1c7828f32e..e0f54265ab 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
@@ -116,11 +116,21 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
}
@Override
- public List<ModuleReference> getAllYangResourcesModuleReferences() {
- final List<YangResourceModuleReference> yangResourceModuleReferenceList =
- yangResourceRepository.findAllModuleNameAndRevision();
+ public Collection<ModuleReference> getYangResourceModuleReferences(final String dataspaceName) {
+ final Set<YangResourceModuleReference> yangResourceModuleReferenceList =
+ yangResourceRepository.findAllModuleReferences(dataspaceName);
return yangResourceModuleReferenceList.stream().map(CpsModulePersistenceServiceImpl::toModuleReference)
- .collect(Collectors.toList());
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public Collection<ModuleReference> getYangResourceModuleReferences(final String dataspaceName,
+ final String anchorName) {
+ final Set<YangResourceModuleReference> yangResourceModuleReferenceList =
+ yangResourceRepository
+ .findAllModuleReferences(dataspaceName, anchorName);
+ return yangResourceModuleReferenceList.stream().map(CpsModulePersistenceServiceImpl::toModuleReference)
+ .collect(Collectors.toList());
}
@Override
@@ -148,15 +158,15 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
@Transactional
public void storeSchemaSetFromModules(final String dataspaceName, final String schemaSetName,
final Map<String, String> newYangResourcesModuleNameToContentMap,
- final List<ModuleReference> moduleReferenceList) {
+ final List<ModuleReference> moduleReferences) {
storeSchemaSet(dataspaceName, schemaSetName, newYangResourcesModuleNameToContentMap);
final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
final var schemaSetEntity =
schemaSetRepository.getByDataspaceAndName(dataspaceEntity, schemaSetName);
final List<Long> listOfYangResourceIds = new ArrayList<>();
- moduleReferenceList.forEach(moduleReference ->
+ moduleReferences.forEach(moduleReference ->
listOfYangResourceIds.add(yangResourceRepository.getIdByModuleNameAndRevision(
- moduleReference.getName(), moduleReference.getRevision())));
+ moduleReference.getModuleName(), moduleReference.getRevision())));
yangResourceRepository.insertSchemaSetIdYangResourceId(schemaSetEntity.getId(), listOfYangResourceIds);
}
@@ -325,10 +335,11 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
return checksum;
}
- private static ModuleReference toModuleReference(final YangResourceModuleReference yangResourceModuleReference) {
+ private static ModuleReference toModuleReference(
+ final YangResourceModuleReference yangResourceModuleReference) {
return ModuleReference.builder()
- .name(yangResourceModuleReference.getModuleName())
- .revision(yangResourceModuleReference.getRevision())
- .build();
+ .moduleName(yangResourceModuleReference.getModuleName())
+ .revision(yangResourceModuleReference.getRevision())
+ .build();
}
}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java
index 0b48eaaf63..b16b284a2a 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java
@@ -37,8 +37,32 @@ public interface YangResourceRepository extends JpaRepository<YangResourceEntity
List<YangResourceEntity> findAllByChecksumIn(@NotNull Set<String> checksum);
- @Query(value = "SELECT module_name, revision FROM yang_resource", nativeQuery = true)
- List<YangResourceModuleReference> findAllModuleNameAndRevision();
+ @Query(value = "SELECT DISTINCT\n"
+ + "yr.module_name AS module_name,\n"
+ + "yr.revision AS revision\n"
+ + "FROM\n"
+ + "dataspace d\n"
+ + "JOIN schema_set ss ON ss.dataspace_id = d.id\n"
+ + "JOIN schema_set_yang_resources ssyr ON ssyr.schema_set_id = ss.id\n"
+ + "JOIN yang_resource yr ON yr.id = ssyr.yang_resource_id\n"
+ + "WHERE\n"
+ + "d.name = :dataspaceName", nativeQuery = true)
+ Set<YangResourceModuleReference> findAllModuleReferences(@Param("dataspaceName") String dataspaceName);
+
+ @Query(value = "SELECT DISTINCT\n"
+ + "yr.module_Name AS module_name,\n"
+ + "yr.revision AS revision\n"
+ + "FROM\n"
+ + "dataspace d\n"
+ + "JOIN anchor a ON a.dataspace_id = d.id\n"
+ + "JOIN schema_set ss ON ss.dataspace_id = a.dataspace_id\n"
+ + "JOIN schema_set_yang_resources ssyr ON ssyr.schema_set_id = ss.id\n"
+ + "JOIN yang_resource yr ON yr.id = ssyr.yang_resource_id\n"
+ + "WHERE\n"
+ + "d.name = :dataspaceName AND\n"
+ + "a.name =:anchorName", nativeQuery = true)
+ Set<YangResourceModuleReference> findAllModuleReferences(
+ @Param("dataspaceName") String dataspaceName, @Param("anchorName") String anchorName);
@Query(value = "SELECT id FROM yang_resource WHERE module_name=:name and revision=:revision", nativeQuery = true)
Long getIdByModuleNameAndRevision(@Param("name") String moduleName, @Param("revision") String revision);
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy
index 8217a4fb0d..e2316e8636 100755
--- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy
@@ -21,11 +21,6 @@
*/
package org.onap.cps.spi.impl
-import org.onap.cps.spi.exceptions.DataValidationException
-
-import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
-import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
-
import com.google.common.collect.ImmutableSet
import com.google.gson.Gson
import com.google.gson.GsonBuilder
@@ -42,6 +37,9 @@ import org.springframework.test.context.jdbc.Sql
import javax.validation.ConstraintViolationException
+import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
+import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
+
class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
@Autowired
@@ -155,17 +153,25 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
}
@Sql([CLEAR_DATA, SET_DATA])
- def 'Add list-node fragment with multiple elements.'() {
- given: 'list node data fragment as a collection of data nodes'
+ def 'Add list-node fragment with multiple elements including an element with a child datanode.'() {
+ given: 'two new data nodes for an existing list'
def listNodeXpaths = ['/parent-201/child-204[@key="B"]', '/parent-201/child-204[@key="C"]']
def listNodeCollection = buildDataNodeCollection(listNodeXpaths)
- when: 'list-node elements added to existing parent node'
+ and: 'a child node for one of the new data nodes'
+ def childDataNode = buildDataNode('/parent-201/child-204[@key="C"]/grand-child-204[@key2="Z"]', [leave:'value'], [])
+ listNodeCollection.iterator().next().childDataNodes = [childDataNode]
+ when: 'the data nodes (list elements) are added to existing parent node'
objectUnderTest.addListDataNodes(DATASPACE_NAME, ANCHOR_NAME3, '/parent-201', listNodeCollection)
then: 'new entries successfully persisted, parent node now contains 5 children (2 new + 3 existing before)'
def parentFragment = fragmentRepository.getById(LIST_DATA_NODE_PARENT201_FRAGMENT_ID)
def allChildXpaths = parentFragment.getChildFragments().collect { it.getXpath() }
assert allChildXpaths.size() == 5
assert allChildXpaths.containsAll(listNodeXpaths)
+ and: 'the child node of the new list entry is also present'
+ def dataspaceEntity = dataspaceRepository.getByName(DATASPACE_NAME)
+ def anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, ANCHOR_NAME3)
+ def listElementChild = fragmentRepository.findByDataspaceAndAnchorAndXpath(dataspaceEntity, anchorEntity, childDataNode.xpath)
+ assert listElementChild.isPresent()
}
@Sql([CLEAR_DATA, SET_DATA])
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy
index 5ed3ae3e8c..162a56682a 100644
--- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy
@@ -19,8 +19,10 @@
package org.onap.cps.spi.impl
import org.hibernate.StaleStateException
+import org.onap.cps.spi.FetchDescendantsOption
import org.onap.cps.spi.entities.FragmentEntity
import org.onap.cps.spi.exceptions.ConcurrencyException
+import org.onap.cps.spi.exceptions.DataValidationException
import org.onap.cps.spi.model.DataNodeBuilder
import org.onap.cps.spi.repository.AnchorRepository
import org.onap.cps.spi.repository.DataspaceRepository
@@ -68,5 +70,43 @@ class CpsDataPersistenceServiceSpec extends Specification {
assert concurrencyException.getDetails().contains(parentXpath)
}
+ def 'Retrieving a data node with a property JSON value of #scenario'() {
+ given: 'a fragment with a property JSON value of #scenario'
+ mockFragmentRepository.getByDataspaceAndAnchorAndXpath(_, _, _) >> {
+ new FragmentEntity(childFragments: Collections.emptySet(),
+ attributes: "{\"some attribute\": ${dataString}}")
+ }
+ when: 'getting the data node represented by this fragment'
+ def dataNode = objectUnderTest.getDataNode('my-dataspace', 'my-anchor',
+ 'parent-01', FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS)
+ then: 'the leaf is of the correct value and data type'
+ def attributeValue = dataNode.leaves.get('some attribute')
+ assert attributeValue == expectedValue
+ assert attributeValue.class == expectedDataClass
+ where: 'the following Data Type is passed'
+ scenario | dataString || expectedValue | expectedDataClass
+ 'just numbers' | '15174' || 15174 | Integer
+ 'number with dot' | '15174.32' || 15174.32 | Double
+ 'number with 0 value after dot' | '15174.0' || 15174.0 | Double
+ 'number with 0 value before dot' | '0.32' || 0.32 | Double
+ 'number higher than max int' | '2147483648' || 2147483648 | Long
+ 'just text' | '"Test"' || 'Test' | String
+ 'number with exponent' | '1.2345e5' || 1.2345e5 | Double
+ 'number higher than max int with dot' | '123456789101112.0' || 123456789101112.0 | Double
+ 'text and numbers' | '"String = \'1234\'"' || "String = '1234'" | String
+ 'number as String' | '"12345"' || '12345' | String
+ }
+
+ def 'Retrieving a data node with invalid JSON'() {
+ given: 'a fragment with invalid JSON'
+ mockFragmentRepository.getByDataspaceAndAnchorAndXpath(_, _, _) >> {
+ new FragmentEntity(childFragments: Collections.emptySet(), attributes: '{invalid json')
+ }
+ when: 'getting the data node represented by this fragment'
+ def dataNode = objectUnderTest.getDataNode('my-dataspace', 'my-anchor',
+ 'parent-01', FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS)
+ then: 'a data validation exception is thrown'
+ thrown(DataValidationException)
+ }
}
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy
index 7a16a97d4b..7e42200799 100644
--- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy
@@ -20,22 +20,23 @@
*/
package org.onap.cps.spi.impl
-import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED
-import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED
-
import org.onap.cps.spi.CpsAdminPersistenceService
import org.onap.cps.spi.CpsModulePersistenceService
import org.onap.cps.spi.entities.YangResourceEntity
-import org.onap.cps.spi.exceptions.DataspaceNotFoundException
import org.onap.cps.spi.exceptions.AlreadyDefinedException
+import org.onap.cps.spi.exceptions.DataspaceNotFoundException
import org.onap.cps.spi.exceptions.SchemaSetInUseException
import org.onap.cps.spi.exceptions.SchemaSetNotFoundException
import org.onap.cps.spi.model.ModuleReference
+import org.onap.cps.spi.model.ExtendedModuleReference
import org.onap.cps.spi.repository.AnchorRepository
import org.onap.cps.spi.repository.SchemaSetRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.jdbc.Sql
+import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED
+import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED
+
class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
@Autowired
@@ -71,13 +72,13 @@ class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase
static final String NEW_RESOURCE_CHECKSUM = 'b13faef573ed1374139d02c40d8ce09c80ea1dc70e63e464c1ed61568d48d539'
static final String NEW_RESOURCE_MODULE_NAME = 'stores'
static final String NEW_RESOURCE_REVISION = '2020-09-15'
- static final ModuleReference newModuleReference = ModuleReference.builder().name(NEW_RESOURCE_MODULE_NAME)
+ static final ExtendedModuleReference newModuleReference = ExtendedModuleReference.builder().name(NEW_RESOURCE_MODULE_NAME)
.revision(NEW_RESOURCE_REVISION).build()
def newYangResourcesNameToContentMap = [(NEW_RESOURCE_NAME):NEW_RESOURCE_CONTENT]
- def allYangResourcesModuleAndRevisionList = [ModuleReference.builder().build(),ModuleReference.builder().build(),
- ModuleReference.builder().build(),ModuleReference.builder().build(),
- ModuleReference.builder().build(), newModuleReference]
+ def allYangResourcesModuleAndRevisionList = [new ExtendedModuleReference(name: 'MODULE-NAME-002',namespace:null, revision: 'REVISION-002'), new ExtendedModuleReference(name: 'MODULE-NAME-003',namespace:null, revision: 'REVISION-003'),
+ new ExtendedModuleReference(name: 'MODULE-NAME-004',namespace:null, revision: 'REVISION-004'), ExtendedModuleReference.builder().build(),
+ ExtendedModuleReference.builder().build(), newModuleReference]
def dataspaceEntity
def setup() {
@@ -109,7 +110,7 @@ class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase
def 'Store and retrieve new schema set from new modules and existing modules.'() {
given: 'map of new modules, a list of existing modules, module reference'
def mapOfNewModules = [newModule1: 'module newmodule { yang-version 1.1; revision "2021-10-12" { } }']
- def moduleReferenceForExistingModule = new ModuleReference("test","test.org","2021-10-12")
+ def moduleReferenceForExistingModule = new ModuleReference("test","2021-10-12")
def listOfExistingModulesModuleReference = [moduleReferenceForExistingModule]
def mapOfExistingModule = [test: 'module test { yang-version 1.1; revision "2021-10-12" { } }']
objectUnderTest.storeSchemaSet(DATASPACE_NAME, "someSchemaSetName", mapOfExistingModule)
@@ -135,13 +136,27 @@ class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase
}
@Sql([CLEAR_DATA, SET_DATA])
- def 'Retrieving all yang resources module references.'() {
- given: 'a new schema set is stored'
- objectUnderTest.storeSchemaSet(DATASPACE_NAME, SCHEMA_SET_NAME_NEW, newYangResourcesNameToContentMap)
- when: 'all yang resources module references are retrieved'
- def result = objectUnderTest.getAllYangResourcesModuleReferences()
+ def 'Retrieving all yang resources module references for the given dataspace.'() {
+ given: 'a dataspace name'
+ def dataspaceName = 'DATASPACE-002'
+ when: 'all yang resources module references are retrieved for the given dataspace name'
+ def result = objectUnderTest.getYangResourceModuleReferences(dataspaceName)
then: 'the correct resources are returned'
- result.sort() == allYangResourcesModuleAndRevisionList.sort()
+ result.sort() == [new ModuleReference(moduleName: 'MODULE-NAME-005', revision: 'REVISION-002'),
+ new ModuleReference(moduleName: 'MODULE-NAME-006', revision: 'REVISION-006')]
+ }
+
+ @Sql([CLEAR_DATA, SET_DATA])
+ def 'Retrieving module names and revisions for the given anchor.'() {
+ given: 'a dataspace name and anchor name'
+ def dataspaceName = 'DATASPACE-001'
+ def anchorName = 'ANCHOR1'
+ when: 'all yang resources module references are retrieved for the given anchor'
+ def result = objectUnderTest.getYangResourceModuleReferences(dataspaceName, anchorName)
+ then: 'the correct module names and revisions are returned'
+ result.sort() == [new ModuleReference(moduleName: null, revision: null), new ModuleReference(moduleName: 'MODULE-NAME-002', revision: 'REVISION-002'),
+ new ModuleReference(moduleName: 'MODULE-NAME-003', revision: 'REVISION-002'),
+ new ModuleReference(moduleName: 'MODULE-NAME-004', revision: 'REVISION-004')]
}
@Sql([CLEAR_DATA, SET_DATA])
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy
index 5132632452..8ec5c90e9c 100644
--- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy
@@ -55,6 +55,7 @@ class CpsPersistenceSpecBase extends Specification {
static final String CLEAR_DATA = '/data/clear-all.sql'
static final String DATASPACE_NAME = 'DATASPACE-001'
+ static final String DATASPACE_NAME2 = 'DATASPACE-002'
static final String SCHEMA_SET_NAME1 = 'SCHEMA-SET-001'
static final String SCHEMA_SET_NAME2 = 'SCHEMA-SET-002'
static final String ANCHOR_NAME1 = 'ANCHOR-001'
diff --git a/cps-ri/src/test/resources/data/schemaset.sql b/cps-ri/src/test/resources/data/schemaset.sql
index adfcfa172e..61600356b9 100644
--- a/cps-ri/src/test/resources/data/schemaset.sql
+++ b/cps-ri/src/test/resources/data/schemaset.sql
@@ -24,26 +24,32 @@ INSERT INTO DATASPACE (ID, NAME) VALUES
(1001, 'DATASPACE-001'), (1002, 'DATASPACE-002');
INSERT INTO SCHEMA_SET (ID, NAME, DATASPACE_ID) VALUES
- (2001, 'SCHEMA-SET-001', 1001), (2002, 'SCHEMA-SET-002', 1001),
+ (2001, 'SCHEMA-SET-001', 1001),
+ (2002, 'SCHEMA-SET-002', 1001),
(2100, 'SCHEMA-SET-100', 1001), -- for removal, not referenced by anchors
- (2101, 'SCHEMA-SET-101', 1001); -- for removal, having anchor and data associated
-
-INSERT INTO YANG_RESOURCE (ID, NAME, CONTENT, CHECKSUM) VALUES
- (3001, 'module1@2020-02-02.yang', 'CONTENT-001', 'e8bdda931099310de66532e08c3fafec391db29f55c81927b168f6aa8f81b73b'),
- (3002, 'module2@2020-02-02.yang', 'CONTENT-002', '7e7d48afbe066ed0a890a09081859046d3dde52300dfcdb13be5b20780353a11'),
- (3003, 'module3@2020-02-02.yang', 'CONTENT-003', 'ca20c45fec8547633f05ff8905c48ffa7b02b94ec3ad4ed79922e6ba40779df3'),
- (3004, 'module4@2020-02-02.yang', 'CONTENT-004', 'f6ed09d343562e4d4ae5140f3c6a55df9c53f6da8e30dda8cbd9eaf9cd449be0'),
- (3100, 'orphan@2020-02-02.yang', 'ORPHAN', 'checksum'); -- for auto-removal as orphan
+ (2101, 'SCHEMA-SET-101', 1001), -- for removal, having anchor and data associated
+ (2003, 'SCHEMA-SET-003', 1002),
+ (2004, 'SCHEMA-SET-004', 1002);
+
+INSERT INTO YANG_RESOURCE (ID, NAME, CONTENT, CHECKSUM, MODULE_NAME, REVISION) VALUES
+ (3001, 'module1@2020-02-02.yang', 'CONTENT-001', 'e8bdda931099310de66532e08c3fafec391db29f55c81927b168f6aa8f81b73b',null,null),
+ (3002, 'module2@2020-02-02.yang', 'CONTENT-002', '7e7d48afbe066ed0a890a09081859046d3dde52300dfcdb13be5b20780353a11','MODULE-NAME-002','REVISION-002'),
+ (3003, 'module3@2020-02-02.yang', 'CONTENT-003', 'ca20c45fec8547633f05ff8905c48ffa7b02b94ec3ad4ed79922e6ba40779df3','MODULE-NAME-003','REVISION-002'),
+ (3004, 'module4@2020-02-02.yang', 'CONTENT-004', 'f6ed09d343562e4d4ae5140f3c6a55df9c53f6da8e30dda8cbd9eaf9cd449be0','MODULE-NAME-004','REVISION-004'),
+ (3100, 'orphan@2020-02-02.yang', 'ORPHAN', 'checksum',null,null), -- for auto-removal as orphan
+ (3005, 'module5@2020-02-02.yang', 'CONTENT-005', 'checksum-005','MODULE-NAME-005','REVISION-002'),
+ (3006, 'module6@2020-02-02.yang', 'CONTENT-006', 'checksum-006','MODULE-NAME-006','REVISION-006');
INSERT INTO SCHEMA_SET_YANG_RESOURCES (SCHEMA_SET_ID, YANG_RESOURCE_ID) VALUES
(2001, 3001), (2001, 3002),
(2002, 3003), (2002, 3004),
(2100, 3003), (2100, 3100), -- orphan removal case
- (2101, 3003), (2101, 3004);
+ (2101, 3003), (2101, 3004),
+ (2003, 3005), (2004, 3006);
INSERT INTO ANCHOR (ID, NAME, DATASPACE_ID, SCHEMA_SET_ID) VALUES -- anchors for removal
(6001, 'ANCHOR1', 1001, 2101),
(6002, 'ANCHOR2', 1001, 2101);
INSERT INTO FRAGMENT (ID, XPATH, ANCHOR_ID, DATASPACE_ID) VALUES
- (7001, '/XPATH', 6001, 1001);
+ (7001, '/XPATH', 6001, 1001); \ No newline at end of file