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 java.util.ArrayList;
24 import java.util.HashSet;
25 import java.util.List;
27 import javax.ws.rs.core.MultivaluedHashMap;
28 import javax.ws.rs.core.MultivaluedMap;
29 import org.onap.aai.restclient.client.OperationResult;
30 import org.onap.crud.dao.GraphDao;
31 import org.onap.crud.entity.Edge;
32 import org.onap.crud.entity.Vertex;
33 import org.onap.crud.exception.CrudException;
35 public class TestDao implements GraphDao {
37 private final String champVertex = "{" +
38 "\"key\": \"test-uuid\"," +
39 "\"type\": \"pserver\"," +
41 "\"fqdn\": \"myhost.onap.com\"," +
42 "\"hostname\": \"myhost\" } }";
44 private final String champVertices = "[ {" +
45 "\"key\": \"test-uuid\"," +
46 "\"type\": \"pserver\"," +
48 "\"fqdn\": \"myhost.onap.com\"," +
49 "\"hostname\": \"myhost\" } } ]";
51 private final String champEdge = "{" +
52 "\"key\": \"test-uuid\"," +
53 "\"type\": \"tosca.relationships.HostedOn\"," +
55 "\"prevent-delete\": \"NONE\" }," +
57 "\"key\": \"50bdab41-ad1c-4d00-952c-a0aa5d827811\", \"type\": \"vserver\"}," +
59 "\"key\": \"1d326bc7-b985-492b-9604-0d5d1f06f908\", \"type\": \"pserver\"}" +
62 private final String champEdges = "[ {" +
63 "\"key\": \"test-uuid\"," +
64 "\"type\": \"tosca.relationships.HostedOn\"," +
66 "\"prevent-delete\": \"NONE\" }," +
68 "\"key\": \"50bdab41-ad1c-4d00-952c-a0aa5d827811\", \"type\": \"vserver\"}," +
70 "\"key\": \"1d326bc7-b985-492b-9604-0d5d1f06f908\", \"type\": \"pserver\"}" +
74 public Vertex getVertex(String id, String version) throws CrudException {
75 return Vertex.fromJson(champVertex, "v11");
79 public OperationResult getVertex(String id, String type, String version, Map<String, String> queryParams)
80 throws CrudException {
81 OperationResult operationResult = new OperationResult();
82 operationResult.setResult(champVertex);
83 return operationResult;
87 public List<Edge> getVertexEdges(String id, Map<String, String> queryParams) throws CrudException {
88 List<Edge> list = new ArrayList<Edge>();
89 list.add(Edge.fromJson(champEdge));
94 public OperationResult getVertices(String type, Map<String, Object> filter, String version) throws CrudException {
95 OperationResult operationResult = new OperationResult();
96 operationResult.setResult(champVertices);
97 return operationResult;
101 public OperationResult getVertices(String type, Map<String, Object> filter, HashSet<String> properties, String version)
102 throws CrudException {
103 OperationResult operationResult = new OperationResult();
104 operationResult.setResult(champVertices);
105 return operationResult;
109 public OperationResult getEdge(String id, String type, Map<String, String> queryParams) throws CrudException {
110 OperationResult operationResult = new OperationResult();
111 operationResult.setResult(champEdge);
112 return operationResult;
116 public OperationResult getEdges(String type, Map<String, Object> filter) throws CrudException {
117 OperationResult operationResult = new OperationResult();
118 operationResult.setResult(champEdges);
119 return operationResult;
123 public OperationResult addVertex(String type, Map<String, Object> properties, String version) throws CrudException {
124 OperationResult operationResult = new OperationResult();
125 operationResult.setHeaders(addReponseHeader());
126 operationResult.setResult(champVertex);
127 return operationResult;
131 public OperationResult updateVertex(String id, String type, Map<String, Object> properties, String version)
132 throws CrudException {
133 OperationResult operationResult = new OperationResult();
134 operationResult.setHeaders(addReponseHeader());
135 operationResult.setResult(champVertex);
136 return operationResult;
140 public void deleteVertex(String id, String type) throws CrudException {
145 public OperationResult addEdge(String type, Vertex source, Vertex target, Map<String, Object> properties, String version)
146 throws CrudException {
147 OperationResult operationResult = new OperationResult();
148 operationResult.setHeaders(addReponseHeader());
149 operationResult.setResult(champEdge);
150 return operationResult;
154 public OperationResult updateEdge(Edge edge) throws CrudException {
155 OperationResult operationResult = new OperationResult();
156 operationResult.setHeaders(addReponseHeader());
157 operationResult.setResult(champEdge);
158 return operationResult;
162 public void deleteEdge(String id, String type) throws CrudException {
167 public String openTransaction() {
168 // TODO Auto-generated method stub
173 public void commitTransaction(String id) throws CrudException {
174 // TODO Auto-generated method stub
179 public void rollbackTransaction(String id) throws CrudException {
180 // TODO Auto-generated method stub
185 public boolean transactionExists(String id) throws CrudException {
186 // TODO Auto-generated method stub
191 public Vertex addVertex(String type, Map<String, Object> properties, String version, String txId)
192 throws CrudException {
193 return Vertex.fromJson(champVertex, "v11");
197 public Edge addEdge(String type, Vertex source, Vertex target, Map<String, Object> properties, String version,
198 String txId) throws CrudException {
199 return Edge.fromJson(champEdge);
203 public Vertex updateVertex(String id, String type, Map<String, Object> properties, String version, String txId)
204 throws CrudException {
205 return Vertex.fromJson(champVertex, "v11");
209 public Edge updateEdge(Edge edge, String txId) throws CrudException {
210 return Edge.fromJson(champEdge);
214 public void deleteVertex(String id, String type, String txId) throws CrudException {
215 // TODO Auto-generated method stub
220 public void deleteEdge(String id, String type, String txId) throws CrudException {
221 // TODO Auto-generated method stub
226 public Edge getEdge(String id, String type, String txId) throws CrudException {
227 return Edge.fromJson(champEdge);
230 private MultivaluedMap<String, String> addReponseHeader() {
231 MultivaluedMap<String, String> headers = new MultivaluedHashMap<String, String>();
232 headers.add("etag", "test123");