2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.sdnc.northbound.util;
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.PropBuilder.propBuilder;
29 import java.util.Properties;
30 import org.onap.sdnc.northbound.GenericResourceApiSvcLogicServiceClient;
31 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.preload.data.PreloadDataBuilder;
32 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.data.ServiceDataBuilder;
36 * GenericResourceApiSvcLogicServiceClientMockUtil provides a set of util methods for quickly configuring method
37 * behaviour on the Mock GenericResourceApiSvcLogicServiceClient
39 public class GenericResourceApiSvcLogicServiceClientMockUtil {
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;
47 public final String errorCode = "error-code";
48 public final String errorMessage = "error-message";
49 public final String ackFinal = "ack-final";
50 public final String serviceObjectPath = "service-object-path";
51 public final String networkObjectPath = "network-object-path";
52 public final String pnfObjectPath = "pnf-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";
57 private final GenericResourceApiSvcLogicServiceClient mockGenericResourceApiSvcLogicServiceClient;
59 public GenericResourceApiSvcLogicServiceClientMockUtil(
60 GenericResourceApiSvcLogicServiceClient mockGenericResourceApiSvcLogicServiceClient) {
61 this.mockGenericResourceApiSvcLogicServiceClient = mockGenericResourceApiSvcLogicServiceClient;
66 * @param scvOperation - The scvOperation parameter to use on the {@link GenericResourceApiSvcLogicServiceClient}
69 public void setScvOperation(String scvOperation) {
70 this.scvOperation = scvOperation;
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
78 public void mockHasGraph(Boolean isHasGraph) throws Exception {
80 mockGenericResourceApiSvcLogicServiceClient
86 ).thenReturn(isHasGraph);
91 * @return PropBuilder - A PropBuilder populated with the expected properties returned from {@link
92 * GenericResourceApiSvcLogicServiceClient#execute(String, String, String, String, ServiceDataBuilder, Properties)}
94 public PropBuilder createExecuteOKResult() {
96 .set(errorCode, "200")
97 .set(errorMessage, "OK")
99 .set(serviceObjectPath, "serviceObjectPath: XYZ")
100 .set(networkObjectPath, "networkObjectPath: XYZ")
101 .set(pnfObjectPath, "pnfObjectPath: XYZ")
102 .set(vnfObjectPath, "vnfObjectPath: XYZ")
103 .set(vfModuleObjectPath, "vfModuleObjectPath: XYZ")
104 .set(networkId, "networkId: XYZ");
109 * Configure {@link GenericResourceApiSvcLogicServiceClient#execute(String, String, String, String,
110 * ServiceDataBuilder, Properties)} to return the specified svcResultProp when when invoked with the parameters
111 * {@link #MODULE}, {@link #MODE}, {@link #VERSION} and {@link #scvOperation}
113 public void mockExecute(PropBuilder svcResultProp) throws Exception {
115 mockGenericResourceApiSvcLogicServiceClient
121 isA(ServiceDataBuilder.class),
122 isA(Properties.class))
123 ).thenReturn(svcResultProp.build());
126 public void mockExecute(RuntimeException exception) throws Exception {
128 mockGenericResourceApiSvcLogicServiceClient
134 isA(ServiceDataBuilder.class),
135 isA(Properties.class)
137 ).thenThrow(exception);
141 public void mockExecuteWoServiceData(PropBuilder svcResultProp) throws Exception {
143 mockGenericResourceApiSvcLogicServiceClient
149 isA(Properties.class))
150 ).thenReturn(svcResultProp.build());
153 public void mockExecuteWoServiceData(RuntimeException exception) throws Exception {
155 mockGenericResourceApiSvcLogicServiceClient
161 isA(Properties.class)
163 ).thenThrow(exception);
166 public void mockExecuteWoServiceDataPreload(RuntimeException exception) throws Exception {
168 mockGenericResourceApiSvcLogicServiceClient
174 isA(PreloadDataBuilder.class),
175 isA(Properties.class)
177 ).thenThrow(exception);