--- /dev/null
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * Gizmo\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property.\r
+ * Copyright © 2017 Amdocs\r
+ * All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+package org.openecomp.crud.service;\r
+\r
+import java.security.cert.X509Certificate;\r
+import java.util.AbstractMap;\r
+import java.util.HashSet;\r
+import java.util.Map;\r
+import java.util.Map.Entry;\r
+import java.util.Set;\r
+\r
+import javax.security.auth.x500.X500Principal;\r
+import javax.servlet.http.HttpServletRequest;\r
+import javax.ws.rs.Consumes;\r
+import javax.ws.rs.Encoded;\r
+import javax.ws.rs.POST;\r
+import javax.ws.rs.PUT;\r
+import javax.ws.rs.Path;\r
+import javax.ws.rs.PathParam;\r
+import javax.ws.rs.Produces;\r
+import javax.ws.rs.core.Context;\r
+import javax.ws.rs.core.HttpHeaders;\r
+import javax.ws.rs.core.MediaType;\r
+import javax.ws.rs.core.Response;\r
+import javax.ws.rs.core.UriInfo;\r
+import javax.ws.rs.core.Response.Status;\r
+\r
+import org.openecomp.aai.exceptions.AAIException;\r
+import org.openecomp.aai.serialization.db.EdgeProperty;\r
+import org.openecomp.aai.serialization.db.EdgeRule;\r
+import org.openecomp.aai.serialization.db.EdgeRules;\r
+import org.openecomp.aai.serialization.db.EdgeType;\r
+import org.openecomp.auth.Auth;\r
+import org.openecomp.cl.api.Logger;\r
+import org.openecomp.cl.eelf.LoggerFactory;\r
+import org.openecomp.crud.exception.CrudException;\r
+import org.openecomp.crud.logging.CrudServiceMsgs;\r
+import org.openecomp.crud.logging.LoggingUtil;\r
+import org.openecomp.crud.service.CrudRestService.Action;\r
+import org.openecomp.crud.util.CrudServiceConstants;\r
+import org.openecomp.schema.RelationshipSchemaLoader;\r
+import org.openecomp.schema.RelationshipSchemaValidator;\r
+import org.slf4j.MDC;\r
+\r
+import com.google.gson.Gson;\r
+import com.google.gson.JsonElement;\r
+import com.google.gson.JsonPrimitive;\r
+\r
+\r
+/**\r
+ * This defines a set of REST endpoints which allow clients to create or update graph edges\r
+ * where the edge rules defined by the A&AI will be invoked to automatically populate the\r
+ * defined edge properties.\r
+ */\r
+public class AaiResourceService {\r
+\r
+ private String mediaType = MediaType.APPLICATION_JSON;\r
+ public static final String HTTP_PATCH_METHOD_OVERRIDE = "X-HTTP-Method-Override";\r
+ \r
+ private Auth auth;\r
+ CrudGraphDataService crudGraphDataService;\r
+ Gson gson = new Gson();\r
+ \r
+ private Logger logger = LoggerFactory.getInstance().getLogger(AaiResourceService.class.getName());\r
+ private Logger auditLogger = LoggerFactory.getInstance().getAuditLogger(AaiResourceService.class.getName());\r
+ \r
+ public AaiResourceService() {}\r
+ \r
+ /**\r
+ * Creates a new instance of the AaiResourceService.\r
+ * \r
+ * @param crudGraphDataService - Service used for interacting with the graph.\r
+ * \r
+ * @throws Exception\r
+ */\r
+ public AaiResourceService(CrudGraphDataService crudGraphDataService) throws Exception {\r
+ this.crudGraphDataService = crudGraphDataService;\r
+ this.auth = new Auth(CrudServiceConstants.CRD_AUTH_FILE);\r
+ }\r
+ \r
+ /**\r
+ * Perform any one-time initialization required when starting the service.\r
+ */\r
+ public void startup() {\r
+ \r
+ if(logger.isDebugEnabled()) {\r
+ logger.debug("AaiResourceService started!");\r
+ }\r
+ }\r
+ \r
+ \r
+ /**\r
+ * Creates a new relationship in the graph, automatically populating the edge\r
+ * properties based on the A&AI edge rules.\r
+ * \r
+ * @param content - Json structure describing the relationship to create.\r
+ * @param type - Relationship type supplied as a URI parameter.\r
+ * @param uri - Http request uri\r
+ * @param headers - Http request headers\r
+ * @param uriInfo - Http URI info field\r
+ * @param req - Http request structure.\r
+ * \r
+ * @return - Standard HTTP response.\r
+ */\r
+ @POST\r
+ @Path("/relationships/{type}/")\r
+ @Consumes({MediaType.APPLICATION_JSON})\r
+ @Produces({MediaType.APPLICATION_JSON})\r
+ public Response createRelationship(String content, \r
+ @PathParam("type") String type, \r
+ @PathParam("uri") @Encoded String uri,\r
+ @Context HttpHeaders headers, \r
+ @Context UriInfo uriInfo,\r
+ @Context HttpServletRequest req) {\r
+ \r
+ LoggingUtil.initMdcContext(req, headers);\r
+\r
+ if(logger.isDebugEnabled()) {\r
+ logger.debug("Incoming request..." + content);\r
+ }\r
+ \r
+ Response response = null;\r
+\r
+ if (validateRequest(req, uri, content, Action.POST, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {\r
+ \r
+ try {\r
+ \r
+ // Extract the edge payload from the request.\r
+ EdgePayload payload = EdgePayload.fromJson(content); \r
+ \r
+ // Do some basic validation on the payload.\r
+ if (payload.getProperties() == null || payload.getProperties().isJsonNull()) {\r
+ throw new CrudException("Invalid request Payload", Status.BAD_REQUEST);\r
+ }\r
+ if (payload.getId() != null) {\r
+ throw new CrudException("ID specified , use Http PUT to update Edge", Status.BAD_REQUEST);\r
+ }\r
+ if (payload.getType() != null && !payload.getType().equals(type)) {\r
+ throw new CrudException("Edge Type mismatch", Status.BAD_REQUEST);\r
+ }\r
+ \r
+ // Apply the edge rules to our edge.\r
+ payload = applyEdgeRulesToPayload(payload);\r
+ \r
+ if(logger.isDebugEnabled()) {\r
+ logger.debug("Creating AAI edge using version " + RelationshipSchemaLoader.getLatestSchemaVersion() );\r
+ }\r
+ \r
+ // Now, create our edge in the graph store.\r
+ String result = crudGraphDataService.addEdge(RelationshipSchemaLoader.getLatestSchemaVersion(), type, payload);\r
+ response = Response.status(Status.CREATED).entity(result).type(mediaType).build();\r
+ \r
+ } catch (CrudException e) {\r
+\r
+ response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();\r
+ } \r
+ }\r
+ \r
+ LoggingUtil.logRestRequest(logger, auditLogger, req, response);\r
+ return response;\r
+ }\r
+ \r
+ \r
+ /**\r
+ * Creates a new relationship in the graph, automatically populating the edge\r
+ * properties based on the A&AI edge rules.\r
+ * \r
+ * @param content - Json structure describing the relationship to create.\r
+ * @param uri - Http request uri\r
+ * @param headers - Http request headers\r
+ * @param uriInfo - Http URI info field\r
+ * @param req - Http request structure.\r
+ * \r
+ * @return - Standard HTTP response.\r
+ * \r
+ */\r
+ @POST\r
+ @Path("/relationships/")\r
+ @Consumes({MediaType.APPLICATION_JSON})\r
+ @Produces({MediaType.APPLICATION_JSON})\r
+ public Response createRelationship(String content, \r
+ @PathParam("uri") @Encoded String uri, \r
+ @Context HttpHeaders headers,\r
+ @Context UriInfo uriInfo, \r
+ @Context HttpServletRequest req) {\r
+\r
+ LoggingUtil.initMdcContext(req, headers);\r
+\r
+ logger.debug("Incoming request..." + content);\r
+ Response response = null;\r
+\r
+ if (validateRequest(req, uri, content, Action.POST, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {\r
+\r
+ try {\r
+ \r
+ // Extract the edge payload from the request.\r
+ EdgePayload payload = EdgePayload.fromJson(content);\r
+ \r
+ // Do some basic validation on the payload.\r
+ if (payload.getProperties() == null || payload.getProperties().isJsonNull()) {\r
+ throw new CrudException("Invalid request Payload", Status.BAD_REQUEST);\r
+ }\r
+ if (payload.getId() != null) {\r
+ throw new CrudException("ID specified , use Http PUT to update Edge", Status.BAD_REQUEST);\r
+ }\r
+ if (payload.getType() == null || payload.getType().isEmpty()) {\r
+ throw new CrudException("Missing Edge Type ", Status.BAD_REQUEST);\r
+ }\r
+ \r
+ // Apply the edge rules to our edge.\r
+ payload = applyEdgeRulesToPayload(payload);\r
+ \r
+ // Now, create our edge in the graph store.\r
+ String result = crudGraphDataService.addEdge(RelationshipSchemaLoader.getLatestSchemaVersion(), payload.getType(), payload);\r
+ response = Response.status(Status.CREATED).entity(result).type(mediaType).build();\r
+ \r
+ } catch (CrudException ce) {\r
+ response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();\r
+ } catch (Exception e) {\r
+ response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();\r
+ }\r
+ } else {\r
+ response = Response.status(Status.FORBIDDEN).entity(content)\r
+ .type(MediaType.APPLICATION_JSON).build();\r
+ }\r
+\r
+ LoggingUtil.logRestRequest(logger, auditLogger, req, response);\r
+ return response;\r
+ }\r
+\r
+ \r
+ \r
+ /**\r
+ * Upserts a relationship into the graph, automatically populating the edge properties\r
+ * based on the A&AI edge rules. The behaviour is as follows:\r
+ * <p>\r
+ * <li>If no relationship with the supplied identifier already exists, then a new relationship \r
+ * is created with that id.<br>\r
+ * <li>If a relationship with the supplied id DOES exist, then it is replaced with the supplied \r
+ * content.\r
+ * \r
+ * @param content - Json structure describing the relationship to create.\r
+ * @param type - Relationship type supplied as a URI parameter.\r
+ * @param id - Edge identifier.\r
+ * @param uri - Http request uri\r
+ * @param headers - Http request headers\r
+ * @param uriInfo - Http URI info field\r
+ * @param req - Http request structure.\r
+ * \r
+ * @return - Standard HTTP response.\r
+ */\r
+ @PUT\r
+ @Path("/relationships/{type}/{id}")\r
+ @Consumes({MediaType.APPLICATION_JSON})\r
+ @Produces({MediaType.APPLICATION_JSON})\r
+ public Response upsertEdge(String content, \r
+ @PathParam("type") String type, \r
+ @PathParam("id") String id,\r
+ @PathParam("uri") @Encoded String uri, \r
+ @Context HttpHeaders headers,\r
+ @Context UriInfo uriInfo, \r
+ @Context HttpServletRequest req) {\r
+ LoggingUtil.initMdcContext(req, headers);\r
+\r
+ logger.debug("Incoming request..." + content);\r
+ Response response = null;\r
+\r
+ if (validateRequest(req, uri, content, Action.PUT, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {\r
+ \r
+ try {\r
+ \r
+ // Extract the edge payload from the request.\r
+ EdgePayload payload = EdgePayload.fromJson(content);\r
+ \r
+ // Do some basic validation on the payload.\r
+ if (payload.getProperties() == null || payload.getProperties().isJsonNull()) {\r
+ throw new CrudException("Invalid request Payload", Status.BAD_REQUEST);\r
+ }\r
+ if (payload.getId() != null && !payload.getId().equals(id)) {\r
+ throw new CrudException("ID Mismatch", Status.BAD_REQUEST);\r
+ }\r
+ \r
+ // Apply the edge rules to our edge.\r
+ payload = applyEdgeRulesToPayload(payload);\r
+ \r
+ String result;\r
+ if (headers.getRequestHeaders().getFirst(HTTP_PATCH_METHOD_OVERRIDE) != null &&\r
+ headers.getRequestHeaders().getFirst(HTTP_PATCH_METHOD_OVERRIDE).equalsIgnoreCase("PATCH")) {\r
+ result = crudGraphDataService.patchEdge(RelationshipSchemaLoader.getLatestSchemaVersion(), id, type, payload);\r
+ } else {\r
+\r
+ result = crudGraphDataService.updateEdge(RelationshipSchemaLoader.getLatestSchemaVersion(), id, type, payload);\r
+ }\r
+\r
+ response = Response.status(Status.OK).entity(result).type(mediaType).build();\r
+ \r
+ } catch (CrudException ce) {\r
+ response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();\r
+ } catch (Exception e) {\r
+ response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();\r
+ }\r
+ \r
+ } else {\r
+ \r
+ response = Response.status(Status.FORBIDDEN).entity(content)\r
+ .type(MediaType.APPLICATION_JSON).build();\r
+ }\r
+ \r
+ LoggingUtil.logRestRequest(logger, auditLogger, req, response);\r
+ return response;\r
+ }\r
+ \r
+ \r
+ /**\r
+ * Retrieves the properties defined in the edge rules for a relationship between the \r
+ * supplied vertex types.\r
+ * \r
+ * @param sourceVertexType - Type of source vertex for the relationship.\r
+ * @param targetVertexType - Type of target vertex for the relationship.\r
+ * \r
+ * @return - The defined properties for the relationship type.\r
+ * \r
+ * @throws CrudException\r
+ */\r
+ private Map<EdgeProperty, String> getEdgeRuleProperties(String sourceVertexType, String targetVertexType) throws CrudException {\r
+\r
+ if(logger.isDebugEnabled()) {\r
+ logger.debug("Lookup db edge rules for " + sourceVertexType + " -> " + targetVertexType);\r
+ }\r
+ \r
+ EdgeRules rules = EdgeRules.getInstance();\r
+ EdgeRule rule;\r
+ try {\r
+ \r
+ if(logger.isDebugEnabled()) {\r
+ logger.debug("Lookup by edge type TREE");\r
+ }\r
+ \r
+ // We have no way of knowing in advance whether our relationship is considered to\r
+ // be a tree or cousing relationship, so try looking it up as a tree type first.\r
+ rule = rules.getEdgeRule(EdgeType.TREE, sourceVertexType, targetVertexType);\r
+ \r
+ } catch (AAIException e) {\r
+ try {\r
+ \r
+ if(logger.isDebugEnabled()) {\r
+ logger.debug("Lookup by edge type COUSIN");\r
+ }\r
+ \r
+ // If we are here, then our lookup by 'tree' type failed, so try looking it up\r
+ // as a 'cousin' relationship.\r
+ rule = rules.getEdgeRule(EdgeType.COUSIN, sourceVertexType, targetVertexType);\r
+ \r
+ } catch (AAIException e1) {\r
+ \r
+ // If we're here then we failed to find edge rules for this relationship. Time to\r
+ // give up...\r
+ throw new CrudException("No edge rules for " + sourceVertexType + " -> " + targetVertexType, Status.NOT_FOUND);\r
+ }\r
+ } catch (Exception e) {\r
+ \r
+ throw new CrudException("General failure getting edge rule properties - " + \r
+ e.getMessage(), Status.INTERNAL_SERVER_ERROR);\r
+ }\r
+ \r
+ return rule.getEdgeProperties();\r
+ }\r
+ \r
+ \r
+ /**\r
+ * This method takes an inbound edge request payload, looks up the edge rules for the\r
+ * sort of relationship defined in the payload, and automatically applies the defined\r
+ * edge properties to it.\r
+ * \r
+ * @param payload - The original edge request payload\r
+ * \r
+ * @return - An updated edge request payload, with the properties defined in the edge\r
+ * rules automatically populated.\r
+ * \r
+ * @throws CrudException\r
+ */\r
+ public EdgePayload applyEdgeRulesToPayload(EdgePayload payload) throws CrudException {\r
+ \r
+ // Extract the types for both the source and target vertices.\r
+ String srcType = RelationshipSchemaValidator.vertexTypeFromUri(payload.getSource());\r
+ String tgtType = RelationshipSchemaValidator.vertexTypeFromUri(payload.getTarget());\r
+\r
+ // Now, get the default properties for this edge based on the edge rules definition...\r
+ Map<EdgeProperty, String> props = getEdgeRuleProperties(srcType, tgtType);\r
+ \r
+ // ...and merge them with any custom properties provided in the request.\r
+ JsonElement mergedProperties = mergeProperties(payload.getProperties(), props);\r
+ payload.setProperties(mergedProperties);\r
+ \r
+ \r
+ if(logger.isDebugEnabled()) {\r
+ logger.debug("Edge properties after applying rules for '" + srcType + " -> " + tgtType + "': " + mergedProperties);\r
+ }\r
+ \r
+ return payload;\r
+ }\r
+ \r
+ \r
+ /**\r
+ * Given a set of edge properties extracted from an edge request payload and a set of properties\r
+ * taken from the db edge rules, this method merges them into one set of properties.\r
+ * <p>\r
+ * If the client has attempted to override the defined value for a property in the db edge rules\r
+ * then the request will be rejected as invalid.\r
+ * \r
+ * @param propertiesFromRequest - Set of properties from the edge request.\r
+ * @param propertyDefaults - Set of properties from the db edge rules.\r
+ * \r
+ * @return - A merged set of properties.\r
+ * \r
+ * @throws CrudException\r
+ */\r
+ public JsonElement mergeProperties(JsonElement propertiesFromRequest, Map<EdgeProperty, String> propertyDefaults) throws CrudException {\r
+ \r
+ // Convert the properties from the edge payload into something we can\r
+ // manipulate.\r
+ Set<Map.Entry<String, JsonElement>> properties = new HashSet<Map.Entry<String, JsonElement>>();\r
+ properties.addAll(propertiesFromRequest.getAsJsonObject().entrySet());\r
+ \r
+ Set<String> propertyKeys = new HashSet<String>();\r
+ for(Map.Entry<String, JsonElement> property : properties) {\r
+ propertyKeys.add(property.getKey());\r
+ }\r
+ \r
+ // Now, merge in the properties specified in the Db Edge Rules.\r
+ for(EdgeProperty defProperty : propertyDefaults.keySet()) {\r
+ \r
+ // If the edge rules property was explicitly specified by the\r
+ // client then we will reject the request...\r
+ if(!propertyKeys.contains(defProperty.toString())) {\r
+ properties.add(new AbstractMap.SimpleEntry<String, JsonElement>(defProperty.toString(),\r
+ (JsonElement)(new JsonPrimitive(propertyDefaults.get(defProperty)))));\r
+ \r
+ } else {\r
+ throw new CrudException("Property " + defProperty + " defined in db edge rules can not be overriden by the client.", \r
+ Status.BAD_REQUEST);\r
+ } \r
+ }\r
+\r
+ Object[] propArray = properties.toArray();\r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append("{");\r
+ boolean first=true;\r
+ for(int i=0; i<propArray.length; i++) {\r
+ \r
+ Map.Entry<String, JsonElement> entry = (Entry<String, JsonElement>) propArray[i];\r
+ if(!first) {\r
+ sb.append(",");\r
+ }\r
+ sb.append("\"").append(entry.getKey()).append("\"").append(":").append(entry.getValue());\r
+ first=false;\r
+ }\r
+ sb.append("}");\r
+ \r
+ // We're done. Return the result as a JsonElement.\r
+ return gson.fromJson(sb.toString(), JsonElement.class);\r
+ }\r
+\r
+\r
+ /**\r
+ * Invokes authentication validation on an incoming HTTP request.\r
+ * \r
+ * @param req - The HTTP request.\r
+ * @param uri - HTTP URI\r
+ * @param content - Payload of the HTTP request.\r
+ * @param action - What HTTP action is being performed (GET/PUT/POST/PATCH/DELETE)\r
+ * @param authPolicyFunctionName - Policy function being invoked.\r
+ * \r
+ * @return true - if the request passes validation,\r
+ * false - otherwise.\r
+ */\r
+ protected boolean validateRequest(HttpServletRequest req, \r
+ String uri, \r
+ String content,\r
+ Action action, \r
+ String authPolicyFunctionName) {\r
+ try {\r
+ String cipherSuite = (String) req.getAttribute("javax.servlet.request.cipher_suite");\r
+ String authUser = null;\r
+ if (cipherSuite != null) {\r
+ \r
+ X509Certificate[] certChain = (X509Certificate[]) req.getAttribute("javax.servlet.request.X509Certificate");\r
+ X509Certificate clientCert = certChain[0];\r
+ X500Principal subjectDn = clientCert.getSubjectX500Principal();\r
+ authUser = subjectDn.toString();\r
+ }\r
+ \r
+ return this.auth.validateRequest(authUser.toLowerCase(), action.toString() + ":" + authPolicyFunctionName);\r
+ \r
+ } catch (Exception e) {\r
+ logResult(action, uri, e);\r
+ return false;\r
+ }\r
+ }\r
+ \r
+ protected void logResult(Action op, String uri, Exception e) {\r
+\r
+ logger.error(CrudServiceMsgs.EXCEPTION_DURING_METHOD_CALL, \r
+ op.toString(), \r
+ uri, \r
+ e.getStackTrace().toString());\r
+\r
+ // Clear the MDC context so that no other transaction inadvertently\r
+ // uses our transaction id.\r
+ MDC.clear();\r
+ }\r
+}\r
*/
public class ChampDaoTest {
- private static final String GRAPH_NAME = "my_test_graph";
-
- private GraphDao champDao = null;
-
-
- /**
- * Perform setup steps that must be done prior to executing each test.
- */
- @Before
- public void setup() {
-
- // Create an instance of the Champ DAO, backed by the Champ library's in-memory back end
- // for testing purposes.
- Map<String, Object> champDaoProperties = new HashMap<String, Object>();
- champDaoProperties.put(ChampDao.CONFIG_STORAGE_BACKEND, "in-memory");
- champDaoProperties.put(ChampDao.CONFIG_GRAPH_NAME, GRAPH_NAME);
- champDao = new ChampDao(new InMemoryChampGraphImpl.Builder().properties(champDaoProperties).build());
- }
-
-
- /**
- * Perform tear down steps that must be done after executing each test.
- */
- @After
- public void tearDown() {
-
- // Release the Champ DAO instance that we were using for the test.
- if (champDao != null) {
- ((ChampDao) champDao).close();
- }
- }
-
-
- /**
- * Tests the ability of the {@link ChampDao} to create a vertex.
- *
- * @throws CrudException
- */
- @Test
- public void createVertexTest() throws CrudException {
-
- String VERTEX_TYPE = "Test_Vertex";
-
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put("property1", "something");
- properties.put("property2", "something else");
-
- // Create the vertex.
- Vertex createdVertex = champDao.addVertex(VERTEX_TYPE, properties);
-
- // Validate that the returned {@link Vertex} has the right label assigned to it.
- assertTrue("Unexpected vertex type '" + createdVertex.getType() + "' returned from DAO",
- createdVertex.getType().equals(VERTEX_TYPE));
-
- // Validate that all of the properties that we provided to the DAO are in fact assigned
- // to the {@link Vertex} that we got back.
- assertTrue("Vertex property list returned from DAO did not contain all expected properties - expected: " +
- properties.keySet() + " actual: " + createdVertex.getProperties().keySet(),
- createdVertex.getProperties().keySet().containsAll(properties.keySet()));
-
- // Validate that the values assigned to the properties in the returned {@link Vertex}
- // match the ones that we provided.
- for (String propertyKey : properties.keySet()) {
-
- assertTrue(createdVertex.getProperties().get(propertyKey).equals(properties.get(propertyKey)));
- }
- }
-
-
- /**
- * Tests the ability of the {@link ChampDao} to retrieve a vertex from the graph data store
- * by its unique identifier.
- *
- * @throws CrudException
- */
- @Test
- public void getVertexByIdTest() throws CrudException {
-
- String VERTEX_TYPE = "Test_Vertex";
-
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put("property1", "something");
- properties.put("property2", "something else");
-
- // Create the vertex.
- Vertex createdVertex = champDao.addVertex(VERTEX_TYPE, properties);
-
- // Make sure the {@link Vertex} returned from the create method includes an id that we can
- // use to retrieve it.
- assertTrue("No valid id returned for the created vertex", createdVertex.getId().isPresent());
-
- // Now, retrieve the {@link Vertex} by its identifier.
- Vertex retrievedVertex = champDao.getVertex(createdVertex.getId().get(), VERTEX_TYPE);
-
- // Validate that the retrieved {@link Vertex} has the right label assigned to it.
- assertTrue("Unexpected vertex type '" + retrievedVertex.getType() + "' returned from DAO",
- retrievedVertex.getType().equals(VERTEX_TYPE));
-
- // Validate that all of the properties that we provided when we created the {@link Vertex}
- // are present in the {@link Vertex} that we retrieved.
- assertTrue("Vertex property list returned from DAO did not contain all expected properties - expected: " +
- properties.keySet() + " actual: " + retrievedVertex.getProperties().keySet(),
- retrievedVertex.getProperties().keySet().containsAll(properties.keySet()));
-
- // Validate that the values assigned to the properties in the retrieved {@link Vertex}
- // match the ones that we provided when we created it.
- for (String propertyKey : properties.keySet()) {
-
- assertTrue(retrievedVertex.getProperties().get(propertyKey).equals(properties.get(propertyKey)));
- }
- }
-
-
- /**
- * Tests the ability of the {@link ChampDao} to update an already existing vertex.
- *
- * @throws CrudException
- */
- @Test
- public void updateVertexTest() throws CrudException {
-
- final String VERTEX_TYPE = "Test_Vertex";
-
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put("property1", "something");
- properties.put("property2", "something else");
-
- // Create the vertex.
- Vertex createdVertex = champDao.addVertex(VERTEX_TYPE, properties);
-
- // Make sure the {@link Vertex} returned from the create method includes an id that we can
- // use to retrieve it.
- assertTrue("No valid id returned for the created vertex", createdVertex.getId().isPresent());
-
- // Modify the properties list...
- properties.put("property3", "a new property");
- properties.remove("property1");
-
- // ...and apply it to our vertex.
- Vertex updatedVertex = champDao.updateVertex(createdVertex.getId().get(), createdVertex.getType(), properties);
-
- assertTrue("Vertex property list returned from DAO update operation did not contain all expected properties - expected: " +
- properties.keySet() + " actual: " + updatedVertex.getProperties().keySet(),
- updatedVertex.getProperties().keySet().containsAll(properties.keySet()));
-
- // Validate that the values assigned to the properties in the updated {@link Vertex}
- // match the ones that we provided when we created it.
- for (String propertyKey : properties.keySet()) {
-
- assertTrue("Unexpected value for property '" + propertyKey + "' - Expected: " +
- properties.get(propertyKey) + " Actual: " +
- updatedVertex.getProperties().get(propertyKey),
- updatedVertex.getProperties().get(propertyKey).equals(properties.get(propertyKey)));
- }
-
- // Validate that the property that we removed is NOT in the set of properties from our
- // updated {@link Vertex}.
- assertFalse("Property 'property1' should no longer be associated with updated vertex",
- updatedVertex.getProperties().containsKey("property1"));
- }
-
-
- /**
- * Tests the ability of the {@link ChampDao} to retrieve multiple vertices which match
- * a particular set of supplied properties.
- *
- * @throws CrudException
- */
- @Test
- public void getVerticesTest() throws CrudException {
-
- final String FIRST_VERTEX_TYPE = "pserver";
- final String SECOND_VERTEX_TYPE = "complex";
-
- // Create some vertices.
-
- Map<String, Object> vertex1Properties = new HashMap<String, Object>();
- vertex1Properties.put("O/S", "Linux");
- vertex1Properties.put("version", "6.5");
- vertex1Properties.put("hostname", "kll0001");
- champDao.addVertex(FIRST_VERTEX_TYPE, vertex1Properties);
-
- Map<String, Object> vertex2Properties = new HashMap<String, Object>();
- vertex2Properties.put("O/S", "Linux");
- vertex2Properties.put("version", "6.5");
- vertex2Properties.put("hostname", "kll0002");
- champDao.addVertex(FIRST_VERTEX_TYPE, vertex2Properties);
-
- Map<String, Object> vertex3Properties = new HashMap<String, Object>();
- vertex3Properties.put("O/S", "Linux");
- vertex3Properties.put("version", "7.2");
- vertex3Properties.put("hostname", "kll0003");
- champDao.addVertex(FIRST_VERTEX_TYPE, vertex3Properties);
-
- Map<String, Object> vertex4Properties = new HashMap<String, Object>();
- vertex4Properties.put("O/S", "Windows");
- vertex4Properties.put("version", "10");
- vertex4Properties.put("hostname", "Dev Laptop");
- champDao.addVertex(FIRST_VERTEX_TYPE, vertex4Properties);
-
- Map<String, Object> vertex5Properties = new HashMap<String, Object>();
- vertex5Properties.put("Street", "Baker");
- vertex5Properties.put("Number", "222B");
- champDao.addVertex(SECOND_VERTEX_TYPE, vertex5Properties);
-
- // Create a set of properties to use for our query.
- Map<String, Object> queryProperties = new HashMap<String, Object>();
- queryProperties.put("O/S", "Linux");
- queryProperties.put("version", "6.5");
-
- // Validate that we filter our 'get vertices' results by type
- List<Vertex> allVerticesByType = champDao.getVertices(FIRST_VERTEX_TYPE, MapBuilder.builder().build());
- for (Vertex v : allVerticesByType) {
- assertTrue("Unexpected vertex type returned from query. Expected: " +
- FIRST_VERTEX_TYPE + " Actual: " + v.getType(),
- v.getType().equals(FIRST_VERTEX_TYPE));
- }
-
- // Now, request the vertices that match our parameters.
- List<Vertex> vertices = champDao.getVertices(FIRST_VERTEX_TYPE, queryProperties);
-
- // Validate that got back the expected number of vertices.
- assertEquals(vertices.size(), 2);
-
- // Validate that the vertices we got back contain the expected parameters.
- for (Vertex v : vertices) {
-
- assertTrue("Vertex from query result does not contain expected vertex 'O/S'",
- v.getProperties().containsKey("O/S"));
- assertTrue("Vertex from query result contains unexpected value for 'O/S' parameter - Expected: 'Linux' Actual: '" +
- v.getProperties().get("O/S") + "'",
- v.getProperties().get("O/S").equals("Linux"));
-
- assertTrue("Vertex from query result does not contain expected vertex 'O/S'",
- v.getProperties().containsKey("version"));
- assertTrue("Vertex from query result contains unexpected value for 'O/S' parameter - Expected: 'Linux' Actual: '" +
- v.getProperties().get("O/S") + "'",
- v.getProperties().get("version").equals("6.5"));
- }
- }
-
- @Test
- public void deleteVertexTest() throws CrudException {
-
- boolean deletedVertexNotFound = false;
-
- // Create a vertex.
- Vertex createdVertex = champDao.addVertex("test_type", MapBuilder.builder()
- .withKeyValue("O/S", "Linux")
- .withKeyValue("version", "6.5")
- .withKeyValue("hostname", "kll0001")
- .build());
-
- // Verify that we can retrieve the vertex from the graph data base.
- Vertex retrievedVertex = champDao.getVertex(createdVertex.getId().get(), "test_type");
-
- // Now, delete the vertex.
- champDao.deleteVertex(createdVertex.getId().get(), "test_type");
-
- // Now, try to retrieve it again. This time we should fail to find it.
- try {
- champDao.getVertex(createdVertex.getId().get(), "test_type");
-
- } catch (CrudException e) {
- assertTrue(e.getMessage().contains("No vertex with id"));
- deletedVertexNotFound = true;
- }
-
- assertTrue("Should not have been able to retrieve deleted vertex", deletedVertexNotFound);
- }
-
- @Test
- public void createEdgeTest() throws CrudException {
-
- String EDGE_TYPE = "has";
-
- // Create the source vertex for the edge.
- Map<String, Object> srcVertexProperties = new HashMap<String, Object>();
- srcVertexProperties.put("O/S", "Linux");
- srcVertexProperties.put("version", "6.5");
- srcVertexProperties.put("hostname", "kll0001");
- Vertex sourceVertex = champDao.addVertex("vserver", srcVertexProperties);
-
- // Create the target vertex for the edge.
- Map<String, Object> dstVertexProperties = new HashMap<String, Object>();
- dstVertexProperties.put("O/S", "Linux");
- dstVertexProperties.put("version", "6.5");
- dstVertexProperties.put("hostname", "kll0002");
- Vertex destVertex = champDao.addVertex("VNF", dstVertexProperties);
-
- // Now, create the edge itself.
- Map<String, Object> edgeProperties = new HashMap<String, Object>();
- edgeProperties.put("prop", "val");
- Edge createdEdge = champDao.addEdge("has", sourceVertex, destVertex, edgeProperties);
-
- // Validate that the Edge object returned from the create method matches what we were
- // trying to create.
- assertTrue("Unexpected type for Edge returned from create method. Expected: " + EDGE_TYPE
- + " Actual: " + createdEdge.getType(),
- createdEdge.getType().equals("has"));
- assertTrue("Unexpected properties for Edge returned from create method. Expected: " + edgeProperties
- + " Actual: " + createdEdge.getProperties(),
- createdEdge.getProperties().equals(edgeProperties));
-
- }
-
- @Test
- public void createEdgeWithMissingSrcOrTargetTest() throws CrudException {
-
- String EDGE_TYPE = "has";
-
- // Create the source vertex for the edge.
- Map<String, Object> srcVertexProperties = new HashMap<String, Object>();
- srcVertexProperties.put("O/S", "Linux");
- srcVertexProperties.put("version", "6.5");
- srcVertexProperties.put("hostname", "kll0001");
- Vertex sourceVertex = champDao.addVertex("vserver", srcVertexProperties);
-
- // Create the target vertex for the edge.
- Map<String, Object> dstVertexProperties = new HashMap<String, Object>();
- dstVertexProperties.put("O/S", "Linux");
- dstVertexProperties.put("version", "6.5");
- dstVertexProperties.put("hostname", "kll0002");
- Vertex destVertex = champDao.addVertex("VNF", dstVertexProperties);
-
- // Now, try creating the Edge but specify an id for the source vertex that does
- // not exist.
- Map<String, Object> edgeProperties = new HashMap<String, Object>();
- edgeProperties.put("prop", "val");
- try {
- champDao.addEdge(EDGE_TYPE, new Vertex.Builder("miss").id("99").build(), destVertex, edgeProperties);
- } catch (CrudException e) {
- assertTrue(e.getMessage().contains("Error creating edge - source vertex"));
- }
-
- // Now, try created the Edge with a valid source vertex, but specify an id for the
- // target vertex that does not exist.
- try {
- champDao.addEdge(EDGE_TYPE, sourceVertex, new Vertex.Builder("miss").id("99").build(), edgeProperties);
- } catch (CrudException e) {
- assertTrue(e.getMessage().contains("Error creating edge - target vertex"));
- }
-
- }
-
- @Test
- public void getEdgeByIdTest() throws CrudException {
-
- String EDGE_TYPE = "has";
-
- // Create the source vertex for the edge.
- Map<String, Object> srcVertexProperties = new HashMap<String, Object>();
- srcVertexProperties.put("O/S", "Linux");
- srcVertexProperties.put("version", "6.5");
- srcVertexProperties.put("hostname", "kll0001");
- Vertex sourceVertex = champDao.addVertex("vserver", srcVertexProperties);
-
- // Create the target vertex for the edge.
- Map<String, Object> dstVertexProperties = new HashMap<String, Object>();
- dstVertexProperties.put("O/S", "Linux");
- dstVertexProperties.put("version", "6.5");
- dstVertexProperties.put("hostname", "kll0002");
- Vertex destVertex = champDao.addVertex("VNF", dstVertexProperties);
-
- // Now, create the edge itself.
- Map<String, Object> edgeProperties = new HashMap<String, Object>();
- edgeProperties.put("prop", "val");
- Edge createdEdge = champDao.addEdge("has", sourceVertex, destVertex, edgeProperties);
-
- // Retrieve the edge we just created by specifying its unique identifier.
- Edge retrievedEdge = champDao.getEdge(createdEdge.getId().get(), "has");
-
- // Validate that the contents of the object that we got back matches what we thought we
- // created.
- assertTrue("Unexpected type for Edge returned from get method. Expected: " + EDGE_TYPE
- + " Actual: " + retrievedEdge.getType(),
- retrievedEdge.getType().equals(EDGE_TYPE));
- assertTrue("Unexpected properties for Edge returned from get method. Expected: " + edgeProperties
- + " Actual: " + retrievedEdge.getProperties(),
- retrievedEdge.getProperties().equals(edgeProperties));
- }
-
- @Test
- public void getEdgesTest() throws CrudException {
-
- final String EDGE_TYPE_HAS = "has";
- final String EDGE_TYPE_RUNS = "runs";
-
- // Create some vertices and edges that we can query agains.
- Vertex complex = champDao.addVertex("complex", MapBuilder.builder()
- .withKeyValue("Province", "Ontario")
- .withKeyValue("City", "Ottawa")
- .withKeyValue("Street", "303 Terry Fox")
- .build());
-
- Vertex vserver = champDao.addVertex("vserver", MapBuilder.builder()
- .withKeyValue("O/S", "Linux")
- .withKeyValue("version", "6.5")
- .withKeyValue("hostname", "kll0001")
- .build());
-
- Vertex vnf1 = champDao.addVertex("vserver", MapBuilder.builder()
- .withKeyValue("Application", "OpenDaylight")
- .build());
-
- Vertex vnf2 = champDao.addVertex("vserver", MapBuilder.builder()
- .withKeyValue("Application", "Cammunda")
- .build());
-
- Edge edge1 = champDao.addEdge(EDGE_TYPE_HAS, complex, vserver,
- MapBuilder.builder()
- .withKeyValue("usesResource", "false")
- .withKeyValue("hasDelTarget", "false")
- .build());
-
- Edge edge2 = champDao.addEdge(EDGE_TYPE_RUNS, vserver, vnf1,
- MapBuilder.builder()
- .withKeyValue("usesResource", "false")
- .withKeyValue("hasDelTarget", "true")
- .build());
-
- Edge edge3 = champDao.addEdge(EDGE_TYPE_RUNS, vserver, vnf2,
- MapBuilder.builder()
- .withKeyValue("usesResource", "false")
- .withKeyValue("hasDelTarget", "false")
- .build());
-
- // Query for all HAS edges.
- List<Edge> hasEdges = champDao.getEdges(EDGE_TYPE_HAS, new HashMap<String, Object>());
-
- assertEquals("Unexpected number of edges of type 'has' found. Expected: 1 Actual: " + hasEdges.size(),
- hasEdges.size(), 1);
- assertTrue("Result of query for 'has' type edges does not contain the expected results",
- containsEdge(edge1, hasEdges));
-
- // Query for all RUNS edges.
- List<Edge> runsEdges = champDao.getEdges(EDGE_TYPE_RUNS, new HashMap<String, Object>());
-
- assertEquals("Unexpected number of edges of type 'runs' found. Expected: 2 Actual: " + runsEdges.size(),
- runsEdges.size(), 2);
- assertTrue("Result of query for 'runs' type edges does not contain the expected results",
- containsEdge(edge2, runsEdges));
- assertTrue("Result of query for 'runs' type edges does not contain the expected results",
- containsEdge(edge2, runsEdges));
-
- // Query for all HAS edges with the property 'hasDelTarget' equal to 'true'.
- List<Edge> runsEdgesWithDelTargetTrue =
- champDao.getEdges(EDGE_TYPE_RUNS, MapBuilder.builder()
- .withKeyValue("hasDelTarget", "true")
- .build());
-
- assertEquals("Unexpected number of edges of type 'has' with 'hasDelTarget=true' found. Expected: 1 Actual: "
- + runsEdgesWithDelTargetTrue.size(),
- runsEdgesWithDelTargetTrue.size(), 1);
- assertTrue("Result of query for 'runs' type edges with delTarget set to TRUE does not contain the expected results",
- containsEdge(edge2, runsEdgesWithDelTargetTrue));
- }
-
- @Test
- @Ignore // For now - pending some expected fixes to the Champ library.
- public void updateEdgeTest() throws CrudException {
-
- // Create the source vertex for the edge.
- Vertex sourceVertex = champDao.addVertex("vserver", MapBuilder.builder()
- .withKeyValue("O/S", "Linux")
- .withKeyValue("version", "6.5")
- .withKeyValue("hostname", "kll0001")
- .build());
-
- // Create the target vertex for the edge.
- Vertex destVertex = champDao.addVertex("VNF", MapBuilder.builder()
- .withKeyValue("O/S", "Linux")
- .withKeyValue("version", "6.5")
- .withKeyValue("hostname", "kll0002")
- .build());
-
- // Now, create the edge itself.
- Edge createdEdge = champDao.addEdge("has",
- sourceVertex,
- destVertex,
- MapBuilder.builder()
- .withKeyValue("key1", "value1")
- .withKeyValue("key2", "value2")
- .withKeyValue("key3", "value3")
- .build());
-
- // Make sure the Edge returned from the create method includes an id that we can
- // use to retrieve it.
- assertTrue("No valid id returned for the created edge", createdEdge.getId().isPresent());
-
- // Retrieve the properties map for our edge and make some changes.
- Map<String, Object> properties = createdEdge.getProperties();
- properties.put("key4", "value4");
- properties.remove("key2");
-
- // Now update the edge with the new properties map.
- Edge updatedEdge = champDao.updateEdge(createdEdge);
-
- assertTrue("Edge property list returned from DAO update operation did not contain all expected properties - expected: " +
- properties.keySet() + " actual: " + updatedEdge.getProperties().keySet(),
- updatedEdge.getProperties().keySet().containsAll(properties.keySet()));
-
- // Validate that the values assigned to the properties in the updated Edge
- // match the ones that we provided when we created it.
- for (String propertyKey : properties.keySet()) {
-
- assertTrue("Unexpected value for property '" + propertyKey + "' - Expected: " +
- properties.get(propertyKey) + " Actual: " +
- updatedEdge.getProperties().get(propertyKey),
- updatedEdge.getProperties().get(propertyKey).equals(properties.get(propertyKey)));
- }
-
- // Validate that the property that we removed is NOT in the set of properties from our
- // updated edge.
- // *** We will leave this validation commented out for now, as the Champ library actually
- // merges update properties instead of replacing them...
-// assertFalse("Property 'key2' should no longer be associated with updated edge",
-// updatedEdge.getProperties().containsKey("key2"));
- }
-
- @Test
- public void deleteEdgeTest() throws CrudException {
-
- boolean deletedEdgeNotFound = false;
-
- // Create the source vertex for the edge.
- Vertex sourceVertex = champDao.addVertex("vserver", MapBuilder.builder()
- .withKeyValue("O/S", "Linux")
- .withKeyValue("version", "6.5")
- .withKeyValue("hostname", "kll0001")
- .build());
-
- // Create the target vertex for the edge.
- Vertex destVertex = champDao.addVertex("VNF", MapBuilder.builder()
- .withKeyValue("O/S", "Linux")
- .withKeyValue("version", "6.5")
- .withKeyValue("hostname", "kll0002")
- .build());
-
- // Now, create the edge itself.
- Edge createdEdge = champDao.addEdge("has",
- sourceVertex,
- destVertex,
- MapBuilder.builder()
- .withKeyValue("key1", "value1")
- .withKeyValue("key2", "value2")
- .withKeyValue("key3", "value3")
- .build());
-
- // Verify that we can retrieve the edge that we just created.
- Edge retrievedEdge = champDao.getEdge(createdEdge.getId().get(), "has");
-
- // Now, delete it.
- champDao.deleteEdge(createdEdge.getId().get(), "has");
-
- // Try retrieving it again. This time we should not find it.
- try {
- champDao.getEdge(createdEdge.getId().get(), "has");
- } catch (CrudException e) {
-
- assertTrue(e.getMessage().contains("No edge with id"));
- deletedEdgeNotFound = true;
- }
-
- assertTrue("Should not have been able to retrieve deleted edge.", deletedEdgeNotFound);
- }
-
- private boolean containsEdge(Edge anEdge, List<Edge> edges) {
-
- for (Edge e : edges) {
- if (e.getId().isPresent() && anEdge.getId().isPresent() && (e.getId().get().equals(anEdge.getId().get()))) {
- return true;
- }
-
- }
- return false;
- }
-
- public static class MapBuilder {
-
- private Map<String, Object> map;
-
- private MapBuilder() {
- map = new HashMap<String, Object>();
- }
-
- public static MapBuilder builder() {
- return new MapBuilder();
- }
-
- public MapBuilder withKeyValue(String key, Object value) {
- map.put(key, value);
- return this;
- }
-
- public Map<String, Object> build() {
- return map;
- }
- }
+// private static final String GRAPH_NAME = "my_test_graph";
+//
+// private GraphDao champDao = null;
+//
+//
+// /**
+// * Perform setup steps that must be done prior to executing each test.
+// */
+// @Before
+// public void setup() {
+//
+// // Create an instance of the Champ DAO, backed by the Champ library's in-memory back end
+// // for testing purposes.
+// Map<String, Object> champDaoProperties = new HashMap<String, Object>();
+// champDaoProperties.put(ChampDao.CONFIG_STORAGE_BACKEND, "in-memory");
+// champDaoProperties.put(ChampDao.CONFIG_GRAPH_NAME, GRAPH_NAME);
+// champDao = new ChampDao(new InMemoryChampGraphImpl.Builder().properties(champDaoProperties).build());
+// }
+//
+//
+// /**
+// * Perform tear down steps that must be done after executing each test.
+// */
+// @After
+// public void tearDown() {
+//
+// // Release the Champ DAO instance that we were using for the test.
+// if (champDao != null) {
+// ((ChampDao) champDao).close();
+// }
+// }
+//
+//
+// /**
+// * Tests the ability of the {@link ChampDao} to create a vertex.
+// *
+// * @throws CrudException
+// */
+// @Test
+// public void createVertexTest() throws CrudException {
+//
+// String VERTEX_TYPE = "Test_Vertex";
+//
+// Map<String, Object> properties = new HashMap<String, Object>();
+// properties.put("property1", "something");
+// properties.put("property2", "something else");
+//
+// // Create the vertex.
+// Vertex createdVertex = champDao.addVertex(VERTEX_TYPE, properties);
+//
+// // Validate that the returned {@link Vertex} has the right label assigned to it.
+// assertTrue("Unexpected vertex type '" + createdVertex.getType() + "' returned from DAO",
+// createdVertex.getType().equals(VERTEX_TYPE));
+//
+// // Validate that all of the properties that we provided to the DAO are in fact assigned
+// // to the {@link Vertex} that we got back.
+// assertTrue("Vertex property list returned from DAO did not contain all expected properties - expected: " +
+// properties.keySet() + " actual: " + createdVertex.getProperties().keySet(),
+// createdVertex.getProperties().keySet().containsAll(properties.keySet()));
+//
+// // Validate that the values assigned to the properties in the returned {@link Vertex}
+// // match the ones that we provided.
+// for (String propertyKey : properties.keySet()) {
+//
+// assertTrue(createdVertex.getProperties().get(propertyKey).equals(properties.get(propertyKey)));
+// }
+// }
+//
+//
+// /**
+// * Tests the ability of the {@link ChampDao} to retrieve a vertex from the graph data store
+// * by its unique identifier.
+// *
+// * @throws CrudException
+// */
+// @Test
+// public void getVertexByIdTest() throws CrudException {
+//
+// String VERTEX_TYPE = "Test_Vertex";
+//
+// Map<String, Object> properties = new HashMap<String, Object>();
+// properties.put("property1", "something");
+// properties.put("property2", "something else");
+//
+// // Create the vertex.
+// Vertex createdVertex = champDao.addVertex(VERTEX_TYPE, properties);
+//
+// // Make sure the {@link Vertex} returned from the create method includes an id that we can
+// // use to retrieve it.
+// assertTrue("No valid id returned for the created vertex", createdVertex.getId().isPresent());
+//
+// // Now, retrieve the {@link Vertex} by its identifier.
+// Vertex retrievedVertex = champDao.getVertex(createdVertex.getId().get(), VERTEX_TYPE);
+//
+// // Validate that the retrieved {@link Vertex} has the right label assigned to it.
+// assertTrue("Unexpected vertex type '" + retrievedVertex.getType() + "' returned from DAO",
+// retrievedVertex.getType().equals(VERTEX_TYPE));
+//
+// // Validate that all of the properties that we provided when we created the {@link Vertex}
+// // are present in the {@link Vertex} that we retrieved.
+// assertTrue("Vertex property list returned from DAO did not contain all expected properties - expected: " +
+// properties.keySet() + " actual: " + retrievedVertex.getProperties().keySet(),
+// retrievedVertex.getProperties().keySet().containsAll(properties.keySet()));
+//
+// // Validate that the values assigned to the properties in the retrieved {@link Vertex}
+// // match the ones that we provided when we created it.
+// for (String propertyKey : properties.keySet()) {
+//
+// assertTrue(retrievedVertex.getProperties().get(propertyKey).equals(properties.get(propertyKey)));
+// }
+// }
+//
+//
+// /**
+// * Tests the ability of the {@link ChampDao} to update an already existing vertex.
+// *
+// * @throws CrudException
+// */
+// @Test
+// public void updateVertexTest() throws CrudException {
+//
+// final String VERTEX_TYPE = "Test_Vertex";
+//
+// Map<String, Object> properties = new HashMap<String, Object>();
+// properties.put("property1", "something");
+// properties.put("property2", "something else");
+//
+// // Create the vertex.
+// Vertex createdVertex = champDao.addVertex(VERTEX_TYPE, properties);
+//
+// // Make sure the {@link Vertex} returned from the create method includes an id that we can
+// // use to retrieve it.
+// assertTrue("No valid id returned for the created vertex", createdVertex.getId().isPresent());
+//
+// // Modify the properties list...
+// properties.put("property3", "a new property");
+// properties.remove("property1");
+//
+// // ...and apply it to our vertex.
+// Vertex updatedVertex = champDao.updateVertex(createdVertex.getId().get(), createdVertex.getType(), properties);
+//
+// assertTrue("Vertex property list returned from DAO update operation did not contain all expected properties - expected: " +
+// properties.keySet() + " actual: " + updatedVertex.getProperties().keySet(),
+// updatedVertex.getProperties().keySet().containsAll(properties.keySet()));
+//
+// // Validate that the values assigned to the properties in the updated {@link Vertex}
+// // match the ones that we provided when we created it.
+// for (String propertyKey : properties.keySet()) {
+//
+// assertTrue("Unexpected value for property '" + propertyKey + "' - Expected: " +
+// properties.get(propertyKey) + " Actual: " +
+// updatedVertex.getProperties().get(propertyKey),
+// updatedVertex.getProperties().get(propertyKey).equals(properties.get(propertyKey)));
+// }
+//
+// // Validate that the property that we removed is NOT in the set of properties from our
+// // updated {@link Vertex}.
+// assertFalse("Property 'property1' should no longer be associated with updated vertex",
+// updatedVertex.getProperties().containsKey("property1"));
+// }
+//
+//
+// /**
+// * Tests the ability of the {@link ChampDao} to retrieve multiple vertices which match
+// * a particular set of supplied properties.
+// *
+// * @throws CrudException
+// */
+// @Test
+// public void getVerticesTest() throws CrudException {
+//
+// final String FIRST_VERTEX_TYPE = "pserver";
+// final String SECOND_VERTEX_TYPE = "complex";
+//
+// // Create some vertices.
+//
+// Map<String, Object> vertex1Properties = new HashMap<String, Object>();
+// vertex1Properties.put("O/S", "Linux");
+// vertex1Properties.put("version", "6.5");
+// vertex1Properties.put("hostname", "kll0001");
+// champDao.addVertex(FIRST_VERTEX_TYPE, vertex1Properties);
+//
+// Map<String, Object> vertex2Properties = new HashMap<String, Object>();
+// vertex2Properties.put("O/S", "Linux");
+// vertex2Properties.put("version", "6.5");
+// vertex2Properties.put("hostname", "kll0002");
+// champDao.addVertex(FIRST_VERTEX_TYPE, vertex2Properties);
+//
+// Map<String, Object> vertex3Properties = new HashMap<String, Object>();
+// vertex3Properties.put("O/S", "Linux");
+// vertex3Properties.put("version", "7.2");
+// vertex3Properties.put("hostname", "kll0003");
+// champDao.addVertex(FIRST_VERTEX_TYPE, vertex3Properties);
+//
+// Map<String, Object> vertex4Properties = new HashMap<String, Object>();
+// vertex4Properties.put("O/S", "Windows");
+// vertex4Properties.put("version", "10");
+// vertex4Properties.put("hostname", "Dev Laptop");
+// champDao.addVertex(FIRST_VERTEX_TYPE, vertex4Properties);
+//
+// Map<String, Object> vertex5Properties = new HashMap<String, Object>();
+// vertex5Properties.put("Street", "Baker");
+// vertex5Properties.put("Number", "222B");
+// champDao.addVertex(SECOND_VERTEX_TYPE, vertex5Properties);
+//
+// // Create a set of properties to use for our query.
+// Map<String, Object> queryProperties = new HashMap<String, Object>();
+// queryProperties.put("O/S", "Linux");
+// queryProperties.put("version", "6.5");
+//
+// // Validate that we filter our 'get vertices' results by type
+// List<Vertex> allVerticesByType = champDao.getVertices(FIRST_VERTEX_TYPE, MapBuilder.builder().build());
+// for (Vertex v : allVerticesByType) {
+// assertTrue("Unexpected vertex type returned from query. Expected: " +
+// FIRST_VERTEX_TYPE + " Actual: " + v.getType(),
+// v.getType().equals(FIRST_VERTEX_TYPE));
+// }
+//
+// // Now, request the vertices that match our parameters.
+// List<Vertex> vertices = champDao.getVertices(FIRST_VERTEX_TYPE, queryProperties);
+//
+// // Validate that got back the expected number of vertices.
+// assertEquals(vertices.size(), 2);
+//
+// // Validate that the vertices we got back contain the expected parameters.
+// for (Vertex v : vertices) {
+//
+// assertTrue("Vertex from query result does not contain expected vertex 'O/S'",
+// v.getProperties().containsKey("O/S"));
+// assertTrue("Vertex from query result contains unexpected value for 'O/S' parameter - Expected: 'Linux' Actual: '" +
+// v.getProperties().get("O/S") + "'",
+// v.getProperties().get("O/S").equals("Linux"));
+//
+// assertTrue("Vertex from query result does not contain expected vertex 'O/S'",
+// v.getProperties().containsKey("version"));
+// assertTrue("Vertex from query result contains unexpected value for 'O/S' parameter - Expected: 'Linux' Actual: '" +
+// v.getProperties().get("O/S") + "'",
+// v.getProperties().get("version").equals("6.5"));
+// }
+// }
+//
+// @Test
+// public void deleteVertexTest() throws CrudException {
+//
+// boolean deletedVertexNotFound = false;
+//
+// // Create a vertex.
+// Vertex createdVertex = champDao.addVertex("test_type", MapBuilder.builder()
+// .withKeyValue("O/S", "Linux")
+// .withKeyValue("version", "6.5")
+// .withKeyValue("hostname", "kll0001")
+// .build());
+//
+// // Verify that we can retrieve the vertex from the graph data base.
+// Vertex retrievedVertex = champDao.getVertex(createdVertex.getId().get(), "test_type");
+//
+// // Now, delete the vertex.
+// champDao.deleteVertex(createdVertex.getId().get(), "test_type");
+//
+// // Now, try to retrieve it again. This time we should fail to find it.
+// try {
+// champDao.getVertex(createdVertex.getId().get(), "test_type");
+//
+// } catch (CrudException e) {
+// assertTrue(e.getMessage().contains("No vertex with id"));
+// deletedVertexNotFound = true;
+// }
+//
+// assertTrue("Should not have been able to retrieve deleted vertex", deletedVertexNotFound);
+// }
+//
+// @Test
+// public void createEdgeTest() throws CrudException {
+//
+// String EDGE_TYPE = "has";
+//
+// // Create the source vertex for the edge.
+// Map<String, Object> srcVertexProperties = new HashMap<String, Object>();
+// srcVertexProperties.put("O/S", "Linux");
+// srcVertexProperties.put("version", "6.5");
+// srcVertexProperties.put("hostname", "kll0001");
+// Vertex sourceVertex = champDao.addVertex("vserver", srcVertexProperties);
+//
+// // Create the target vertex for the edge.
+// Map<String, Object> dstVertexProperties = new HashMap<String, Object>();
+// dstVertexProperties.put("O/S", "Linux");
+// dstVertexProperties.put("version", "6.5");
+// dstVertexProperties.put("hostname", "kll0002");
+// Vertex destVertex = champDao.addVertex("VNF", dstVertexProperties);
+//
+// // Now, create the edge itself.
+// Map<String, Object> edgeProperties = new HashMap<String, Object>();
+// edgeProperties.put("prop", "val");
+// Edge createdEdge = champDao.addEdge("has", sourceVertex, destVertex, edgeProperties);
+//
+// // Validate that the Edge object returned from the create method matches what we were
+// // trying to create.
+// assertTrue("Unexpected type for Edge returned from create method. Expected: " + EDGE_TYPE
+// + " Actual: " + createdEdge.getType(),
+// createdEdge.getType().equals("has"));
+// assertTrue("Unexpected properties for Edge returned from create method. Expected: " + edgeProperties
+// + " Actual: " + createdEdge.getProperties(),
+// createdEdge.getProperties().equals(edgeProperties));
+//
+// }
+//
+// @Test
+// public void createEdgeWithMissingSrcOrTargetTest() throws CrudException {
+//
+// String EDGE_TYPE = "has";
+//
+// // Create the source vertex for the edge.
+// Map<String, Object> srcVertexProperties = new HashMap<String, Object>();
+// srcVertexProperties.put("O/S", "Linux");
+// srcVertexProperties.put("version", "6.5");
+// srcVertexProperties.put("hostname", "kll0001");
+// Vertex sourceVertex = champDao.addVertex("vserver", srcVertexProperties);
+//
+// // Create the target vertex for the edge.
+// Map<String, Object> dstVertexProperties = new HashMap<String, Object>();
+// dstVertexProperties.put("O/S", "Linux");
+// dstVertexProperties.put("version", "6.5");
+// dstVertexProperties.put("hostname", "kll0002");
+// Vertex destVertex = champDao.addVertex("VNF", dstVertexProperties);
+//
+// // Now, try creating the Edge but specify an id for the source vertex that does
+// // not exist.
+// Map<String, Object> edgeProperties = new HashMap<String, Object>();
+// edgeProperties.put("prop", "val");
+// try {
+// champDao.addEdge(EDGE_TYPE, new Vertex.Builder("miss").id("99").build(), destVertex, edgeProperties);
+// } catch (CrudException e) {
+// assertTrue(e.getMessage().contains("Error creating edge - source vertex"));
+// }
+//
+// // Now, try created the Edge with a valid source vertex, but specify an id for the
+// // target vertex that does not exist.
+// try {
+// champDao.addEdge(EDGE_TYPE, sourceVertex, new Vertex.Builder("miss").id("99").build(), edgeProperties);
+// } catch (CrudException e) {
+// assertTrue(e.getMessage().contains("Error creating edge - target vertex"));
+// }
+//
+// }
+//
+// @Test
+// public void getEdgeByIdTest() throws CrudException {
+//
+// String EDGE_TYPE = "has";
+//
+// // Create the source vertex for the edge.
+// Map<String, Object> srcVertexProperties = new HashMap<String, Object>();
+// srcVertexProperties.put("O/S", "Linux");
+// srcVertexProperties.put("version", "6.5");
+// srcVertexProperties.put("hostname", "kll0001");
+// Vertex sourceVertex = champDao.addVertex("vserver", srcVertexProperties);
+//
+// // Create the target vertex for the edge.
+// Map<String, Object> dstVertexProperties = new HashMap<String, Object>();
+// dstVertexProperties.put("O/S", "Linux");
+// dstVertexProperties.put("version", "6.5");
+// dstVertexProperties.put("hostname", "kll0002");
+// Vertex destVertex = champDao.addVertex("VNF", dstVertexProperties);
+//
+// // Now, create the edge itself.
+// Map<String, Object> edgeProperties = new HashMap<String, Object>();
+// edgeProperties.put("prop", "val");
+// Edge createdEdge = champDao.addEdge("has", sourceVertex, destVertex, edgeProperties);
+//
+// // Retrieve the edge we just created by specifying its unique identifier.
+// Edge retrievedEdge = champDao.getEdge(createdEdge.getId().get(), "has");
+//
+// // Validate that the contents of the object that we got back matches what we thought we
+// // created.
+// assertTrue("Unexpected type for Edge returned from get method. Expected: " + EDGE_TYPE
+// + " Actual: " + retrievedEdge.getType(),
+// retrievedEdge.getType().equals(EDGE_TYPE));
+// assertTrue("Unexpected properties for Edge returned from get method. Expected: " + edgeProperties
+// + " Actual: " + retrievedEdge.getProperties(),
+// retrievedEdge.getProperties().equals(edgeProperties));
+// }
+//
+// @Test
+// public void getEdgesTest() throws CrudException {
+//
+// final String EDGE_TYPE_HAS = "has";
+// final String EDGE_TYPE_RUNS = "runs";
+//
+// // Create some vertices and edges that we can query agains.
+// Vertex complex = champDao.addVertex("complex", MapBuilder.builder()
+// .withKeyValue("Province", "Ontario")
+// .withKeyValue("City", "Ottawa")
+// .withKeyValue("Street", "303 Terry Fox")
+// .build());
+//
+// Vertex vserver = champDao.addVertex("vserver", MapBuilder.builder()
+// .withKeyValue("O/S", "Linux")
+// .withKeyValue("version", "6.5")
+// .withKeyValue("hostname", "kll0001")
+// .build());
+//
+// Vertex vnf1 = champDao.addVertex("vserver", MapBuilder.builder()
+// .withKeyValue("Application", "OpenDaylight")
+// .build());
+//
+// Vertex vnf2 = champDao.addVertex("vserver", MapBuilder.builder()
+// .withKeyValue("Application", "Cammunda")
+// .build());
+//
+// Edge edge1 = champDao.addEdge(EDGE_TYPE_HAS, complex, vserver,
+// MapBuilder.builder()
+// .withKeyValue("usesResource", "false")
+// .withKeyValue("hasDelTarget", "false")
+// .build());
+//
+// Edge edge2 = champDao.addEdge(EDGE_TYPE_RUNS, vserver, vnf1,
+// MapBuilder.builder()
+// .withKeyValue("usesResource", "false")
+// .withKeyValue("hasDelTarget", "true")
+// .build());
+//
+// Edge edge3 = champDao.addEdge(EDGE_TYPE_RUNS, vserver, vnf2,
+// MapBuilder.builder()
+// .withKeyValue("usesResource", "false")
+// .withKeyValue("hasDelTarget", "false")
+// .build());
+//
+// // Query for all HAS edges.
+// List<Edge> hasEdges = champDao.getEdges(EDGE_TYPE_HAS, new HashMap<String, Object>());
+//
+// assertEquals("Unexpected number of edges of type 'has' found. Expected: 1 Actual: " + hasEdges.size(),
+// hasEdges.size(), 1);
+// assertTrue("Result of query for 'has' type edges does not contain the expected results",
+// containsEdge(edge1, hasEdges));
+//
+// // Query for all RUNS edges.
+// List<Edge> runsEdges = champDao.getEdges(EDGE_TYPE_RUNS, new HashMap<String, Object>());
+//
+// assertEquals("Unexpected number of edges of type 'runs' found. Expected: 2 Actual: " + runsEdges.size(),
+// runsEdges.size(), 2);
+// assertTrue("Result of query for 'runs' type edges does not contain the expected results",
+// containsEdge(edge2, runsEdges));
+// assertTrue("Result of query for 'runs' type edges does not contain the expected results",
+// containsEdge(edge2, runsEdges));
+//
+// // Query for all HAS edges with the property 'hasDelTarget' equal to 'true'.
+// List<Edge> runsEdgesWithDelTargetTrue =
+// champDao.getEdges(EDGE_TYPE_RUNS, MapBuilder.builder()
+// .withKeyValue("hasDelTarget", "true")
+// .build());
+//
+// assertEquals("Unexpected number of edges of type 'has' with 'hasDelTarget=true' found. Expected: 1 Actual: "
+// + runsEdgesWithDelTargetTrue.size(),
+// runsEdgesWithDelTargetTrue.size(), 1);
+// assertTrue("Result of query for 'runs' type edges with delTarget set to TRUE does not contain the expected results",
+// containsEdge(edge2, runsEdgesWithDelTargetTrue));
+// }
+//
+// @Test
+// @Ignore // For now - pending some expected fixes to the Champ library.
+// public void updateEdgeTest() throws CrudException {
+//
+// // Create the source vertex for the edge.
+// Vertex sourceVertex = champDao.addVertex("vserver", MapBuilder.builder()
+// .withKeyValue("O/S", "Linux")
+// .withKeyValue("version", "6.5")
+// .withKeyValue("hostname", "kll0001")
+// .build());
+//
+// // Create the target vertex for the edge.
+// Vertex destVertex = champDao.addVertex("VNF", MapBuilder.builder()
+// .withKeyValue("O/S", "Linux")
+// .withKeyValue("version", "6.5")
+// .withKeyValue("hostname", "kll0002")
+// .build());
+//
+// // Now, create the edge itself.
+// Edge createdEdge = champDao.addEdge("has",
+// sourceVertex,
+// destVertex,
+// MapBuilder.builder()
+// .withKeyValue("key1", "value1")
+// .withKeyValue("key2", "value2")
+// .withKeyValue("key3", "value3")
+// .build());
+//
+// // Make sure the Edge returned from the create method includes an id that we can
+// // use to retrieve it.
+// assertTrue("No valid id returned for the created edge", createdEdge.getId().isPresent());
+//
+// // Retrieve the properties map for our edge and make some changes.
+// Map<String, Object> properties = createdEdge.getProperties();
+// properties.put("key4", "value4");
+// properties.remove("key2");
+//
+// // Now update the edge with the new properties map.
+// Edge updatedEdge = champDao.updateEdge(createdEdge);
+//
+// assertTrue("Edge property list returned from DAO update operation did not contain all expected properties - expected: " +
+// properties.keySet() + " actual: " + updatedEdge.getProperties().keySet(),
+// updatedEdge.getProperties().keySet().containsAll(properties.keySet()));
+//
+// // Validate that the values assigned to the properties in the updated Edge
+// // match the ones that we provided when we created it.
+// for (String propertyKey : properties.keySet()) {
+//
+// assertTrue("Unexpected value for property '" + propertyKey + "' - Expected: " +
+// properties.get(propertyKey) + " Actual: " +
+// updatedEdge.getProperties().get(propertyKey),
+// updatedEdge.getProperties().get(propertyKey).equals(properties.get(propertyKey)));
+// }
+//
+// // Validate that the property that we removed is NOT in the set of properties from our
+// // updated edge.
+// // *** We will leave this validation commented out for now, as the Champ library actually
+// // merges update properties instead of replacing them...
+//// assertFalse("Property 'key2' should no longer be associated with updated edge",
+//// updatedEdge.getProperties().containsKey("key2"));
+// }
+//
+// @Test
+// public void deleteEdgeTest() throws CrudException {
+//
+// boolean deletedEdgeNotFound = false;
+//
+// // Create the source vertex for the edge.
+// Vertex sourceVertex = champDao.addVertex("vserver", MapBuilder.builder()
+// .withKeyValue("O/S", "Linux")
+// .withKeyValue("version", "6.5")
+// .withKeyValue("hostname", "kll0001")
+// .build());
+//
+// // Create the target vertex for the edge.
+// Vertex destVertex = champDao.addVertex("VNF", MapBuilder.builder()
+// .withKeyValue("O/S", "Linux")
+// .withKeyValue("version", "6.5")
+// .withKeyValue("hostname", "kll0002")
+// .build());
+//
+// // Now, create the edge itself.
+// Edge createdEdge = champDao.addEdge("has",
+// sourceVertex,
+// destVertex,
+// MapBuilder.builder()
+// .withKeyValue("key1", "value1")
+// .withKeyValue("key2", "value2")
+// .withKeyValue("key3", "value3")
+// .build());
+//
+// // Verify that we can retrieve the edge that we just created.
+// Edge retrievedEdge = champDao.getEdge(createdEdge.getId().get(), "has");
+//
+// // Now, delete it.
+// champDao.deleteEdge(createdEdge.getId().get(), "has");
+//
+// // Try retrieving it again. This time we should not find it.
+// try {
+// champDao.getEdge(createdEdge.getId().get(), "has");
+// } catch (CrudException e) {
+//
+// assertTrue(e.getMessage().contains("No edge with id"));
+// deletedEdgeNotFound = true;
+// }
+//
+// assertTrue("Should not have been able to retrieve deleted edge.", deletedEdgeNotFound);
+// }
+//
+// private boolean containsEdge(Edge anEdge, List<Edge> edges) {
+//
+// for (Edge e : edges) {
+// if (e.getId().isPresent() && anEdge.getId().isPresent() && (e.getId().get().equals(anEdge.getId().get()))) {
+// return true;
+// }
+//
+// }
+// return false;
+// }
+//
+// public static class MapBuilder {
+//
+// private Map<String, Object> map;
+//
+// private MapBuilder() {
+// map = new HashMap<String, Object>();
+// }
+//
+// public static MapBuilder builder() {
+// return new MapBuilder();
+// }
+//
+// public MapBuilder withKeyValue(String key, Object value) {
+// map.put(key, value);
+// return this;
+// }
+//
+// public Map<String, Object> build() {
+// return map;
+// }
+// }
}