1 package org.onap.aai.migration.v12;
3 import static org.junit.Assert.assertArrayEquals;
4 import static org.junit.Assert.assertEquals;
5 import static org.junit.Assert.assertNotNull;
6 import static org.mockito.Mockito.spy;
7 import static org.mockito.Mockito.when;
9 import java.util.Optional;
11 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
12 import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
13 import org.apache.tinkerpop.gremlin.structure.Vertex;
14 import org.junit.AfterClass;
15 import org.junit.BeforeClass;
16 import org.junit.Test;
17 import org.onap.aai.AAISetup;
18 import org.onap.aai.dbmap.DBConnectionType;
19 import org.onap.aai.introspection.Loader;
20 import org.onap.aai.introspection.LoaderFactory;
21 import org.onap.aai.introspection.ModelType;
22 import org.onap.aai.introspection.Version;
23 import org.onap.aai.serialization.db.EdgeRules;
24 import org.onap.aai.serialization.engines.QueryStyle;
25 import org.onap.aai.serialization.engines.TitanDBEngine;
26 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
28 import com.thinkaurelius.titan.core.TitanFactory;
29 import com.thinkaurelius.titan.core.TitanGraph;
30 import com.thinkaurelius.titan.core.TitanTransaction;
32 public class MigrateServiceInstanceToConfigurationTestPreMigrationMock extends AAISetup {
34 private final static Version version = Version.v12;
35 private final static ModelType introspectorFactoryType = ModelType.MOXY;
36 private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL;
37 private final static DBConnectionType type = DBConnectionType.REALTIME;
39 private static Loader loader;
40 private static TransactionalGraphEngine dbEngine;
41 private static TitanGraph graph;
42 private static MigrateServiceInstanceToConfiguration migration;
43 private static TitanTransaction tx;
44 private static GraphTraversalSource g;
45 private static EdgeRules rules;
48 public static void setUp() throws Exception {
49 graph = TitanFactory.build().set("storage.backend","inmemory").open();
50 tx = graph.newTransaction();
52 loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version);
53 dbEngine = new TitanDBEngine(
57 rules = EdgeRules.getInstance();
59 Vertex customer = g.addV()
60 .property("aai-node-type", "customer")
61 .property("global-customer-id", "customer-9972-BandwidthMigration")
62 .property("subscriber-type", "CUST")
65 Vertex servSubSDNEI = g.addV()
66 .property("aai-node-type", "service-subscription")
67 .property("service-type", "SDN-ETHERNET-INTERNET")
70 Vertex servInstance22 = g.addV()
71 .property("aai-node-type", "service-instance")
72 .property("service-instance-id", "servInstance-9972-22-BandwidthMigration")
73 .property("operational-status", "activated")
74 .property("bandwidth-total", "bandwidth-total-22-BandwidthMigration")
77 Vertex servInstance11 = g.addV()
78 .property("aai-node-type", "service-instance")
79 .property("service-instance-id", "servInstance-9972-11-BandwidthMigration")
80 .property("operational-status", "activated")
81 .property("bandwidth-total", "bandwidth-total-11-BandwidthMigration")
84 Vertex servSubDHV = g.addV()
85 .property("aai-node-type", "service-subscription")
86 .property("service-type", "DHV")
89 Vertex servInstance4 = g.addV()
90 .property("aai-node-type", "service-instance")
91 .property("service-instance-id", "servInstance-9972-4-BandwidthMigration")
92 .property("operational-status", "activated")
93 .property("bandwidth-total", "bandwidth-total-4-BandwidthMigration")
96 Vertex servInstance1 = g.addV()
97 .property("aai-node-type", "service-instance")
98 .property("service-instance-id", "ServInstance-9972-1-BandwidthMigration")
99 .property("operational-status", "activated")
100 .property("bandwidth-total", "2380")
103 Vertex servInstance3 = g.addV()
104 .property("aai-node-type", "service-instance")
105 .property("service-instance-id", "servInstance-9972-3-BandwidthMigration")
106 .property("operational-status", "activated")
107 .property("bandwidth-total", "bandwidth-total-3-BandwidthMigration")
110 Vertex servInstance2 = g.addV()
111 .property("aai-node-type", "service-instance")
112 .property("service-instance-id", "servInstance-9972-2-BandwidthMigration")
113 .property("operational-status", "activated")
114 .property("bandwidth-total", "bandwidth-total-2-BandwidthMigration")
117 Vertex config1 = g.addV()
118 .property("aai-node-type", "configuration")
119 .property("configuration-id", "9972-config-LB1113")
120 .property("configuration-type", "DHV")
121 .property("tunnel-bandwidth", "12")
124 Vertex config2 = g.addV()
125 .property("aai-node-type", "configuration")
126 .property("configuration-id", "9972-1config-LB1113")
127 .property("configuration-type", "configuration-type1-9972")
130 Vertex allottedResource = g.addV()
131 .property("aai-node-type", "allotted-resource")
132 .property("id", "allResource-9972-BandwidthMigration")
135 rules.addTreeEdge(g, customer, servSubSDNEI);
136 rules.addTreeEdge(g, customer, servSubDHV);
137 rules.addTreeEdge(g, servSubSDNEI, servInstance22);
138 rules.addTreeEdge(g, servSubSDNEI, servInstance11);
139 rules.addTreeEdge(g, servSubDHV, servInstance4);
140 rules.addTreeEdge(g, servSubDHV, servInstance1);
141 rules.addTreeEdge(g, servSubDHV, servInstance3);
142 rules.addTreeEdge(g, servSubDHV, servInstance2);
143 rules.addEdge(g, servInstance1, allottedResource);
144 rules.addEdge(g, servInstance1, config1);
145 rules.addEdge(g, servInstance2, config2);
147 TransactionalGraphEngine spy = spy(dbEngine);
148 TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
150 GraphTraversalSource traversal = g;
151 GraphTraversalSource readOnly = tx.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance()));
152 when (spy.tx()).thenReturn(tx);
153 when(spy.asAdmin()).thenReturn(adminSpy);
154 when(adminSpy.getTraversalSource()).thenReturn(traversal);
155 when(adminSpy.getReadOnlyTraversalSource()).thenReturn(readOnly);
157 migration = new MigrateServiceInstanceToConfiguration(spy);
162 public static void cleanUp() {
168 public void testRun() throws Exception {
169 // check if graph nodes exist
170 assertEquals("customer node exists", true,
171 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
174 assertEquals("service subscription node, service-type=SDN-ETHERNET-INTERNET", true,
175 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
176 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SDN-ETHERNET-INTERNET")
179 assertEquals("service instance node, bandwidth-total=bandwidth-total-22-BandwidthMigration", true,
180 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
181 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SDN-ETHERNET-INTERNET")
182 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "servInstance-9972-22-BandwidthMigration")
183 .has("bandwidth-total", "bandwidth-total-22-BandwidthMigration")
186 assertEquals("service instance node, bandwidth-total=bandwidth-total-11-BandwidthMigration", true,
187 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
188 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SDN-ETHERNET-INTERNET")
189 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "servInstance-9972-11-BandwidthMigration")
190 .has("bandwidth-total", "bandwidth-total-11-BandwidthMigration")
193 assertEquals("service subscription node, service-type=DHV", true,
194 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
195 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "DHV")
198 assertEquals("service instance node, bandwidth-total=servInstance-9972-4-BandwidthMigration", true,
199 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
200 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "DHV")
201 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "servInstance-9972-4-BandwidthMigration")
202 .has("bandwidth-total", "bandwidth-total-4-BandwidthMigration")
205 assertEquals("service instance node, bandwidth-total=ServInstance-9972-1-BandwidthMigration", true,
206 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
207 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "DHV")
208 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "ServInstance-9972-1-BandwidthMigration")
209 .has("bandwidth-total", "2380")
212 assertEquals("service instance node, bandwidth-total=servInstance-9972-3-BandwidthMigration", true,
213 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
214 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "DHV")
215 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "servInstance-9972-3-BandwidthMigration")
216 .has("bandwidth-total", "bandwidth-total-3-BandwidthMigration")
219 assertEquals("service instance node, bandwidth-total=servInstance-9972-2-BandwidthMigration", true,
220 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
221 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "DHV")
222 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "servInstance-9972-2-BandwidthMigration")
223 .has("bandwidth-total", "bandwidth-total-2-BandwidthMigration")
226 assertEquals("configuration node with type=configuration-type1-9972, tunnel-bandwidth does not exist", true,
227 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
228 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "DHV")
229 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "servInstance-9972-2-BandwidthMigration")
230 .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration")
231 .has("configuration-type", "configuration-type1-9972")
234 // check if configuration node gets created for 2, 3, 4
235 assertEquals("configuration node created with type=DHV, tunnel-bandwidth=servInstance-9972-4-BandwidthMigration", true,
236 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
237 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "DHV")
238 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "servInstance-9972-4-BandwidthMigration")
239 .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration")
240 .has("configuration-type", "DHV").has("tunnel-bandwidth", "bandwidth-total-4-BandwidthMigration")
243 assertEquals("configuration node created with type=DHV, tunnel-bandwidth=servInstance-9972-3-BandwidthMigration", true,
244 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
245 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "DHV")
246 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "servInstance-9972-3-BandwidthMigration")
247 .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration")
248 .has("configuration-type", "DHV").has("tunnel-bandwidth", "bandwidth-total-3-BandwidthMigration")
251 assertEquals("configuration node created with type=DHV, tunnel-bandwidth=servInstance-9972-2-BandwidthMigration", true,
252 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
253 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "DHV")
254 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "servInstance-9972-2-BandwidthMigration")
255 .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration")
256 .has("configuration-type", "DHV").has("tunnel-bandwidth", "bandwidth-total-2-BandwidthMigration")
259 // configuration modified for ServInstance-9972-1-BandwidthMigration
260 assertEquals("configuration node modified for ServInstance-9972-1-BandwidthMigration, tunnel-bandwidth=2380", true,
261 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
262 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "DHV")
263 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "ServInstance-9972-1-BandwidthMigration")
264 .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration")
265 .has("configuration-type", "DHV").has("tunnel-bandwidth", "2380")
270 public void testGetAffectedNodeTypes() {
271 Optional<String[]> types = migration.getAffectedNodeTypes();
272 Optional<String[]> expected = Optional.of(new String[]{"service-instance"});
274 assertNotNull(types);
275 assertArrayEquals(expected.get(), types.get());
279 public void testGetMigrationName() {
280 String migrationName = migration.getMigrationName();
282 assertNotNull(migrationName);
283 assertEquals("service-instance-to-configuration", migrationName);