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.api.impl
23 import ch.qos.logback.classic.Level
24 import ch.qos.logback.classic.Logger
25 import ch.qos.logback.classic.spi.ILoggingEvent
26 import ch.qos.logback.core.read.ListAppender
27 import org.slf4j.LoggerFactory
28 import org.onap.cps.ncmp.api.models.datajob.DataJobReadRequest
29 import org.onap.cps.ncmp.api.models.datajob.DataJobWriteRequest
30 import org.onap.cps.ncmp.api.models.datajob.DataJobMetadata
31 import org.onap.cps.ncmp.api.models.datajob.ReadOperation
32 import org.onap.cps.ncmp.api.models.datajob.WriteOperation
33 import spock.lang.Specification
35 class DataJobServiceImplSpec extends Specification{
37 def objectUnderTest = new DataJobServiceImpl()
39 def logger = Spy(ListAppender<ILoggingEvent>)
46 ((Logger) LoggerFactory.getLogger(DataJobServiceImpl.class)).detachAndStopAllAppenders()
49 def '#operation data job request.'() {
50 given: 'data job metadata'
51 def dataJobMetadata = new DataJobMetadata('client-topic', 'application/vnd.3gpp.object-tree-hierarchical+json', 'application/3gpp-json-patch+json')
52 when: 'read/write data job request is processed'
53 if (operation == 'read') {
54 objectUnderTest.readDataJob('some-job-id', dataJobMetadata, new DataJobReadRequest([getWriteOrReadOperationRequest(operation)]))
56 objectUnderTest.writeDataJob('some-job-id', dataJobMetadata, new DataJobWriteRequest([getWriteOrReadOperationRequest(operation)]))
58 then: 'the data job id is correctly logged'
59 def loggingEvent = logger.list[0]
60 assert loggingEvent.level == Level.INFO
61 assert loggingEvent.formattedMessage.contains('data job id for ' + operation + ' operation is: some-job-id')
62 where: 'the following data job operations are used'
63 operation << ['read', 'write']
66 def getWriteOrReadOperationRequest(operation) {
67 if (operation == 'write') {
68 return new WriteOperation('some/write/path', 'add', 'some-operation-id', 'some-value')
70 return new ReadOperation('some/read/path', 'read', 'some-operation-id', ['some-attrib-1'], ['some-field-1'], 'some-filter', 'some-scope-type', 1)
74 def setupLogger = ((Logger) LoggerFactory.getLogger(DataJobServiceImpl.class))
75 setupLogger.setLevel(Level.DEBUG)
76 setupLogger.addAppender(logger)