diff options
author | 2024-05-21 12:16:43 +0100 | |
---|---|---|
committer | 2024-05-22 16:33:59 +0100 | |
commit | ba41fe964a2039fb6dd9c0fd0b53163465869799 (patch) | |
tree | b3f886e7bf6c15027a606b1c5a7708e2cfd12d3f /cps-ncmp-service/src/test/groovy/org/onap | |
parent | 6d85c1547fad014fbea44af57440e3de1c3ce9ff (diff) |
Remove un-used code of RestTemplate
- Removed unused property belons to resttemplate
- Refactored dmi properties class (from static internal class)
- Overriden getter method of dmi basepath that removes any leading and trailing slashes from it.
Issue-ID: CPS-2202
Change-Id: I16f61388fce2a6b9e258788fa826d485581d6138
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/test/groovy/org/onap')
7 files changed, 30 insertions, 41 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy index 547d08a3e..d2dce06b0 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy @@ -47,9 +47,10 @@ import org.springframework.web.reactive.function.client.WebClient import reactor.core.publisher.Mono import spock.lang.Specification import org.springframework.web.reactive.function.client.WebClientResponseException +import org.onap.cps.ncmp.api.impl.config.DmiProperties @SpringBootTest -@ContextConfiguration(classes = [DmiWebClientConfiguration, DmiRestClient, ObjectMapper]) +@ContextConfiguration(classes = [DmiProperties, DmiRestClient, ObjectMapper]) class DmiRestClientSpec extends Specification { static final NO_AUTH_HEADER = null @@ -57,7 +58,7 @@ class DmiRestClientSpec extends Specification { static final BEARER_AUTH_HEADER = 'Bearer my-bearer-token' @Autowired - DmiWebClientConfiguration.DmiProperties dmiProperties + DmiProperties dmiProperties @Autowired DmiRestClient objectUnderTest diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/DmiWebClientConfigurationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/DmiWebClientConfigurationSpec.groovy index 6a73089e8..ee7ab3f28 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/DmiWebClientConfigurationSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/DmiWebClientConfigurationSpec.groovy @@ -20,7 +20,7 @@ package org.onap.cps.ncmp.api.impl.config -import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.test.context.SpringBootTest import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.TestPropertySource @@ -28,30 +28,18 @@ import org.springframework.web.reactive.function.client.WebClient import spock.lang.Specification @SpringBootTest -@ContextConfiguration(classes = [DmiWebClientConfiguration.DmiProperties]) +@ContextConfiguration(classes = [HttpClientConfiguration]) @TestPropertySource(properties = ['ncmp.dmi.httpclient.connectionTimeoutInSeconds=1', 'ncmp.dmi.httpclient.maximumInMemorySizeInMegabytes=1']) +@EnableConfigurationProperties class DmiWebClientConfigurationSpec extends Specification { - @Autowired - DmiWebClientConfiguration.DmiProperties dmiProperties + def httpClientConfiguration = Spy(HttpClientConfiguration.class) - def objectUnderTest = new DmiWebClientConfiguration() - - def setup() { - objectUnderTest.connectionTimeoutInSeconds = 10 - objectUnderTest.maximumInMemorySizeInMegabytes = 1 - objectUnderTest.maximumConnectionsTotal = 2 - } - - def 'DMI Properties.'() { - expect: 'properties are set to values in test configuration yaml file' - dmiProperties.authUsername == 'some-user' - dmiProperties.authPassword == 'some-password' - } + def objectUnderTest = new DmiWebClientConfiguration(httpClientConfiguration) def 'Web Client Configuration construction.'() { expect: 'the system can create an instance' - new DmiWebClientConfiguration() != null + new DmiWebClientConfiguration(httpClientConfiguration) != null } def 'Creating a WebClient instance.'() { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/HttpClientConfigurationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/HttpClientConfigurationSpec.groovy index 2c76b5bb4..4ede360e6 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/HttpClientConfigurationSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/HttpClientConfigurationSpec.groovy @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation. + * Copyright (C) 2023-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,32 +17,31 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ + package org.onap.cps.ncmp.api.impl.config -import java.time.Duration import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.test.context.SpringBootTest import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.support.AnnotationConfigContextLoader import spock.lang.Specification @SpringBootTest @ContextConfiguration(classes = [HttpClientConfiguration]) @EnableConfigurationProperties(HttpClientConfiguration.class) -@TestPropertySource(properties = ["ncmp.dmi.httpclient.connectionTimeoutInSeconds=1", "ncmp.dmi.httpclient.maximumConnectionsTotal=200"]) +@TestPropertySource(properties = ["ncmp.dmi.httpclient.readTimeoutInSeconds=123", "ncmp.dmi.httpclient.maximumConnectionsTotal=200"]) class HttpClientConfigurationSpec extends Specification { @Autowired private HttpClientConfiguration httpClientConfiguration def 'Test HttpClientConfiguration properties with custom and default values'() { - expect: 'custom property values' - assert httpClientConfiguration.getConnectionTimeoutInSeconds() == Duration.ofSeconds(1) - assert httpClientConfiguration.getMaximumConnectionsTotal() == 200 - and: 'default property values' - assert httpClientConfiguration.getMaximumConnectionsPerRoute() == 50 - assert httpClientConfiguration.getIdleConnectionEvictionThresholdInSeconds() == Duration.ofSeconds(5) + expect: 'properties are populated correctly' + assert httpClientConfiguration.connectionTimeoutInSeconds == 123 + assert httpClientConfiguration.readTimeoutInSeconds == 123 + assert httpClientConfiguration.writeTimeoutInSeconds == 30 + assert httpClientConfiguration.maximumConnectionsTotal == 200 + assert httpClientConfiguration.maximumInMemorySizeInMegabytes == 16 } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy index 8fcdc3fb3..d04052f79 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy @@ -31,7 +31,7 @@ import static org.onap.cps.ncmp.api.impl.operations.OperationType.UPDATE import com.fasterxml.jackson.databind.ObjectMapper import org.onap.cps.events.EventsPublisher -import org.onap.cps.ncmp.api.impl.config.DmiWebClientConfiguration +import org.onap.cps.ncmp.api.impl.config.DmiProperties import org.onap.cps.ncmp.api.impl.exception.DmiClientRequestException import org.onap.cps.ncmp.api.impl.utils.DmiServiceUrlBuilder import org.onap.cps.ncmp.api.impl.utils.context.CpsApplicationContext @@ -49,7 +49,7 @@ import org.springframework.test.context.ContextConfiguration import spock.lang.Shared @SpringBootTest -@ContextConfiguration(classes = [EventsPublisher, CpsApplicationContext, DmiWebClientConfiguration.DmiProperties, DmiDataOperations]) +@ContextConfiguration(classes = [EventsPublisher, CpsApplicationContext, DmiProperties, DmiDataOperations]) class DmiDataOperationsSpec extends DmiOperationsBaseSpec { @SpringBean diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy index ae9c1749e..88af0479d 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy @@ -23,7 +23,7 @@ package org.onap.cps.ncmp.api.impl.operations import com.fasterxml.jackson.core.JsonProcessingException import com.fasterxml.jackson.databind.ObjectMapper -import org.onap.cps.ncmp.api.impl.config.DmiWebClientConfiguration +import org.onap.cps.ncmp.api.impl.config.DmiProperties import org.onap.cps.spi.model.ModuleReference import org.onap.cps.utils.JsonObjectMapper import org.spockframework.spring.SpringBean @@ -37,7 +37,7 @@ import spock.lang.Shared import static org.onap.cps.ncmp.api.impl.operations.OperationType.READ @SpringBootTest -@ContextConfiguration(classes = [DmiWebClientConfiguration.DmiProperties, DmiModelOperations]) +@ContextConfiguration(classes = [DmiProperties, DmiModelOperations]) class DmiModelOperationsSpec extends DmiOperationsBaseSpec { @Shared diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiOperationsBaseSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiOperationsBaseSpec.groovy index 042cb4a0d..3518440ca 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiOperationsBaseSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiOperationsBaseSpec.groovy @@ -22,7 +22,7 @@ package org.onap.cps.ncmp.api.impl.operations import com.fasterxml.jackson.databind.ObjectMapper import org.onap.cps.ncmp.api.impl.client.DmiRestClient -import org.onap.cps.ncmp.api.impl.config.DmiWebClientConfiguration +import org.onap.cps.ncmp.api.impl.config.DmiProperties import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle import org.onap.cps.ncmp.api.impl.utils.DmiServiceUrlBuilder import org.onap.cps.ncmp.api.impl.inventory.CmHandleState @@ -50,7 +50,7 @@ abstract class DmiOperationsBaseSpec extends Specification { ObjectMapper spyObjectMapper = Spy() @SpringBean - DmiServiceUrlBuilder dmiServiceUrlBuilder = new DmiServiceUrlBuilder(new DmiWebClientConfiguration.DmiProperties(), mockCpsValidator) + DmiServiceUrlBuilder dmiServiceUrlBuilder = new DmiServiceUrlBuilder(new DmiProperties(), mockCpsValidator) def yangModelCmHandle = new YangModelCmHandle() def static dmiServiceName = 'some service name' diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/DmiServiceUrlBuilderSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/DmiServiceUrlBuilderSpec.groovy index 86baca680..2c7fa654c 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/DmiServiceUrlBuilderSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/DmiServiceUrlBuilderSpec.groovy @@ -22,7 +22,7 @@ package org.onap.cps.ncmp.api.impl.utils import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_RUNNING -import org.onap.cps.ncmp.api.impl.config.DmiWebClientConfiguration +import org.onap.cps.ncmp.api.impl.config.DmiProperties import org.onap.cps.ncmp.api.impl.operations.RequiredDmiService import org.onap.cps.spi.utils.CpsValidator import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle @@ -34,7 +34,7 @@ class DmiServiceUrlBuilderSpec extends Specification { static YangModelCmHandle yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle('dmiServiceName', 'dmiDataServiceName', 'dmiModuleServiceName', new NcmpServiceCmHandle(cmHandleId: 'some-cm-handle-id'),'my-module-set-tag', 'my-alternate-id', 'my-data-producer-identifier') - DmiWebClientConfiguration.DmiProperties dmiProperties = new DmiWebClientConfiguration.DmiProperties() + DmiProperties dmiProperties = new DmiProperties() def mockCpsValidator = Mock(CpsValidator) @@ -74,9 +74,10 @@ class DmiServiceUrlBuilderSpec extends Specification { then: 'the created dmi service url matches the expected' assert dmiServiceUrl == expectedDmiServiceUrl where: 'the following parameters are used' - scenario | decription | dmiBasePath || expectedDmiServiceUrl - 'with base path / ' | 'Invalid base path as it starts with /' | '/dmi' || 'dmiServiceName//dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running' - 'without base path / ' | 'Valid path as it does not starts with /' | 'dmi' || 'dmiServiceName/dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running' + scenario | decription | dmiBasePath || expectedDmiServiceUrl + 'base path starts with /' | 'Remove / from start of base path' | '/dmi' || 'dmiServiceName/dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running' + 'base path ends with / ' | 'Remove / from end of base path' | 'dmi/' || 'dmiServiceName/dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running' + 'base path without any / ' | 'base path does not contains any /' | 'dmi' || 'dmiServiceName/dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running' } def 'Bath request Url creation.'() { |