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