summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToineSiebelink <toine.siebelink@est.tech>2021-09-30 16:53:42 +0100
committerToineSiebelink <toine.siebelink@est.tech>2021-10-01 08:42:00 +0100
commit4cbd60b974fa68cab8501e9f3e9edef134eac09b (patch)
tree2eb45ddbf569afd841d012a43ebbeaab0eb4a358
parent7e148f8eda2c5741d5c08ae37c6fd36f8d861659 (diff)
Fix issues with SOnar Qube coverage report
-removed invalid jacoco exclude -removed strange (generated/accidental?) comment in main pom header -moved manually coded 'models' package (included in coverage now) to separate it from swagger generated package/classes with same name (exluded in coverage) -added some missing test scenarios -increased coverage limit from 70 to 98% to prevent regression Issue-ID: CPS-475 Signed-off-by: ToineSiebelink <toine.siebelink@est.tech> Change-Id: I2f1c276c543926d2d259e33b418f21de4abfea96
-rw-r--r--pom.xml106
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java8
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java4
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java12
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/model/CmHandleOperation.java (renamed from src/main/java/org/onap/cps/ncmp/dmi/model/CmHandleOperation.java)4
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/model/CreatedCmHandle.java (renamed from src/main/java/org/onap/cps/ncmp/dmi/model/CreatedCmHandle.java)4
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/model/ModuleReference.java (renamed from src/main/java/org/onap/cps/ncmp/dmi/model/ModuleReference.java)2
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/model/ModuleSchemaList.java (renamed from src/main/java/org/onap/cps/ncmp/dmi/model/ModuleSchemaList.java)2
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/model/ModuleSchemaProperties.java (renamed from src/main/java/org/onap/cps/ncmp/dmi/model/ModuleSchemaProperties.java)2
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/model/ModuleSchemas.java (renamed from src/main/java/org/onap/cps/ncmp/dmi/model/ModuleSchemas.java)2
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/config/DmiConfigurationSpec.groovy66
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/config/DmiPluginConfigSpec.groovy52
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/model/ModuleSchemaPropertiesSpec.groovy41
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy28
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy35
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy2
-rw-r--r--src/test/resources/GetModules.json4
-rw-r--r--src/test/resources/application.yml12
18 files changed, 247 insertions, 139 deletions
diff --git a/pom.xml b/pom.xml
index 2eca0b26..4fb6b167 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,108 +17,7 @@
SPDX-License-Identifier: Apache-2.0
============LICENSE_END=========================================================
---><!DOCTYPE project [
- <!ELEMENT project (modelVersion|parent|organization|groupId|artifactId|version|name|description|properties|dependencyManagement|dependencies|build|pluginManagement)*>
- <!ATTLIST project
- xmlns CDATA #REQUIRED
- xmlns:xsi CDATA #REQUIRED
- xsi:schemaLocation CDATA #REQUIRED>
- <!ELEMENT modelVersion (#PCDATA)>
- <!ELEMENT parent (groupId|artifactId|version|relativePath)*>
- <!ELEMENT groupId (#PCDATA)>
- <!ELEMENT artifactId (#PCDATA)>
- <!ELEMENT version (#PCDATA)>
- <!ELEMENT relativePath (#PCDATA)>
- <!ELEMENT organization (name|url)*>
- <!ELEMENT name (#PCDATA)>
- <!ELEMENT url (#PCDATA)>
- <!ELEMENT description (#PCDATA)>
- <!ELEMENT properties (app|base.image|cps.version|image.tag|jacoco.minimum.coverage|maven.build.timestamp.format|project.build.sourceEncoding|image.name)*>
- <!ELEMENT app (#PCDATA)>
- <!ELEMENT base.image (#PCDATA)>
- <!ELEMENT cps.version (#PCDATA)>
- <!ELEMENT image.tag (#PCDATA)>
- <!ELEMENT jacoco.minimum.coverage (#PCDATA)>
- <!ELEMENT maven.build.timestamp.format (#PCDATA)>
- <!ELEMENT project.build.sourceEncoding (#PCDATA)>
- <!ELEMENT dependencyManagement (dependencies)*>
- <!ELEMENT dependencies (dependency)*>
- <!ELEMENT dependency (groupId|artifactId|version|type|scope|exclusions)*>
- <!ELEMENT type (#PCDATA)>
- <!ELEMENT scope (#PCDATA)>
- <!ELEMENT exclusions (exclusion)*>
- <!ELEMENT exclusion (groupId|artifactId)*>
- <!ELEMENT build (resources|plugins|plugin)*>
- <!ELEMENT resources (resource)*>
- <!ELEMENT resource (directory|filtering|includes|targetPath)*>
- <!ELEMENT directory (#PCDATA)>
- <!ELEMENT filtering (#PCDATA)>
- <!ELEMENT includes (include)*>
- <!ELEMENT include (#PCDATA)>
- <!ELEMENT targetPath (#PCDATA)>
- <!ELEMENT plugins (plugin)*>
- <!ELEMENT plugin (groupId|artifactId|version|executions|configuration|dependencies)*>
- <!ELEMENT executions (execution)*>
- <!ELEMENT execution (goals|configuration|id|phase)*>
- <!ELEMENT goals (goal)*>
- <!ELEMENT goal (#PCDATA)>
- <!ELEMENT configuration (inputSpec|language|generateSupportingFiles|apiPackage|modelPackage|configOptions|argLine|includes|excludes|configLocation|includeResources|includeTestSourceDirectory|includeTestResources|sourceDirectories|consoleOutput|violationSeverity|failOnViolation|plugins|effort|threshold|failOnError|excludeFilterFile|xmlOutput|xmlOutputDirectory|dataFile|rules|dataFileIncludes|container|from|to)*>
- <!ELEMENT inputSpec (#PCDATA)>
- <!ELEMENT language (#PCDATA)>
- <!ELEMENT generateSupportingFiles (#PCDATA)>
- <!ELEMENT apiPackage (#PCDATA)>
- <!ELEMENT modelPackage (#PCDATA)>
- <!ELEMENT configOptions (sourceFolder|dateLibrary|interfaceOnly|useTags)*>
- <!ELEMENT sourceFolder (#PCDATA)>
- <!ELEMENT dateLibrary (#PCDATA)>
- <!ELEMENT interfaceOnly (#PCDATA)>
- <!ELEMENT useTags (#PCDATA)>
- <!ELEMENT id (#PCDATA)>
- <!ELEMENT phase (#PCDATA)>
- <!ELEMENT argLine (#PCDATA)>
- <!ELEMENT excludes (exclude)*>
- <!ELEMENT exclude (#PCDATA)>
- <!ELEMENT configLocation (#PCDATA)>
- <!ELEMENT includeResources (#PCDATA)>
- <!ELEMENT includeTestSourceDirectory (#PCDATA)>
- <!ELEMENT includeTestResources (#PCDATA)>
- <!ELEMENT sourceDirectories (sourceDirectory)*>
- <!ELEMENT sourceDirectory (#PCDATA)>
- <!ELEMENT consoleOutput (#PCDATA)>
- <!ELEMENT violationSeverity (#PCDATA)>
- <!ELEMENT failOnViolation (#PCDATA)>
- <!ELEMENT effort (#PCDATA)>
- <!ELEMENT threshold (#PCDATA)>
- <!ELEMENT failOnError (#PCDATA)>
- <!ELEMENT excludeFilterFile (#PCDATA)>
- <!ELEMENT xmlOutput (#PCDATA)>
- <!ELEMENT xmlOutputDirectory (#PCDATA)>
- <!ELEMENT dataFile (#PCDATA)>
- <!ELEMENT rules (rule)*>
- <!ELEMENT rule (element|limits)*>
- <!ELEMENT element (#PCDATA)>
- <!ELEMENT limits (limit)*>
- <!ELEMENT limit (counter|value|minimum)*>
- <!ELEMENT counter (#PCDATA)>
- <!ELEMENT value (#PCDATA)>
- <!ELEMENT minimum (#PCDATA)>
- <!ELEMENT dataFileIncludes (fileInclude)*>
- <!ELEMENT fileInclude (#PCDATA)>
- <!ELEMENT pluginManagement (plugins)*>
- <!ELEMENT container (mainClass|creationTime)*>
- <!ELEMENT mainClass (#PCDATA)>
- <!ELEMENT creationTime (#PCDATA)>
- <!ELEMENT from (image)*>
- <!ELEMENT image (#PCDATA)>
- <!ELEMENT to (tags|image)*>
- <!ELEMENT tags (tag)*>
- <!ELEMENT tag (#PCDATA)>
- <!ELEMENT profiles (profile)*>
- <!ELEMENT profile (id|activation|properties|build)*>
- <!ELEMENT activation (activeByDefault)*>
- <!ELEMENT activeByDefault (#PCDATA)>
- <!ELEMENT image.name (#PCDATA)>
- ]>
+-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
@@ -143,7 +42,7 @@
<base.image>${docker.pull.registry}/onap/integration-java11:8.0.0</base.image>
<cps.version>2.0.0</cps.version>
<image.tag>${project.version}-${maven.build.timestamp}</image.tag>
- <jacoco.minimum.coverage>0.7</jacoco.minimum.coverage>
+ <jacoco.minimum.coverage>0.98</jacoco.minimum.coverage>
<maven.build.timestamp.format>yyyyMMdd'T'HHmmss'Z'</maven.build.timestamp.format>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
@@ -443,7 +342,6 @@
<configuration>
<excludes>
<exclude>org/onap/cps/ncmp/dmi/model/*</exclude>
- <exclude>org/onap/cps/ncmp/dmi/config/*</exclude>
</excludes>
</configuration>
<executions>
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java
index ff3cefcd..0afefeb0 100644
--- a/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java
@@ -20,6 +20,8 @@
package org.onap.cps.ncmp.dmi.rest.controller;
+import static org.onap.cps.ncmp.dmi.model.DmiModuleReadRequestBody.OperationEnum.READ;
+
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
@@ -30,12 +32,12 @@ import org.onap.cps.ncmp.dmi.model.CmHandles;
import org.onap.cps.ncmp.dmi.model.DataAccessReadRequest;
import org.onap.cps.ncmp.dmi.model.DataAccessWriteRequest;
import org.onap.cps.ncmp.dmi.model.DmiModuleReadRequestBody;
-import org.onap.cps.ncmp.dmi.model.ModuleReference;
import org.onap.cps.ncmp.dmi.model.ModuleSet;
import org.onap.cps.ncmp.dmi.model.YangResources;
import org.onap.cps.ncmp.dmi.rest.api.DmiPluginApi;
import org.onap.cps.ncmp.dmi.rest.api.DmiPluginInternalApi;
import org.onap.cps.ncmp.dmi.service.DmiService;
+import org.onap.cps.ncmp.dmi.service.model.ModuleReference;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
@@ -68,7 +70,7 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
public ResponseEntity<YangResources> retrieveModuleResources(
final @Valid DmiModuleReadRequestBody dmiModuleReadRequestBody,
final String cmHandle) {
- if (dmiModuleReadRequestBody.getOperation().toString().equals("read")) {
+ if (READ.equals(dmiModuleReadRequestBody.getOperation())) {
final var moduleReferenceList = convertRestObjectToJavaApiObject(dmiModuleReadRequestBody);
final var response = dmiService.getModuleResources(cmHandle, moduleReferenceList);
return new ResponseEntity<>(response, HttpStatus.OK);
@@ -172,4 +174,4 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
.convertValue(dmiModuleSchemaReadRequestBody.getData().getModules(),
new TypeReference<List<ModuleReference>>() {});
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java
index bd0dc600..753810a2 100644
--- a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java
@@ -24,9 +24,9 @@ import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotNull;
import org.onap.cps.ncmp.dmi.exception.DmiException;
-import org.onap.cps.ncmp.dmi.model.ModuleReference;
import org.onap.cps.ncmp.dmi.model.ModuleSet;
import org.onap.cps.ncmp.dmi.model.YangResources;
+import org.onap.cps.ncmp.dmi.service.model.ModuleReference;
/**
* Interface for handling Dmi plugin Data.
@@ -108,4 +108,4 @@ public interface DmiService {
*/
String writeResourceDataPassthroughForCmHandle(String cmHandle, String resourceIdentifier, String dataType,
String data);
-} \ No newline at end of file
+}
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java
index 182bdd84..844cc4de 100644
--- a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java
@@ -37,16 +37,16 @@ import org.onap.cps.ncmp.dmi.exception.DmiException;
import org.onap.cps.ncmp.dmi.exception.ModuleResourceNotFoundException;
import org.onap.cps.ncmp.dmi.exception.ModulesNotFoundException;
import org.onap.cps.ncmp.dmi.exception.ResourceDataNotFound;
-import org.onap.cps.ncmp.dmi.model.CmHandleOperation;
-import org.onap.cps.ncmp.dmi.model.CreatedCmHandle;
-import org.onap.cps.ncmp.dmi.model.ModuleReference;
-import org.onap.cps.ncmp.dmi.model.ModuleSchemaProperties;
-import org.onap.cps.ncmp.dmi.model.ModuleSchemas;
import org.onap.cps.ncmp.dmi.model.ModuleSet;
import org.onap.cps.ncmp.dmi.model.ModuleSetSchemas;
import org.onap.cps.ncmp.dmi.model.YangResource;
import org.onap.cps.ncmp.dmi.model.YangResources;
import org.onap.cps.ncmp.dmi.service.client.NcmpRestClient;
+import org.onap.cps.ncmp.dmi.service.model.CmHandleOperation;
+import org.onap.cps.ncmp.dmi.service.model.CreatedCmHandle;
+import org.onap.cps.ncmp.dmi.service.model.ModuleReference;
+import org.onap.cps.ncmp.dmi.service.model.ModuleSchemaProperties;
+import org.onap.cps.ncmp.dmi.service.model.ModuleSchemas;
import org.onap.cps.ncmp.dmi.service.operation.SdncOperations;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -269,4 +269,4 @@ public class DmiServiceImpl implements DmiService {
return responseBodyAsJsonObject.getAsJsonObject(IETF_NETCONF_MONITORING_OUTPUT).getAsJsonPrimitive("data")
.toString();
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/model/CmHandleOperation.java b/src/main/java/org/onap/cps/ncmp/dmi/service/model/CmHandleOperation.java
index 8ddd42f8..82eac92a 100644
--- a/src/main/java/org/onap/cps/ncmp/dmi/model/CmHandleOperation.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/service/model/CmHandleOperation.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.dmi.model;
+package org.onap.cps.ncmp.dmi.service.model;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.List;
@@ -32,4 +32,4 @@ public class CmHandleOperation {
private String dmiPlugin;
private List<CreatedCmHandle> createdCmHandles;
-} \ No newline at end of file
+}
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/model/CreatedCmHandle.java b/src/main/java/org/onap/cps/ncmp/dmi/service/model/CreatedCmHandle.java
index 9198d7da..6ab6a01e 100644
--- a/src/main/java/org/onap/cps/ncmp/dmi/model/CreatedCmHandle.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/service/model/CreatedCmHandle.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.dmi.model;
+package org.onap.cps.ncmp.dmi.service.model;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.Map;
@@ -33,4 +33,4 @@ public class CreatedCmHandle {
private String cmHandle;
private Map<String, String> cmHandleProperties;
-} \ No newline at end of file
+}
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/model/ModuleReference.java b/src/main/java/org/onap/cps/ncmp/dmi/service/model/ModuleReference.java
index cb9b7cbb..75c37dff 100644
--- a/src/main/java/org/onap/cps/ncmp/dmi/model/ModuleReference.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/service/model/ModuleReference.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.dmi.model;
+package org.onap.cps.ncmp.dmi.service.model;
import lombok.EqualsAndHashCode;
import lombok.Getter;
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/model/ModuleSchemaList.java b/src/main/java/org/onap/cps/ncmp/dmi/service/model/ModuleSchemaList.java
index 1e7dcb0a..a4af1761 100644
--- a/src/main/java/org/onap/cps/ncmp/dmi/model/ModuleSchemaList.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/service/model/ModuleSchemaList.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.dmi.model;
+package org.onap.cps.ncmp.dmi.service.model;
import java.util.List;
import lombok.Getter;
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/model/ModuleSchemaProperties.java b/src/main/java/org/onap/cps/ncmp/dmi/service/model/ModuleSchemaProperties.java
index 507758ad..6de7d131 100644
--- a/src/main/java/org/onap/cps/ncmp/dmi/model/ModuleSchemaProperties.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/service/model/ModuleSchemaProperties.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.dmi.model;
+package org.onap.cps.ncmp.dmi.service.model;
import java.util.List;
import lombok.Getter;
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/model/ModuleSchemas.java b/src/main/java/org/onap/cps/ncmp/dmi/service/model/ModuleSchemas.java
index 5945168b..a7b2430d 100644
--- a/src/main/java/org/onap/cps/ncmp/dmi/model/ModuleSchemas.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/service/model/ModuleSchemas.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.dmi.model;
+package org.onap.cps.ncmp.dmi.service.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/config/DmiConfigurationSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/config/DmiConfigurationSpec.groovy
new file mode 100644
index 00000000..1798c9f2
--- /dev/null
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/config/DmiConfigurationSpec.groovy
@@ -0,0 +1,66 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.ncmp.dmi.config
+
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.test.context.SpringBootTest
+import org.springframework.boot.web.client.RestTemplateBuilder
+import org.springframework.test.context.ContextConfiguration
+import spock.lang.Specification
+
+@SpringBootTest
+@ContextConfiguration(classes = [DmiConfiguration.CpsProperties, DmiConfiguration.SdncProperties])
+class DmiConfigurationSpec extends Specification {
+
+ @Autowired
+ DmiConfiguration.CpsProperties cpsProperties
+
+ @Autowired
+ DmiConfiguration.SdncProperties sdncProperties
+
+ def 'CPS properties configuration.'() {
+ expect: 'CPS properties are set to values in test configuration yaml file'
+ cpsProperties.baseUrl == 'some url for cps'
+ cpsProperties.dmiRegistrationUrl == 'some registration url'
+ cpsProperties.authUsername == 'some cps core user'
+ cpsProperties.authPassword == 'some cps core password'
+ }
+
+ def 'SDNC properties configuration.'() {
+ expect: 'SDNC properties are set to values in test configuration yaml file'
+ sdncProperties.authUsername == 'test'
+ sdncProperties.authPassword == 'test'
+ sdncProperties.baseUrl == 'http://test'
+ sdncProperties.topologyId == 'test-topology'
+ }
+
+ def 'Rest template building.'() {
+ given: 'a DMI configuration'
+ DmiConfiguration objectUnderTest = new DmiConfiguration()
+ and: 'a rest template builder'
+ RestTemplateBuilder mockRestTemplateBuilder = Mock(RestTemplateBuilder)
+ when: 'rest template method is invoked'
+ objectUnderTest.restTemplate(mockRestTemplateBuilder)
+ then: 'DMI configuration uses the build method on the template builder'
+ 1 * mockRestTemplateBuilder.build()
+ }
+
+}
diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/config/DmiPluginConfigSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/config/DmiPluginConfigSpec.groovy
new file mode 100644
index 00000000..64b82329
--- /dev/null
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/config/DmiPluginConfigSpec.groovy
@@ -0,0 +1,52 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.ncmp.dmi.config
+
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.test.context.SpringBootTest
+import org.springframework.test.context.ContextConfiguration
+import spock.lang.Specification
+import springfox.documentation.spring.web.plugins.Docket
+
+@SpringBootTest
+@ContextConfiguration(classes = [DmiPluginConfig.DmiPluginProperties])
+class DmiPluginConfigSpec extends Specification {
+
+ @Autowired
+ DmiPluginConfig.DmiPluginProperties dmiPluginProperties
+
+ def 'DMI plugin properties configuration.'() {
+ expect: 'DMI plugin properties are set to values in test configuration yaml file'
+ dmiPluginProperties.dmiServiceUrl == 'some url for the dmi service'
+ }
+
+ def 'DMI plugin docket creation.'() {
+ given: 'a DMI plugin configuration'
+ DmiPluginConfig objectUnderTest = new DmiPluginConfig()
+ when: 'the api method is invoked'
+ def result = objectUnderTest.api()
+ then: 'a spring web plugin docket is returned'
+ result instanceof Docket
+ and: 'it is named "dmi-plugin-docket"'
+ result.groupName == 'dmi-plugin-docket'
+ }
+
+}
diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/model/ModuleSchemaPropertiesSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/model/ModuleSchemaPropertiesSpec.groovy
new file mode 100644
index 00000000..51dddc7d
--- /dev/null
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/model/ModuleSchemaPropertiesSpec.groovy
@@ -0,0 +1,41 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.ncmp.dmi.model
+
+import org.onap.cps.ncmp.dmi.service.model.ModuleSchemaProperties
+import spock.lang.Specification
+
+class ModuleSchemaPropertiesSpec extends Specification {
+ def objectUnderTest = new ModuleSchemaProperties(identifier:'some id',
+ version:'some version',
+ format:'some format',
+ namespace:'some namespace',
+ location: ['some','locations'])
+
+ def 'Reading all properties.'() {
+ expect: 'all properties return the expected values'
+ objectUnderTest.identifier == 'some id'
+ objectUnderTest.version == 'some version'
+ objectUnderTest.format == 'some format'
+ objectUnderTest.namespace == 'some namespace'
+ objectUnderTest.location == ['some','locations']
+ }
+}
diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy
index 9c27dc1b..8aebbca2 100644
--- a/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy
@@ -26,8 +26,8 @@ import org.onap.cps.ncmp.dmi.TestUtils
import org.onap.cps.ncmp.dmi.exception.DmiException
import org.onap.cps.ncmp.dmi.exception.ModuleResourceNotFoundException
import org.onap.cps.ncmp.dmi.exception.ModulesNotFoundException
-import org.onap.cps.ncmp.dmi.model.ModuleReference
-import org.onap.cps.ncmp.dmi.model.ModuleSchemaList
+import org.onap.cps.ncmp.dmi.service.model.ModuleReference
+import org.onap.cps.ncmp.dmi.service.model.ModuleSchemaList
import org.onap.cps.ncmp.dmi.model.ModuleSet
import org.onap.cps.ncmp.dmi.model.ModuleSetSchemas
import org.onap.cps.ncmp.dmi.model.YangResource
@@ -151,7 +151,7 @@ class DmiRestControllerSpec extends Specification {
def 'Retrieve module resources.'() {
given: 'an endpoint and json data'
def getModulesEndpoint = "$basePathV1/ch/some-cm-handle/moduleResources"
- def jsonData = TestUtils.getResourceFileContent('GetModules.json')
+ String jsonData = getJsonDataForGetModules('read')
and: 'the DMI service returns the yang resources'
ModuleReference moduleReference1 = new ModuleReference(name: 'ietf-yang-library', revision: '2016-06-21')
ModuleReference moduleReference2 = new ModuleReference(name: 'nc-notifications', revision: '2008-07-14')
@@ -170,10 +170,22 @@ class DmiRestControllerSpec extends Specification {
response.getContentAsString() == '[{"yangSource":"\\"some-data\\"","moduleName":"NAME","revision":"REVISION"}]'
}
+ def 'Retrieve module resources with invalid operation.'() {
+ given: 'an endpoint and json data with invalid operation value'
+ def getModulesEndpoint = "$basePathV1/ch/some-cm-handle/moduleResources"
+ def jsonData = getJsonDataForGetModules('invalid operation')
+ when: 'get module resource api is invoked'
+ def response = mvc.perform(post(getModulesEndpoint)
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(jsonData)).andReturn().response
+ then: 'a conflict status is returned'
+ response.status == HttpStatus.CONFLICT.value()
+ }
+
def 'Retrieve module resources with exception handling.'() {
given: 'an endpoint and json data'
def getModulesEndpoint = "$basePathV1/ch/some-cm-handle/moduleResources"
- def jsonData = TestUtils.getResourceFileContent('GetModules.json')
+ String jsonData = getJsonDataForGetModules('read')
and: 'the service method is invoked to get module resources and throws an exception'
mockDmiService.getModuleResources('some-cm-handle', _) >> { throw Mock(ModuleResourceNotFoundException.class) }
when: 'get module resource api is invoked'
@@ -248,4 +260,10 @@ class DmiRestControllerSpec extends Specification {
5,
['prop1':'value1', 'prop2':'value2'])
}
-} \ No newline at end of file
+
+ def getJsonDataForGetModules(operation) {
+ def jsonData = TestUtils.getResourceFileContent('GetModules.json')
+ return jsonData.replace('${operation-for-test}', operation)
+ }
+
+}
diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy
index 93bc641e..4c6bc750 100644
--- a/src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy
@@ -22,6 +22,7 @@ package org.onap.cps.ncmp.dmi.service
import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.databind.ObjectMapper
+import com.fasterxml.jackson.databind.ObjectWriter
import org.onap.cps.ncmp.dmi.TestUtils
import org.onap.cps.ncmp.dmi.config.DmiPluginConfig
import org.onap.cps.ncmp.dmi.exception.CmHandleRegistrationException
@@ -29,7 +30,7 @@ import org.onap.cps.ncmp.dmi.exception.DmiException
import org.onap.cps.ncmp.dmi.exception.ModuleResourceNotFoundException
import org.onap.cps.ncmp.dmi.exception.ModulesNotFoundException
import org.onap.cps.ncmp.dmi.exception.ResourceDataNotFound
-import org.onap.cps.ncmp.dmi.model.ModuleReference
+import org.onap.cps.ncmp.dmi.service.model.ModuleReference
import org.onap.cps.ncmp.dmi.model.YangResource
import org.onap.cps.ncmp.dmi.model.YangResources
import org.onap.cps.ncmp.dmi.service.client.NcmpRestClient
@@ -43,10 +44,10 @@ class DmiServiceImplSpec extends Specification {
def mockNcmpRestClient = Mock(NcmpRestClient)
def mockDmiPluginProperties = Mock(DmiPluginConfig.DmiPluginProperties)
- def objectMapper = new ObjectMapper()
+ def spyObjectMapper = Spy(ObjectMapper)
def mockObjectMapper = Mock(ObjectMapper)
def mockSdncOperations = Mock(SdncOperations)
- def objectUnderTest = new DmiServiceImpl(mockDmiPluginProperties, mockNcmpRestClient, mockSdncOperations, objectMapper)
+ def objectUnderTest = new DmiServiceImpl(mockDmiPluginProperties, mockNcmpRestClient, mockSdncOperations, spyObjectMapper)
def 'Call get modules for cm-handle on dmi Service.'() {
given: 'cm handle id'
@@ -175,17 +176,35 @@ class DmiServiceImplSpec extends Specification {
def 'Get module resources when sdnc returns #scenario response.'() {
given: 'get module schema is invoked and returns a response from sdnc'
- mockSdncOperations.getModuleResource(_ as String, _ as String) >> new ResponseEntity<String>('some-response-body', httpResponse)
+ mockSdncOperations.getModuleResource(_ as String, _ as String) >> new ResponseEntity<String>('some-response-body', httpStatus)
when: 'get module resources is invoked with the given cm handle and a module list'
objectUnderTest.getModuleResources('some-cmHandle', [new ModuleReference()] as LinkedList<ModuleReference>)
- then: 'ModuleResourceNotFoundException is thrown'
- thrown(exception)
+ then: '#expectedException is thrown'
+ thrown(expectedException)
where: 'the following values are returned'
- scenario | httpResponse || exception
+ scenario | httpStatus || expectedException
'not found' | HttpStatus.NOT_FOUND || ModuleResourceNotFoundException
'a internal server' | HttpStatus.INTERNAL_SERVER_ERROR || DmiException
}
+ def 'Get module resources with JSON processing exception.'() {
+ given: 'a json processing exception during conversion'
+ def mockObjectWriter = Mock(ObjectWriter)
+ spyObjectMapper.writer() >> mockObjectWriter
+ mockObjectWriter.withRootName(_) >> mockObjectWriter
+ def jsonProcessingException = new JsonProcessingException('')
+ mockObjectWriter.writeValueAsString(_) >> { throw jsonProcessingException }
+ when: 'get module resources is invoked with the given cm handle and a module list'
+ objectUnderTest.getModuleResources('some-cmHandle', [new ModuleReference()] as LinkedList<ModuleReference>)
+ then: 'a DMI exception is thrown'
+ def thrownException = thrown(DmiException.class)
+ and: 'the exception has the expected message and details'
+ thrownException.message == 'Unable to process JSON.'
+ thrownException.details == 'JSON exception occurred when creating the module request.'
+ and: 'the cause is the original json processing exception'
+ thrownException.cause == jsonProcessingException
+ }
+
def 'Get resource data for pass through operational from cm handle.'() {
given: 'cm-handle, pass through parameter, resourceId, accept header, fields, depth'
def cmHandle = 'testCmHandle'
@@ -278,4 +297,4 @@ class DmiServiceImplSpec extends Specification {
then: 'a dmi exception is thrown'
thrown(DmiException.class)
}
-} \ No newline at end of file
+}
diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy
index 14a62ebb..95a9c0a7 100644
--- a/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy
@@ -77,4 +77,4 @@ class SdncOperationsSpec extends Specification {
then: 'the post operation is executed with the correct URL and data'
1 * mockSdncRestClient.postOperationWithJsonData(expectedUrl, 'requestData', _ as HttpHeaders)
}
-} \ No newline at end of file
+}
diff --git a/src/test/resources/GetModules.json b/src/test/resources/GetModules.json
index 23fe77c2..98e41672 100644
--- a/src/test/resources/GetModules.json
+++ b/src/test/resources/GetModules.json
@@ -1,5 +1,5 @@
{
- "operation": "read",
+ "operation": "${operation-for-test}",
"data": {
"modules": [
{
@@ -15,4 +15,4 @@
"cmHandleProperties": {
"subsystemId": "system-001"
}
-} \ No newline at end of file
+}
diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml
index e8ca3d01..dc30c9da 100644
--- a/src/test/resources/application.yml
+++ b/src/test/resources/application.yml
@@ -31,3 +31,15 @@ sdnc:
auth:
username: test
password: test
+
+cps-core:
+ baseUrl: some url for cps
+ dmiRegistrationUrl: some registration url
+ auth:
+ username: some cps core user
+ password: some cps core password
+
+dmi:
+ service:
+ url: some url for the dmi service
+