AAI-1523 Batch reformat aai-core
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / parsers / query / RelationshipGremlinQueryTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.aai.parsers.query;
22
23 import static org.hamcrest.CoreMatchers.containsString;
24 import static org.junit.Assert.assertEquals;
25
26 import java.io.StringReader;
27 import java.io.UnsupportedEncodingException;
28
29 import javax.xml.bind.JAXBException;
30 import javax.xml.bind.Unmarshaller;
31 import javax.xml.transform.stream.StreamSource;
32
33 import org.eclipse.persistence.dynamic.DynamicEntity;
34 import org.eclipse.persistence.jaxb.UnmarshallerProperties;
35 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
36 import org.junit.Before;
37 import org.junit.Ignore;
38 import org.junit.Rule;
39 import org.junit.Test;
40 import org.junit.rules.ExpectedException;
41 import org.onap.aai.AAISetup;
42 import org.onap.aai.exceptions.AAIException;
43 import org.onap.aai.introspection.*;
44 import org.onap.aai.nodes.NodeIngestor;
45 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
46 import org.onap.aai.serialization.engines.QueryStyle;
47 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
48 import org.onap.aai.setup.SchemaVersion;
49 import org.springframework.beans.factory.annotation.Autowired;
50
51 @Ignore
52 public class RelationshipGremlinQueryTest extends AAISetup {
53
54     @Autowired
55     private NodeIngestor injestor;
56     private TransactionalGraphEngine dbEngine;
57     private SchemaVersion version;
58     private DynamicJAXBContext context = injestor.getContextForVersion(version);
59
60     @Rule
61     public ExpectedException thrown = ExpectedException.none();
62
63     @Before
64     public void setup() {
65         version = new SchemaVersion("v10");
66         dbEngine = new JanusGraphDBEngine(QueryStyle.GREMLIN_TRAVERSAL,
67                 loaderFactory.createLoaderForVersion(ModelType.MOXY, version), false);
68     }
69
70     /**
71      * Parent query.
72      *
73      * @throws JAXBException the JAXB exception
74      * @throws UnsupportedEncodingException the unsupported encoding exception
75      * @throws AAIException the AAI exception
76      */
77     @Test
78     public void parentQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
79
80         String content = "{" + "\"related-to\" : \"pserver\"," + "\"relationship-data\" : [{"
81                 + "\"relationship-key\" : \"pserver.hostname\"," + "\"relationship-value\" : \"key1\"" + "}]" + "}";
82
83         Unmarshaller unmarshaller = context.createUnmarshaller();
84         unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
85         unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
86         unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
87         Object obj = context.newDynamicEntity("Relationship");
88
89         DynamicEntity entity = (DynamicEntity) unmarshaller
90                 .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
91
92         Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
93         QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
94
95         String expected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
96         assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
97         assertEquals("parent gremlin query should be equal to normal query", expected,
98                 query.getQueryBuilder().getParentQuery().getQuery());
99         assertEquals("result type should be pserver", "pserver", query.getResultType());
100
101     }
102
103     /**
104      * Child query.
105      *
106      * @throws JAXBException the JAXB exception
107      * @throws UnsupportedEncodingException the unsupported encoding exception
108      * @throws AAIException the AAI exception
109      */
110     @Test
111     public void childQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
112         String content = "{" + "\"related-to\" : \"lag-interface\"," + "\"relationship-data\" : [{"
113                 + "\"relationship-key\" : \"pserver.hostname\"," + "\"relationship-value\" : \"key1\"" + "}, {"
114                 + "\"relationship-key\" : \"lag-interface.interface-name\"," + "\"relationship-value\" : \"key2\""
115                 + "}]" + "}";
116
117         Unmarshaller unmarshaller = context.createUnmarshaller();
118         unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
119         unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
120         unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
121         Object obj = context.newDynamicEntity("Relationship");
122
123         DynamicEntity entity = (DynamicEntity) unmarshaller
124                 .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
125
126         Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
127         QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
128
129         String expected =
130                 ".has('hostname', 'key1').has('aai-node-type', 'pserver').in('tosca.relationships.BindsTo').has('aai-node-type', 'lag-interface')"
131                         + ".has('interface-name', 'key2')";
132         String parentExpected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
133         assertEquals("gremlin query should be for node", expected, query.getQueryBuilder().getQuery());
134         assertEquals("parent gremlin query should be for parent", parentExpected,
135                 query.getQueryBuilder().getParentQuery().getQuery());
136         assertEquals("result type should be lag-interface", "lag-interface", query.getResultType());
137     }
138
139     /**
140      * Naming exceptions.
141      *
142      * @throws JAXBException the JAXB exception
143      * @throws UnsupportedEncodingException the unsupported encoding exception
144      * @throws AAIException the AAI exception
145      */
146     @Test
147     public void namingExceptions() throws JAXBException, UnsupportedEncodingException, AAIException {
148         String content = "{" + "\"related-to\" : \"cvlan-tag\"," + "\"relationship-data\" : [{"
149                 + "\"relationship-key\" : \"vce.vnf-id\"," + "\"relationship-value\" : \"key1\"" + "}, {"
150                 + "\"relationship-key\" : \"port-group.interface-id\"," + "\"relationship-value\" : \"key2\"" + "},{"
151                 + "\"relationship-key\" : \"cvlan-tag.cvlan-tag\"," + "\"relationship-value\" : \"655\"" + "}]" + "}";
152
153         Unmarshaller unmarshaller = context.createUnmarshaller();
154         unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
155         unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
156         unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
157         Object obj = context.newDynamicEntity("Relationship");
158
159         DynamicEntity entity = (DynamicEntity) unmarshaller
160                 .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
161
162         Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
163         QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
164         String expected = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
165                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
166                 + ".has('interface-id', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
167                 + ".has('cvlan-tag', 655)";
168         String expectedParent = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
169                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
170                 + ".has('interface-id', 'key2')";
171         assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
172         assertEquals("parent gremlin query should be equal the query for port group", expectedParent,
173                 query.getQueryBuilder().getParentQuery().getQuery());
174         assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
175
176     }
177
178     /**
179      * Scrambled relationship.
180      *
181      * @throws JAXBException the JAXB exception
182      * @throws UnsupportedEncodingException the unsupported encoding exception
183      * @throws AAIException the AAI exception
184      */
185     @Test
186     public void scrambledRelationship() throws JAXBException, UnsupportedEncodingException, AAIException {
187         String content = "{" + "\"related-to\" : \"l3-interface-ipv4-address-list\"," + "\"relationship-data\" : [{"
188                 + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\","
189                 + "\"relationship-value\" : \"key5\"" + "},{"
190                 + "\"relationship-key\" : \"lag-interface.interface-name\"," + "\"relationship-value\" : \"key2\""
191                 + "},{" + "\"relationship-key\" : \"l-interface.interface-name\"," + "\"relationship-value\" : \"key3\""
192                 + "},{" + "\"relationship-key\" : \"vlan.vlan-interface\"," + "\"relationship-value\" : \"key4\""
193                 + "},{" + "\"relationship-key\" : \"generic-vnf.vnf-id\"," + "\"relationship-value\" : \"key1\"" + "}]"
194                 + "}";
195         scrambledRelationshipSpec(content);
196     }
197
198     /**
199      * Reversed relationship.
200      *
201      * @throws JAXBException the JAXB exception
202      * @throws UnsupportedEncodingException the unsupported encoding exception
203      * @throws AAIException the AAI exception
204      */
205     @Test
206     public void reversedRelationship() throws JAXBException, UnsupportedEncodingException, AAIException {
207         String content = "{" + "\"related-to\" : \"l3-interface-ipv4-address-list\"," + "\"relationship-data\" : [{"
208                 + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\","
209                 + "\"relationship-value\" : \"key5\"" + "},{" + "\"relationship-key\" : \"vlan.vlan-interface\","
210                 + "\"relationship-value\" : \"key4\"" + "},{" + "\"relationship-key\" : \"l-interface.interface-name\","
211                 + "\"relationship-value\" : \"key3\"" + "},{"
212                 + "\"relationship-key\" : \"lag-interface.interface-name\"," + "\"relationship-value\" : \"key2\""
213                 + "},{" + "\"relationship-key\" : \"generic-vnf.vnf-id\"," + "\"relationship-value\" : \"key1\"" + "}]"
214                 + "}";
215         scrambledRelationshipSpec(content);
216     }
217
218     /**
219      * Ordered ambiguous relationship.
220      *
221      * @throws JAXBException the JAXB exception
222      * @throws UnsupportedEncodingException the unsupported encoding exception
223      * @throws AAIException the AAI exception
224      */
225     @Test
226     public void orderedAmbiguousRelationship() throws JAXBException, UnsupportedEncodingException, AAIException {
227         String content = "{" + "\"related-to\" : \"l3-interface-ipv4-address-list\"," + "\"relationship-data\" : [{"
228                 + "\"relationship-key\" : \"generic-vnf.vnf-id\"," + "\"relationship-value\" : \"key1\"" + "},{"
229                 + "\"relationship-key\" : \"lag-interface.interface-name\"," + "\"relationship-value\" : \"key2\""
230                 + "},{" + "\"relationship-key\" : \"l-interface.interface-name\"," + "\"relationship-value\" : \"key3\""
231                 + "},{" + "\"relationship-key\" : \"vlan.vlan-interface\"," + "\"relationship-value\" : \"key4\""
232                 + "},{" + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\","
233                 + "\"relationship-value\" : \"key5\"" + "}]" + "}";
234         scrambledRelationshipSpec(content);
235     }
236
237     /**
238      * Scrambled relationship spec.
239      *
240      * @param content the content
241      * @throws JAXBException the JAXB exception
242      * @throws UnsupportedEncodingException the unsupported encoding exception
243      * @throws AAIException the AAI exception
244      */
245     public void scrambledRelationshipSpec(String content)
246             throws JAXBException, UnsupportedEncodingException, AAIException {
247
248         Unmarshaller unmarshaller = context.createUnmarshaller();
249         unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
250         unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
251         unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
252         Object obj = context.newDynamicEntity("Relationship");
253
254         DynamicEntity entity = (DynamicEntity) unmarshaller
255                 .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
256
257         Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
258         QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
259         String expected = ".has('vnf-id', 'key1').has('aai-node-type', 'generic-vnf')"
260                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'lag-interface')"
261                 + ".has('interface-name', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'l-interface')"
262                 + ".has('interface-name', 'key3').out('tosca.relationships.LinksTo').has('aai-node-type', 'vlan')"
263                 + ".has('vlan-interface', 'key4').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'l3-interface-ipv4-address-list')"
264                 + ".has('l3-interface-ipv4-address', 'key5')";
265         String expectedParent = ".has('vnf-id', 'key1').has('aai-node-type', 'generic-vnf')"
266                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'lag-interface')"
267                 + ".has('interface-name', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'l-interface')"
268                 + ".has('interface-name', 'key3').out('tosca.relationships.LinksTo').has('aai-node-type', 'vlan')"
269                 + ".has('vlan-interface', 'key4')";
270         assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
271         assertEquals("parent gremlin query should be equal the query for vlan", expectedParent,
272                 query.getQueryBuilder().getParentQuery().getQuery());
273         assertEquals("result type should be l3-interface-ipv4-address-list", "l3-interface-ipv4-address-list",
274                 query.getResultType());
275
276     }
277
278     /**
279      * Short circuit.
280      *
281      * @throws JAXBException the JAXB exception
282      * @throws UnsupportedEncodingException the unsupported encoding exception
283      * @throws AAIException the AAI exception
284      */
285     @Test
286     public void shortCircuit() throws JAXBException, UnsupportedEncodingException, AAIException {
287         String content = "{" + "\"related-to\" : \"cvlan-tag\","
288                 + "\"related-link\" : \"http://mock-system-name.com:8443/aai/v6/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655\","
289                 + "\"relationship-data\" : [{" + "\"relationship-key\" : \"vce.vnf-id\","
290                 + "\"relationship-value\" : \"key1\"" + "}, {" + "\"relationship-key\" : \"port-group.interface-id\","
291                 + "\"relationship-value\" : \"key2\"" + "},{" + "\"relationship-key\" : \"cvlan-tag.cvlan-tag\","
292                 + "\"relationship-value\" : \"655\"" + "}]" + "}";
293
294         Unmarshaller unmarshaller = context.createUnmarshaller();
295         unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
296         unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
297         unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
298         Object obj = context.newDynamicEntity("Relationship");
299
300         DynamicEntity entity = (DynamicEntity) unmarshaller
301                 .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
302
303         Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
304         QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
305         String expected = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
306                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
307                 + ".has('interface-id', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
308                 + ".has('cvlan-tag', 655)";
309         String expectedParent = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
310                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
311                 + ".has('interface-id', 'key2')";
312         assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
313         assertEquals("parent gremlin query should be equal the query for port group", expectedParent,
314                 query.getQueryBuilder().getParentQuery().getQuery());
315         assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
316
317     }
318
319     @Test
320     public void shorterCircuit() throws JAXBException, UnsupportedEncodingException, AAIException {
321         String content = "{" + "\"related-to\" : \"cvlan-tag\","
322                 + "\"related-link\" : \"file:///network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655\""
323                 + "}";
324
325         Unmarshaller unmarshaller = context.createUnmarshaller();
326         unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
327         unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
328         unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
329         Object obj = context.newDynamicEntity("Relationship");
330
331         DynamicEntity entity = (DynamicEntity) unmarshaller
332                 .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
333
334         Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
335         QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
336         String expected = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
337                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
338                 + ".has('interface-id', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
339                 + ".has('cvlan-tag', 655)";
340         String expectedParent = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
341                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
342                 + ".has('interface-id', 'key2')";
343         assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
344         assertEquals("parent gremlin query should be equal the query for port group", expectedParent,
345                 query.getQueryBuilder().getParentQuery().getQuery());
346         assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
347
348     }
349
350     /**
351      * Double key.
352      *
353      * @throws JAXBException the JAXB exception
354      * @throws UnsupportedEncodingException the unsupported encoding exception
355      * @throws AAIException the AAI exception
356      */
357     @Test
358     public void doubleKey() throws JAXBException, UnsupportedEncodingException, AAIException {
359         String content = "{" + "\"related-to\" : \"ctag-pool\"," + "\"relationship-data\" : [{"
360                 + "\"relationship-key\" : \"complex.physical-location-id\"," + "\"relationship-value\" : \"key1\""
361                 + " }, { " + "\"relationship-key\" : \"ctag-pool.target-pe\"," + " \"relationship-value\" : \"key2\""
362                 + " },{" + "\"relationship-key\" : \"ctag-pool.availability-zone-name\","
363                 + "\"relationship-value\" : \"key3\"" + "}]" + "}";
364
365         Unmarshaller unmarshaller = context.createUnmarshaller();
366         unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
367         unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
368         unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
369         Object obj = context.newDynamicEntity("Relationship");
370
371         DynamicEntity entity = (DynamicEntity) unmarshaller
372                 .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
373
374         Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
375         QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
376
377         String expected = ".has('physical-location-id', 'key1').has('aai-node-type', 'complex')"
378                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'ctag-pool')"
379                 + ".has('target-pe', 'key2')" + ".has('availability-zone-name', 'key3')";
380         String expectedParent = ".has('physical-location-id', 'key1').has('aai-node-type', 'complex')";
381
382         assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
383         assertEquals("parent gremlin query should be equal the query for port group", expectedParent,
384                 query.getQueryBuilder().getParentQuery().getQuery());
385         assertEquals("result type should be ctag-pool", "ctag-pool", query.getResultType());
386
387     }
388
389     /**
390      * Abstract type.
391      *
392      * @throws JAXBException the JAXB exception
393      * @throws UnsupportedEncodingException the unsupported encoding exception
394      * @throws AAIException the AAI exception
395      */
396     @Test
397     public void abstractType() throws JAXBException, UnsupportedEncodingException, AAIException {
398         String content = "{" + "\"related-to\" : \"vnf\"," + "\"relationship-data\" : [{"
399                 + "\"relationship-key\" : \"vnf.vnf-id\"," + "\"relationship-value\" : \"key1\"" + " }]" + "}";
400
401         Unmarshaller unmarshaller = context.createUnmarshaller();
402         unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
403         unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
404         unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
405         Object obj = context.newDynamicEntity("Relationship");
406
407         DynamicEntity entity = (DynamicEntity) unmarshaller
408                 .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
409
410         Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
411         QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
412
413         String expected = ".has('vnf-id', 'key1')" + ".has('aai-node-type', P.within('vce','generic-vnf'))";
414
415         String expectedParent = ".has('vnf-id', 'key1')" + ".has('aai-node-type', P.within('vce','generic-vnf'))";
416
417         assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
418         assertEquals("parent gremlin query should be equal the query for port group", expectedParent,
419                 query.getQueryBuilder().getParentQuery().getQuery());
420         assertEquals("result type should be vnf", "vnf", query.getResultType());
421
422     }
423
424     /**
425      * Invalid node name.
426      *
427      * @throws JAXBException the JAXB exception
428      * @throws UnsupportedEncodingException the unsupported encoding exception
429      * @throws AAIException the AAI exception
430      */
431     @Test
432     public void invalidNodeName() throws JAXBException, UnsupportedEncodingException, AAIException {
433         String content = "{" + "\"related-to\" : \"l3-interface-ipv4-address-list\"," + "\"relationship-data\" : [{"
434                 + "\"relationship-key\" : \"generic-vnf.vnf-id\"," + "\"relationship-value\" : \"key1\"" + "},{"
435                 + "\"relationship-key\" : \"lag-interface.interface-name\"," + "\"relationship-value\" : \"key2\""
436                 + "},{" + "\"relationship-key\" : \"l-infeaterface.interface-name\","
437                 + "\"relationship-value\" : \"key3\"" + "},{" + "\"relationship-key\" : \"vlan.vlan-interface\","
438                 + "\"relationship-value\" : \"key4\"" + "},{"
439                 + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\","
440                 + "\"relationship-value\" : \"key5\"" + "}]" + "}";
441         thrown.expect(AAIException.class);
442         thrown.expectMessage(containsString("invalid object name"));
443
444         Unmarshaller unmarshaller = context.createUnmarshaller();
445         unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
446         unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
447         unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
448         Object obj = context.newDynamicEntity("Relationship");
449
450         DynamicEntity entity = (DynamicEntity) unmarshaller
451                 .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
452
453         Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
454         dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
455
456     }
457
458     /**
459      * Invalid property name.
460      *
461      * @throws JAXBException the JAXB exception
462      * @throws UnsupportedEncodingException the unsupported encoding exception
463      * @throws AAIException the AAI exception
464      */
465     @Test
466     public void invalidPropertyName() throws JAXBException, UnsupportedEncodingException, AAIException {
467         String content = "{" + "\"related-to\" : \"l3-interface-ipv4-address-list\"," + "\"relationship-data\" : [{"
468                 + "\"relationship-key\" : \"generic-vnf.vnf-id\"," + "\"relationship-value\" : \"key1\"" + "},{"
469                 + "\"relationship-key\" : \"lag-interface.intfdaferface-name\"," + "\"relationship-value\" : \"key2\""
470                 + "},{" + "\"relationship-key\" : \"l-interface.interface-name\"," + "\"relationship-value\" : \"key3\""
471                 + "},{" + "\"relationship-key\" : \"vlan.vlan-interface\"," + "\"relationship-value\" : \"key4\""
472                 + "},{" + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\","
473                 + "\"relationship-value\" : \"key5\"" + "}]" + "}";
474         thrown.expect(AAIException.class);
475         thrown.expectMessage(containsString("invalid property name"));
476
477         Unmarshaller unmarshaller = context.createUnmarshaller();
478         unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
479         unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
480         unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
481         Object obj = context.newDynamicEntity("Relationship");
482
483         DynamicEntity entity = (DynamicEntity) unmarshaller
484                 .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
485
486         Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
487         dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
488
489     }
490 }