summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main
diff options
context:
space:
mode:
authorToineSiebelink <toine.siebelink@est.tech>2023-05-08 17:54:46 +0100
committerToineSiebelink <toine.siebelink@est.tech>2023-05-11 16:47:29 +0100
commit26a51754dd8aa9b467bcb442e6042f22af2ba001 (patch)
treedd701435071c0ac94931940b6f73a2139fee87fa /cps-ri/src/main
parentf8aaf8b5f26573d0dd66fef2365e547b7ca6ee7a (diff)
Move integration test for moduleService
- all modules service interation test moved - added some aditional scenarios to increase coverage - removed unused method(s) - remove javdoc on private methods - some minor refactoring like replace 'var' with correct type Issue-ID: CPS-1687 Signed-off-by: ToineSiebelink <toine.siebelink@est.tech> Change-Id: I03ff1f3562cfe38318e8b9af81be47a1fe667da2
Diffstat (limited to 'cps-ri/src/main')
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java64
1 files changed, 23 insertions, 41 deletions
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 cd1457e359..5eda15a3d7 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
@@ -37,6 +37,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
@@ -94,20 +95,14 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
@Override
public Map<String, String> getYangSchemaResources(final String dataspaceName, final String schemaSetName) {
- final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
- final var schemaSetEntity =
+ final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ final SchemaSetEntity schemaSetEntity =
schemaSetRepository.getByDataspaceAndName(dataspaceEntity, schemaSetName);
return schemaSetEntity.getYangResources().stream().collect(
Collectors.toMap(YangResourceEntity::getFileName, YangResourceEntity::getContent));
}
@Override
- public Map<String, String> getYangSchemaSetResources(final String dataspaceName, final String anchorName) {
- final var anchor = cpsAdminPersistenceService.getAnchor(dataspaceName, anchorName);
- return getYangSchemaResources(dataspaceName, anchor.getSchemaSetName());
- }
-
- @Override
public Collection<ModuleReference> getYangResourceModuleReferences(final String dataspaceName) {
final Set<YangResourceModuleReference> yangResourceModuleReferenceList =
yangResourceRepository.findAllModuleReferencesByDataspace(dataspaceName);
@@ -143,9 +138,9 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
@Backoff(random = true, delay = 200, maxDelay = 2000, multiplier = 2))
public void storeSchemaSet(final String dataspaceName, final String schemaSetName,
final Map<String, String> moduleReferenceNameToContentMap) {
- final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
- final var yangResourceEntities = synchronizeYangResources(moduleReferenceNameToContentMap);
- final var schemaSetEntity = new SchemaSetEntity();
+ final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ final Set<YangResourceEntity> yangResourceEntities = synchronizeYangResources(moduleReferenceNameToContentMap);
+ final SchemaSetEntity schemaSetEntity = new SchemaSetEntity();
schemaSetEntity.setName(schemaSetName);
schemaSetEntity.setDataspace(dataspaceEntity);
schemaSetEntity.setYangResources(yangResourceEntities);
@@ -185,8 +180,8 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
@Override
@Transactional
public void deleteSchemaSet(final String dataspaceName, final String schemaSetName) {
- final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
- final var schemaSetEntity =
+ final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ final SchemaSetEntity schemaSetEntity =
schemaSetRepository.getByDataspaceAndName(dataspaceEntity, schemaSetName);
schemaSetRepository.delete(schemaSetEntity);
}
@@ -194,7 +189,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
@Override
@Transactional
public void deleteSchemaSets(final String dataspaceName, final Collection<String> schemaSetNames) {
- final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
schemaSetRepository.deleteByDataspaceAndNameIn(dataspaceEntity, schemaSetNames);
}
@@ -217,7 +212,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
final String checksum = DigestUtils.sha256Hex(entry.getValue().getBytes(StandardCharsets.UTF_8));
final Map<String, String> moduleNameAndRevisionMap = createModuleNameAndRevisionMap(entry.getKey(),
entry.getValue());
- final var yangResourceEntity = new YangResourceEntity();
+ final YangResourceEntity yangResourceEntity = new YangResourceEntity();
yangResourceEntity.setFileName(entry.getKey());
yangResourceEntity.setContent(entry.getValue());
yangResourceEntity.setModuleName(moduleNameAndRevisionMap.get("moduleName"));
@@ -264,10 +259,10 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
private static Map<String, String> createModuleNameAndRevisionMap(final String sourceName, final String source) {
final Map<String, String> metaDataMap = new HashMap<>();
- final var revisionSourceIdentifier =
- createIdentifierFromSourceName(checkNotNull(sourceName));
+ final RevisionSourceIdentifier revisionSourceIdentifier =
+ createIdentifierFromSourceName(checkNotNull(sourceName));
- final var tempYangTextSchemaSource = new YangTextSchemaSource(revisionSourceIdentifier) {
+ final YangTextSchemaSource tempYangTextSchemaSource = new YangTextSchemaSource(revisionSourceIdentifier) {
@Override
public Optional<String> getSymbolicName() {
return Optional.empty();
@@ -285,9 +280,10 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
}
};
try {
- final var dependencyInfo = YangModelDependencyInfo.forYangText(tempYangTextSchemaSource);
- metaDataMap.put("moduleName", dependencyInfo.getName());
- metaDataMap.put("revision", dependencyInfo.getFormattedRevision());
+ final YangModelDependencyInfo yangModelDependencyInfo
+ = YangModelDependencyInfo.forYangText(tempYangTextSchemaSource);
+ metaDataMap.put("moduleName", yangModelDependencyInfo.getName());
+ metaDataMap.put("revision", yangModelDependencyInfo.getFormattedRevision());
} catch (final YangSyntaxErrorException | IOException e) {
throw new ModelValidationException("Yang resource is invalid.",
String.format("Yang syntax validation failed for resource %s:%n%s", sourceName, e.getMessage()), e);
@@ -296,7 +292,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
}
private static RevisionSourceIdentifier createIdentifierFromSourceName(final String sourceName) {
- final var matcher = RFC6020_RECOMMENDED_FILENAME_PATTERN.matcher(sourceName);
+ final Matcher matcher = RFC6020_RECOMMENDED_FILENAME_PATTERN.matcher(sourceName);
if (matcher.matches()) {
return RevisionSourceIdentifier.create(matcher.group(1), Revision.of(matcher.group(2)));
}
@@ -335,15 +331,8 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
}
- /**
- * Get the name of the yang resource having the specified checksum.
- *
- * @param checksum the checksum. Null is supported.
- * @param yangResourceEntities the list of yang resources to search among.
- * @return the name found or null if none.
- */
- private String getNameForChecksum(
- final String checksum, final Collection<YangResourceEntity> yangResourceEntities) {
+ private String getNameForChecksum(final String checksum,
+ final Collection<YangResourceEntity> yangResourceEntities) {
final Optional<String> optionalFileName = yangResourceEntities.stream()
.filter(entity -> StringUtils.equals(checksum, (entity.getChecksum())))
.findFirst()
@@ -354,19 +343,12 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
return null;
}
- /**
- * Get the checksum that caused the constraint violation exception.
- *
- * @param exception the exception having the checksum in error.
- * @return the checksum in error or null if not found.
- */
private String getDuplicatedChecksumFromException(final ConstraintViolationException exception) {
- String checksum = null;
- final var matcher = CHECKSUM_EXCEPTION_PATTERN.matcher(exception.getSQLException().getMessage());
+ final Matcher matcher = CHECKSUM_EXCEPTION_PATTERN.matcher(exception.getSQLException().getMessage());
if (matcher.find() && matcher.groupCount() == 1) {
- checksum = matcher.group(1);
+ return matcher.group(1);
}
- return checksum;
+ return null;
}
private static ModuleReference toModuleReference(