Dublin yang model update
[sdnc/northbound.git] / generic-resource-api / provider / src / test / java / org / onap / sdnc / northbound / util / GenericResourceApiSvcLogicServiceClientMockUtil.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.sdnc.northbound.util;
23
24 import static org.mockito.Mockito.eq;
25 import static org.mockito.Mockito.isA;
26 import static org.mockito.Mockito.when;
27 import static org.onap.sdnc.northbound.util.MDSALUtil.build;
28 import static org.onap.sdnc.northbound.util.PropBuilder.propBuilder;
29
30 import java.util.Properties;
31 import org.onap.sdnc.northbound.GenericResourceApiSvcLogicServiceClient;
32 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.preload.data.PreloadDataBuilder;
33 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.data.ServiceDataBuilder;
34
35
36 /**
37  * GenericResourceApiSvcLogicServiceClientMockUtil provides a set of util methods for quickly configuring method
38  * behaviour on the Mock GenericResourceApiSvcLogicServiceClient
39  */
40 public class GenericResourceApiSvcLogicServiceClientMockUtil {
41
42
43     private final String MODULE = "generic-resource-api";
44     private final String MODE = "sync";
45     private final String VERSION = null;
46     private String scvOperation = null;
47
48     public final String errorCode = "error-code";
49     public final String errorMessage = "error-message";
50     public final String ackFinal = "ack-final";
51     public final String serviceObjectPath = "service-object-path";
52     public final String networkObjectPath = "network-object-path";
53     public final String pnfObjectPath = "pnf-object-path";
54     public final String vnfObjectPath = "vnf-object-path";
55     public final String vfModuleObjectPath = "vf-module-object-path";
56     public final String networkId = "networkId";
57
58     private final GenericResourceApiSvcLogicServiceClient mockGenericResourceApiSvcLogicServiceClient;
59
60     public GenericResourceApiSvcLogicServiceClientMockUtil(
61         GenericResourceApiSvcLogicServiceClient mockGenericResourceApiSvcLogicServiceClient) {
62         this.mockGenericResourceApiSvcLogicServiceClient = mockGenericResourceApiSvcLogicServiceClient;
63     }
64
65
66     /**
67      * @param scvOperation -  The scvOperation parameter to use on the {@link GenericResourceApiSvcLogicServiceClient}
68      * methods
69      */
70     public void setScvOperation(String scvOperation) {
71         this.scvOperation = scvOperation;
72     }
73
74     /**
75      * Configure {@link GenericResourceApiSvcLogicServiceClient#hasGraph(String, String, String, String)} to return the
76      * specified value when when invoked with the parameters {@link #MODULE}, {@link #MODE}, {@link #VERSION} and {@link
77      * #scvOperation}
78      */
79     public void mockHasGraph(Boolean isHasGraph) throws Exception {
80         when(
81             mockGenericResourceApiSvcLogicServiceClient
82                 .hasGraph(
83                     eq(MODULE),
84                     eq(scvOperation),
85                     eq(VERSION),
86                     eq(MODE))
87         ).thenReturn(isHasGraph);
88     }
89
90
91     /**
92      * @return PropBuilder - A PropBuilder populated with the expected properties returned from {@link
93      * GenericResourceApiSvcLogicServiceClient#execute(String, String, String, String, ServiceDataBuilder, Properties)}
94      */
95     public PropBuilder createExecuteOKResult() {
96         return propBuilder()
97             .set(errorCode, "200")
98             .set(errorMessage, "OK")
99             .set(ackFinal, "Y")
100             .set(serviceObjectPath, "serviceObjectPath: XYZ")
101             .set(networkObjectPath, "networkObjectPath: XYZ")
102             .set(pnfObjectPath,  "pnfObjectPath: XYZ")
103             .set(vnfObjectPath,  "vnfObjectPath: XYZ")
104             .set(vfModuleObjectPath,  "vfModuleObjectPath: XYZ")
105             .set(networkId, "networkId: XYZ");
106     }
107
108
109     /**
110      * Configure {@link GenericResourceApiSvcLogicServiceClient#execute(String, String, String, String,
111      * ServiceDataBuilder, Properties)} to return the specified svcResultProp when when invoked with the parameters
112      * {@link #MODULE}, {@link #MODE}, {@link #VERSION} and {@link #scvOperation}
113      */
114     public void mockExecute(PropBuilder svcResultProp) throws Exception {
115         when(
116             mockGenericResourceApiSvcLogicServiceClient
117                 .execute(
118                     eq(MODULE),
119                     eq(scvOperation),
120                     eq(VERSION),
121                     eq(MODE),
122                     isA(ServiceDataBuilder.class),
123                     isA(Properties.class))
124         ).thenReturn(build(svcResultProp));
125     }
126
127     public void mockExecute(RuntimeException exception) throws Exception {
128         when(
129             mockGenericResourceApiSvcLogicServiceClient
130                 .execute(
131                     eq(MODULE),
132                     eq(scvOperation),
133                     eq(VERSION),
134                     eq(MODE),
135                     isA(ServiceDataBuilder.class),
136                     isA(Properties.class)
137                 )
138         ).thenThrow(exception);
139     }
140
141
142     public void mockExecuteWoServiceData(PropBuilder svcResultProp) throws Exception {
143         when(
144             mockGenericResourceApiSvcLogicServiceClient
145                 .execute(
146                     eq(MODULE),
147                     eq(scvOperation),
148                     eq(VERSION),
149                     eq(MODE),
150                     isA(Properties.class))
151         ).thenReturn(build(svcResultProp));
152     }
153
154     public void mockExecuteWoServiceData(RuntimeException exception) throws Exception {
155         when(
156             mockGenericResourceApiSvcLogicServiceClient
157                 .execute(
158                     eq(MODULE),
159                     eq(scvOperation),
160                     eq(VERSION),
161                     eq(MODE),
162                     isA(Properties.class)
163                 )
164         ).thenThrow(exception);
165     }
166
167     public void mockExecuteWoServiceDataPreload(RuntimeException exception) throws Exception {
168         when(
169             mockGenericResourceApiSvcLogicServiceClient
170                 .execute(
171                     eq(MODULE),
172                     eq(scvOperation),
173                     eq(VERSION),
174                     eq(MODE),
175                     isA(PreloadDataBuilder.class),
176                     isA(Properties.class)
177                 )
178         ).thenThrow(exception);
179     }
180
181
182 }