75d5bfdcb6b5dd58e3b3d712d22d1fcc8c1f8b65
[aai/gizmo.git] / src / test / java / org / onap / crud / service / ChampDaoMockTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
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 package org.onap.crud.service;
22
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.when;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30 import javax.ws.rs.core.MediaType;
31 import javax.ws.rs.core.MultivaluedHashMap;
32 import javax.ws.rs.core.MultivaluedMap;
33 import org.onap.aai.logging.LoggingContext;
34 import org.onap.aai.restclient.client.OperationResult;
35 import org.onap.aai.restclient.client.RestClient;
36 import org.onap.crud.dao.champ.ChampDao;
37 import org.slf4j.MDC;
38
39 public class ChampDaoMockTest {
40     // @formatter:off
41         private final String champVertex = "{" +
42             "\"key\": \"test-uuid\"," +
43             "\"type\": \"vertexType\"," +
44             "\"properties\": {" +
45             "\"fqdn\": \"myhost.onap.com\"," +
46             "\"hostname\": \"myhost\" } }";
47         
48         private final String champEdge = "{" +
49             "\"key\": \"test-uuid\"," +
50             "\"type\": \"edgeType\"," +
51             "\"properties\": {" +
52             "\"prevent-delete\": \"NONE\" }," +
53             "\"source\": {" +
54             "\"key\": \"50bdab41-ad1c-4d00-952c-a0aa5d827811\", \"type\": \"vserver\"}," +
55             "\"target\": {" +
56             "\"key\": \"1d326bc7-b985-492b-9604-0d5d1f06f908\", \"type\": \"pserver\"}" +
57             " }";
58         
59         private final String edgePayload = "{" + 
60                 "\"type\":\"tosca.relationships.HostedOn\"," + 
61                 "\"properties\":{" + 
62                 "\"prevent-delete\":\"NONE\"}," + 
63                 "\"source\":{" + 
64                 "\"key\":\"test-uuid\"," + 
65                 "\"type\":\"vserver\"," + 
66                 "\"properties\":{}}," + 
67                 "\"target\":{" + 
68                 "\"key\":\"test-uuid\"," + 
69                 "\"type\":\"pserver\"," + 
70                 "\"properties\":{" + 
71                 "\"hostname\":\"myhost\"," + 
72                 "\"fqdn\":\"myhost.onap.com\"}}}";
73
74         private final String edgePayloadForPut = "{" + 
75                 "\"key\":\"test-uuid\"," + 
76                 "\"type\":\"tosca.relationships.HostedOn\"," + 
77                 "\"properties\":{" + 
78                 "\"prevent-delete\":\"NONE\"}," + 
79                 "\"source\":{" + 
80                 "\"key\":\"50bdab41-ad1c-4d00-952c-a0aa5d827811\"," + 
81                 "\"type\":\"vserver\"," + 
82                 "\"properties\":{}}," + 
83                 "\"target\":{" + 
84                 "\"key\":\"1d326bc7-b985-492b-9604-0d5d1f06f908\"," + 
85                 "\"type\":\"pserver\"," + 
86                 "\"properties\":{}}}";
87         
88         private final String edgePayloadForPatch = "{" + 
89                 "\"key\":\"test-uuid\"," + 
90                 "\"type\":\"tosca.relationships.HostedOn\"," + 
91                 "\"properties\":{" + 
92                 "\"prevent-delete\":\"NONE\"}," + 
93                 "\"source\":{" + 
94                 "\"key\":\"50bdab41-ad1c-4d00-952c-a0aa5d827811\"," + 
95                 "\"type\":\"vserver\"}," + 
96                 "\"target\":{" + 
97                 "\"key\":\"1d326bc7-b985-492b-9604-0d5d1f06f908\"," + 
98                 "\"type\":\"pserver\"}}";
99         
100         private final String edgePayloadForPost = "{" + 
101                 "\"type\":\"tosca.relationships.HostedOn\"," + 
102                 "\"properties\":{" + 
103                 "\"SVC-INFRA\":\"OUT\"," + 
104                 "\"prevent-delete\":\"IN\"," + 
105                 "\"delete-other-v\":\"NONE\"," + 
106                 "\"contains-other-v\":\"NONE\"" + 
107                 "}," + 
108                 "\"source\":{" + 
109                 "\"key\":\"test-uuid\"," + 
110                 "\"type\":\"vserver\"," + 
111                 "\"properties\":{" + 
112                 "" + 
113                 "}" + 
114                 "}," + 
115                 "\"target\":{" + 
116                 "\"key\":\"test-uuid\"," + 
117                 "\"type\":\"pserver\"," + 
118                 "\"properties\":{" + 
119                 "\"hostname\":\"myhost\"," + 
120                 "\"fqdn\":\"myhost.onap.com\"" + 
121                 "}" + 
122                 "}" + 
123                 "}";
124         
125         private final String edgePayloadForPutNoProperties = "{" + 
126                 "\"key\":\"test-uuid\"," + 
127                 "\"type\":\"tosca.relationships.HostedOn\"," + 
128                 "\"properties\":{" + 
129                 "\"SVC-INFRA\":\"OUT\"," + 
130                 "\"prevent-delete\":\"IN\"," + 
131                 "\"delete-other-v\":\"NONE\"," + 
132                 "\"contains-other-v\":\"NONE\"" + 
133                 "}," + 
134                 "\"source\":{" + 
135                 "\"key\":\"50bdab41-ad1c-4d00-952c-a0aa5d827811\"," + 
136                 "\"type\":\"vserver\"," + 
137                 "\"properties\":{" + 
138                 "" + 
139                 "}" + 
140                 "}," + 
141                 "\"target\":{" + 
142                 "\"key\":\"1d326bc7-b985-492b-9604-0d5d1f06f908\"," + 
143                 "\"type\":\"pserver\"," + 
144                 "\"properties\":{" + 
145                 "" + 
146                 "}" + 
147                 "}" + 
148                 "}";
149         
150         private final String vertexPayload = "{" + 
151                 "\"type\":\"pserver\"," + 
152                 "\"properties\":{" + 
153                 "\"hostname\":\"myhost\"," + 
154                 "\"in-maint\":false," + 
155                 "\"fqdn\":\"myhost.onap.com\"," + 
156                 "\"last-mod-source-of-truth\":\"source-of-truth\"," + 
157                 "\"source-of-truth\":\"source-of-truth\"," + 
158                 "\"aai-node-type\":\"pserver\"}}";
159         
160         private final String vertexPayloadForVserver = "{" + 
161                 "\"type\":\"vserver\"," + 
162                 "\"properties\":{" + 
163                 "\"in-maint\":false," + 
164                 "\"vserver-name\":\"test-vserver\"," + 
165                 "\"vserver-id\":\"VSER1\"," + 
166                 "\"last-mod-source-of-truth\":\"source-of-truth\"," + 
167                 "\"vserver-name2\":\"alt-test-vserver\"," + 
168                 "\"source-of-truth\":\"source-of-truth\"," + 
169                 "\"vserver-selflink\":\"http://1.2.3.4/moreInfo\"," + 
170                 "\"is-closed-loop-disabled\":false," + 
171                 "\"aai-node-type\":\"vserver\"}}";
172         
173         private final String vertexPayloadForPserver = "{" + 
174                 "\"key\":\"50bdab41-ad1c-4d00-952c-a0aa5d827811\"," + 
175                 "\"type\":\"pserver\"," + 
176                 "\"properties\":{" + 
177                 "\"ptnii-equip-name\":\"e-name\"," + 
178                 "\"hostname\":\"steve-host2\"," + 
179                 "\"equip-type\":\"server\"," + 
180                 "\"equip-vendor\":\"HP\"," + 
181                 "\"equip-model\":\"DL380p-nd\"," + 
182                 "\"in-maint\":false," + 
183                 "\"fqdn\":\"myhost.onap.net\"," + 
184                 "\"purpose\":\"my-purpose\"," + 
185                 "\"ipv4-oam-address\":\"1.2.3.4\"," + 
186                 "\"last-mod-source-of-truth\":\"source-of-truth\"," + 
187                 "\"aai-node-type\":\"pserver\"}}";
188         
189         private final String vertexPayloadForPut = "{" + 
190                 "\"key\":\"test-uuid\"," + 
191                 "\"type\":\"pserver\"," + 
192                 "\"properties\":{" + 
193                 "\"hostname\":\"myhost\"," + 
194                 "\"in-maint\":false," + 
195                 "\"fqdn\":\"myhost.onap.com\"," + 
196                 "\"last-mod-source-of-truth\":\"source-of-truth\"," + 
197                 "\"aai-node-type\":\"pserver\"}}";
198         
199         private final String vertexPayloadForPatch = "{" + 
200                 "\"key\":\"test-uuid\"," + 
201                 "\"type\":\"pserver\"," + 
202                 "\"properties\":{" + 
203                 "\"hostname\":\"myhost\"," + 
204                 "\"fqdn\":\"myhost.onap.com\"," + 
205                 "\"last-mod-source-of-truth\":\"source-of-truth\"," + 
206                 "\"aai-node-type\":\"pserver\"}}";
207         // @formatter:on
208
209     private RestClient restClientMock;
210     private ChampDao champDao;
211
212     static final String CHAMP_URL = "https://host:9522/services/champ-service/v1/";
213     static final String OBJECT_SUB_URL = "objects";
214     static final String RELATIONSHIP_SUB_URL = "relationships";
215     static final String TRANSACTION_SUB_URL = "transaction";
216     static final String BASE_OBJECT_URL = CHAMP_URL + OBJECT_SUB_URL;
217     static final String HEADER_FROM_APP = "X-FromAppId";
218     static final String HEADER_TRANS_ID = "X-TransactionId";
219     static final String FROM_APP_NAME = "Gizmo";
220     static final String HEADER_TRANS_ID_VALUE = "1234567890";
221
222     ChampDaoMockTest() {
223         restClientMock = mock(RestClient.class);
224         init();
225         buildChampDao();
226     }
227
228     public void init() {
229
230         Map<String, String> queryParamsVertex = new HashMap<>();
231         queryParamsVertex.put("_reserved_version", "v11");
232         queryParamsVertex.put("hostname", "myhost");
233         queryParamsVertex.put("_reserved_aai-type", "pserver");
234
235         Map<String, String> queryParamsVertexV13 = new HashMap<>();
236         queryParamsVertexV13.put("_reserved_version", "v13");
237         queryParamsVertexV13.put("hostname", "myhost");
238         queryParamsVertexV13.put("_reserved_aai-type", "pserver");
239
240         Map<String, String> queryParamsVertices = new HashMap<>();
241         queryParamsVertices.put("_reserved_version", "v11");
242         queryParamsVertices.put("hostname", "myhost");
243         queryParamsVertices.put("_reserved_aai-type", "pserver");
244         queryParamsVertices.put("aai-node-type", "pserver");
245
246         Map<String, String> queryParamsVerticesV13 = new HashMap<>();
247         queryParamsVerticesV13.put("_reserved_version", "v13");
248         queryParamsVerticesV13.put("hostname", "myhost");
249         queryParamsVerticesV13.put("_reserved_aai-type", "pserver");
250         queryParamsVerticesV13.put("aai-node-type", "pserver");
251
252         Map<String, String> queryParamsEdge = new HashMap<>();
253         queryParamsEdge.put("_reserved_version", "v11");
254         queryParamsEdge.put("hostname", "myhost");
255         queryParamsEdge.put("_reserved_aai-type", "tosca.relationships.HostedOn");
256
257         Map<String, String> emptyQueryParams = null;
258
259         mockOpenTransaction();
260         mockRollbackTransaction("");
261         mockTransactionExists("");
262         mockCommitTransaction("");
263         mockGetVertex("872dd5df-0be9-4167-95e9-2cf4b21165ed", queryParamsVertex, "pserver");
264         mockGetVertex("872dd5df-0be9-4167-95e9-2cf4b21165ed", queryParamsVertexV13, "pserver");
265         mockGetVertex("50bdab41-ad1c-4d00-952c-a0aa5d827811", "", "vserver");
266         mockGetVertex("1d326bc7-b985-492b-9604-0d5d1f06f908", "", "pserver");
267         mockGetVertex("1d326bc7-b985-492b-9604-0d5d1f06f908", "?transactionId=", "pserver");
268         mockGetVertex("test-uuid", "", "pserver");
269         mockGetVertex("50bdab41-ad1c-4d00-952c-a0aa5d827811", "?transactionId=", "vserver");
270         mockGetVertices(queryParamsVertices, "pserver");
271         mockGetVertices(queryParamsVerticesV13, "pserver");
272         mockGetVertexEdges("872dd5df-0be9-4167-95e9-2cf4b21165ed", queryParamsVertex, "tosca.relationships.HostedOn");
273         mockGetVertexEdges("872dd5df-0be9-4167-95e9-2cf4b21165ed", queryParamsVertexV13,
274                 "tosca.relationships.HostedOn");
275         mockGetVertexEdges("50bdab41-ad1c-4d00-952c-a0aa5d827811", emptyQueryParams, "tosca.relationships.HostedOn");
276         mockGetVertexEdges("1d326bc7-b985-492b-9604-0d5d1f06f908", emptyQueryParams, "tosca.relationships.HostedOn");
277         mockGetEdges("?", "tosca.relationships.HostedOn");
278         mockGetEdge("50bdab41-ad1c-4d00-952c-a0aa5d827811", "?transactionId=", "tosca.relationships.HostedOn");
279         mockGetEdge("872dd5df-0be9-4167-95e9-2cf4b21165ed", emptyQueryParams, "tosca.relationships.HostedOn");
280         mockGetEdge("872dd5df-0be9-4167-95e9-2cf4b21165ed", queryParamsEdge, "tosca.relationships.HostedOn");
281         mockGetEdge("my-uuid", emptyQueryParams, "tosca.relationships.HostedOn");
282         mockGetEdge("50bdab41-ad1c-4d00-952c-a0aa5d827811", queryParamsEdge, "tosca.relationships.HostedOn");
283         mockPostEdge("tosca.relationships.HostedOn", "", edgePayload);
284         mockPostEdge("tosca.relationships.HostedOn", "?transactionId=", edgePayloadForPost);
285         mockPostVertex("pserver", vertexPayload, "");
286         mockPostVertex("vserver", vertexPayloadForVserver, "?transactionId=");
287         mockPutVertex("test-uuid", "pserver", vertexPayloadForPut, "");
288         mockPutVertex("test-uuid", "pserver", vertexPayloadForPatch, "");
289         mockPutVertex("50bdab41-ad1c-4d00-952c-a0aa5d827811", "pserver", vertexPayloadForPserver, "?transactionId=");
290         mockPutEdge("test-uuid", "tosca.relationships.HostedOn", "", edgePayloadForPut);
291         mockPutEdge("test-uuid", "tosca.relationships.HostedOn", "", edgePayloadForPatch);
292         mockPutEdge("test-uuid", "tosca.relationships.HostedOn", "?transactionId=", edgePayloadForPutNoProperties);
293         mockDeleteVertex("872dd5df-0be9-4167-95e9-2cf4b21165ed", "pserver", "");
294         mockDeleteVertex("50bdab41-ad1c-4d00-952c-a0aa5d827811", "pserver", "?transactionId=");
295         mockDeleteEdge("872dd5df-0be9-4167-95e9-2cf4b21165ed", "tosca.relationships.HostedOn", "");
296         mockDeleteEdge("50bdab41-ad1c-4d00-952c-a0aa5d827811", "tosca.relationships.HostedOn", "?transactionId=");
297     }
298
299     public void buildChampDao() {
300         String baseRelationshipUrl = CHAMP_URL + RELATIONSHIP_SUB_URL;
301         String baseTransactionUrl = CHAMP_URL + TRANSACTION_SUB_URL;
302         champDao = new ChampDao(restClientMock, BASE_OBJECT_URL, baseRelationshipUrl, baseTransactionUrl);
303     }
304
305     public void mockOpenTransaction() {
306         OperationResult operationResult = new OperationResult();
307         operationResult.setResult("");
308         operationResult.setResultCode(200);
309         String url = CHAMP_URL + "transaction";
310
311
312         when(restClientMock.post(url, "", createHeaders(), MediaType.TEXT_PLAIN_TYPE, MediaType.TEXT_PLAIN_TYPE))
313                 .thenReturn(operationResult);
314     }
315
316     public void mockRollbackTransaction(String id) {
317         OperationResult operationResult = new OperationResult();
318         operationResult.setResult("");
319         operationResult.setResultCode(200);
320         String url = CHAMP_URL + TRANSACTION_SUB_URL + "/" + id;
321
322
323         when(restClientMock.put(url, "{\"method\": \"rollback\"}", createHeaders(), MediaType.APPLICATION_JSON_TYPE,
324                 MediaType.TEXT_PLAIN_TYPE)).thenReturn(operationResult);
325     }
326
327     public void mockCommitTransaction(String id) {
328         OperationResult operationResult = new OperationResult();
329         operationResult.setResult("");
330         operationResult.setResultCode(200);
331         String url = CHAMP_URL + TRANSACTION_SUB_URL + "/" + id;
332
333
334         when(restClientMock.put(url, "{\"method\": \"commit\"}", createHeaders(), MediaType.APPLICATION_JSON_TYPE,
335                 MediaType.TEXT_PLAIN_TYPE)).thenReturn(operationResult);
336     }
337
338     public void mockTransactionExists(String id) {
339         OperationResult operationResult = new OperationResult();
340         operationResult.setResult("");
341         operationResult.setResultCode(200);
342         String url = CHAMP_URL + TRANSACTION_SUB_URL + "/" + id;
343
344         Map<String, List<String>> headers = new HashMap<>();
345         headers.put(HEADER_FROM_APP, Arrays.asList(FROM_APP_NAME));
346         headers.put(HEADER_TRANS_ID, Arrays.asList(MDC.get(LoggingContext.LoggingField.REQUEST_ID.toString())));
347
348         when(restClientMock.get(url, headers, MediaType.APPLICATION_JSON_TYPE)).thenReturn(operationResult);
349     }
350
351     public void mockGetVertex(String id, String txId, String type) {
352         String vertexResponse = champVertex.replace("vertexType", type);
353         OperationResult operationResult = new OperationResult();
354         operationResult.setResult(vertexResponse);
355         operationResult.setResultCode(200);
356
357         String url = BASE_OBJECT_URL + "/" + id + txId;
358
359
360         when(restClientMock.get(url, createHeaders(), MediaType.APPLICATION_JSON_TYPE)).thenReturn(operationResult);
361     }
362
363     public void mockGetVertex(String id, Map<String, String> queryParams, String type) {
364         String vertexResponse = champVertex.replace("vertexType", type);
365         OperationResult operationResult = new OperationResult();
366         operationResult.setResult(vertexResponse);
367         operationResult.setResultCode(200);
368
369         StringBuilder url = appendQueryParams(BASE_OBJECT_URL + "/" + id, queryParams);
370
371         when(restClientMock.get(url.toString(), createHeaders(), MediaType.APPLICATION_JSON_TYPE))
372                 .thenReturn(operationResult);
373     }
374
375     public void mockGetVertexEdges(String id, Map<String, String> queryParams, String type) {
376         String edgeResponse = champEdge.replace("edgeType", type);
377         OperationResult operationResult = new OperationResult();
378         List<String> edgeResponselist = new ArrayList<>();
379         edgeResponselist.add(edgeResponse);
380         operationResult.setResult(edgeResponselist.toString());
381         operationResult.setResultCode(200);
382
383         StringBuilder url = appendQueryParams(BASE_OBJECT_URL + "/" + RELATIONSHIP_SUB_URL + "/" + id, queryParams);
384
385         when(restClientMock.get(url.toString(), createHeaders(), MediaType.APPLICATION_JSON_TYPE))
386                 .thenReturn(operationResult);
387     }
388
389     public void mockGetVertices(Map<String, String> queryParams, String type) {
390         String vertexResponse = champVertex.replace("vertexType", type);
391         OperationResult operationResult = new OperationResult();
392         List<String> vertexResponselist = new ArrayList<>();
393         vertexResponselist.add(vertexResponse);
394         operationResult.setResult(vertexResponselist.toString());
395         operationResult.setResultCode(200);
396
397         StringBuilder url = appendQueryParams(BASE_OBJECT_URL + "/" + "filter", queryParams);
398
399         when(restClientMock.get(url.toString(), createHeaders(), MediaType.APPLICATION_JSON_TYPE))
400                 .thenReturn(operationResult);
401     }
402
403     public void mockGetEdges(String queryParams, String type) {
404         String edgeResponse = champEdge.replace("edgeType", type);
405         OperationResult operationResult = new OperationResult();
406         List<String> edgeResponselist = new ArrayList<>();
407         edgeResponselist.add(edgeResponse);
408         operationResult.setResult(edgeResponselist.toString());
409         operationResult.setResultCode(200);
410
411         String url = CHAMP_URL + RELATIONSHIP_SUB_URL + "/" + "filter" + queryParams;
412
413
414         when(restClientMock.get(url, createHeaders(), MediaType.APPLICATION_JSON_TYPE)).thenReturn(operationResult);
415     }
416
417     public void mockGetEdge(String id, String txId, String type) {
418         String edgeResponse = champEdge.replace("edgeType", type);
419         OperationResult operationResult = new OperationResult();
420         operationResult.setResult(edgeResponse);
421         operationResult.setResultCode(200);
422
423         String url = CHAMP_URL + RELATIONSHIP_SUB_URL + "/" + id + txId;
424
425         when(restClientMock.get(url, createHeaders(), MediaType.APPLICATION_JSON_TYPE)).thenReturn(operationResult);
426     }
427
428     public void mockGetEdge(String id, Map<String, String> queryParams, String type) {
429         String edgeResponse = champEdge.replace("edgeType", type);
430         OperationResult operationResult = new OperationResult();
431         operationResult.setResult(edgeResponse);
432         operationResult.setResultCode(200);
433
434         StringBuilder url = appendQueryParams(CHAMP_URL + RELATIONSHIP_SUB_URL + "/" + id, queryParams);
435
436         when(restClientMock.get(url.toString(), createHeaders(), MediaType.APPLICATION_JSON_TYPE))
437                 .thenReturn(operationResult);
438     }
439
440     public void mockPostEdge(String type, String txId, String payload) {
441         String edgeResponse = champEdge.replace("edgeType", type);
442         OperationResult operationResult = new OperationResult();
443         operationResult.setResult(edgeResponse);
444         operationResult.setResultCode(201);
445         MultivaluedMap<String, String> headers = new MultivaluedHashMap<String, String>();
446         headers.add("etag", "test123");
447         operationResult.setHeaders(headers);
448
449         String baseRelationshipUrl = CHAMP_URL + RELATIONSHIP_SUB_URL + txId;
450         String url = baseRelationshipUrl;
451
452
453         when(restClientMock.post(url, payload, createHeaders(), MediaType.APPLICATION_JSON_TYPE,
454                 MediaType.APPLICATION_JSON_TYPE)).thenReturn(operationResult);
455     }
456
457     public void mockPostVertex(String type, String payload, String txId) {
458         String vertexResponse = champVertex.replace("vertexType", type);
459         OperationResult operationResult = new OperationResult();
460         operationResult.setResult(vertexResponse);
461         operationResult.setResultCode(201);
462         MultivaluedMap<String, String> headers = new MultivaluedHashMap<String, String>();
463         headers.add("etag", "test123");
464         operationResult.setHeaders(headers);
465
466         String url = BASE_OBJECT_URL + txId;
467
468
469         when(restClientMock.post(url, payload, createHeaders(), MediaType.APPLICATION_JSON_TYPE,
470                 MediaType.APPLICATION_JSON_TYPE)).thenReturn(operationResult);
471     }
472
473     public void mockPutVertex(String id, String type, String payload, String txId) {
474         String vertexResponse = champVertex.replace("vertexType", type);
475         OperationResult operationResult = new OperationResult();
476         operationResult.setResult(vertexResponse);
477         operationResult.setResultCode(200);
478         MultivaluedMap<String, String> headers = new MultivaluedHashMap<String, String>();
479         headers.add("etag", "test123");
480         operationResult.setHeaders(headers);
481
482         String url = BASE_OBJECT_URL + "/" + id + txId;
483
484
485         when(restClientMock.put(url, payload, createHeaders(), MediaType.APPLICATION_JSON_TYPE,
486                 MediaType.APPLICATION_JSON_TYPE)).thenReturn(operationResult);
487     }
488
489     public void mockPutEdge(String id, String type, String txId, String payload) {
490         String edgeResponse = champEdge.replace("edgeType", type);
491         OperationResult operationResult = new OperationResult();
492         operationResult.setResult(edgeResponse);
493         operationResult.setResultCode(200);
494         MultivaluedMap<String, String> headers = new MultivaluedHashMap<String, String>();
495         headers.add("etag", "test123");
496         operationResult.setHeaders(headers);
497
498         String url = CHAMP_URL + RELATIONSHIP_SUB_URL + "/" + id + txId;
499
500
501         when(restClientMock.put(url, payload, createHeaders(), MediaType.APPLICATION_JSON_TYPE,
502                 MediaType.APPLICATION_JSON_TYPE)).thenReturn(operationResult);
503     }
504
505     public void mockDeleteVertex(String id, String type, String txId) {
506         String vertexResponse = champVertex.replace("vertexType", type);
507         OperationResult operationResult = new OperationResult();
508         operationResult.setResult(vertexResponse);
509         operationResult.setResultCode(200);
510
511         String url = BASE_OBJECT_URL + "/" + id + txId;
512
513
514         when(restClientMock.delete(url, createHeaders(), MediaType.APPLICATION_JSON_TYPE)).thenReturn(operationResult);
515     }
516
517     public void mockDeleteEdge(String id, String type, String txId) {
518         String edgeResponse = champEdge.replace("edgeType", type);
519         OperationResult operationResult = new OperationResult();
520         operationResult.setResult(edgeResponse);
521         operationResult.setResultCode(200);
522
523         String url = CHAMP_URL + RELATIONSHIP_SUB_URL + "/" + id + txId;
524
525
526         when(restClientMock.delete(url, createHeaders(), MediaType.APPLICATION_JSON_TYPE)).thenReturn(operationResult);
527     }
528
529     private Map<String, List<String>> createHeaders() {
530         Map<String, List<String>> headers = new HashMap<>();
531         List<String> listFromApp = new ArrayList<>();
532         List<String> listTransId = new ArrayList<>();
533         listFromApp.add(FROM_APP_NAME);
534         listTransId.add(HEADER_TRANS_ID_VALUE);
535         headers.put(HEADER_FROM_APP, listFromApp);
536         headers.put(HEADER_TRANS_ID, listTransId);
537
538         return headers;
539     }
540
541     private StringBuilder appendQueryParams(String url, Map<String, String> queryParams) {
542         StringBuilder strBuilder = new StringBuilder(url);
543
544         if (queryParams != null) {
545             String prefix = "?";
546             for (Map.Entry<String, String> entry : queryParams.entrySet()) {
547                 strBuilder.append(prefix);
548                 prefix = "&";
549                 strBuilder.append(entry.getKey() + "=" + entry.getValue());
550             }
551         }
552         return strBuilder;
553     }
554
555     public ChampDao getChampDao() {
556         return champDao;
557     }
558
559     public void setChampDao(ChampDao champDao) {
560         this.champDao = champDao;
561     }
562 }