74bd0484dfe21a6f530a5609cda5f753ef71768a
[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 DataJobResultServiceImplSpec extends Specification {
30
31     def mockDmiRestClient = Mock(DmiRestClient)
32     def mockDmiProperties = Mock(DmiProperties)
33     def objectUnderTest = new DataJobResultServiceImpl(mockDmiRestClient, mockDmiProperties)
34
35     def setup() {
36         mockDmiProperties.dmiBasePath >> 'dmi'
37     }
38
39     def 'Retrieve data job result.'() {
40         given: 'the required parameters for querying'
41             def dmiServiceName = 'some-dmi-service'
42             def dataProducerJobId = 'some-data-producer-job-id'
43             def dataProducerId = 'some-data-producer-id'
44             def authorization = 'my authorization header'
45             def destination = 'some-destination'
46             def urlParams = new UrlTemplateParameters('some-dmi-service/dmi/v1/cmwriteJob/dataProducer/{dataProducerId}/dataProducerJob/{dataProducerJobId}/result?destination={destination}', ['dataProducerJobId':'some-data-producer-job-id', 'dataProducerId':'some-data-producer-id', 'destination': 'some-destination'])
47         and: 'the rest client returns the result for the given parameters'
48             mockDmiRestClient.getDataJobResult(urlParams, authorization) >> Mono.just('some result')
49         when: 'the job status is queried'
50             def result = objectUnderTest.getDataJobResult(authorization, dmiServiceName,dataProducerId,  dataProducerJobId, destination)
51         then: 'the result from the rest client is returned'
52             assert result != null
53             assert  result == 'some result'
54     }
55 }