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
 
   9  *        http://www.apache.org/licenses/LICENSE-2.0
 
  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.
 
  17  *  SPDX-License-Identifier: Apache-2.0
 
  18  *  ============LICENSE_END=========================================================
 
  21 package org.onap.cps.ncmp.impl.datajobs
 
  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.dmi.UrlTemplateParameters
 
  26 import reactor.core.publisher.Mono
 
  27 import spock.lang.Specification
 
  29 class DataJobResultServiceImplSpec extends Specification {
 
  31     def mockDmiRestClient = Mock(DmiRestClient)
 
  32     def mockDmiProperties = Mock(DmiProperties)
 
  33     def objectUnderTest = new DataJobResultServiceImpl(mockDmiRestClient, mockDmiProperties)
 
  36         mockDmiProperties.dmiBasePath >> 'dmi'
 
  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'
 
  53             assert  result == 'some result'