diff options
author | ToineSiebelink <toine.siebelink@est.tech> | 2021-01-14 11:29:40 +0000 |
---|---|---|
committer | ToineSiebelink <toine.siebelink@est.tech> | 2021-01-14 14:22:06 +0000 |
commit | b7359210ff315cf9b1daf251da452fb48217b051 (patch) | |
tree | 58938ab100c5c209e4deaa0f4257516d9c5b8bd0 /cps-service | |
parent | d45b2dc0ec3bb7d56ef1eee784a887459f609832 (diff) |
SonarQube fixes
- Ignore SonarQube violations related to inheritance depth for exception classes
- Increase coverage service module
Issue-ID: CPS-89
Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
Change-Id: I7998dee0f9abea0638639e0587b08febad6075f5
Diffstat (limited to 'cps-service')
7 files changed, 127 insertions, 5 deletions
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 index efdb86e970..2a4abad319 100644 --- 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 @@ -19,6 +19,11 @@ package org.onap.cps.spi.exceptions; +/** + * Anchor already defined exception. Indicates the an anchor with same name already exists in the same dataspace + */ + +@SuppressWarnings("squid:S110") // Team agreed to accept 6 levels of inheritance for CPS Exceptions public class AnchorAlreadyDefinedException extends CpsAdminException { private static final long serialVersionUID = 5744381546778730691L; diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataspaceAlreadyDefinedException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataspaceAlreadyDefinedException.java index d6d933c66e..fcc085aa08 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataspaceAlreadyDefinedException.java +++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataspaceAlreadyDefinedException.java @@ -22,6 +22,8 @@ package org.onap.cps.spi.exceptions; /** * Dataspace already defined exception. Indicates the dataspace with same name already exists. */ + +@SuppressWarnings("squid:S110") // Team agreed to accept 6 levels of inheritance for CPS Exceptions public class DataspaceAlreadyDefinedException extends CpsAdminException { private static final long serialVersionUID = -5813793951842079228L; diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataspaceNotFoundException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataspaceNotFoundException.java index 58fcde3d14..42b77a23be 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataspaceNotFoundException.java +++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataspaceNotFoundException.java @@ -19,10 +19,11 @@ package org.onap.cps.spi.exceptions; - /** * Dataspace Not Found Exception. Indicates the requested data being absent. */ + +@SuppressWarnings("squid:S110") // Team agreed to accept 6 levels of inheritance for CPS Exceptions public class DataspaceNotFoundException extends CpsAdminException { private static final long serialVersionUID = -1852996415384288431L; 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 index 66cce1bfce..56a2f87433 100644 --- 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 @@ -19,12 +19,11 @@ package org.onap.cps.spi.exceptions; - /** - * CP Service exception. Indicates the requested data being absent in a given dataspace + * Not found in dataspace 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) { 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 index b3766726f0..9376d6893d 100644 --- 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 @@ -19,6 +19,9 @@ package org.onap.cps.spi.exceptions; +/** + * Schema set already defined exception. Indicates the a schema set with same name already exists in the same dataspace + */ public class SchemaSetAlreadyDefinedException extends CpsAdminException { private static final long serialVersionUID = 501929839139881112L; diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetNotFoundException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetNotFoundException.java index f92ca37298..cf63f924fd 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetNotFoundException.java +++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetNotFoundException.java @@ -19,6 +19,11 @@ package org.onap.cps.spi.exceptions; +/** + * Schema set not found exception. Indicates the schema set is not found in a given dataspace + */ + +@SuppressWarnings("squid:S110") // Team agreed to accept 6 levels of inheritance for CPS Exceptions public class SchemaSetNotFoundException extends CpsAdminException { private static final long serialVersionUID = 7422782395935450035L; @@ -33,4 +38,4 @@ public class SchemaSetNotFoundException extends CpsAdminException { super("Schema Set not found.", String.format("Schema Set with name %s was not found for dataspace %s.", schemaSetName, dataspaceName)); } -}
\ No newline at end of file +} diff --git a/cps-service/src/test/groovy/org/onap/cps/spi/exceptions/CpsExceptionsSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/spi/exceptions/CpsExceptionsSpec.groovy new file mode 100644 index 0000000000..5c6a16dfff --- /dev/null +++ b/cps-service/src/test/groovy/org/onap/cps/spi/exceptions/CpsExceptionsSpec.groovy @@ -0,0 +1,107 @@ +/* + * ============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 + +import spock.lang.Specification + +class CpsExceptionsSpec extends Specification { + def dataspaceName = 'some data space' + def anchorName = 'some anchor' + def schemaSetName = 'some schema set' + def rootCause = new Throwable() + def providedMessage = 'some message' + def providedDetails = 'some details' + + def 'Creating an exception that the Anchor already exist.'() { + given: 'an exception dat the Anchor already exist is created' + def exception = new AnchorAlreadyDefinedException(dataspaceName, anchorName, rootCause) + expect: 'the exception details contains the correct message with Anchor name and Dataspace name' + exception.details == "Anchor with name ${anchorName} already exists for dataspace ${dataspaceName}." + and: 'the correct root cause is maintained' + exception.cause == rootCause + } + + def 'Creating an exception that the dataspace already exists.'() { + given: 'an exception that the dataspace already exists is created' + def exception = new DataspaceAlreadyDefinedException(dataspaceName, rootCause) + expect: 'the exception details contains the correct message with dataspace name' + exception.details == "Dataspace with name ${dataspaceName} already exists." + and: 'the correct root cause is maintained' + exception.cause == rootCause + } + + def 'Creating a exception that a dataspace is not found.'() { + expect: 'the exception details contains the correct message with dataspace name' + (new DataspaceNotFoundException(dataspaceName)).details + == "Dataspace with name ${dataspaceName} does not exist." + } + + def'Creating a data validation exception.'() { + given: 'a data validation exception is created' + def exception = new DataValidationException(providedMessage, providedDetails, rootCause) + expect: 'the exception has the provided message' + exception.message == providedMessage + and: 'the exception has the provided details' + exception.details == providedDetails + and: 'the correct root cause is maintained' + exception.cause == rootCause + } + + def'Creating a model validation exception.'() { + given: 'a data validation exception is created' + def exception = new ModelValidationException(providedMessage, providedDetails) + expect: 'the exception has the provided message' + exception.message == providedMessage + and: 'the exception has the provided details' + exception.details == providedDetails + } + + def 'Creating a model validation exception with a root cause.'() { + given: 'a model validation exception is created' + def exception = new ModelValidationException(providedMessage, providedDetails, rootCause) + expect: 'the exception has the provided message' + exception.message == providedMessage + and: 'the exception has the provided details' + exception.details == providedDetails + and: 'the correct root cause is maintained' + exception.cause == rootCause + } + + def 'Creating a exception for an object not found in a dataspace.'() { + def descriptionOfObject = 'some object' + expect: 'the exception details contains the correct message with dataspace name and description of the object' + (new NotFoundInDataspaceException(dataspaceName,descriptionOfObject)).details + == "${descriptionOfObject} does not exist in dataspace ${dataspaceName}." + } + + def 'Creating an exception that the schema set already exists.'() { + given: 'an exception that the schema set already exists is created' + def exception = new SchemaSetAlreadyDefinedException(dataspaceName, schemaSetName, rootCause) + expect: 'the exception details contains the correct message with dataspace and schema set names' + exception.details == "Schema Set with name ${schemaSetName} already exists for dataspace ${dataspaceName}." + and: 'the correct root cause is maintained' + exception.cause == rootCause + } + + def 'Creating a exception that a schema set cannot be found.'() { + expect: 'the exception details contains the correct message with dataspace and schema set names' + (new SchemaSetNotFoundException(dataspaceName,schemaSetName)).details + == "Schema Set with name ${schemaSetName} was not found for dataspace ${dataspaceName}." + } +} |