diff options
author | leventecsanyi <levente.csanyi@est.tech> | 2024-07-25 16:53:08 +0200 |
---|---|---|
committer | leventecsanyi <levente.csanyi@est.tech> | 2024-07-26 10:39:13 +0200 |
commit | 58a5a6fc361bec017d967b6b0f431a340a4581e3 (patch) | |
tree | 3dab67543a8c713348847a094eb1c94f256a8bc8 /cps-ncmp-service | |
parent | dc56d427e0c1f3161d752bd6078b31529c5469d8 (diff) |
Added missing authorization header to DataJobService
- added auth header to the interface & updated testware
Issue-ID: CPS-2330
Change-Id: I091fc5c3c3fa323024f55055129cc7240732479a
Signed-off-by: leventecsanyi <levente.csanyi@est.tech>
Diffstat (limited to 'cps-ncmp-service')
5 files changed, 35 insertions, 18 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/DataJobService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/DataJobService.java index 6ff79a9344..255b3847eb 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/DataJobService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/DataJobService.java @@ -31,20 +31,27 @@ public interface DataJobService { /** * process read data job operations. * - * @param dataJobId Unique identifier of the job within the request + * @param authorization the authorization header from the REST request + * @param dataJobId unique identifier of the job within the request * @param dataJobMetadata data job request headers * @param dataJobReadRequest read data job request */ - void readDataJob(String dataJobId, DataJobMetadata dataJobMetadata, DataJobReadRequest dataJobReadRequest); + void readDataJob(String authorization, + String dataJobId, + DataJobMetadata dataJobMetadata, + DataJobReadRequest dataJobReadRequest); /** * process write data job operations. * - * @param dataJobId Unique identifier of the job within the request + * @param authorization the authorization header from the REST request + * @param dataJobId unique identifier of the job within the request * @param dataJobMetadata data job request headers * @param dataJobWriteRequest write data job request * @return a list of sub-job write responses */ - List<SubJobWriteResponse> writeDataJob(String dataJobId, DataJobMetadata dataJobMetadata, + List<SubJobWriteResponse> writeDataJob(String authorization, + String dataJobId, + DataJobMetadata dataJobMetadata, DataJobWriteRequest dataJobWriteRequest); }
\ No newline at end of file diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImpl.java index 56ed6e30da..04c3ad2fc6 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImpl.java @@ -42,19 +42,26 @@ public class DataJobServiceImpl implements DataJobService { private final WriteRequestExaminer writeRequestExaminer; @Override - public void readDataJob(final String dataJobId, final DataJobMetadata dataJobMetadata, + public void readDataJob(final String authorization, + final String dataJobId, + final DataJobMetadata dataJobMetadata, final DataJobReadRequest dataJobReadRequest) { log.info("data job id for read operation is: {}", dataJobId); } @Override - public List<SubJobWriteResponse> writeDataJob(final String dataJobId, final DataJobMetadata dataJobMetadata, + public List<SubJobWriteResponse> writeDataJob(final String authorization, + final String dataJobId, + final DataJobMetadata dataJobMetadata, final DataJobWriteRequest dataJobWriteRequest) { log.info("data job id for write operation is: {}", dataJobId); final Map<ProducerKey, List<DmiWriteOperation>> dmiWriteOperationsPerProducerKey = writeRequestExaminer.splitDmiWriteOperationsFromRequest(dataJobId, dataJobWriteRequest); - return dmiSubJobClient.sendRequestsToDmi(dataJobId, dataJobMetadata, dmiWriteOperationsPerProducerKey); + return dmiSubJobClient.sendRequestsToDmi(authorization, + dataJobId, + dataJobMetadata, + dmiWriteOperationsPerProducerKey); } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandler.java index 1624ce8ae6..c93709ce75 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandler.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandler.java @@ -48,17 +48,19 @@ public class DmiSubJobRequestHandler { private final DmiRestClient dmiRestClient; private final DmiProperties dmiProperties; private final JsonObjectMapper jsonObjectMapper; - static final String NO_AUTH_HEADER = null; /** * Sends sub-job write requests to the DMI Plugin. * - * @param dataJobId data ojb identifier + * @param authorization the authorization header from the REST request + * @param dataJobId data job identifier * @param dataJobMetadata the data job's metadata - * @param dmiWriteOperationsPerProducerKey a collection of write requests per producer key. + * @param dmiWriteOperationsPerProducerKey a collection of write requests per producer key * @return a list of sub-job write responses */ - public List<SubJobWriteResponse> sendRequestsToDmi(final String dataJobId, final DataJobMetadata dataJobMetadata, + public List<SubJobWriteResponse> sendRequestsToDmi(final String authorization, + final String dataJobId, + final DataJobMetadata dataJobMetadata, final Map<ProducerKey, List<DmiWriteOperation>> dmiWriteOperationsPerProducerKey) { final List<SubJobWriteResponse> subJobWriteResponses = new ArrayList<>(dmiWriteOperationsPerProducerKey.size()); dmiWriteOperationsPerProducerKey.forEach((producerKey, dmi3ggpWriteOperations) -> { @@ -71,7 +73,7 @@ public class DmiSubJobRequestHandler { urlTemplateParameters, jsonObjectMapper.asJsonString(subJobWriteRequest), OperationType.CREATE, - NO_AUTH_HEADER); + authorization); final SubJobWriteResponse subJobWriteResponse = jsonObjectMapper .convertToValueType(responseEntity.getBody(), SubJobWriteResponse.class); log.debug("Sub job write response: {}", subJobWriteResponse); diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImplSpec.groovy index 94c490ab07..4b536b9710 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImplSpec.groovy @@ -40,6 +40,7 @@ class DataJobServiceImplSpec extends Specification { def objectUnderTest = new DataJobServiceImpl(mockDmiSubJobRequestHandler, mockWriteRequestExaminer) def myDataJobMetadata = new DataJobMetadata('', '', '') + def authorization = 'my authorization header' def logger = Spy(ListAppender<ILoggingEvent>) @@ -54,7 +55,7 @@ class DataJobServiceImplSpec extends Specification { def 'Read data job request.'() { when: 'read data job request is processed' def readOperation = new ReadOperation('', '', '', [], [], '', '', 1) - objectUnderTest.readDataJob('my-job-id', myDataJobMetadata, new DataJobReadRequest([readOperation])) + objectUnderTest.readDataJob(authorization, 'my-job-id', myDataJobMetadata, new DataJobReadRequest([readOperation])) then: 'the data job id is correctly logged' def loggingEvent = logger.list[0] assert loggingEvent.level == Level.INFO @@ -67,11 +68,11 @@ class DataJobServiceImplSpec extends Specification { and: 'a map of producer key and dmi 3gpp write operation' def dmiWriteOperationsPerProducerKey = [:] when: 'write data job request is processed' - objectUnderTest.writeDataJob('my-job-id', myDataJobMetadata, dataJobWriteRequest) + objectUnderTest.writeDataJob(authorization, 'my-job-id', myDataJobMetadata, dataJobWriteRequest) then: 'the examiner service is called and a map is returned' 1 * mockWriteRequestExaminer.splitDmiWriteOperationsFromRequest('my-job-id', dataJobWriteRequest) >> dmiWriteOperationsPerProducerKey and: 'the dmi request handler is called with the result from the examiner' - 1 * mockDmiSubJobRequestHandler.sendRequestsToDmi('my-job-id', myDataJobMetadata, dmiWriteOperationsPerProducerKey) + 1 * mockDmiSubJobRequestHandler.sendRequestsToDmi(authorization, 'my-job-id', myDataJobMetadata, dmiWriteOperationsPerProducerKey) } def setupLogger() { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandlerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandlerSpec.groovy index 7005cc6b18..b3dd02dec3 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandlerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandlerSpec.groovy @@ -19,7 +19,6 @@ class DmiSubJobRequestHandlerSpec extends Specification { def mockDmiRestClient = Mock(DmiRestClient) def jsonObjectMapper = new JsonObjectMapper(new ObjectMapper()) def mockDmiProperties = Mock(DmiProperties) - def static NO_AUTH = null def objectUnderTest = new DmiSubJobRequestHandler(mockDmiRestClient, mockDmiProperties, jsonObjectMapper) def 'Send a sub-job request to the DMI Plugin.'() { @@ -28,12 +27,13 @@ class DmiSubJobRequestHandlerSpec extends Specification { def dataJobMetadata = new DataJobMetadata('d1', 't1', 't2') def dmiWriteOperation = new DmiWriteOperation('p', 'operation', 'tag', null, 'o1', [:]) def dmiWriteOperationsPerProducerKey = [new ProducerKey('dmi1', 'prod1'): [dmiWriteOperation]] + def authorization = 'my authorization header' and: 'the dmi rest client will return a response (for the correct parameters)' def responseEntity = new ResponseEntity<>(new SubJobWriteResponse('my-sub-job-id', 'dmi1', 'prod1'), HttpStatus.OK) def expectedJson = '{"dataAcceptType":"t1","dataContentType":"t2","dataProducerId":"prod1","data":[{"path":"p","op":"operation","moduleSetTag":"tag","value":null,"operationId":"o1","privateProperties":{}}]}' - mockDmiRestClient.synchronousPostOperationWithJsonData(RequiredDmiService.DATA, _, expectedJson, OperationType.CREATE, NO_AUTH) >> responseEntity + mockDmiRestClient.synchronousPostOperationWithJsonData(RequiredDmiService.DATA, _, expectedJson, OperationType.CREATE, authorization) >> responseEntity when: 'sending request to DMI invoked' - objectUnderTest.sendRequestsToDmi(dataJobId, dataJobMetadata, dmiWriteOperationsPerProducerKey) + objectUnderTest.sendRequestsToDmi(authorization, dataJobId, dataJobMetadata, dmiWriteOperationsPerProducerKey) then: 'the result contains the expected sub-job id' assert responseEntity.body.subJobId == 'my-sub-job-id' } |