summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lombok.config20
-rw-r--r--pom.xml6
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/Application.java (renamed from src/main/java/org/onap/cps/ncmp/Application.java)2
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/config/CpsConfiguration.java55
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/config/DmiPluginConfig.java (renamed from src/main/java/org/onap/cps/ncmp/config/DmiPluginConfig.java)2
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/config/WebSecurityConfig.java (renamed from src/main/java/org/onap/cps/ncmp/config/WebSecurityConfig.java)2
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java (renamed from src/main/java/org/onap/cps/ncmp/rest/controller/DmiRestController.java)4
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java (renamed from src/main/java/org/onap/cps/ncmp/service/DmiService.java)2
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java (renamed from src/main/java/org/onap/cps/ncmp/service/DmiServiceImpl.java)2
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/client/NcmpRestClient.java63
-rw-r--r--src/main/resources/application.yml9
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/ControllerSecuritySpec.groovy (renamed from src/test/groovy/org/onap/cps/ncmp/rest/controller/ControllerSecuritySpec.groovy)2
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy (renamed from src/test/groovy/org/onap/cps/ncmp/rest/controller/DmiRestControllerSpec.groovy)5
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy (renamed from src/test/groovy/org/onap/cps/ncmp/service/DmiServiceImplSpec.groovy)2
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/service/client/NcmpRestClientSpec.groovy56
-rw-r--r--src/test/java/org/onap/cps/ncmp/dmi/rest/controller/TestController.java (renamed from src/test/java/org/onap/cps/ncmp/rest/controller/TestController.java)2
16 files changed, 221 insertions, 13 deletions
diff --git a/lombok.config b/lombok.config
new file mode 100644
index 00000000..8e900f62
--- /dev/null
+++ b/lombok.config
@@ -0,0 +1,20 @@
+# ============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=========================================================
+
+config.stopBubbling = true
+lombok.addLombokGeneratedAnnotation = true \ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 26a7b4e4..ffa14340 100644
--- a/pom.xml
+++ b/pom.xml
@@ -38,7 +38,7 @@
<name>ncmp-dmi-plugin</name>
<description>DMI Plugin Service</description>
<properties>
- <app>org.onap.cps.ncmp.Application</app>
+ <app>org.onap.cps.ncmp.dmi.Application</app>
<base.image>${docker.pull.registry}/onap/integration-java11:8.0.0</base.image>
<cps.version>1.1.0-SNAPSHOT</cps.version>
<image.tag>${project.version}-${maven.build.timestamp}</image.tag>
@@ -117,6 +117,10 @@
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ </dependency>
+ <dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
diff --git a/src/main/java/org/onap/cps/ncmp/Application.java b/src/main/java/org/onap/cps/ncmp/dmi/Application.java
index 44acde4c..69d21ba1 100644
--- a/src/main/java/org/onap/cps/ncmp/Application.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/Application.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp;
+package org.onap.cps.ncmp.dmi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/config/CpsConfiguration.java b/src/main/java/org/onap/cps/ncmp/dmi/config/CpsConfiguration.java
new file mode 100644
index 00000000..a9970da8
--- /dev/null
+++ b/src/main/java/org/onap/cps/ncmp/dmi/config/CpsConfiguration.java
@@ -0,0 +1,55 @@
+/*
+ * ============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 lombok.Getter;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.web.client.RestTemplateBuilder;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * Provides access to cps base url and cps authentication.
+ */
+@Configuration
+public class CpsConfiguration {
+
+ @Getter
+ @Component
+ public static class CpsProperties {
+
+ @Value("${cps-core.baseUrl}")
+ private String baseUrl;
+ @Value("${cps-core.dmiRegistrationUrl}")
+ private String dmiRegistrationUrl;
+ @Value("${cps-core.auth.username}")
+ private String authUsername;
+ @Value("${cps-core.auth.password}")
+ private String authPassword;
+ }
+
+ @Bean
+ public RestTemplate restTemplate(final RestTemplateBuilder restTemplateBuilder) {
+ return restTemplateBuilder.build();
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/cps/ncmp/config/DmiPluginConfig.java b/src/main/java/org/onap/cps/ncmp/dmi/config/DmiPluginConfig.java
index 06b28691..33d6ae89 100644
--- a/src/main/java/org/onap/cps/ncmp/config/DmiPluginConfig.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/config/DmiPluginConfig.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.config;
+package org.onap.cps.ncmp.dmi.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
diff --git a/src/main/java/org/onap/cps/ncmp/config/WebSecurityConfig.java b/src/main/java/org/onap/cps/ncmp/dmi/config/WebSecurityConfig.java
index a911ef82..a51d4862 100644
--- a/src/main/java/org/onap/cps/ncmp/config/WebSecurityConfig.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/config/WebSecurityConfig.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.config;
+package org.onap.cps.ncmp.dmi.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
diff --git a/src/main/java/org/onap/cps/ncmp/rest/controller/DmiRestController.java b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java
index 16fb73a8..c4cbaece 100644
--- a/src/main/java/org/onap/cps/ncmp/rest/controller/DmiRestController.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java
@@ -18,10 +18,10 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.rest.controller;
+package org.onap.cps.ncmp.dmi.rest.controller;
+import org.onap.cps.ncmp.dmi.service.DmiService;
import org.onap.cps.ncmp.rest.api.DmiPluginApi;
-import org.onap.cps.ncmp.service.DmiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
diff --git a/src/main/java/org/onap/cps/ncmp/service/DmiService.java b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java
index 48509d98..84c60d55 100644
--- a/src/main/java/org/onap/cps/ncmp/service/DmiService.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.service;
+package org.onap.cps.ncmp.dmi.service;
/**
* Interface for handling Dmi plugin Data.
diff --git a/src/main/java/org/onap/cps/ncmp/service/DmiServiceImpl.java b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java
index f84039bb..5051b1ad 100644
--- a/src/main/java/org/onap/cps/ncmp/service/DmiServiceImpl.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.service;
+package org.onap.cps.ncmp.dmi.service;
import org.springframework.stereotype.Service;
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/client/NcmpRestClient.java b/src/main/java/org/onap/cps/ncmp/dmi/service/client/NcmpRestClient.java
new file mode 100644
index 00000000..2158e836
--- /dev/null
+++ b/src/main/java/org/onap/cps/ncmp/dmi/service/client/NcmpRestClient.java
@@ -0,0 +1,63 @@
+/*
+ * ============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.service.client;
+
+import org.onap.cps.ncmp.dmi.config.CpsConfiguration.CpsProperties;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.util.UriComponentsBuilder;
+
+@Component
+public class NcmpRestClient {
+
+ private CpsProperties cpsProperties;
+ private RestTemplate restTemplate;
+
+ public NcmpRestClient(final CpsProperties cpsProperties, final RestTemplate restTemplate) {
+ this.cpsProperties = cpsProperties;
+ this.restTemplate = restTemplate;
+ }
+
+ /**
+ * Register a cmHandle with NCMP using a HTTP call.
+ * @param jsonData json data
+ * @return the response entity
+ */
+ public ResponseEntity<String> registerCmHandlesWithNcmp(final String jsonData) {
+ final var ncmpRegistrationUrl = buildNcmpRegistrationUrl();
+ final var httpHeaders = new HttpHeaders();
+ httpHeaders.setBasicAuth(cpsProperties.getAuthUsername(), cpsProperties.getAuthPassword());
+ httpHeaders.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
+ final var httpEntity = new HttpEntity<>(jsonData, httpHeaders);
+ return restTemplate.postForEntity(ncmpRegistrationUrl, httpEntity, String.class);
+ }
+
+ private String buildNcmpRegistrationUrl() {
+ return UriComponentsBuilder
+ .fromHttpUrl(cpsProperties.getBaseUrl())
+ .path(cpsProperties.getDmiRegistrationUrl())
+ .toUriString();
+ }
+} \ No newline at end of file
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index ad1c8a3c..6a0cf975 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -45,3 +45,12 @@ management:
# kubernetes probes: liveness and readiness
probes:
enabled: true
+ loggers:
+ enabled: true
+
+cps-core:
+ baseUrl: http://${CPS_CORE_HOST}:${CPS_CORE_PORT}
+ dmiRegistrationUrl : /cps-ncmp/api/ncmp-dmi/v1/ch
+ auth:
+ username: ${CPS_CORE_USERNAME}
+ password: ${CPS_CORE_PASSWORD} \ No newline at end of file
diff --git a/src/test/groovy/org/onap/cps/ncmp/rest/controller/ControllerSecuritySpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/ControllerSecuritySpec.groovy
index 6536de7a..14ab7147 100644
--- a/src/test/groovy/org/onap/cps/ncmp/rest/controller/ControllerSecuritySpec.groovy
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/ControllerSecuritySpec.groovy
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.rest.controller
+package org.onap.cps.ncmp.dmi.rest.controller
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
diff --git a/src/test/groovy/org/onap/cps/ncmp/rest/controller/DmiRestControllerSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy
index 2271bb46..f8b4c015 100644
--- a/src/test/groovy/org/onap/cps/ncmp/rest/controller/DmiRestControllerSpec.groovy
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy
@@ -18,11 +18,12 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.rest.controller
+package org.onap.cps.ncmp.dmi.rest.controller
+
+import org.onap.cps.ncmp.dmi.service.DmiService
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
-import org.onap.cps.ncmp.service.DmiService
import org.spockframework.spring.SpringBean
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.http.HttpStatus
diff --git a/src/test/groovy/org/onap/cps/ncmp/service/DmiServiceImplSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy
index 85303f4b..2124c9b4 100644
--- a/src/test/groovy/org/onap/cps/ncmp/service/DmiServiceImplSpec.groovy
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.service
+package org.onap.cps.ncmp.dmi.service
import spock.lang.Specification
diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/service/client/NcmpRestClientSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/service/client/NcmpRestClientSpec.groovy
new file mode 100644
index 00000000..4f929865
--- /dev/null
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/service/client/NcmpRestClientSpec.groovy
@@ -0,0 +1,56 @@
+/*
+ * ============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.service.client
+
+import org.onap.cps.ncmp.dmi.config.CpsConfiguration
+import org.springframework.http.ResponseEntity
+import org.springframework.web.client.RestTemplate
+import spock.lang.Specification
+
+class NcmpRestClientSpec extends Specification {
+ def objectUnderTest = new NcmpRestClient(mockCpsProperties, mockRestTemplate)
+ def mockCpsProperties = Mock(CpsConfiguration.CpsProperties)
+ def mockRestTemplate = Mock(RestTemplate)
+
+ def setup() {
+ objectUnderTest.cpsProperties = mockCpsProperties
+ objectUnderTest.restTemplate = mockRestTemplate
+ }
+
+ def 'Register a cm handle.'() {
+ given: 'json data'
+ def jsonData = 'some json'
+ and: 'configuration data'
+ mockCpsProperties.baseUrl >> 'http://some-uri'
+ mockCpsProperties.dmiRegistrationUrl >> 'some-url'
+ mockCpsProperties.authUsername >> 'some-username'
+ mockCpsProperties.authPassword >> 'some-password'
+ and: 'the rest template returns a valid response entity'
+ def mockResponseEntity = Mock(ResponseEntity)
+ when: 'registerCmHandle is invoked'
+ def result = objectUnderTest.registerCmHandlesWithNcmp(jsonData)
+ then: 'the rest template is called with the correct uri and json in the body'
+ 1 * mockRestTemplate.postForEntity({ it.toString() == 'http://some-uri/some-url' },
+ { it.body.contains(jsonData) }, String.class) >> mockResponseEntity
+ and: 'the output of the method is the same as the output from the test template'
+ result == mockResponseEntity
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/cps/ncmp/rest/controller/TestController.java b/src/test/java/org/onap/cps/ncmp/dmi/rest/controller/TestController.java
index 5d6f7b90..5240e239 100644
--- a/src/test/java/org/onap/cps/ncmp/rest/controller/TestController.java
+++ b/src/test/java/org/onap/cps/ncmp/dmi/rest/controller/TestController.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.rest.controller;
+package org.onap.cps.ncmp.dmi.rest.controller;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;