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.MDSALUtil.build;
28 import static org.onap.sdnc.northbound.util.PropBuilder.propBuilder;
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;
37 * GenericResourceApiSvcLogicServiceClientMockUtil provides a set of util methods for quickly configuring method
38 * behaviour on the Mock GenericResourceApiSvcLogicServiceClient
40 public class GenericResourceApiSvcLogicServiceClientMockUtil {
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;
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";
58 private final GenericResourceApiSvcLogicServiceClient mockGenericResourceApiSvcLogicServiceClient;
60 public GenericResourceApiSvcLogicServiceClientMockUtil(
61 GenericResourceApiSvcLogicServiceClient mockGenericResourceApiSvcLogicServiceClient) {
62 this.mockGenericResourceApiSvcLogicServiceClient = mockGenericResourceApiSvcLogicServiceClient;
67 * @param scvOperation - The scvOperation parameter to use on the {@link GenericResourceApiSvcLogicServiceClient}
70 public void setScvOperation(String scvOperation) {
71 this.scvOperation = scvOperation;
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
79 public void mockHasGraph(Boolean isHasGraph) throws Exception {
81 mockGenericResourceApiSvcLogicServiceClient
87 ).thenReturn(isHasGraph);
92 * @return PropBuilder - A PropBuilder populated with the expected properties returned from {@link
93 * GenericResourceApiSvcLogicServiceClient#execute(String, String, String, String, ServiceDataBuilder, Properties)}
95 public PropBuilder createExecuteOKResult() {
97 .set(errorCode, "200")
98 .set(errorMessage, "OK")
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");
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}
114 public void mockExecute(PropBuilder svcResultProp) throws Exception {
116 mockGenericResourceApiSvcLogicServiceClient
122 isA(ServiceDataBuilder.class),
123 isA(Properties.class))
124 ).thenReturn(build(svcResultProp));
127 public void mockExecute(RuntimeException exception) throws Exception {
129 mockGenericResourceApiSvcLogicServiceClient
135 isA(ServiceDataBuilder.class),
136 isA(Properties.class)
138 ).thenThrow(exception);
142 public void mockExecuteWoServiceData(PropBuilder svcResultProp) throws Exception {
144 mockGenericResourceApiSvcLogicServiceClient
150 isA(Properties.class))
151 ).thenReturn(build(svcResultProp));
154 public void mockExecuteWoServiceData(RuntimeException exception) throws Exception {
156 mockGenericResourceApiSvcLogicServiceClient
162 isA(Properties.class)
164 ).thenThrow(exception);
167 public void mockExecuteWoServiceDataPreload(RuntimeException exception) throws Exception {
169 mockGenericResourceApiSvcLogicServiceClient
175 isA(PreloadDataBuilder.class),
176 isA(Properties.class)
178 ).thenThrow(exception);