diff options
Diffstat (limited to 'aai-resources/src/test/java/org')
17 files changed, 1723 insertions, 74 deletions
diff --git a/aai-resources/src/test/java/org/onap/aai/dbgen/DupeToolTest.java b/aai-resources/src/test/java/org/onap/aai/dbgen/DupeToolTest.java index 1e3d256..e9e95eb 100644 --- a/aai-resources/src/test/java/org/onap/aai/dbgen/DupeToolTest.java +++ b/aai-resources/src/test/java/org/onap/aai/dbgen/DupeToolTest.java @@ -21,7 +21,7 @@ package org.onap.aai.dbgen; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; -import com.thinkaurelius.titan.core.TitanTransaction; +import org.janusgraph.core.JanusGraphTransaction; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.junit.After; @@ -48,7 +48,7 @@ public class DupeToolTest extends AAISetup { } private void createGraph() { - TitanTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); + JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); EdgeRules edgeRules = EdgeRules.getInstance(); @@ -121,7 +121,7 @@ public class DupeToolTest extends AAISetup { @After public void tearDown(){ - TitanTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); + JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); boolean success = true; try { diff --git a/aai-resources/src/test/java/org/onap/aai/dbgen/ForceDeleteToolTest.java b/aai-resources/src/test/java/org/onap/aai/dbgen/ForceDeleteToolTest.java index f001089..f5b1da4 100644 --- a/aai-resources/src/test/java/org/onap/aai/dbgen/ForceDeleteToolTest.java +++ b/aai-resources/src/test/java/org/onap/aai/dbgen/ForceDeleteToolTest.java @@ -21,7 +21,7 @@ package org.onap.aai.dbgen; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; -import com.thinkaurelius.titan.core.TitanTransaction; +import org.janusgraph.core.JanusGraphTransaction; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Vertex; @@ -52,7 +52,7 @@ public class ForceDeleteToolTest extends AAISetup { public void setup(){ deleteTool = new ForceDeleteTool(); deleteTool.SHOULD_EXIT_VM = false; - TitanTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); + JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); EdgeRules edgeRules = EdgeRules.getInstance(); @@ -137,7 +137,7 @@ public class ForceDeleteToolTest extends AAISetup { @Test public void testCollectDataForEdge(){ - TitanTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); + JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); GraphTraversalSource g = transaction.traversal(); List<Edge> edges = g.E().toList(); String cloudRegionToPserverId = edges.get(0).id().toString(); @@ -161,7 +161,7 @@ public class ForceDeleteToolTest extends AAISetup { InputStream systemInputStream = System.in; ByteArrayInputStream in = new ByteArrayInputStream("y".getBytes()); System.setIn(in); - TitanTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); + JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); GraphTraversalSource g = transaction.traversal(); List<Edge> edges = g.E().toList(); String cloudRegionToPserverId = edges.get(0).id().toString(); @@ -182,7 +182,7 @@ public class ForceDeleteToolTest extends AAISetup { @After public void tearDown(){ - TitanTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); + JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); boolean success = true; try { diff --git a/aai-resources/src/test/java/org/onap/aai/dbgen/tags/UpdateEdgeTagsTest.java b/aai-resources/src/test/java/org/onap/aai/dbgen/tags/UpdateEdgeTagsTest.java new file mode 100644 index 0000000..89c4955 --- /dev/null +++ b/aai-resources/src/test/java/org/onap/aai/dbgen/tags/UpdateEdgeTagsTest.java @@ -0,0 +1,228 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.aai.dbgen.tags; + +import org.janusgraph.core.JanusGraphFactory; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.schema.JanusGraphManagement; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Direction; +import org.apache.tinkerpop.gremlin.structure.Edge; +import org.apache.tinkerpop.gremlin.structure.Graph; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.Mockito; +import org.onap.aai.AAISetup; +import org.onap.aai.db.props.AAIProperties; +import org.onap.aai.dbmap.AAIGraph; +import org.onap.aai.dbmap.DBConnectionType; +import org.onap.aai.introspection.Loader; +import org.onap.aai.introspection.LoaderFactory; +import org.onap.aai.introspection.ModelType; +import org.onap.aai.introspection.Version; +import org.onap.aai.serialization.db.AAIDirection; +import org.onap.aai.serialization.db.EdgeProperty; +import org.onap.aai.serialization.db.EdgeRules; +import org.onap.aai.serialization.engines.QueryStyle; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; +import org.onap.aai.serialization.engines.TransactionalGraphEngine; +import org.onap.aai.exceptions.AAIException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import java.util.Iterator; + +public class UpdateEdgeTagsTest extends AAISetup { + + private final static Version version = Version.v12; + private final static ModelType introspectorFactoryType = ModelType.MOXY; + private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL; + private final static DBConnectionType type = DBConnectionType.REALTIME; + private Loader loader; + private TransactionalGraphEngine dbEngine; + private JanusGraph graph; + private JanusGraph passedGraph; + private UpdateEdgeTagsCmd edgeOp; + private GraphTraversalSource g; + private Graph tx; + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void setUp() throws Exception { + graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); + JanusGraphManagement janusgraphManagement = graph.openManagement(); + tx = graph.newTransaction(); + g = tx.traversal(); + loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); + dbEngine = new JanusGraphDBEngine( + queryStyle, + type, + loader); + + Vertex gvnf = g.addV().property(AAIProperties.NODE_TYPE, "generic-vnf") + .property("vnf-id", "test-vnf") + .next(); + + Vertex lInterface = g.addV().property(AAIProperties.NODE_TYPE, "l-interface") + .property("interface-name", "toscaMigration-test-lint") + .next(); + + Vertex logicalLink = g.addV().property(AAIProperties.NODE_TYPE, "logical-link") + .property("link-name", "toscaMigration-logical-link") + .next(); + + + + gvnf.addEdge("hasLInterface", lInterface, EdgeProperty.CONTAINS.toString(), AAIDirection.OUT.toString(), + EdgeProperty.DELETE_OTHER_V.toString(), AAIDirection.NONE.toString()); + + lInterface.addEdge("usesLogicalLink", logicalLink, EdgeProperty.CONTAINS.toString(), AAIDirection.NONE.toString(), + EdgeProperty.DELETE_OTHER_V.toString(), AAIDirection.NONE.toString()); + lInterface.addEdge("sourceLInterface", logicalLink, EdgeProperty.CONTAINS.toString(), AAIDirection.NONE.toString(), + EdgeProperty.DELETE_OTHER_V.toString(), AAIDirection.NONE.toString()); + + Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next(); + Vertex vnfc = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next(); + pserver.addEdge("tosca.relationships.HostedOn", vnfc, EdgeProperty.CONTAINS.toString(), AAIDirection.NONE.toString(), + EdgeProperty.DELETE_OTHER_V.toString(), AAIDirection.NONE.toString()); + GraphTraversalSource traversal = g; + + passedGraph = spy(graph); + when(passedGraph.traversal()).thenReturn(traversal); + + Iterator<Edge> edgeItr = traversal.E(); + while( edgeItr != null && edgeItr.hasNext() ){ + Edge tEdge = edgeItr.next(); + String edLab = tEdge.label().toString(); + System.out.println("key = " + tEdge.inVertex().<String>property("aai-node-type").orElse(null)+"|"+ tEdge.outVertex().<String>property("aai-node-type").orElse(null)+ ", label = " + tEdge.label() + + ", for id = " + tEdge.id().toString() + ", set: "+tEdge.keys()+":"+tEdge.values()); + System.out.println("DEBUG - label = " + edLab); + } + + } + + @After + public void cleanUp() { + tx.tx().rollback(); + graph.close(); + } + + @Test + public void verifyDirectionWasReversed_OriginalGraph() { + + edgeOp = new UpdateEdgeTagsCmd("all", "/updateEdgeTestRules.json"); + edgeOp.setGraph(passedGraph); + try { + edgeOp.execute(); + } catch (AAIException e) { + e.printStackTrace(); + } + Iterator<Edge> edgeItr = g.E(); + while( edgeItr != null && edgeItr.hasNext() ){ + Edge tmpEd = edgeItr.next(); + System.out.println("Edge = " + tmpEd.inVertex().property("aai-node-type") + ", label = " + tmpEd.label() + + ", for id = " + tmpEd.id().toString() +","+tmpEd.keys()+tmpEd.value("contains-other-v")); + try { + System.out.println("Edge prevent-delete = " +tmpEd.value("prevent-delete")); + System.out.println("Edge description = " +tmpEd.value("description")); + } catch (Exception e) {;} finally {;} + } + assertEquals("Graph should have four(4) Edges with contains-other-v=OUT" + , Long.valueOf(4) + , g.E().has("contains-other-v",AAIDirection.IN.toString()).count().next()); + assertEquals("Graph should have zero(0) Edges with contains-other-v=NONE" + , Long.valueOf(0) + , g.E().has("contains-other-v",AAIDirection.NONE.toString()).count().next()); + } + + @Test + public void verifyDirectionWasReversed_withFilter() { + + edgeOp = new UpdateEdgeTagsCmd("vnfc|pserver", "/updateEdgeTestRules.json"); + edgeOp.setGraph(passedGraph); + try { + edgeOp.execute(); + } catch (AAIException e) { + e.printStackTrace(); + } + Iterator<Edge> edgeItr = g.E(); + while( edgeItr != null && edgeItr.hasNext() ){ + Edge tmpEd = edgeItr.next(); + System.out.println("Edge = " + tmpEd.inVertex().property("aai-node-type") + ", label = " + tmpEd.label() + + ", for id = " + tmpEd.id().toString() +","+tmpEd.keys()+tmpEd.value("contains-other-v")); + } + assertEquals("Graph should have one(1) Edges with contains-other-v=OUT" + , Long.valueOf(1) + , g.E().has("contains-other-v",AAIDirection.OUT.toString()).count().next()); + assertEquals("Graph should have one(1) Edges with contains-other-v=IN" + , Long.valueOf(1) + , g.E().has("contains-other-v",AAIDirection.IN.toString()).count().next()); + assertEquals("Graph should have two(2) Edges with contains-other-v=NONE" + , Long.valueOf(2) + , g.E().has("contains-other-v",AAIDirection.NONE.toString()).count().next()); + } + + @Test + public void verifyFaultyRuleFile_MissingEdgeSpec() throws AAIException { + + thrown.expect(AAIException.class); + thrown.expectMessage("No EdgeRule found for nodeTypes: pserver|vnfc|blah"); + + Vertex pserver = g.V().has(AAIProperties.NODE_TYPE, "pserver").has("hostname", "a-name").next(); + Vertex vnfc = g.V().has(AAIProperties.NODE_TYPE,"vnfc").has("vnfc-name","a-name").next(); + pserver.addEdge("blah", vnfc, EdgeProperty.CONTAINS.toString(), AAIDirection.NONE.toString(), + EdgeProperty.DELETE_OTHER_V.toString(), AAIDirection.NONE.toString()); + //Edge "blah" is not found in updateEdgeTestRules.json + edgeOp = new UpdateEdgeTagsCmd("all", "/updateEdgeTestRules.json"); + edgeOp.setGraph(passedGraph); + edgeOp.execute(); + } + + @Test + public void verifyNewPropertyWasNOTAdded() { + //Edge rules in updateEdgeTestRules.json have "description" and "newProperty" + // but they don't transfer + edgeOp = new UpdateEdgeTagsCmd("all", "/updateEdgeTestRules.json"); + edgeOp.setGraph(passedGraph); + try { + edgeOp.execute(); + } catch (AAIException e) { + e.printStackTrace(); + } + assertEquals("Graph could have zero(4) Edges with newProperty=newValue" + , Long.valueOf(0) + , g.E().has("newProperty","newValue").count().next()); + assertEquals("Graph should have one(1) Edge with description=A l-interface/logical-link(1) edge description" + , Long.valueOf(0) + , g.E().has("description","A l-interface/logical-link(0) edge description").count().next()); + } +} + +
\ No newline at end of file diff --git a/aai-resources/src/test/java/org/onap/aai/migration/EdgeSwingMigratorTest.java b/aai-resources/src/test/java/org/onap/aai/migration/EdgeSwingMigratorTest.java new file mode 100644 index 0000000..89da7fa --- /dev/null +++ b/aai-resources/src/test/java/org/onap/aai/migration/EdgeSwingMigratorTest.java @@ -0,0 +1,258 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.aai.migration; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Optional; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Direction; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.apache.tinkerpop.gremlin.structure.Edge; +import org.apache.tinkerpop.gremlin.structure.Property; +import org.javatuples.Pair; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.aai.AAISetup; +import org.onap.aai.db.props.AAIProperties; +import org.onap.aai.dbmap.AAIGraph; +import org.onap.aai.dbmap.DBConnectionType; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.introspection.Loader; +import org.onap.aai.introspection.LoaderFactory; +import org.onap.aai.introspection.ModelType; +import org.onap.aai.introspection.Version; +import org.onap.aai.serialization.db.EdgeRules; +import org.onap.aai.serialization.engines.QueryStyle; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; +import org.onap.aai.serialization.engines.TransactionalGraphEngine; + +import org.janusgraph.core.JanusGraphFactory; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphTransaction; +import org.janusgraph.core.schema.JanusGraphManagement; + +public class EdgeSwingMigratorTest extends AAISetup { + + private final static Version version = Version.getLatest(); + private final static ModelType introspectorFactoryType = ModelType.MOXY; + private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL; + private final static DBConnectionType type = DBConnectionType.REALTIME; + private Loader loader; + private TransactionalGraphEngine dbEngine; + private JanusGraph graph; + private GraphTraversalSource g; + private JanusGraphTransaction tx; + private MockEdgeSwingMigrator migration; + private EdgeRules rules; + private Vertex modelVer1 = null; + private Vertex modelVer3 = null; + + + @Before + public void setUp() throws Exception { + graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); + JanusGraphManagement janusgraphManagement = graph.openManagement(); + tx = graph.newTransaction(); + g = graph.traversal(); + loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); + dbEngine = new JanusGraphDBEngine( + queryStyle, + type, + loader); + rules = EdgeRules.getInstance(); + createFirstVertexAndRelatedVertexes(); + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + GraphTraversalSource traversal = g; + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + Mockito.doReturn(janusgraphManagement).when(adminSpy).getManagementSystem(); + + + migration = new MockEdgeSwingMigrator(spy); + migration.run(); + } + + private void createFirstVertexAndRelatedVertexes() throws AAIException { + Vertex model1 = g.addV().property("aai-node-type", "model") + .property("model-invariant-id", "model-invariant-id-1") + .property("model-type", "widget") + .next(); + modelVer1 = g.addV().property("aai-node-type", "model-ver") + .property("model-version-id", "model-version-id-1") + .property("model-name", "connector") + .property("model-version", "v1.0") + .next(); + rules.addTreeEdge(g, model1, modelVer1); + + //Create the cousin vertex - modelElement2 which will point to modelVer1 + Vertex model2 = g.addV().property("aai-node-type", "model") + .property("model-invariant-id", "model-invariant-id-2") + .property("model-type", "resource") + .next(); + Vertex modelVer2 = g.addV().property("aai-node-type", "model-ver") + .property("model-version-id", "model-version-id-2") + .property("model-name", "resourceModTestVer") + .property("model-version", "v1.0") + .next(); + rules.addTreeEdge(g, model2, modelVer2); + Vertex modelElement2 = g.addV().property("aai-node-type", "model-element") + .property("model-element-uuid", "model-element-uuid-2") + .property("new-data-del-flag", "T") + .property("cardinality", "unbounded") + .next(); + rules.addTreeEdge(g, modelVer2, modelElement2); + rules.addEdge(g, modelVer1, modelElement2); + + Vertex model3 = g.addV().property("aai-node-type", "model") + .property("model-invariant-id", "model-invariant-id-3") + .property("model-type", "widget") + .next(); + modelVer3 = g.addV().property("aai-node-type", "model-ver") + .property("model-version-id", "model-version-id-3") + .property("model-name", "connector") + .property("model-version", "v1.0") + .next(); + rules.addTreeEdge(g, model3, modelVer3); + } + + class MockEdgeSwingMigrator extends EdgeSwingMigrator { + + public MockEdgeSwingMigrator(TransactionalGraphEngine engine) { + super(engine); + } + + @Override + public List<Pair<Vertex, Vertex>> getAffectedNodePairs() { + List<Pair<Vertex, Vertex>> fromToVertPairList = new ArrayList<Pair<Vertex, Vertex>>(); + Vertex fromVert = modelVer1; + Vertex toVert = modelVer3; + fromToVertPairList.add(new Pair<>(fromVert, toVert)); + return fromToVertPairList; + } + + public String getNodeTypeRestriction(){ + return "model-element"; + } + + public String getEdgeLabelRestriction(){ + return "org.onap.relationships.inventory.IsA"; + } + + public String getEdgeDirRestriction(){ + return "IN"; + } + + @Override + public void cleanupAsAppropriate(List<Pair<Vertex, Vertex>> nodePairL) { + // For the scenario we're testing, we would define this to remove the model-ver that + // we moved off of, and also remove its parent model since it was a widget model and + // these are currently one-to-one (model-ver to model). + // + // But what gets cleaned up (if anything) after a node's edges are migrated will vary depending + // on what the edgeSwingMigration is being used for. + + + } + + @Override + public Optional<String[]> getAffectedNodeTypes() { + return Optional.of(new String[]{"model", "model-element", "model-ver"}); + } + + @Override + public String getMigrationName() { + return "MockEdgeSwingMigrator"; + } + } + + @After + public void cleanUp() { + tx.rollback(); + graph.close(); + } + + + + @Test + public void testBelongsToEdgesStillThere() { + assertEquals(true, g.V().has("aai-node-type", "model-ver").has("model-version-id", "model-version-id-1") + .out("org.onap.relationships.inventory.BelongsTo").has("model-invariant-id", "model-invariant-id-1").hasNext()); + assertEquals(true, g.V().has("aai-node-type", "model-ver").has("model-version-id", "model-version-id-3") + .out("org.onap.relationships.inventory.BelongsTo").has("model-invariant-id", "model-invariant-id-3").hasNext()); + assertEquals(true, g.V().has("aai-node-type", "model-element").has("model-element-uuid", "model-element-uuid-2") + .out("org.onap.relationships.inventory.BelongsTo").has("model-version-id", "model-version-id-2").hasNext()); + } + + @Test + public void testThatNewEdgeAdded() { + assertEquals(true, g.V().has("aai-node-type", "model-ver").has("model-version-id", "model-version-id-3") + .in("org.onap.relationships.inventory.IsA").has("model-element-uuid", "model-element-uuid-2").hasNext()); + } + + @Test + public void testThatNewEdgeHasAaiUuidAndDelProperties() { + boolean haveUuidProp = false; + boolean haveDelOtherVProp = false; + GraphTraversal<Vertex, Vertex> modVerTrav = g.V().has("aai-node-type", "model-ver").has("model-version-id", "model-version-id-3"); + while (modVerTrav.hasNext()) { + Vertex modVerVtx = modVerTrav.next(); + Iterator <Edge> edgeIter = modVerVtx.edges(Direction.IN, "org.onap.relationships.inventory.IsA"); + while( edgeIter.hasNext() ){ + Edge oldOutE = edgeIter.next(); + + Iterator <Property<Object>> propsIter2 = oldOutE.properties(); + HashMap<String, String> propMap2 = new HashMap<String,String>(); + while( propsIter2.hasNext() ){ + Property <Object> ep2 = propsIter2.next(); + if( ep2.key().equals("aai-uuid") ){ + haveUuidProp = true; + } + else if( ep2.key().equals("delete-other-v") ){ + haveDelOtherVProp = true; + } + } + } + } + + assertTrue("New IsA edge has aai-uuid property ", haveUuidProp ); + assertTrue("New IsA edge has delete-other-v property ", haveDelOtherVProp ); + } + + + @Test + public void testThatOldEdgeGone() { + assertEquals(false, g.V().has("aai-node-type", "model-ver").has("model-version-id", "model-version-id-1") + .in("org.onap.relationships.inventory.IsA").has("model-element-uuid", "model-element-uuid-2").hasNext()); + } + + +}
\ No newline at end of file diff --git a/aai-resources/src/test/java/org/onap/aai/migration/MigrationControllerInternalTest.java b/aai-resources/src/test/java/org/onap/aai/migration/MigrationControllerInternalTest.java new file mode 100644 index 0000000..4ba200a --- /dev/null +++ b/aai-resources/src/test/java/org/onap/aai/migration/MigrationControllerInternalTest.java @@ -0,0 +1,281 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.aai.migration; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.janusgraph.core.JanusGraphTransaction; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.aai.AAISetup; +import org.onap.aai.dbmap.AAIGraph; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.EdgeRules; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.StringContains.containsString; + +public class MigrationControllerInternalTest extends AAISetup { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(MigrationControllerInternalTest.class); + + private MigrationControllerInternal migrationControllerInternal; + + @Before + public void setup() throws AAIException { + migrationControllerInternal = new MigrationControllerInternal(); + clearGraph(); + createGraph(); + } + + private void createGraph(){ + + JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); + boolean success = true; + + try { + GraphTraversalSource g = transaction.traversal(); + + Vertex servSub1 = g.addV().property("aai-node-type", "service-subscription") + .property("service-type", "DHV") + .property("source-of-truth", "JUNIT") + .next(); + Vertex servinst1 = g.addV().property( "aai-node-type", "service-instance") + .property("service-type", "DHV") + .property("source-of-truth", "JUNIT") + .next(); + Vertex allotedRsrc1 = g.addV().property( "aai-node-type", "allotted-resource") + .property("id","rsrc1") + .property("source-of-truth", "JUNIT") + .next(); + Vertex servinst2 = g.addV().property( "aai-node-type", "service-instance") + .property("service-type", "VVIG") + .property("source-of-truth", "JUNIT") + .next(); + Vertex servSub2 = g.addV().property("aai-node-type", "service-subscription") + .property("service-type", "VVIG") + .property("source-of-truth", "JUNIT") + .next(); + + Vertex genericvnf1 = g.addV().property("aai-node-type", "generic-vnf") + .property("vnf-id", "vnfId1") + .property("source-of-truth", "JUNIT") + .next(); + Vertex vServer1 = g.addV().property("aai-node-type", "vserver") + .property("source-of-truth", "JUNIT") + .next(); + Vertex pServer1 = g.addV().property("aai-node-type", "pserver") + .property("source-of-truth", "JUNIT") + .next(); + Vertex pInterfaceWan1 = g.addV().property("aai-node-type", "p-interface") + .property("interface-name","ge-0/0/10") + .property("source-of-truth", "JUNIT") + .next(); + Vertex tunnelXConnectAll_Wan1 = g.addV().property( "aai-node-type", "tunnel-xconnect") + .property("id", "tunnelXConnectWan1") + .property("bandwidth-up-wan1", "300") + .property("bandwidth-down-wan1", "400") + .property("bandwidth-up-wan2", "500") + .property("bandwidth-down-wan2", "600") + .property("source-of-truth", "JUNIT") + .next(); + + Vertex pLinkWan1 = g.addV().property("aai-node-type", "physical-link") + .property("link-name", "pLinkWan1") + .property("service-provider-bandwidth-up-units", "empty") + .property("service-provider-bandwidth-down-units", "empty") + .property("source-of-truth", "JUNIT") + .next(); + Vertex servSub3 = g.addV().property("aai-node-type", "service-subscription") + .property("service-type", "DHV") + .property("source-of-truth", "JUNIT") + .next(); + Vertex servinst3 = g.addV().property( "aai-node-type", "service-instance") + .property("service-type", "DHV") + .property("source-of-truth", "JUNIT") + .next(); + Vertex allotedRsrc3 = g.addV().property( "aai-node-type", "allotted-resource") + .property("id","rsrc3") + .property("source-of-truth", "JUNIT") + .next(); + Vertex servinst4 = g.addV().property( "aai-node-type", "service-instance") + .property("service-type", "VVIG") + .property("source-of-truth", "JUNIT") + .next(); + Vertex servSub4 = g.addV().property("aai-node-type", "service-subscription") + .property("service-type", "VVIG") + .property("source-of-truth", "JUNIT") + .next(); + + Vertex genericvnf3 = g.addV().property("aai-node-type", "generic-vnf") + .property("vnf-id", "vnfId3") + .property("source-of-truth", "JUNIT") + .next(); + Vertex vServer3 = g.addV().property("aai-node-type", "vserver") + .property("source-of-truth", "JUNIT") + .next(); + Vertex pServer3 = g.addV().property("aai-node-type", "pserver") + .property("source-of-truth", "JUNIT") + .next(); + Vertex pInterfaceWan3 = g.addV().property("aai-node-type", "p-interface") + .property("interface-name","ge-0/0/11") + .property("source-of-truth", "JUNIT") + .next(); + Vertex tunnelXConnectAll_Wan3 = g.addV().property( "aai-node-type", "tunnel-xconnect") + .property("id", "tunnelXConnectWan3") + .property("bandwidth-up-wan1", "300") + .property("bandwidth-down-wan1", "400") + .property("bandwidth-up-wan2", "500") + .property("bandwidth-down-wan2", "600") + .property("source-of-truth", "JUNIT") + .next(); + + Vertex pLinkWan3 = g.addV().property("aai-node-type", "physical-link") + .property("link-name", "pLinkWan3") + .property("service-provider-bandwidth-up-units", "empty") + .property("service-provider-bandwidth-down-units", "empty") + .property("source-of-truth", "JUNIT") + .next(); + + EdgeRules rules = EdgeRules.getInstance(); + + rules.addTreeEdge(g,servSub1,servinst1); + rules.addEdge(g,servinst1,allotedRsrc1); + rules.addTreeEdge(g,servinst2,servSub2); + rules.addTreeEdge(g,allotedRsrc1,servinst2); + + rules.addTreeEdge(g,allotedRsrc1,tunnelXConnectAll_Wan1); + + + rules.addEdge(g,servinst1,genericvnf1); + rules.addEdge(g,genericvnf1,vServer1); + rules.addEdge(g,vServer1,pServer1); + rules.addTreeEdge(g,pServer1,pInterfaceWan1); + rules.addEdge(g,pInterfaceWan1,pLinkWan1); + + rules.addTreeEdge(g,servSub3,servinst3); + rules.addEdge(g,servinst3,allotedRsrc3); + rules.addTreeEdge(g,servinst4,servSub4); + rules.addTreeEdge(g,allotedRsrc3,servinst4); + + rules.addTreeEdge(g,allotedRsrc3,tunnelXConnectAll_Wan3); + + + rules.addEdge(g,servinst3,genericvnf3); + rules.addEdge(g,genericvnf3,vServer3); + rules.addEdge(g,vServer3,pServer3); + rules.addTreeEdge(g,pServer3,pInterfaceWan3); + rules.addEdge(g,pInterfaceWan3,pLinkWan3); + + } catch(Exception ex){ + success = false; + logger.error("Unable to create the graph {}", ex); + } finally { + if(success){ + transaction.commit(); + } else { + transaction.rollback(); + } + + } + } + + @Test + public void testListAllOfMigrations() throws Exception { + PrintStream oldOutputStream = System.out; + final ByteArrayOutputStream myOut = new ByteArrayOutputStream(); + System.setOut(new PrintStream(myOut)); + + String [] args = { + "-c", "./bundleconfig-local/etc/appprops/janusgraph-realtime.properties", + "-l" + }; + + migrationControllerInternal.run(args); + + String content = myOut.toString(); + assertThat(content, containsString("List of all migrations")); + System.setOut(oldOutputStream); + } + + @Test + public void testRunSpecificMigration() throws Exception { + String [] args = "-c ./bundleconfig-local/etc/appprops/janusgraph-realtime.properties -m SDWANSpeedChangeMigration".split(" "); + migrationControllerInternal.run(args); + } + + @Test + public void testRunSpecificMigrationAndCommit() throws Exception { + String [] args = { + "-c", "./bundleconfig-local/etc/appprops/janusgraph-realtime.properties", + "-m", "SDWANSpeedChangeMigration", + "--commit" + }; + migrationControllerInternal.run(args); + } + + @Test + public void testRunSpecificMigrationFromLoadingSnapshotAndCommit() throws Exception{ + clearGraph(); + String [] args = { + "-d", "./snapshots/sdwan_test_migration.graphson", + "-c", "./bundleconfig-local/etc/appprops/janusgraph-realtime.properties", + "-m", "SDWANSpeedChangeMigration" + }; + migrationControllerInternal.run(args); + } + + @After + public void tearDown(){ + clearGraph(); + } + + public void clearGraph(){ + + JanusGraphTransaction janusgraphTransaction = AAIGraph.getInstance().getGraph().newTransaction(); + + boolean success = true; + + try { + GraphTraversalSource g = janusgraphTransaction.traversal(); + + g.V().has("source-of-truth", "JUNIT") + .toList() + .forEach((v) -> v.remove()); + + } catch(Exception ex) { + success = false; + logger.error("Unable to remove all of the vertexes", ex); + } finally { + if(success){ + janusgraphTransaction.commit(); + } else { + janusgraphTransaction.rollback(); + } + } + + } +}
\ No newline at end of file diff --git a/aai-resources/src/test/java/org/onap/aai/migration/PropertyMigratorTest.java b/aai-resources/src/test/java/org/onap/aai/migration/PropertyMigratorTest.java new file mode 100644 index 0000000..2b7d58d --- /dev/null +++ b/aai-resources/src/test/java/org/onap/aai/migration/PropertyMigratorTest.java @@ -0,0 +1,126 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.aai.migration; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.janusgraph.core.Cardinality; +import org.janusgraph.core.JanusGraphTransaction; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Before; +import org.junit.Test; +import org.onap.aai.AAISetup; +import org.onap.aai.dbmap.AAIGraph; +import org.onap.aai.dbmap.DBConnectionType; +import org.onap.aai.introspection.Loader; +import org.onap.aai.introspection.LoaderFactory; +import org.onap.aai.introspection.ModelType; +import org.onap.aai.introspection.Version; +import org.onap.aai.serialization.engines.QueryStyle; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; +import org.onap.aai.serialization.engines.TransactionalGraphEngine; + +import java.util.List; +import java.util.Optional; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class PropertyMigratorTest extends AAISetup { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(PropertyMigratorTest.class); + + public static class PserverPropMigrator extends PropertyMigrator { + + public PserverPropMigrator(TransactionalGraphEngine engine, String oldName, String newName, Class<?> type, Cardinality cardinality) { + super(engine, oldName, newName, type, cardinality); + } + + @Override + public boolean isIndexed() { + return true; + } + + @Override + public Optional<String[]> getAffectedNodeTypes() { + return Optional.of(new String[]{ "pserver" }); + } + + @Override + public String getMigrationName() { + return "PserverPropMigrator"; + } + } + + @Before + public void setup(){ + AAIGraph.getInstance(); + JanusGraphTransaction janusgraphTransaction = AAIGraph.getInstance().getGraph().newTransaction(); + boolean success = true; + + try { + GraphTraversalSource g = janusgraphTransaction.traversal(); + g.addV() + .property("aai-node-type", "pserver") + .property("hostname", "fake-hostname") + .property("inv-status", "some status") + .property("source-of-truth", "JUNIT") + .next(); + } catch(Exception ex){ + success = false; + logger.error("Unable to commit the transaction {}", ex); + + } finally { + if(success){ + janusgraphTransaction.commit(); + } else { + janusgraphTransaction.rollback(); + } + + } + } + + @Test + public void testAfterPropertyMigration(){ + + String oldPropName = "inv-status"; + String newPropName = "inventory-status"; + + Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v11); + JanusGraphDBEngine dbEngine = new JanusGraphDBEngine(QueryStyle.TRAVERSAL, DBConnectionType.REALTIME, loader); + dbEngine.startTransaction(); + + PropertyMigrator propertyMigrator = new PserverPropMigrator(dbEngine, oldPropName, newPropName, String.class, Cardinality.SINGLE); + propertyMigrator.run(); + assertEquals("Expecting the property to be success", Status.SUCCESS, propertyMigrator.getStatus()); + dbEngine.commit(); + + JanusGraphTransaction janusgraphTransaction = AAIGraph.getInstance().getGraph().newTransaction(); + GraphTraversalSource g = janusgraphTransaction.traversal(); + + List<Vertex> oldVList = g.V().has("aai-node-type", "pserver").has(oldPropName).toList(); + List<Vertex> newVList = g.V().has("aai-node-type", "pserver").has(newPropName).toList(); + + assertEquals("Expecting the vertex list with old property to be zero", 0, oldVList.size()); + assertEquals("Expecting the vertex list with new property to be 1", 1, newVList.size()); + assertEquals("Expecting the equipment type to be some equipment", "some status", newVList.get(0).property(newPropName).value()); + } +}
\ No newline at end of file diff --git a/aai-resources/src/test/java/org/onap/aai/migration/ValueMigratorTest.java b/aai-resources/src/test/java/org/onap/aai/migration/ValueMigratorTest.java new file mode 100644 index 0000000..7850fd2 --- /dev/null +++ b/aai-resources/src/test/java/org/onap/aai/migration/ValueMigratorTest.java @@ -0,0 +1,154 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.aai.migration; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.janusgraph.core.JanusGraphFactory; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphTransaction; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.junit.Before; +import org.junit.Test; +import org.onap.aai.AAISetup; +import org.onap.aai.dbmap.DBConnectionType; +import org.onap.aai.introspection.Loader; +import org.onap.aai.introspection.LoaderFactory; +import org.onap.aai.introspection.ModelType; +import org.onap.aai.introspection.Version; +import org.onap.aai.serialization.db.EdgeRules; +import org.onap.aai.serialization.engines.QueryStyle; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; +import org.onap.aai.serialization.engines.TransactionalGraphEngine; + +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; + +public class ValueMigratorTest extends AAISetup{ + + public static class SampleValueMigrator extends ValueMigrator { + public SampleValueMigrator(TransactionalGraphEngine engine, Map map, Boolean updateExistingValues){ + super(engine, map, updateExistingValues); + } + @Override + public Status getStatus() { + return Status.SUCCESS; + } + @Override + public Optional<String[]> getAffectedNodeTypes() { + return null; + } + @Override + public String getMigrationName() { + return "SampleValueMigrator"; + } + } + + private final static Version version = Version.v10; + private final static ModelType introspectorFactoryType = ModelType.MOXY; + private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL; + private final static DBConnectionType type = DBConnectionType.REALTIME; + private Loader loader; + private TransactionalGraphEngine dbEngine; + private JanusGraph graph; + private SampleValueMigrator migration; + private EdgeRules rules; + private GraphTraversalSource g; + private JanusGraphTransaction tx; + private SampleValueMigrator existingValuesMigration; + + @Before + public void setup() throws Exception{ + graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open(); + tx = graph.newTransaction(); + g = tx.traversal(); + loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); + dbEngine = new JanusGraphDBEngine( + queryStyle, + type, + loader); + rules = EdgeRules.getInstance(); + Map<String, Map> map = new HashMap<>(); + Map<String, Boolean> pair = new HashMap<>(); + pair.put("in-maint", true); + map.put("pserver", pair); + map.put("pnf", pair); + g.addV().property("aai-node-type", "pserver") + .property("pserver-id", "pserver0") + .next(); + g.addV().property("aai-node-type", "pserver") + .property("pserver-id", "pserver1") + .property("in-maint", "") + .next(); + g.addV().property("aai-node-type", "pserver") + .property("pserver-id", "pserver2") + .property("in-maint", false) + .next(); + g.addV().property("aai-node-type", "pnf") + .property("pnf-name","pnf1" ) + .property("in-maint", false) + .next(); + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + GraphTraversalSource traversal = g; + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + migration = new SampleValueMigrator(spy, map, false); + migration.run(); + + map = new HashMap<>(); + pair = new HashMap<>(); + pair.put("in-maint", true); + map.put("pnf", pair); + existingValuesMigration = new SampleValueMigrator(spy, map, true); + existingValuesMigration.run(); + } + + @Test + public void testMissingProperty(){ + assertTrue("Value of pnf should be updated since the property doesn't exist", + g.V().has("aai-node-type", "pserver").has("pserver-id", "pserver0").has("in-maint", true).hasNext()); + } + + @Test + public void testExistingValue() { + assertTrue("Value of pserver shouldn't be updated since it already exists", + g.V().has("aai-node-type", "pserver").has("pserver-id", "pserver2").has("in-maint", false).hasNext()); + } + + @Test + public void testEmptyValue() { + assertTrue("Value of pserver should be updated since the value is an empty string", + g.V().has("aai-node-type", "pserver").has("pserver-id", "pserver1").has("in-maint", true).hasNext()); + } + + @Test + public void testUpdateExistingValues() { + assertTrue("Value of pnf should be updated even though it already exists", + g.V().has("aai-node-type", "pnf").has("pnf-name", "pnf1").has("in-maint", true).hasNext()); + } +} diff --git a/aai-resources/src/test/java/org/onap/aai/migration/VertexMergeTest.java b/aai-resources/src/test/java/org/onap/aai/migration/VertexMergeTest.java index 18ceac1..90cd921 100644 --- a/aai-resources/src/test/java/org/onap/aai/migration/VertexMergeTest.java +++ b/aai-resources/src/test/java/org/onap/aai/migration/VertexMergeTest.java @@ -19,10 +19,10 @@ */ package org.onap.aai.migration; -import com.thinkaurelius.titan.core.Cardinality; -import com.thinkaurelius.titan.core.TitanFactory; -import com.thinkaurelius.titan.core.TitanGraph; -import com.thinkaurelius.titan.core.schema.TitanManagement; +import org.janusgraph.core.Cardinality; +import org.janusgraph.core.JanusGraphFactory; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.schema.JanusGraphManagement; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; @@ -37,7 +37,7 @@ import org.onap.aai.introspection.Version; import org.onap.aai.serialization.db.DBSerializer; import org.onap.aai.serialization.db.EdgeRules; import org.onap.aai.serialization.engines.QueryStyle; -import org.onap.aai.serialization.engines.TitanDBEngine; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import java.io.UnsupportedEncodingException; @@ -59,24 +59,24 @@ public class VertexMergeTest extends AAISetup { private final static DBConnectionType type = DBConnectionType.REALTIME; private Loader loader; private TransactionalGraphEngine dbEngine; - private TitanGraph graph; + private JanusGraph graph; private EdgeRules rules; private GraphTraversalSource g; private Graph tx; @Before public void setUp() throws Exception { - graph = TitanFactory.build().set("storage.backend","inmemory").open(); + graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); tx = graph.newTransaction(); g = tx.traversal(); loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); - dbEngine = new TitanDBEngine( + dbEngine = new JanusGraphDBEngine( queryStyle, type, loader); rules = EdgeRules.getInstance(); - TitanManagement mgmt = graph.openManagement(); + JanusGraphManagement mgmt = graph.openManagement(); mgmt.makePropertyKey("test-list").dataType(String.class).cardinality(Cardinality.SET).make(); mgmt.commit(); Vertex pserverSkeleton = g.addV().property("aai-node-type", "pserver").property("hostname", "TEST1") diff --git a/aai-resources/src/test/java/org/onap/aai/migration/v12/ContainmentDeleteOtherVPropertyMigrationTest.java b/aai-resources/src/test/java/org/onap/aai/migration/v12/ContainmentDeleteOtherVPropertyMigrationTest.java index 6ecc481..f80229c 100644 --- a/aai-resources/src/test/java/org/onap/aai/migration/v12/ContainmentDeleteOtherVPropertyMigrationTest.java +++ b/aai-resources/src/test/java/org/onap/aai/migration/v12/ContainmentDeleteOtherVPropertyMigrationTest.java @@ -19,9 +19,9 @@ */ package org.onap.aai.migration.v12; -import com.thinkaurelius.titan.core.TitanFactory; -import com.thinkaurelius.titan.core.TitanGraph; -import com.thinkaurelius.titan.core.schema.TitanManagement; +import org.janusgraph.core.JanusGraphFactory; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.schema.JanusGraphManagement; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Graph; @@ -39,7 +39,7 @@ import org.onap.aai.introspection.Version; import org.onap.aai.serialization.db.AAIDirection; import org.onap.aai.serialization.db.EdgeProperty; import org.onap.aai.serialization.engines.QueryStyle; -import org.onap.aai.serialization.engines.TitanDBEngine; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import static org.junit.Assert.assertEquals; @@ -54,19 +54,19 @@ public class ContainmentDeleteOtherVPropertyMigrationTest extends AAISetup { private final static DBConnectionType type = DBConnectionType.REALTIME; private Loader loader; private TransactionalGraphEngine dbEngine; - private TitanGraph graph; + private JanusGraph graph; private ContainmentDeleteOtherVPropertyMigration migration; private GraphTraversalSource g; private Graph tx; @Before public void setUp() throws Exception { - graph = TitanFactory.build().set("storage.backend","inmemory").open(); - TitanManagement titanManagement = graph.openManagement(); + graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); + JanusGraphManagement janusgraphManagement = graph.openManagement(); tx = graph.newTransaction(); g = tx.traversal(); loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); - dbEngine = new TitanDBEngine( + dbEngine = new JanusGraphDBEngine( queryStyle, type, loader); @@ -88,7 +88,7 @@ public class ContainmentDeleteOtherVPropertyMigrationTest extends AAISetup { GraphTraversalSource traversal = g; when(spy.asAdmin()).thenReturn(adminSpy); when(adminSpy.getTraversalSource()).thenReturn(traversal); - Mockito.doReturn(titanManagement).when(adminSpy).getManagementSystem(); + Mockito.doReturn(janusgraphManagement).when(adminSpy).getManagementSystem(); migration = new ContainmentDeleteOtherVPropertyMigration(spy, "/edgeMigrationTestRules.json"); migration.run(); } diff --git a/aai-resources/src/test/java/org/onap/aai/migration/v12/MigrateDataFromASDCToConfigurationTest.java b/aai-resources/src/test/java/org/onap/aai/migration/v12/MigrateDataFromASDCToConfigurationTest.java index 0552dd9..4fbed4c 100644 --- a/aai-resources/src/test/java/org/onap/aai/migration/v12/MigrateDataFromASDCToConfigurationTest.java +++ b/aai-resources/src/test/java/org/onap/aai/migration/v12/MigrateDataFromASDCToConfigurationTest.java @@ -19,9 +19,9 @@ */ package org.onap.aai.migration.v12; -import com.thinkaurelius.titan.core.TitanFactory; -import com.thinkaurelius.titan.core.TitanGraph; -import com.thinkaurelius.titan.core.TitanTransaction; +import org.janusgraph.core.JanusGraphFactory; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphTransaction; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.junit.After; @@ -35,7 +35,7 @@ import org.onap.aai.introspection.ModelType; import org.onap.aai.introspection.Version; import org.onap.aai.serialization.db.EdgeRules; import org.onap.aai.serialization.engines.QueryStyle; -import org.onap.aai.serialization.engines.TitanDBEngine; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import static org.junit.Assert.assertEquals; @@ -51,11 +51,11 @@ public class MigrateDataFromASDCToConfigurationTest extends AAISetup { private final static DBConnectionType type = DBConnectionType.REALTIME; private Loader loader; private TransactionalGraphEngine dbEngine; - private TitanGraph graph; + private JanusGraph graph; private MigrateDataFromASDCToConfiguration migration; private EdgeRules rules; private GraphTraversalSource g; - private TitanTransaction tx; + private JanusGraphTransaction tx; Vertex configuration; Vertex configuration2; Vertex configuration3; @@ -68,11 +68,11 @@ public class MigrateDataFromASDCToConfigurationTest extends AAISetup { @Before public void setUp() throws Exception { - graph = TitanFactory.build().set("storage.backend","inmemory").open(); + graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); tx = graph.newTransaction(); g = tx.traversal(); loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); - dbEngine = new TitanDBEngine( + dbEngine = new JanusGraphDBEngine( queryStyle, type, loader); diff --git a/aai-resources/src/test/java/org/onap/aai/migration/v12/MigrateServiceInstanceToConfigurationTest.java b/aai-resources/src/test/java/org/onap/aai/migration/v12/MigrateServiceInstanceToConfigurationTest.java index 33f5f2c..b07c728 100644 --- a/aai-resources/src/test/java/org/onap/aai/migration/v12/MigrateServiceInstanceToConfigurationTest.java +++ b/aai-resources/src/test/java/org/onap/aai/migration/v12/MigrateServiceInstanceToConfigurationTest.java @@ -41,12 +41,12 @@ import org.onap.aai.introspection.ModelType; import org.onap.aai.introspection.Version; import org.onap.aai.serialization.db.EdgeRules; import org.onap.aai.serialization.engines.QueryStyle; -import org.onap.aai.serialization.engines.TitanDBEngine; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.TransactionalGraphEngine; -import com.thinkaurelius.titan.core.TitanFactory; -import com.thinkaurelius.titan.core.TitanGraph; -import com.thinkaurelius.titan.core.TitanTransaction; +import org.janusgraph.core.JanusGraphFactory; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphTransaction; public class MigrateServiceInstanceToConfigurationTest extends AAISetup { @@ -57,19 +57,19 @@ public class MigrateServiceInstanceToConfigurationTest extends AAISetup { private static Loader loader; private static TransactionalGraphEngine dbEngine; - private static TitanGraph graph; + private static JanusGraph graph; private static MigrateServiceInstanceToConfiguration migration; - private static TitanTransaction tx; + private static JanusGraphTransaction tx; private static GraphTraversalSource g; private static EdgeRules rules; @BeforeClass public static void setUp() throws Exception { - graph = TitanFactory.build().set("storage.backend","inmemory").open(); + graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); tx = graph.newTransaction(); g = tx.traversal(); loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); - dbEngine = new TitanDBEngine( + dbEngine = new JanusGraphDBEngine( queryStyle, type, loader); diff --git a/aai-resources/src/test/java/org/onap/aai/migration/v12/MigrateServiceInstanceToConfigurationTestPreMigrationMock.java b/aai-resources/src/test/java/org/onap/aai/migration/v12/MigrateServiceInstanceToConfigurationTestPreMigrationMock.java index c3449ab..498fd0c 100644 --- a/aai-resources/src/test/java/org/onap/aai/migration/v12/MigrateServiceInstanceToConfigurationTestPreMigrationMock.java +++ b/aai-resources/src/test/java/org/onap/aai/migration/v12/MigrateServiceInstanceToConfigurationTestPreMigrationMock.java @@ -41,12 +41,12 @@ import org.onap.aai.introspection.ModelType; import org.onap.aai.introspection.Version; import org.onap.aai.serialization.db.EdgeRules; import org.onap.aai.serialization.engines.QueryStyle; -import org.onap.aai.serialization.engines.TitanDBEngine; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.TransactionalGraphEngine; -import com.thinkaurelius.titan.core.TitanFactory; -import com.thinkaurelius.titan.core.TitanGraph; -import com.thinkaurelius.titan.core.TitanTransaction; +import org.janusgraph.core.JanusGraphFactory; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphTransaction; public class MigrateServiceInstanceToConfigurationTestPreMigrationMock extends AAISetup { @@ -57,19 +57,19 @@ public class MigrateServiceInstanceToConfigurationTestPreMigrationMock extends A private static Loader loader; private static TransactionalGraphEngine dbEngine; - private static TitanGraph graph; + private static JanusGraph graph; private static MigrateServiceInstanceToConfiguration migration; - private static TitanTransaction tx; + private static JanusGraphTransaction tx; private static GraphTraversalSource g; private static EdgeRules rules; @BeforeClass public static void setUp() throws Exception { - graph = TitanFactory.build().set("storage.backend","inmemory").open(); + graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); tx = graph.newTransaction(); g = tx.traversal(); loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); - dbEngine = new TitanDBEngine( + dbEngine = new JanusGraphDBEngine( queryStyle, type, loader); diff --git a/aai-resources/src/test/java/org/onap/aai/migration/v12/SDWANSpeedChangeMigrationTest.java b/aai-resources/src/test/java/org/onap/aai/migration/v12/SDWANSpeedChangeMigrationTest.java new file mode 100644 index 0000000..677050a --- /dev/null +++ b/aai-resources/src/test/java/org/onap/aai/migration/v12/SDWANSpeedChangeMigrationTest.java @@ -0,0 +1,379 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.aai.migration.v12; + +import org.janusgraph.core.JanusGraphFactory; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphTransaction; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.aai.AAISetup; +import org.onap.aai.dbmap.DBConnectionType; +import org.onap.aai.introspection.Loader; +import org.onap.aai.introspection.LoaderFactory; +import org.onap.aai.introspection.ModelType; +import org.onap.aai.introspection.Version; +import org.onap.aai.serialization.db.EdgeRules; +import org.onap.aai.serialization.engines.QueryStyle; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; +import org.onap.aai.serialization.engines.TransactionalGraphEngine; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +public class SDWANSpeedChangeMigrationTest extends AAISetup { + + private final static Version version = Version.v12; + private final static ModelType introspectorFactoryType = ModelType.MOXY; + private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL; + private final static DBConnectionType type = DBConnectionType.REALTIME; + private Loader loader; + private TransactionalGraphEngine dbEngine; + private JanusGraph graph; + private SDWANSpeedChangeMigration migration; + private EdgeRules rules; + private GraphTraversalSource g; + private JanusGraphTransaction tx; + Vertex pLinkWan1; + Vertex pLinkWan3; + Vertex pLinkWan5; + Vertex pLinkWan7; + + + + @Before + public void setUp() throws Exception { + graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open(); + tx = graph.newTransaction(); + g = tx.traversal(); + loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); + dbEngine = new JanusGraphDBEngine( + queryStyle, + type, + loader); + rules = EdgeRules.getInstance(); + + Vertex servSub1 = g.addV().property("aai-node-type", "service-subscription") + .property("service-type", "DHV") + .next(); + Vertex servinst1 = g.addV().property("aai-node-type", "service-instance") + .property("service-type", "DHV") + .next(); + Vertex allotedRsrc1 = g.addV().property("aai-node-type", "allotted-resource") + .property("id", "rsrc1") + .next(); + Vertex servinst2 = g.addV().property("aai-node-type", "service-instance") + .property("service-type", "VVIG") + .next(); + Vertex servSub2 = g.addV().property("aai-node-type", "service-subscription") + .property("service-type", "VVIG") + .next(); + + Vertex genericvnf1 = g.addV().property("aai-node-type", "generic-vnf") + .property("vnf-id", "vnfId1") + .next(); + Vertex vServer1 = g.addV().property("aai-node-type", "vserver") + .next(); + Vertex pServer1 = g.addV().property("aai-node-type", "pserver") + .next(); + Vertex pInterfaceWan1 = g.addV().property("aai-node-type", "p-interface") + .property("interface-name", "ge-0/0/10") + .next(); + Vertex tunnelXConnectAll_Wan1 = g.addV().property("aai-node-type", "tunnel-xconnect") + .property("id", "txc1") + .property("bandwidth-up-wan1", "300 Mbps") + .property("bandwidth-down-wan1", "400 Mbps") + .property("bandwidth-up-wan2", "500 Mbps") + .property("bandwidth-down-wan2", "600 Mbps") + .next(); + + pLinkWan1 = g.addV().property("aai-node-type", "physical-link") + .property("link-name", "pLinkWan1") + .property("service-provider-bandwidth-up-value", "empty") + .property("service-provider-bandwidth-up-units", "empty") + .property("service-provider-bandwidth-down-value", "empty") + .property("service-provider-bandwidth-down-units", "empty") + .next(); + Vertex servSub3 = g.addV().property("aai-node-type", "service-subscription") + .property("service-type", "DHV") + .next(); + Vertex servinst3 = g.addV().property("aai-node-type", "service-instance") + .property("service-type", "DHV") + .next(); + Vertex allotedRsrc3 = g.addV().property("aai-node-type", "allotted-resource") + .property("id", "rsrc1") + .next(); + Vertex servinst4 = g.addV().property("aai-node-type", "service-instance") + .property("service-type", "VVIG") + .next(); + Vertex servSub4 = g.addV().property("aai-node-type", "service-subscription") + .property("service-type", "VVIG") + .next(); + + Vertex genericvnf3 = g.addV().property("aai-node-type", "generic-vnf") + .property("vnf-id", "vnfId1") + .next(); + Vertex vServer3 = g.addV().property("aai-node-type", "vserver") + .next(); + Vertex pServer3 = g.addV().property("aai-node-type", "pserver") + .next(); + Vertex pInterfaceWan3 = g.addV().property("aai-node-type", "p-interface") + .property("interface-name", "ge-0/0/11") + .next(); + Vertex tunnelXConnectAll_Wan3 = g.addV().property("aai-node-type", "tunnel-xconnect") + .property("id", "txc3") + .property("bandwidth-up-wan1", "300 Mbps") + .property("bandwidth-down-wan1", "400 Mbps") + .property("bandwidth-up-wan2", "500 Mbps") + .property("bandwidth-down-wan2", "600 Mbps") + .next(); + + pLinkWan3 = g.addV().property("aai-node-type", "physical-link") + .property("link-name", "pLinkWan3") + .property("service-provider-bandwidth-up-value", "empty") + .property("service-provider-bandwidth-up-units", "empty") + .property("service-provider-bandwidth-down-value", "empty") + .property("service-provider-bandwidth-down-units", "empty") + .next(); + + + Vertex servSub5 = g.addV().property("aai-node-type", "service-subscription") + .property("service-type", "DHV") + .next(); + Vertex servinst5 = g.addV().property("aai-node-type", "service-instance") + .property("service-type", "DHV") + .next(); + Vertex allotedRsrc5 = g.addV().property("aai-node-type", "allotted-resource") + .property("id", "rsrc1") + .next(); + Vertex servinst6 = g.addV().property("aai-node-type", "service-instance") + .property("service-type", "VVIG") + .next(); + Vertex servSub6 = g.addV().property("aai-node-type", "service-subscription") + .property("service-type", "VVIG") + .next(); + + Vertex genericvnf5 = g.addV().property("aai-node-type", "generic-vnf") + .property("vnf-id", "vnfId1") + .next(); + Vertex vServer5 = g.addV().property("aai-node-type", "vserver") + .next(); + Vertex pServer5 = g.addV().property("aai-node-type", "pserver") + .next(); + Vertex pInterfaceWan5 = g.addV().property("aai-node-type", "p-interface") + .property("interface-name", "ge-0/0/10") + .next(); + Vertex tunnelXConnectAll_Wan5 = g.addV().property("aai-node-type", "tunnel-xconnect") + .property("id", "txc5") + .property("bandwidth-up-wan1", "") + .property("bandwidth-down-wan1", "") + .property("bandwidth-up-wan2", "500 Mbps") + .property("bandwidth-down-wan2", "600 Mbps") + .next(); + + pLinkWan5 = g.addV().property("aai-node-type", "physical-link") + .property("link-name", "pLinkWan5") + .property("service-provider-bandwidth-up-value", "") + .property("service-provider-bandwidth-up-units", "") + .property("service-provider-bandwidth-down-value", "") + .property("service-provider-bandwidth-down-units", "") + .next(); + + + Vertex servSub7 = g.addV().property("aai-node-type", "service-subscription") + .property("service-type", "DHV") + .next(); + Vertex servinst7 = g.addV().property("aai-node-type", "service-instance") + .property("service-type", "DHV") + .next(); + Vertex allotedRsrc7 = g.addV().property("aai-node-type", "allotted-resource") + .property("id", "rsrc1") + .next(); + Vertex servinst9 = g.addV().property("aai-node-type", "service-instance") + .property("service-type", "VVIG") + .next(); + Vertex servSub9 = g.addV().property("aai-node-type", "service-subscription") + .property("service-type", "VVIG") + .next(); + + Vertex genericvnf7 = g.addV().property("aai-node-type", "generic-vnf") + .property("vnf-id", "vnfId1") + .next(); + Vertex vServer7 = g.addV().property("aai-node-type", "vserver") + .next(); + Vertex pServer7 = g.addV().property("aai-node-type", "pserver") + .next(); + Vertex pInterfaceWan7 = g.addV().property("aai-node-type", "p-interface") + .property("interface-name", "ge-0/0/11") + .next(); + Vertex tunnelXConnectAll_Wan7 = g.addV().property("aai-node-type", "tunnel-xconnect") + .property("id", "txc7") + .property("bandwidth-up-wan1", "300 Mbps") + .property("bandwidth-down-wan1", "400 Mbps") + .property("bandwidth-up-wan2", "") + .property("bandwidth-down-wan2", "") + .next(); + + pLinkWan7 = g.addV().property("aai-node-type", "physical-link") + .property("link-name", "pLinkWan5") + .property("service-provider-bandwidth-up-value", "") + .property("service-provider-bandwidth-up-units", "") + .property("service-provider-bandwidth-down-value", "") + .property("service-provider-bandwidth-down-units", "") + .next(); + + + + rules.addTreeEdge(g, servSub1, servinst1); + rules.addEdge(g, servinst1, allotedRsrc1); + rules.addTreeEdge(g, servinst2, servSub2); + rules.addTreeEdge(g, allotedRsrc1, servinst2); + + rules.addTreeEdge(g, allotedRsrc1, tunnelXConnectAll_Wan1); + + + rules.addEdge(g, servinst1, genericvnf1); + rules.addEdge(g, genericvnf1, vServer1); + rules.addEdge(g, vServer1, pServer1); + rules.addTreeEdge(g, pServer1, pInterfaceWan1); + rules.addEdge(g, pInterfaceWan1, pLinkWan1); + + rules.addTreeEdge(g, servSub3, servinst3); + rules.addEdge(g, servinst3, allotedRsrc3); + rules.addTreeEdge(g, servinst4, servSub4); + rules.addTreeEdge(g, allotedRsrc3, servinst4); + + rules.addTreeEdge(g, allotedRsrc3, tunnelXConnectAll_Wan3); + + + rules.addEdge(g, servinst3, genericvnf3); + rules.addEdge(g, genericvnf3, vServer3); + rules.addEdge(g, vServer3, pServer3); + rules.addTreeEdge(g, pServer3, pInterfaceWan3); + rules.addEdge(g, pInterfaceWan3, pLinkWan3); + + + rules.addTreeEdge(g, servSub5, servinst5); + rules.addEdge(g, servinst5, allotedRsrc5); + rules.addTreeEdge(g, servinst6, servSub6); + rules.addTreeEdge(g, allotedRsrc5, servinst6); + + rules.addTreeEdge(g, allotedRsrc5, tunnelXConnectAll_Wan5); + + + rules.addEdge(g, servinst5, genericvnf5); + rules.addEdge(g, genericvnf5, vServer5); + rules.addEdge(g, vServer5, pServer5); + rules.addTreeEdge(g, pServer5, pInterfaceWan5); + rules.addEdge(g, pInterfaceWan5, pLinkWan5); + + rules.addTreeEdge(g, servSub7, servinst7); + rules.addEdge(g, servinst7, allotedRsrc7); + rules.addTreeEdge(g, servinst9, servSub9); + rules.addTreeEdge(g, allotedRsrc7, servinst9); + + rules.addTreeEdge(g, allotedRsrc7, tunnelXConnectAll_Wan7); + + + rules.addEdge(g, servinst7, genericvnf7); + rules.addEdge(g, genericvnf7, vServer7); + rules.addEdge(g, vServer7, pServer7); + rules.addTreeEdge(g, pServer7, pInterfaceWan7); + rules.addEdge(g, pInterfaceWan7, pLinkWan7); + + + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + GraphTraversalSource traversal = g; + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + migration = new SDWANSpeedChangeMigration(spy); + migration.run(); + } + + + @After + public void cleanUp() { + tx.rollback(); + graph.close(); + } + + + /*** + * Checks to see if the Wan1 properties were updated in the physical link + */ + + @Test + public void ConfirmWan1Changes() { + + assertEquals("300", pLinkWan1.property("service-provider-bandwidth-up-value").value().toString()); + assertEquals("Mbps", pLinkWan1.property("service-provider-bandwidth-up-units").value().toString()); + assertEquals("400", pLinkWan1.property("service-provider-bandwidth-down-value").value().toString()); + assertEquals("Mbps", pLinkWan1.property("service-provider-bandwidth-down-units").value().toString()); + + } + + /*** + * Checks to see if the Wan2 properties were updated in the physical link + */ + @Test + public void ConfirmWan2Changes() { + + assertEquals("500", pLinkWan3.property("service-provider-bandwidth-up-value").value().toString()); + assertEquals("Mbps", pLinkWan3.property("service-provider-bandwidth-up-units").value().toString()); + assertEquals("600", pLinkWan3.property("service-provider-bandwidth-down-value").value().toString()); + assertEquals("Mbps", pLinkWan3.property("service-provider-bandwidth-down-units").value().toString()); + + } + + /*** + * if tunnel xconncets missing bandwidth up 1 value the plink should not be updated + */ + + @Test + public void Wan1EmptyNoChanges() { + + assertEquals("", pLinkWan5.property("service-provider-bandwidth-up-value").value().toString()); + assertEquals("", pLinkWan5.property("service-provider-bandwidth-up-units").value().toString()); + assertEquals("", pLinkWan5.property("service-provider-bandwidth-down-value").value().toString()); + assertEquals("", pLinkWan5.property("service-provider-bandwidth-down-units").value().toString()); + + } + + /*** + * if tunnel xconncets missing bandwidth up 2 value the plink should not be updated + */ + + @Test + public void Wan2EmptyNoChanges() { + + assertEquals("", pLinkWan7.property("service-provider-bandwidth-up-value").value().toString()); + assertEquals("", pLinkWan7.property("service-provider-bandwidth-up-units").value().toString()); + assertEquals("", pLinkWan7.property("service-provider-bandwidth-down-value").value().toString()); + assertEquals("", pLinkWan7.property("service-provider-bandwidth-down-units").value().toString()); + + } + + +} diff --git a/aai-resources/src/test/java/org/onap/aai/migration/v12/ToscaMigrationTest.java b/aai-resources/src/test/java/org/onap/aai/migration/v12/ToscaMigrationTest.java index a690308..9e21947 100644 --- a/aai-resources/src/test/java/org/onap/aai/migration/v12/ToscaMigrationTest.java +++ b/aai-resources/src/test/java/org/onap/aai/migration/v12/ToscaMigrationTest.java @@ -19,9 +19,9 @@ */ package org.onap.aai.migration.v12; -import com.thinkaurelius.titan.core.TitanFactory; -import com.thinkaurelius.titan.core.TitanGraph; -import com.thinkaurelius.titan.core.schema.TitanManagement; +import org.janusgraph.core.JanusGraphFactory; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.schema.JanusGraphManagement; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; @@ -39,7 +39,7 @@ import org.onap.aai.introspection.Version; import org.onap.aai.serialization.db.AAIDirection; import org.onap.aai.serialization.db.EdgeProperty; import org.onap.aai.serialization.engines.QueryStyle; -import org.onap.aai.serialization.engines.TitanDBEngine; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import static org.junit.Assert.assertEquals; @@ -55,19 +55,19 @@ public class ToscaMigrationTest extends AAISetup { private final static DBConnectionType type = DBConnectionType.REALTIME; private Loader loader; private TransactionalGraphEngine dbEngine; - private TitanGraph graph; + private JanusGraph graph; private ToscaMigration migration; private GraphTraversalSource g; private Graph tx; @Before public void setUp() throws Exception { - graph = TitanFactory.build().set("storage.backend","inmemory").open(); - TitanManagement titanManagement = graph.openManagement(); + graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); + JanusGraphManagement janusgraphManagement = graph.openManagement(); tx = graph.newTransaction(); g = tx.traversal(); loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); - dbEngine = new TitanDBEngine( + dbEngine = new JanusGraphDBEngine( queryStyle, type, loader); @@ -104,7 +104,7 @@ public class ToscaMigrationTest extends AAISetup { GraphTraversalSource traversal = g; when(spy.asAdmin()).thenReturn(adminSpy); when(adminSpy.getTraversalSource()).thenReturn(traversal); - Mockito.doReturn(titanManagement).when(adminSpy).getManagementSystem(); + Mockito.doReturn(janusgraphManagement).when(adminSpy).getManagementSystem(); migration = new ToscaMigration(spy); migration.run(); diff --git a/aai-resources/src/test/java/org/onap/aai/migration/v13/MigrateInstanceGroupSubTypeTest.java b/aai-resources/src/test/java/org/onap/aai/migration/v13/MigrateInstanceGroupSubTypeTest.java new file mode 100644 index 0000000..a29fb6b --- /dev/null +++ b/aai-resources/src/test/java/org/onap/aai/migration/v13/MigrateInstanceGroupSubTypeTest.java @@ -0,0 +1,112 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.aai.migration.v13; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.aai.AAISetup; +import org.onap.aai.dbmap.DBConnectionType; +import org.onap.aai.introspection.Loader; +import org.onap.aai.introspection.LoaderFactory; +import org.onap.aai.introspection.ModelType; +import org.onap.aai.introspection.Version; +import org.onap.aai.serialization.engines.QueryStyle; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; +import org.onap.aai.serialization.engines.TransactionalGraphEngine; + +import org.janusgraph.core.JanusGraphFactory; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphTransaction; + + +public class MigrateInstanceGroupSubTypeTest extends AAISetup{ + + private static final String SUB_TYPE_VALUE = "SubTypeValue"; + private final static Version version = Version.v13; + private final static ModelType introspectorFactoryType = ModelType.MOXY; + private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL; + private final static DBConnectionType type = DBConnectionType.REALTIME; + private Loader loader; + private TransactionalGraphEngine dbEngine; + private JanusGraph graph; + private MigrateInstanceGroupSubType migration; + private GraphTraversalSource g; + private JanusGraphTransaction tx; + Vertex instanceGroup; + Vertex instanceGroupWithoutTSubType; + + + @Before + public void setUp() throws Exception { + graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open(); + tx = graph.newTransaction(); + g = tx.traversal(); + loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); + dbEngine = new JanusGraphDBEngine( + queryStyle, + type, + loader); + instanceGroup = g.addV().property("aai-node-type", MigrateInstanceGroupSubType.INSTANCE_GROUP_NODE_TYPE) + .property( MigrateInstanceGroupSubType.SUB_TYPE_PROPERTY, SUB_TYPE_VALUE) + .next(); + + instanceGroupWithoutTSubType = g.addV().property("aai-node-type", MigrateInstanceGroupSubType.INSTANCE_GROUP_NODE_TYPE) + .next(); + + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + GraphTraversalSource traversal = g; + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + migration = new MigrateInstanceGroupSubType(spy); + } + + @After + public void cleanUp() { + tx.rollback(); + graph.close(); + } + + + /*** + * checks if the type/subtype property were renamed + */ + + @Test + public void confirmTypeAndSubTypeWereRenamed() { + migration.run(); + + //instance group with sub-type + assertEquals(SUB_TYPE_VALUE, instanceGroup.property(MigrateInstanceGroupSubType.INSTANCE_GROUP_ROLE_PROPERTY).value()); + assertFalse(instanceGroup.property(MigrateInstanceGroupSubType.SUB_TYPE_PROPERTY).isPresent()); + + //instance group without subtype + assertFalse(instanceGroupWithoutTSubType.property(MigrateInstanceGroupSubType.INSTANCE_GROUP_ROLE_PROPERTY).isPresent()); + assertFalse(instanceGroupWithoutTSubType.property(MigrateInstanceGroupSubType.SUB_TYPE_PROPERTY).isPresent()); + } +}
\ No newline at end of file diff --git a/aai-resources/src/test/java/org/onap/aai/migration/v13/MigrateInstanceGroupTypeTest.java b/aai-resources/src/test/java/org/onap/aai/migration/v13/MigrateInstanceGroupTypeTest.java new file mode 100644 index 0000000..11e5157 --- /dev/null +++ b/aai-resources/src/test/java/org/onap/aai/migration/v13/MigrateInstanceGroupTypeTest.java @@ -0,0 +1,112 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.aai.migration.v13; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.aai.AAISetup; +import org.onap.aai.dbmap.DBConnectionType; +import org.onap.aai.introspection.Loader; +import org.onap.aai.introspection.LoaderFactory; +import org.onap.aai.introspection.ModelType; +import org.onap.aai.introspection.Version; +import org.onap.aai.serialization.engines.QueryStyle; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; +import org.onap.aai.serialization.engines.TransactionalGraphEngine; + +import org.janusgraph.core.JanusGraphFactory; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphTransaction; + + +public class MigrateInstanceGroupTypeTest extends AAISetup{ + + private static final String TYPE_VALUE = "TypeValue"; + private final static Version version = Version.v13; + private final static ModelType introspectorFactoryType = ModelType.MOXY; + private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL; + private final static DBConnectionType type = DBConnectionType.REALTIME; + private Loader loader; + private TransactionalGraphEngine dbEngine; + private JanusGraph graph; + private MigrateInstanceGroupType migration; + private GraphTraversalSource g; + private JanusGraphTransaction tx; + Vertex instanceGroup; + Vertex instanceGroupWithoutType; + + + @Before + public void setUp() throws Exception { + graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open(); + tx = graph.newTransaction(); + g = tx.traversal(); + loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); + dbEngine = new JanusGraphDBEngine( + queryStyle, + type, + loader); + instanceGroup = g.addV().property("aai-node-type", MigrateInstanceGroupType.INSTANCE_GROUP_NODE_TYPE) + .property( MigrateInstanceGroupType.TYPE_PROPERTY, TYPE_VALUE) + .next(); + + instanceGroupWithoutType = g.addV().property("aai-node-type", MigrateInstanceGroupType.INSTANCE_GROUP_NODE_TYPE) + .next(); + + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + GraphTraversalSource traversal = g; + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + migration = new MigrateInstanceGroupType(spy); + } + + @After + public void cleanUp() { + tx.rollback(); + graph.close(); + } + + + /*** + * checks if the type/subtype property were renamed + */ + + @Test + public void confirmTypeAndSubTypeWereRenamed() { + migration.run(); + + //instance group with type + assertEquals(TYPE_VALUE, instanceGroup.property(MigrateInstanceGroupType.INSTANCE_GROUP_TYPE_PROPERTY).value()); + assertFalse(instanceGroup.property(MigrateInstanceGroupType.TYPE_PROPERTY).isPresent()); + + //instance group without type + assertFalse(instanceGroupWithoutType.property(MigrateInstanceGroupType.INSTANCE_GROUP_TYPE_PROPERTY).isPresent()); + assertFalse(instanceGroupWithoutType.property(MigrateInstanceGroupType.TYPE_PROPERTY).isPresent()); + } +}
\ No newline at end of file diff --git a/aai-resources/src/test/java/org/onap/aai/schema/db/ManageSchemaTest.java b/aai-resources/src/test/java/org/onap/aai/schema/db/ManageSchemaTest.java index 5c2c2d7..de5eba1 100644 --- a/aai-resources/src/test/java/org/onap/aai/schema/db/ManageSchemaTest.java +++ b/aai-resources/src/test/java/org/onap/aai/schema/db/ManageSchemaTest.java @@ -19,18 +19,18 @@ */ package org.onap.aai.schema.db; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.thinkaurelius.titan.core.TitanFactory; -import com.thinkaurelius.titan.core.TitanGraph; -import com.thinkaurelius.titan.core.schema.TitanManagement; +import org.janusgraph.core.JanusGraphFactory; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.schema.JanusGraphManagement; +import org.codehaus.jackson.JsonParseException; +import org.codehaus.jackson.map.JsonMappingException; +import org.codehaus.jackson.map.ObjectMapper; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.onap.aai.AAISetup; import org.onap.aai.db.schema.DBIndex; -import org.onap.aai.db.schema.ManageTitanSchema; +import org.onap.aai.db.schema.ManageJanusGraphSchema; import java.io.IOException; import java.util.Set; @@ -38,24 +38,23 @@ import java.util.Set; @Ignore("not ready yet") public class ManageSchemaTest extends AAISetup { - private TitanGraph graph = null; + private JanusGraph graph = null; @Before public void beforeTest() { - //graph = TitanFactory.open("src/test/resources/inmemory_titan.properties"); - graph = TitanFactory.open("bundleconfig-local/etc/appprops/aaiconfig.properties"); + graph = JanusGraphFactory.open("bundleconfig-local/etc/appprops/aaiconfig.properties"); } /* @Test public void populateEmptyGraph() { - ManageTitanSchema schema = new ManageTitanSchema(graph); + ManageJanusGraphSchema schema = new ManageJanusGraphSchema(graph); schema.buildSchema(); } @Test public void modifyIndex() { - ManageTitanSchema schema = new ManageTitanSchema(graph); + ManageJanusGraphSchema schema = new ManageJanusGraphSchema(graph); schema.buildSchema(); Vertex v = graph.addVertex(); v.setProperty("aai-node-type", "pserver"); @@ -72,7 +71,7 @@ public class ManageSchemaTest extends AAISetup { @Test public void closeRunningInstances() { - TitanManagement mgmt = graph.openManagement(); + JanusGraphManagement mgmt = graph.openManagement(); Set<String> instances = mgmt.getOpenInstances(); for (String instance : instances) { @@ -99,8 +98,8 @@ public class ManageSchemaTest extends AAISetup { " } ]\r\n" + " }"; DBIndex index = mapper.readValue(content, DBIndex.class); - ManageTitanSchema schema = new ManageTitanSchema(graph); - TitanManagement mgmt = graph.openManagement(); + ManageJanusGraphSchema schema = new ManageJanusGraphSchema(graph); + JanusGraphManagement mgmt = graph.openManagement(); Set<String> instances = mgmt.getOpenInstances(); System.out.println(instances); schema.updateIndex(index); |