Update license files, sonar plugin and fix tests
[aai/aai-common.git] / aai-core / src / test / java / org / openecomp / aai / parsers / query / RelationshipGremlinQueryTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.openecomp.aai
4  * ================================================================================
5  * Copyright (C) 2017 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.openecomp.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.BeforeClass;
37 import org.junit.Ignore;
38 import org.junit.Rule;
39 import org.junit.Test;
40 import org.junit.rules.ExpectedException;
41
42 import org.openecomp.aai.exceptions.AAIException;
43 import org.openecomp.aai.introspection.Introspector;
44 import org.openecomp.aai.introspection.IntrospectorFactory;
45 import org.openecomp.aai.introspection.LoaderFactory;
46 import org.openecomp.aai.introspection.ModelInjestor;
47 import org.openecomp.aai.introspection.ModelType;
48 import org.openecomp.aai.introspection.Version;
49 import org.openecomp.aai.serialization.engines.QueryStyle;
50 import org.openecomp.aai.serialization.engines.TitanDBEngine;
51 import org.openecomp.aai.serialization.engines.TransactionalGraphEngine;
52
53 @Ignore
54 public class RelationshipGremlinQueryTest {
55
56         private ModelInjestor injestor = ModelInjestor.getInstance();
57         private TransactionalGraphEngine dbEngine = 
58                         new TitanDBEngine(QueryStyle.GREMLIN_TRAVERSAL, 
59                                 LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8),
60                                 false);
61         private final Version version = Version.v8;
62         private DynamicJAXBContext context = injestor.getContextForVersion(version);
63         
64         @Rule
65         public ExpectedException thrown = ExpectedException.none();
66         
67         /**
68          * Configure.
69          */
70         @BeforeClass
71         public static void configure() {
72                 System.setProperty("AJSC_HOME", "./src/test/resources/");
73                 System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
74         }
75         
76         
77         /**
78          * Parent query.
79          *
80          * @throws JAXBException the JAXB exception
81          * @throws UnsupportedEncodingException the unsupported encoding exception
82          * @throws AAIException the AAI exception
83          */
84         @Test
85     public void parentQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
86                 
87                 String content =
88                                 "{"
89                                 + "\"related-to\" : \"pserver\","
90                                 + "\"relationship-data\" : [{"
91                                 + "\"relationship-key\" : \"pserver.hostname\","
92                                 + "\"relationship-value\" : \"key1\""
93                                 + "}]"
94                                 + "}";
95                                                 
96                 Unmarshaller unmarshaller = context.createUnmarshaller();
97             unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
98             unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
99                 unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
100                 Object obj = context.newDynamicEntity("Relationship");
101
102                 DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
103                 
104                 Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
105                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
106
107                 String expected = 
108                                 ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
109                 assertEquals(
110                                 "gremlin query should be " + expected,
111                                 expected,
112                                 query.getQueryBuilder().getQuery());
113                 assertEquals(
114                                 "parent gremlin query should be equal to normal query",
115                                 expected,
116                                 query.getQueryBuilder().getParentQuery().getQuery());
117                 assertEquals(
118                                 "result type should be pserver",
119                                 "pserver",
120                                 query.getResultType());
121                 
122     }
123
124         /**
125          * Child query.
126          *
127          * @throws JAXBException the JAXB exception
128          * @throws UnsupportedEncodingException the unsupported encoding exception
129          * @throws AAIException the AAI exception
130          */
131         @Test
132     public void childQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
133                 String content =
134                                 "{"
135                                 + "\"related-to\" : \"lag-interface\","
136                                 + "\"relationship-data\" : [{"
137                                 + "\"relationship-key\" : \"pserver.hostname\","
138                                 + "\"relationship-value\" : \"key1\""
139                                 + "}, {"
140                                 + "\"relationship-key\" : \"lag-interface.interface-name\","
141                                 + "\"relationship-value\" : \"key2\""
142                                 + "}]"
143                                 + "}";
144                                                 
145                 Unmarshaller unmarshaller = context.createUnmarshaller();
146             unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
147             unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
148                 unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
149                 Object obj = context.newDynamicEntity("Relationship");
150
151                 DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
152                         
153                 Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
154                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
155
156                 String expected = ".has('hostname', 'key1').has('aai-node-type', 'pserver').in('tosca.relationships.BindsTo').has('aai-node-type', 'lag-interface')"
157                                 + ".has('interface-name', 'key2')";
158                 String parentExpected =
159                                 ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
160                 assertEquals(
161                                 "gremlin query should be for node",
162                                 expected,
163                                 query.getQueryBuilder().getQuery());
164                 assertEquals(
165                                 "parent gremlin query should be for parent",
166                                 parentExpected,
167                                 query.getQueryBuilder().getParentQuery().getQuery());
168                 assertEquals(
169                                 "result type should be lag-interface",
170                                 "lag-interface",
171                                 query.getResultType());
172     }
173         
174         /**
175          * Naming exceptions.
176          *
177          * @throws JAXBException the JAXB exception
178          * @throws UnsupportedEncodingException the unsupported encoding exception
179          * @throws AAIException the AAI exception
180          */
181         @Test
182     public void namingExceptions() throws JAXBException, UnsupportedEncodingException, AAIException {
183                 String content =
184                                 "{"
185                                 + "\"related-to\" : \"cvlan-tag\","
186                                 + "\"relationship-data\" : [{"
187                                 + "\"relationship-key\" : \"vce.vnf-id\","
188                                 + "\"relationship-value\" : \"key1\""
189                                 + "}, {"
190                                 + "\"relationship-key\" : \"port-group.interface-id\","
191                                 + "\"relationship-value\" : \"key2\""
192                                 + "},{"
193                                 + "\"relationship-key\" : \"cvlan-tag.cvlan-tag\","
194                                 + "\"relationship-value\" : \"655\""
195                                 + "}]"
196                                 + "}";
197                                                 
198                 Unmarshaller unmarshaller = context.createUnmarshaller();
199             unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
200             unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
201                 unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
202                 Object obj = context.newDynamicEntity("Relationship");
203
204                 DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
205                         
206                 Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
207                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
208                 String expected = 
209                                 ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
210                                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
211                                 + ".has('interface-id', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
212                                 + ".has('cvlan-tag', 655)";
213                 String expectedParent = 
214                                                 ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
215                                                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
216                                                 + ".has('interface-id', 'key2')";
217                 assertEquals(
218                                 "gremlin query should be " + expected,
219                                 expected,
220                                 query.getQueryBuilder().getQuery());
221                 assertEquals(
222                                 "parent gremlin query should be equal the query for port group",
223                                 expectedParent,
224                                 query.getQueryBuilder().getParentQuery().getQuery());
225                 assertEquals(
226                                 "result type should be cvlan-tag",
227                                 "cvlan-tag",
228                                 query.getResultType());
229                 
230     }
231         
232         /**
233          * Scrambled relationship.
234          *
235          * @throws JAXBException the JAXB exception
236          * @throws UnsupportedEncodingException the unsupported encoding exception
237          * @throws AAIException the AAI exception
238          */
239         @Test
240         public void scrambledRelationship() throws JAXBException, UnsupportedEncodingException, AAIException {
241                 String content =
242                                 "{"
243                                 + "\"related-to\" : \"l3-interface-ipv4-address-list\","
244                                 + "\"relationship-data\" : [{"
245                                 + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\","
246                                 + "\"relationship-value\" : \"key5\""
247                                 + "},{"
248                                 + "\"relationship-key\" : \"lag-interface.interface-name\","
249                                 + "\"relationship-value\" : \"key2\""
250                                 + "},{"
251                                 + "\"relationship-key\" : \"l-interface.interface-name\","
252                                 + "\"relationship-value\" : \"key3\""
253                                 + "},{"
254                                 + "\"relationship-key\" : \"vlan.vlan-interface\","
255                                 + "\"relationship-value\" : \"key4\""
256                                 + "},{"
257                                 + "\"relationship-key\" : \"generic-vnf.vnf-id\","
258                                 + "\"relationship-value\" : \"key1\""
259                                 + "}]"
260                                 + "}";
261                 scrambledRelationshipSpec(content);
262         }
263         
264         /**
265          * Reversed relationship.
266          *
267          * @throws JAXBException the JAXB exception
268          * @throws UnsupportedEncodingException the unsupported encoding exception
269          * @throws AAIException the AAI exception
270          */
271         @Test
272         public void reversedRelationship() throws JAXBException, UnsupportedEncodingException, AAIException {
273                 String content =
274                                 "{"
275                                 + "\"related-to\" : \"l3-interface-ipv4-address-list\","
276                                 + "\"relationship-data\" : [{"
277                                 + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\","
278                                 + "\"relationship-value\" : \"key5\""
279                                 + "},{"
280                                 + "\"relationship-key\" : \"vlan.vlan-interface\","
281                                 + "\"relationship-value\" : \"key4\""
282                                 + "},{"
283                                 + "\"relationship-key\" : \"l-interface.interface-name\","
284                                 + "\"relationship-value\" : \"key3\""
285                                 + "},{"
286                                 + "\"relationship-key\" : \"lag-interface.interface-name\","
287                                 + "\"relationship-value\" : \"key2\""
288                                 + "},{"
289                                 + "\"relationship-key\" : \"generic-vnf.vnf-id\","
290                                 + "\"relationship-value\" : \"key1\""
291                                 + "}]"
292                                 + "}";
293                 scrambledRelationshipSpec(content);
294         }
295         
296         /**
297          * Ordered ambiguous relationship.
298          *
299          * @throws JAXBException the JAXB exception
300          * @throws UnsupportedEncodingException the unsupported encoding exception
301          * @throws AAIException the AAI exception
302          */
303         @Test
304         public void orderedAmbiguousRelationship() throws JAXBException, UnsupportedEncodingException, AAIException {
305                 String content =
306                                 "{"
307                                 + "\"related-to\" : \"l3-interface-ipv4-address-list\","
308                                 + "\"relationship-data\" : [{"
309                                 + "\"relationship-key\" : \"generic-vnf.vnf-id\","
310                                 + "\"relationship-value\" : \"key1\""
311                                 + "},{"
312                                 + "\"relationship-key\" : \"lag-interface.interface-name\","
313                                 + "\"relationship-value\" : \"key2\""
314                                 + "},{"
315                                 + "\"relationship-key\" : \"l-interface.interface-name\","
316                                 + "\"relationship-value\" : \"key3\""
317                                 + "},{"
318                                 + "\"relationship-key\" : \"vlan.vlan-interface\","
319                                 + "\"relationship-value\" : \"key4\""
320                                 + "},{"
321                                 + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\","
322                                 + "\"relationship-value\" : \"key5\""
323                                 + "}]"
324                                 + "}";
325                 scrambledRelationshipSpec(content);
326         }
327     
328     /**
329      * Scrambled relationship spec.
330      *
331      * @param content the content
332      * @throws JAXBException the JAXB exception
333      * @throws UnsupportedEncodingException the unsupported encoding exception
334      * @throws AAIException the AAI exception
335      */
336     public void scrambledRelationshipSpec(String content) throws JAXBException, UnsupportedEncodingException, AAIException {
337
338                                                 
339                 Unmarshaller unmarshaller = context.createUnmarshaller();
340             unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
341             unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
342                 unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
343                 Object obj = context.newDynamicEntity("Relationship");
344
345                 DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
346                         
347                 Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
348                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
349                 String expected = 
350                                 ".has('vnf-id', 'key1').has('aai-node-type', 'generic-vnf')"
351                                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'lag-interface')"
352                                 + ".has('interface-name', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'l-interface')"
353                                 + ".has('interface-name', 'key3').out('tosca.relationships.LinksTo').has('aai-node-type', 'vlan')"
354                                 + ".has('vlan-interface', 'key4').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'l3-interface-ipv4-address-list')"
355                                 + ".has('l3-interface-ipv4-address', 'key5')";
356                 String expectedParent = 
357                                 ".has('vnf-id', 'key1').has('aai-node-type', 'generic-vnf')"
358                                                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'lag-interface')"
359                                                 + ".has('interface-name', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'l-interface')"
360                                                 + ".has('interface-name', 'key3').out('tosca.relationships.LinksTo').has('aai-node-type', 'vlan')"
361                                                 + ".has('vlan-interface', 'key4')";
362                 assertEquals(
363                                 "gremlin query should be " + expected,
364                                 expected,
365                                 query.getQueryBuilder().getQuery());
366                 assertEquals(
367                                 "parent gremlin query should be equal the query for vlan",
368                                 expectedParent,
369                                 query.getQueryBuilder().getParentQuery().getQuery());
370                 assertEquals(
371                                 "result type should be l3-interface-ipv4-address-list",
372                                 "l3-interface-ipv4-address-list",
373                                 query.getResultType());
374                 
375     }
376         
377         /**
378          * Short circuit.
379          *
380          * @throws JAXBException the JAXB exception
381          * @throws UnsupportedEncodingException the unsupported encoding exception
382          * @throws AAIException the AAI exception
383          */
384         @Test
385     public void shortCircuit() throws JAXBException, UnsupportedEncodingException, AAIException {
386                 String content =
387                                 "{"
388                                 + "\"related-to\" : \"cvlan-tag\","
389                                 + "\"related-link\" : \"http://mock-system-name.com:8443/aai/v6/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655\","
390                                 + "\"relationship-data\" : [{"
391                                 + "\"relationship-key\" : \"vce.vnf-id\","
392                                 + "\"relationship-value\" : \"key1\""
393                                 + "}, {"
394                                 + "\"relationship-key\" : \"port-group.interface-id\","
395                                 + "\"relationship-value\" : \"key2\""
396                                 + "},{"
397                                 + "\"relationship-key\" : \"cvlan-tag.cvlan-tag\","
398                                 + "\"relationship-value\" : \"655\""
399                                 + "}]"
400                                 + "}";
401                                                 
402                 Unmarshaller unmarshaller = context.createUnmarshaller();
403             unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
404             unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
405                 unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
406                 Object obj = context.newDynamicEntity("Relationship");
407
408                 DynamicEntity entity = (DynamicEntity)unmarshaller.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                 String expected = 
413                                 ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
414                                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
415                                 + ".has('interface-id', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
416                                 + ".has('cvlan-tag', 655)";
417                 String expectedParent = 
418                                                 ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
419                                                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
420                                                 + ".has('interface-id', 'key2')";
421                 assertEquals(
422                                 "gremlin query should be " + expected,
423                                 expected,
424                                 query.getQueryBuilder().getQuery());
425                 assertEquals(
426                                 "parent gremlin query should be equal the query for port group",
427                                 expectedParent,
428                                 query.getQueryBuilder().getParentQuery().getQuery());
429                 assertEquals(
430                                 "result type should be cvlan-tag",
431                                 "cvlan-tag",
432                                 query.getResultType());
433                 
434     }
435         
436         @Test
437     public void shorterCircuit() throws JAXBException, UnsupportedEncodingException, AAIException {
438                 String content =
439                                 "{"
440                                 + "\"related-to\" : \"cvlan-tag\","
441                                 + "\"related-link\" : \"file:///network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655\""
442                                 + "}";
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.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
451                         
452                 Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
453                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
454                 String expected = 
455                                 ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
456                                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
457                                 + ".has('interface-id', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
458                                 + ".has('cvlan-tag', 655)";
459                 String expectedParent = 
460                                                 ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
461                                                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
462                                                 + ".has('interface-id', 'key2')";
463                 assertEquals(
464                                 "gremlin query should be " + expected,
465                                 expected,
466                                 query.getQueryBuilder().getQuery());
467                 assertEquals(
468                                 "parent gremlin query should be equal the query for port group",
469                                 expectedParent,
470                                 query.getQueryBuilder().getParentQuery().getQuery());
471                 assertEquals(
472                                 "result type should be cvlan-tag",
473                                 "cvlan-tag",
474                                 query.getResultType());
475                 
476     }
477         
478         /**
479          * Double key.
480          *
481          * @throws JAXBException the JAXB exception
482          * @throws UnsupportedEncodingException the unsupported encoding exception
483          * @throws AAIException the AAI exception
484          */
485         @Test
486     public void doubleKey() throws JAXBException, UnsupportedEncodingException, AAIException {
487                 String content =
488                                 "{"
489                                 + "\"related-to\" : \"ctag-pool\","
490                                 + "\"relationship-data\" : [{"
491                                 + "\"relationship-key\" : \"complex.physical-location-id\","
492                                 + "\"relationship-value\" : \"key1\""
493                                 + " }, { "
494                                 + "\"relationship-key\" : \"ctag-pool.target-pe\","
495                                 + " \"relationship-value\" : \"key2\""
496                                 + " },{"
497                                 + "\"relationship-key\" : \"ctag-pool.availability-zone-name\","
498                                 + "\"relationship-value\" : \"key3\""
499                                 + "}]"
500                                 + "}";
501                                                 
502                                                 
503                 Unmarshaller unmarshaller = context.createUnmarshaller();
504             unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
505             unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
506                 unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
507                 Object obj = context.newDynamicEntity("Relationship");
508
509                 DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
510                         
511                 Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
512                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
513
514                 String expected = 
515                                 ".has('physical-location-id', 'key1').has('aai-node-type', 'complex')"
516                                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'ctag-pool')"
517                                 + ".has('target-pe', 'key2')"
518                                 + ".has('availability-zone-name', 'key3')";
519                 String expectedParent = 
520                                 ".has('physical-location-id', 'key1').has('aai-node-type', 'complex')";
521
522                 assertEquals(
523                                 "gremlin query should be " + expected,
524                                 expected,
525                                 query.getQueryBuilder().getQuery());
526                 assertEquals(
527                                 "parent gremlin query should be equal the query for port group",
528                                 expectedParent,
529                                 query.getQueryBuilder().getParentQuery().getQuery());
530                 assertEquals(
531                                 "result type should be ctag-pool",
532                                 "ctag-pool",
533                                 query.getResultType());
534                 
535     }
536         
537         /**
538          * Abstract type.
539          *
540          * @throws JAXBException the JAXB exception
541          * @throws UnsupportedEncodingException the unsupported encoding exception
542          * @throws AAIException the AAI exception
543          */
544         @Test
545     public void abstractType() throws JAXBException, UnsupportedEncodingException, AAIException {
546                 String content =
547                                 "{"
548                                 + "\"related-to\" : \"vnf\","
549                                 + "\"relationship-data\" : [{"
550                                 + "\"relationship-key\" : \"vnf.vnf-id\","
551                                 + "\"relationship-value\" : \"key1\""
552                                 + " }]"
553                                 + "}";
554                                                 
555                                                 
556                 Unmarshaller unmarshaller = context.createUnmarshaller();
557             unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
558             unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
559                 unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
560                 Object obj = context.newDynamicEntity("Relationship");
561
562                 DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
563                         
564                 Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
565                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
566
567                 String expected = 
568                                 ".has('vnf-id', 'key1')"
569                                 + ".has('aai-node-type', P.within('vce','vpe','generic-vnf'))";
570                                 
571                 String expectedParent = 
572                                 ".has('vnf-id', 'key1')"
573                                                 + ".has('aai-node-type', P.within('vce','vpe','generic-vnf'))";
574                                                 
575                 assertEquals(
576                                 "gremlin query should be " + expected,
577                                 expected,
578                                 query.getQueryBuilder().getQuery());
579                 assertEquals(
580                                 "parent gremlin query should be equal the query for port group",
581                                 expectedParent,
582                                 query.getQueryBuilder().getParentQuery().getQuery());
583                 assertEquals(
584                                 "result type should be vnf",
585                                 "vnf",
586                                 query.getResultType());
587                 
588     }
589         
590         /**
591          * Invalid node name.
592          *
593          * @throws JAXBException the JAXB exception
594          * @throws UnsupportedEncodingException the unsupported encoding exception
595          * @throws AAIException the AAI exception
596          */
597         @Test
598         public void invalidNodeName() throws JAXBException, UnsupportedEncodingException, AAIException {
599                 String content =
600                                 "{"
601                                 + "\"related-to\" : \"l3-interface-ipv4-address-list\","
602                                 + "\"relationship-data\" : [{"
603                                 + "\"relationship-key\" : \"generic-vnf.vnf-id\","
604                                 + "\"relationship-value\" : \"key1\""
605                                 + "},{"
606                                 + "\"relationship-key\" : \"lag-interface.interface-name\","
607                                 + "\"relationship-value\" : \"key2\""
608                                 + "},{"
609                                 + "\"relationship-key\" : \"l-infeaterface.interface-name\","
610                                 + "\"relationship-value\" : \"key3\""
611                                 + "},{"
612                                 + "\"relationship-key\" : \"vlan.vlan-interface\","
613                                 + "\"relationship-value\" : \"key4\""
614                                 + "},{"
615                                 + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\","
616                                 + "\"relationship-value\" : \"key5\""
617                                 + "}]"
618                                 + "}";
619                 thrown.expect(AAIException.class);
620                 thrown.expectMessage(containsString("invalid object name"));
621                 
622                 Unmarshaller unmarshaller = context.createUnmarshaller();
623             unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
624             unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
625                 unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
626                 Object obj = context.newDynamicEntity("Relationship");
627
628                 DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
629                         
630                 Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
631                 dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
632
633         }
634         
635         /**
636          * Invalid property name.
637          *
638          * @throws JAXBException the JAXB exception
639          * @throws UnsupportedEncodingException the unsupported encoding exception
640          * @throws AAIException the AAI exception
641          */
642         @Test
643         public void invalidPropertyName() throws JAXBException, UnsupportedEncodingException, AAIException {
644                 String content =
645                                 "{"
646                                 + "\"related-to\" : \"l3-interface-ipv4-address-list\","
647                                 + "\"relationship-data\" : [{"
648                                 + "\"relationship-key\" : \"generic-vnf.vnf-id\","
649                                 + "\"relationship-value\" : \"key1\""
650                                 + "},{"
651                                 + "\"relationship-key\" : \"lag-interface.intfdaferface-name\","
652                                 + "\"relationship-value\" : \"key2\""
653                                 + "},{"
654                                 + "\"relationship-key\" : \"l-interface.interface-name\","
655                                 + "\"relationship-value\" : \"key3\""
656                                 + "},{"
657                                 + "\"relationship-key\" : \"vlan.vlan-interface\","
658                                 + "\"relationship-value\" : \"key4\""
659                                 + "},{"
660                                 + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\","
661                                 + "\"relationship-value\" : \"key5\""
662                                 + "}]"
663                                 + "}";
664                 thrown.expect(AAIException.class);
665                 thrown.expectMessage(containsString("invalid property name"));
666                 
667                 Unmarshaller unmarshaller = context.createUnmarshaller();
668             unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
669             unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
670                 unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
671                 Object obj = context.newDynamicEntity("Relationship");
672
673                 DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
674                         
675                 Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
676                 dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
677
678         }
679 }