2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022 Bell Canada
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.models
23 import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.RegistrationError
24 import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.Status
25 import spock.lang.Specification
27 import java.util.stream.Collectors
29 class CmHandleRegistrationResponseSpec extends Specification {
31 def 'Successful cm-handle Registration Response'() {
32 when: 'cm-handle response is created'
33 def cmHandleRegistrationResponse = CmHandleRegistrationResponse.createSuccessResponse('cmHandle')
34 then: 'a success response is returned'
35 with(cmHandleRegistrationResponse) {
36 assert it.cmHandle == 'cmHandle'
37 assert it.status == Status.SUCCESS
39 and: 'error details are null'
40 cmHandleRegistrationResponse.registrationError == null
41 cmHandleRegistrationResponse.errorText == null
44 def 'Failed cm-handle Registration Response: for unexpected exception'() {
45 when: 'cm-handle response is created for an unexpected exception'
46 def cmHandleRegistrationResponse =
47 CmHandleRegistrationResponse.createFailureResponse('cmHandle', new Exception('unexpected error'))
48 then: 'the response is created with expected value'
49 with(cmHandleRegistrationResponse) {
50 assert it.registrationError == RegistrationError.UNKNOWN_ERROR
51 assert it.cmHandle == 'cmHandle'
52 assert errorText == 'unexpected error'
56 def 'Failed cm-handle Registration Response: for #scenario'() {
57 when: 'cm-handle failure response is created for #scenario'
58 def cmHandleRegistrationResponse =
59 CmHandleRegistrationResponse.createFailureResponse(cmHandleId, registrationError)
60 then: 'the response is created with expected value'
61 with(cmHandleRegistrationResponse) {
62 assert it.registrationError == registrationError
63 assert it.cmHandle == cmHandleId
64 assert it.status == Status.FAILURE
65 assert errorText == registrationError.errorText
68 scenario | cmHandleId | registrationError
69 'cm-handle already exists' | 'cmHandle' | RegistrationError.CM_HANDLE_ALREADY_EXIST
70 'cm-handle id is invalid' | 'cm handle' | RegistrationError.CM_HANDLE_INVALID_ID
73 def 'Failed cm-handle Registration with multiple responses.'() {
74 when: 'cm-handle failure response is created for 2 xpaths'
75 def cmHandleRegistrationResponses =
76 CmHandleRegistrationResponse.createFailureResponses(["somePathWithId[@id='123']","somePathWithId[@id='456']"], RegistrationError.CM_HANDLE_ALREADY_EXIST)
77 then: 'the response has the correct cm handle ids'
78 assert cmHandleRegistrationResponses.size() == 2
79 assert cmHandleRegistrationResponses.stream().map(it -> it.cmHandle).collect(Collectors.toList())
80 .containsAll(['123','456'])
83 def 'Failed cm-handle Registration with multiple responses with an unexpected xpath.'() {
84 when: 'cm-handle failure response is created for one valid and one unexpected xpath'
85 def cmHandleRegistrationResponses =
86 CmHandleRegistrationResponse.createFailureResponses(["somePathWithId[@id='123']","valid/xpath/without-id[@key='123']"], RegistrationError.CM_HANDLE_ALREADY_EXIST)
87 then: 'the response has only one entry'
88 assert cmHandleRegistrationResponses.size() == 1