diff options
author | shrek2000 <orenkle@amdocs.com> | 2019-03-28 16:29:17 +0200 |
---|---|---|
committer | Avi Gaffa <avi.gaffa@amdocs.com> | 2019-03-30 07:53:05 +0000 |
commit | 969a4e89e2363f76212623d9e563665804682fcf (patch) | |
tree | 72edd634ca657513394b52b26eef5537d089e4a4 /catalog-dao/src/test/java/org | |
parent | 5c980e10f4f6ef92a67de9cc1bd6f0043b4848be (diff) |
Heal Vertex Data
Enable healing of vertex information when reading it.
Issue-ID: SDC-2213
Change-Id: I907beeb25bd231d9e05d3a5b8e070d6bdf9cb781
Signed-off-by: shrek2000 <orenkle@amdocs.com>
Diffstat (limited to 'catalog-dao/src/test/java/org')
-rw-r--r-- | catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/HealingPipelineDaoTest.java | 315 | ||||
-rw-r--r-- | catalog-dao/src/test/java/org/openecomp/sdc/be/resources/HealVersionTest.java | 33 |
2 files changed, 348 insertions, 0 deletions
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/HealingPipelineDaoTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/HealingPipelineDaoTest.java new file mode 100644 index 0000000000..83b68920b9 --- /dev/null +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/HealingPipelineDaoTest.java @@ -0,0 +1,315 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdc.be.dao.cassandra; + +import com.google.common.collect.ImmutableListMultimap; +import com.thinkaurelius.titan.core.TitanVertex; +import com.thinkaurelius.titan.graphdb.relations.StandardVertexProperty; +import com.thinkaurelius.titan.graphdb.types.system.EmptyVertex; +import com.thinkaurelius.titan.graphdb.types.system.ImplicitKey; +import java.util.HashMap; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge; +import org.openecomp.sdc.be.dao.graph.datatype.GraphNode; +import org.openecomp.sdc.be.dao.impl.HealingPipelineDao; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.dao.jsongraph.heal.*; +import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; +import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels; +import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; +import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; + +import java.util.Map; +import java.util.Optional; + +import static org.junit.Assert.*; + +public class HealingPipelineDaoTest { + + + @Test + public void shouldUpgrade() { + HealingPipelineDao healingPipelineDao = new HealingPipelineDao(); + healingPipelineDao.setHealVersion(3); + healingPipelineDao.initHealVersion(); + healingPipelineDao.initGraphHealers(); + final HealVersion<Integer> version3 = HealVersionBuilder.build(3); + assertFalse(healingPipelineDao.shouldHeal(HealVersionBuilder.build(2), version3)); + assertFalse(healingPipelineDao.shouldHeal(version3, version3)); + assertTrue(healingPipelineDao.shouldHeal(HealVersionBuilder.build(2), HealVersionBuilder.build(1))); + } + + + @Test + public void testPipelineFilter3Attributes() { + // init data + HealingPipelineDao healingPipelineDao = new HealingPipelineDao(); + healingPipelineDao.setHealVersion(7); + healingPipelineDao.initHealVersion(); + healingPipelineDao.initGraphHealers(); + healingPipelineDao.setHealingPipeline(createPipelineMap()); + + assertEquals(2, + healingPipelineDao.getHealersForVertex(EdgeLabelEnum.ATTRIBUTES.name(), HealVersionBuilder.build(5)).size()); + + GraphVertex graphVertex = new GraphVertex(); + final int version = 5; + graphVertex.addMetadataProperty(GraphPropertyEnum.HEALING_VERSION, Integer.valueOf(version)); + + // perform test + + Optional optional = healingPipelineDao.performGraphReadHealing(graphVertex, EdgeLabelEnum.ATTRIBUTES); + assertTrue(optional.isPresent()); + final GraphVertex changedVertex = (GraphVertex) optional.get(); + + //validate result + final Object healVersion = changedVertex.getMetadataProperties().get(GraphPropertyEnum.HEALING_VERSION); + assertNotNull(healVersion); + assertTrue(healVersion instanceof Integer); + assertEquals(healingPipelineDao.getCurrentHealVersion().getVersion().intValue(), ((Integer) healVersion).intValue()); + } + + @Test + public void testPipelineFilter3AttributesTitanVertex() { + // init data + HealingPipelineDao healingPipelineDao = new HealingPipelineDao(); + healingPipelineDao.setHealVersion(7); + healingPipelineDao.initHealVersion(); + healingPipelineDao.initGraphHealers(); + healingPipelineDao.setHealingPipeline(createPipelineMap()); + + assertEquals(2, + healingPipelineDao.getHealersForVertex(GraphEdgeLabels.CAPABILITY.getProperty(), HealVersionBuilder.build(5)).size()); + TitanVertex titanVertex = Mockito.mock(TitanVertex.class); + final int version = 5; + StandardVertexProperty vertexProperty = new StandardVertexProperty(1, ImplicitKey.ID, new EmptyVertex(), version, (byte) 1); + Mockito.when(titanVertex.property(GraphPropertyEnum.HEALING_VERSION.getProperty())).thenReturn(vertexProperty); + + // perform test + + Optional optional = healingPipelineDao.performGraphReadHealing(titanVertex, GraphEdgeLabels.CAPABILITY); + assertTrue(optional.isPresent()); + final TitanVertex changedVertex = (TitanVertex) optional.get(); + + //validate result + assertNotNull(changedVertex); + + } + + @Test + public void testPipelineFilterGenericTitanDao() { + // init data + HealingPipelineDao healingPipelineDao = new HealingPipelineDao(); + healingPipelineDao.setHealVersion(7); + healingPipelineDao.initHealVersion(); + healingPipelineDao.initGraphHealers(); + healingPipelineDao.setHealingPipeline(createPipelineMap()); + assertEquals(1, + + healingPipelineDao.getHealersForVertex(GraphEdgeLabels.ATTRIBUTE.getProperty(), HealVersionBuilder.build(6)).size()); + + GraphNode mockGraphNode = new MockGraphNode(NodeTypeEnum.Attribute); + final int version = 5; + mockGraphNode.setHealingVersion(Integer.valueOf(version)); + + // perform test + + Optional optional = healingPipelineDao.performGraphReadHealing(mockGraphNode,createGraphEdge(GraphEdgeLabels.ATTRIBUTE)); + assertTrue(optional.isPresent()); + final GraphNode changedVertex = (GraphNode) optional.get(); + + //validate result + final Integer healVersion = changedVertex.getHealingVersion(); + assertNotNull(healVersion); + assertEquals(healingPipelineDao.getCurrentHealVersion().getVersion(), healVersion); + } + + @Test + public void testPipelineFilterTitanGraph1Attributes() { + // init data + HealingPipelineDao healingPipelineDao = new HealingPipelineDao(); + healingPipelineDao.setHealVersion(7); + healingPipelineDao.initHealVersion(); + healingPipelineDao.initGraphHealers(); + healingPipelineDao.setHealingPipeline(createPipelineMap()); + + assertEquals(2, + healingPipelineDao.getHealersForVertex(GraphEdgeLabels.ATTRIBUTE.getProperty(), HealVersionBuilder.build(5)).size()); + + } + + @Test + public void healTest() { + HealingPipelineDao healingPipelineDao = new HealingPipelineDao(); + healingPipelineDao.setHealVersion(3); + healingPipelineDao.initHealVersion(); + healingPipelineDao.initGraphHealers(); + final HealVersion<Integer> version3 = HealVersionBuilder.build(3); + assertFalse(healingPipelineDao.shouldHeal(HealVersionBuilder.build(2), version3)); + assertFalse(healingPipelineDao.shouldHeal(version3, version3)); + assertTrue(healingPipelineDao.shouldHeal(HealVersionBuilder.build(2), HealVersionBuilder.build(1))); + } + + + @Test + public void setCurrentVersion() { + //init data + GraphVertex graphVertex = new GraphVertex(); + HealingPipelineDao healingPipelineDao = new HealingPipelineDao(); + final int healVersion = 7; + healingPipelineDao.setHealVersion(healVersion); + healingPipelineDao.initHealVersion(); + healingPipelineDao.initGraphHealers(); + + //execute code + healingPipelineDao.setHealingVersion(graphVertex); + + //validate result + final Object currentVersion = graphVertex.getMetadataProperties().get(GraphPropertyEnum.HEALING_VERSION); + assertNotNull(currentVersion); + assertTrue(currentVersion instanceof Integer); + assertEquals(healingPipelineDao.getCurrentHealVersion().getVersion().intValue(), ((Integer) currentVersion).intValue()); + } + + @Test(expected = IllegalStateException.class) + public void testMultilistValidation() { + // init data + HealingPipelineDao healingPipelineDao = new HealingPipelineDao(); + healingPipelineDao.setHealVersion(7); + healingPipelineDao.initHealVersion(); + healingPipelineDao.initGraphHealers(); + + ImmutableListMultimap<String, Heal> shouldFail = ImmutableListMultimap.<String, Heal>builder().put(EdgeLabelEnum.ATTRIBUTES.name(), new GraphVertexHealTestMock(3)) + .put(EdgeLabelEnum.ATTRIBUTES.name(), new GraphVertexHealTestMock(4)) + .put(EdgeLabelEnum.ATTRIBUTES.name(), new GraphVertexHealTestMock(5)) + .put(EdgeLabelEnum.ATTRIBUTES.name(), new GraphVertexHealTestMock(6)) + .put(EdgeLabelEnum.CAPABILITIES.name(), new GraphVertexHealTestMock(3)) + .put(EdgeLabelEnum.CAPABILITIES.name(), new GraphVertexHealTestMock(3)) // this should cause exception + .put(EdgeLabelEnum.CAPABILITIES.name(), new GraphVertexHealTestMock(69)).build(); + + //performTest + healingPipelineDao.setHealingPipeline(shouldFail); + } + + private ImmutableListMultimap<String, Heal> createPipelineMap() { + return ImmutableListMultimap.<String, Heal>builder().put(EdgeLabelEnum.ATTRIBUTES.name(), new GraphVertexHealTestMock(3)) + .put(EdgeLabelEnum.ATTRIBUTES.name(), new GraphVertexHealTestMock(4)) + .put(EdgeLabelEnum.ATTRIBUTES.name(), new GraphVertexHealTestMock(5)) + .put(EdgeLabelEnum.ATTRIBUTES.name(), new GraphVertexHealTestMock(6)) + .put(EdgeLabelEnum.CAPABILITIES.name(), new GraphVertexHealTestMock(3)) + .put(EdgeLabelEnum.CAPABILITIES.name(), new GraphVertexHealTestMock(6)) + .put(EdgeLabelEnum.CAPABILITIES.name(), new GraphVertexHealTestMock(69)) + .put(GraphEdgeLabels.ATTRIBUTE.getProperty(), new GraphNodeHealTestMock(4)) + .put(GraphEdgeLabels.ATTRIBUTE.getProperty(), new GraphNodeHealTestMock(5)) + .put(GraphEdgeLabels.ATTRIBUTE.getProperty(), new GraphNodeHealTestMock(6)) + .put(GraphEdgeLabels.CAPABILITY.getProperty(), new TitanVertexHealTestMock(4)) + .put(GraphEdgeLabels.CAPABILITY.getProperty(), new TitanVertexHealTestMock(5)) + .put(GraphEdgeLabels.CAPABILITY.getProperty(), new TitanVertexHealTestMock(6)).build(); + } + + public GraphEdge createGraphEdge(GraphEdgeLabels graphEdgeLabels){ + return new GraphEdge(graphEdgeLabels, new HashMap<>()); + } + + + private class GraphVertexHealTestMock extends AbstractGraphVertexHeal { + + private HealVersion healVersion; + + public GraphVertexHealTestMock(int i) { + healVersion = HealVersionBuilder.build(i); + } + + @Override + public HealVersion fromVersion() { + return healVersion; + } + + @Override + public void healData(GraphVertex parentVertex) { + + } + + } + + private class GraphNodeHealTestMock extends AbstractTitanVertexHeal { + private HealVersion healVersion; + + public GraphNodeHealTestMock(int i) { + healVersion = HealVersionBuilder.build(i); + } + + @Override + public HealVersion fromVersion() { + return healVersion; + } + + @Override + public void healData(GraphNode parentV) { + + } + } + + + private class TitanVertexHealTestMock implements Heal<TitanVertex> { + private HealVersion healVersion; + + public TitanVertexHealTestMock(int i) { + healVersion = HealVersionBuilder.build(i); + } + + @Override + public HealVersion fromVersion() { + return healVersion; + } + + @Override + public void healData(TitanVertex parentV) { + + } + } + + private class MockGraphNode extends GraphNode { + private int healVersion; + + public MockGraphNode(NodeTypeEnum label) { + super(label); + } + + @Override + public String getUniqueId() { + return null; + } + + @Override + public Map<String, Object> toGraphMap() { + return null; + } + + @Override + public Integer getHealingVersion() { + return healVersion; + } + + @Override + public void setHealingVersion(Integer version) { + this.healVersion = version; + } + } + +} diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/HealVersionTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/HealVersionTest.java new file mode 100644 index 0000000000..01ac5c3e57 --- /dev/null +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/HealVersionTest.java @@ -0,0 +1,33 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdc.be.resources; + +import org.junit.Assert; +import org.junit.Test; +import org.openecomp.sdc.be.dao.jsongraph.heal.HealVersion; +import org.openecomp.sdc.be.dao.jsongraph.heal.HealVersionBuilder; + +public class HealVersionTest { + + @Test + public void buildVersions() { + final HealVersion<Integer> version1 = HealVersionBuilder.build(1); + final HealVersion<Integer> version2 = HealVersionBuilder.build(2); + Assert.assertTrue(version1.compareTo(version2) < 0); + } + +} |