Performance Improvements for Gizmo bulk API
[aai/gizmo.git] / src / test / java / org / onap / crud / service / TestDao.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 java.util.ArrayList;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Set;
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;
35
36 public class TestDao implements GraphDao {
37
38   private final String champVertex = "{" +
39       "\"key\": \"test-uuid\"," +
40       "\"type\": \"pserver\"," +
41       "\"properties\": {" +
42       "\"fqdn\": \"myhost.onap.com\"," +
43       "\"hostname\": \"myhost\" } }";
44
45   private final String champVertices = "[ {" +
46           "\"key\": \"test-uuid\"," +
47           "\"type\": \"pserver\"," +
48           "\"properties\": {" +
49           "\"fqdn\": \"myhost.onap.com\"," +
50           "\"hostname\": \"myhost\" } } ]";
51
52   private final String champEdge = "{" +
53       "\"key\": \"test-uuid\"," +
54       "\"type\": \"tosca.relationships.HostedOn\"," +
55       "\"properties\": {" +
56       "\"prevent-delete\": \"NONE\" }," +
57       "\"source\": {" +
58       "\"key\": \"50bdab41-ad1c-4d00-952c-a0aa5d827811\", \"type\": \"vserver\"}," +
59       "\"target\": {" +
60       "\"key\": \"1d326bc7-b985-492b-9604-0d5d1f06f908\", \"type\": \"pserver\"}" +
61       " }";
62
63   private final String champEdges = "[ {" +
64           "\"key\": \"test-uuid\"," +
65           "\"type\": \"tosca.relationships.HostedOn\"," +
66           "\"properties\": {" +
67           "\"prevent-delete\": \"NONE\" }," +
68           "\"source\": {" +
69           "\"key\": \"50bdab41-ad1c-4d00-952c-a0aa5d827811\", \"type\": \"vserver\"}," +
70           "\"target\": {" +
71           "\"key\": \"1d326bc7-b985-492b-9604-0d5d1f06f908\", \"type\": \"pserver\"}" +
72           " } ]";
73
74   @Override
75   public Vertex getVertex(String id, String version) throws CrudException {
76     return Vertex.fromJson(champVertex, "v11");
77   }
78
79   @Override
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;
85   }
86
87   @Override
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));
91     return list;
92   }
93
94   @Override
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;
99   }
100
101   @Override
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;
107   }
108
109   @Override
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;
114   }
115
116   @Override
117   public OperationResult getEdges(String type, Map<String, Object> filter) throws CrudException {
118       OperationResult operationResult = new OperationResult();
119       operationResult.setResult(champEdges);
120       return operationResult;
121   }
122
123   @Override
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;
129   }
130
131   @Override
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;
138   }
139
140   @Override
141   public void deleteVertex(String id, String type) throws CrudException {
142     
143   }
144
145   @Override
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;
152   }
153
154   @Override
155   public OperationResult updateEdge(Edge edge) throws CrudException {
156     OperationResult operationResult = new OperationResult();
157         operationResult.setHeaders(addReponseHeader());
158     operationResult.setResult(champEdge);
159     return operationResult;
160   }
161
162   @Override
163   public void deleteEdge(String id) throws CrudException {
164     
165   }
166
167   @Override
168   public String openTransaction() {
169     // TODO Auto-generated method stub
170     return null;
171   }
172
173   @Override
174   public void commitTransaction(String id) throws CrudException {
175     // TODO Auto-generated method stub
176     
177   }
178
179   @Override
180   public void rollbackTransaction(String id) throws CrudException {
181     // TODO Auto-generated method stub
182     
183   }
184
185   @Override
186   public boolean transactionExists(String id) throws CrudException {
187     // TODO Auto-generated method stub
188     return false;
189   }
190
191   @Override
192   public Vertex addVertex(String type, Map<String, Object> properties, String version, String txId)
193       throws CrudException {
194     return Vertex.fromJson(champVertex, "v11");
195   }
196
197   @Override
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);
201   }
202
203   @Override
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");
207   }
208
209   @Override
210   public Edge updateEdge(Edge edge, String txId) throws CrudException {
211     return Edge.fromJson(champEdge);
212   }
213
214   @Override
215   public void deleteVertex(String id, String type, String txId) throws CrudException {
216     // TODO Auto-generated method stub
217     
218   }
219
220   @Override
221   public void deleteEdge(String id, String txId) throws CrudException {
222     // TODO Auto-generated method stub
223     
224   }
225
226   @Override
227   public Edge getEdge(String id, String txId) throws CrudException {
228     return Edge.fromJson(champEdge);
229   }
230   
231   private MultivaluedMap<String, String> addReponseHeader() {
232     MultivaluedMap<String, String> headers = new MultivaluedHashMap<String, String>();
233     headers.add("etag", "test123");
234     return headers;
235   }
236
237   @Override
238   public Edge getEdge(String id) throws CrudException {
239     // TODO Auto-generated method stub
240     return null;
241   }
242
243 @Override
244 public OperationResult bulkOperation(ChampBulkPayload champPayload) throws CrudException {
245     // TODO Auto-generated method stub
246     return null;
247 }
248 }