Improve CPS Exception handling 30/116230/5
authorToineSiebelink <toine.siebelink@est.tech>
Tue, 8 Dec 2020 12:08:31 +0000 (12:08 +0000)
committerToineSiebelink <toine.siebelink@est.tech>
Thu, 10 Dec 2020 10:11:53 +0000 (10:11 +0000)
- Removing unnecessary level of CPS(Validation)Exception
- Moved exception inside spi package
- Rename exceptions are per agreed new exception hierarchy
- Use new exceptions
- Added SchemaSetAlreadDefined Exception
- Added AnchorAlreadyDefined Exception
- Ensure unique serialVersionUIDs
- Fixed CpsAdmin(Persistence)ServiceImplSpec tests (there was a mix-up about what this class was testing)
- Replaced exception builder with dedicated exception (constructors)

Issue-ID: CPS-8

Change-Id: I9cb80af4951e69ee7b0e99303853955de9d4399f
Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
22 files changed:
cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestController.java
cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java
cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy
cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java
cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
cps-ri/src/main/java/org/onap/cps/spi/repository/DataspaceRepository.java
cps-ri/src/main/java/org/onap/cps/spi/repository/ModuleRepository.java
cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java
cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java
cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java
cps-service/src/main/java/org/onap/cps/exceptions/CpsExceptionBuilder.java [deleted file]
cps-service/src/main/java/org/onap/cps/spi/exceptions/AnchorAlreadyDefinedException.java [new file with mode: 0644]
cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsAdminException.java [moved from cps-service/src/main/java/org/onap/cps/exceptions/CpsAdminException.java with 73% similarity]
cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsException.java [moved from cps-service/src/main/java/org/onap/cps/exceptions/CpsException.java with 75% similarity]
cps-service/src/main/java/org/onap/cps/spi/exceptions/DataValidationException.java [moved from cps-service/src/main/java/org/onap/cps/exceptions/CpsNotFoundException.java with 54% similarity]
cps-service/src/main/java/org/onap/cps/spi/exceptions/DataspaceNotFoundException.java [moved from cps-service/src/main/java/org/onap/cps/exceptions/DataspaceNotFoundException.java with 65% similarity]
cps-service/src/main/java/org/onap/cps/spi/exceptions/ModelValidationException.java [moved from cps-service/src/main/java/org/onap/cps/exceptions/CpsValidationException.java with 59% similarity]
cps-service/src/main/java/org/onap/cps/spi/exceptions/NotFoundInDataspaceException.java [new file with mode: 0644]
cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetAlreadyDefinedException.java [new file with mode: 0644]
cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminPersistenceServiceImplSpec.groovy [deleted file]
cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy [new file with mode: 0644]
cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModulePersistenceServiceImplSpec.groovy

index 0821dca..30d3e24 100755 (executable)
@@ -31,9 +31,9 @@ import org.modelmapper.ModelMapper;
 import org.onap.cps.api.CpService;
 import org.onap.cps.api.CpsAdminService;
 import org.onap.cps.api.CpsModuleService;
-import org.onap.cps.exceptions.CpsException;
-import org.onap.cps.exceptions.CpsValidationException;
 import org.onap.cps.rest.api.CpsRestApi;
+import org.onap.cps.spi.exceptions.CpsException;
+import org.onap.cps.spi.exceptions.DataValidationException;
 import org.onap.cps.spi.model.Anchor;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -75,7 +75,7 @@ public class CpsRestController implements CpsRestApi {
         final Anchor anchorDetails = modelMapper.map(anchor, Anchor.class);
         anchorDetails.setDataspaceName(dataspaceName);
         final String anchorName = cpsAdminService.createAnchor(anchorDetails);
-        return new ResponseEntity<String>(anchorName, HttpStatus.CREATED);
+        return new ResponseEntity<>(anchorName, HttpStatus.CREATED);
     }
 
     @Override
