diff options
Diffstat (limited to 'src/test/java/org/onap/aai/migration/v12')
9 files changed, 2380 insertions, 0 deletions
diff --git a/src/test/java/org/onap/aai/migration/v12/ALTSLicenseEntitlementMigrationTest.java b/src/test/java/org/onap/aai/migration/v12/ALTSLicenseEntitlementMigrationTest.java new file mode 100644 index 0000000..ad4ae1b --- /dev/null +++ b/src/test/java/org/onap/aai/migration/v12/ALTSLicenseEntitlementMigrationTest.java @@ -0,0 +1,161 @@ +/** + * ============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 static org.junit.Assert.*; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import java.io.UnsupportedEncodingException; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.*; +import org.onap.aai.AAISetup; +import org.onap.aai.db.props.AAIProperties; +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.setup.SchemaVersions; +import org.onap.aai.setup.SchemaVersion; +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 ALTSLicenseEntitlementMigrationTest extends AAISetup { + 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 ALTSLicenseEntitlementMigration migration; + private GraphTraversalSource g; + private JanusGraphTransaction tx; + + @Before + public void setUp() throws Exception { + graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); + tx = graph.newTransaction(); + g = tx.traversal(); + loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion()); + System.setProperty("AJSC_HOME", "."); + System.setProperty("BUNDLECONFIG_DIR", "src/test/resources"); + dbEngine = new JanusGraphDBEngine( + queryStyle, + type, + loader); + + Vertex vnf = g.addV().property("aai-node-type", "generic-vnf") + .property("vnf-id", "123456789") + .property("vnf-name", "test-vnf-name") + .property("equipment-role", "UCPE") + .next(); + + Vertex entitlement = g.addV().property("aai-node-type", "entitlement") + .property("group-uuid", "guuid-entitlement") + .property("resource-uuid", "ruuid-entitlement") + .property("aai-uri", "/network/generic-vnfs/generic-vnf/123456789/entitlements/entitlement/ruuideuuid/ruuid-entitlement") + .next(); + + Vertex license = g.addV().property("aai-node-type", "license") + .property("group-uuid", "guuid-license") + .property("resource-uuid", "ruuid-license") + .property("aai-uri", "/network/generic-vnfs/generic-vnf/123456789/licenses/license/ruuideuuid/ruuid-license") + .next(); + + Vertex vnf2 = g.addV().property("aai-node-type", "generic-vnf") + .property("vnf-id", "23456789") + .property("vnf-name", "test-vnf-name") + .property("equipment-role", "UCPE") + .next(); + Vertex duplicateEntitlement = g.addV().property("aai-node-type", "entitlement") + .property("group-uuid", "guuid") + .property("resource-uuid", "ruuid-entitlement") + .property("aai-uri", "/network/generic-vnfs/generic-vnf/123456789/entitlements/entitlement/ruuideuuid/ruuid-entitlement") + .next(); + + Vertex duplicateLicense = g.addV().property("aai-node-type", "license") + .property("group-uuid", "guuid") + .property("resource-uuid", "ruuid-license") + .property("aai-uri", "/network/generic-vnfs/generic-vnf/123456789/licenses/license/ruuideuuid/ruuid-license") + .next(); + + + + edgeSerializer.addTreeEdge(g, vnf, license); + edgeSerializer.addTreeEdge(g, vnf, entitlement); + edgeSerializer.addTreeEdge(g, vnf2, duplicateEntitlement); + edgeSerializer.addTreeEdge(g, vnf2, duplicateLicense); + + 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 ALTSLicenseEntitlementMigration(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions); + migration.run(); + } + + @After + public void cleanUp() { + tx.rollback(); + graph.close(); + } + + @Test + public void testEntitlementsUpdated() throws UnsupportedEncodingException { + assertEquals("Found 1 entitlement", (Long)1L, + g.V().has("aai-node-type", "generic-vnf").has("vnf-id", "123456789").in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "entitlement").count().next()); + assertEquals("Entitlement's resource-uuid is updated ", true, + g.V().has("aai-node-type", "generic-vnf").has("vnf-id", "123456789").in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "entitlement").has("resource-uuid", "new-ruuid-entitlement").hasNext()); + assertEquals("Entitlement's resource-uuid is updated by migration ", true, + g.V().has("aai-node-type", "generic-vnf").has("vnf-id", "123456789").in("org.onap.relationships.inventory.BelongsTo") + .has("aai-node-type", "entitlement").has("resource-uuid", "new-ruuid-entitlement").has("last-mod-source-of-truth", "ALTSLicenseEntitlementMigration").hasNext()); + } + @Test + public void testLicensesUpdated() throws UnsupportedEncodingException { + assertEquals("Found 1 License", (Long)1L, + g.V().has("aai-node-type", "generic-vnf").has("vnf-id", "123456789").in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "license").count().next()); + assertEquals("License's resource-uuid is updated ", true, + g.V().has("aai-node-type", "generic-vnf").has("vnf-id", "123456789").in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "license").has("resource-uuid", "new-ruuid-license").hasNext()); + } + + @Test + public void verifyUri() { + assertEquals("Uri should be updated", "/network/generic-vnfs/generic-vnf/123456789/entitlements/entitlement/ruuideuuid/new-ruuid-entitlement", + g.V().has("aai-node-type", "generic-vnf").has("vnf-id", "123456789").in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "entitlement").has("resource-uuid", "new-ruuid-entitlement").next().property(AAIProperties.AAI_URI).value()); + assertEquals("Uri should be updated", "/network/generic-vnfs/generic-vnf/123456789/licenses/license/ruuideuuid/new-ruuid-license", + g.V().has("aai-node-type", "generic-vnf").has("vnf-id", "123456789").in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "license").has("resource-uuid", "new-ruuid-license").next().property(AAIProperties.AAI_URI).value()); + } + + @Test + public void duplicateGroupUuid() { + Long count = g.V().has("aai-node-type", "generic-vnf").has("vnf-id", "23456789").in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "license").has("resource-uuid", "new-ruuid-license2").count().next() + + g.V().has("aai-node-type", "generic-vnf").has("vnf-id", "23456789").in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "entitlement").has("resource-uuid", "new-ruuid-entitlement2").count().next(); + assertEquals("Duplicate Entitlement or License Group Uuid should be skipped", (Long)1L, count); + + + } +} diff --git a/src/test/java/org/onap/aai/migration/v12/MigrateDataFromASDCToConfigurationTest.java b/src/test/java/org/onap/aai/migration/v12/MigrateDataFromASDCToConfigurationTest.java new file mode 100644 index 0000000..7acb40d --- /dev/null +++ b/src/test/java/org/onap/aai/migration/v12/MigrateDataFromASDCToConfigurationTest.java @@ -0,0 +1,199 @@ +/** + * ============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.ModelType; +import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.setup.SchemaVersion; +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 MigrateDataFromASDCToConfigurationTest extends AAISetup { + + 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 MigrateDataFromASDCToConfiguration migration; + private GraphTraversalSource g; + private JanusGraphTransaction tx; + + Vertex configuration; + Vertex configuration2; + Vertex configuration3; + Vertex configuration4; + Vertex configuration5; + + private boolean success = true; + private String entitlementPoolUuid = ""; + private final String PARENT_NODE_TYPE = "generic-vnf"; + private String VNT = ""; + + @Before + public void setUp() throws Exception { + graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); + tx = graph.newTransaction(); + g = tx.traversal(); + loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion()); + dbEngine = new JanusGraphDBEngine( + queryStyle, + type, + loader); + + System.setProperty("BUNDLECONFIG_DIR", "src/test/resources"); + Vertex genericvnf1 = g.addV().property("aai-node-type", "generic-vnf") + .property("vnf-id", "vnfId1") + .property("vnf-type","HN") + .next(); + + Vertex genericvnf2 = g.addV().property("aai-node-type", "generic-vnf") + .property("vnf-id", "vnfId2") + .property("vnf-type","HN") + .next(); + + Vertex genericvnf_wrongtype = g.addV().property("aai-node-type", "generic-vnf") + .property("vnf-id", "vnfIdWrong") + .property("vnf-type","vHNF") + .next(); + + Vertex entitlement1 = g.addV().property("aai-node-type", "entitlement") + .property("group-uuid", "599a2d74-cfbd-413d-aedb-ec4875817313") + .next(); + + Vertex entitlement2 = g.addV().property("aai-node-type", "entitlement") + .property("group-uuid", "ea9a547e-137b-48e9-a788-c3fb4e631a2a") + .next(); + + Vertex serviceInstance1 = g.addV().property("aai-node-type", "service-instance") + .property("service-instance-id", "servinstanceTestId1") + .next(); + + Vertex serviceInstance2 = g.addV().property("aai-node-type", "service-instance") + .property("service-instance-id", "servinstanceTestId2") + .next(); + + configuration = g.addV().property("aai-node-type", "configuration") + .property("configuration-id", "configurationIdGraph") + .property("vendor-allowed-max-bandwidth", "20") + .next(); + configuration3 = g.addV().property("aai-node-type", "configuration") + .property("configuration-id", "configurationIdGraph3") + .property("vendor-allowed-max-bandwidth", "15") + .next(); + configuration2 = g.addV().property("aai-node-type", "configuration") + .property("configuration-id", "configurationIdGraph2") + .property("vendor-allowed-max-bandwidth", "25") + .next(); + configuration4 = g.addV().property("aai-node-type", "configuration") + .property("configuration-id", "configurationIdGraph4") + .property("vendor-allowed-max-bandwidth", "50") + .next(); + configuration5 = g.addV().property("aai-node-type", "configuration") + .property("configuration-id", "configurationIdGraph4") + .property("vendor-allowed-max-bandwidth", "75") + .next(); + + edgeSerializer.addTreeEdge(g, genericvnf1, entitlement1); + edgeSerializer.addEdge(g, genericvnf1, serviceInstance1); + edgeSerializer.addEdge(g, serviceInstance1, configuration); + edgeSerializer.addEdge(g, serviceInstance1, configuration3); + + + edgeSerializer.addEdge(g, genericvnf2, configuration2, "org.onap.relationships.inventory.Uses"); + + edgeSerializer.addTreeEdge(g, genericvnf_wrongtype, entitlement2); + edgeSerializer.addEdge(g, genericvnf_wrongtype, serviceInstance2); + edgeSerializer.addEdge(g, serviceInstance2, configuration5); + + 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 MigrateDataFromASDCToConfiguration(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions); + migration.run(); + } + + + @After + public void cleanUp() { + tx.rollback(); + graph.close(); + } + + + /*** + * checks if the VNt value was updated and if theres a second configuration object it is also to be modified + */ + + @Test + public void confirmVNtValueChanged() { + + assertEquals("1000",configuration.property("vendor-allowed-max-bandwidth").value()); + assertEquals("1000",configuration3.property("vendor-allowed-max-bandwidth").value()); + + } + + /*** + * checks to see if the entitlement object is missing the configuration objects should not be modified at all + */ + @Test + public void missingEntitlementObject() { + assertEquals("25",configuration2.property("vendor-allowed-max-bandwidth").value()); + } + /*** + * checks to see if there's a configuration object not connected to anything it should not be modified at all + */ + + @Test + public void confirmConfiguration4notchanged() { + assertEquals("50",configuration4.property("vendor-allowed-max-bandwidth").value()); + } + /*** + * checks that a configuration object not linked to a "HN" vnf-type should not be changed + */ + @Test + public void differentVNFType() { + assertEquals("75",configuration5.property("vendor-allowed-max-bandwidth").value()); + } + + + + +} diff --git a/src/test/java/org/onap/aai/migration/v12/MigrateHUBEvcInventoryTest.java b/src/test/java/org/onap/aai/migration/v12/MigrateHUBEvcInventoryTest.java new file mode 100644 index 0000000..72daf2e --- /dev/null +++ b/src/test/java/org/onap/aai/migration/v12/MigrateHUBEvcInventoryTest.java @@ -0,0 +1,377 @@ +/** + * ============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 static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import java.util.Optional; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy; +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.setup.SchemaVersions; +import org.onap.aai.setup.SchemaVersion; +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 MigrateHUBEvcInventoryTest extends AAISetup { + + 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 MigrateHUBEvcInventory migration; + private JanusGraphTransaction tx; + private GraphTraversalSource g; + + @Before + public void setUp() throws Exception { + graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); + tx = graph.newTransaction(); + g = tx.traversal(); + loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion()); + dbEngine = new JanusGraphDBEngine( + queryStyle, + type, + loader); + + System.setProperty("BUNDLECONFIG_DIR", "src/test/resources"); + + Vertex customer1 = g.addV() + .property("aai-node-type", "customer") + .property("global-customer-id", "customer-id-1") + .property("subscriber-type", "CUST") + .next(); + + Vertex servSub1 = g.addV() + .property("aai-node-type", "service-subscription") + .property("service-type", "SAREA") + .next(); + + Vertex servInstance1 = g.addV() + .property("aai-node-type", "service-instance") + .property("service-type", "SAREA") + .property("service-instance-id", "evc-name-1") + .next(); + Vertex servInstance3 = g.addV() + .property("aai-node-type", "service-instance") + .property("service-type", "SAREA") + .property("service-instance-id", "evc-name-3") + .next(); + Vertex servInstance2 = g.addV() + .property("aai-node-type", "service-instance") + .property("service-type", "SAREA") + .property("service-instance-id", "evc-name-2") + .next(); + + Vertex evc1 = g.addV().property("aai-node-type", "evc") + .property("evc-id", "evc-name-1") + .next(); + Vertex config1 = g.addV().property("aai-node-type", "configuration") + .property("configuration-id", "evc-name-1") + .next(); + Vertex fp1 = g.addV() + .property("aai-node-type", "forwarding-path") + .property("forwarding-path-id", "evc-name-1") + .next(); + Vertex for11 = g.addV() + .property("aai-node-type", "forwarder") + .property("sequence", "1") + .property("forwarder-role","ingress") + .next(); + Vertex for12 = g.addV() + .property("aai-node-type", "forwarder") + .property("sequence", "2") + .property("forwarder-role","egress") + .next(); + Vertex config11 = g.addV() + .property("aai-node-type", "configuration") + .property("configuration-id", "evc-name-1-1") + .next(); + Vertex config12 = g.addV() + .property("aai-node-type", "configuration") + .property("configuration-id", "evc-name-1-2") + .next(); + Vertex fevc11 = g.addV() + .property("aai-node-type", "forwarder-evc") + .property("forwarder-evc-id", "evc-name-1-1") + .property("svlan", "6") + .next(); + Vertex fevc12 = g.addV() + .property("aai-node-type", "forwarder-evc") + .property("forwarder-evc-id", "evc-name-1-2") + .property("svlan", "16") + .next(); + + + + Vertex evc2 = g.addV().property("aai-node-type", "evc") + .property("evc-id", "evc-name-2") + .next(); + Vertex config2 = g.addV().property("aai-node-type", "configuration") + .property("configuration-id", "evc-name-2") + .next(); + Vertex fp2 = g.addV() + .property("aai-node-type", "forwarding-path") + .property("forwarding-path-id", "evc-name-2") + .next(); + Vertex for21 = g.addV() + .property("aai-node-type", "forwarder") + .property("sequence", "1") + .property("forwarder-role","ingress") + .next(); + Vertex for22 = g.addV() + .property("aai-node-type", "forwarder") + .property("sequence", "2") + .property("forwarder-role","ingress") + .next(); + Vertex for23 = g.addV() + .property("aai-node-type", "forwarder") + .property("sequence", "3") + .property("forwarder-role","egress") + .next(); + Vertex for24 = g.addV() + .property("aai-node-type", "forwarder") + .property("sequence", "4") + .property("forwarder-role","egress") + .next(); + Vertex config21 = g.addV() + .property("aai-node-type", "configuration") + .property("configuration-id", "evc-name-2-1") + .next(); + Vertex config22 = g.addV() + .property("aai-node-type", "configuration") + .property("configuration-id", "evc-name-2-2") + .next(); + Vertex config23 = g.addV() + .property("aai-node-type", "configuration") + .property("configuration-id", "evc-name-2-3") + .next(); + Vertex config24 = g.addV() + .property("aai-node-type", "configuration") + .property("configuration-id", "evc-name-2-4") + .next(); + Vertex fevc21 = g.addV() + .property("aai-node-type", "forwarder-evc") + .property("forwarder-evc-id", "evc-name-2-1") + .property("svlan", "6") + .next(); + Vertex fevc22 = g.addV() + .property("aai-node-type", "forwarder-evc") + .property("forwarder-evc-id", "evc-name-2-2") + .property("svlan", "16") + .next(); + Vertex fevc23 = g.addV() + .property("aai-node-type", "forwarder-evc") + .property("forwarder-evc-id", "evc-name-2-3") + .property("svlan", "12") + .property("ivlan", "600") + .next(); + Vertex fevc24 = g.addV() + .property("aai-node-type", "forwarder-evc") + .property("forwarder-evc-id", "evc-name-2-4") + .property("svlan", "16") + .property("ivlan", "600") + .next(); + + Vertex evc3 = g.addV().property("aai-node-type", "evc") + .property("evc-id", "evc-name-3") + .next(); + Vertex config3 = g.addV().property("aai-node-type", "configuration") + .property("configuration-id", "evc-name-3") + .next(); + Vertex fp3 = g.addV() + .property("aai-node-type", "forwarding-path") + .property("forwarding-path-id", "evc-name-3") + .next(); + Vertex for31 = g.addV() + .property("aai-node-type", "forwarder") + .property("sequence", "1") + .property("forwarder-role","ingress") + .next(); + Vertex for32 = g.addV() + .property("aai-node-type", "forwarder") + .property("sequence", "2") + .property("forwarder-role","egress") + .next(); + Vertex config31 = g.addV() + .property("aai-node-type", "configuration") + .property("configuration-id", "evc-name-3-1") + .next(); + Vertex config32 = g.addV() + .property("aai-node-type", "configuration") + .property("configuration-id", "evc-name-3-2") + .next(); + Vertex fevc31 = g.addV() + .property("aai-node-type", "forwarder-evc") + .property("forwarder-evc-id", "evc-name-3-1") + .property("svlan", "6") + .next(); + Vertex fevc32 = g.addV() + .property("aai-node-type", "forwarder-evc") + .property("forwarder-evc-id", "evc-name-3-2") +// .property("svlan", "16") + .next(); + + // graph 1 + edgeSerializer.addTreeEdge(g, customer1, servSub1); + edgeSerializer.addTreeEdge(g, servSub1, servInstance1); + edgeSerializer.addTreeEdge(g, servSub1, servInstance2); + edgeSerializer.addTreeEdge(g, servSub1, servInstance3); + + edgeSerializer.addEdge(g, servInstance1, fp1); + edgeSerializer.addEdge(g, servInstance2, fp2); + + edgeSerializer.addEdge(g, fp1, config1); + edgeSerializer.addEdge(g, fp2, config2); + edgeSerializer.addEdge(g, fp3, config3); + + edgeSerializer.addTreeEdge(g, evc1, config1); + edgeSerializer.addTreeEdge(g, evc2, config2); + edgeSerializer.addTreeEdge(g, evc3, config3); + + edgeSerializer.addTreeEdge(g, fp1, for11); + edgeSerializer.addTreeEdge(g, fp1, for12); + edgeSerializer.addTreeEdge(g, fp2, for21); + edgeSerializer.addTreeEdge(g, fp2, for22); + edgeSerializer.addTreeEdge(g, fp2, for23); + edgeSerializer.addTreeEdge(g, fp2, for24); + edgeSerializer.addTreeEdge(g, fp3, for31); + edgeSerializer.addTreeEdge(g, fp3, for32); + + edgeSerializer.addEdge(g, for11, config11); + edgeSerializer.addEdge(g, for12, config12); + edgeSerializer.addEdge(g, for21, config21); + edgeSerializer.addEdge(g, for22, config22); + edgeSerializer.addEdge(g, for23, config23); + edgeSerializer.addEdge(g, for24, config24); + edgeSerializer.addEdge(g, for31, config31); + edgeSerializer.addEdge(g, for32, config32); + + edgeSerializer.addTreeEdge(g, config11, fevc11); + edgeSerializer.addTreeEdge(g, config12, fevc12); + edgeSerializer.addTreeEdge(g, config21, fevc21); + edgeSerializer.addTreeEdge(g, config22, fevc22); + edgeSerializer.addTreeEdge(g, config23, fevc23); + edgeSerializer.addTreeEdge(g, config24, fevc24); + edgeSerializer.addTreeEdge(g, config31, fevc31); + edgeSerializer.addTreeEdge(g, config32, fevc32); + + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + + GraphTraversalSource traversal = g; + GraphTraversalSource readOnly = tx.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance())); + when (spy.tx()).thenReturn(tx); + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + when(adminSpy.getReadOnlyTraversalSource()).thenReturn(readOnly); + + migration = new MigrateHUBEvcInventory(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions); + migration.run(); + } + + @After + public void cleanUp() { + tx.tx().rollback(); + graph.close(); + } + + @Test + public void testRun_checkFevc1AndFevc2AreUpdated() throws Exception { + + // check if forwarder-evc nodes get updated + assertEquals("forwarder-evc evc-name-1-1 updated with ivlan", true, + g.V().has("aai-node-type", "forwarder-evc") + .has("forwarder-evc-id", "evc-name-1-1") + .has("ivlan","4054") + .hasNext()); + + assertEquals("forwarder-evc evc-name-2-2 updated with ivlan", true, + g.V().has("aai-node-type", "forwarder-evc") + .has("forwarder-evc-id", "evc-name-2-2") + .has("ivlan","4084") + .hasNext()); + assertEquals("forwarder-evc evc-name-2-3 updated with ivlan", true, + g.V().has("aai-node-type", "forwarder-evc") + .has("forwarder-evc-id", "evc-name-2-3") + .has("ivlan","4054") + .hasNext()); + + assertEquals("4 forwarder-evcs exist for evc evc-name-2", new Long(4L), + g.V().has("forwarding-path-id", "evc-name-2") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder-evc") + .count().next()); + + assertEquals("3 forwarder-evcs updated for evc evc-name-2", new Long(3L), + g.V().has("forwarding-path-id", "evc-name-2") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder-evc") + .has("forwarder-evc-id").has("ivlan") + .count().next()); + + assertEquals("forwarder-evc evc-name-3-1 updated with ivlan", false, + g.V().has("aai-node-type", "forwarder-evc") + .has("forwarder-evc-id", "evc-name-3-1") + .has("ivlan") + .hasNext()); + } + + + @Test + public void testGetAffectedNodeTypes() { + Optional<String[]> types = migration.getAffectedNodeTypes(); + Optional<String[]> expected = Optional.of(new String[]{"forwarder-evc"}); + + assertNotNull(types); + assertArrayEquals(expected.get(), types.get()); + } + + @Test + public void testGetMigrationName() { + String migrationName = migration.getMigrationName(); + + assertNotNull(migrationName); + assertEquals("MigrateHUBEvcInventory", migrationName); + } +} diff --git a/src/test/java/org/onap/aai/migration/v12/MigrateINVPhysicalInventoryMethodTest.java b/src/test/java/org/onap/aai/migration/v12/MigrateINVPhysicalInventoryMethodTest.java new file mode 100644 index 0000000..59ae5e7 --- /dev/null +++ b/src/test/java/org/onap/aai/migration/v12/MigrateINVPhysicalInventoryMethodTest.java @@ -0,0 +1,149 @@ +/** + * ============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.process.traversal.strategy.verification.ReadOnlyStrategy; +import org.javatuples.Pair; +import org.junit.*; +import org.onap.aai.AAISetup; +import org.onap.aai.dbmap.DBConnectionType; +import org.onap.aai.introspection.Loader; +import org.onap.aai.introspection.ModelType; +import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.setup.SchemaVersion; +import org.onap.aai.serialization.engines.QueryStyle; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; +import org.onap.aai.serialization.engines.TransactionalGraphEngine; + +import java.util.*; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +public class MigrateINVPhysicalInventoryMethodTest extends AAISetup { + + 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 JanusGraphTransaction tx; + private GraphTraversalSource g; + private TransactionalGraphEngine spy; + + @Before + public void setUp() throws Exception { + graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); + tx = graph.newTransaction(); + g = tx.traversal(); + loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion()); + dbEngine = new JanusGraphDBEngine( + queryStyle, + type, + loader); + + System.setProperty("BUNDLECONFIG_DIR", "src/test/resources"); + + spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + + GraphTraversalSource traversal = g; + GraphTraversalSource readOnly = tx.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance())); + when (spy.tx()).thenReturn(tx); + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + when(adminSpy.getReadOnlyTraversalSource()).thenReturn(readOnly); + } + + @After + public void cleanUp() { + tx.tx().rollback(); + graph.close(); + } + + + @Test + public void headerTest() throws Exception { + MigrateINVPhysicalInventory m = new MigrateINVPhysicalInventory(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions); + String header = "ptnii-name,fic,equipment-model,equipment-role,equipment-role-additional,ip-addr,subnet-mask,slot-name,card-type,card-port-lock,card-vlan-lock,port-aid,port-type,port-role,port-lock,vlan-lock,reservation-name,collector-interconnect-type,tag-mode,media-type,media-speed-value+media-speed-units,uni-cir-value+uni-cir-units,evc-name"; + List<String> lines = new ArrayList<>(); + lines.add(header); + assertEquals(header, m.processAndRemoveHeader(lines)); + assertEquals(0, lines.size()); + assertEquals(23, m.headerLength); + + } + + @Test + public void verifyLineTest() throws Exception { + MigrateINVPhysicalInventory m = new MigrateINVPhysicalInventory(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions); + m.headerLength = 23; + assertFalse(m.verifyLine(Collections.nCopies(5, "foo"))); + assertTrue(m.verifyLine(Collections.nCopies(23, "foo"))); + assertEquals(1, m.skippedRowsCount.intValue()); + + } + + @Test + public void readLineTest() throws Exception { + MigrateINVPhysicalInventory m = new MigrateINVPhysicalInventory(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions); + String line = "pnf-name-collector-1,06000D.121,5150,AED,,2001:1890:fcfe:7000:7021:0:1:2,64,,,,,\"1.7 \",SFP_1GE/Ethernet_10/100/1000M,ACCESS,N,N,M0651881_ST,SHARED,DOUBLE,SFP-1GE-LX,1000Mbps,,evc-name-1\n"; + Pair<String, String> pair = m.processLine(Arrays.asList(line.split("\\s*,\\s*", -1))).get(); + assertEquals("Test 1","pnf-name-collector-1", pair.getValue0()); + assertEquals("Test 1","1.7", pair.getValue1()); + + line = "pnf-name-1,06000D.121,5150,AED,,2001:1890:fcfe:7000:7021:0:1:2,64,,,,,1.2,SFP_1GE/Ethernet_10/100/1000M,ACCESS,N,N,M0651882_ST,SHARED,DOUBLE,SFP-1GE-LX,1000Mbps,,evc-name-3"; + pair = m.processLine(Arrays.asList(line.split("\\s*,\\s*", -1))).get(); + assertEquals("Test 1","pnf-name-1", pair.getValue0()); + assertEquals("Test 1","1.2", pair.getValue1()); + + } + + @Test + public void getFileContentsTest() throws Exception { + MigrateINVPhysicalInventory m = new MigrateINVPhysicalInventory(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions); + + Map<String,Set<String>> expected = new HashMap<>(); + List<String> lines = new ArrayList<>(); + + String header = "ptnii-name,fic,equipment-model,equipment-role,equipment-role-additional,ip-addr,subnet-mask,slot-name,card-type,card-port-lock,card-vlan-lock,port-aid,port-type,port-role,port-lock,vlan-lock,reservation-name,collector-interconnect-type,tag-mode,media-type,media-speed-value+media-speed-units,uni-cir-value+uni-cir-units,evc-name"; + lines.add(header); + + lines.add("pnf-name-collector-1,06000D.121,5150,AED,,2001:1890:fcfe:7000:7021:0:1:2,64,,,,,\"1.7 \",SFP_1GE/Ethernet_10/100/1000M,ACCESS,N,N,M0651881_ST,SHARED,DOUBLE,SFP-1GE-LX,1000Mbps,,evc-name-1"); + expected.put("pnf-name-collector-1", new HashSet<>(Arrays.asList("1.7"))); + + lines.add("pnf-name-1,06000D.121,5150,AED,,2001:1890:fcfe:7000:7021:0:1:2,64,,,,,1.2,SFP_1GE/Ethernet_10/100/1000M,ACCESS,N,N,M0651882_ST,SHARED,DOUBLE,SFP-1GE-LX,1000Mbps,,evc-name-3"); + lines.add("pnf-name-1,06000D.121,5150,AED,,2001:1890:fcfe:7000:7021:0:1:2,64,,,,,1.2,SFP_1GE/Ethernet_10/100/1000M,ACCESS,N,N,M0651882_ST,SHARED,DOUBLE,SFP-1GE-LX,1000Mbps,,evc-name-3"); + lines.add("pnf-name-1,06000D.121,5150,AED,,2001:1890:fcfe:7000:7021:0:1:2,64,,,,,1.3,SFP_1GE/Ethernet_10/100/1000M,ACCESS,N,N,M0651882_ST,SHARED,DOUBLE,SFP-1GE-LX,1000Mbps,,evc-name-3"); + expected.put("pnf-name-1", new HashSet<>(Arrays.asList("1.2", "1.3"))); + + lines.add("foo"); + + assertEquals(expected, m.getFileContents(lines)); + + } +} diff --git a/src/test/java/org/onap/aai/migration/v12/MigrateINVPhysicalInventoryTest.java b/src/test/java/org/onap/aai/migration/v12/MigrateINVPhysicalInventoryTest.java new file mode 100644 index 0000000..82ea770 --- /dev/null +++ b/src/test/java/org/onap/aai/migration/v12/MigrateINVPhysicalInventoryTest.java @@ -0,0 +1,168 @@ +/** + * ============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.process.traversal.strategy.verification.ReadOnlyStrategy; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.*; +import org.onap.aai.AAISetup; +import org.onap.aai.dbmap.DBConnectionType; +import org.onap.aai.introspection.Loader; +import org.onap.aai.introspection.ModelType; +import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.setup.SchemaVersion; +import org.onap.aai.serialization.engines.QueryStyle; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; +import org.onap.aai.serialization.engines.TransactionalGraphEngine; + +import java.util.Optional; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +public class MigrateINVPhysicalInventoryTest extends AAISetup { + + 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 MigrateINVPhysicalInventory migration; + private JanusGraphTransaction tx; + private GraphTraversalSource g; + + @Before + public void setUp() throws Exception { + graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); + tx = graph.newTransaction(); + g = tx.traversal(); + loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion()); + dbEngine = new JanusGraphDBEngine( + queryStyle, + type, + loader); + + System.setProperty("BUNDLECONFIG_DIR", "src/test/resources"); + + + Vertex pnf1 = g.addV() + .property("aai-node-type", "pnf") + .property("pnf-name", "pnf-name-1") + .property("aai-uri", "/network/pnfs/pnf/pnf-name-1") + .next(); + Vertex port11 = g.addV() + .property("aai-node-type", "p-interface") + .property("interface-name", "1.1") + .property("aai-uri", "/network/pnfs/pnf/pnf-name-1/p-interfaces/pinterface/1.1") + .next(); + // graph 1 + + edgeSerializer.addTreeEdge(g, pnf1, port11); + + + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + + GraphTraversalSource traversal = g; + GraphTraversalSource readOnly = tx.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance())); + when (spy.tx()).thenReturn(tx); + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + when(adminSpy.getReadOnlyTraversalSource()).thenReturn(readOnly); + + migration = new MigrateINVPhysicalInventory(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions); + migration.run(); + } + + @After + public void cleanUp() { + tx.tx().rollback(); + graph.close(); + } + + + @Test + public void pnfsExistTest() throws Exception { + // check if pnf node gets created + assertEquals("2 PNFs exist", new Long(2L), + g.V().has("aai-node-type", "pnf") + .count().next()); + } + + @Test + public void pInterfacesExistTest() throws Exception { + + assertEquals("4 Pinterfaces exist", new Long(4L), + g.V().has("aai-node-type", "p-interface") + .count().next()); + } + + @Test + public void testRun_checkPnfsAndPInterfacesExist() throws Exception { + // check if graph nodes exist + + // check if pnf node gets created + assertEquals("2 PNFs exist", new Long(2L), + g.V().has("aai-node-type", "pnf") + .count().next()); + + System.out.println("cOUNT:" +g.V().has("aai-node-type", "pnf") + .has("pnf-name", "pnf-name-collector-1").in("tosca.relationships.network.BindsTo").count().next()); + + assertEquals("p-interfaces created for pnfs", new Long(1L), + g.V().has("aai-node-type", "pnf") + .has("pnf-name", "pnf-name-collector-1").count().next()); + + assertEquals("p-interface 1.7 created for pnf-name-collector-1", true, + g.V().has("aai-node-type", "pnf") + .has("pnf-name", "pnf-name-collector-1") + .in("tosca.relationships.network.BindsTo") + .has("interface-name","1.7") + .hasNext()); + assertEquals("p-interfaces created for pnfs", new Long(2L), + g.V().has("aai-node-type", "pnf") + .has("pnf-name", "pnf-name-1") + .in("tosca.relationships.network.BindsTo").count().next()); + } + + @Test + public void testGetAffectedNodeTypes() { + Optional<String[]> types = migration.getAffectedNodeTypes(); + Optional<String[]> expected = Optional.of(new String[]{"pnf"}); + + assertNotNull(types); + assertArrayEquals(expected.get(), types.get()); + } + + @Test + public void testGetMigrationName() { + String migrationName = migration.getMigrationName(); + + assertNotNull(migrationName); + assertEquals("MigrateINVPhysicalInventory", migrationName); + } +} diff --git a/src/test/java/org/onap/aai/migration/v12/MigrateInvEvcInventoryTest.java b/src/test/java/org/onap/aai/migration/v12/MigrateInvEvcInventoryTest.java new file mode 100644 index 0000000..ebe5136 --- /dev/null +++ b/src/test/java/org/onap/aai/migration/v12/MigrateInvEvcInventoryTest.java @@ -0,0 +1,152 @@ +/** + * ============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 static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import java.util.Optional; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.*; +import org.onap.aai.AAISetup; +import org.onap.aai.dbmap.DBConnectionType; +import org.onap.aai.introspection.Loader; +import org.onap.aai.introspection.ModelType; +import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.setup.SchemaVersion; +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 MigrateInvEvcInventoryTest extends AAISetup { + + private final static ModelType introspectorFactoryType = ModelType.MOXY; + private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL; + private final static DBConnectionType type = DBConnectionType.REALTIME; + + private static Loader loader; + private static TransactionalGraphEngine dbEngine; + private static JanusGraph graph; + private static MigrateINVEvcInventory migration; + private static JanusGraphTransaction tx; + private static GraphTraversalSource g; + + @Before + public void setUp() throws Exception { + graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); + tx = graph.newTransaction(); + g = tx.traversal(); + loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion()); + dbEngine = new JanusGraphDBEngine( + queryStyle, + type, + loader); + + System.setProperty("BUNDLECONFIG_DIR", "src/test/resources"); + + Vertex evc = g.addV() + .property("aai-node-type", "evc") + .property("evc-id", "evc-name-1") + .next(); + + Vertex evc2 = g.addV() + .property("aai-node-type", "evc") + .property("evc-id", "evc-name-2") + .next(); + + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + + GraphTraversalSource traversal = g; + GraphTraversalSource readOnly = tx.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance())); + when (spy.tx()).thenReturn(tx); + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + when(adminSpy.getReadOnlyTraversalSource()).thenReturn(readOnly); + + migration = new MigrateINVEvcInventory(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions); + migration.run(); + } + + @After + public void cleanUp() { + tx.tx().rollback(); + graph.close(); + } + + @Test + public void testRun_updateEvcNode() throws Exception { + // check if graph nodes exist + assertEquals("evc node exists", true, + g.V().has("aai-node-type", "evc") + .has("evc-id", "evc-name-1") + .hasNext()); + + // check if evc object is updated to set the value for inter-connect-type-ingress + assertEquals("evc is updated", true, + g.V().has("aai-node-type", "evc").has("evc-id", "evc-name-1") + .has("inter-connect-type-ingress", "SHARED") + .hasNext()); + } + + @Test + public void testRun_evcNotCreated() throws Exception { + + assertEquals("evc node does not exist", false, + g.V().has("aai-node-type", "evc").has("evc-id", "evc-name-3") + .hasNext()); + + //inter-connect-type-ingress is not present on the evc + assertEquals("evc node exists", true, + g.V().has("aai-node-type", "evc").has("evc-id", "evc-name-2") + .hasNext()); + assertEquals("evc node not updated with inter-connect-type-ingress", false, + g.V().has("aai-node-type", "evc").has("evc-id", "evc-name-2").has("inter-connect-type-ingress") + .hasNext()); + + } + + @Test + public void testGetAffectedNodeTypes() { + Optional<String[]> types = migration.getAffectedNodeTypes(); + Optional<String[]> expected = Optional.of(new String[]{"evc"}); + + assertNotNull(types); + assertArrayEquals(expected.get(), types.get()); + } + + @Test + public void testGetMigrationName() { + String migrationName = migration.getMigrationName(); + + assertNotNull(migrationName); + assertEquals("MigrateINVEvcInventory", migrationName); + } +} diff --git a/src/test/java/org/onap/aai/migration/v12/MigratePATHEvcInventoryTest.java b/src/test/java/org/onap/aai/migration/v12/MigratePATHEvcInventoryTest.java new file mode 100644 index 0000000..334f32b --- /dev/null +++ b/src/test/java/org/onap/aai/migration/v12/MigratePATHEvcInventoryTest.java @@ -0,0 +1,658 @@ +/** + * ============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 static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import java.util.Optional; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.*; +import org.onap.aai.AAISetup; +import org.onap.aai.dbmap.DBConnectionType; +import org.onap.aai.introspection.Loader; +import org.onap.aai.introspection.ModelType; +import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.setup.SchemaVersion; +import org.onap.aai.serialization.engines.QueryStyle; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; +import org.onap.aai.serialization.engines.TransactionalGraphEngine; + +public class MigratePATHEvcInventoryTest extends AAISetup { + + 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 MigratePATHEvcInventory migration; + private GraphTraversalSource g; + + @Before + public void setUp() throws Exception { + g = tx.traversal(); + loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion()); + dbEngine = new JanusGraphDBEngine( + queryStyle, + type, + loader); + + System.setProperty("BUNDLECONFIG_DIR", "src/test/resources"); + + Vertex customer1 = g.addV() + .property("aai-node-type", "customer") + .property("global-customer-id", "customer-id-1") + .property("subscriber-type", "CUST") + .next(); + + Vertex servSub1 = g.addV() + .property("aai-node-type", "service-subscription") + .property("service-type", "SAREA") + .next(); + + Vertex servInstance1 = g.addV() + .property("aai-node-type", "service-instance") + .property("service-type", "SAREA") + .property("service-instance-id", "evc-name-1") + .next(); + Vertex servInstance3 = g.addV() + .property("aai-node-type", "service-instance") + .property("service-type", "SAREA") + .property("service-instance-id", "evc-name-3") + .next(); + Vertex servInstance2 = g.addV() + .property("aai-node-type", "service-instance") + .property("service-type", "SAREA") + .property("service-instance-id", "evc-name-2") + .next(); + + Vertex pnf1 = g.addV() + .property("aai-node-type", "pnf") + .property("pnf-name", "pnf-name-1") + .next(); + Vertex port11 = g.addV() + .property("aai-node-type", "p-interface") + .property("interface-name", "1.1") + .next(); + Vertex port12 = g.addV() + .property("aai-node-type", "p-interface") + .property("interface-name", "1.41") + .next(); + + Vertex pnf2 = g.addV() + .property("aai-node-type", "pnf") + .property("pnf-name", "pnf-name-2") + .next(); + Vertex port21 = g.addV() + .property("aai-node-type", "p-interface") + .property("interface-name", "1.25") + .next(); + Vertex port22 = g.addV() + .property("aai-node-type", "lag-interface") + .property("interface-name", "ae1") + .next(); + + Vertex pnf3 = g.addV() + .property("aai-node-type", "pnf") + .property("pnf-name", "pnf-name-3") + .next(); + Vertex port31 = g.addV() + .property("aai-node-type", "p-interface") + .property("interface-name", "1.32") + .next(); + Vertex port32 = g.addV() + .property("aai-node-type", "lag-interface") + .property("interface-name", "ae1") + .next(); + + Vertex pnf4 = g.addV() + .property("aai-node-type", "pnf") + .property("pnf-name", "pnf-name-4") + .next(); + Vertex port41 = g.addV() + .property("aai-node-type", "p-interface") + .property("interface-name", "1.7") + .next(); + Vertex port42 = g.addV() + .property("aai-node-type", "lag-interface") + .property("interface-name", "ae101") + .next(); + + Vertex pnf5 = g.addV() + .property("aai-node-type", "pnf") + .property("pnf-name", "pnf-name-5") + .next(); + Vertex port51 = g.addV() + .property("aai-node-type", "lag-interface") + .property("interface-name", "104") + .next(); + Vertex port52 = g.addV() + .property("aai-node-type", "lag-interface") + .property("interface-name", "101") + .next(); + + Vertex pnf6 = g.addV() + .property("aai-node-type", "pnf") + .property("pnf-name", "pnf-name-6") + .next(); + Vertex port61 = g.addV() + .property("aai-node-type", "lag-interface") + .property("interface-name", "ae104") + .next(); + Vertex port62 = g.addV() + .property("aai-node-type", "p-interface") + .property("interface-name", "1.39") + .next(); + + Vertex evc1 = g.addV().property("aai-node-type", "evc") + .property("evc-id", "evc-name-1") + .next(); + Vertex fp1 = g.addV() + .property("aai-node-type", "forwarding-path") + .property("forwarding-path-id", "evc-name-1") + .next(); + + Vertex evc2 = g.addV().property("aai-node-type", "evc") + .property("evc-id", "evc-name-2") + .next(); + Vertex fp2 = g.addV() + .property("aai-node-type", "forwarding-path") + .property("forwarding-path-id", "evc-name-2") + .next(); + + Vertex evc3 = g.addV().property("aai-node-type", "evc") + .property("evc-id", "evc-name-3") + .next(); + Vertex fp3 = g.addV() + .property("aai-node-type", "forwarding-path") + .property("forwarding-path-id", "evc-name-3") + .next(); + + // graph 1 + edgeSerializer.addTreeEdge(g, customer1, servSub1); + edgeSerializer.addTreeEdge(g, servSub1, servInstance1); + edgeSerializer.addTreeEdge(g, servSub1, servInstance2); + edgeSerializer.addTreeEdge(g, servSub1, servInstance3); + + edgeSerializer.addEdge(g, servInstance1, fp1); + edgeSerializer.addEdge(g, servInstance2, fp2); + edgeSerializer.addEdge(g, servInstance3, fp3); + + edgeSerializer.addTreeEdge(g, pnf1, port11); + edgeSerializer.addTreeEdge(g, pnf1, port12); + + edgeSerializer.addTreeEdge(g, pnf2, port21); + edgeSerializer.addTreeEdge(g, pnf2, port22); + + edgeSerializer.addTreeEdge(g, pnf3, port31); + edgeSerializer.addTreeEdge(g, pnf3, port32); + + edgeSerializer.addTreeEdge(g, pnf4, port41); + edgeSerializer.addTreeEdge(g, pnf4, port42); + + edgeSerializer.addTreeEdge(g, pnf5, port51); + edgeSerializer.addTreeEdge(g, pnf5, port52); + + edgeSerializer.addTreeEdge(g, pnf6, port61); + edgeSerializer.addTreeEdge(g, pnf6, port62); + + + + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + + GraphTraversalSource traversal = g; + GraphTraversalSource readOnly = tx.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance())); + when (spy.tx()).thenReturn(tx); + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + when(adminSpy.getReadOnlyTraversalSource()).thenReturn(readOnly); + + migration = new MigratePATHEvcInventory(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions); + migration.run(); + } + + @Test + public void testRun_checkServInstanceAndForwardingPathsExist() throws Exception { + // check if graph nodes exist + + // check if service-instance node gets created + assertEquals("service subscription node, service-type=SAREA", true, + g.V().has("service-instance-id", "evc-name-1") + .out("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .hasNext()); + + assertEquals("fowarding-path node exists", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-1") + .in("org.onap.relationships.inventory.AppliesTo") + .has("aai-node-type", "forwarding-path") + .has("forwarding-path-id", "evc-name-1") + .hasNext()); + assertEquals("fowarding-path node exists", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-2") + .in("org.onap.relationships.inventory.AppliesTo") + .has("aai-node-type", "forwarding-path") + .has("forwarding-path-id", "evc-name-2") + .hasNext()); + assertEquals("fowarding-path node exists", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo") + .has("aai-node-type", "forwarding-path") + .has("forwarding-path-id", "evc-name-3") + .hasNext()); + + } + + @Test + public void testRun_checkForwardersForEvc1AreCreated() throws Exception { + // check if graph nodes exist + // check if forwarder node gets created + + assertEquals("forwarder node is created for evc-name-1 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-1") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 1) + .has("forwarder-role", "ingress") + .hasNext()); + + assertEquals("forwarder node is created for evc-name-1 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-1") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 2) + .has("forwarder-role", "egress") + .hasNext()); + } + + @Test + public void testRun_checkForwardersForEvc2AreCreated() throws Exception { + + // check if forwarder node gets created + + assertEquals("forwarder node is created for evc-name-2 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-2") + .hasNext()); + + assertEquals("forwarder node is created for evc-name-2 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-2") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .hasNext()); + + assertEquals("4 forwarders are created for evc-name-2 ", (Long)4l, + g.V(). + has("aai-node-type", "forwarding-path").has("forwarding-path-id","evc-name-2") + .in("org.onap.relationships.inventory.BelongsTo") + .has("aai-node-type", "forwarder").count().next()); //org.onap.relationships.inventory.BelongsTo + + assertEquals("forwarder node is created for evc-name-2 ", true, + g.V().has("aai-node-type", "forwarding-path").has("forwarding-path-id","evc-name-2") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 1) + .has("forwarder-role", "ingress") + .hasNext()); + + assertEquals("forwarder node is created for evc-name-2 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-2") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 1) + .has("forwarder-role", "ingress") + .hasNext()); + + assertEquals("forwarder node is created for evc-name-2 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-2") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 2) + .has("forwarder-role", "intermediate") + .hasNext()); + + assertEquals("forwarder node is created for evc-name-2 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-2") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 3) + .has("forwarder-role", "intermediate") + .hasNext()); + + assertEquals("forwarder node is created for evc-name-2 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-2") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 4) + .has("forwarder-role", "egress") + .hasNext()); + } + + @Test + public void testRun_checkForwardersForEvc3AreCreated() throws Exception { + + // check if forwarder node gets created + + assertEquals("forwarder node is created for evc-name-3 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 1) + .has("forwarder-role", "ingress") + .hasNext()); + + assertEquals("forwarder node is created for evc-name-3 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 1) + .has("forwarder-role", "ingress") + .out("org.onap.relationships.inventory.ForwardsTo") + .has("aai-node-type", "p-interface") + .has("interface-name","1.7") + .hasNext()); + + assertEquals("forwarder-evc node is created for forwarder with sequence 1 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 1) + .has("forwarder-role", "ingress") + .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration") + .has("configuration-id","evc-name-3-1").has("configuration-type","forwarder").has("configuration-sub-type", "forwarder") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder-evc") + .has("forwarder-evc-id","evc-name-3-1") + .has("circuit-id","M0651881") + .has("cvlan","34") + .has("svlan","8") + .hasNext()); + + assertEquals("forwarder node is created for evc-name-3 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 2) + .has("forwarder-role", "intermediate") + .hasNext()); + + //forwarder to interface check + assertEquals("forwarder node is created for evc-name-3 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 2) + .has("forwarder-role", "intermediate") + .out("org.onap.relationships.inventory.ForwardsTo") + .has("aai-node-type", "lag-interface") + .has("interface-name","ae101") + .hasNext()); + + assertEquals("forwarder-evc node is created for forwarder with sequence 2 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 2) + .has("forwarder-role", "intermediate") + .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration") + .has("configuration-id","evc-name-3-2").has("configuration-type","forwarder").has("configuration-sub-type", "forwarder") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder-evc") + .has("forwarder-evc-id","evc-name-3-2") + .has("cvlan","34") + .has("svlan","740") + .hasNext()); + + assertEquals("forwarder node is created for evc-name-3 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 3) + .has("forwarder-role", "intermediate") + .hasNext()); + + assertEquals("forwarder node is created for evc-name-3 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 3) + .has("forwarder-role", "intermediate") + .out("org.onap.relationships.inventory.ForwardsTo") + .has("aai-node-type", "lag-interface") + .has("interface-name","101") + .hasNext()); + + assertEquals("forwarder-evc node is created for forwarder with sequence 3 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 3) + .has("forwarder-role", "intermediate") + .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration") + .has("configuration-id","evc-name-3-3").has("configuration-type","forwarder").has("configuration-sub-type", "forwarder") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder-evc") + .has("forwarder-evc-id","evc-name-3-3") + .has("cvlan","35") + .has("svlan","740") + .hasNext()); + + assertEquals("forwarder node is created for evc-name-3 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 4) + .has("forwarder-role", "intermediate") + .hasNext()); + + assertEquals("forwarder node is created for evc-name-3 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 4) + .has("forwarder-role", "intermediate") + .out("org.onap.relationships.inventory.ForwardsTo") + .has("aai-node-type", "lag-interface") + .has("interface-name","104") + .hasNext()); + + assertEquals("forwarder-evc node is created for forwarder with sequence 4 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 4) + .has("forwarder-role", "intermediate") + .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration") + .has("configuration-id","evc-name-3-4").has("configuration-type","forwarder").has("configuration-sub-type", "forwarder") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder-evc") + .has("forwarder-evc-id","evc-name-3-4") + .has("cvlan","37") + .has("svlan","740") + .hasNext()); + + assertEquals("forwarder node is created for evc-name-3 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 5) + .has("forwarder-role", "intermediate") + .hasNext()); + + assertEquals("forwarder node is created for evc-name-3 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 5) + .has("forwarder-role", "intermediate") + .out("org.onap.relationships.inventory.ForwardsTo") + .has("aai-node-type", "lag-interface") + .has("interface-name","ae104") + .hasNext()); + + + + assertEquals("configuration node is created for forwarder with sequence 5 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 5) + .has("forwarder-role", "intermediate") + .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration") + .has("configuration-id","evc-name-3-5").has("configuration-type","forwarder").has("configuration-sub-type", "forwarder") + .hasNext()); + + assertEquals("forwarder-evc node is created for forwarder with sequence 5 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 5) + .has("forwarder-role", "intermediate") + .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration") + .has("configuration-id","evc-name-3-5").has("configuration-type","forwarder").has("configuration-sub-type", "forwarder") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder-evc") + .has("forwarder-evc-id","evc-name-3-5") + .has("cvlan","36") + .has("svlan","740") + .hasNext()); + + assertEquals("forwarder node is created for evc-name-3 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 6) + .has("forwarder-role", "egress") + .hasNext()); + + assertEquals("forwarder node is created for evc-name-3 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 6) + .has("forwarder-role", "egress") + .out("org.onap.relationships.inventory.ForwardsTo") + .has("aai-node-type", "p-interface") + .has("interface-name","1.39") + .hasNext()); + + assertEquals("configuration node is created for forwarder with sequence 6 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 6) + .has("forwarder-role", "egress") + .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration") + .has("configuration-id","evc-name-3-6").has("configuration-type","forwarder").has("configuration-sub-type", "forwarder") + .hasNext()); + + assertEquals("configuration node is created for forwarder with sequence 6 ", true, + g.V().has("global-customer-id", "customer-id-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder") + .has("sequence", 6) + .has("forwarder-role", "egress") + .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration") + .has("configuration-id","evc-name-3-6").has("configuration-type","forwarder").has("configuration-sub-type", "forwarder") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "forwarder-evc") + .has("forwarder-evc-id","evc-name-3-6").has("circuit-id","IZEZ.597112..ATI").has("cvlan","36").has("svlan","3") + .hasNext()); + + } + + + @Test + public void testGetAffectedNodeTypes() { + Optional<String[]> types = migration.getAffectedNodeTypes(); + Optional<String[]> expected = Optional.of(new String[]{"forwarding-path"}); + + assertNotNull(types); + assertArrayEquals(expected.get(), types.get()); + } + + @Test + public void testGetMigrationName() { + String migrationName = migration.getMigrationName(); + + assertNotNull(migrationName); + assertEquals("MigratePATHEvcInventory", migrationName); + } +} diff --git a/src/test/java/org/onap/aai/migration/v12/MigratePATHPhysicalInventoryTest.java b/src/test/java/org/onap/aai/migration/v12/MigratePATHPhysicalInventoryTest.java new file mode 100644 index 0000000..11aa0a6 --- /dev/null +++ b/src/test/java/org/onap/aai/migration/v12/MigratePATHPhysicalInventoryTest.java @@ -0,0 +1,159 @@ +/** + * ============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 static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.shortThat; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import java.util.Optional; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.*; +import org.onap.aai.AAISetup; +import org.onap.aai.dbmap.DBConnectionType; +import org.onap.aai.introspection.Loader; +import org.onap.aai.introspection.ModelType; +import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.setup.SchemaVersion; +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 MigratePATHPhysicalInventoryTest extends AAISetup { + + 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 MigratePATHPhysicalInventory migration; + private GraphTraversalSource g; + + @Before + public void setUp() throws Exception { + g = tx.traversal(); + loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion()); + dbEngine = new JanusGraphDBEngine( + queryStyle, + type, + loader); + + System.setProperty("BUNDLECONFIG_DIR", "src/test/resources"); + + Vertex pnf2 = g.addV() + .property("aai-node-type", "pnf") + .property("pnf-name", "pnf-name-2") + .next(); + Vertex port21 = g.addV() + .property("aai-node-type", "lag-interface") + .property("interface-name", "ae1") + .next(); + + Vertex pnf3 = g.addV() + .property("aai-node-type", "pnf") + .property("pnf-name", "pnf-name-3") + .next(); + Vertex pnf4 = g.addV() + .property("aai-node-type", "pnf") + .property("pnf-name", "pnf-name-4") + .next(); + Vertex pnf5 = g.addV() + .property("aai-node-type", "pnf") + .property("pnf-name", "pnf-name-5") + .next(); + // graph 1 + + edgeSerializer.addTreeEdge(g, pnf2, port21); + + + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + + GraphTraversalSource traversal = g; + GraphTraversalSource readOnly = tx.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance())); + when (spy.tx()).thenReturn(tx); + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + when(adminSpy.getReadOnlyTraversalSource()).thenReturn(readOnly); + + migration = new MigratePATHPhysicalInventory(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions); + migration.run(); + } + + @Test + public void testRun_checkPnfsAndPInterfacesExist() throws Exception { + // check if graph nodes exist + + testGetMigrationName(); + testGetAffectedNodeTypes(); + + // check if pnf node gets created + assertEquals("4 PNFs exist", new Long(4L), + g.V().has("aai-node-type", "pnf") + .count().next()); + + assertEquals("5 lag-interfaces were created", new Long (5L), g.V().has("aai-node-type", "lag-interface") + .out("tosca.relationships.network.BindsTo").count().next()); + + assertEquals("lag-interfaces created for pnfs", new Long(1L), + g.V().has("aai-node-type", "pnf") + .has("pnf-name", "pnf-name-3").count().next()); + + assertEquals("lag-interface ae1 created for pnf-name-3", true, + g.V().has("aai-node-type", "pnf") + .has("pnf-name", "pnf-name-3") + .in("tosca.relationships.network.BindsTo") + .has("aai-node-type", "lag-interface") + .has("interface-name","ae1") + .hasNext()); + + assertEquals("lag-interfaces created for pnfs", new Long(2L), + g.V().has("aai-node-type", "pnf") + .has("pnf-name", "pnf-name-5") + .in("tosca.relationships.network.BindsTo") + .has("aai-node-type", "lag-interface").count().next()); + } + + public void testGetAffectedNodeTypes() { + Optional<String[]> types = migration.getAffectedNodeTypes(); + Optional<String[]> expected = Optional.of(new String[]{"lag-interface"}); + + assertNotNull(types); + assertArrayEquals(expected.get(), types.get()); + } + + public void testGetMigrationName() { + String migrationName = migration.getMigrationName(); + + assertNotNull(migrationName); + assertEquals("MigratePATHPhysicalInventory", migrationName); + } +} diff --git a/src/test/java/org/onap/aai/migration/v12/MigrateSAREvcInventoryTest.java b/src/test/java/org/onap/aai/migration/v12/MigrateSAREvcInventoryTest.java new file mode 100644 index 0000000..79a5877 --- /dev/null +++ b/src/test/java/org/onap/aai/migration/v12/MigrateSAREvcInventoryTest.java @@ -0,0 +1,357 @@ +/** + * ============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 static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import java.util.Optional; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy; +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.ModelType; +import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.setup.SchemaVersion; +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 MigrateSAREvcInventoryTest extends AAISetup { + + 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 MigrateSAREvcInventory migration; + private JanusGraphTransaction tx; + private GraphTraversalSource g; + + @Before + public void setUp() throws Exception { + graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); + tx = graph.newTransaction(); + g = tx.traversal(); + loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion()); + dbEngine = new JanusGraphDBEngine( + queryStyle, + type, + loader); + + System.setProperty("BUNDLECONFIG_DIR", "src/test/resources"); + + Vertex customer1 = g.addV() + .property("aai-node-type", "customer") + .property("global-customer-id", "8a00890a-e6ae-446b-9dbe-b828dbeb38bd") + .property("subscriber-type", "CUST") + .next(); + + Vertex servSub1 = g.addV() + .property("aai-node-type", "service-subscription") + .property("service-type", "SAREA") + .next(); + + Vertex servInst1 = g.addV() + .property("aai-node-type", "service-instance") + .property("service-instance-id", "evc-name-1") + .next(); + + Vertex customer2 = g.addV() + .property("aai-node-type", "customer") + .property("global-customer-id", "cust-1") + .property("subscriber-type", "CUST") + .next(); + + Vertex servSub2 = g.addV() + .property("aai-node-type", "service-subscription") + .property("service-type", "SAREA") + .next(); + + Vertex servInst2 = g.addV() + .property("aai-node-type", "service-instance") + .property("service-instance-id", "evc-name-1") + .next(); + + Vertex collectorPnf = g.addV() + .property("aai-node-type", "pnf") + .property("pnf-name", "pnf-name-collector-1") + .next(); + + Vertex bearerPnf = g.addV() + .property("aai-node-type", "pnf") + .property("pnf-name", "pnf-name-bearer-1") + .next(); + + Vertex collectorPort = g.addV() + .property("aai-node-type", "p-interface") + .property("interface-name", "p-int-collector-1") + .next(); + + Vertex bearerPort = g.addV() + .property("aai-node-type", "p-interface") + .property("interface-name", "p-int-bearer-1") + .next(); + + Vertex servInst4 = g.addV() + .property("aai-node-type", "service-instance") + .property("service-instance-id", "evc-name-4") + .next(); + + // graph 1 + edgeSerializer.addTreeEdge(g, customer1, servSub1); +// edgeSerializer.addTreeEdge(g, servSub1, servInst1); + edgeSerializer.addTreeEdge(g, customer2, servSub2); + edgeSerializer.addTreeEdge(g, servSub2, servInst2); + edgeSerializer.addTreeEdge(g, servSub1, servInst4); //evc-name-4 exists in graph as a child of SAREA serv-sub + edgeSerializer.addTreeEdge(g, collectorPnf, collectorPort); + edgeSerializer.addTreeEdge(g, bearerPnf, bearerPort); + + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + + GraphTraversalSource traversal = g; + GraphTraversalSource readOnly = tx.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance())); + when (spy.tx()).thenReturn(tx); + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + when(adminSpy.getReadOnlyTraversalSource()).thenReturn(readOnly); + + migration = new MigrateSAREvcInventory(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions); + migration.run(); + } + + @After + public void cleanUp() { + tx.tx().rollback(); + graph.close(); + } + + @Test + public void testRun_createServiceInstanceNode() throws Exception { + // check if graph nodes exist + assertEquals("service instance node exists", true, + g.V().has("service-instance-id", "evc-name-1") + .hasNext()); + + // check if service-instance node gets created + assertEquals("service subscription node, service-type=SAREA", true, + g.V().has("service-instance-id", "evc-name-1") + .out("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .hasNext()); + + + + // check if fowarding-path node gets created + assertEquals("fowarding-path is created", true, g.V().has("forwarding-path-id", "evc-name-1") + .has("forwarding-path-name", "evc-name-1").hasNext()); + + assertEquals("fowarding-path node exists", true, + g.V().has("global-customer-id", "8a00890a-e6ae-446b-9dbe-b828dbeb38bd") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-1") + .in("org.onap.relationships.inventory.AppliesTo") + .has("aai-node-type", "forwarding-path") + .has("forwarding-path-id", "evc-name-1") + .has("forwarding-path-name", "evc-name-1") + .hasNext()); + + // check if configuration node gets created + assertEquals("configuration node, configuration-type= forwarding-path", true, + g.V().has("global-customer-id", "8a00890a-e6ae-446b-9dbe-b828dbeb38bd") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-1") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration") + .has("configuration-type", "forwarding-path") + .has("configuration-sub-type", "evc") + .hasNext()); + + //check if evc node gets created + assertEquals("evc is created", true, + g.V().has("global-customer-id", "8a00890a-e6ae-446b-9dbe-b828dbeb38bd") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-1") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "evc") + .hasNext()); + + // check if evc node gets created + assertEquals("configuration node, configuration-type= evc", true, + g.V().has("global-customer-id", "8a00890a-e6ae-446b-9dbe-b828dbeb38bd") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-1") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "evc") + .has("evc-id", "evc-name-1") + .has("forwarding-path-topology", "PointToPoint") + .has("cir-value", "40") + .has("cir-units", "Mbps") + .has("tagmode-access-ingress", "DOUBLE") + .has("tagmode-access-egress", "DOUBLE") + .hasNext()); + } + + @Test + public void testRun_evcNotCreated() throws Exception { + // check if graph nodes exist + assertEquals("customer node exists", true, + g.V().has("global-customer-id", "8a00890a-e6ae-446b-9dbe-b828dbeb38bd") + .hasNext()); + + assertEquals("service subscription node, service-type=SAREA", true, + g.V().has("global-customer-id", "8a00890a-e6ae-446b-9dbe-b828dbeb38bd") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .hasNext()); + + //service-instance should not be created + assertEquals("service instance node created", false, + g.V().has("global-customer-id", "8a00890a-e6ae-446b-9dbe-b828dbeb38bd") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-2") + .hasNext()); + + assertEquals("service instance node already exists", true, + g.V().has("global-customer-id", "cust-1") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-1") + .hasNext()); + + // fowarding-path node should not be created + assertEquals("fowarding-path created", false, g.V().has("aai-node-type", "forwarding-path") + .has("forwarding-path-name", "evc-name-2").hasNext()); + + // configuration node should not be created + assertEquals("configuration node created", false, g.V().has("aai-node-type", "configuration") + .has("configuration-id", "evc-name-2").hasNext()); + + // evc node should not be created + assertEquals("evc node created", false, g.V().has("aai-node-type", "evc") + .has("evc-id", "evc-name-2").hasNext()); + + // service-instance is not created because pnf exists, but p-interface does not + assertEquals("service instance node created", false, + g.V().has("global-customer-id", "8a00890a-e6ae-446b-9dbe-b828dbeb38bd") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-3") + .hasNext()); + } + + @Test + public void testRun_createFPConfigurationEvcNode4() throws Exception { + // check if graph nodes exist + assertEquals("service instance node exists", true, + g.V().has("service-instance-id", "evc-name-4") + .hasNext()); + + // check if service-instance node gets created + assertEquals("service subscription node, service-type=SAREA", true, + g.V().has("service-instance-id", "evc-name-4") + .out("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .hasNext()); + + + + // check if fowarding-path node gets created + assertEquals("fowarding-path is created", true, g.V().has("forwarding-path-id", "evc-name-4") + .has("forwarding-path-name", "evc-name-4").hasNext()); + + assertEquals("fowarding-path node exists", true, + g.V().has("global-customer-id", "8a00890a-e6ae-446b-9dbe-b828dbeb38bd") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-4") + .in("org.onap.relationships.inventory.AppliesTo") + .has("aai-node-type", "forwarding-path") + .has("forwarding-path-id", "evc-name-4") + .has("forwarding-path-name", "evc-name-4") + .hasNext()); + + // check if configuration node gets created + assertEquals("configuration node, configuration-type= forwarding-path", true, + g.V().has("global-customer-id", "8a00890a-e6ae-446b-9dbe-b828dbeb38bd") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-4") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration") + .has("configuration-type", "forwarding-path") + .has("configuration-sub-type", "evc") + .hasNext()); + + //check if evc node gets created + assertEquals("evc is created", true, + g.V().has("global-customer-id", "8a00890a-e6ae-446b-9dbe-b828dbeb38bd") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-4") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "evc") + .hasNext()); + + // check if evc node gets created + assertEquals("configuration node, configuration-type= evc", true, + g.V().has("global-customer-id", "8a00890a-e6ae-446b-9dbe-b828dbeb38bd") + .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SAREA") + .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "evc-name-1") + .in("org.onap.relationships.inventory.AppliesTo").has("aai-node-type", "forwarding-path") + .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration") + .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "evc") + .has("evc-id", "evc-name-1") + .has("forwarding-path-topology", "PointToPoint") + .has("cir-value", "40") + .has("cir-units", "Mbps") + .has("tagmode-access-ingress", "DOUBLE") + .has("tagmode-access-egress", "DOUBLE") + .hasNext()); + } + + @Test + public void testGetAffectedNodeTypes() { + Optional<String[]> types = migration.getAffectedNodeTypes(); + Optional<String[]> expected = Optional.of(new String[]{"service-instance"}); + + assertNotNull(types); + assertArrayEquals(expected.get(), types.get()); + } + + @Test + public void testGetMigrationName() { + String migrationName = migration.getMigrationName(); + + assertNotNull(migrationName); + assertEquals("MigrateSAREvcInventory", migrationName); + } +} |