ETags on resources
[aai/gizmo.git] / src / test / java / org / onap / crud / service / TestDao.java
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
-package org.onap.crud.dao;
+package org.onap.crud.service;
 
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+import org.onap.aai.restclient.client.OperationResult;
 import org.onap.crud.dao.GraphDao;
 import org.onap.crud.entity.Edge;
 import org.onap.crud.entity.Vertex;
 import org.onap.crud.exception.CrudException;
 
 public class TestDao implements GraphDao {
-  
+
   private final String champVertex = "{" +
       "\"key\": \"test-uuid\"," +
       "\"type\": \"pserver\"," +
       "\"properties\": {" +
       "\"fqdn\": \"myhost.onap.com\"," +
       "\"hostname\": \"myhost\" } }";
-  
+
+  private final String champVertices = "[ {" +
+          "\"key\": \"test-uuid\"," +
+          "\"type\": \"pserver\"," +
+          "\"properties\": {" +
+          "\"fqdn\": \"myhost.onap.com\"," +
+          "\"hostname\": \"myhost\" } } ]";
+
   private final String champEdge = "{" +
       "\"key\": \"test-uuid\"," +
       "\"type\": \"tosca.relationships.HostedOn\"," +
@@ -50,15 +59,28 @@ public class TestDao implements GraphDao {
       "\"key\": \"1d326bc7-b985-492b-9604-0d5d1f06f908\", \"type\": \"pserver\"}" +
       " }";
 
+  private final String champEdges = "[ {" +
+          "\"key\": \"test-uuid\"," +
+          "\"type\": \"tosca.relationships.HostedOn\"," +
+          "\"properties\": {" +
+          "\"prevent-delete\": \"NONE\" }," +
+          "\"source\": {" +
+          "\"key\": \"50bdab41-ad1c-4d00-952c-a0aa5d827811\", \"type\": \"vserver\"}," +
+          "\"target\": {" +
+          "\"key\": \"1d326bc7-b985-492b-9604-0d5d1f06f908\", \"type\": \"pserver\"}" +
+          " } ]";
+
   @Override
   public Vertex getVertex(String id, String version) throws CrudException {
     return Vertex.fromJson(champVertex, "v11");
   }
 
   @Override
-  public Vertex getVertex(String id, String type, String version, Map<String, String> queryParams)
+  public OperationResult getVertex(String id, String type, String version, Map<String, String> queryParams)
       throws CrudException {
-    return Vertex.fromJson(champVertex, "v11");
+    OperationResult operationResult = new OperationResult();
+    operationResult.setResult(champVertex);
+    return operationResult;
   }
 
   @Override
@@ -69,41 +91,49 @@ public class TestDao implements GraphDao {
   }
 
   @Override
-  public List<Vertex> getVertices(String type, Map<String, Object> filter, String version) throws CrudException {
-    List<Vertex> list = new ArrayList<Vertex>();
-    list.add(Vertex.fromJson(champVertex, "v11"));
-    return list;
+  public OperationResult getVertices(String type, Map<String, Object> filter, String version) throws CrudException {
+      OperationResult operationResult = new OperationResult();
+      operationResult.setResult(champVertices);
+      return operationResult;
   }
 
   @Override
-  public List<Vertex> getVertices(String type, Map<String, Object> filter, HashSet<String> properties, String version)
+  public OperationResult getVertices(String type, Map<String, Object> filter, HashSet<String> properties, String version)
       throws CrudException {
-    List<Vertex> list = new ArrayList<Vertex>();
-    list.add(Vertex.fromJson(champVertex, "v11"));
-    return list;
+    OperationResult operationResult = new OperationResult();
+    operationResult.setResult(champVertices);
+    return operationResult;
   }
 
   @Override
-  public Edge getEdge(String id, String type, Map<String, String> queryParams) throws CrudException {
-    return Edge.fromJson(champEdge);
+  public OperationResult getEdge(String id, String type, Map<String, String> queryParams) throws CrudException {
+    OperationResult operationResult = new OperationResult();
+    operationResult.setResult(champEdge);
+    return operationResult;
   }
 
   @Override
-  public List<Edge> getEdges(String type, Map<String, Object> filter) throws CrudException {
-    List<Edge> list = new ArrayList<Edge>();
-    list.add(Edge.fromJson(champEdge));
-    return list;
+  public OperationResult getEdges(String type, Map<String, Object> filter) throws CrudException {
+      OperationResult operationResult = new OperationResult();
+      operationResult.setResult(champEdges);
+      return operationResult;
   }
 
   @Override
-  public Vertex addVertex(String type, Map<String, Object> properties, String version) throws CrudException {
-    return Vertex.fromJson(champVertex, "v11");
+  public OperationResult addVertex(String type, Map<String, Object> properties, String version) throws CrudException {
+    OperationResult operationResult = new OperationResult();
+    operationResult.setHeaders(addReponseHeader());
+    operationResult.setResult(champVertex);
+    return operationResult;
   }
 
   @Override
-  public Vertex updateVertex(String id, String type, Map<String, Object> properties, String version)
+  public OperationResult updateVertex(String id, String type, Map<String, Object> properties, String version)
       throws CrudException {
-    return Vertex.fromJson(champVertex, "v11");
+    OperationResult operationResult = new OperationResult();
+       operationResult.setHeaders(addReponseHeader());
+    operationResult.setResult(champVertex);
+    return operationResult;
   }
 
   @Override
@@ -112,14 +142,20 @@ public class TestDao implements GraphDao {
   }
 
   @Override
-  public Edge addEdge(String type, Vertex source, Vertex target, Map<String, Object> properties, String version)
+  public OperationResult addEdge(String type, Vertex source, Vertex target, Map<String, Object> properties, String version)
       throws CrudException {
-    return Edge.fromJson(champEdge);
+    OperationResult operationResult = new OperationResult();
+       operationResult.setHeaders(addReponseHeader());
+    operationResult.setResult(champEdge);
+    return operationResult;
   }
 
   @Override
-  public Edge updateEdge(Edge edge) throws CrudException {
-    return Edge.fromJson(champEdge);
+  public OperationResult updateEdge(Edge edge) throws CrudException {
+    OperationResult operationResult = new OperationResult();
+       operationResult.setHeaders(addReponseHeader());
+    operationResult.setResult(champEdge);
+    return operationResult;
   }
 
   @Override
@@ -190,5 +226,10 @@ public class TestDao implements GraphDao {
   public Edge getEdge(String id, String type, String txId) throws CrudException {
     return Edge.fromJson(champEdge);
   }
-
-}
+  
+  private MultivaluedMap<String, String> addReponseHeader() {
+    MultivaluedMap<String, String> headers = new MultivaluedHashMap<String, String>();
+    headers.add("etag", "test123");
+    return headers;
+  }
+}
\ No newline at end of file