be46d885e01eda78b414ce790f9a905af3945f45
[cps.git] /
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2024 Nordix Foundation
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20
21 package org.onap.cps.ncmp.impl.datajobs
22
23 import org.onap.cps.ncmp.impl.dmi.DmiProperties
24 import org.onap.cps.ncmp.impl.dmi.DmiRestClient
25 import org.onap.cps.ncmp.impl.utils.http.UrlTemplateParameters
26 import reactor.core.publisher.Mono
27 import spock.lang.Specification
28
29 class DataJobStatusServiceImplSpec extends Specification {
30
31     def mockDmiRestClient = Mock(DmiRestClient)
32     def mockDmiProperties = Mock(DmiProperties)
33     def objectUnderTest = new DataJobStatusServiceImpl(mockDmiRestClient, mockDmiProperties)
34
35     def setup() {
36         mockDmiProperties.dmiBasePath >> 'dmi'
37     }
38
39     def 'Forward a data job status query to DMI.' () {
40         given: 'the required parameters for querying'
41             def dmiServiceName = 'some-dmi-service'
42             def dataProducerId = 'some-data-producer-id'
43             def dataProducerJobId = 'some-data-producer-job-id'
44             def authorization = 'my authorization header'
45             def urlParams = new UrlTemplateParameters('some-dmi-service/dmi/v1/cmwriteJob/dataProducer/{dataProducerId}/dataProducerJob/{dataProducerJobId}/status', ['dataProducerId':'some-data-producer-id', 'dataProducerJobId':'some-data-producer-job-id'])
46         and: 'the rest client returns a status for the given parameters'
47             mockDmiRestClient.getDataJobStatus(urlParams, authorization) >> Mono.just('some status')
48         when: 'the job status is queried'
49             def status = objectUnderTest.getDataJobStatus(authorization, dmiServiceName, dataProducerId, dataProducerJobId)
50         then: 'the status from the rest client is returned'
51             assert status == 'some status'
52     }
53 }