summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorputhuparambil.aditya <aditya.puthuparambil@bell.ca>2020-12-14 15:46:30 +0000
committerputhuparambil.aditya <aditya.puthuparambil@bell.ca>2020-12-16 11:49:42 +0000
commit008c0adc3712ba0aee6410e8cd7efc61f4cbeeac (patch)
tree255b28e757eecda25bb900d4b041902787a18d24
parentc040bcb4ae61177b1aa691f059d19c96c6cfff7b (diff)
Few Sonar Fixes
Add spock-spring testing Issue-ID: CPS-89 Signed-off-by: puthuparambil.aditya <aditya.puthuparambil@bell.ca> Change-Id: I1e12fb56916e2123fc1d29bdf1524accbb9eeffd
-rwxr-xr-xcps-dependencies/pom.xml6
-rw-r--r--cps-parent/pom.xml6
-rwxr-xr-xcps-rest/pom.xml27
-rw-r--r--cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java3
-rw-r--r--cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy31
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java2
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java3
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsException.java22
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/model/DataNode.java3
9 files changed, 52 insertions, 51 deletions
diff --git a/cps-dependencies/pom.xml b/cps-dependencies/pom.xml
index 821422c40e..5c94387db4 100755
--- a/cps-dependencies/pom.xml
+++ b/cps-dependencies/pom.xml
@@ -22,6 +22,7 @@
<snapshotNexusPath>/content/repositories/snapshots/</snapshotNexusPath>
<modelmapper.version>2.3.8</modelmapper.version>
<spock-core.version>2.0-M2-groovy-3.0</spock-core.version>
+ <spock-spring.version>1.3-groovy-2.5</spock-spring.version>
<springboot.version>2.3.3.RELEASE</springboot.version>
<springfox.version>3.0.0</springfox.version>
<swagger.version>2.1.4</swagger.version>
@@ -84,6 +85,11 @@
<version>${spock-core.version}</version>
</dependency>
<dependency>
+ <groupId>org.spockframework</groupId>
+ <artifactId>spock-spring</artifactId>
+ <version>${spock-spring.version}</version>
+ </dependency>
+ <dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>${cglib-nodep.version}</version>
diff --git a/cps-parent/pom.xml b/cps-parent/pom.xml
index 89f9629a6f..9c1760cf23 100644
--- a/cps-parent/pom.xml
+++ b/cps-parent/pom.xml
@@ -20,7 +20,7 @@
<base.image>openjdk:11-jre-slim</base.image>
<java.version>11</java.version>
<jib-maven-plugin.version>2.6.0</jib-maven-plugin.version>
- <minimum-coverage>0.20</minimum-coverage>
+ <minimum-coverage>0.35</minimum-coverage>
<nexusproxy>https://nexus.onap.org</nexusproxy>
<oparent.version>3.1.0</oparent.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -324,6 +324,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
+ <!--suppress UnresolvedMavenProperty -->
<argLine>${surefireArgLine}</argLine>
<useFile>false</useFile>
<includes>
@@ -351,6 +352,9 @@
<goal>check</goal>
</goals>
<configuration>
+ <excludes>
+ <exclude>org/onap/cps/rest/model/*</exclude>
+ </excludes>
<dataFile>${project.build.directory}/code-coverage/jacoco-ut.exec</dataFile>
<rules>
<rule>
diff --git a/cps-rest/pom.xml b/cps-rest/pom.xml
index 3a82ca3770..f2f643ac23 100755
--- a/cps-rest/pom.xml
+++ b/cps-rest/pom.xml
@@ -54,17 +54,6 @@
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
</dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- <exclusions>
- <exclusion>
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
<!-- T E S T D E P E N D E N C I E S -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
@@ -77,10 +66,26 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.spockframework</groupId>
+ <artifactId>spock-spring</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.junit.vintage</groupId>
+ <artifactId>junit-vintage-engine</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
</dependencies>
<build>
diff --git a/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java b/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java
index 00e72a189e..54f3db4a08 100644
--- a/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java
+++ b/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java
@@ -37,6 +37,9 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice(assignableTypes = {CpsRestController.class})
public class CpsRestExceptionHandler {
+ private CpsRestExceptionHandler() {
+ }
+
/**
* Default exception handler.
*
diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy
index e427c6063e..7a777bf380 100644
--- a/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy
+++ b/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy
@@ -20,14 +20,18 @@
package org.onap.cps.rest.exceptions
import groovy.json.JsonSlurper
+import org.modelmapper.ModelMapper
import org.onap.cps.api.CpsAdminService
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 org.spockframework.spring.SpringBean
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
+import org.springframework.test.web.servlet.MockMvc
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll
@@ -36,10 +40,19 @@ import static org.springframework.http.HttpStatus.BAD_REQUEST
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR
import static org.springframework.http.HttpStatus.NOT_FOUND
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
-import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup
+@WebMvcTest
class CpsRestExceptionHandlerSpec extends Specification {
+ @SpringBean
+ CpsAdminService mockCpsAdminService = Mock()
+
+ @SpringBean
+ ModelMapper modelMapper = Mock()
+
+ @Autowired
+ MockMvc mvc
+
@Shared
def errorMessage = 'some error message'
@Shared
@@ -49,14 +62,6 @@ class CpsRestExceptionHandlerSpec extends Specification {
@Shared
def existingObjectName = 'MyAdminObject'
- def cpsRestController = new CpsRestController()
- def mockCpsAdminService = Mock(CpsAdminService.class)
- def objectUnderTest = new CpsRestExceptionHandler()
- def mockMvc = standaloneSetup(cpsRestController).setControllerAdvice(objectUnderTest).build()
-
- def setup() {
- cpsRestController.cpsAdminService = mockCpsAdminService
- }
def 'Get request with runtime exception returns HTTP Status Internal Server Error'() {
@@ -134,15 +139,15 @@ class CpsRestExceptionHandlerSpec extends Specification {
}
def performTestRequest() {
- return mockMvc.perform(get('/v1/dataspaces/dataspace-name/anchors')).andReturn().response
+ return mvc.perform(get('/v1/dataspaces/dataspace-name/anchors')).andReturn().response
}
- void assertTestResponse(response, expectedStatus, expectedErrorMessage, expectedErrorDetails) {
+ void assertTestResponse(response, expectedStatus,
+ expectedErrorMessage, expectedErrorDetails) {
assert response.status == expectedStatus.value()
def content = new JsonSlurper().parseText(response.contentAsString)
assert content['status'] == expectedStatus.toString()
assert content['message'] == expectedErrorMessage
assert expectedErrorDetails == null || content['details'] == expectedErrorDetails
}
-
}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java
index 7ae7c13b73..b1a8992370 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java
@@ -25,8 +25,6 @@ import java.util.Collection;
import org.onap.cps.spi.entities.Dataspace;
import org.onap.cps.spi.entities.Fragment;
import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.jpa.repository.Query;
-import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
@Repository
diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java
index 9749d8b2e3..7feae367e8 100644
--- a/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java
@@ -31,13 +31,14 @@ public interface CpsModulePersistenceService {
* TODO
* clean up method to conform with spi proposal - https://jira.onap.org/browse/CPS-103
* Store the module from a yang model in the database.
+ * @deprecated
*
* @param namespace module namespace
* @param moduleContent module content
* @param revision module revision
* @param dataspaceName the name of the dataspace the module is associated with
*/
- @Deprecated
+ @Deprecated(forRemoval = true)
void storeModule(final String namespace, final String moduleContent, final String revision,
final String dataspaceName);
diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsException.java
index 406ade688b..96a0678062 100644
--- a/cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsException.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsException.java
@@ -28,26 +28,8 @@ public class CpsException extends RuntimeException {
private static final long serialVersionUID = 1592619410918497467L;
- @Getter String details;
-
- /**
- * Constructor.
- *
- * @param cause the cause of the exception
- */
- public CpsException(final Throwable cause) {
- super(cause.getMessage(), cause);
- }
-
- /**
- * Constructor.
- *
- * @param message the error message
- * @param cause the cause of the exception
- */
- public CpsException(final String message, final Throwable cause) {
- super(message, cause);
- }
+ @Getter
+ final String details;
/**
* Constructor.
diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/DataNode.java b/cps-service/src/main/java/org/onap/cps/spi/model/DataNode.java
index 5ed45ad6e1..8bd4047007 100644
--- a/cps-service/src/main/java/org/onap/cps/spi/model/DataNode.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/model/DataNode.java
@@ -24,9 +24,6 @@ import java.util.Collection;
import java.util.Map;
import lombok.Builder;
import lombok.Data;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
@Data
@Builder