650147fd4fbe935f5fe41de1ab7b3e5e01c6b09c
[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
60     public GenericResourceApiSvcLogicServiceClientMockUtil(GenericResourceApiSvcLogicServiceClient mockGenericResourceApiSvcLogicServiceClient) {
61         this.mockGenericResourceApiSvcLogicServiceClient = mockGenericResourceApiSvcLogicServiceClient;
62     }
63
64
65     /** @param scvOperation -  The scvOperation parameter to use on the {@link GenericResourceApiSvcLogicServiceClient} methods */
66     public void setScvOperation(String scvOperation) {
67         this.scvOperation = scvOperation;
68     }
69
70     /**
71      * Configure {@link GenericResourceApiSvcLogicServiceClient#hasGraph(String, String, String, String)}
72      * to return the specified value when when invoked with the parameters
73      * {@link #MODULE}, {@link #MODE}, {@link #VERSION} and {@link #scvOperation}
74      */
75     public void mockHasGraph(Boolean isHasGraph) throws Exception {
76         when(
77             mockGenericResourceApiSvcLogicServiceClient
78                 .hasGraph(
79                     eq(MODULE),
80                     eq(scvOperation),
81                     eq(VERSION),
82                     eq(MODE))
83         ).thenReturn(isHasGraph);
84     }
85
86
87     /**
88      * @return
89      * PropBuilder - A PropBuilder populated with the expected properties returned from
90      * {@link GenericResourceApiSvcLogicServiceClient#execute(String, String, String, String, ServiceDataBuilder, Properties)}
91      */
92     public PropBuilder createExecuteOKResult(){
93         return propBuilder()
94                 .set(errorCode,"200")
95                 .set(errorMessage,"OK")
96                 .set(ackFinal,"Y")
97                 .set(serviceObjectPath,"serviceObjectPath: XYZ")
98                 .set(networkObjectPath,"networkObjectPath: XYZ")
99                 .set(networkId,"networkId: XYZ");
100
101     }
102
103
104     /**
105      * Configure
106      * {@link GenericResourceApiSvcLogicServiceClient#execute(String, String, String, String, ServiceDataBuilder, Properties)}
107      * to return the specified svcResultProp when when invoked with the parameters
108      * {@link #MODULE}, {@link #MODE}, {@link #VERSION} and {@link #scvOperation}
109      */
110     public void mockExecute(PropBuilder svcResultProp) throws Exception{
111         when(
112             mockGenericResourceApiSvcLogicServiceClient
113                 .execute(
114                     eq(MODULE),
115                     eq(scvOperation),
116                     eq(VERSION),
117                     eq(MODE),
118                     isA(ServiceDataBuilder.class),
119                     isA(Properties.class))
120         ).thenReturn(build(svcResultProp));
121     }
122
123     public void mockExecute(RuntimeException exception) throws Exception{
124         when(
125             mockGenericResourceApiSvcLogicServiceClient
126                 .execute(
127                     eq(MODULE),
128                     eq(scvOperation),
129                     eq(VERSION),
130                     eq(MODE),
131                     isA(ServiceDataBuilder.class),
132                     isA(Properties.class)
133                 )
134         ).thenThrow(exception);
135     }
136
137 }