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