From b348af8ed2c4192f88169b37bf53fa25b8a7a681 Mon Sep 17 00:00:00 2001 From: "Sotiropoulos, Ioannis (is948x)" Date: Fri, 15 Jun 2018 15:32:01 +0100 Subject: ETags on resources An etag should be generated (by Champ) when creating a resource (edge or vertex). The Champ microservice should return this etag in the response header. Gizmo should also return the etag in it's response header (Gizmo will receive the etag from Champ). Issue-ID: AAI-1196 Change-Id: Ie16f871eccbceeccde037e73e0de0d96eeba18bd Signed-off-by: Sotiropoulos, Ioannis (is948x) --- src/test/java/org/onap/crud/dao/TestDao.java | 194 ----------------- .../org/onap/crud/service/CrudRestServiceTest.java | 45 ++-- src/test/java/org/onap/crud/service/TestDao.java | 235 +++++++++++++++++++++ .../org/onap/crud/util/etag/EtagGeneratorTest.java | 168 +++++++++++++++ 4 files changed, 430 insertions(+), 212 deletions(-) delete mode 100644 src/test/java/org/onap/crud/dao/TestDao.java create mode 100644 src/test/java/org/onap/crud/service/TestDao.java create mode 100644 src/test/java/org/onap/crud/util/etag/EtagGeneratorTest.java (limited to 'src/test') diff --git a/src/test/java/org/onap/crud/dao/TestDao.java b/src/test/java/org/onap/crud/dao/TestDao.java deleted file mode 100644 index 69ce4a3..0000000 --- a/src/test/java/org/onap/crud/dao/TestDao.java +++ /dev/null @@ -1,194 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.crud.dao; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; - -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 champEdge = "{" + - "\"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 queryParams) - throws CrudException { - return Vertex.fromJson(champVertex, "v11"); - } - - @Override - public List getVertexEdges(String id, Map queryParams) throws CrudException { - List list = new ArrayList(); - list.add(Edge.fromJson(champEdge)); - return list; - } - - @Override - public List getVertices(String type, Map filter, String version) throws CrudException { - List list = new ArrayList(); - list.add(Vertex.fromJson(champVertex, "v11")); - return list; - } - - @Override - public List getVertices(String type, Map filter, HashSet properties, String version) - throws CrudException { - List list = new ArrayList(); - list.add(Vertex.fromJson(champVertex, "v11")); - return list; - } - - @Override - public Edge getEdge(String id, String type, Map queryParams) throws CrudException { - return Edge.fromJson(champEdge); - } - - @Override - public List getEdges(String type, Map filter) throws CrudException { - List list = new ArrayList(); - list.add(Edge.fromJson(champEdge)); - return list; - } - - @Override - public Vertex addVertex(String type, Map properties, String version) throws CrudException { - return Vertex.fromJson(champVertex, "v11"); - } - - @Override - public Vertex updateVertex(String id, String type, Map properties, String version) - throws CrudException { - return Vertex.fromJson(champVertex, "v11"); - } - - @Override - public void deleteVertex(String id, String type) throws CrudException { - - } - - @Override - public Edge addEdge(String type, Vertex source, Vertex target, Map properties, String version) - throws CrudException { - return Edge.fromJson(champEdge); - } - - @Override - public Edge updateEdge(Edge edge) throws CrudException { - return Edge.fromJson(champEdge); - } - - @Override - public void deleteEdge(String id, String type) throws CrudException { - - } - - @Override - public String openTransaction() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void commitTransaction(String id) throws CrudException { - // TODO Auto-generated method stub - - } - - @Override - public void rollbackTransaction(String id) throws CrudException { - // TODO Auto-generated method stub - - } - - @Override - public boolean transactionExists(String id) throws CrudException { - // TODO Auto-generated method stub - return false; - } - - @Override - public Vertex addVertex(String type, Map properties, String version, String txId) - throws CrudException { - return Vertex.fromJson(champVertex, "v11"); - } - - @Override - public Edge addEdge(String type, Vertex source, Vertex target, Map properties, String version, - String txId) throws CrudException { - return Edge.fromJson(champEdge); - } - - @Override - public Vertex updateVertex(String id, String type, Map properties, String version, String txId) - throws CrudException { - return Vertex.fromJson(champVertex, "v11"); - } - - @Override - public Edge updateEdge(Edge edge, String txId) throws CrudException { - return Edge.fromJson(champEdge); - } - - @Override - public void deleteVertex(String id, String type, String txId) throws CrudException { - // TODO Auto-generated method stub - - } - - @Override - public void deleteEdge(String id, String type, String txId) throws CrudException { - // TODO Auto-generated method stub - - } - - @Override - public Edge getEdge(String id, String type, String txId) throws CrudException { - return Edge.fromJson(champEdge); - } - -} diff --git a/src/test/java/org/onap/crud/service/CrudRestServiceTest.java b/src/test/java/org/onap/crud/service/CrudRestServiceTest.java index 13cba11..68c876c 100644 --- a/src/test/java/org/onap/crud/service/CrudRestServiceTest.java +++ b/src/test/java/org/onap/crud/service/CrudRestServiceTest.java @@ -26,8 +26,6 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.Response; @@ -37,8 +35,8 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.Mockito; -import org.onap.crud.dao.TestDao; import org.onap.crud.exception.CrudException; +import org.onap.crud.service.TestDao; import org.onap.crud.service.util.TestHeaders; import org.onap.crud.service.util.TestRequest; import org.onap.crud.service.util.TestUriInfo; @@ -80,18 +78,18 @@ public class CrudRestServiceTest { @Before public void init() throws Exception { - Path resourcePath = Paths.get(ClassLoader.getSystemResource("model").toURI()); - Path parentPath = resourcePath.getParent(); + ClassLoader classLoader = getClass().getClassLoader(); + File dir = new File(classLoader.getResource("model").getFile()); + System.setProperty("CONFIG_HOME", dir.getParent()); + EdgeRulesLoader.resetSchemaVersionContext(); - System.setProperty("CONFIG_HOME", parentPath.toString()); - EdgeRulesLoader.resetSchemaVersionContext (); - CrudGraphDataService service = new CrudGraphDataService(new TestDao()); - CrudRestService restService = new CrudRestService(service, null); - mockService = Mockito.spy(restService); - - Mockito.doReturn(true).when(mockService).validateRequest(Mockito.any(HttpServletRequest.class), - Mockito.anyString(), Mockito.anyString(), Mockito.any(CrudRestService.Action.class), Mockito.anyString(), - Mockito.any(HttpHeaders.class)); + CrudGraphDataService service = new CrudGraphDataService(new TestDao()); + CrudRestService restService = new CrudRestService(service, null); + mockService = Mockito.spy(restService); + + Mockito.doReturn(true).when(mockService).validateRequest(Mockito.any(HttpServletRequest.class), + Mockito.anyString(), Mockito.anyString(), Mockito.any(CrudRestService.Action.class), Mockito.anyString(), + Mockito.any(HttpHeaders.class)); } @Test @@ -123,21 +121,25 @@ public class CrudRestServiceTest { new TestHeaders(), null, new TestRequest()); System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString()); assertTrue(response.getStatus() == 400); + Assert.assertNull(response.getEntityTag()); response = mockService.addVertex(postVertexPayload, "v11", "services/inventory/v11", new TestHeaders(), null, new TestRequest()); System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString()); assertTrue(response.getStatus() == 201); + Assert.assertEquals(response.getEntityTag().getValue(), "test123"); response = mockService.addVertex(postMissingPropVertexPayload, "v11", "pserver", "services/inventory/v11", new TestHeaders(), null, new TestRequest()); System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString()); - assertTrue(response.getStatus() == 400); + assertTrue(response.getStatus() == 400); + Assert.assertNull(response.getEntityTag()); response = mockService.addVertex(postVertexPayload, "v11", "pserver", "services/inventory/v11", new TestHeaders(), null, new TestRequest()); System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString()); - assertTrue(response.getStatus() == 201); + assertTrue(response.getStatus() == 201); + Assert.assertEquals(response.getEntityTag().getValue(), "test123"); } @Test @@ -148,11 +150,13 @@ public class CrudRestServiceTest { new TestHeaders(), null, new TestRequest()); System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString()); assertTrue(response.getStatus() == 201); + Assert.assertEquals(response.getEntityTag().getValue(), "test123"); response = mockService.addEdge(postEdgePayload, "v11", "tosca.relationships.HostedOn", "services/inventory/v11", new TestHeaders(), null, new TestRequest()); System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString()); - assertTrue(response.getStatus() == 201); + assertTrue(response.getStatus() == 201); + Assert.assertEquals(response.getEntityTag().getValue(), "test123"); } @Test @@ -170,19 +174,22 @@ public class CrudRestServiceTest { response = mockService.updateVertex(putVertexPayload, "v11", "pserver", "bad-id", "services/inventory/v11", new TestHeaders(), null, new TestRequest()); System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString()); - assertTrue(response.getStatus() == 400); + assertTrue(response.getStatus() == 400); + Assert.assertNull(response.getEntityTag()); // Success case response = mockService.updateVertex(putVertexPayload, "v11", "pserver", "test-uuid", "services/inventory/v11", new TestHeaders(), null, new TestRequest()); System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString()); assertTrue(response.getStatus() == 200); + Assert.assertEquals(response.getEntityTag().getValue(), "test123"); // Patch response = mockService.patchVertex(putVertexPayload, "v11", "pserver", "test-uuid", "services/inventory/v11", new TestHeaders(), null, new TestRequest()); System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString()); assertTrue(response.getStatus() == 200); + Assert.assertEquals(response.getEntityTag().getValue(), "test123"); } @Test @@ -193,12 +200,14 @@ public class CrudRestServiceTest { "services/inventory/v11", new TestHeaders(), null, new TestRequest()); System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString()); assertTrue(response.getStatus() == 200); + Assert.assertEquals(response.getEntityTag().getValue(), "test123"); // Patch response = mockService.patchEdge(postEdgePayload, "v11", "tosca.relationships.HostedOn", "my-uuid", "services/inventory/v11", new TestHeaders(), null, new TestRequest()); System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString()); assertTrue(response.getStatus() == 200); + Assert.assertEquals(response.getEntityTag().getValue(), "test123"); } @Test diff --git a/src/test/java/org/onap/crud/service/TestDao.java b/src/test/java/org/onap/crud/service/TestDao.java new file mode 100644 index 0000000..d412163 --- /dev/null +++ b/src/test/java/org/onap/crud/service/TestDao.java @@ -0,0 +1,235 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +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\"," + + "\"properties\": {" + + "\"prevent-delete\": \"NONE\" }," + + "\"source\": {" + + "\"key\": \"50bdab41-ad1c-4d00-952c-a0aa5d827811\", \"type\": \"vserver\"}," + + "\"target\": {" + + "\"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 OperationResult getVertex(String id, String type, String version, Map queryParams) + throws CrudException { + OperationResult operationResult = new OperationResult(); + operationResult.setResult(champVertex); + return operationResult; + } + + @Override + public List getVertexEdges(String id, Map queryParams) throws CrudException { + List list = new ArrayList(); + list.add(Edge.fromJson(champEdge)); + return list; + } + + @Override + public OperationResult getVertices(String type, Map filter, String version) throws CrudException { + OperationResult operationResult = new OperationResult(); + operationResult.setResult(champVertices); + return operationResult; + } + + @Override + public OperationResult getVertices(String type, Map filter, HashSet properties, String version) + throws CrudException { + OperationResult operationResult = new OperationResult(); + operationResult.setResult(champVertices); + return operationResult; + } + + @Override + public OperationResult getEdge(String id, String type, Map queryParams) throws CrudException { + OperationResult operationResult = new OperationResult(); + operationResult.setResult(champEdge); + return operationResult; + } + + @Override + public OperationResult getEdges(String type, Map filter) throws CrudException { + OperationResult operationResult = new OperationResult(); + operationResult.setResult(champEdges); + return operationResult; + } + + @Override + public OperationResult addVertex(String type, Map properties, String version) throws CrudException { + OperationResult operationResult = new OperationResult(); + operationResult.setHeaders(addReponseHeader()); + operationResult.setResult(champVertex); + return operationResult; + } + + @Override + public OperationResult updateVertex(String id, String type, Map properties, String version) + throws CrudException { + OperationResult operationResult = new OperationResult(); + operationResult.setHeaders(addReponseHeader()); + operationResult.setResult(champVertex); + return operationResult; + } + + @Override + public void deleteVertex(String id, String type) throws CrudException { + + } + + @Override + public OperationResult addEdge(String type, Vertex source, Vertex target, Map properties, String version) + throws CrudException { + OperationResult operationResult = new OperationResult(); + operationResult.setHeaders(addReponseHeader()); + operationResult.setResult(champEdge); + return operationResult; + } + + @Override + public OperationResult updateEdge(Edge edge) throws CrudException { + OperationResult operationResult = new OperationResult(); + operationResult.setHeaders(addReponseHeader()); + operationResult.setResult(champEdge); + return operationResult; + } + + @Override + public void deleteEdge(String id, String type) throws CrudException { + + } + + @Override + public String openTransaction() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void commitTransaction(String id) throws CrudException { + // TODO Auto-generated method stub + + } + + @Override + public void rollbackTransaction(String id) throws CrudException { + // TODO Auto-generated method stub + + } + + @Override + public boolean transactionExists(String id) throws CrudException { + // TODO Auto-generated method stub + return false; + } + + @Override + public Vertex addVertex(String type, Map properties, String version, String txId) + throws CrudException { + return Vertex.fromJson(champVertex, "v11"); + } + + @Override + public Edge addEdge(String type, Vertex source, Vertex target, Map properties, String version, + String txId) throws CrudException { + return Edge.fromJson(champEdge); + } + + @Override + public Vertex updateVertex(String id, String type, Map properties, String version, String txId) + throws CrudException { + return Vertex.fromJson(champVertex, "v11"); + } + + @Override + public Edge updateEdge(Edge edge, String txId) throws CrudException { + return Edge.fromJson(champEdge); + } + + @Override + public void deleteVertex(String id, String type, String txId) throws CrudException { + // TODO Auto-generated method stub + + } + + @Override + public void deleteEdge(String id, String type, String txId) throws CrudException { + // TODO Auto-generated method stub + + } + + @Override + public Edge getEdge(String id, String type, String txId) throws CrudException { + return Edge.fromJson(champEdge); + } + + private MultivaluedMap addReponseHeader() { + MultivaluedMap headers = new MultivaluedHashMap(); + headers.add("etag", "test123"); + return headers; + } +} \ No newline at end of file diff --git a/src/test/java/org/onap/crud/util/etag/EtagGeneratorTest.java b/src/test/java/org/onap/crud/util/etag/EtagGeneratorTest.java new file mode 100644 index 0000000..c4f7c38 --- /dev/null +++ b/src/test/java/org/onap/crud/util/etag/EtagGeneratorTest.java @@ -0,0 +1,168 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.crud.util.etag; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.junit.Assert.assertThat; +import java.io.IOException; +import java.security.NoSuchAlgorithmException; +import org.junit.Before; +import org.junit.Test; +import org.onap.crud.event.GraphEventEdge; +import org.onap.crud.event.GraphEventVertex; +import org.onap.crud.util.etag.EtagGenerator; +import com.google.gson.JsonObject; + +public class EtagGeneratorTest { + + private EtagGenerator etagGenerator; + + @Before + public void init() throws NoSuchAlgorithmException { + etagGenerator = new EtagGenerator(); + } + + private GraphEventVertex createVertex(String propKey, String propValue) { + JsonObject properties = new JsonObject(); + properties.addProperty(propKey, propValue); + GraphEventVertex vertex = new GraphEventVertex("vertex1", "v11", "pserver", properties); + return vertex; + } + + private GraphEventEdge createEdge(String id, GraphEventVertex source, GraphEventVertex target, String propKey, + String propValue) { + JsonObject properties = new JsonObject(); + properties.addProperty(propKey, propValue); + GraphEventEdge edge = new GraphEventEdge(id, "v11", "tosca.relationships.HostedOn", source, target, properties); + return edge; + } + + @Test + public void computeHashForIdenticalVertexObjects() throws IOException { + // everything is same + GraphEventVertex sourceVertex1 = createVertex("prop1", "value1"); + GraphEventVertex targetVertex1 = createVertex("prop2", "value2"); + + GraphEventEdge edge1 = createEdge("edge1", sourceVertex1, targetVertex1, "prop1", "value1"); + + GraphEventVertex sourceVertex2 = createVertex("prop1", "value1"); + GraphEventVertex targetVertex2 = createVertex("prop2", "value2"); + + GraphEventEdge edge2 = createEdge("edge1", sourceVertex2, targetVertex2, "prop1", "value1"); + + assertThat(etagGenerator.computeHashForEdge(edge1), is(etagGenerator.computeHashForEdge(edge2))); + } + + @Test + public void computeHashForVertexObjectsWithDifferentKey() throws IOException { + // key is different + GraphEventVertex sourceVertex1 = createVertex("prop1", "value1"); + GraphEventVertex targetVertex1 = createVertex("prop2", "value2"); + + GraphEventEdge edge1 = createEdge("edge1", sourceVertex1, targetVertex1, "prop1", "value1"); + + GraphEventVertex sourceVertex2 = createVertex("prop1", "value1"); + GraphEventVertex targetVertex2 = createVertex("prop2", "value2"); + + GraphEventEdge edge2 = createEdge("edge2", sourceVertex2, targetVertex2, "prop1", "value1"); + + assertThat(etagGenerator.computeHashForEdge(edge1), not(etagGenerator.computeHashForEdge(edge2))); + } + + @Test + public void computeHashForVertexObjectsWithDifferentEdge() throws IOException { + // relationship is different + GraphEventVertex sourceVertex1 = createVertex("prop1", "value1"); + GraphEventVertex targetVertex1 = createVertex("prop2", "value2"); + + GraphEventEdge edge1 = createEdge("edge1", sourceVertex1, targetVertex1, "prop1", "value1"); + + GraphEventVertex sourceVertex2 = createVertex("prop1", "value1"); + GraphEventVertex targetVertex2 = createVertex("prop2", "value2"); + + GraphEventEdge edge2 = createEdge("edge2", sourceVertex2, targetVertex2, "prop1", "value1"); + edge2.setType("tosca.relationships.RelatedTo"); + + assertThat(etagGenerator.computeHashForEdge(edge1), not(etagGenerator.computeHashForEdge(edge2))); + } + + @Test + public void computeHashForEdgeObjectsWithDifferentVertexObjects() throws IOException { + // source/target different + GraphEventVertex sourceVertex1 = createVertex("prop1", "value1"); + GraphEventVertex targetVertex1 = createVertex("prop2", "value2"); + targetVertex1.setId("vertex2"); + + GraphEventEdge edge1 = createEdge("edge1", sourceVertex1, targetVertex1, "prop1", "value1"); + + GraphEventVertex sourceVertex2 = createVertex("prop1", "value1"); + GraphEventVertex targetVertex2 = createVertex("prop2", "value2"); + + GraphEventEdge edge2 = createEdge("edge2", sourceVertex2, targetVertex2, "prop1", "value1"); + edge2.setType("tosca.relationships.RelatedTo"); + + assertThat(etagGenerator.computeHashForEdge(edge1), not(etagGenerator.computeHashForEdge(edge2))); + } + + @Test + public void computeHashForEdgeObjectsWithDifferentProperties() throws IOException { + // property different + GraphEventVertex sourceVertex1 = createVertex("sourceprop1", "value1"); + GraphEventVertex targetVertex1 = createVertex("targetprop2", "value2"); + + GraphEventEdge edge1 = createEdge("edge1", sourceVertex1, targetVertex1, "edgeprop1", "value1"); + + GraphEventVertex sourceVertex2 = createVertex("sourceprop1", "value1"); + GraphEventVertex targetVertex2 = createVertex("targetprop2", "value2"); + + GraphEventEdge edge2 = createEdge("edge1", sourceVertex2, targetVertex2, "edgeprop2", "value2"); + + assertThat(etagGenerator.computeHashForEdge(edge1), not(etagGenerator.computeHashForEdge(edge2))); + } + + @Test + public void testComputeHashForIdenticalVertexObjects() throws IOException { + GraphEventVertex sourceVertex1 = createVertex("prop1", "value1"); + GraphEventVertex targetVertex1 = createVertex("prop1", "value1"); + assertThat(etagGenerator.computeHashForVertex(sourceVertex1), + is(etagGenerator.computeHashForVertex(targetVertex1))); + } + + @Test + public void testComputeHashForVertexObjectsWithDifferentProperties() throws IOException { + GraphEventVertex sourceVertex1 = createVertex("prop1", "value1"); + GraphEventVertex targetVertex1 = createVertex("prop2", "value2"); + assertThat(etagGenerator.computeHashForVertex(sourceVertex1), + not(etagGenerator.computeHashForVertex(targetVertex1))); + } + + @Test + public void testComputeHashForChampObjectsWithDifferentKey() throws IOException { + GraphEventVertex sourceVertex1 = createVertex("prop1", "value1"); + GraphEventVertex targetVertex1 = createVertex("prop1", "value1"); + targetVertex1.setId("vertex2"); + assertThat(etagGenerator.computeHashForVertex(sourceVertex1), + not(etagGenerator.computeHashForVertex(targetVertex1))); + } + + +} \ No newline at end of file -- cgit 1.2.3-korg