@@ -154,7 +154,7 @@ public class CpsRestController implements CpsRestApi {
     @GetMapping("/json-object/{id}")
     public final ResponseEntity<String> getJsonObjectById(
         @PathVariable("id") final int jsonObjectId) {
-        return new ResponseEntity<String>(cpService.getJsonById(jsonObjectId), HttpStatus.OK);
+        return new ResponseEntity<>(cpService.getJsonById(jsonObjectId), HttpStatus.OK);
     }
 
     /**
@@ -175,7 +175,7 @@ public class CpsRestController implements CpsRestApi {
             final Gson gson = new Gson();
             gson.fromJson(getJsonString(multipartFile), Object.class);
         } catch (final JsonSyntaxException e) {
-            throw new CpsValidationException("Not a valid JSON file.", e);
+            throw new DataValidationException("Not a valid JSON file.", e.getMessage(), e);
         }
     }
 
@@ -183,7 +183,7 @@ public class CpsRestController implements CpsRestApi {
         try {
             final File file = File.createTempFile("tempFile", ".yang");
             file.deleteOnExit();
-            try (OutputStream outputStream = new FileOutputStream(file)) {
+            try (final OutputStream outputStream = new FileOutputStream(file)) {
                 outputStream.write(multipartFile.getBytes());
             }
             return file;
@@ -200,4 +200,4 @@ public class CpsRestController implements CpsRestApi {
             throw new CpsException(e);
         }
     }
-}
\ No newline at end of file
+}
index 94226b7..fc0164f 100644 (file)
 package org.onap.cps.rest.exceptions;
 
 import org.apache.commons.lang3.exception.ExceptionUtils;
-import org.onap.cps.exceptions.CpsException;
-import org.onap.cps.exceptions.CpsNotFoundException;
-import org.onap.cps.exceptions.CpsValidationException;
 import org.onap.cps.rest.controller.CpsRestController;
 import org.onap.cps.rest.model.ErrorMessage;
+import org.onap.cps.spi.exceptions.AnchorAlreadyDefinedException;
+import org.onap.cps.spi.exceptions.CpsException;
+import org.onap.cps.spi.exceptions.DataValidationException;
+import org.onap.cps.spi.exceptions.ModelValidationException;
+import org.onap.cps.spi.exceptions.NotFoundInDataspaceException;
+import org.onap.cps.spi.exceptions.SchemaSetAlreadyDefinedException;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.ExceptionHandler;
@@ -39,32 +42,33 @@ public class CpsRestExceptionHandler {
      * @param exception the exception to handle
      * @return response with response code 500.
      */
-    @ExceptionHandler
-    public ResponseEntity<Object> handleInternalErrorException(final Exception exception) {
+    @ExceptionHandler public static ResponseEntity<Object> handleInternalServerErrorExceptions(
+        final Exception exception) {
         return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception);
     }
 
-    @ExceptionHandler({CpsException.class})
-    public ResponseEntity<Object> handleCpsException(final CpsException exception) {
-        return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception.getMessage(), extractDetails(exception));
-    }
-
-    @ExceptionHandler({CpsValidationException.class})
-    public ResponseEntity<Object> handleCpsValidationException(final CpsException exception) {
+    @ExceptionHandler({ModelValidationException.class, DataValidationException.class,
+        SchemaSetAlreadyDefinedException.class, AnchorAlreadyDefinedException.class})
+    public static ResponseEntity<Object> handleBadRequestExceptions(final CpsException exception) {
         return buildErrorResponse(HttpStatus.BAD_REQUEST, exception.getMessage(), extractDetails(exception));
     }
 
-    @ExceptionHandler({CpsNotFoundException.class})
-    public ResponseEntity<Object> handleCpsNotFoundException(final CpsException exception) {
+    @ExceptionHandler({NotFoundInDataspaceException.class})
+    public static ResponseEntity<Object> handleNotFoundExceptions(final CpsException exception) {
         return buildErrorResponse(HttpStatus.NOT_FOUND, exception.getMessage(), extractDetails(exception));
     }
 
+    @ExceptionHandler({CpsException.class})
+    public static ResponseEntity<Object> handleAnyOtherCpsExceptions(final CpsException exception) {
+        return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception.getMessage(), extractDetails(exception));
+    }
+
     private static ResponseEntity<Object> buildErrorResponse(final HttpStatus status, final Exception exception) {
         return buildErrorResponse(status, exception.getMessage(), ExceptionUtils.getStackTrace(exception));
     }
 
     private static ResponseEntity<Object> buildErrorResponse(final HttpStatus status, final String message,
-            final String details) {
+        final String details) {
         final ErrorMessage errorMessage = new ErrorMessage();
         errorMessage.setStatus(status.toString());
         errorMessage.setMessage(message);
index dd1b956..d951cbe 100644 (file)
@@ -21,11 +21,16 @@ package org.onap.cps.rest.exceptions
 
 import groovy.json.JsonSlurper
 import org.onap.cps.api.CpService
-import org.onap.cps.exceptions.CpsException
-import org.onap.cps.exceptions.CpsNotFoundException
-import org.onap.cps.exceptions.CpsValidationException
+import org.onap.cps.spi.exceptions.AnchorAlreadyDefinedException
+import org.onap.cps.spi.exceptions.CpsException
+import org.onap.cps.spi.exceptions.DataValidationException
+import org.onap.cps.spi.exceptions.NotFoundInDataspaceException
+import org.onap.cps.spi.exceptions.ModelValidationException
 import org.onap.cps.rest.controller.CpsRestController
+import org.onap.cps.spi.exceptions.SchemaSetAlreadyDefinedException
+import spock.lang.Shared
 import spock.lang.Specification
+import spock.lang.Unroll
 
 import static org.springframework.http.HttpStatus.BAD_REQUEST
 import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR
@@ -35,9 +40,18 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standal
 
 class CpsRestExceptionHandlerSpec extends Specification {
 
-    def cpsRestController = new CpsRestController();
+    @Shared
+    def errorMessage = 'some error message'
+    @Shared
+    def errorDetails = 'some error details'
+    @Shared
+    def dataspaceName = 'MyDataSpace'
+    @Shared
+    def existingObjectName = 'MyAdminObject'
+
+    def cpsRestController = new CpsRestController()
     def mockCpService = Mock(CpService.class)
-    def objectUnderTest = new CpsRestExceptionHandler();
+    def objectUnderTest = new CpsRestExceptionHandler()
     def mockMvc = standaloneSetup(cpsRestController).setControllerAdvice(objectUnderTest).build()
 
     def setup() {
@@ -47,48 +61,67 @@ class CpsRestExceptionHandlerSpec extends Specification {
     def 'Get request with runtime exception returns HTTP Status Internal Server Error'() {
 
         when: 'runtime exception is thrown by the service'
-            def errorMessage = 'runtime error message'
             setupTestException(new IllegalStateException(errorMessage))
             def response = performTestRequest()
 
-        then: 'an HTTP Internal Server Error response is returned with the correct message'
+        then: 'an HTTP Internal Server Error response is returned with correct message and details'
             assertTestResponse(response, INTERNAL_SERVER_ERROR, errorMessage, null)
     }
 
     def 'Get request with generic CPS exception returns HTTP Status Internal Server Error'() {
 
         when: 'generic CPS exception is thrown by the service'
-            def errorMessage = 'cps generic error message'
-            def errorDetails = 'cps generic error details'
             setupTestException(new CpsException(errorMessage, errorDetails))
             def response = performTestRequest()
 
-        then: 'an HTTP Internal Server Error response is returned with the correct message'
+        then: 'an HTTP Internal Server Error response is returned with correct message and details'
             assertTestResponse(response, INTERNAL_SERVER_ERROR, errorMessage, errorDetails)
     }
 
     def 'Get request with no data found CPS exception returns HTTP Status Not Found'() {
 
         when: 'no data found CPS exception is thrown by the service'
-            def errorMessage = 'cps no data error message'
-            def errorDetails = 'cps no data error details'
-            setupTestException(new CpsNotFoundException(errorMessage, errorDetails))
+            def dataspaceName = 'MyDataSpace'
+            def descriptionOfObject = 'Description'
+            setupTestException(new NotFoundInDataspaceException(dataspaceName, descriptionOfObject))
             def response = performTestRequest()
 
-        then: 'an HTTP Not Found response is returned with the correct message'
-            assertTestResponse(response, NOT_FOUND, errorMessage, errorDetails)
+        then: 'an HTTP Not Found response is returned with correct message and details'
+            assertTestResponse(response, NOT_FOUND, 'Object not found',
+                    'Description does not exist in dataspace MyDataSpace.')
     }
 
-    def 'Get request with CPS validation exception returns HTTP Status Bad Request'() {
+    @Unroll
+    def 'request with an expectedObjectTypeInMessage object already defined exception returns HTTP Status Bad Request'() {
+
+        when: 'no data found CPS exception is thrown by the service'
+            setupTestException(exceptionThrown)
+            def response = performTestRequest()
+
+        then: 'an HTTP Bad Request response is returned with correct message an details'
+            assertTestResponse(response, BAD_REQUEST,
+                    "Duplicate ${expectedObjectTypeInMessage}",
+                    "${expectedObjectTypeInMessage} with name ${existingObjectName} " +
+                            'already exists for dataspace MyDataSpace.')
+        where: 'the following exceptions are thrown'
+            exceptionThrown                                                               || expectedObjectTypeInMessage
+            new SchemaSetAlreadyDefinedException(dataspaceName, existingObjectName, null) || 'Schema Set'
+            new AnchorAlreadyDefinedException(dataspaceName, existingObjectName, null)    || 'Anchor'
+    }
+
+    @Unroll
+    def 'Get request with a #exceptionThrown.class.simpleName returns HTTP Status Bad Request'() {
 
         when: 'CPS validation exception is thrown by the service'
-            def errorMessage = 'cps validation error message'
-            def errorDetails = 'cps validation error details'
-            setupTestException(new CpsValidationException(errorMessage, errorDetails))
+            setupTestException(exceptionThrown)
             def response = performTestRequest()
 
-        then: 'an HTTP Bad Request response is returned with the correct message'
+        then: 'an HTTP Bad Request response is returned with correct message and details'
             assertTestResponse(response, BAD_REQUEST, errorMessage, errorDetails)
+
+        where: 'the following exceptions are thrown'
+            exceptionThrown << [new ModelValidationException(errorMessage, errorDetails, null),
+                                new DataValidationException(errorMessage, errorDetails, null)]
     }
 
     /*
@@ -111,5 +144,5 @@ class CpsRestExceptionHandlerSpec extends Specification {
         assert content['message'] == expectedErrorMessage
         assert expectedErrorDetails == null || content['details'] == expectedErrorDetails
     }
-    
+
 }
index 684750c..f119507 100644 (file)
 
 package org.onap.cps.spi.impl;
 
-import org.onap.cps.exceptions.CpsNotFoundException;
-import org.onap.cps.exceptions.CpsValidationException;
 import org.onap.cps.spi.CpsAdminPersistenceService;
 import org.onap.cps.spi.entities.Dataspace;
 import org.onap.cps.spi.entities.Fragment;
 import org.onap.cps.spi.entities.Module;
+import org.onap.cps.spi.exceptions.AnchorAlreadyDefinedException;
 import org.onap.cps.spi.model.Anchor;
 import org.onap.cps.spi.repository.DataspaceRepository;
 import org.onap.cps.spi.repository.FragmentRepository;
@@ -51,23 +50,15 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
         final String anchorName = anchor.getAnchorName();
         try {
             final Dataspace dataspace = dataspaceRepository.getByName(anchor.getDataspaceName());
-            final Module module =
-                moduleRepository.getByDataspaceAndNamespaceAndRevision(dataspace,
-                    anchor.getNamespace(), anchor.getRevision());
-
-            final Fragment fragment = Fragment.builder().xpath(anchorName)
-                .anchorName(anchorName)
-                .dataspace(dataspace).module(module).build();
+            final Module module = moduleRepository
+                .getByDataspaceAndNamespaceAndRevision(dataspace, anchor.getNamespace(), anchor.getRevision());
+            final Fragment fragment =
+                Fragment.builder().xpath(anchorName).anchorName(anchorName).dataspace(dataspace).module(module).build();
 
             fragmentRepository.save(fragment);
             return anchorName;
-        } catch (final CpsNotFoundException ex) {
-            throw new CpsValidationException("Validation Error",
-                "Dataspace and/or Module do not exist.");
         } catch (final DataIntegrityViolationException ex) {
-            throw new CpsValidationException("Duplication Error",
-                String.format("Anchor with name %s already exist in dataspace %s.",
-                    anchorName, anchor.getDataspaceName()));
+            throw new AnchorAlreadyDefinedException(anchor.getDataspaceName(), anchorName, ex);
         }
     }
 }
index 52f8034..e63ae59 100644 (file)
@@ -20,9 +20,6 @@
 
 package org.onap.cps.spi.impl;
 
-import static org.onap.cps.exceptions.CpsExceptionBuilder.duplicateSchemaSetException;
-import static org.onap.cps.exceptions.CpsExceptionBuilder.invalidDataspaceException;
-
 import com.google.common.collect.ImmutableSet;
 import java.util.List;
 import java.util.Map;
@@ -33,6 +30,7 @@ import org.onap.cps.spi.CpsModulePersistenceService;
 import org.onap.cps.spi.entities.Dataspace;
 import org.onap.cps.spi.entities.SchemaSet;
 import org.onap.cps.spi.entities.YangResource;
+import org.onap.cps.spi.exceptions.SchemaSetAlreadyDefinedException;
 import org.onap.cps.spi.repository.DataspaceRepository;
 import org.onap.cps.spi.repository.SchemaSetRepository;
 import org.onap.cps.spi.repository.YangResourceRepository;
@@ -65,9 +63,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
     public void storeSchemaSet(final String dataspaceName, final String schemaSetName,
                                final Set<String> yangResourcesAsStrings) {
 
-        final Dataspace dataspace = dataspaceRepository.findByName(dataspaceName)
-            .orElseThrow(() -> invalidDataspaceException(dataspaceName));
-
+        final Dataspace dataspace = dataspaceRepository.getByName(dataspaceName);
         final Set<YangResource> yangResources = synchronizeYangResources(yangResourcesAsStrings);
         final SchemaSet schemaSet = new SchemaSet();
         schemaSet.setName(schemaSetName);
@@ -76,7 +72,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
         try {
             schemaSetRepository.save(schemaSet);
         } catch (final DataIntegrityViolationException e) {
-            throw duplicateSchemaSetException(dataspaceName, schemaSetName);
+            throw new SchemaSetAlreadyDefinedException(dataspaceName, schemaSetName, e);
         }
     }
 
index 4b64916..ce231c9 100755 (executable)
@@ -21,8 +21,8 @@ package org.onap.cps.spi.repository;
 
 import java.util.Optional;
 import javax.validation.constraints.NotNull;
-import org.onap.cps.exceptions.DataspaceNotFoundException;
 import org.onap.cps.spi.entities.Dataspace;
+import org.onap.cps.spi.exceptions.DataspaceNotFoundException;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.stereotype.Repository;
 
@@ -32,8 +32,14 @@ public interface DataspaceRepository extends JpaRepository<Dataspace, Integer> {
 
     Optional<Dataspace> findByName(@NotNull String name);
 
-    default Dataspace getByName(@NotNull String name) {
-        return findByName(name).orElseThrow(
-            () -> new DataspaceNotFoundException("Dataspace " + name + " does not exist."));
+    /**
+     * Get a dataspace by name.
+     * throws a DataspaceNotFoundException if it does not exist
+     *
+     * @param name the name of the dataspace
+     * @return the Dataspace found
+     */
+    default Dataspace getByName(@NotNull final String name) {
+        return findByName(name).orElseThrow(() -> new DataspaceNotFoundException(name));
     }
-}
\ No newline at end of file
+}
index d3a8bc1..cab7e19 100755 (executable)
@@ -22,9 +22,9 @@ package org.onap.cps.spi.repository;
 
 import java.util.Optional;
 import javax.validation.constraints.NotNull;
-import org.onap.cps.exceptions.CpsNotFoundException;
 import org.onap.cps.spi.entities.Dataspace;
 import org.onap.cps.spi.entities.Module;
+import org.onap.cps.spi.exceptions.NotFoundInDataspaceException;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.stereotype.Repository;
 
@@ -32,24 +32,24 @@ import org.springframework.stereotype.Repository;
 public interface ModuleRepository extends JpaRepository<Module, Integer> {
 
     Optional<Module> findByDataspaceAndNamespaceAndRevision(@NotNull Dataspace dataspace,
-        @NotNull String namespace,
-        @NotNull String revision);
+            @NotNull String namespace,
+            @NotNull String revision);
 
     /**
      * This method gets a Module by dataspace, namespace and revision.
      *
      * @param dataspace the dataspace
      * @param namespace the namespace
-     * @param revision the revision
+     * @param revision  the revision
      * @return the Module
-     * @throws CpsNotFoundException if Module not found
+     * @throws NotFoundInDataspaceException if Module not found
      */
-    default Module getByDataspaceAndNamespaceAndRevision(@NotNull Dataspace dataspace, @NotNull String namespace,
-        @NotNull String revision) {
-        return findByDataspaceAndNamespaceAndRevision(dataspace, namespace,
-            revision)
-            .orElseThrow(() -> new CpsNotFoundException("Validation Error", String.format(
-                "Module with dataspace %s, revision %s does not exist in namespace %s.",
-                dataspace.getName(), revision, namespace)));
+    default Module getByDataspaceAndNamespaceAndRevision(@NotNull final Dataspace dataspace,
+            @NotNull final String namespace,
+            @NotNull final String revision) {
+        return findByDataspaceAndNamespaceAndRevision(dataspace, namespace, revision)
+                .orElseThrow(() -> new NotFoundInDataspaceException("Validation Error", String.format(
+                        "Module with dataspace %s, revision %s does not exist in namespace %s.",
+                        dataspace.getName(), revision, namespace)));
     }
-}
\ No newline at end of file
+}
index 406655e..98ea8eb 100644 (file)
@@ -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);
 }
index 02553d0..94ebea2 100644 (file)
@@ -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);
 }
index 87ffdd3..c7fa047 100644 (file)
@@ -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 (file)
index 2acbb92..0000000
+++ /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 (file)
index 0000000..efdb86e
--- /dev/null
@@ -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);
+    }
+}
  *  ============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);
     }
+
 }
@@ -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;
+    }
+
 }
@@ -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.
  *  ============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);
     }
 }
@@ -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));
     }
 }
@@ -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.
  *  ============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 (file)
index 0000000..66cce1b
--- /dev/null
@@ -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 (file)
index 0000000..b376672
--- /dev/null
@@ -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 (file)
index 465badd..0000000
+++ /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 (file)
index 0000000..65a8e71
--- /dev/null
@@ -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
+    }
+}
index 79b981b..da2df40 100644 (file)
@@ -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'() {