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.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.dao.champ.ChampBulkPayload;
32 import org.onap.crud.entity.Edge;
33 import org.onap.crud.entity.Vertex;
34 import org.onap.crud.exception.CrudException;
36 public class TestDao implements GraphDao {
38 private final String champVertex = "{" +
39 "\"key\": \"test-uuid\"," +
40 "\"type\": \"pserver\"," +
42 "\"fqdn\": \"myhost.onap.com\"," +
43 "\"hostname\": \"myhost\" } }";
45 private final String champVertices = "[ {" +
46 "\"key\": \"test-uuid\"," +
47 "\"type\": \"pserver\"," +
49 "\"fqdn\": \"myhost.onap.com\"," +
50 "\"hostname\": \"myhost\" } } ]";
52 private final String champEdge = "{" +
53 "\"key\": \"test-uuid\"," +
54 "\"type\": \"tosca.relationships.HostedOn\"," +
56 "\"prevent-delete\": \"NONE\" }," +
58 "\"key\": \"50bdab41-ad1c-4d00-952c-a0aa5d827811\", \"type\": \"vserver\"}," +
60 "\"key\": \"1d326bc7-b985-492b-9604-0d5d1f06f908\", \"type\": \"pserver\"}" +
63 private final String champEdges = "[ {" +
64 "\"key\": \"test-uuid\"," +
65 "\"type\": \"tosca.relationships.HostedOn\"," +
67 "\"prevent-delete\": \"NONE\" }," +
69 "\"key\": \"50bdab41-ad1c-4d00-952c-a0aa5d827811\", \"type\": \"vserver\"}," +
71 "\"key\": \"1d326bc7-b985-492b-9604-0d5d1f06f908\", \"type\": \"pserver\"}" +
75 public Vertex getVertex(String id, String version) throws CrudException {
76 return Vertex.fromJson(champVertex, "v11");
80 public OperationResult getVertex(String id, String type, String version, Map<String, String> queryParams)
81 throws CrudException {
82 OperationResult operationResult = new OperationResult();
83 operationResult.setResult(champVertex);
84 return operationResult;
88 public List<Edge> getVertexEdges(String id, Map<String, String> queryParams, String txId) throws CrudException {
89 List<Edge> list = new ArrayList<Edge>();
90 list.add(Edge.fromJson(champEdge));
95 public OperationResult getVertices(String type, Map<String, Object> filter, String version) throws CrudException {
96 OperationResult operationResult = new OperationResult();
97 operationResult.setResult(champVertices);
98 return operationResult;
102 public OperationResult getVertices(String type, Map<String, Object> filter, Set<String> properties, String version)
103 throws CrudException {
104 OperationResult operationResult = new OperationResult();
105 operationResult.setResult(champVertices);
106 return operationResult;
110 public OperationResult getEdge(String id, String type, Map<String, String> queryParams) throws CrudException {
111 OperationResult operationResult = new OperationResult();
112 operationResult.setResult(champEdge);
113 return operationResult;
117 public OperationResult getEdges(String type, Map<String, Object> filter) throws CrudException {
118 OperationResult operationResult = new OperationResult();
119 operationResult.setResult(champEdges);
120 return operationResult;
124 public OperationResult addVertex(String type, Map<String, Object> properties, String version) throws CrudException {
125 OperationResult operationResult = new OperationResult();
126 operationResult.setHeaders(addReponseHeader());
127 operationResult.setResult(champVertex);
128 return operationResult;
132 public OperationResult updateVertex(String id, String type, Map<String, Object> properties, String version)
133 throws CrudException {
134 OperationResult operationResult = new OperationResult();
135 operationResult.setHeaders(addReponseHeader());
136 operationResult.setResult(champVertex);
137 return operationResult;
141 public void deleteVertex(String id, String type) throws CrudException {
146 public OperationResult addEdge(String type, Vertex source, Vertex target, Map<String, Object> properties, String version)
147 throws CrudException {
148 OperationResult operationResult = new OperationResult();
149 operationResult.setHeaders(addReponseHeader());
150 operationResult.setResult(champEdge);
151 return operationResult;
155 public OperationResult updateEdge(Edge edge) throws CrudException {
156 OperationResult operationResult = new OperationResult();
157 operationResult.setHeaders(addReponseHeader());
158 operationResult.setResult(champEdge);
159 return operationResult;
163 public void deleteEdge(String id) throws CrudException {
168 public String openTransaction() {
169 // TODO Auto-generated method stub
174 public void commitTransaction(String id) throws CrudException {
175 // TODO Auto-generated method stub
180 public void rollbackTransaction(String id) throws CrudException {
181 // TODO Auto-generated method stub
186 public boolean transactionExists(String id) throws CrudException {
187 // TODO Auto-generated method stub
192 public Vertex addVertex(String type, Map<String, Object> properties, String version, String txId)
193 throws CrudException {
194 return Vertex.fromJson(champVertex, "v11");
198 public Edge addEdge(String type, Vertex source, Vertex target, Map<String, Object> properties, String version,
199 String txId) throws CrudException {
200 return Edge.fromJson(champEdge);
204 public Vertex updateVertex(String id, String type, Map<String, Object> properties, String version, String txId)
205 throws CrudException {
206 return Vertex.fromJson(champVertex, "v11");
210 public Edge updateEdge(Edge edge, String txId) throws CrudException {
211 return Edge.fromJson(champEdge);
215 public void deleteVertex(String id, String type, String txId) throws CrudException {
216 // TODO Auto-generated method stub
221 public void deleteEdge(String id, String txId) throws CrudException {
222 // TODO Auto-generated method stub
227 public Edge getEdge(String id, String txId) throws CrudException {
228 return Edge.fromJson(champEdge);
231 private MultivaluedMap<String, String> addReponseHeader() {
232 MultivaluedMap<String, String> headers = new MultivaluedHashMap<String, String>();
233 headers.add("etag", "test123");
238 public Edge getEdge(String id) throws CrudException {
239 // TODO Auto-generated method stub
244 public OperationResult bulkOperation(ChampBulkPayload champPayload) throws CrudException {
245 // TODO Auto-generated method stub