Generic resource API catch up
[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 vnfObjectPath = "vnf-object-path";
54     public final String vfModuleObjectPath = "vf-module-object-path";
55     public final String networkId = "networkId";
56
57     private final GenericResourceApiSvcLogicServiceClient mockGenericResourceApiSvcLogicServiceClient;
58
59     public GenericResourceApiSvcLogicServiceClientMockUtil(
60         GenericResourceApiSvcLogicServiceClient mockGenericResourceApiSvcLogicServiceClient) {
61         this.mockGenericResourceApiSvcLogicServiceClient = mockGenericResourceApiSvcLogicServiceClient;
62     }
63
64
65     /**
66      * @param scvOperation -  The scvOperation parameter to use on the {@link GenericResourceApiSvcLogicServiceClient}
67      * methods
68      */
69     public void setScvOperation(String scvOperation) {
70         this.scvOperation = scvOperation;
71     }
72
73     /**
74      * Configure {@link GenericResourceApiSvcLogicServiceClient#hasGraph(String, String, String, String)} to return the
75      * specified value when when invoked with the parameters {@link #MODULE}, {@link #MODE}, {@link #VERSION} and {@link
76      * #scvOperation}
77      */
78     public void mockHasGraph(Boolean isHasGraph) throws Exception {
79         when(
80             mockGenericResourceApiSvcLogicServiceClient
81                 .hasGraph(
82                     eq(MODULE),
83                     eq(scvOperation),
84                     eq(VERSION),
85                     eq(MODE))
86         ).thenReturn(isHasGraph);
87     }
88
89
90     /**
91      * @return PropBuilder - A PropBuilder populated with the expected properties returned from {@link
92      * GenericResourceApiSvcLogicServiceClient#execute(String, String, String, String, ServiceDataBuilder, Properties)}
93      */
94     public PropBuilder createExecuteOKResult() {
95         return propBuilder()
96             .set(errorCode, "200")
97             .set(errorMessage, "OK")
98             .set(ackFinal, "Y")
99             .set(serviceObjectPath, "serviceObjectPath: XYZ")
100             .set(networkObjectPath, "networkObjectPath: XYZ")
101             .set(vnfObjectPath,  "vnfObjectPath: XYZ")
102             .set(vfModuleObjectPath,  "vfModuleObjectPath: XYZ")
103             .set(networkId, "networkId: XYZ");
104     }
105
106
107     /**
108      * Configure {@link GenericResourceApiSvcLogicServiceClient#execute(String, String, String, String,
109      * ServiceDataBuilder, Properties)} to return the specified svcResultProp when when invoked with the parameters
110      * {@link #MODULE}, {@link #MODE}, {@link #VERSION} and {@link #scvOperation}
111      */
112     public void mockExecute(PropBuilder svcResultProp) throws Exception {
113         when(
114             mockGenericResourceApiSvcLogicServiceClient
115                 .execute(
116                     eq(MODULE),
117                     eq(scvOperation),
118                     eq(VERSION),
119                     eq(MODE),
120                     isA(ServiceDataBuilder.class),
121                     isA(Properties.class))
122         ).thenReturn(build(svcResultProp));
123     }
124
125     public void mockExecute(RuntimeException exception) throws Exception {
126         when(
127             mockGenericResourceApiSvcLogicServiceClient
128                 .execute(
129                     eq(MODULE),
130                     eq(scvOperation),
131                     eq(VERSION),
132                     eq(MODE),
133                     isA(ServiceDataBuilder.class),
134                     isA(Properties.class)
135                 )
136         ).thenThrow(exception);
137     }
138
139
140     public void mockExecuteWoServiceData(PropBuilder svcResultProp) throws Exception {
141         when(
142             mockGenericResourceApiSvcLogicServiceClient
143                 .execute(
144                     eq(MODULE),
145                     eq(scvOperation),
146                     eq(VERSION),
147                     eq(MODE),
148                     isA(Properties.class))
149         ).thenReturn(build(svcResultProp));
150     }
151
152     public void mockExecuteWoServiceData(RuntimeException exception) throws Exception {
153         when(
154             mockGenericResourceApiSvcLogicServiceClient
155                 .execute(
156                     eq(MODULE),
157                     eq(scvOperation),
158                     eq(VERSION),
159                     eq(MODE),
160                     isA(Properties.class)
161                 )
162         ).thenThrow(exception);
163     }
164
165     public void mockExecuteWoServiceDataPreload(RuntimeException exception) throws Exception {
166         when(
167             mockGenericResourceApiSvcLogicServiceClient
168                 .execute(
169                     eq(MODULE),
170                     eq(scvOperation),
171                     eq(VERSION),
172                     eq(MODE),
173                     isA(PreloadDataBuilder.class),
174                     isA(Properties.class)
175                 )
176         ).thenThrow(exception);
177     }
178
179
180 }