diff options
Diffstat (limited to 'cps-ncmp-service/src/test/groovy/org')
2 files changed, 66 insertions, 0 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DataJobStatusServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DataJobStatusServiceImplSpec.groovy new file mode 100644 index 0000000000..cc042988f6 --- /dev/null +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DataJobStatusServiceImplSpec.groovy @@ -0,0 +1,54 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 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. + * 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.impl.datajobs + +import org.onap.cps.ncmp.impl.dmi.DmiProperties +import org.onap.cps.ncmp.impl.dmi.DmiRestClient +import org.onap.cps.ncmp.impl.dmi.UrlTemplateParameters +import reactor.core.publisher.Mono +import spock.lang.Specification + +class DataJobStatusServiceImplSpec extends Specification { + + def mockDmiRestClient = Mock(DmiRestClient) + def mockDmiProperties = Mock(DmiProperties) + def objectUnderTest = new DataJobStatusServiceImpl(mockDmiRestClient, mockDmiProperties) + + def setup() { + mockDmiProperties.dmiBasePath >> 'dmi' + } + + def 'Forward a data job status query to DMI.' () { + given: 'the required parameters for querying' + def dmiServiceName = 'some-dmi-service' + def requestId = 'some-request-id' + def dataProducerJobId = 'some-data-producer-job-id' + def dataJobId = 'some-data-job-id' + def authorization = 'my authorization header' + def urlParams = new UrlTemplateParameters('some-dmi-service/dmi/v1/dataJob/{requestId}/dataProducerJob/{dataProducerJobId}/status?dataProducerId={dataProducerId}', ['dataProducerJobId':'some-data-producer-job-id', 'dataProducerId':'some-data-job-id', 'requestId':'some-request-id']) + and: 'the rest client returns a status for the given parameters' + mockDmiRestClient.getDataJobStatus(urlParams, authorization) >> Mono.just('some status') + when: 'the job status is queried' + def status = objectUnderTest.getDataJobStatus(authorization, dmiServiceName, requestId, dataProducerJobId, dataJobId) + then: 'the status from the rest client is returned' + assert status == 'some status' + } +} diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiRestClientSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiRestClientSpec.groovy index 3dadf23249..3444d7b86a 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiRestClientSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiRestClientSpec.groovy @@ -163,4 +163,16 @@ class DmiRestClientSpec extends Specification { 'DMI basic auth disabled, with NCMP bearer token' | false | BEARER_AUTH_HEADER || BEARER_AUTH_HEADER 'DMI basic auth disabled, with NCMP basic auth' | false | BASIC_AUTH_HEADER || NO_AUTH_HEADER } + + def 'DMI GET Operation for DMI Data Service '() { + given: 'the Data web client returns a valid response entity for the expected parameters' + mockDataServicesWebClient.get() >> mockRequestBody + def jsonNode = jsonObjectMapper.convertJsonString('{"status":"some status"}', JsonNode.class) + ((ObjectNode) jsonNode).put('status', 'some status') + mockResponse.bodyToMono(JsonNode.class) >> Mono.just(jsonNode) + when: 'GET operation is invoked for Data Service' + def response = objectUnderTest.getDataJobStatus(urlTemplateParameters, NO_AUTH_HEADER).block() + then: 'the response equals to the expected value' + assert response == 'some status' + } } |