784717d9df9e1e38ad4e1170c640992d5fd347d1
[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.service.data.ServiceDataBuilder;
33
34
35 /**
36  * GenericResourceApiSvcLogicServiceClientMockUtil provides a set of util methods for quickly configuring method
37  * behaviour on the Mock GenericResourceApiSvcLogicServiceClient
38  */
39 public class GenericResourceApiSvcLogicServiceClientMockUtil {
40
41
42     private final String MODULE = "generic-resource-api";
43     private final String MODE = "sync";
44     private final String VERSION = null;
45     private String scvOperation = null;
46
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 networkId = "networkId";
54
55
56     private final GenericResourceApiSvcLogicServiceClient mockGenericResourceApiSvcLogicServiceClient;
57
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(networkId, "networkId: XYZ");
102
103     }
104
105
106     /**
107      * Configure {@link GenericResourceApiSvcLogicServiceClient#execute(String, String, String, String,
108      * ServiceDataBuilder, Properties)} to return the specified svcResultProp when when invoked with the parameters
109      * {@link #MODULE}, {@link #MODE}, {@link #VERSION} and {@link #scvOperation}
110      */
111     public void mockExecute(PropBuilder svcResultProp) throws Exception {
112         when(
113             mockGenericResourceApiSvcLogicServiceClient
114                 .execute(
115                     eq(MODULE),
116                     eq(scvOperation),
117                     eq(VERSION),
118                     eq(MODE),
119                     isA(ServiceDataBuilder.class),
120                     isA(Properties.class))
121         ).thenReturn(build(svcResultProp));
122     }
123
124     public void mockExecute(RuntimeException exception) throws Exception {
125         when(
126             mockGenericResourceApiSvcLogicServiceClient
127                 .execute(
128                     eq(MODULE),
129                     eq(scvOperation),
130                     eq(VERSION),
131                     eq(MODE),
132                     isA(ServiceDataBuilder.class),
133                     isA(Properties.class)
134                 )
135         ).thenThrow(exception);
136     }
137
138
139     public void mockExecuteWoServiceData(PropBuilder svcResultProp) throws Exception {
140         when(
141             mockGenericResourceApiSvcLogicServiceClient
142                 .execute(
143                     eq(MODULE),
144                     eq(scvOperation),
145                     eq(VERSION),
146                     eq(MODE),
147                     isA(Properties.class))
148         ).thenReturn(build(svcResultProp));
149     }
150
151     public void mockExecuteWoServiceData(RuntimeException exception) throws Exception {
152         when(
153             mockGenericResourceApiSvcLogicServiceClient
154                 .execute(
155                     eq(MODULE),
156                     eq(scvOperation),
157                     eq(VERSION),
158                     eq(MODE),
159                     isA(Properties.class)
160                 )
161         ).thenThrow(exception);
162     }
163
164
165 }