Return Registration response for updating cmhandles
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / models / CmHandleRegistrationResponseSpec.groovy
1 /*
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
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.api.models
22
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
26
27 class CmHandleRegistrationResponseSpec extends Specification {
28
29     def 'Successful CmHandle Registration Response'() {
30         when: 'CMHandle response is created'
31             def cmHandleRegistrationResponse = CmHandleRegistrationResponse.createSuccessResponse('cmHandle')
32         then: 'a success response is returned'
33             with(cmHandleRegistrationResponse) {
34                 assert it.cmHandle == 'cmHandle'
35                 assert it.status == Status.SUCCESS
36             }
37         and: 'error details are null'
38             cmHandleRegistrationResponse.registrationError == null
39             cmHandleRegistrationResponse.errorText == null
40     }
41
42     def 'Failed Cm Handle Registration Response: for unexpected exception'() {
43         when: 'CMHandle response is created for an unexpected exception'
44             def cmHandleRegistrationResponse =
45                 CmHandleRegistrationResponse.createFailureResponse('cmHandle', new RuntimeException('unexpected error'))
46         then: 'the response is created with expected value'
47             with(cmHandleRegistrationResponse) {
48                 assert it.registrationError == RegistrationError.UNKNOWN_ERROR
49                 assert it.cmHandle == 'cmHandle'
50                 assert errorText == 'unexpected error'
51             }
52     }
53
54     def 'Failed Cm Handle Registration Response: for known error'() {
55         when: 'CMHandle response is created for known error'
56             def cmHandleRegistrationResponse =
57                 CmHandleRegistrationResponse.createFailureResponse('cmHandle', RegistrationError.CM_HANDLE_ALREADY_EXIST)
58         then: 'the response is created with expected value'
59             with(cmHandleRegistrationResponse) {
60                 assert it.registrationError == RegistrationError.CM_HANDLE_ALREADY_EXIST
61                 assert it.cmHandle == 'cmHandle'
62                 assert it.status == Status.FAILURE
63                 assert errorText == RegistrationError.CM_HANDLE_ALREADY_EXIST.errorText
64             }
65
66     }
67
68 }