summaryrefslogtreecommitdiffstats
path: root/cps-service/src
diff options
context:
space:
mode:
authorBruno Sakoto <bruno.sakoto@bell.ca>2020-12-10 13:29:14 +0000
committerGerrit Code Review <gerrit@onap.org>2020-12-10 13:29:14 +0000
commit57bb1d811eac4011bfcdf3be1ea60d869879c147 (patch)
tree81ea6f0d0f4449249c14d6dfed6a75747d12c9d3 /cps-service/src
parentb5056a392694c50d26d69e587cc55a04a2af04bd (diff)
parent098a93c84aae8d8d74e7589518a576b84c38ca27 (diff)
Merge "Improve CPS Exception handling"
Diffstat (limited to 'cps-service/src')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java4
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java4
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java8
-rw-r--r--cps-service/src/main/java/org/onap/cps/exceptions/CpsExceptionBuilder.java94
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/exceptions/AnchorAlreadyDefinedException.java37
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsAdminException.java (renamed from cps-service/src/main/java/org/onap/cps/exceptions/CpsAdminException.java)28
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsException.java (renamed from cps-service/src/main/java/org/onap/cps/exceptions/CpsException.java)22
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/exceptions/DataValidationException.java (renamed from cps-service/src/main/java/org/onap/cps/exceptions/CpsNotFoundException.java)37
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/exceptions/DataspaceNotFoundException.java (renamed from cps-service/src/main/java/org/onap/cps/exceptions/DataspaceNotFoundException.java)26
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/exceptions/ModelValidationException.java (renamed from cps-service/src/main/java/org/onap/cps/exceptions/CpsValidationException.java)32
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/exceptions/NotFoundInDataspaceException.java34
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetAlreadyDefinedException.java39
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminPersistenceServiceImplSpec.groovy86
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy55
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModulePersistenceServiceImplSpec.groovy4
15 files changed, 221 insertions, 289 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java b/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java
index 406655e5e2..98ea8ebd8d 100644
--- a/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java
+++ b/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java
@@ -20,7 +20,7 @@
package org.onap.cps.api;
-import org.onap.cps.exceptions.CpsValidationException;
+import org.onap.cps.spi.exceptions.CpsException;
import org.onap.cps.spi.model.Anchor;
/**
@@ -33,7 +33,7 @@ public interface CpsAdminService {
*
* @param anchor the anchor details object.
* @return the anchor name.
- * @throws CpsValidationException if input data is invalid.
+ * @throws CpsException if input data is invalid.
*/
String createAnchor(Anchor anchor);
}
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java b/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java
index 02553d0741..94ebea2fc2 100644
--- a/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java
+++ b/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java
@@ -20,7 +20,7 @@
package org.onap.cps.api;
import java.io.File;
-import org.onap.cps.exceptions.CpsValidationException;
+import org.onap.cps.spi.exceptions.CpsException;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
/**
@@ -49,7 +49,7 @@ public interface CpsModuleService {
*
* @param schemaContext the schema context
* @param dataspaceName the dataspace name
- * @throws CpsValidationException if input data already exists.
+ * @throws CpsException if input data already exists.
*/
void storeSchemaContext(SchemaContext schemaContext, String dataspaceName);
}
diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java
index 87ffdd3d90..c7fa04759a 100644
--- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java
@@ -26,9 +26,9 @@ import java.io.FileWriter;
import java.io.IOException;
import java.util.Optional;
import org.onap.cps.api.CpsModuleService;
-import org.onap.cps.exceptions.CpsException;
-import org.onap.cps.exceptions.CpsValidationException;
import org.onap.cps.spi.CpsModulePersistenceService;
+import org.onap.cps.spi.exceptions.CpsException;
+import org.onap.cps.spi.exceptions.ModelValidationException;
import org.onap.cps.utils.YangUtils;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.Module;
@@ -47,7 +47,7 @@ public class CpsModuleServiceImpl implements CpsModuleService {
public SchemaContext parseAndValidateModel(final String yangModelContent) {
try {
final File tempFile = File.createTempFile("yang", ".yang");
- try (BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile))) {
+ try (final BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile))) {
writer.write(yangModelContent);
}
return parseAndValidateModel(tempFile);
@@ -61,7 +61,7 @@ public class CpsModuleServiceImpl implements CpsModuleService {
try {
return YangUtils.parseYangModelFile(yangModelFile);
} catch (final YangParserException e) {
- throw new CpsValidationException("Yang file validation failed", e.getMessage());
+ throw new ModelValidationException("Yang file validation failed", e.getMessage(), e);
} catch (final IOException e) {
throw new CpsException(e);
}
diff --git a/cps-service/src/main/java/org/onap/cps/exceptions/CpsExceptionBuilder.java b/cps-service/src/main/java/org/onap/cps/exceptions/CpsExceptionBuilder.java
deleted file mode 100644
index 2acbb92322..0000000000
--- a/cps-service/src/main/java/org/onap/cps/exceptions/CpsExceptionBuilder.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2020 Pantheon.tech
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.cps.exceptions;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-/**
- * Utility class.
- * Serves error message consistency for same error cases occurred in different CPS modules.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public class CpsExceptionBuilder {
-
- private static final String SCHEMA_SET_IS_INVALID = "Schema Set is invalid.";
-
- /**
- * Generates validation error exception for case when requested dataspace is absent.
- *
- * @param dataspaceName dataspace name
- */
- public static CpsException invalidDataspaceException(final String dataspaceName) {
- return new CpsValidationException("Dataspace is invalid.",
- String.format("Dataspace with name %s does not exist.", dataspaceName));
- }
-
- /**
- * Generates validation error exception for case when requested schema set is absent for existing dataspace.
- *
- * @param dataspaceName dataspace name
- * @param schemaSetName schema set name
- */
- public static CpsException invalidSchemaSetException(final String dataspaceName, final String schemaSetName) {
- return new CpsValidationException(SCHEMA_SET_IS_INVALID,
- String.format("Schema Set with name %s was not found for dataspace %s.", schemaSetName, dataspaceName));
- }
-
- /**
- * Returns validation error exception for case when SchemaSet contains no files.
- */
- public static CpsException emptySchemaSetException() {
- return new CpsValidationException(SCHEMA_SET_IS_INVALID, "Schema Set has no YANG resources to store");
- }
-
- /**
- * Generates validation error exception for case when SchemaSet with same name already exists in the dataspace.
- *
- * @param dataspaceName dataspace name
- * @param schemaSetName schema set name
- */
- public static CpsException duplicateSchemaSetException(final String dataspaceName, final String schemaSetName) {
- return new CpsValidationException(SCHEMA_SET_IS_INVALID,
- String.format("Schema Set with name %s already exists for dataspace %s.", schemaSetName, dataspaceName));
- }
-
- /**
- * Generates no data found exception for case when requested dataspace is absent.
- *
- * @param dataspaceName dataspace name
- */
- public static CpsException dataspaceNotFoundException(final String dataspaceName) {
- return new CpsNotFoundException("Dataspace was not found.",
- String.format("Dataspace with name %s does not exist.", dataspaceName));
- }
-
- /**
- * Generates no data found exception for case when requested SchemaSet is absent for existing dataspace.
- *
- * @param dataspaceName dataspace name
- * @param schemaSetName schema set name
- */
- public static CpsException schemaSetNotFoundException(final String dataspaceName, final String schemaSetName) {
- return new CpsNotFoundException("Schema Set was not found.",
- String.format("Schema Set with name %s was not found for dataspace %s.", schemaSetName, dataspaceName));
- }
-
-}
diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/AnchorAlreadyDefinedException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/AnchorAlreadyDefinedException.java
new file mode 100644
index 0000000000..efdb86e970
--- /dev/null
+++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/AnchorAlreadyDefinedException.java
@@ -0,0 +1,37 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.spi.exceptions;
+
+public class AnchorAlreadyDefinedException extends CpsAdminException {
+
+ private static final long serialVersionUID = 5744381546778730691L;
+
+ /**
+ * Constructor.
+ *
+ * @param dataspaceName the name dataspace
+ * @param anchorName the name of the schema set
+ * @param cause the cause of the exception
+ */
+ public AnchorAlreadyDefinedException(final String dataspaceName, final String anchorName, final Throwable cause) {
+ super("Duplicate Anchor",
+ String.format("Anchor with name %s already exists for dataspace %s.", anchorName, dataspaceName), cause);
+ }
+}
diff --git a/cps-service/src/main/java/org/onap/cps/exceptions/CpsAdminException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsAdminException.java
index a088913375..6d6a6c31fa 100644
--- a/cps-service/src/main/java/org/onap/cps/exceptions/CpsAdminException.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsAdminException.java
@@ -17,34 +17,23 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.exceptions;
-
-import lombok.Getter;
+package org.onap.cps.spi.exceptions;
/**
* CPS Admin exception.
*/
-public class CpsAdminException extends CpsValidationException {
+public class CpsAdminException extends CpsException {
private static final long serialVersionUID = 5573438585188332404L;
/**
* Constructor.
*
- * @param cause the cause of the exception
- */
- public CpsAdminException(final Throwable cause) {
- super(cause.getMessage(), cause);
- }
-
- /**
- * Constructor.
- *
* @param message the error message
- * @param cause the cause of the exception
+ * @param details the error details
*/
- public CpsAdminException(final String message, final Throwable cause) {
- super(message, cause);
+ public CpsAdminException(final String message, final String details) {
+ super(message, details);
}
/**
@@ -52,9 +41,10 @@ public class CpsAdminException extends CpsValidationException {
*
* @param message the error message
* @param details the error details
+ * @param cause the error cause
*/
- public CpsAdminException(final String message, final String details) {
- super(message, details);
- this.details = details;
+ public CpsAdminException(final String message, final String details, final Throwable cause) {
+ super(message, details, cause);
}
+
}
diff --git a/cps-service/src/main/java/org/onap/cps/exceptions/CpsException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsException.java
index acdada14ae..406ade688b 100644
--- a/cps-service/src/main/java/org/onap/cps/exceptions/CpsException.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsException.java
@@ -17,7 +17,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.exceptions;
+package org.onap.cps.spi.exceptions;
import lombok.Getter;
@@ -26,10 +26,9 @@ import lombok.Getter;
*/
public class CpsException extends RuntimeException {
- private static final long serialVersionUID = 5573438585188332404L;
+ private static final long serialVersionUID = 1592619410918497467L;
- @Getter
- String details;
+ @Getter String details;
/**
* Constructor.
@@ -46,7 +45,7 @@ public class CpsException extends RuntimeException {
* @param message the error message
* @param cause the cause of the exception
*/
- public CpsException(final String message, final Throwable cause) {
+ public CpsException(final String message, final Throwable cause) {
super(message, cause);
}
@@ -60,4 +59,17 @@ public class CpsException extends RuntimeException {
super(message);
this.details = details;
}
+
+ /**
+ * Constructor.
+ *
+ * @param message the error message
+ * @param details the error details
+ * @param cause the cause of the exception
+ */
+ public CpsException(final String message, final String details, final Throwable cause) {
+ super(message, cause);
+ this.details = details;
+ }
+
}
diff --git a/cps-service/src/main/java/org/onap/cps/exceptions/CpsNotFoundException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataValidationException.java
index e66c3bd3b9..e6af607601 100644
--- a/cps-service/src/main/java/org/onap/cps/exceptions/CpsNotFoundException.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataValidationException.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Pantheon.tech
+ * Copyright (C) 2020 Nordix Foundation
+ * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,42 +18,20 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.exceptions;
+package org.onap.cps.spi.exceptions;
+public class DataValidationException extends CpsException {
-/**
- * CP Service exception. Indicates the requested data being absent.
- */
-public class CpsNotFoundException extends CpsException {
-
- private static final long serialVersionUID = -1852996415384288431L;
-
- /**
- * Constructor.
- *
- * @param cause the cause of the exception
- */
- public CpsNotFoundException(final Throwable cause) {
- super(cause.getMessage(), cause);
- }
-
- /**
- * Constructor.
- *
- * @param message the error message
- * @param cause the cause of the exception
- */
- public CpsNotFoundException(final String message, final Throwable cause) {
- super(message, cause);
- }
+ private static final long serialVersionUID = 7747941311132087621L;
/**
* Constructor.
*
* @param message the error message
* @param details the error details
+ * @param cause the error cause
*/
- public CpsNotFoundException(final String message, final String details) {
- super(message, details);
+ public DataValidationException(final String message, final String details, final Throwable cause) {
+ super(message, details, cause);
}
}
diff --git a/cps-service/src/main/java/org/onap/cps/exceptions/DataspaceNotFoundException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataspaceNotFoundException.java
index 1b09cdd1eb..58fcde3d14 100644
--- a/cps-service/src/main/java/org/onap/cps/exceptions/DataspaceNotFoundException.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataspaceNotFoundException.java
@@ -17,7 +17,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.exceptions;
+package org.onap.cps.spi.exceptions;
/**
@@ -30,28 +30,10 @@ public class DataspaceNotFoundException extends CpsAdminException {
/**
* Constructor.
*
- * @param cause the cause of the exception
+ * @param dataspaceName the name of the dataspace
*/
- public DataspaceNotFoundException(final Throwable cause) {
- super(cause.getMessage(), cause);
- }
- /**
- * Constructor.
- *
- * @param message the error message
- * @param cause the cause of the exception
- */
- public DataspaceNotFoundException(final String message, final Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Constructor.
- *
- * @param details the error details
- */
- public DataspaceNotFoundException(final String details) {
- super("Dataspace Not Found", details);
+ public DataspaceNotFoundException(final String dataspaceName) {
+ super("Dataspace not found", String.format("Dataspace with name %s does not exist.", dataspaceName));
}
}
diff --git a/cps-service/src/main/java/org/onap/cps/exceptions/CpsValidationException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/ModelValidationException.java
index 8e049c66e4..04a8836aca 100644
--- a/cps-service/src/main/java/org/onap/cps/exceptions/CpsValidationException.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/ModelValidationException.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Pantheon.tech
+ * Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,39 +17,23 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.exceptions;
+package org.onap.cps.spi.exceptions;
/**
- * CP Service exception. Indicates the parameter validation failure.
+ * Yang Model Validation exception.
*/
-public class CpsValidationException extends CpsException {
+public class ModelValidationException extends CpsException {
- /**
- * Constructor.
- *
- * @param cause the cause of the exception
- */
- public CpsValidationException(final Throwable cause) {
- super(cause.getMessage(), cause);
- }
-
- /**
- * Constructor.
- *
- * @param message the error message
- * @param cause the cause of the exception
- */
- public CpsValidationException(final String message, final Throwable cause) {
- super(message, cause);
- }
+ private static final long serialVersionUID = 650368325928748496L;
/**
* Constructor.
*
* @param message the error message
* @param details the error details
+ * @param cause the cause of the exception
*/
- public CpsValidationException(final String message, final String details) {
- super(message, details);
+ public ModelValidationException(final String message, final String details, final Throwable cause) {
+ super(message, details, cause);
}
}
diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/NotFoundInDataspaceException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/NotFoundInDataspaceException.java
new file mode 100644
index 0000000000..66cce1bfce
--- /dev/null
+++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/NotFoundInDataspaceException.java
@@ -0,0 +1,34 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Pantheon.tech
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.spi.exceptions;
+
+
+/**
+ * CP Service exception. Indicates the requested data being absent in a given dataspace
+ */
+public class NotFoundInDataspaceException extends CpsException {
+
+ private static final long serialVersionUID = 3838769447129047713L;
+
+ public NotFoundInDataspaceException(final String dataspaceName, final String descriptionOfObject) {
+ super("Object not found",
+ String.format("%s does not exist in dataspace %s.", descriptionOfObject, dataspaceName));
+ }
+}
diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetAlreadyDefinedException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetAlreadyDefinedException.java
new file mode 100644
index 0000000000..b3766726f0
--- /dev/null
+++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetAlreadyDefinedException.java
@@ -0,0 +1,39 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.spi.exceptions;
+
+public class SchemaSetAlreadyDefinedException extends CpsAdminException {
+
+ private static final long serialVersionUID = 501929839139881112L;
+
+ /**
+ * Constructor.
+ *
+ * @param dataspaceName the name dataspace
+ * @param schemaSetName the name of the schema set
+ * @param cause the cause of the exception
+ */
+ public SchemaSetAlreadyDefinedException(final String dataspaceName, final String schemaSetName,
+ final Throwable cause) {
+ super("Duplicate Schema Set",
+ String.format("Schema Set with name %s already exists for dataspace %s.", schemaSetName, dataspaceName),
+ cause);
+ }
+}
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminPersistenceServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminPersistenceServiceImplSpec.groovy
deleted file mode 100644
index 465badd0c2..0000000000
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminPersistenceServiceImplSpec.groovy
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation
- * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.cps.api.impl
-
-import org.onap.cps.exceptions.CpsValidationException
-import org.onap.cps.spi.CpsAdminPersistenceService
-import org.onap.cps.spi.model.Anchor
-import spock.lang.Specification
-
-class CpsAdminPersistenceServiceImplSpec extends Specification {
- def mockCpsAdminService = Mock(CpsAdminPersistenceService)
- def objectUnderTest = new CpsAdminServiceImpl()
-
- def setup() {
- objectUnderTest.cpsAdminPersistenceService = mockCpsAdminService
- }
-
- def 'Create an anchor with a non-existant dataspace'() {
- given: 'that the dataspace does not exist service throws an exception'
- Anchor anchor = new Anchor()
- anchor.setDataspaceName('dummyDataspace')
- mockCpsAdminService.createAnchor(anchor) >> { throw new CpsValidationException(_ as String, _ as String) }
- when: 'we try to create a anchor with a non-existant dataspace'
- objectUnderTest.createAnchor(anchor)
- then: 'the same exception is thrown by CPS'
- thrown(CpsValidationException)
- }
-
- def 'Create an anchor with invalid dataspace, namespace and revision'() {
- given: 'that the dataspace, namespace and revison combination does not exist service throws an exception'
- Anchor anchor = new Anchor()
- anchor.setDataspaceName('dummyDataspace')
- anchor.setNamespace('dummyNamespace')
- anchor.setRevision('dummyRevision')
- mockCpsAdminService.createAnchor(anchor) >> { throw new CpsValidationException(_ as String, _ as String) }
- when: 'we try to create a anchor with a non-existant dataspace, namespace and revison combination'
- objectUnderTest.createAnchor(anchor)
- then: 'the same exception is thrown by CPS'
- thrown(CpsValidationException)
- }
-
- def 'Create a duplicate anchor'() {
- given: 'that the anchor already exist service throws an exception'
- Anchor anchor = new Anchor()
- anchor.setDataspaceName('dummyDataspace')
- anchor.setNamespace('dummyNamespace')
- anchor.setRevision('dummyRevision')
- anchor.setRevision('dummyAnchorName')
- mockCpsAdminService.createAnchor(anchor) >> { throw new CpsValidationException(_ as String, _ as String) }
- when: 'we try to create a duplicate anchor'
- objectUnderTest.createAnchor(anchor)
- then: 'the same exception is thrown by CPS'
- thrown(CpsValidationException)
- }
-
- def 'Create an anchor with supplied anchor name, dataspace, namespace and revision'() {
- given: 'that the anchor does not pre-exist service creates an anchor'
- Anchor anchor = new Anchor()
- anchor.setDataspaceName('dummyDataspace')
- anchor.setNamespace('dummyNamespace')
- anchor.setRevision('dummyRevision')
- anchor.setRevision('dummyAnchorName')
- mockCpsAdminService.createAnchor(anchor) >> 'dummyAnchorName'
- expect: 'anchor name is returned by service'
- objectUnderTest.createAnchor(anchor) == 'dummyAnchorName'
- }
-
-}
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy
new file mode 100644
index 0000000000..65a8e71bca
--- /dev/null
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy
@@ -0,0 +1,55 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.api.impl
+
+
+import org.onap.cps.spi.CpsAdminPersistenceService
+import org.onap.cps.spi.model.Anchor
+import spock.lang.Specification
+
+class CpsAdminServiceImplSpec extends Specification {
+ def mockCpsAdminPersistenceService = Mock(CpsAdminPersistenceService)
+ def objectUnderTest = new CpsAdminServiceImpl()
+ def anchor = new Anchor()
+
+ def setup() {
+ objectUnderTest.cpsAdminPersistenceService = mockCpsAdminPersistenceService
+ }
+
+ def 'Create an anchor'() {
+ given: 'that the persistence service returns the name of the anchor'
+ def anchorName = 'some anchor name'
+ mockCpsAdminPersistenceService.createAnchor(_) >> anchorName
+ expect: 'the same anchor name is returned by CPS Admin service'
+ objectUnderTest.createAnchor(anchor) == anchorName
+ }
+
+ def 'Create an anchor with some exception in the persistence layer'() {
+ given: 'that the persistence service throws some exception'
+ def exceptionThrownInPersistenceLayer = new RuntimeException()
+ mockCpsAdminPersistenceService.createAnchor(_) >> { throw exceptionThrownInPersistenceLayer }
+ when: 'we try to create an anchor'
+ objectUnderTest.createAnchor(anchor)
+ then: 'the same exception is thrown by the CPS Admin Service'
+ def exceptionThrownInServiceLayer = thrown(Exception)
+ exceptionThrownInServiceLayer == exceptionThrownInPersistenceLayer
+ }
+}
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModulePersistenceServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModulePersistenceServiceImplSpec.groovy
index 79b981b2a2..da2df404eb 100644
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModulePersistenceServiceImplSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModulePersistenceServiceImplSpec.groovy
@@ -21,8 +21,8 @@
package org.onap.cps.api.impl
import org.onap.cps.TestUtils
-import org.onap.cps.exceptions.CpsValidationException
import org.onap.cps.spi.CpsModulePersistenceService
+import org.onap.cps.spi.exceptions.CpsException
import org.opendaylight.yangtools.yang.common.Revision
import org.opendaylight.yangtools.yang.model.api.SchemaContext
import spock.lang.Specification
@@ -65,7 +65,7 @@ class CpsModulePersistenceServiceImplSpec extends Specification {
when: 'the model is parsed and validated'
objectUnderTest.parseAndValidateModel(file)
then: 'a CpsValidationException is thrown'
- thrown(CpsValidationException)
+ thrown(CpsException)
}
def 'Store a SchemaContext'() {