2 * ============LICENSE_START=======================================================
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
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=========================================================
21 package org.onap.crud.service;
23 import static org.hamcrest.CoreMatchers.containsString;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertThat;
26 import static org.mockito.Matchers.anyString;
27 import static org.mockito.Matchers.eq;
28 import static org.mockito.Mockito.mock;
29 import static org.mockito.Mockito.when;
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.HashMap;
33 import java.util.List;
35 import javax.ws.rs.core.MediaType;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.onap.aai.cl.mdc.MdcContext;
39 import org.onap.aai.restclient.client.OperationResult;
40 import org.onap.aai.restclient.client.RestClient;
41 import org.onap.crud.dao.champ.ChampDao;
42 import org.onap.crud.entity.Edge;
43 import org.onap.crud.entity.Vertex;
44 import org.onap.crud.exception.CrudException;
46 import org.junit.runner.RunWith;
47 import org.mockito.junit.MockitoJUnitRunner;
48 import org.onap.crud.OXMModelLoaderSetup;
50 @RunWith(MockitoJUnitRunner.Silent.class)
51 public class ChampDaoExceptionsTest extends OXMModelLoaderSetup {
53 private final String champVertex = "{" +
54 "\"key\": \"test-uuid\"," +
55 "\"type\": \"vertexType\"," +
57 "\"fqdn\": \"myhost.onap.com\"," +
58 "\"hostname\": \"myhost\" } }";
60 private final String champEdge = "{" +
61 "\"key\": \"test-uuid\"," +
62 "\"type\": \"edgeType\"," +
64 "\"prevent-delete\": \"NONE\" }," +
66 "\"key\": \"50bdab41-ad1c-4d00-952c-a0aa5d827811\", \"type\": \"vserver\"}," +
68 "\"key\": \"1d326bc7-b985-492b-9604-0d5d1f06f908\", \"type\": \"pserver\"}" +
71 private final String vertexPayload = "{" +
72 "\"type\":\"pserver\"," +
74 "\"aai-node-type\":\"pserver\"}}";
77 private RestClient restClientMock;
78 private ChampDao champDao;
80 static final String CHAMP_URL = "https://host:9522/services/champ-service/v1/";
81 static final String OBJECT_SUB_URL = "objects";
82 static final String RELATIONSHIP_SUB_URL = "relationships";
83 static final String TRANSACTION_SUB_URL = "transaction";
84 static final String BASE_OBJECT_URL = CHAMP_URL + OBJECT_SUB_URL;
85 static final String HEADER_FROM_APP = "X-FromAppId";
86 static final String HEADER_TRANS_ID = "X-TransactionId";
87 static final String FROM_APP_NAME = "Gizmo";
91 restClientMock = mock(RestClient.class);
95 public void testGetVertexIdNotExists() {
96 String id = "test-id";
97 String idNotExists = "test-id-not-exists";
98 String type = "pserver";
99 String version = "v11";
100 String failureCauseForGetVertex = "No vertex with id " + id + " found in graph";
102 Map<String, String> queryParams = new HashMap<>();
103 queryParams.put("hostname", "myhost");
104 mockGetVertex(idNotExists, "", "", type, 404, failureCauseForGetVertex);
108 champDao.getVertex(idNotExists, version);
109 } catch (CrudException e) {
110 assertEquals(404, e.getHttpStatus().getStatusCode());
111 assertThat(e.getMessage(), containsString(failureCauseForGetVertex));
116 public void testGetVertexIdNotExistsWithQueryParams() {
117 String id = "test-id";
118 String idNotExists = "test-id-not-exists";
119 String queryParamsForMock = "?hostname=myhost";
120 String type = "pserver";
121 String version = "v11";
122 String failureCauseForGetVertex = "No vertex with id " + id + " found in graph";
124 Map<String, String> queryParams = new HashMap<>();
125 queryParams.put("hostname", "myhost");
126 mockGetVertex(idNotExists, queryParamsForMock, "", type, 404, failureCauseForGetVertex);
130 champDao.getVertex(idNotExists, type, version, queryParams);
131 } catch (CrudException e) {
132 assertEquals(404, e.getHttpStatus().getStatusCode());
133 assertThat(e.getMessage(), containsString(failureCauseForGetVertex));
138 public void testGetVertexWithQueryParamsTypeNotMatch() {
139 String id = "test-id";
140 String queryParamsForMock = "?hostname=myhost";
141 String type = "pserver";
142 String version = "v11";
143 String failureCauseForGetVertexTypeNotMatches = "No vertex with id " + id + " and type vserver found in graph";
145 Map<String, String> queryParams = new HashMap<>();
146 queryParams.put("hostname", "myhost");
147 mockGetVertex(id, queryParamsForMock, "", type, 200, "");
151 champDao.getVertex(id, "vserver", version, queryParams);
152 } catch (CrudException e) {
153 assertEquals(404, e.getHttpStatus().getStatusCode());
154 assertThat(e.getMessage(), containsString(failureCauseForGetVertexTypeNotMatches));
159 public void testGetVertexIdNotExistsWithTxId() {
160 String id = "test-id";
161 String idNotExists = "test-id-not-exists";
162 String txId = "1234";
163 String type = "pserver";
164 String version = "v11";
165 String failureCauseForGetVertex = "No vertex with id " + id + " found in graph";
167 Map<String, String> queryParams = new HashMap<>();
168 queryParams.put("hostname", "myhost");
169 mockGetVertex(idNotExists, "", txId, type, 404, failureCauseForGetVertex);
173 champDao.getVertex(idNotExists, type, version, txId);
174 } catch (CrudException e) {
175 assertEquals(404, e.getHttpStatus().getStatusCode());
176 assertThat(e.getMessage(), containsString(failureCauseForGetVertex));
181 public void testGetVertexWithTxIdAndTypeNotMatch() {
182 String id = "test-id";
183 String txId = "1234";
184 String type = "pserver";
185 String version = "v11";
186 String failureCauseForGetVertexTypeNotMatches = "No vertex with id " + id + " and type vserver found in graph";
188 Map<String, String> queryParams = new HashMap<>();
189 queryParams.put("hostname", "myhost");
190 mockGetVertex(id, "", txId, type, 200, "");
194 champDao.getVertex(id, "vserver", version, txId);
195 } catch (CrudException e) {
196 assertEquals(404, e.getHttpStatus().getStatusCode());
197 assertThat(e.getMessage(), containsString(failureCauseForGetVertexTypeNotMatches));
202 public void testGetVertices() {
203 String queryParamsForMockGetVertices = "?aai-node-type=pserver";
204 String type = "pserver";
205 String version = "v11";
206 String failureCauseForGetVertices = "No vertices found in graph for given filters";
208 Map<String, Object> filter = new HashMap<>();
209 Map<String, String> queryParams = new HashMap<>();
210 queryParams.put("hostname", "myhost");
211 mockGetVertices(queryParamsForMockGetVertices, type, 404, failureCauseForGetVertices);
215 champDao.getVertices(type, filter, version);
216 } catch (CrudException e) {
217 assertEquals(404, e.getHttpStatus().getStatusCode());
218 assertThat(e.getMessage(), containsString(failureCauseForGetVertices));
223 public void testGetEdgeIdNotExists() {
224 String idNotExists = "test-id-not-exists";
225 String id = "test-id";
226 String txId = "1234";
227 String type = "tosca.relationships.HostedOn";
228 String failureCauseForGetEdge = "No edge with id " + id + " found in graph";
230 Map<String, String> queryParams = new HashMap<>();
231 queryParams.put("hostname", "myhost");
232 mockGetEdge(idNotExists, "", txId, type, 404, failureCauseForGetEdge);
236 champDao.getEdge(idNotExists, txId);
237 } catch (CrudException e) {
238 assertEquals(404, e.getHttpStatus().getStatusCode());
239 assertThat(e.getMessage(), containsString(failureCauseForGetEdge));
244 public void testGetEdgeTypeNotMatch() {
245 String id = "test-id";
246 String txId = "1234";
247 String type = "tosca.relationships.HostedOn";
248 String failureCauseForGetEdgeTypeNotMatches = "No edge with id " + id + " and type " + "" + " found in graph";
250 Map<String, String> queryParams = new HashMap<>();
251 queryParams.put("hostname", "myhost");
252 mockGetEdge(id, "", txId, type, 200, "");
257 champDao.getEdge(id, txId);
258 } catch (CrudException e) {
259 assertEquals(404, e.getHttpStatus().getStatusCode());
260 assertThat(e.getMessage(), containsString(failureCauseForGetEdgeTypeNotMatches));
265 public void testGetEdgeIdNotExistsWithQueryParams() {
266 String idNotExists = "test-id-not-exists";
267 String id = "test-id";
268 String queryParamsForMock = "?hostname=myhost";
269 String type = "tosca.relationships.HostedOn";
270 String failureCauseForGetEdge = "No edge with id " + id + " found in graph";
272 Map<String, String> queryParams = new HashMap<>();
273 queryParams.put("hostname", "myhost");
274 mockGetEdge(idNotExists, queryParamsForMock, "", type, 404, failureCauseForGetEdge);
278 champDao.getEdge(idNotExists, type, queryParams);
279 } catch (CrudException e) {
280 assertEquals(404, e.getHttpStatus().getStatusCode());
281 assertThat(e.getMessage(), containsString(failureCauseForGetEdge));
286 public void testGetEdgeTypeNotMatchWithQueryParams() {
287 String id = "test-id";
288 String queryParamsForMock = "?hostname=myhost";
289 String type = "tosca.relationships.HostedOn";
290 String failureCauseForGetEdgeTypeNotMatches = "No edge with id " + id + " and type " + "" + " found in graph";
292 Map<String, String> queryParams = new HashMap<>();
293 queryParams.put("hostname", "myhost");
294 mockGetEdge(id, queryParamsForMock, "", type, 200, "");
299 champDao.getEdge(id, "", queryParams);
300 } catch (CrudException e) {
301 assertEquals(404, e.getHttpStatus().getStatusCode());
302 assertThat(e.getMessage(), containsString(failureCauseForGetEdgeTypeNotMatches));
307 public void testGetEdges() {
308 String type = "tosca.relationships.HostedOn";
309 String failureCauseForGetEdges = "No edges found in graph for given filters";
311 Map<String, Object> filter = new HashMap<>();
312 Map<String, String> queryParams = new HashMap<>();
313 queryParams.put("hostname", "myhost");
314 mockGetEdges("?", type, 404, failureCauseForGetEdges);
318 champDao.getEdges(type, filter);
319 } catch (CrudException e) {
320 assertEquals(404, e.getHttpStatus().getStatusCode());
321 assertThat(e.getMessage(), containsString(failureCauseForGetEdges));
326 public void testGetVertexEdges() {
327 String idNotExists = "test-id-not-exists";
328 String id = "test-id";
329 String queryParamsForMock = "?hostname=myhost";
330 String type = "tosca.relationships.HostedOn";
331 String failureCauseForGetVertexEdges = "No vertex with id " + id + " found in graph";
333 Map<String, String> queryParams = new HashMap<>();
334 queryParams.put("hostname", "myhost");
335 mockGetVertexEdges(idNotExists, queryParamsForMock, type, 404, failureCauseForGetVertexEdges);
339 champDao.getVertexEdges(idNotExists, queryParams, null);
340 } catch (CrudException e) {
341 assertEquals(404, e.getHttpStatus().getStatusCode());
342 assertThat(e.getMessage(), containsString(failureCauseForGetVertexEdges));
347 public void addVertexTest() {
348 String type = "pserver";
349 String txId = "1234";
350 String version = "v11";
352 Map<String, Object> properties = new HashMap<>();
354 mockAddVertex(type, vertexPayload, "", 400);
355 mockAddVertex(type, vertexPayload, txId, 400);
359 champDao.addVertex(type, properties, version);
360 } catch (CrudException e) {
361 assertEquals(400, e.getHttpStatus().getStatusCode());
362 assertThat(e.getMessage(), containsString("Failed to create vertex"));
366 champDao.addVertex(type, properties, version, txId);
367 } catch (CrudException e) {
368 assertEquals(400, e.getHttpStatus().getStatusCode());
369 assertThat(e.getMessage(), containsString("Failed to create vertex"));
374 public void addEdgeTest() throws CrudException {
375 String txId = "1234";
376 String vertexType = "pserver";
377 String edgeType = "tosca.relationships.HostedOn";
378 String version = "v11";
380 Map<String, Object> properties = new HashMap<>();
382 mockGetVertex("test-uuid", "", "", "pserver", 200, "");
383 mockGetVertex("test-uuid", "", txId, "pserver", 200, "");
384 mockAddEdge(edgeType, "", 400);
385 mockAddEdge(edgeType, txId, 400);
388 String vertex = champVertex.replace("vertexType", vertexType);
389 Vertex source = Vertex.fromJson(vertex, "v11");
390 Vertex target = Vertex.fromJson(vertex, "v11");
393 champDao.addEdge(edgeType, source, target, properties, version);
394 } catch (CrudException e) {
395 assertEquals(400, e.getHttpStatus().getStatusCode());
396 assertThat(e.getMessage(), containsString("Failed to create edge"));
400 champDao.addEdge(edgeType, source, target, properties, version, txId);
401 } catch (CrudException e) {
402 assertEquals(400, e.getHttpStatus().getStatusCode());
403 assertThat(e.getMessage(), containsString("Failed to create edge"));
408 public void updateVertexTest() {
409 String id = "test-id";
410 String type = "pserver";
411 String txId = "1234";
412 String version = "v11";
414 Map<String, Object> properties = new HashMap<>();
416 mockPutVertex(id, type, "", 400);
417 mockPutVertex(id, type, txId, 400);
421 champDao.updateVertex(id, type, properties, version);
422 } catch (CrudException e) {
423 assertEquals(400, e.getHttpStatus().getStatusCode());
424 assertThat(e.getMessage(), containsString("Failed to update vertex"));
428 champDao.updateVertex(id, type, properties, version, txId);
429 } catch (CrudException e) {
430 assertEquals(400, e.getHttpStatus().getStatusCode());
431 assertThat(e.getMessage(), containsString("Failed to update vertex"));
436 public void updateEdgeTest() {
437 String id = "test-uuid";
438 String txId = "1234";
439 String type = "tosca.relationships.HostedOn";
441 mockPutEdge(id, type, "", 400);
442 mockPutEdge(id, type, txId, 400);
445 String champJson = champEdge.replace("\"test-uuid\"", "null").replace("edgeType", type);
446 Edge edge = Edge.fromJson(champJson);
449 champDao.updateEdge(edge);
450 } catch (CrudException e) {
451 assertEquals(400, e.getHttpStatus().getStatusCode());
452 assertThat(e.getMessage(), containsString("Unable to identify edge"));
456 champDao.updateEdge(edge, txId);
457 } catch (CrudException e) {
458 assertEquals(400, e.getHttpStatus().getStatusCode());
459 assertThat(e.getMessage(), containsString("Unable to identify edge"));
462 champJson = champEdge.replace("edgeType", type);
463 edge = Edge.fromJson(champJson);
466 champDao.updateEdge(edge);
467 } catch (CrudException e) {
468 assertEquals(400, e.getHttpStatus().getStatusCode());
469 assertThat(e.getMessage(), containsString("Failed to update edge"));
473 champDao.updateEdge(edge, txId);
474 } catch (CrudException e) {
475 assertEquals(400, e.getHttpStatus().getStatusCode());
476 assertThat(e.getMessage(), containsString("Failed to update edge"));
481 public void deleteVertexTest() {
482 String id = "test-id";
483 String type = "pserver";
484 String txId = "1234";
486 mockDeleteVertex(id, type, "", 400);
487 mockDeleteVertex(id, type, txId, 400);
491 champDao.deleteVertex(id, type);
492 } catch (CrudException e) {
493 assertEquals(400, e.getHttpStatus().getStatusCode());
494 assertThat(e.getMessage(), containsString("Failed to delete vertex"));
497 champDao.deleteVertex(id, type, txId);
498 } catch (CrudException e) {
499 assertEquals(400, e.getHttpStatus().getStatusCode());
500 assertThat(e.getMessage(), containsString("Failed to delete vertex"));
505 public void deleteEdgeTest() {
506 String id = "test-uuid";
507 String txId = "1234";
508 String type = "tosca.relationships.HostedOn";
509 String failureCauseFordeleteEdge = "No edge with id " + id + " found in graph";
511 mockDeleteEdge(id, type, "", 400, failureCauseFordeleteEdge);
512 mockDeleteEdge(id, type, txId, 400, failureCauseFordeleteEdge);
516 champDao.deleteEdge(id);
517 } catch (CrudException e) {
518 assertEquals(400, e.getHttpStatus().getStatusCode());
519 assertThat(e.getMessage(), containsString(failureCauseFordeleteEdge));
522 champDao.deleteEdge(id, txId);
523 } catch (CrudException e) {
524 assertEquals(400, e.getHttpStatus().getStatusCode());
525 assertThat(e.getMessage(), containsString(failureCauseFordeleteEdge));
530 public void transactionsTest() {
531 String id = "test-id";
532 int resultCode = 500;
534 mockOpenTransaction(resultCode);
535 mockRollbackTransaction(id, resultCode);
536 mockCommitTransaction(id, resultCode);
539 String response = champDao.openTransaction();
540 assertEquals(null, response);
543 champDao.rollbackTransaction(id);
544 } catch (CrudException e) {
545 assertEquals(500, e.getHttpStatus().getStatusCode());
546 assertThat(e.getMessage(), containsString("Unable to rollback transaction"));
550 champDao.commitTransaction(id);
551 } catch (CrudException e) {
552 assertEquals(500, e.getHttpStatus().getStatusCode());
553 assertThat(e.getMessage(), containsString("Unable to commit transaction"));
557 public void buildChampDao() {
558 String baseRelationshipUrl = CHAMP_URL + RELATIONSHIP_SUB_URL;
559 String baseTransactionUrl = CHAMP_URL + TRANSACTION_SUB_URL;
560 champDao = new ChampDao(restClientMock, BASE_OBJECT_URL, baseRelationshipUrl, baseTransactionUrl);
563 public void mockOpenTransaction(int resultCode) {
564 OperationResult operationResult = new OperationResult();
565 operationResult.setResult("");
566 operationResult.setResultCode(resultCode);
567 String url = CHAMP_URL + "transaction";
569 when(restClientMock.post(url, "", createHeader(), MediaType.TEXT_PLAIN_TYPE, MediaType.TEXT_PLAIN_TYPE))
570 .thenReturn(operationResult);
573 public void mockRollbackTransaction(String id, int resultCode) {
574 OperationResult operationResult = new OperationResult();
575 operationResult.setResult("");
576 operationResult.setResultCode(resultCode);
577 String url = CHAMP_URL + TRANSACTION_SUB_URL + "/" + id;
579 when(restClientMock.put(url, "{\"method\": \"rollback\"}", createHeader(), MediaType.APPLICATION_JSON_TYPE,
580 MediaType.TEXT_PLAIN_TYPE)).thenReturn(operationResult);
583 public void mockCommitTransaction(String id, int resultCode) {
584 OperationResult operationResult = new OperationResult();
585 operationResult.setResult("");
586 operationResult.setResultCode(resultCode);
587 String url = CHAMP_URL + TRANSACTION_SUB_URL + "/" + id;
589 when(restClientMock.put(url, "{\"method\": \"commit\"}", createHeader(), MediaType.APPLICATION_JSON_TYPE,
590 MediaType.TEXT_PLAIN_TYPE)).thenReturn(operationResult);
593 public void mockGetVertex(String id, String queryParams, String txId, String type, int resultCode,
594 String failureCause) {
595 String vertexResponse = champVertex.replace("vertexType", type);
596 OperationResult operationResult = new OperationResult();
597 operationResult.setResult(vertexResponse);
598 operationResult.setResultCode(resultCode);
599 operationResult.setFailureCause(failureCause);
602 if (queryParams != null && !queryParams.isEmpty() && (txId.isEmpty() || txId == null)) {
603 url = BASE_OBJECT_URL + "/" + id + queryParams;
604 } else if (txId != null && !txId.isEmpty() && (queryParams.isEmpty() || queryParams == null)) {
605 url = BASE_OBJECT_URL + "/" + id + "?transactionId=" + txId;
607 url = BASE_OBJECT_URL + "/" + id;
610 when(restClientMock.get(url, createHeader(), MediaType.APPLICATION_JSON_TYPE)).thenReturn(operationResult);
613 public void mockGetVertexEdges(String id, String queryParams, String type, int resultCode, String failureCause) {
614 String edgeResponse = champEdge.replace("edgeType", type);
615 OperationResult operationResult = new OperationResult();
616 List<String> edgeResponselist = new ArrayList<>();
617 edgeResponselist.add(edgeResponse);
618 operationResult.setResult(edgeResponselist.toString());
619 operationResult.setResultCode(resultCode);
620 operationResult.setFailureCause(failureCause);
622 String url = BASE_OBJECT_URL + "/" + RELATIONSHIP_SUB_URL + "/" + id + queryParams;
624 when(restClientMock.get(url, createHeader(), MediaType.APPLICATION_JSON_TYPE)).thenReturn(operationResult);
627 public void mockGetVertices(String queryParams, String type, int resultCode, String failureCause) {
628 String vertexResponse = champVertex.replace("vertexType", type);
629 OperationResult operationResult = new OperationResult();
630 List<String> vertexResponselist = new ArrayList<>();
631 vertexResponselist.add(vertexResponse);
632 operationResult.setResult(vertexResponselist.toString());
633 operationResult.setResultCode(resultCode);
634 operationResult.setFailureCause(failureCause);
636 String url = BASE_OBJECT_URL + "/" + "filter" + queryParams;
638 when(restClientMock.get(url, createHeader(), MediaType.APPLICATION_JSON_TYPE)).thenReturn(operationResult);
641 public void mockGetEdges(String queryParams, String type, int resultCode, String failureCause) {
642 String edgeResponse = champEdge.replace("edgeType", type);
643 OperationResult operationResult = new OperationResult();
644 List<String> edgeResponselist = new ArrayList<>();
645 edgeResponselist.add(edgeResponse);
646 operationResult.setResult(edgeResponselist.toString());
647 operationResult.setResultCode(resultCode);
648 operationResult.setFailureCause(failureCause);
650 String url = CHAMP_URL + RELATIONSHIP_SUB_URL + "/" + "filter" + queryParams;
652 when(restClientMock.get(url, createHeader(), MediaType.APPLICATION_JSON_TYPE)).thenReturn(operationResult);
655 public void mockGetEdge(String id, String queryParams, String txId, String type, int resultCode,
656 String failureCause) {
657 String edgeResponse = champEdge.replace("edgeType", type);
658 OperationResult operationResult = new OperationResult();
659 operationResult.setResult(edgeResponse);
660 operationResult.setResultCode(resultCode);
661 operationResult.setFailureCause(failureCause);
665 if (queryParams != null && !queryParams.isEmpty() && (txId.isEmpty() || txId == null)) {
666 url = CHAMP_URL + RELATIONSHIP_SUB_URL + "/" + id + queryParams;
667 } else if (txId != null && !txId.isEmpty() && (queryParams.isEmpty() || queryParams == null)) {
668 url = CHAMP_URL + RELATIONSHIP_SUB_URL + "/" + id + "?transactionId=" + txId;
670 url = CHAMP_URL + RELATIONSHIP_SUB_URL + "/" + id;
673 when(restClientMock.get(url, createHeader(), MediaType.APPLICATION_JSON_TYPE)).thenReturn(operationResult);
676 public void mockAddEdge(String type, String txId, int resultCode) {
677 String edgeResponse = champEdge.replace("edgeType", type);
678 OperationResult operationResult = new OperationResult();
679 operationResult.setResult(edgeResponse);
680 operationResult.setResultCode(resultCode);
683 if (txId != null && !txId.isEmpty()) {
684 url = CHAMP_URL + RELATIONSHIP_SUB_URL + "?transactionId=" + txId;
686 url = CHAMP_URL + RELATIONSHIP_SUB_URL;
689 when(restClientMock.post(eq(url), anyString(), eq(createHeader()), eq(MediaType.APPLICATION_JSON_TYPE),
690 eq(MediaType.APPLICATION_JSON_TYPE))).thenReturn(operationResult);
693 public void mockAddVertex(String type, String payload, String txId, int resultCode) {
694 String vertexResponse = champVertex.replace("vertexType", type);
695 OperationResult operationResult = new OperationResult();
696 operationResult.setResult(vertexResponse);
697 operationResult.setResultCode(resultCode);
700 if (txId != null && !txId.isEmpty()) {
701 url = BASE_OBJECT_URL + "?transactionId=" + txId;
703 url = BASE_OBJECT_URL;
706 when(restClientMock.post(url, payload, createHeader(), MediaType.APPLICATION_JSON_TYPE,
707 MediaType.APPLICATION_JSON_TYPE)).thenReturn(operationResult);
710 public void mockPutVertex(String id, String type, String txId, int resultCode) {
711 String vertexResponse = champVertex.replace("vertexType", type);
712 OperationResult operationResult = new OperationResult();
713 operationResult.setResult(vertexResponse);
714 operationResult.setResultCode(resultCode);
717 if (txId != null && !txId.isEmpty()) {
718 url = BASE_OBJECT_URL + "/" + id + "?transactionId=" + txId;
720 url = BASE_OBJECT_URL + "/" + id;
723 when(restClientMock.put(eq(url), anyString(), eq(createHeader()), eq(MediaType.APPLICATION_JSON_TYPE),
724 eq(MediaType.APPLICATION_JSON_TYPE))).thenReturn(operationResult);
727 public void mockPutEdge(String id, String type, String txId, int resultCode) {
728 String edgeResponse = champEdge.replace("edgeType", type);
729 OperationResult operationResult = new OperationResult();
730 operationResult.setResult(edgeResponse);
731 operationResult.setResultCode(resultCode);
734 if (txId != null && !txId.isEmpty()) {
735 url = CHAMP_URL + RELATIONSHIP_SUB_URL + "/" + id + "?transactionId=" + txId;
737 url = CHAMP_URL + RELATIONSHIP_SUB_URL + "/" + id;
740 when(restClientMock.put(eq(url), anyString(), eq(createHeader()), eq(MediaType.APPLICATION_JSON_TYPE),
741 eq(MediaType.APPLICATION_JSON_TYPE))).thenReturn(operationResult);
744 public void mockDeleteVertex(String id, String type, String txId, int resultCode) {
745 String vertexResponse = champVertex.replace("vertexType", type);
746 OperationResult operationResult = new OperationResult();
747 operationResult.setResult(vertexResponse);
748 operationResult.setResultCode(resultCode);
751 if (txId != null && !txId.isEmpty()) {
752 url = BASE_OBJECT_URL + "/" + id + "?transactionId=" + txId;
754 url = BASE_OBJECT_URL + "/" + id;
757 when(restClientMock.delete(url, createHeader(), MediaType.APPLICATION_JSON_TYPE)).thenReturn(operationResult);
760 public void mockDeleteEdge(String id, String type, String txId, int resultCode, String failureCause) {
761 String edgeResponse = champEdge.replace("edgeType", type);
762 OperationResult operationResult = new OperationResult();
763 operationResult.setResult(edgeResponse);
764 operationResult.setResultCode(resultCode);
765 operationResult.setFailureCause(failureCause);
768 if (txId != null && !txId.isEmpty()) {
769 url = CHAMP_URL + RELATIONSHIP_SUB_URL + "/" + id + "?transactionId=" + txId;
771 url = CHAMP_URL + RELATIONSHIP_SUB_URL + "/" + id;
774 when(restClientMock.delete(url, createHeader(), MediaType.APPLICATION_JSON_TYPE)).thenReturn(operationResult);
777 public ChampDao getChampDao() {
781 public void setChampDao(ChampDao champDao) {
782 this.champDao = champDao;
785 private Map<String, List<String>> createHeader() {
786 Map<String, List<String>> headers = new HashMap<>();
787 headers.put(HEADER_FROM_APP, Arrays.asList(FROM_APP_NAME));
788 headers.put(HEADER_TRANS_ID, Arrays.asList(MDC.get(MdcContext.MDC_REQUEST_ID)));