diff options
Diffstat (limited to 'aai-core/src/test/java/org/onap/aai/parsers/query/RelationshipGremlinQueryTest.java')
-rw-r--r-- | aai-core/src/test/java/org/onap/aai/parsers/query/RelationshipGremlinQueryTest.java | 1154 |
1 files changed, 577 insertions, 577 deletions
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/query/RelationshipGremlinQueryTest.java b/aai-core/src/test/java/org/onap/aai/parsers/query/RelationshipGremlinQueryTest.java index dfb251b1..045f6b30 100644 --- a/aai-core/src/test/java/org/onap/aai/parsers/query/RelationshipGremlinQueryTest.java +++ b/aai-core/src/test/java/org/onap/aai/parsers/query/RelationshipGremlinQueryTest.java @@ -49,274 +49,274 @@ import static org.junit.Assert.assertEquals; @Ignore public class RelationshipGremlinQueryTest extends AAISetup { - @Autowired - private NodeIngestor injestor; - private TransactionalGraphEngine dbEngine; - private SchemaVersion version; - private DynamicJAXBContext context = injestor.getContextForVersion(version); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Before - public void setup(){ - version = new SchemaVersion("v10"); - dbEngine = - new JanusGraphDBEngine(QueryStyle.GREMLIN_TRAVERSAL, - loaderFactory.createLoaderForVersion(ModelType.MOXY, version), - false); - } - - /** - * Parent query. - * - * @throws JAXBException the JAXB exception - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test + @Autowired + private NodeIngestor injestor; + private TransactionalGraphEngine dbEngine; + private SchemaVersion version; + private DynamicJAXBContext context = injestor.getContextForVersion(version); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void setup(){ + version = new SchemaVersion("v10"); + dbEngine = + new JanusGraphDBEngine(QueryStyle.GREMLIN_TRAVERSAL, + loaderFactory.createLoaderForVersion(ModelType.MOXY, version), + false); + } + + /** + * Parent query. + * + * @throws JAXBException the JAXB exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test public void parentQuery() throws JAXBException, UnsupportedEncodingException, AAIException { - String content = - "{" - + "\"related-to\" : \"pserver\"," - + "\"relationship-data\" : [{" - + "\"relationship-key\" : \"pserver.hostname\"," - + "\"relationship-value\" : \"key1\"" - + "}]" - + "}"; - - Unmarshaller unmarshaller = context.createUnmarshaller(); - unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); - unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); - unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); - Object obj = context.newDynamicEntity("Relationship"); - - DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); - - Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); - - String expected = - ".has('hostname', 'key1').has('aai-node-type', 'pserver')"; - assertEquals( - "gremlin query should be " + expected, - expected, - query.getQueryBuilder().getQuery()); - assertEquals( - "parent gremlin query should be equal to normal query", - expected, - query.getQueryBuilder().getParentQuery().getQuery()); - assertEquals( - "result type should be pserver", - "pserver", - query.getResultType()); + String content = + "{" + + "\"related-to\" : \"pserver\"," + + "\"relationship-data\" : [{" + + "\"relationship-key\" : \"pserver.hostname\"," + + "\"relationship-value\" : \"key1\"" + + "}]" + + "}"; + + Unmarshaller unmarshaller = context.createUnmarshaller(); + unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); + unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); + unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); + Object obj = context.newDynamicEntity("Relationship"); + + DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); + + Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); + + String expected = + ".has('hostname', 'key1').has('aai-node-type', 'pserver')"; + assertEquals( + "gremlin query should be " + expected, + expected, + query.getQueryBuilder().getQuery()); + assertEquals( + "parent gremlin query should be equal to normal query", + expected, + query.getQueryBuilder().getParentQuery().getQuery()); + assertEquals( + "result type should be pserver", + "pserver", + query.getResultType()); } - /** - * Child query. - * - * @throws JAXBException the JAXB exception - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test + /** + * Child query. + * + * @throws JAXBException the JAXB exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test public void childQuery() throws JAXBException, UnsupportedEncodingException, AAIException { - String content = - "{" - + "\"related-to\" : \"lag-interface\"," - + "\"relationship-data\" : [{" - + "\"relationship-key\" : \"pserver.hostname\"," - + "\"relationship-value\" : \"key1\"" - + "}, {" - + "\"relationship-key\" : \"lag-interface.interface-name\"," - + "\"relationship-value\" : \"key2\"" - + "}]" - + "}"; - - Unmarshaller unmarshaller = context.createUnmarshaller(); - unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); - unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); - unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); - Object obj = context.newDynamicEntity("Relationship"); - - DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); - - Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); - - String expected = ".has('hostname', 'key1').has('aai-node-type', 'pserver').in('tosca.relationships.BindsTo').has('aai-node-type', 'lag-interface')" - + ".has('interface-name', 'key2')"; - String parentExpected = - ".has('hostname', 'key1').has('aai-node-type', 'pserver')"; - assertEquals( - "gremlin query should be for node", - expected, - query.getQueryBuilder().getQuery()); - assertEquals( - "parent gremlin query should be for parent", - parentExpected, - query.getQueryBuilder().getParentQuery().getQuery()); - assertEquals( - "result type should be lag-interface", - "lag-interface", - query.getResultType()); + String content = + "{" + + "\"related-to\" : \"lag-interface\"," + + "\"relationship-data\" : [{" + + "\"relationship-key\" : \"pserver.hostname\"," + + "\"relationship-value\" : \"key1\"" + + "}, {" + + "\"relationship-key\" : \"lag-interface.interface-name\"," + + "\"relationship-value\" : \"key2\"" + + "}]" + + "}"; + + Unmarshaller unmarshaller = context.createUnmarshaller(); + unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); + unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); + unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); + Object obj = context.newDynamicEntity("Relationship"); + + DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); + + Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); + + String expected = ".has('hostname', 'key1').has('aai-node-type', 'pserver').in('tosca.relationships.BindsTo').has('aai-node-type', 'lag-interface')" + + ".has('interface-name', 'key2')"; + String parentExpected = + ".has('hostname', 'key1').has('aai-node-type', 'pserver')"; + assertEquals( + "gremlin query should be for node", + expected, + query.getQueryBuilder().getQuery()); + assertEquals( + "parent gremlin query should be for parent", + parentExpected, + query.getQueryBuilder().getParentQuery().getQuery()); + assertEquals( + "result type should be lag-interface", + "lag-interface", + query.getResultType()); } - /** - * Naming exceptions. - * - * @throws JAXBException the JAXB exception - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test + /** + * Naming exceptions. + * + * @throws JAXBException the JAXB exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test public void namingExceptions() throws JAXBException, UnsupportedEncodingException, AAIException { - String content = - "{" - + "\"related-to\" : \"cvlan-tag\"," - + "\"relationship-data\" : [{" - + "\"relationship-key\" : \"vce.vnf-id\"," - + "\"relationship-value\" : \"key1\"" - + "}, {" - + "\"relationship-key\" : \"port-group.interface-id\"," - + "\"relationship-value\" : \"key2\"" - + "},{" - + "\"relationship-key\" : \"cvlan-tag.cvlan-tag\"," - + "\"relationship-value\" : \"655\"" - + "}]" - + "}"; - - Unmarshaller unmarshaller = context.createUnmarshaller(); - unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); - unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); - unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); - Object obj = context.newDynamicEntity("Relationship"); - - DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); - - Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); - String expected = - ".has('vnf-id', 'key1').has('aai-node-type', 'vce')" - + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')" - + ".has('interface-id', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')" - + ".has('cvlan-tag', 655)"; - String expectedParent = - ".has('vnf-id', 'key1').has('aai-node-type', 'vce')" - + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')" - + ".has('interface-id', 'key2')"; - assertEquals( - "gremlin query should be " + expected, - expected, - query.getQueryBuilder().getQuery()); - assertEquals( - "parent gremlin query should be equal the query for port group", - expectedParent, - query.getQueryBuilder().getParentQuery().getQuery()); - assertEquals( - "result type should be cvlan-tag", - "cvlan-tag", - query.getResultType()); + String content = + "{" + + "\"related-to\" : \"cvlan-tag\"," + + "\"relationship-data\" : [{" + + "\"relationship-key\" : \"vce.vnf-id\"," + + "\"relationship-value\" : \"key1\"" + + "}, {" + + "\"relationship-key\" : \"port-group.interface-id\"," + + "\"relationship-value\" : \"key2\"" + + "},{" + + "\"relationship-key\" : \"cvlan-tag.cvlan-tag\"," + + "\"relationship-value\" : \"655\"" + + "}]" + + "}"; + + Unmarshaller unmarshaller = context.createUnmarshaller(); + unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); + unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); + unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); + Object obj = context.newDynamicEntity("Relationship"); + + DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); + + Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); + String expected = + ".has('vnf-id', 'key1').has('aai-node-type', 'vce')" + + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')" + + ".has('interface-id', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')" + + ".has('cvlan-tag', 655)"; + String expectedParent = + ".has('vnf-id', 'key1').has('aai-node-type', 'vce')" + + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')" + + ".has('interface-id', 'key2')"; + assertEquals( + "gremlin query should be " + expected, + expected, + query.getQueryBuilder().getQuery()); + assertEquals( + "parent gremlin query should be equal the query for port group", + expectedParent, + query.getQueryBuilder().getParentQuery().getQuery()); + assertEquals( + "result type should be cvlan-tag", + "cvlan-tag", + query.getResultType()); } - /** - * Scrambled relationship. - * - * @throws JAXBException the JAXB exception - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test - public void scrambledRelationship() throws JAXBException, UnsupportedEncodingException, AAIException { - String content = - "{" - + "\"related-to\" : \"l3-interface-ipv4-address-list\"," - + "\"relationship-data\" : [{" - + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\"," - + "\"relationship-value\" : \"key5\"" - + "},{" - + "\"relationship-key\" : \"lag-interface.interface-name\"," - + "\"relationship-value\" : \"key2\"" - + "},{" - + "\"relationship-key\" : \"l-interface.interface-name\"," - + "\"relationship-value\" : \"key3\"" - + "},{" - + "\"relationship-key\" : \"vlan.vlan-interface\"," - + "\"relationship-value\" : \"key4\"" - + "},{" - + "\"relationship-key\" : \"generic-vnf.vnf-id\"," - + "\"relationship-value\" : \"key1\"" - + "}]" - + "}"; - scrambledRelationshipSpec(content); - } - - /** - * Reversed relationship. - * - * @throws JAXBException the JAXB exception - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test - public void reversedRelationship() throws JAXBException, UnsupportedEncodingException, AAIException { - String content = - "{" - + "\"related-to\" : \"l3-interface-ipv4-address-list\"," - + "\"relationship-data\" : [{" - + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\"," - + "\"relationship-value\" : \"key5\"" - + "},{" - + "\"relationship-key\" : \"vlan.vlan-interface\"," - + "\"relationship-value\" : \"key4\"" - + "},{" - + "\"relationship-key\" : \"l-interface.interface-name\"," - + "\"relationship-value\" : \"key3\"" - + "},{" - + "\"relationship-key\" : \"lag-interface.interface-name\"," - + "\"relationship-value\" : \"key2\"" - + "},{" - + "\"relationship-key\" : \"generic-vnf.vnf-id\"," - + "\"relationship-value\" : \"key1\"" - + "}]" - + "}"; - scrambledRelationshipSpec(content); - } - - /** - * Ordered ambiguous relationship. - * - * @throws JAXBException the JAXB exception - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test - public void orderedAmbiguousRelationship() throws JAXBException, UnsupportedEncodingException, AAIException { - String content = - "{" - + "\"related-to\" : \"l3-interface-ipv4-address-list\"," - + "\"relationship-data\" : [{" - + "\"relationship-key\" : \"generic-vnf.vnf-id\"," - + "\"relationship-value\" : \"key1\"" - + "},{" - + "\"relationship-key\" : \"lag-interface.interface-name\"," - + "\"relationship-value\" : \"key2\"" - + "},{" - + "\"relationship-key\" : \"l-interface.interface-name\"," - + "\"relationship-value\" : \"key3\"" - + "},{" - + "\"relationship-key\" : \"vlan.vlan-interface\"," - + "\"relationship-value\" : \"key4\"" - + "},{" - + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\"," - + "\"relationship-value\" : \"key5\"" - + "}]" - + "}"; - scrambledRelationshipSpec(content); - } + /** + * Scrambled relationship. + * + * @throws JAXBException the JAXB exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test + public void scrambledRelationship() throws JAXBException, UnsupportedEncodingException, AAIException { + String content = + "{" + + "\"related-to\" : \"l3-interface-ipv4-address-list\"," + + "\"relationship-data\" : [{" + + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\"," + + "\"relationship-value\" : \"key5\"" + + "},{" + + "\"relationship-key\" : \"lag-interface.interface-name\"," + + "\"relationship-value\" : \"key2\"" + + "},{" + + "\"relationship-key\" : \"l-interface.interface-name\"," + + "\"relationship-value\" : \"key3\"" + + "},{" + + "\"relationship-key\" : \"vlan.vlan-interface\"," + + "\"relationship-value\" : \"key4\"" + + "},{" + + "\"relationship-key\" : \"generic-vnf.vnf-id\"," + + "\"relationship-value\" : \"key1\"" + + "}]" + + "}"; + scrambledRelationshipSpec(content); + } + + /** + * Reversed relationship. + * + * @throws JAXBException the JAXB exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test + public void reversedRelationship() throws JAXBException, UnsupportedEncodingException, AAIException { + String content = + "{" + + "\"related-to\" : \"l3-interface-ipv4-address-list\"," + + "\"relationship-data\" : [{" + + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\"," + + "\"relationship-value\" : \"key5\"" + + "},{" + + "\"relationship-key\" : \"vlan.vlan-interface\"," + + "\"relationship-value\" : \"key4\"" + + "},{" + + "\"relationship-key\" : \"l-interface.interface-name\"," + + "\"relationship-value\" : \"key3\"" + + "},{" + + "\"relationship-key\" : \"lag-interface.interface-name\"," + + "\"relationship-value\" : \"key2\"" + + "},{" + + "\"relationship-key\" : \"generic-vnf.vnf-id\"," + + "\"relationship-value\" : \"key1\"" + + "}]" + + "}"; + scrambledRelationshipSpec(content); + } + + /** + * Ordered ambiguous relationship. + * + * @throws JAXBException the JAXB exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test + public void orderedAmbiguousRelationship() throws JAXBException, UnsupportedEncodingException, AAIException { + String content = + "{" + + "\"related-to\" : \"l3-interface-ipv4-address-list\"," + + "\"relationship-data\" : [{" + + "\"relationship-key\" : \"generic-vnf.vnf-id\"," + + "\"relationship-value\" : \"key1\"" + + "},{" + + "\"relationship-key\" : \"lag-interface.interface-name\"," + + "\"relationship-value\" : \"key2\"" + + "},{" + + "\"relationship-key\" : \"l-interface.interface-name\"," + + "\"relationship-value\" : \"key3\"" + + "},{" + + "\"relationship-key\" : \"vlan.vlan-interface\"," + + "\"relationship-value\" : \"key4\"" + + "},{" + + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\"," + + "\"relationship-value\" : \"key5\"" + + "}]" + + "}"; + scrambledRelationshipSpec(content); + } /** * Scrambled relationship spec. @@ -329,344 +329,344 @@ public class RelationshipGremlinQueryTest extends AAISetup { public void scrambledRelationshipSpec(String content) throws JAXBException, UnsupportedEncodingException, AAIException { - Unmarshaller unmarshaller = context.createUnmarshaller(); - unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); - unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); - unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); - Object obj = context.newDynamicEntity("Relationship"); - - DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); - - Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); - String expected = - ".has('vnf-id', 'key1').has('aai-node-type', 'generic-vnf')" - + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'lag-interface')" - + ".has('interface-name', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'l-interface')" - + ".has('interface-name', 'key3').out('tosca.relationships.LinksTo').has('aai-node-type', 'vlan')" - + ".has('vlan-interface', 'key4').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'l3-interface-ipv4-address-list')" - + ".has('l3-interface-ipv4-address', 'key5')"; - String expectedParent = - ".has('vnf-id', 'key1').has('aai-node-type', 'generic-vnf')" - + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'lag-interface')" - + ".has('interface-name', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'l-interface')" - + ".has('interface-name', 'key3').out('tosca.relationships.LinksTo').has('aai-node-type', 'vlan')" - + ".has('vlan-interface', 'key4')"; - assertEquals( - "gremlin query should be " + expected, - expected, - query.getQueryBuilder().getQuery()); - assertEquals( - "parent gremlin query should be equal the query for vlan", - expectedParent, - query.getQueryBuilder().getParentQuery().getQuery()); - assertEquals( - "result type should be l3-interface-ipv4-address-list", - "l3-interface-ipv4-address-list", - query.getResultType()); + Unmarshaller unmarshaller = context.createUnmarshaller(); + unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); + unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); + unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); + Object obj = context.newDynamicEntity("Relationship"); + + DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); + + Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); + String expected = + ".has('vnf-id', 'key1').has('aai-node-type', 'generic-vnf')" + + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'lag-interface')" + + ".has('interface-name', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'l-interface')" + + ".has('interface-name', 'key3').out('tosca.relationships.LinksTo').has('aai-node-type', 'vlan')" + + ".has('vlan-interface', 'key4').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'l3-interface-ipv4-address-list')" + + ".has('l3-interface-ipv4-address', 'key5')"; + String expectedParent = + ".has('vnf-id', 'key1').has('aai-node-type', 'generic-vnf')" + + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'lag-interface')" + + ".has('interface-name', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'l-interface')" + + ".has('interface-name', 'key3').out('tosca.relationships.LinksTo').has('aai-node-type', 'vlan')" + + ".has('vlan-interface', 'key4')"; + assertEquals( + "gremlin query should be " + expected, + expected, + query.getQueryBuilder().getQuery()); + assertEquals( + "parent gremlin query should be equal the query for vlan", + expectedParent, + query.getQueryBuilder().getParentQuery().getQuery()); + assertEquals( + "result type should be l3-interface-ipv4-address-list", + "l3-interface-ipv4-address-list", + query.getResultType()); } - /** - * Short circuit. - * - * @throws JAXBException the JAXB exception - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test + /** + * Short circuit. + * + * @throws JAXBException the JAXB exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test public void shortCircuit() throws JAXBException, UnsupportedEncodingException, AAIException { - String content = - "{" - + "\"related-to\" : \"cvlan-tag\"," - + "\"related-link\" : \"http://mock-system-name.com:8443/aai/v6/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655\"," - + "\"relationship-data\" : [{" - + "\"relationship-key\" : \"vce.vnf-id\"," - + "\"relationship-value\" : \"key1\"" - + "}, {" - + "\"relationship-key\" : \"port-group.interface-id\"," - + "\"relationship-value\" : \"key2\"" - + "},{" - + "\"relationship-key\" : \"cvlan-tag.cvlan-tag\"," - + "\"relationship-value\" : \"655\"" - + "}]" - + "}"; - - Unmarshaller unmarshaller = context.createUnmarshaller(); - unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); - unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); - unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); - Object obj = context.newDynamicEntity("Relationship"); - - DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); - - Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); - String expected = - ".has('vnf-id', 'key1').has('aai-node-type', 'vce')" - + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')" - + ".has('interface-id', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')" - + ".has('cvlan-tag', 655)"; - String expectedParent = - ".has('vnf-id', 'key1').has('aai-node-type', 'vce')" - + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')" - + ".has('interface-id', 'key2')"; - assertEquals( - "gremlin query should be " + expected, - expected, - query.getQueryBuilder().getQuery()); - assertEquals( - "parent gremlin query should be equal the query for port group", - expectedParent, - query.getQueryBuilder().getParentQuery().getQuery()); - assertEquals( - "result type should be cvlan-tag", - "cvlan-tag", - query.getResultType()); + String content = + "{" + + "\"related-to\" : \"cvlan-tag\"," + + "\"related-link\" : \"http://mock-system-name.com:8443/aai/v6/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655\"," + + "\"relationship-data\" : [{" + + "\"relationship-key\" : \"vce.vnf-id\"," + + "\"relationship-value\" : \"key1\"" + + "}, {" + + "\"relationship-key\" : \"port-group.interface-id\"," + + "\"relationship-value\" : \"key2\"" + + "},{" + + "\"relationship-key\" : \"cvlan-tag.cvlan-tag\"," + + "\"relationship-value\" : \"655\"" + + "}]" + + "}"; + + Unmarshaller unmarshaller = context.createUnmarshaller(); + unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); + unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); + unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); + Object obj = context.newDynamicEntity("Relationship"); + + DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); + + Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); + String expected = + ".has('vnf-id', 'key1').has('aai-node-type', 'vce')" + + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')" + + ".has('interface-id', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')" + + ".has('cvlan-tag', 655)"; + String expectedParent = + ".has('vnf-id', 'key1').has('aai-node-type', 'vce')" + + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')" + + ".has('interface-id', 'key2')"; + assertEquals( + "gremlin query should be " + expected, + expected, + query.getQueryBuilder().getQuery()); + assertEquals( + "parent gremlin query should be equal the query for port group", + expectedParent, + query.getQueryBuilder().getParentQuery().getQuery()); + assertEquals( + "result type should be cvlan-tag", + "cvlan-tag", + query.getResultType()); } - @Test + @Test public void shorterCircuit() throws JAXBException, UnsupportedEncodingException, AAIException { - String content = - "{" - + "\"related-to\" : \"cvlan-tag\"," - + "\"related-link\" : \"file:///network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655\"" - + "}"; - - Unmarshaller unmarshaller = context.createUnmarshaller(); - unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); - unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); - unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); - Object obj = context.newDynamicEntity("Relationship"); - - DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); - - Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); - String expected = - ".has('vnf-id', 'key1').has('aai-node-type', 'vce')" - + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')" - + ".has('interface-id', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')" - + ".has('cvlan-tag', 655)"; - String expectedParent = - ".has('vnf-id', 'key1').has('aai-node-type', 'vce')" - + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')" - + ".has('interface-id', 'key2')"; - assertEquals( - "gremlin query should be " + expected, - expected, - query.getQueryBuilder().getQuery()); - assertEquals( - "parent gremlin query should be equal the query for port group", - expectedParent, - query.getQueryBuilder().getParentQuery().getQuery()); - assertEquals( - "result type should be cvlan-tag", - "cvlan-tag", - query.getResultType()); + String content = + "{" + + "\"related-to\" : \"cvlan-tag\"," + + "\"related-link\" : \"file:///network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655\"" + + "}"; + + Unmarshaller unmarshaller = context.createUnmarshaller(); + unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); + unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); + unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); + Object obj = context.newDynamicEntity("Relationship"); + + DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); + + Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); + String expected = + ".has('vnf-id', 'key1').has('aai-node-type', 'vce')" + + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')" + + ".has('interface-id', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')" + + ".has('cvlan-tag', 655)"; + String expectedParent = + ".has('vnf-id', 'key1').has('aai-node-type', 'vce')" + + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')" + + ".has('interface-id', 'key2')"; + assertEquals( + "gremlin query should be " + expected, + expected, + query.getQueryBuilder().getQuery()); + assertEquals( + "parent gremlin query should be equal the query for port group", + expectedParent, + query.getQueryBuilder().getParentQuery().getQuery()); + assertEquals( + "result type should be cvlan-tag", + "cvlan-tag", + query.getResultType()); } - /** - * Double key. - * - * @throws JAXBException the JAXB exception - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test + /** + * Double key. + * + * @throws JAXBException the JAXB exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test public void doubleKey() throws JAXBException, UnsupportedEncodingException, AAIException { - String content = - "{" - + "\"related-to\" : \"ctag-pool\"," - + "\"relationship-data\" : [{" - + "\"relationship-key\" : \"complex.physical-location-id\"," - + "\"relationship-value\" : \"key1\"" - + " }, { " - + "\"relationship-key\" : \"ctag-pool.target-pe\"," - + " \"relationship-value\" : \"key2\"" - + " },{" - + "\"relationship-key\" : \"ctag-pool.availability-zone-name\"," - + "\"relationship-value\" : \"key3\"" - + "}]" - + "}"; - - - Unmarshaller unmarshaller = context.createUnmarshaller(); - unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); - unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); - unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); - Object obj = context.newDynamicEntity("Relationship"); - - DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); - - Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); - - String expected = - ".has('physical-location-id', 'key1').has('aai-node-type', 'complex')" - + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'ctag-pool')" - + ".has('target-pe', 'key2')" - + ".has('availability-zone-name', 'key3')"; - String expectedParent = - ".has('physical-location-id', 'key1').has('aai-node-type', 'complex')"; - - assertEquals( - "gremlin query should be " + expected, - expected, - query.getQueryBuilder().getQuery()); - assertEquals( - "parent gremlin query should be equal the query for port group", - expectedParent, - query.getQueryBuilder().getParentQuery().getQuery()); - assertEquals( - "result type should be ctag-pool", - "ctag-pool", - query.getResultType()); + String content = + "{" + + "\"related-to\" : \"ctag-pool\"," + + "\"relationship-data\" : [{" + + "\"relationship-key\" : \"complex.physical-location-id\"," + + "\"relationship-value\" : \"key1\"" + + " }, { " + + "\"relationship-key\" : \"ctag-pool.target-pe\"," + + " \"relationship-value\" : \"key2\"" + + " },{" + + "\"relationship-key\" : \"ctag-pool.availability-zone-name\"," + + "\"relationship-value\" : \"key3\"" + + "}]" + + "}"; + + + Unmarshaller unmarshaller = context.createUnmarshaller(); + unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); + unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); + unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); + Object obj = context.newDynamicEntity("Relationship"); + + DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); + + Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); + + String expected = + ".has('physical-location-id', 'key1').has('aai-node-type', 'complex')" + + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'ctag-pool')" + + ".has('target-pe', 'key2')" + + ".has('availability-zone-name', 'key3')"; + String expectedParent = + ".has('physical-location-id', 'key1').has('aai-node-type', 'complex')"; + + assertEquals( + "gremlin query should be " + expected, + expected, + query.getQueryBuilder().getQuery()); + assertEquals( + "parent gremlin query should be equal the query for port group", + expectedParent, + query.getQueryBuilder().getParentQuery().getQuery()); + assertEquals( + "result type should be ctag-pool", + "ctag-pool", + query.getResultType()); } - /** - * Abstract type. - * - * @throws JAXBException the JAXB exception - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test + /** + * Abstract type. + * + * @throws JAXBException the JAXB exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test public void abstractType() throws JAXBException, UnsupportedEncodingException, AAIException { - String content = - "{" - + "\"related-to\" : \"vnf\"," - + "\"relationship-data\" : [{" - + "\"relationship-key\" : \"vnf.vnf-id\"," - + "\"relationship-value\" : \"key1\"" - + " }]" - + "}"; - - - Unmarshaller unmarshaller = context.createUnmarshaller(); - unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); - unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); - unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); - Object obj = context.newDynamicEntity("Relationship"); - - DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); - - Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); - - String expected = - ".has('vnf-id', 'key1')" - + ".has('aai-node-type', P.within('vce','generic-vnf'))"; - - String expectedParent = - ".has('vnf-id', 'key1')" - + ".has('aai-node-type', P.within('vce','generic-vnf'))"; - - assertEquals( - "gremlin query should be " + expected, - expected, - query.getQueryBuilder().getQuery()); - assertEquals( - "parent gremlin query should be equal the query for port group", - expectedParent, - query.getQueryBuilder().getParentQuery().getQuery()); - assertEquals( - "result type should be vnf", - "vnf", - query.getResultType()); + String content = + "{" + + "\"related-to\" : \"vnf\"," + + "\"relationship-data\" : [{" + + "\"relationship-key\" : \"vnf.vnf-id\"," + + "\"relationship-value\" : \"key1\"" + + " }]" + + "}"; + + + Unmarshaller unmarshaller = context.createUnmarshaller(); + unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); + unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); + unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); + Object obj = context.newDynamicEntity("Relationship"); + + DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); + + Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); + + String expected = + ".has('vnf-id', 'key1')" + + ".has('aai-node-type', P.within('vce','generic-vnf'))"; + + String expectedParent = + ".has('vnf-id', 'key1')" + + ".has('aai-node-type', P.within('vce','generic-vnf'))"; + + assertEquals( + "gremlin query should be " + expected, + expected, + query.getQueryBuilder().getQuery()); + assertEquals( + "parent gremlin query should be equal the query for port group", + expectedParent, + query.getQueryBuilder().getParentQuery().getQuery()); + assertEquals( + "result type should be vnf", + "vnf", + query.getResultType()); } - /** - * Invalid node name. - * - * @throws JAXBException the JAXB exception - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test - public void invalidNodeName() throws JAXBException, UnsupportedEncodingException, AAIException { - String content = - "{" - + "\"related-to\" : \"l3-interface-ipv4-address-list\"," - + "\"relationship-data\" : [{" - + "\"relationship-key\" : \"generic-vnf.vnf-id\"," - + "\"relationship-value\" : \"key1\"" - + "},{" - + "\"relationship-key\" : \"lag-interface.interface-name\"," - + "\"relationship-value\" : \"key2\"" - + "},{" - + "\"relationship-key\" : \"l-infeaterface.interface-name\"," - + "\"relationship-value\" : \"key3\"" - + "},{" - + "\"relationship-key\" : \"vlan.vlan-interface\"," - + "\"relationship-value\" : \"key4\"" - + "},{" - + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\"," - + "\"relationship-value\" : \"key5\"" - + "}]" - + "}"; - thrown.expect(AAIException.class); - thrown.expectMessage(containsString("invalid object name")); - - Unmarshaller unmarshaller = context.createUnmarshaller(); - unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); - unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); - unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); - Object obj = context.newDynamicEntity("Relationship"); - - DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); - - Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); - dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); - - } - - /** - * Invalid property name. - * - * @throws JAXBException the JAXB exception - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test - public void invalidPropertyName() throws JAXBException, UnsupportedEncodingException, AAIException { - String content = - "{" - + "\"related-to\" : \"l3-interface-ipv4-address-list\"," - + "\"relationship-data\" : [{" - + "\"relationship-key\" : \"generic-vnf.vnf-id\"," - + "\"relationship-value\" : \"key1\"" - + "},{" - + "\"relationship-key\" : \"lag-interface.intfdaferface-name\"," - + "\"relationship-value\" : \"key2\"" - + "},{" - + "\"relationship-key\" : \"l-interface.interface-name\"," - + "\"relationship-value\" : \"key3\"" - + "},{" - + "\"relationship-key\" : \"vlan.vlan-interface\"," - + "\"relationship-value\" : \"key4\"" - + "},{" - + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\"," - + "\"relationship-value\" : \"key5\"" - + "}]" - + "}"; - thrown.expect(AAIException.class); - thrown.expectMessage(containsString("invalid property name")); - - Unmarshaller unmarshaller = context.createUnmarshaller(); - unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); - unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); - unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); - Object obj = context.newDynamicEntity("Relationship"); - - DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); - - Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); - dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); - - } + /** + * Invalid node name. + * + * @throws JAXBException the JAXB exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test + public void invalidNodeName() throws JAXBException, UnsupportedEncodingException, AAIException { + String content = + "{" + + "\"related-to\" : \"l3-interface-ipv4-address-list\"," + + "\"relationship-data\" : [{" + + "\"relationship-key\" : \"generic-vnf.vnf-id\"," + + "\"relationship-value\" : \"key1\"" + + "},{" + + "\"relationship-key\" : \"lag-interface.interface-name\"," + + "\"relationship-value\" : \"key2\"" + + "},{" + + "\"relationship-key\" : \"l-infeaterface.interface-name\"," + + "\"relationship-value\" : \"key3\"" + + "},{" + + "\"relationship-key\" : \"vlan.vlan-interface\"," + + "\"relationship-value\" : \"key4\"" + + "},{" + + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\"," + + "\"relationship-value\" : \"key5\"" + + "}]" + + "}"; + thrown.expect(AAIException.class); + thrown.expectMessage(containsString("invalid object name")); + + Unmarshaller unmarshaller = context.createUnmarshaller(); + unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); + unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); + unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); + Object obj = context.newDynamicEntity("Relationship"); + + DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); + + Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); + dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); + + } + + /** + * Invalid property name. + * + * @throws JAXBException the JAXB exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test + public void invalidPropertyName() throws JAXBException, UnsupportedEncodingException, AAIException { + String content = + "{" + + "\"related-to\" : \"l3-interface-ipv4-address-list\"," + + "\"relationship-data\" : [{" + + "\"relationship-key\" : \"generic-vnf.vnf-id\"," + + "\"relationship-value\" : \"key1\"" + + "},{" + + "\"relationship-key\" : \"lag-interface.intfdaferface-name\"," + + "\"relationship-value\" : \"key2\"" + + "},{" + + "\"relationship-key\" : \"l-interface.interface-name\"," + + "\"relationship-value\" : \"key3\"" + + "},{" + + "\"relationship-key\" : \"vlan.vlan-interface\"," + + "\"relationship-value\" : \"key4\"" + + "},{" + + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\"," + + "\"relationship-value\" : \"key5\"" + + "}]" + + "}"; + thrown.expect(AAIException.class); + thrown.expectMessage(containsString("invalid property name")); + + Unmarshaller unmarshaller = context.createUnmarshaller(); + unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); + unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); + unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); + Object obj = context.newDynamicEntity("Relationship"); + + DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); + + Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); + dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); + + } } |