diff options
author | Keong Lim <keong.lim@huawei.com> | 2018-11-01 17:06:59 +1100 |
---|---|---|
committer | Keong Lim <keong.lim@huawei.com> | 2019-01-30 11:08:15 +1100 |
commit | 6904c12bfbc7400ae8c8ea8ad7c71f948985bf6b (patch) | |
tree | 22f6b1300e01a2c5e7d482f5292f61a5c3b2e26a /aai-core | |
parent | 8b9367d9595c19e2cdcd64e07ae7ed358faa401c (diff) |
AAI-1523 checkstyle warnings for aai-core parsers
Issue-ID: AAI-1523
re-indent code with spaces to clean up some checkstyle warnings
for aai-core test parsers (part of 24k lines of output)
Change-Id: I9908650b6fccfca9657b0b2ca75f74dc6b469449
Signed-off-by: Keong Lim <keong.lim@huawei.com>
Diffstat (limited to 'aai-core')
12 files changed, 2640 insertions, 2640 deletions
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/query/GraphTraversalTest.java b/aai-core/src/test/java/org/onap/aai/parsers/query/GraphTraversalTest.java index c2f8055b..478f8bfa 100644 --- a/aai-core/src/test/java/org/onap/aai/parsers/query/GraphTraversalTest.java +++ b/aai-core/src/test/java/org/onap/aai/parsers/query/GraphTraversalTest.java @@ -59,772 +59,772 @@ import static org.junit.Assert.assertEquals; @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) public class GraphTraversalTest extends DataLinkSetup { - private TransactionalGraphEngine dbEngine; - private TransactionalGraphEngine dbEngineDepthVersion; - - @Parameterized.Parameter(value = 0) - public QueryStyle queryStyle; - - @Parameterized.Parameters(name = "QueryStyle.{0}") - public static Collection<Object[]> data() { - return Arrays.asList(new Object[][]{ - {QueryStyle.TRAVERSAL}, - {QueryStyle.TRAVERSAL_URI} - }); - } - - @Rule public ExpectedException thrown = ExpectedException.none(); - - - /** - * Configure. - * @throws Exception - * @throws SecurityException - * @throws NoSuchFieldException - */ - @Before - public void configure() throws Exception { - dbEngine = - new JanusGraphDBEngine(queryStyle, - loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()), - false); - - dbEngineDepthVersion = - new JanusGraphDBEngine(queryStyle, - loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion()), - false); - } - - /** - * Parent query. - * - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test + private TransactionalGraphEngine dbEngine; + private TransactionalGraphEngine dbEngineDepthVersion; + + @Parameterized.Parameter(value = 0) + public QueryStyle queryStyle; + + @Parameterized.Parameters(name = "QueryStyle.{0}") + public static Collection<Object[]> data() { + return Arrays.asList(new Object[][]{ + {QueryStyle.TRAVERSAL}, + {QueryStyle.TRAVERSAL_URI} + }); + } + + @Rule public ExpectedException thrown = ExpectedException.none(); + + + /** + * Configure. + * @throws Exception + * @throws SecurityException + * @throws NoSuchFieldException + */ + @Before + public void configure() throws Exception { + dbEngine = + new JanusGraphDBEngine(queryStyle, + loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()), + false); + + dbEngineDepthVersion = + new JanusGraphDBEngine(queryStyle, + loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion()), + false); + } + + /** + * Parent query. + * + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test public void parentQuery() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1").build(); - - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); - - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex"); - assertEquals( - "gremlin query should be " + expected.toString(), - expected.toString(), - query.getQueryBuilder().getQuery().toString()); - assertEquals( - "parent gremlin query should be equal to normal query", - expected.toString(), - query.getQueryBuilder().getParentQuery().getQuery().toString()); - assertEquals( - "result type should be complex", - "complex", - query.getResultType()); - assertEquals( - "result type should be empty", - "", - query.getParentResultType()); - assertEquals("dependent",false, query.isDependent()); + URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1").build(); + + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); + + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex"); + assertEquals( + "gremlin query should be " + expected.toString(), + expected.toString(), + query.getQueryBuilder().getQuery().toString()); + assertEquals( + "parent gremlin query should be equal to normal query", + expected.toString(), + query.getQueryBuilder().getParentQuery().getQuery().toString()); + assertEquals( + "result type should be complex", + "complex", + query.getResultType()); + assertEquals( + "result type should be empty", + "", + query.getParentResultType()); + assertEquals("dependent",false, query.isDependent()); } - /** - * Child query. - * - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test + /** + * Child query. + * + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test public void childQuery() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3").build(); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() - .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"); - GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() - .has("physical-location-id", "key1").has("aai-node-type", "complex"); - assertEquals( - "gremlin query should be " + expected.toString(), - expected.toString(), - query.getQueryBuilder().getQuery().toString()); - assertEquals( - "parent gremlin query should be equal the query for complex", - expectedParent.toString(), - query.getQueryBuilder().getParentQuery().getQuery().toString()); - assertEquals( - "result type should be complex", - "complex", - query.getParentResultType()); - assertEquals( - "result type should be ctag-pool", - "ctag-pool", - query.getResultType()); - assertEquals("dependent",true, query.isDependent()); + URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3").build(); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() + .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"); + GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() + .has("physical-location-id", "key1").has("aai-node-type", "complex"); + assertEquals( + "gremlin query should be " + expected.toString(), + expected.toString(), + query.getQueryBuilder().getQuery().toString()); + assertEquals( + "parent gremlin query should be equal the query for complex", + expectedParent.toString(), + query.getQueryBuilder().getParentQuery().getQuery().toString()); + assertEquals( + "result type should be complex", + "complex", + query.getParentResultType()); + assertEquals( + "result type should be ctag-pool", + "ctag-pool", + query.getResultType()); + assertEquals("dependent",true, query.isDependent()); } - /** - * Naming exceptions. - * - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test + /** + * Naming exceptions. + * + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test public void namingExceptions() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build(); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() - .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); - GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() - .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.toString(), - expected.toString(), - query.getQueryBuilder().getQuery().toString()); - assertEquals( - "parent gremlin query should be equal the query for port group", - expectedParent.toString(), - query.getQueryBuilder().getParentQuery().getQuery().toString()); - assertEquals( - "result type should be cvlan-tag", - "cvlan-tag", - query.getResultType()); - assertEquals( - "result type should be port-group", - "port-group", - query.getParentResultType()); - assertEquals( - "contaner type should be empty", - "", - query.getContainerType()); - assertEquals("dependent",true, query.isDependent()); + URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build(); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() + .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); + GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() + .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.toString(), + expected.toString(), + query.getQueryBuilder().getQuery().toString()); + assertEquals( + "parent gremlin query should be equal the query for port group", + expectedParent.toString(), + query.getQueryBuilder().getParentQuery().getQuery().toString()); + assertEquals( + "result type should be cvlan-tag", + "cvlan-tag", + query.getResultType()); + assertEquals( + "result type should be port-group", + "port-group", + query.getParentResultType()); + assertEquals( + "contaner type should be empty", + "", + query.getContainerType()); + assertEquals("dependent",true, query.isDependent()); } - /** - * Gets the all. - * - * @return the all - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test + /** + * Gets the all. + * + * @return the all + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test public void getAll() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags").build(); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() - .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"); - GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() - .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.toString(), - expected.toString(), - query.getQueryBuilder().getQuery().toString()); - assertEquals( - "parent gremlin query should be equal the query for port group", - expectedParent.toString(), - query.getQueryBuilder().getParentQuery().getQuery().toString()); - assertEquals( - "result type should be port-group", - "port-group", - query.getParentResultType()); - assertEquals( - "result type should be cvlan-tag", - "cvlan-tag", - query.getResultType()); - assertEquals( - "container type should be cvlan-tags", - "cvlan-tags", - query.getContainerType()); - assertEquals("dependent",true, query.isDependent()); + URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags").build(); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() + .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"); + GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() + .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.toString(), + expected.toString(), + query.getQueryBuilder().getQuery().toString()); + assertEquals( + "parent gremlin query should be equal the query for port group", + expectedParent.toString(), + query.getQueryBuilder().getParentQuery().getQuery().toString()); + assertEquals( + "result type should be port-group", + "port-group", + query.getParentResultType()); + assertEquals( + "result type should be cvlan-tag", + "cvlan-tag", + query.getResultType()); + assertEquals( + "container type should be cvlan-tags", + "cvlan-tags", + query.getContainerType()); + assertEquals("dependent",true, query.isDependent()); } - @Test + @Test public void getAllParent() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers").build(); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() - .has("aai-node-type", "pserver"); - GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() - .has("aai-node-type", "pserver"); - assertEquals( - "gremlin query should be " + expected.toString(), - expected.toString(), - query.getQueryBuilder().getQuery().toString()); - assertEquals( - "parent gremlin query should be equal the query for pserver", - expectedParent.toString(), - query.getQueryBuilder().getParentQuery().getQuery().toString()); - assertEquals( - "parent result type should be empty", - "", - query.getParentResultType()); - assertEquals( - "result type should be pserver", - "pserver", - query.getResultType()); - assertEquals( - "container type should be pservers", - "pservers", - query.getContainerType()); - assertEquals("dependent",false, query.isDependent()); + URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers").build(); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() + .has("aai-node-type", "pserver"); + GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() + .has("aai-node-type", "pserver"); + assertEquals( + "gremlin query should be " + expected.toString(), + expected.toString(), + query.getQueryBuilder().getQuery().toString()); + assertEquals( + "parent gremlin query should be equal the query for pserver", + expectedParent.toString(), + query.getQueryBuilder().getParentQuery().getQuery().toString()); + assertEquals( + "parent result type should be empty", + "", + query.getParentResultType()); + assertEquals( + "result type should be pserver", + "pserver", + query.getResultType()); + assertEquals( + "container type should be pservers", + "pservers", + query.getContainerType()); + assertEquals("dependent",false, query.isDependent()); + + + } + + + /** + * Gets the via query param. + * + * @return the via query param + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test + public void getViaQueryParam() throws UnsupportedEncodingException, AAIException { + URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant").build(); + MultivaluedMap<String, String> map = new MultivaluedHashMap<>(); + map.putSingle("tenant-name", "Tenant1"); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map); + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() + .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid") + .has("aai-node-type", "cloud-region") + .in("org.onap.relationships.inventory.BelongsTo") + .has("aai-node-type", "tenant") + .has("tenant-name", "Tenant1"); + + GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() + .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid") + .has("aai-node-type", "cloud-region"); + + assertEquals( + "gremlin query should be " + expected.toString(), + expected.toString(), + query.getQueryBuilder().getQuery().toString()); + assertEquals( + "parent gremlin query should be equal the query for cloud-region", + expectedParent.toString(), + query.getQueryBuilder().getParentQuery().getQuery().toString()); + assertEquals( + "result type should be cloud-region", + "cloud-region", + query.getParentResultType()); + assertEquals( + "result type should be tenant", + "tenant", + query.getResultType()); + assertEquals( + "container type should be empty", + "", + query.getContainerType()); + assertEquals("dependent",true, query.isDependent()); + } + + @Test + public void getViaDuplicateQueryParam() throws UnsupportedEncodingException, AAIException { + URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant").build(); + MultivaluedMap<String, String> map = new MultivaluedHashMap<>(); + List<String> values = new ArrayList<>(); + values.add("Tenant1"); + values.add("Tenant2"); + map.put("tenant-name", values); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map); + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() + .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid") + .has("aai-node-type", "cloud-region") + .in("org.onap.relationships.inventory.BelongsTo") + .has("aai-node-type", "tenant") + .has("tenant-name", P.within(values)); + + GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() + .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid") + .has("aai-node-type", "cloud-region"); + + assertEquals( + "gremlin query should be " + expected.toString(), + expected.toString(), + query.getQueryBuilder().getQuery().toString()); + assertEquals( + "parent gremlin query should be equal the query for cloud-region", + expectedParent.toString(), + query.getQueryBuilder().getParentQuery().getQuery().toString()); + assertEquals( + "result type should be cloud-region", + "cloud-region", + query.getParentResultType()); + assertEquals( + "result type should be tenant", + "tenant", + query.getResultType()); + assertEquals( + "container type should be empty", + "", + query.getContainerType()); + assertEquals("dependent",true, query.isDependent()); } + /** + * Gets the plural via query param. + * + * @return the plural via query param + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test + public void getPluralViaQueryParam() throws UnsupportedEncodingException, AAIException { + URI uri = UriBuilder.fromPath("network/vnfcs").build(); + MultivaluedMap<String, String> map = new MultivaluedHashMap<>(); + map.putSingle("prov-status", "up"); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map); + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() + .has("aai-node-type", "vnfc") + .has("prov-status", "up"); + + GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() + .has("aai-node-type", "vnfc"); + + assertEquals( + "gremlin query should be " + expected.toString(), + expected.toString(), + query.getQueryBuilder().getQuery().toString()); + assertEquals( + "parent", + expectedParent.toString(), + query.getQueryBuilder().getParentQuery().getQuery().toString()); + assertEquals( + "parent result type should be empty", + "", + query.getParentResultType()); + assertEquals( + "result type should be vnfc", + "vnfc", + query.getResultType()); + assertEquals( + "container type should be empty", + "vnfcs", + query.getContainerType()); + assertEquals("dependent",true, query.isDependent()); - /** - * Gets the via query param. - * - * @return the via query param - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test - public void getViaQueryParam() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant").build(); - MultivaluedMap<String, String> map = new MultivaluedHashMap<>(); - map.putSingle("tenant-name", "Tenant1"); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map); - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() - .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid") - .has("aai-node-type", "cloud-region") - .in("org.onap.relationships.inventory.BelongsTo") - .has("aai-node-type", "tenant") - .has("tenant-name", "Tenant1"); - - GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() - .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid") - .has("aai-node-type", "cloud-region"); - - assertEquals( - "gremlin query should be " + expected.toString(), - expected.toString(), - query.getQueryBuilder().getQuery().toString()); - assertEquals( - "parent gremlin query should be equal the query for cloud-region", - expectedParent.toString(), - query.getQueryBuilder().getParentQuery().getQuery().toString()); - assertEquals( - "result type should be cloud-region", - "cloud-region", - query.getParentResultType()); - assertEquals( - "result type should be tenant", - "tenant", - query.getResultType()); - assertEquals( - "container type should be empty", - "", - query.getContainerType()); - assertEquals("dependent",true, query.isDependent()); - - } - - @Test - public void getViaDuplicateQueryParam() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant").build(); - MultivaluedMap<String, String> map = new MultivaluedHashMap<>(); - List<String> values = new ArrayList<>(); - values.add("Tenant1"); - values.add("Tenant2"); - map.put("tenant-name", values); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map); - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() - .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid") - .has("aai-node-type", "cloud-region") - .in("org.onap.relationships.inventory.BelongsTo") - .has("aai-node-type", "tenant") - .has("tenant-name", P.within(values)); - - GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() - .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid") - .has("aai-node-type", "cloud-region"); - - assertEquals( - "gremlin query should be " + expected.toString(), - expected.toString(), - query.getQueryBuilder().getQuery().toString()); - assertEquals( - "parent gremlin query should be equal the query for cloud-region", - expectedParent.toString(), - query.getQueryBuilder().getParentQuery().getQuery().toString()); - assertEquals( - "result type should be cloud-region", - "cloud-region", - query.getParentResultType()); - assertEquals( - "result type should be tenant", - "tenant", - query.getResultType()); - assertEquals( - "container type should be empty", - "", - query.getContainerType()); - assertEquals("dependent",true, query.isDependent()); - - } - - /** - * Gets the plural via query param. - * - * @return the plural via query param - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test - public void getPluralViaQueryParam() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("network/vnfcs").build(); - MultivaluedMap<String, String> map = new MultivaluedHashMap<>(); - map.putSingle("prov-status", "up"); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map); - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() - .has("aai-node-type", "vnfc") - .has("prov-status", "up"); - - GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() - .has("aai-node-type", "vnfc"); - - assertEquals( - "gremlin query should be " + expected.toString(), - expected.toString(), - query.getQueryBuilder().getQuery().toString()); - assertEquals( - "parent", - expectedParent.toString(), - query.getQueryBuilder().getParentQuery().getQuery().toString()); - assertEquals( - "parent result type should be empty", - "", - query.getParentResultType()); - assertEquals( - "result type should be vnfc", - "vnfc", - query.getResultType()); - assertEquals( - "container type should be empty", - "vnfcs", - query.getContainerType()); - assertEquals("dependent",true, query.isDependent()); - - } - - /** - * Gets the all query param naming exception. - * - * @return the all query param naming exception - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test + } + + /** + * Gets the all query param naming exception. + * + * @return the all query param naming exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test public void getAllQueryParamNamingException() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags").build(); - MultivaluedMap<String, String> map = new MultivaluedHashMap<>(); - map.putSingle("cvlan-tag", "333"); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map); - - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() - .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", 333); - GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() - .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.toString(), - expected.toString(), - query.getQueryBuilder().getQuery().toString()); - assertEquals( - "parent gremlin query should be equal the query for port group", - expectedParent.toString(), - query.getQueryBuilder().getParentQuery().getQuery().toString()); - assertEquals( - "result type should be port-group", - "port-group", - query.getParentResultType()); - assertEquals( - "result type should be cvlan-tag", - "cvlan-tag", - query.getResultType()); - assertEquals( - "container type should be cvlan-tags", - "cvlan-tags", - query.getContainerType()); - assertEquals("dependent",true, query.isDependent()); + URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags").build(); + MultivaluedMap<String, String> map = new MultivaluedHashMap<>(); + map.putSingle("cvlan-tag", "333"); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map); + + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() + .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", 333); + GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() + .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.toString(), + expected.toString(), + query.getQueryBuilder().getQuery().toString()); + assertEquals( + "parent gremlin query should be equal the query for port group", + expectedParent.toString(), + query.getQueryBuilder().getParentQuery().getQuery().toString()); + assertEquals( + "result type should be port-group", + "port-group", + query.getParentResultType()); + assertEquals( + "result type should be cvlan-tag", + "cvlan-tag", + query.getResultType()); + assertEquals( + "container type should be cvlan-tags", + "cvlan-tags", + query.getContainerType()); + assertEquals("dependent",true, query.isDependent()); } - /** - * Abstract type. - * - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test + /** + * Abstract type. + * + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test public void abstractType() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("vnf/key1").build(); - - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); - - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() - .has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf")); - - GraphTraversal<Vertex, Vertex> expectedParent = expected; - assertEquals( - "gremlin query should be " + expected.toString(), - expected.toString(), - query.getQueryBuilder().getQuery().toString()); - assertEquals( - "parent gremlin query should be equal the query for port group", - expectedParent.toString(), - query.getQueryBuilder().getParentQuery().getQuery().toString()); - assertEquals( - "result type should be empty", - "", - query.getParentResultType()); - assertEquals( - "result type should be vnf", - "vnf", - query.getResultType()); - - assertEquals("dependent",false, query.isDependent()); + URI uri = UriBuilder.fromPath("vnf/key1").build(); + + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); + + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() + .has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf")); + + GraphTraversal<Vertex, Vertex> expectedParent = expected; + assertEquals( + "gremlin query should be " + expected.toString(), + expected.toString(), + query.getQueryBuilder().getQuery().toString()); + assertEquals( + "parent gremlin query should be equal the query for port group", + expectedParent.toString(), + query.getQueryBuilder().getParentQuery().getQuery().toString()); + assertEquals( + "result type should be empty", + "", + query.getParentResultType()); + assertEquals( + "result type should be vnf", + "vnf", + query.getResultType()); + + assertEquals("dependent",false, query.isDependent()); } - /** - * Non parent abstract type. - * - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test + /** + * Non parent abstract type. + * + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test public void nonParentAbstractType() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key2/vnf/key1").build(); - thrown.expect(AAIException.class); - thrown.expectMessage(containsString("not a valid path")); - dbEngine.getQueryBuilder().createQueryFromURI(uri); + URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key2/vnf/key1").build(); + thrown.expect(AAIException.class); + thrown.expectMessage(containsString("not a valid path")); + dbEngine.getQueryBuilder().createQueryFromURI(uri); + } + + @Test + public void parentAbstractTypeWithNesting() throws UnsupportedEncodingException, AAIException { + URI uri = UriBuilder.fromPath("vnf/key1/vf-modules/vf-module/key2").build(); + + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); + + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() + .has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf")) + .union(__.in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "vf-module")).has("vf-module-id", "key2"); + + GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() + .has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf")); + assertEquals( + "gremlin query should be " + expected.toString(), + expected.toString(), + query.getQueryBuilder().getQuery().toString()); + assertEquals( + "parent gremlin query should be equal the query for ", + expectedParent.toString(), + query.getQueryBuilder().getParentQuery().getQuery().toString()); + assertEquals( + "result type should be vnf", + "vnf", + query.getParentResultType()); + assertEquals( + "result type should be vf-module", + "vf-module", + query.getResultType()); + + assertEquals("dependent",true, query.isDependent()); + + } + + @Test + public void getViaBadQueryParam() throws UnsupportedEncodingException, AAIException { + URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/a/b/tenants/tenant").build(); + MultivaluedMap<String, String> map = new MultivaluedHashMap<>(); + map.putSingle("tenant-n231ame", "Tenant1"); + thrown.expect(AAIException.class); + thrown.expect(hasProperty("code", is("AAI_3000"))); + + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map); + + } + + @Test + public void getPluralViaBadQueryParam() throws UnsupportedEncodingException, AAIException { + URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/a/b/tenants").build(); + MultivaluedMap<String, String> map = new MultivaluedHashMap<>(); + map.putSingle("tenant-n231ame", "Tenant1"); + thrown.expect(AAIException.class); + thrown.expect(hasProperty("code", is("AAI_3000"))); + + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map); + + } + + @Test + public void getPluralViaDuplicateQueryParam() throws UnsupportedEncodingException, AAIException { + URI uri = UriBuilder.fromPath("network/vnfcs").build(); + MultivaluedMap<String, String> map = new MultivaluedHashMap<>(); + List<String> values = new ArrayList<>(); + values.add("up"); + values.add("down"); + values.add("left"); + values.add("right"); + values.add("start"); + map.put("prov-status", values); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map); + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() + .has("aai-node-type", "vnfc") + .has("prov-status", P.within(values)); + + GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() + .has("aai-node-type", "vnfc"); + + assertEquals( + "gremlin query should be " + expected.toString(), + expected.toString(), + query.getQueryBuilder().getQuery().toString()); + assertEquals( + "parent", + expectedParent.toString(), + query.getQueryBuilder().getParentQuery().getQuery().toString()); + assertEquals( + "parent result type should be empty", + "", + query.getParentResultType()); + assertEquals( + "result type should be vnfc", + "vnfc", + query.getResultType()); + assertEquals( + "container type should be empty", + "vnfcs", + query.getContainerType()); + assertEquals("dependent",true, query.isDependent()); + + } + + @Test + public void dbAliasedSearch() throws UnsupportedEncodingException, AAIException { + URI uri = UriBuilder.fromPath("network/generic-vnfs").build(); + MultivaluedMap<String, String> map = new MultivaluedHashMap<>(); + map.putSingle("persona-model-customization-id", "key2"); + QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri, map); + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() + .has("aai-node-type", "generic-vnf") + .has("model-customization-id", "key2"); + GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() + .has("aai-node-type", "generic-vnf"); + + assertEquals( + "gremlin query should be " + expected.toString(), + expected.toString(), + query.getQueryBuilder().getQuery().toString()); + assertEquals( + "parent", + expectedParent.toString(), + query.getQueryBuilder().getParentQuery().getQuery().toString()); + + assertEquals( + "result type should be", + "generic-vnf", + query.getResultType()); + assertEquals( + "result type should be empty", + "", + query.getParentResultType()); + assertEquals("dependent",true, query.isDependent()); + + + } + + @Test + public void dataLinkedSearch() throws UnsupportedEncodingException, AAIException { + URI uri = UriBuilder.fromPath("network/vpn-bindings").build(); + MultivaluedMap<String, String> map = new MultivaluedHashMap<>(); + map.putSingle("global-route-target", "key2"); + QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri, map); + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() + .has("aai-node-type", "vpn-binding") + .where(__.in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "key2")); + GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() + .has("aai-node-type", "vpn-binding"); + + assertEquals( + "gremlin query should be " + expected.toString(), + expected.toString(), + query.getQueryBuilder().getQuery().toString()); + assertEquals( + "parent", + expectedParent.toString(), + query.getQueryBuilder().getParentQuery().getQuery().toString()); + + assertEquals( + "result type should be", + "vpn-binding", + query.getResultType()); + assertEquals( + "result type should be empty", + "", + query.getParentResultType()); + assertEquals("dependent",true, query.isDependent()); + } + + @Test + public void pluralCousin() throws UnsupportedEncodingException, AAIException { + URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers").build(); + + QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri); + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() + .has("physical-location-id", "key1") + .has("aai-node-type", "complex") + .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver"); + GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() + .has("physical-location-id", "key1") + .has("aai-node-type", "complex"); + + assertEquals( + "gremlin query should be " + expected.toString(), + expected.toString(), + query.getQueryBuilder().getQuery().toString()); + assertEquals( + "parent", + expectedParent.toString(), + query.getQueryBuilder().getParentQuery().getQuery().toString()); + + assertEquals( + "result type should be", + "pserver", + query.getResultType()); + assertEquals( + "result type should be", + "complex", + query.getParentResultType()); + //this is controversial but we're not allowing writes on this currently + assertEquals("dependent",true, query.isDependent()); } - @Test - public void parentAbstractTypeWithNesting() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("vnf/key1/vf-modules/vf-module/key2").build(); - - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); - - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() - .has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf")) - .union(__.in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "vf-module")).has("vf-module-id", "key2"); - - GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() - .has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf")); - assertEquals( - "gremlin query should be " + expected.toString(), - expected.toString(), - query.getQueryBuilder().getQuery().toString()); - assertEquals( - "parent gremlin query should be equal the query for ", - expectedParent.toString(), - query.getQueryBuilder().getParentQuery().getQuery().toString()); - assertEquals( - "result type should be vnf", - "vnf", - query.getParentResultType()); - assertEquals( - "result type should be vf-module", - "vf-module", - query.getResultType()); - - assertEquals("dependent",true, query.isDependent()); - - } - - @Test - public void getViaBadQueryParam() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/a/b/tenants/tenant").build(); - MultivaluedMap<String, String> map = new MultivaluedHashMap<>(); - map.putSingle("tenant-n231ame", "Tenant1"); - thrown.expect(AAIException.class); - thrown.expect(hasProperty("code", is("AAI_3000"))); - - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map); - - } - - @Test - public void getPluralViaBadQueryParam() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/a/b/tenants").build(); - MultivaluedMap<String, String> map = new MultivaluedHashMap<>(); - map.putSingle("tenant-n231ame", "Tenant1"); - thrown.expect(AAIException.class); - thrown.expect(hasProperty("code", is("AAI_3000"))); - - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map); - - } - - @Test - public void getPluralViaDuplicateQueryParam() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("network/vnfcs").build(); - MultivaluedMap<String, String> map = new MultivaluedHashMap<>(); - List<String> values = new ArrayList<>(); - values.add("up"); - values.add("down"); - values.add("left"); - values.add("right"); - values.add("start"); - map.put("prov-status", values); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map); - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() - .has("aai-node-type", "vnfc") - .has("prov-status", P.within(values)); - - GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() - .has("aai-node-type", "vnfc"); - - assertEquals( - "gremlin query should be " + expected.toString(), - expected.toString(), - query.getQueryBuilder().getQuery().toString()); - assertEquals( - "parent", - expectedParent.toString(), - query.getQueryBuilder().getParentQuery().getQuery().toString()); - assertEquals( - "parent result type should be empty", - "", - query.getParentResultType()); - assertEquals( - "result type should be vnfc", - "vnfc", - query.getResultType()); - assertEquals( - "container type should be empty", - "vnfcs", - query.getContainerType()); - assertEquals("dependent",true, query.isDependent()); - - } - - @Test - public void dbAliasedSearch() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("network/generic-vnfs").build(); - MultivaluedMap<String, String> map = new MultivaluedHashMap<>(); - map.putSingle("persona-model-customization-id", "key2"); - QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri, map); - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() - .has("aai-node-type", "generic-vnf") - .has("model-customization-id", "key2"); - GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() - .has("aai-node-type", "generic-vnf"); - - assertEquals( - "gremlin query should be " + expected.toString(), - expected.toString(), - query.getQueryBuilder().getQuery().toString()); - assertEquals( - "parent", - expectedParent.toString(), - query.getQueryBuilder().getParentQuery().getQuery().toString()); - - assertEquals( - "result type should be", - "generic-vnf", - query.getResultType()); - assertEquals( - "result type should be empty", - "", - query.getParentResultType()); - assertEquals("dependent",true, query.isDependent()); - - - } - - @Test - public void dataLinkedSearch() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("network/vpn-bindings").build(); - MultivaluedMap<String, String> map = new MultivaluedHashMap<>(); - map.putSingle("global-route-target", "key2"); - QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri, map); - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() - .has("aai-node-type", "vpn-binding") - .where(__.in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "key2")); - GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() - .has("aai-node-type", "vpn-binding"); - - assertEquals( - "gremlin query should be " + expected.toString(), - expected.toString(), - query.getQueryBuilder().getQuery().toString()); - assertEquals( - "parent", - expectedParent.toString(), - query.getQueryBuilder().getParentQuery().getQuery().toString()); - - assertEquals( - "result type should be", - "vpn-binding", - query.getResultType()); - assertEquals( - "result type should be empty", - "", - query.getParentResultType()); - assertEquals("dependent",true, query.isDependent()); - } - - @Test - public void pluralCousin() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers").build(); - - QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri); - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() - .has("physical-location-id", "key1") - .has("aai-node-type", "complex") - .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver"); - GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() - .has("physical-location-id", "key1") - .has("aai-node-type", "complex"); - - assertEquals( - "gremlin query should be " + expected.toString(), - expected.toString(), - query.getQueryBuilder().getQuery().toString()); - assertEquals( - "parent", - expectedParent.toString(), - query.getQueryBuilder().getParentQuery().getQuery().toString()); - - assertEquals( - "result type should be", - "pserver", - query.getResultType()); - assertEquals( - "result type should be", - "complex", - query.getParentResultType()); - //this is controversial but we're not allowing writes on this currently - assertEquals("dependent",true, query.isDependent()); - } - - @Test - public void specificCousin() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers/pserver/key2").build(); - - QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri); - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() - .has("physical-location-id", "key1") - .has("aai-node-type", "complex") - .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver") - .has("hostname", "key2"); - GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() - .has("physical-location-id", "key1") - .has("aai-node-type", "complex"); - - assertEquals( - "gremlin query should be " + expected.toString(), - expected.toString(), - query.getQueryBuilder().getQuery().toString()); - assertEquals( - "parent", - expectedParent.toString(), - query.getQueryBuilder().getParentQuery().getQuery().toString()); - - assertEquals( - "result type should be", - "pserver", - query.getResultType()); - assertEquals( - "result type should be", - "complex", - query.getParentResultType()); - //this is controversial but we're not allowing writes on this currently - assertEquals("dependent",true, query.isDependent()); - } - - @Test - public void doubleSpecificCousin() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers/pserver/key2/related-to/vservers/vserver/key3").build(); - - QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri); - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() - .has("physical-location-id", "key1") - .has("aai-node-type", "complex") - .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver") - .has("hostname", "key2") - .in("tosca.relationships.HostedOn").has("aai-node-type", "vserver") - .has("vserver-id", "key3"); - GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() - .has("physical-location-id", "key1") - .has("aai-node-type", "complex") - .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver") - .has("hostname", "key2"); - - assertEquals( - "gremlin query should be " + expected.toString(), - expected.toString(), - query.getQueryBuilder().getQuery().toString()); - assertEquals( - "parent", - expectedParent.toString(), - query.getQueryBuilder().getParentQuery().getQuery().toString()); - - assertEquals( - "result type should be", - "vserver", - query.getResultType()); - assertEquals( - "result type should be", - "pserver", - query.getParentResultType()); - //this is controversial but we're not allowing writes on this currently - assertEquals("dependent",true, query.isDependent()); - } - - @Test - public void traversalEndsInRelatedTo() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to").build(); - - thrown.expect(AAIException.class); - thrown.expectMessage(containsString(RestTokens.COUSIN.toString())); - QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri); - - } - - @Test - public void pluralCousinToPluralCousin() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/related-to/pservers").build(); - - thrown.expect(AAIException.class); - thrown.expectMessage(containsString("chain plurals")); - QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri); - - } + @Test + public void specificCousin() throws UnsupportedEncodingException, AAIException { + URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers/pserver/key2").build(); + + QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri); + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() + .has("physical-location-id", "key1") + .has("aai-node-type", "complex") + .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver") + .has("hostname", "key2"); + GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() + .has("physical-location-id", "key1") + .has("aai-node-type", "complex"); + + assertEquals( + "gremlin query should be " + expected.toString(), + expected.toString(), + query.getQueryBuilder().getQuery().toString()); + assertEquals( + "parent", + expectedParent.toString(), + query.getQueryBuilder().getParentQuery().getQuery().toString()); + + assertEquals( + "result type should be", + "pserver", + query.getResultType()); + assertEquals( + "result type should be", + "complex", + query.getParentResultType()); + //this is controversial but we're not allowing writes on this currently + assertEquals("dependent",true, query.isDependent()); + } + + @Test + public void doubleSpecificCousin() throws UnsupportedEncodingException, AAIException { + URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers/pserver/key2/related-to/vservers/vserver/key3").build(); + + QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri); + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start() + .has("physical-location-id", "key1") + .has("aai-node-type", "complex") + .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver") + .has("hostname", "key2") + .in("tosca.relationships.HostedOn").has("aai-node-type", "vserver") + .has("vserver-id", "key3"); + GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start() + .has("physical-location-id", "key1") + .has("aai-node-type", "complex") + .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver") + .has("hostname", "key2"); + + assertEquals( + "gremlin query should be " + expected.toString(), + expected.toString(), + query.getQueryBuilder().getQuery().toString()); + assertEquals( + "parent", + expectedParent.toString(), + query.getQueryBuilder().getParentQuery().getQuery().toString()); + + assertEquals( + "result type should be", + "vserver", + query.getResultType()); + assertEquals( + "result type should be", + "pserver", + query.getParentResultType()); + //this is controversial but we're not allowing writes on this currently + assertEquals("dependent",true, query.isDependent()); + } + + @Test + public void traversalEndsInRelatedTo() throws UnsupportedEncodingException, AAIException { + URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to").build(); + + thrown.expect(AAIException.class); + thrown.expectMessage(containsString(RestTokens.COUSIN.toString())); + QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri); + + } + + @Test + public void pluralCousinToPluralCousin() throws UnsupportedEncodingException, AAIException { + URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/related-to/pservers").build(); + + thrown.expect(AAIException.class); + thrown.expectMessage(containsString("chain plurals")); + QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri); + + } } diff --git a/aai-core/src/test/java/org/onap/aai/parsers/query/LegacyQueryTest.java b/aai-core/src/test/java/org/onap/aai/parsers/query/LegacyQueryTest.java index 376b7933..8272f775 100644 --- a/aai-core/src/test/java/org/onap/aai/parsers/query/LegacyQueryTest.java +++ b/aai-core/src/test/java/org/onap/aai/parsers/query/LegacyQueryTest.java @@ -43,116 +43,116 @@ import static org.junit.Assert.assertEquals; public class LegacyQueryTest extends AAISetup { - private TransactionalGraphEngine dbEngine; - private SchemaVersion version; - private DynamicJAXBContext context = nodeIngestor.getContextForVersion(version); + private TransactionalGraphEngine dbEngine; + private SchemaVersion version; + private DynamicJAXBContext context = nodeIngestor.getContextForVersion(version); - public void setup(){ - version = new SchemaVersion("v10"); - dbEngine = - new JanusGraphDBEngine(QueryStyle.GREMLIN_TRAVERSAL, - loaderFactory.createLoaderForVersion(ModelType.MOXY, version), - false); - } + 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 + /** + * 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 { - - URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1").build(); + + URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1").build(); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); - 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 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 { - URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1/lag-interfaces/lag-interface/key2").build(); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); + URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1/lag-interfaces/lag-interface/key2").build(); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); - String expected = - ".has('hostname', 'key1').has('aai-node-type', 'pserver')" - + ".out('hasLAGInterface').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 expected = + ".has('hostname', 'key1').has('aai-node-type', 'pserver')" + + ".out('hasLAGInterface').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 { - URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build(); - - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); - 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()); - + URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build(); + + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); + 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()); + } - + } 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); + + } } diff --git a/aai-core/src/test/java/org/onap/aai/parsers/query/RelationshipQueryTest.java b/aai-core/src/test/java/org/onap/aai/parsers/query/RelationshipQueryTest.java index 4baa944b..71089c6b 100644 --- a/aai-core/src/test/java/org/onap/aai/parsers/query/RelationshipQueryTest.java +++ b/aai-core/src/test/java/org/onap/aai/parsers/query/RelationshipQueryTest.java @@ -45,231 +45,231 @@ import static org.junit.Assert.assertEquals; public class RelationshipQueryTest extends AAISetup { - private TransactionalGraphEngine dbEngine; - private SchemaVersion version; - private DynamicJAXBContext context = nodeIngestor.getContextForVersion(version); - - @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 + private TransactionalGraphEngine dbEngine; + private SchemaVersion version; + private DynamicJAXBContext context = nodeIngestor.getContextForVersion(version); + + @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 - */ - @Ignore - @Test + /** + * Child query. + * + * @throws JAXBException the JAXB exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Ignore + @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').out('hasLAGInterface').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').out('hasLAGInterface').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 - */ - @Ignore - @Test + /** + * Naming exceptions. + * + * @throws JAXBException the JAXB exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Ignore + @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()); } - /** - * Double key. - * - * @throws JAXBException the JAXB exception - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Ignore - @Test + /** + * Double key. + * + * @throws JAXBException the JAXB exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Ignore + @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()); } diff --git a/aai-core/src/test/java/org/onap/aai/parsers/query/UniqueRelationshipQueryTest.java b/aai-core/src/test/java/org/onap/aai/parsers/query/UniqueRelationshipQueryTest.java index 10174b69..319f0b88 100644 --- a/aai-core/src/test/java/org/onap/aai/parsers/query/UniqueRelationshipQueryTest.java +++ b/aai-core/src/test/java/org/onap/aai/parsers/query/UniqueRelationshipQueryTest.java @@ -49,253 +49,253 @@ import static org.junit.Assert.assertEquals; @Ignore public class UniqueRelationshipQueryTest extends AAISetup { - @Autowired - private NodeIngestor ingestor ; - - private TransactionalGraphEngine dbEngine; - private SchemaVersion version ; - private DynamicJAXBContext context = ingestor.getContextForVersion(version); - private Unmarshaller unmarshaller = null; - - /** - * Setup. - * - * @throws JAXBException the JAXB exception - */ - @Before - public void setup() throws JAXBException { - version = new SchemaVersion("v10"); - dbEngine = new JanusGraphDBEngine(QueryStyle.GREMLIN_UNIQUE, - loaderFactory.createLoaderForVersion(ModelType.MOXY, version), - false); - 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); - } - - /** - * Parent query. - * - * @throws JAXBException the JAXB exception - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test + @Autowired + private NodeIngestor ingestor ; + + private TransactionalGraphEngine dbEngine; + private SchemaVersion version ; + private DynamicJAXBContext context = ingestor.getContextForVersion(version); + private Unmarshaller unmarshaller = null; + + /** + * Setup. + * + * @throws JAXBException the JAXB exception + */ + @Before + public void setup() throws JAXBException { + version = new SchemaVersion("v10"); + dbEngine = new JanusGraphDBEngine(QueryStyle.GREMLIN_UNIQUE, + loaderFactory.createLoaderForVersion(ModelType.MOXY, version), + false); + 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); + } + + /** + * 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\"" - + "}]" - + "}"; + String content = + "{" + + "\"related-to\" : \"pserver\"," + + "\"relationship-data\" : [{" + + "\"relationship-key\" : \"pserver.hostname\"," + + "\"relationship-value\" : \"key1\"" + + "}]" + + "}"; - Object obj = context.newDynamicEntity("Relationship"); + Object obj = context.newDynamicEntity("Relationship"); - DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue(); + 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 key = "pserver/key1"; - GraphTraversal<Vertex, Vertex> expected = - __.<Vertex>start().has("aai-unique-key", key); - String resultType = "pserver"; - String containerType = ""; + Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj); + String key = "pserver/key1"; + GraphTraversal<Vertex, Vertex> expected = + __.<Vertex>start().has("aai-unique-key", key); + String resultType = "pserver"; + String containerType = ""; - testSet(query, expected, expected, resultType, containerType); + testSet(query, expected, expected, resultType, containerType); } - /** - * 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\"" - + "}]" - + "}"; - - 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 key = "pserver/key1/lag-interface/key2"; - GraphTraversal<Vertex, Vertex> expected = - __.<Vertex>start().has("aai-unique-key", key); - GraphTraversal<Vertex, Vertex> parentExpected = - __.<Vertex>start().has("aai-unique-key", "pserver/key1"); - String resultType = "lag-interface"; - String containerType = ""; - - testSet(query, expected, parentExpected, resultType, containerType); + String content = + "{" + + "\"related-to\" : \"lag-interface\"," + + "\"relationship-data\" : [{" + + "\"relationship-key\" : \"pserver.hostname\"," + + "\"relationship-value\" : \"key1\"" + + "}, {" + + "\"relationship-key\" : \"lag-interface.interface-name\"," + + "\"relationship-value\" : \"key2\"" + + "}]" + + "}"; + + 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 key = "pserver/key1/lag-interface/key2"; + GraphTraversal<Vertex, Vertex> expected = + __.<Vertex>start().has("aai-unique-key", key); + GraphTraversal<Vertex, Vertex> parentExpected = + __.<Vertex>start().has("aai-unique-key", "pserver/key1"); + String resultType = "lag-interface"; + String containerType = ""; + + testSet(query, expected, parentExpected, resultType, containerType); } - /** - * 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\"" - + "}]" - + "}"; - - 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 key = "vce/key1/port-group/key2/cvlan-tag/655"; - GraphTraversal<Vertex, Vertex> expected = - __.<Vertex>start().has("aai-unique-key", key); - GraphTraversal<Vertex, Vertex> parentExpected = - __.<Vertex>start().has("aai-unique-key", "vce/key1/port-group/key2"); - String resultType = "cvlan-tag"; - String containerType = ""; - - testSet(query, expected, parentExpected, resultType, containerType); + 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\"" + + "}]" + + "}"; + + 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 key = "vce/key1/port-group/key2/cvlan-tag/655"; + GraphTraversal<Vertex, Vertex> expected = + __.<Vertex>start().has("aai-unique-key", key); + GraphTraversal<Vertex, Vertex> parentExpected = + __.<Vertex>start().has("aai-unique-key", "vce/key1/port-group/key2"); + String resultType = "cvlan-tag"; + String containerType = ""; + + testSet(query, expected, parentExpected, resultType, containerType); } - /** - * 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\" : \"service-capability\"," - + "\"relationship-data\" : [{" - + "\"relationship-key\" : \"service-capability.service-type\"," - + "\"relationship-value\" : \"key1\"" - + " }, { " - + "\"relationship-key\" : \"service-capability.vnf-type\"," - + " \"relationship-value\" : \"key2\"" - + " }]" - + "}"; - - 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 key = "service-capability/key1/key2"; - GraphTraversal<Vertex, Vertex> expected = - __.<Vertex>start().has("aai-unique-key", key); - GraphTraversal<Vertex, Vertex> parentExpected = - __.<Vertex>start().has("aai-unique-key", "service-capability/key1/key2"); - String resultType = "service-capability"; - String containerType = ""; - - testSet(query, expected, parentExpected, resultType, containerType); + String content = + "{" + + "\"related-to\" : \"service-capability\"," + + "\"relationship-data\" : [{" + + "\"relationship-key\" : \"service-capability.service-type\"," + + "\"relationship-value\" : \"key1\"" + + " }, { " + + "\"relationship-key\" : \"service-capability.vnf-type\"," + + " \"relationship-value\" : \"key2\"" + + " }]" + + "}"; + + 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 key = "service-capability/key1/key2"; + GraphTraversal<Vertex, Vertex> expected = + __.<Vertex>start().has("aai-unique-key", key); + GraphTraversal<Vertex, Vertex> parentExpected = + __.<Vertex>start().has("aai-unique-key", "service-capability/key1/key2"); + String resultType = "service-capability"; + String containerType = ""; + + testSet(query, expected, parentExpected, resultType, containerType); } - /** - * 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.hostname\"," - + "\"relationship-value\" : \"key1\"" - + "}, {" - + "\"relationship-key\" : \"port-group.interface-name\"," - + "\"relationship-value\" : \"key2\"" - + "},{" - + "\"relationship-key\" : \"cvlan-tag.-name\"," - + "\"relationship-value\" : \"655\"" - + "}]" - + "}"; - - 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 key = "vce/key1/port-group/key2/cvlan-tag/655"; - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key); - GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key", "vce/key1/port-group/key2"); - String resultType = "cvlan-tag"; - String containerType = ""; - - testSet(query, expected, parentExpected, resultType, containerType); + 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.hostname\"," + + "\"relationship-value\" : \"key1\"" + + "}, {" + + "\"relationship-key\" : \"port-group.interface-name\"," + + "\"relationship-value\" : \"key2\"" + + "},{" + + "\"relationship-key\" : \"cvlan-tag.-name\"," + + "\"relationship-value\" : \"655\"" + + "}]" + + "}"; + + 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 key = "vce/key1/port-group/key2/cvlan-tag/655"; + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key); + GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key", "vce/key1/port-group/key2"); + String resultType = "cvlan-tag"; + String containerType = ""; + + testSet(query, expected, parentExpected, resultType, containerType); } - /** - * Test set. - * - * @param query the query - * @param expected the expected - * @param parentExpected the parent expected - * @param resultType the result type - * @param containerType the container type - */ - public void testSet(QueryParser query, GraphTraversal<Vertex, Vertex> expected, GraphTraversal<Vertex, Vertex> parentExpected, String resultType, String containerType) { - assertEquals( - "gremlin query should be " + expected, - expected, - query.getQueryBuilder().getQuery()); - assertEquals( - "parent gremlin query should be " + parentExpected, - parentExpected, - query.getParentQueryBuilder().getParentQuery()); - assertEquals( - "result type should be " + resultType, - resultType, - query.getResultType()); - assertEquals( - "container type should be " + containerType, - containerType, - query.getContainerType()); - } + /** + * Test set. + * + * @param query the query + * @param expected the expected + * @param parentExpected the parent expected + * @param resultType the result type + * @param containerType the container type + */ + public void testSet(QueryParser query, GraphTraversal<Vertex, Vertex> expected, GraphTraversal<Vertex, Vertex> parentExpected, String resultType, String containerType) { + assertEquals( + "gremlin query should be " + expected, + expected, + query.getQueryBuilder().getQuery()); + assertEquals( + "parent gremlin query should be " + parentExpected, + parentExpected, + query.getParentQueryBuilder().getParentQuery()); + assertEquals( + "result type should be " + resultType, + resultType, + query.getResultType()); + assertEquals( + "container type should be " + containerType, + containerType, + query.getContainerType()); + } } diff --git a/aai-core/src/test/java/org/onap/aai/parsers/query/UniqueURIQueryTest.java b/aai-core/src/test/java/org/onap/aai/parsers/query/UniqueURIQueryTest.java index a173a37e..631574b4 100644 --- a/aai-core/src/test/java/org/onap/aai/parsers/query/UniqueURIQueryTest.java +++ b/aai-core/src/test/java/org/onap/aai/parsers/query/UniqueURIQueryTest.java @@ -44,150 +44,150 @@ import static org.junit.Assert.assertEquals; public class UniqueURIQueryTest extends AAISetup { - private TransactionalGraphEngine dbEngine; - private SchemaVersion version; - private DynamicJAXBContext context = nodeIngestor.getContextForVersion(version); - - /** - * Parent query. - * - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test + private TransactionalGraphEngine dbEngine; + private SchemaVersion version; + private DynamicJAXBContext context = nodeIngestor.getContextForVersion(version); + + /** + * Parent query. + * + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test public void parentQuery() throws UnsupportedEncodingException, AAIException { - version = new SchemaVersion("v10"); - dbEngine = new JanusGraphDBEngine(QueryStyle.GREMLIN_UNIQUE, - loaderFactory.createLoaderForVersion(ModelType.MOXY, version), - false); - URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1").build(); - String key = "complex/key1"; - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key); - String parentResultType = ""; - String resultType = "complex"; - String containerType = ""; - - testSet(query, expected, expected, parentResultType, resultType, containerType); + version = new SchemaVersion("v10"); + dbEngine = new JanusGraphDBEngine(QueryStyle.GREMLIN_UNIQUE, + loaderFactory.createLoaderForVersion(ModelType.MOXY, version), + false); + URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1").build(); + String key = "complex/key1"; + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key); + String parentResultType = ""; + String resultType = "complex"; + String containerType = ""; + + testSet(query, expected, expected, parentResultType, resultType, containerType); } - /** - * Parent plural query. - * - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test + /** + * Parent plural query. + * + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test public void parentPluralQuery() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes").build(); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-node-type", "complex"); - String parentResultType = ""; - String resultType = "complex"; - String containerType = "complexes"; + URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes").build(); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-node-type", "complex"); + String parentResultType = ""; + String resultType = "complex"; + String containerType = "complexes"; - testSet(query, expected, expected, parentResultType, resultType, containerType); + testSet(query, expected, expected, parentResultType, resultType, containerType); } - /** - * Child query. - * - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test + /** + * Child query. + * + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test public void childQuery() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3").build(); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); - String parentKey = "complex/key1"; - String key = parentKey + "/ctag-pool/key2/key3"; - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key); - GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key", parentKey); - String parentResultType = "complex"; - String resultType = "ctag-pool"; - String containerType = ""; - - testSet(query, expected, parentExpected, parentResultType, resultType, containerType); + URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3").build(); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); + String parentKey = "complex/key1"; + String key = parentKey + "/ctag-pool/key2/key3"; + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key); + GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key", parentKey); + String parentResultType = "complex"; + String resultType = "ctag-pool"; + String containerType = ""; + + testSet(query, expected, parentExpected, parentResultType, resultType, containerType); } - /** - * Naming exceptions. - * - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test + /** + * Naming exceptions. + * + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test public void namingExceptions() throws UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build(); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); - String parentKey = "vce/key1/port-group/key2"; - String key = parentKey + "/cvlan-tag/655"; - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key); - GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key", parentKey); - String parentResultType = "port-group"; - String resultType = "cvlan-tag"; - String containerType = ""; - - testSet(query, expected, parentExpected, parentResultType, resultType, containerType); + URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build(); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); + String parentKey = "vce/key1/port-group/key2"; + String key = parentKey + "/cvlan-tag/655"; + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key); + GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key", parentKey); + String parentResultType = "port-group"; + String resultType = "cvlan-tag"; + String containerType = ""; + + testSet(query, expected, parentExpected, parentResultType, resultType, containerType); } - /** - * Gets the all. - * - * @return the all - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test + /** + * Gets the all. + * + * @return the all + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test public void getAll() throws UnsupportedEncodingException, AAIException { - String parentURI = "network/vces/vce/key1/port-groups/port-group/key2"; - String parentKey = "vce/key1/port-group/key2"; - URI uri = UriBuilder.fromPath(parentURI + "/cvlan-tags").build(); - QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); - GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", parentKey).in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "cvlan-tag"); - GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key",parentKey); - String parentResultType = "port-group"; - String resultType = "cvlan-tag"; - String containerType = "cvlan-tags"; - - testSet(query, expected, parentExpected, parentResultType, resultType, containerType); + String parentURI = "network/vces/vce/key1/port-groups/port-group/key2"; + String parentKey = "vce/key1/port-group/key2"; + URI uri = UriBuilder.fromPath(parentURI + "/cvlan-tags").build(); + QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri); + GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", parentKey).in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "cvlan-tag"); + GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key",parentKey); + String parentResultType = "port-group"; + String resultType = "cvlan-tag"; + String containerType = "cvlan-tags"; + + testSet(query, expected, parentExpected, parentResultType, resultType, containerType); } - /** - * Test set. - * - * @param query the query - * @param expected the expected - * @param parentExpected the parent expected - * @param parentResultType the parent result type - * @param resultType the result type - * @param containerType the container type - */ - public void testSet(QueryParser query, GraphTraversal<Vertex, Vertex> expected, GraphTraversal<Vertex, Vertex> parentExpected, String parentResultType, String resultType, String containerType) { - assertEquals( - "gremlin query should be " + expected, - expected, - query.getQueryBuilder().getQuery()); - assertEquals( - "parent gremlin query should be " + parentExpected, - parentExpected, - query.getQueryBuilder().getParentQuery().getQuery()); - assertEquals( - "parent result type should be " + parentResultType, - parentResultType, - query.getParentResultType()); - assertEquals( - "result type should be " + resultType, - resultType, - query.getResultType()); - assertEquals( - "container type should be " + containerType, - containerType, - query.getContainerType()); - } + /** + * Test set. + * + * @param query the query + * @param expected the expected + * @param parentExpected the parent expected + * @param parentResultType the parent result type + * @param resultType the result type + * @param containerType the container type + */ + public void testSet(QueryParser query, GraphTraversal<Vertex, Vertex> expected, GraphTraversal<Vertex, Vertex> parentExpected, String parentResultType, String resultType, String containerType) { + assertEquals( + "gremlin query should be " + expected, + expected, + query.getQueryBuilder().getQuery()); + assertEquals( + "parent gremlin query should be " + parentExpected, + parentExpected, + query.getQueryBuilder().getParentQuery().getQuery()); + assertEquals( + "parent result type should be " + parentResultType, + parentResultType, + query.getParentResultType()); + assertEquals( + "result type should be " + resultType, + resultType, + query.getResultType()); + assertEquals( + "container type should be " + containerType, + containerType, + query.getContainerType()); + } } diff --git a/aai-core/src/test/java/org/onap/aai/parsers/relationship/RelationshipToURITest.java b/aai-core/src/test/java/org/onap/aai/parsers/relationship/RelationshipToURITest.java index f3b85778..42f1fd44 100644 --- a/aai-core/src/test/java/org/onap/aai/parsers/relationship/RelationshipToURITest.java +++ b/aai-core/src/test/java/org/onap/aai/parsers/relationship/RelationshipToURITest.java @@ -44,154 +44,154 @@ import static org.junit.Assert.assertEquals; @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) public class RelationshipToURITest extends AAISetup { - private final ModelType modelType = ModelType.MOXY; - private final SchemaVersion version10 = new SchemaVersion("v10"); - - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void onlyLink() throws AAIException, URISyntaxException, IOException { - Loader loader = loaderFactory.createLoaderForVersion(modelType, version10); - Introspector obj = loader.unmarshal("relationship", this.getJsonString("only-related-link.json")); - URI expected = new URI("/aai/v10/network/generic-vnfs/generic-vnf/key1"); - - RelationshipToURI parse = new RelationshipToURI(loader, obj); - - URI uri = parse.getUri(); - - assertEquals("related-link is equal", expected.getPath(), uri.getPath()); - } - - @Test - public void onlyData() throws AAIException, URISyntaxException, IOException { - Loader loader = loaderFactory.createLoaderForVersion(modelType, version10); - Introspector obj = loader.unmarshal("relationship", this.getJsonString("only-relationship-data.json")); - URI expected = new URI("/network/generic-vnfs/generic-vnf/key1"); + private final ModelType modelType = ModelType.MOXY; + private final SchemaVersion version10 = new SchemaVersion("v10"); + + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void onlyLink() throws AAIException, URISyntaxException, IOException { + Loader loader = loaderFactory.createLoaderForVersion(modelType, version10); + Introspector obj = loader.unmarshal("relationship", this.getJsonString("only-related-link.json")); + URI expected = new URI("/aai/v10/network/generic-vnfs/generic-vnf/key1"); + + RelationshipToURI parse = new RelationshipToURI(loader, obj); + + URI uri = parse.getUri(); + + assertEquals("related-link is equal", expected.getPath(), uri.getPath()); + } + + @Test + public void onlyData() throws AAIException, URISyntaxException, IOException { + Loader loader = loaderFactory.createLoaderForVersion(modelType, version10); + Introspector obj = loader.unmarshal("relationship", this.getJsonString("only-relationship-data.json")); + URI expected = new URI("/network/generic-vnfs/generic-vnf/key1"); - RelationshipToURI parse = new RelationshipToURI(loader, obj); - - URI uri = parse.getUri(); - - assertEquals("related-link is equal", expected, uri); - } - - @Test - public void failV10() throws AAIException, URISyntaxException, IOException { - Loader loader = loaderFactory.createLoaderForVersion(modelType, version10); - Introspector obj = loader.unmarshal("relationship", this.getJsonString("both-failv10-successv9.json")); - URI expected = new URI("/aai/v10/network/generic-vnfs/generic-vnf/key1"); - - thrown.expect(AAIIdentityMapParseException.class); - thrown.expect(hasProperty("code", is("AAI_3000"))); - RelationshipToURI parse = new RelationshipToURI(loader, obj); - URI uri = parse.getUri(); - - } - - @Test - public void failNothingToParse() throws AAIException, URISyntaxException, IOException { - Loader loader = loaderFactory.createLoaderForVersion(modelType, version10); - Introspector obj = loader.unmarshal("relationship", this.getJsonString("nothing-to-parse.json")); - URI expected = new URI("/aai/v10/network/generic-vnfs/generic-vnf/key1"); - - thrown.expect(AAIIdentityMapParseException.class); - thrown.expect(hasProperty("code", is("AAI_3000"))); - RelationshipToURI parse = new RelationshipToURI(loader, obj); - - URI uri = parse.getUri(); - - } - - @Test - public void successV10() throws AAIException, URISyntaxException, IOException { - Loader loader = loaderFactory.createLoaderForVersion(modelType, version10); - Introspector obj = loader.unmarshal("relationship", this.getJsonString("both-successv10-failv9.json")); - URI expected = new URI("/aai/v10/network/generic-vnfs/generic-vnf/key1"); - - RelationshipToURI parse = new RelationshipToURI(loader, obj); - + RelationshipToURI parse = new RelationshipToURI(loader, obj); + + URI uri = parse.getUri(); + + assertEquals("related-link is equal", expected, uri); + } + + @Test + public void failV10() throws AAIException, URISyntaxException, IOException { + Loader loader = loaderFactory.createLoaderForVersion(modelType, version10); + Introspector obj = loader.unmarshal("relationship", this.getJsonString("both-failv10-successv9.json")); + URI expected = new URI("/aai/v10/network/generic-vnfs/generic-vnf/key1"); + + thrown.expect(AAIIdentityMapParseException.class); + thrown.expect(hasProperty("code", is("AAI_3000"))); + RelationshipToURI parse = new RelationshipToURI(loader, obj); + URI uri = parse.getUri(); + + } + + @Test + public void failNothingToParse() throws AAIException, URISyntaxException, IOException { + Loader loader = loaderFactory.createLoaderForVersion(modelType, version10); + Introspector obj = loader.unmarshal("relationship", this.getJsonString("nothing-to-parse.json")); + URI expected = new URI("/aai/v10/network/generic-vnfs/generic-vnf/key1"); + + thrown.expect(AAIIdentityMapParseException.class); + thrown.expect(hasProperty("code", is("AAI_3000"))); + RelationshipToURI parse = new RelationshipToURI(loader, obj); + + URI uri = parse.getUri(); + + } + + @Test + public void successV10() throws AAIException, URISyntaxException, IOException { + Loader loader = loaderFactory.createLoaderForVersion(modelType, version10); + Introspector obj = loader.unmarshal("relationship", this.getJsonString("both-successv10-failv9.json")); + URI expected = new URI("/aai/v10/network/generic-vnfs/generic-vnf/key1"); + + RelationshipToURI parse = new RelationshipToURI(loader, obj); + - URI uri = parse.getUri(); - - assertEquals("related-link is equal", expected, uri); + URI uri = parse.getUri(); + + assertEquals("related-link is equal", expected, uri); - - } - - @Test - public void ambiguousRelationship() throws AAIException, URISyntaxException, IOException { - Loader loader = loaderFactory.createLoaderForVersion(modelType, version10); - Introspector obj = loader.unmarshal("relationship", this.getJsonString("ambiguous-relationship.json")); - URI expected = new URI("/aai/v10/network/generic-vnfs/generic-vnf/key1"); - - thrown.expect(AmbiguousMapAAIException.class); - thrown.expect(hasProperty("code", is("AAI_6146"))); - - RelationshipToURI parse = new RelationshipToURI(loader, obj); - - URI uri = parse.getUri(); - - assertEquals("related-link is equal", expected, uri); + + } + + @Test + public void ambiguousRelationship() throws AAIException, URISyntaxException, IOException { + Loader loader = loaderFactory.createLoaderForVersion(modelType, version10); + Introspector obj = loader.unmarshal("relationship", this.getJsonString("ambiguous-relationship.json")); + URI expected = new URI("/aai/v10/network/generic-vnfs/generic-vnf/key1"); + + thrown.expect(AmbiguousMapAAIException.class); + thrown.expect(hasProperty("code", is("AAI_6146"))); + + RelationshipToURI parse = new RelationshipToURI(loader, obj); + + URI uri = parse.getUri(); + + assertEquals("related-link is equal", expected, uri); - - } + + } - @Ignore - @Test - public void moreItemsThanRequired() throws AAIException, URISyntaxException, IOException { - Loader loader = loaderFactory.createLoaderForVersion(modelType, version10); - Introspector obj = loader.unmarshal("relationship", this.getJsonString("too-many-items-relationship.json")); - URI expected = new URI("/network/generic-vnfs/generic-vnf/key1/l-interfaces/l-interface/key2"); - - RelationshipToURI parse = new RelationshipToURI(loader, obj); + @Ignore + @Test + public void moreItemsThanRequired() throws AAIException, URISyntaxException, IOException { + Loader loader = loaderFactory.createLoaderForVersion(modelType, version10); + Introspector obj = loader.unmarshal("relationship", this.getJsonString("too-many-items-relationship.json")); + URI expected = new URI("/network/generic-vnfs/generic-vnf/key1/l-interfaces/l-interface/key2"); + + RelationshipToURI parse = new RelationshipToURI(loader, obj); - URI uri = parse.getUri(); - - assertEquals("related-link is equal", expected.toString(), uri.toString()); - - } - - @Test - public void twoTopLevelNodes() throws AAIException, URISyntaxException, IOException { - Loader loader = loaderFactory.createLoaderForVersion(modelType, version10); - Introspector obj = loader.unmarshal("relationship", this.getJsonString("two-top-level-relationship.json")); - URI expected = new URI("/network/generic-vnfs/generic-vnf/key1/l-interfaces/l-interface/key2"); - - thrown.expect(AmbiguousMapAAIException.class); - thrown.expect(hasProperty("code", is("AAI_6146"))); - - RelationshipToURI parse = new RelationshipToURI(loader, obj); - - URI uri = parse.getUri(); - - assertEquals("related-link is equal", expected, uri); - - } - - @Test - public void topLevelWithTwoKeys() throws AAIException, URISyntaxException, IOException { - Loader loader = loaderFactory.createLoaderForVersion(modelType, version10); - Introspector obj = loader.unmarshal("relationship", this.getJsonString("top-level-two-keys-relationship.json")); - URI expected = new URI("/cloud-infrastructure/cloud-regions/cloud-region/key1/key2/availability-zones/availability-zone/key3"); - - RelationshipToURI parse = new RelationshipToURI(loader, obj); - - URI uri = parse.getUri(); - - assertEquals("related-link is equal", expected.toString(), uri.toString()); - - } - - - private String getJsonString(String filename) throws IOException { - - - FileInputStream is = new FileInputStream("src/test/resources/bundleconfig-local/etc/relationship/" + filename); - String s = IOUtils.toString(is, "UTF-8"); - IOUtils.closeQuietly(is); - - return s; - } + URI uri = parse.getUri(); + + assertEquals("related-link is equal", expected.toString(), uri.toString()); + + } + + @Test + public void twoTopLevelNodes() throws AAIException, URISyntaxException, IOException { + Loader loader = loaderFactory.createLoaderForVersion(modelType, version10); + Introspector obj = loader.unmarshal("relationship", this.getJsonString("two-top-level-relationship.json")); + URI expected = new URI("/network/generic-vnfs/generic-vnf/key1/l-interfaces/l-interface/key2"); + + thrown.expect(AmbiguousMapAAIException.class); + thrown.expect(hasProperty("code", is("AAI_6146"))); + + RelationshipToURI parse = new RelationshipToURI(loader, obj); + + URI uri = parse.getUri(); + + assertEquals("related-link is equal", expected, uri); + + } + + @Test + public void topLevelWithTwoKeys() throws AAIException, URISyntaxException, IOException { + Loader loader = loaderFactory.createLoaderForVersion(modelType, version10); + Introspector obj = loader.unmarshal("relationship", this.getJsonString("top-level-two-keys-relationship.json")); + URI expected = new URI("/cloud-infrastructure/cloud-regions/cloud-region/key1/key2/availability-zones/availability-zone/key3"); + + RelationshipToURI parse = new RelationshipToURI(loader, obj); + + URI uri = parse.getUri(); + + assertEquals("related-link is equal", expected.toString(), uri.toString()); + + } + + + private String getJsonString(String filename) throws IOException { + + + FileInputStream is = new FileInputStream("src/test/resources/bundleconfig-local/etc/relationship/" + filename); + String s = IOUtils.toString(is, "UTF-8"); + IOUtils.closeQuietly(is); + + return s; + } } diff --git a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIParserTest.java b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIParserTest.java index 42cfd922..aab124f3 100644 --- a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIParserTest.java +++ b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIParserTest.java @@ -39,67 +39,67 @@ import static org.hamcrest.Matchers.is; public class URIParserTest extends AAISetup { - private Loader loader ; + private Loader loader ; - @Rule - public ExpectedException thrown = ExpectedException.none(); - - /** - * Invalid path. - * - * @throws JAXBException the JAXB exception - * @throws AAIException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - */ - @PostConstruct - public void createLoader(){ - loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, new SchemaVersion("v10")); - } + @Rule + public ExpectedException thrown = ExpectedException.none(); + + /** + * Invalid path. + * + * @throws JAXBException the JAXB exception + * @throws AAIException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + */ + @PostConstruct + public void createLoader(){ + loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, new SchemaVersion("v10")); + } - @Test + @Test public void invalidPath() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException { - URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/network/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build(); - - thrown.expect(AAIException.class); - thrown.expect(hasProperty("code", is("AAI_3001"))); - - new URIToDBKey(loader, uri); - } - - /** - * Invalid path no name space. - * - * @throws JAXBException the JAXB exception - * @throws AAIException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - */ - @Test + URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/network/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build(); + + thrown.expect(AAIException.class); + thrown.expect(hasProperty("code", is("AAI_3001"))); + + new URIToDBKey(loader, uri); + } + + /** + * Invalid path no name space. + * + * @throws JAXBException the JAXB exception + * @throws AAIException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + */ + @Test public void invalidPathNoNameSpace() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException { - URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build(); - - thrown.expect(AAIException.class); - thrown.expect(hasProperty("code", is("AAI_3000"))); - - new URIToDBKey(loader, uri); - } - - /** - * Invalid path partial. - * - * @throws JAXBException the JAXB exception - * @throws AAIException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - */ - @Test + URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build(); + + thrown.expect(AAIException.class); + thrown.expect(hasProperty("code", is("AAI_3000"))); + + new URIToDBKey(loader, uri); + } + + /** + * Invalid path partial. + * + * @throws JAXBException the JAXB exception + * @throws AAIException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + */ + @Test public void invalidPathPartial() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException { - URI uri = UriBuilder.fromPath("vservers/vserver/key2/l-interfaces/l-interface/key3").build(); - - thrown.expect(AAIException.class); - thrown.expect(hasProperty("code", is("AAI_3000"))); - - new URIToDBKey(loader, uri); - } + URI uri = UriBuilder.fromPath("vservers/vserver/key2/l-interfaces/l-interface/key3").build(); + + thrown.expect(AAIException.class); + thrown.expect(hasProperty("code", is("AAI_3000"))); + + new URIToDBKey(loader, uri); + } } diff --git a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToDBKeyTest.java b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToDBKeyTest.java index 311ac358..757fbc1f 100644 --- a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToDBKeyTest.java +++ b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToDBKeyTest.java @@ -41,146 +41,146 @@ import static org.junit.Assert.assertEquals; public class URIToDBKeyTest extends AAISetup { - private Loader loader ; + private Loader loader ; - @Rule - public ExpectedException thrown = ExpectedException.none(); - - /** - * Uri. - * - * @throws JAXBException the JAXB exception - * @throws AAIException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - */ - @PostConstruct - public void createLoader(){ - loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); - } - - @Test + @Rule + public ExpectedException thrown = ExpectedException.none(); + + /** + * Uri. + * + * @throws JAXBException the JAXB exception + * @throws AAIException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + */ + @PostConstruct + public void createLoader(){ + loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); + } + + @Test public void uri() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException { - URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner-key/cloudRegion-key/tenants/tenant/tenantId-key/vservers/vserver/vserverId-key/l-interfaces/l-interface/key3").build(); - URIToDBKey parse = new URIToDBKey(loader, uri); - Object result = parse.getResult(); + URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner-key/cloudRegion-key/tenants/tenant/tenantId-key/vservers/vserver/vserverId-key/l-interfaces/l-interface/key3").build(); + URIToDBKey parse = new URIToDBKey(loader, uri); + Object result = parse.getResult(); - String expected = "cloud-region/tenant/vserver/l-interface"; - - assertEquals("blah", expected, result); - - } - - /** - * Uri no version. - * - * @throws JAXBException the JAXB exception - * @throws AAIException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - */ - @Test + String expected = "cloud-region/tenant/vserver/l-interface"; + + assertEquals("blah", expected, result); + + } + + /** + * Uri no version. + * + * @throws JAXBException the JAXB exception + * @throws AAIException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + */ + @Test public void uriNoVersion() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException { - URI uri = UriBuilder.fromPath("/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner-key/cloudRegion-key/tenants/tenant/tenantId-key/vservers/vserver/vserverId-key/l-interfaces/l-interface/key3").build(); - URIToDBKey parse = new URIToDBKey(loader, uri); - Object result = parse.getResult(); - - String expected = "cloud-region/tenant/vserver/l-interface"; - - assertEquals("blah", expected, result); - - } - + URI uri = UriBuilder.fromPath("/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner-key/cloudRegion-key/tenants/tenant/tenantId-key/vservers/vserver/vserverId-key/l-interfaces/l-interface/key3").build(); + URIToDBKey parse = new URIToDBKey(loader, uri); + Object result = parse.getResult(); + + String expected = "cloud-region/tenant/vserver/l-interface"; + + assertEquals("blah", expected, result); + + } + - /** - * Bad URI. - * - * @throws JAXBException the JAXB exception - * @throws AAIException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - */ - @Test + /** + * Bad URI. + * + * @throws JAXBException the JAXB exception + * @throws AAIException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + */ + @Test public void badURI() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException { - URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/tenants/tenant/key1/vservers/vserver/key2/l-interadsfaces/l-interface/key3").build(); - - thrown.expect(AAIException.class); - thrown.expect(hasProperty("code", is("AAI_3001"))); - - new URIToDBKey(loader, uri); - } - - /** - * NotValid namespace. - * - * @throws JAXBException the JAXB exception - * @throws DoesNotStartWithValidNamespaceException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - */ - @Test + URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/tenants/tenant/key1/vservers/vserver/key2/l-interadsfaces/l-interface/key3").build(); + + thrown.expect(AAIException.class); + thrown.expect(hasProperty("code", is("AAI_3001"))); + + new URIToDBKey(loader, uri); + } + + /** + * NotValid namespace. + * + * @throws JAXBException the JAXB exception + * @throws DoesNotStartWithValidNamespaceException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + */ + @Test public void notValidNamespace() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException { - URI uri = UriBuilder.fromPath("/cloud-region/cloud-regions/cloud-region/cloudOwner-key/cloudRegion-key/tenants/tenant/tenantId-key/vservers/vserver/vserverId-key/l-interfaces/l-interface/key3").build(); - thrown.expect(DoesNotStartWithValidNamespaceException.class); - URIToDBKey parse = new URIToDBKey(loader, uri); - } - - - /** - * No valid tokens. - * - * @throws JAXBException the JAXB exception - * @throws AAIException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - */ - @Test + URI uri = UriBuilder.fromPath("/cloud-region/cloud-regions/cloud-region/cloudOwner-key/cloudRegion-key/tenants/tenant/tenantId-key/vservers/vserver/vserverId-key/l-interfaces/l-interface/key3").build(); + thrown.expect(DoesNotStartWithValidNamespaceException.class); + URIToDBKey parse = new URIToDBKey(loader, uri); + } + + + /** + * No valid tokens. + * + * @throws JAXBException the JAXB exception + * @throws AAIException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + */ + @Test public void noValidTokens() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException { - URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud/blah/blah").build(); - - thrown.expect(AAIException.class); - thrown.expect(hasProperty("code", is("AAI_3000"))); - - new URIToDBKey(loader, uri); - } - - /** - * Starts with valid namespace. - * - * @throws JAXBException the JAXB exception - * @throws AAIException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - */ - @Test + URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud/blah/blah").build(); + + thrown.expect(AAIException.class); + thrown.expect(hasProperty("code", is("AAI_3000"))); + + new URIToDBKey(loader, uri); + } + + /** + * Starts with valid namespace. + * + * @throws JAXBException the JAXB exception + * @throws AAIException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + */ + @Test public void startsWithValidNamespace() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException { - URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner-key/cloudRegion-key/tenants/tenant/tenantId-key/vservers/vserver/vserverId-key/l-interfaces/l-interface/key3").build(); - - URIToDBKey parse = new URIToDBKey(loader, uri); - Object result = parse.getResult(); + URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner-key/cloudRegion-key/tenants/tenant/tenantId-key/vservers/vserver/vserverId-key/l-interfaces/l-interface/key3").build(); + + URIToDBKey parse = new URIToDBKey(loader, uri); + Object result = parse.getResult(); - String expected = "cloud-region/tenant/vserver/l-interface"; - - assertEquals("blah", expected, result); - } - - /** - * Naming exceptions. - * - * @throws IllegalArgumentException the illegal argument exception - * @throws AAIException the AAI exception - * @throws UnsupportedEncodingException the unsupported encoding exception - */ - @Test + String expected = "cloud-region/tenant/vserver/l-interface"; + + assertEquals("blah", expected, result); + } + + /** + * Naming exceptions. + * + * @throws IllegalArgumentException the illegal argument exception + * @throws AAIException the AAI exception + * @throws UnsupportedEncodingException the unsupported encoding exception + */ + @Test public void namingExceptions() throws IllegalArgumentException, AAIException, UnsupportedEncodingException { - URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build(); - URIToDBKey parse = new URIToDBKey(loader, uri); - Object result = parse.getResult(); + URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build(); + URIToDBKey parse = new URIToDBKey(loader, uri); + Object result = parse.getResult(); - String expected = "vce/port-group/cvlan-tag"; - - assertEquals("blah", expected, result); - + String expected = "vce/port-group/cvlan-tag"; + + assertEquals("blah", expected, result); + } - + } diff --git a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToExtensionInformationTest.java b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToExtensionInformationTest.java index 16cc14a1..cb365bb7 100644 --- a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToExtensionInformationTest.java +++ b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToExtensionInformationTest.java @@ -37,62 +37,62 @@ import static org.junit.Assert.assertEquals; public class URIToExtensionInformationTest extends AAISetup { - - private Loader specificLoader ; - - /** - * Vservers V 7. - * - * @throws JAXBException the JAXB exception - * @throws AAIException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - */ - - @PostConstruct - public void createLoader(){ - specificLoader = loaderFactory.createLoaderForVersion(ModelType.MOXY, new SchemaVersion("v10")); - } - - @Test + + private Loader specificLoader ; + + /** + * Vservers V 7. + * + * @throws JAXBException the JAXB exception + * @throws AAIException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + */ + + @PostConstruct + public void createLoader(){ + specificLoader = loaderFactory.createLoaderForVersion(ModelType.MOXY, new SchemaVersion("v10")); + } + + @Test public void vserversV8() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException { - URI uri = UriBuilder.fromPath("/aai/" + specificLoader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/testOwner1/testRegion1/tenants/tenant/key1/vservers/vserver/key2").build(); - URIToExtensionInformation parse = new URIToExtensionInformation(specificLoader, uri); - - String namespace = "cloudInfrastructure"; - String preMethodName = "DynamicAddCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverPreProc"; - String postMethodName = "DynamicAddCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverPostProc"; - String topLevel = "CloudRegion"; - testSpec(parse, HttpMethod.PUT, namespace, preMethodName, postMethodName, topLevel); + URI uri = UriBuilder.fromPath("/aai/" + specificLoader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/testOwner1/testRegion1/tenants/tenant/key1/vservers/vserver/key2").build(); + URIToExtensionInformation parse = new URIToExtensionInformation(specificLoader, uri); + + String namespace = "cloudInfrastructure"; + String preMethodName = "DynamicAddCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverPreProc"; + String postMethodName = "DynamicAddCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverPostProc"; + String topLevel = "CloudRegion"; + testSpec(parse, HttpMethod.PUT, namespace, preMethodName, postMethodName, topLevel); - } + } - /** - * Test spec. - * - * @param info the info - * @param httpMethod the http method - * @param namespace the namespace - * @param preMethodName the pre method name - * @param postMethodName the post method name - * @param topLevel the top level - */ - private void testSpec(URIToExtensionInformation info, HttpMethod httpMethod, String namespace, String preMethodName, String postMethodName, String topLevel) { - + /** + * Test spec. + * + * @param info the info + * @param httpMethod the http method + * @param namespace the namespace + * @param preMethodName the pre method name + * @param postMethodName the post method name + * @param topLevel the top level + */ + private void testSpec(URIToExtensionInformation info, HttpMethod httpMethod, String namespace, String preMethodName, String postMethodName, String topLevel) { + - String namespaceResult = info.getNamespace(); - String methodNameResult = info.getMethodName(httpMethod, true); - - assertEquals("namespace", namespace, namespaceResult); - assertEquals("preprocess method name", preMethodName, methodNameResult); - methodNameResult = info.getMethodName(httpMethod, false); + String namespaceResult = info.getNamespace(); + String methodNameResult = info.getMethodName(httpMethod, true); + + assertEquals("namespace", namespace, namespaceResult); + assertEquals("preprocess method name", preMethodName, methodNameResult); + methodNameResult = info.getMethodName(httpMethod, false); - assertEquals("postprocess method name", postMethodName, methodNameResult); + assertEquals("postprocess method name", postMethodName, methodNameResult); - String topLevelResult = info.getTopObject(); - - assertEquals("topLevel", topLevel, topLevelResult); - } - - + String topLevelResult = info.getTopObject(); + + assertEquals("topLevel", topLevel, topLevelResult); + } + + } diff --git a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToObjectTest.java b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToObjectTest.java index c2a25eac..2bf1e35e 100644 --- a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToObjectTest.java +++ b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToObjectTest.java @@ -47,212 +47,212 @@ import static org.junit.Assert.assertEquals; @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) public class URIToObjectTest extends AAISetup { - private SchemaVersion version ; - private SchemaVersion currentVersion; - private Loader loader ; - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - /** - * Uri. - * - * @throws JAXBException the JAXB exception - * @throws AAIException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - */ - @PostConstruct - public void createLoader(){ - version = schemaVersions.getRelatedLinkVersion(); - currentVersion = schemaVersions.getDefaultVersion(); - loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getRelatedLinkVersion()); - } - - @Test + private SchemaVersion version ; + private SchemaVersion currentVersion; + private Loader loader ; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + /** + * Uri. + * + * @throws JAXBException the JAXB exception + * @throws AAIException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + */ + @PostConstruct + public void createLoader(){ + version = schemaVersions.getRelatedLinkVersion(); + currentVersion = schemaVersions.getDefaultVersion(); + loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getRelatedLinkVersion()); + } + + @Test public void uri() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException { - URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build(); - URIToObject parse = new URIToObject(loader, uri); - Introspector result = parse.getTopEntity(); - String expected = "{\"cloud-owner\":\"mycloudowner\",\"cloud-region-id\":\"mycloudregionid\",\"tenants\":{\"tenant\":[{\"tenant-id\":\"key1\",\"vservers\":{\"vserver\":[{\"vserver-id\":\"key2\",\"l-interfaces\":{\"l-interface\":[{\"interface-name\":\"key3\"}]}}]}}]}}"; - String topEntity = "cloud-region"; - String entity = "l-interface"; - - testSet(result.marshal(false), parse, expected, topEntity, entity, version); - - } - - /** - * Uri no version. - * - * @throws JAXBException the JAXB exception - * @throws AAIException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIUnknownObjectException - */ - @Test + URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build(); + URIToObject parse = new URIToObject(loader, uri); + Introspector result = parse.getTopEntity(); + String expected = "{\"cloud-owner\":\"mycloudowner\",\"cloud-region-id\":\"mycloudregionid\",\"tenants\":{\"tenant\":[{\"tenant-id\":\"key1\",\"vservers\":{\"vserver\":[{\"vserver-id\":\"key2\",\"l-interfaces\":{\"l-interface\":[{\"interface-name\":\"key3\"}]}}]}}]}}"; + String topEntity = "cloud-region"; + String entity = "l-interface"; + + testSet(result.marshal(false), parse, expected, topEntity, entity, version); + + } + + /** + * Uri no version. + * + * @throws JAXBException the JAXB exception + * @throws AAIException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIUnknownObjectException + */ + @Test public void uriNoVersion() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, AAIUnknownObjectException { - URI uri = UriBuilder.fromPath("/cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build(); - HashMap<String, Introspector> relatedObjects = new HashMap<>(); - Introspector tenantObj = this.loader.introspectorFromName("tenant"); - tenantObj.setValue("tenant-id", "key1"); - tenantObj.setValue("tenant-name", "name1"); - relatedObjects.put(tenantObj.getObjectId(), tenantObj); - Introspector vserverObj = this.loader.introspectorFromName("vserver"); - vserverObj.setValue("vserver-id", "key2"); - vserverObj.setValue("vserver-name", "name2"); - relatedObjects.put(vserverObj.getObjectId(), vserverObj); - - URIToObject parse = new URIToObject(loader, uri, relatedObjects); - Introspector result = parse.getTopEntity(); - String expected = "{\"cloud-owner\":\"mycloudowner\",\"cloud-region-id\":\"mycloudregionid\",\"tenants\":{\"tenant\":[{\"tenant-id\":\"key1\",\"tenant-name\":\"name1\",\"vservers\":{\"vserver\":[{\"vserver-id\":\"key2\",\"vserver-name\":\"name2\",\"l-interfaces\":{\"l-interface\":[{\"interface-name\":\"key3\"}]}}]}}]}}"; - String topEntity = "cloud-region"; - String entity = "l-interface"; - - testSet(result.marshal(false), parse, expected, topEntity, entity, version); - - - } - - - /** - * Bad URI. - * - * @throws JAXBException the JAXB exception - * @throws AAIException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - */ - @Test + URI uri = UriBuilder.fromPath("/cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build(); + HashMap<String, Introspector> relatedObjects = new HashMap<>(); + Introspector tenantObj = this.loader.introspectorFromName("tenant"); + tenantObj.setValue("tenant-id", "key1"); + tenantObj.setValue("tenant-name", "name1"); + relatedObjects.put(tenantObj.getObjectId(), tenantObj); + Introspector vserverObj = this.loader.introspectorFromName("vserver"); + vserverObj.setValue("vserver-id", "key2"); + vserverObj.setValue("vserver-name", "name2"); + relatedObjects.put(vserverObj.getObjectId(), vserverObj); + + URIToObject parse = new URIToObject(loader, uri, relatedObjects); + Introspector result = parse.getTopEntity(); + String expected = "{\"cloud-owner\":\"mycloudowner\",\"cloud-region-id\":\"mycloudregionid\",\"tenants\":{\"tenant\":[{\"tenant-id\":\"key1\",\"tenant-name\":\"name1\",\"vservers\":{\"vserver\":[{\"vserver-id\":\"key2\",\"vserver-name\":\"name2\",\"l-interfaces\":{\"l-interface\":[{\"interface-name\":\"key3\"}]}}]}}]}}"; + String topEntity = "cloud-region"; + String entity = "l-interface"; + + testSet(result.marshal(false), parse, expected, topEntity, entity, version); + + + } + + + /** + * Bad URI. + * + * @throws JAXBException the JAXB exception + * @throws AAIException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + */ + @Test public void badURI() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException { - URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interadsfaces/l-interface/key3").build(); - - thrown.expect(AAIException.class); - thrown.expect(hasProperty("code", is("AAI_3000"))); - - new URIToObject(loader, uri); - } - - /** - * Starts with valid namespace. - * - * @throws JAXBException the JAXB exception - * @throws AAIException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - */ - @Test + URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interadsfaces/l-interface/key3").build(); + + thrown.expect(AAIException.class); + thrown.expect(hasProperty("code", is("AAI_3000"))); + + new URIToObject(loader, uri); + } + + /** + * Starts with valid namespace. + * + * @throws JAXBException the JAXB exception + * @throws AAIException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + */ + @Test public void startsWithValidNamespace() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException { - URI uri = UriBuilder.fromPath("/cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build(); - URIToObject parse = new URIToObject(loader, uri); - Introspector result = parse.getTopEntity(); - String expected = "{\"cloud-owner\":\"mycloudowner\",\"cloud-region-id\":\"mycloudregionid\",\"tenants\":{\"tenant\":[{\"tenant-id\":\"key1\",\"vservers\":{\"vserver\":[{\"vserver-id\":\"key2\",\"l-interfaces\":{\"l-interface\":[{\"interface-name\":\"key3\"}]}}]}}]}}"; - String topEntity = "cloud-region"; - String entity = "l-interface"; - - testSet(result.marshal(false), parse, expected, topEntity, entity, version); - } - - /** - * Single top level. - * - * @throws JAXBException the JAXB exception - * @throws AAIException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - */ - @Test + URI uri = UriBuilder.fromPath("/cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build(); + URIToObject parse = new URIToObject(loader, uri); + Introspector result = parse.getTopEntity(); + String expected = "{\"cloud-owner\":\"mycloudowner\",\"cloud-region-id\":\"mycloudregionid\",\"tenants\":{\"tenant\":[{\"tenant-id\":\"key1\",\"vservers\":{\"vserver\":[{\"vserver-id\":\"key2\",\"l-interfaces\":{\"l-interface\":[{\"interface-name\":\"key3\"}]}}]}}]}}"; + String topEntity = "cloud-region"; + String entity = "l-interface"; + + testSet(result.marshal(false), parse, expected, topEntity, entity, version); + } + + /** + * Single top level. + * + * @throws JAXBException the JAXB exception + * @throws AAIException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + */ + @Test public void singleTopLevel() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException { - URI uri = UriBuilder.fromPath("/network/generic-vnfs/generic-vnf/key1").build(); - URIToObject parse = new URIToObject(loader, uri); - Introspector result = parse.getTopEntity(); - String expected = "{\"vnf-id\":\"key1\"}"; - - String topEntity = "generic-vnf"; - String entity = "generic-vnf"; - - testSet(result.marshal(false), parse, expected, topEntity, entity, version); - - } - - /** - * Naming exceptions. - * - * @throws JAXBException the JAXB exception - * @throws AAIException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - */ - @Test - @Ignore + URI uri = UriBuilder.fromPath("/network/generic-vnfs/generic-vnf/key1").build(); + URIToObject parse = new URIToObject(loader, uri); + Introspector result = parse.getTopEntity(); + String expected = "{\"vnf-id\":\"key1\"}"; + + String topEntity = "generic-vnf"; + String entity = "generic-vnf"; + + testSet(result.marshal(false), parse, expected, topEntity, entity, version); + + } + + /** + * Naming exceptions. + * + * @throws JAXBException the JAXB exception + * @throws AAIException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + */ + @Test + @Ignore public void namingExceptions() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException { - URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build(); - URIToObject parse = new URIToObject(loader, uri); - Introspector result = parse.getTopEntity(); - String expected = "{\"vnf-id\":\"key1\",\"port-groups\":{\"port-group\":[{\"interface-id\":\"key2\",\"cvlan-tags\":{\"cvlan-tag-entry\":[{\"cvlan-tag\":655}]}}]}}"; - String topEntity = "vce"; - String entity = "cvlan-tag"; + URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build(); + URIToObject parse = new URIToObject(loader, uri); + Introspector result = parse.getTopEntity(); + String expected = "{\"vnf-id\":\"key1\",\"port-groups\":{\"port-group\":[{\"interface-id\":\"key2\",\"cvlan-tags\":{\"cvlan-tag-entry\":[{\"cvlan-tag\":655}]}}]}}"; + String topEntity = "vce"; + String entity = "cvlan-tag"; + + testSet(result.marshal(false), parse, expected, topEntity, entity, version); + + } - testSet(result.marshal(false), parse, expected, topEntity, entity, version); + /** + * No list object. + * + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws AAIException the AAI exception + */ + @Test + @Ignore + public void noListObject() throws IllegalArgumentException, UnsupportedEncodingException, AAIException { + URI uri = UriBuilder.fromPath("/aai/v6/network/vpls-pes/vpls-pe/0e6189fd-9257-49b9-a3be-d7ba980ccfc9/lag-interfaces/lag-interface/8ae5aa76-d597-4382-b219-04f266fe5e37/l-interfaces/l-interface/9e141d03-467b-437f-b4eb-b3133ec1e205/l3-interface-ipv4-address-list/8f19f0ea-a81f-488e-8d5c-9b7b53696c11").build(); + URIToObject parse = new URIToObject(loader, uri); + Introspector result = parse.getTopEntity(); + String topEntity = "vpls-pe"; + String entity = "l3-interface-ipv4-address-list"; + String expected = "{\"equipment-name\":\"0e6189fd-9257-49b9-a3be-d7ba980ccfc9\",\"lag-interfaces\":{\"lag-interface\":[{\"interface-name\":\"8ae5aa76-d597-4382-b219-04f266fe5e37\",\"l-interfaces\":{\"l-interface\":[{\"interface-name\":\"9e141d03-467b-437f-b4eb-b3133ec1e205\",\"l3-interface-ipv4-address-list\":[{\"l3-interface-ipv4-address\":\"8f19f0ea-a81f-488e-8d5c-9b7b53696c11\"}]}]}}]}}"; + testSet(result.marshal(false), parse, expected, topEntity, entity, version); } - /** - * No list object. - * - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws AAIException the AAI exception - */ - @Test - @Ignore - public void noListObject() throws IllegalArgumentException, UnsupportedEncodingException, AAIException { - URI uri = UriBuilder.fromPath("/aai/v6/network/vpls-pes/vpls-pe/0e6189fd-9257-49b9-a3be-d7ba980ccfc9/lag-interfaces/lag-interface/8ae5aa76-d597-4382-b219-04f266fe5e37/l-interfaces/l-interface/9e141d03-467b-437f-b4eb-b3133ec1e205/l3-interface-ipv4-address-list/8f19f0ea-a81f-488e-8d5c-9b7b53696c11").build(); - URIToObject parse = new URIToObject(loader, uri); - Introspector result = parse.getTopEntity(); - String topEntity = "vpls-pe"; - String entity = "l3-interface-ipv4-address-list"; - String expected = "{\"equipment-name\":\"0e6189fd-9257-49b9-a3be-d7ba980ccfc9\",\"lag-interfaces\":{\"lag-interface\":[{\"interface-name\":\"8ae5aa76-d597-4382-b219-04f266fe5e37\",\"l-interfaces\":{\"l-interface\":[{\"interface-name\":\"9e141d03-467b-437f-b4eb-b3133ec1e205\",\"l3-interface-ipv4-address-list\":[{\"l3-interface-ipv4-address\":\"8f19f0ea-a81f-488e-8d5c-9b7b53696c11\"}]}]}}]}}"; - testSet(result.marshal(false), parse, expected, topEntity, entity, version); - - } - - @Test + @Test public void relativePath() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException { - URI uri = UriBuilder.fromPath("./l-interfaces/l-interface/key1").build(); - URIToObject parse = new URIToObject(loader, uri); - Introspector result = parse.getEntity(); - String expected = "{\"interface-name\":\"key1\"}"; + URI uri = UriBuilder.fromPath("./l-interfaces/l-interface/key1").build(); + URIToObject parse = new URIToObject(loader, uri); + Introspector result = parse.getEntity(); + String expected = "{\"interface-name\":\"key1\"}"; - String topEntity = "l-interface"; - String entity = "l-interface"; + String topEntity = "l-interface"; + String entity = "l-interface"; - testSet(result.marshal(false), parse, expected, topEntity, entity, version); + testSet(result.marshal(false), parse, expected, topEntity, entity, version); - } + } - /** - * Test set. - * - * @param json the json - * @param parse the parse - * @param expected the expected - * @param topEntity the top entity - * @param entity the entity - * @param version the version - */ - public void testSet(String json, URIToObject parse, String expected, String topEntity, String entity, SchemaVersion version) { - assertEquals("blah", expected, json); + /** + * Test set. + * + * @param json the json + * @param parse the parse + * @param expected the expected + * @param topEntity the top entity + * @param entity the entity + * @param version the version + */ + public void testSet(String json, URIToObject parse, String expected, String topEntity, String entity, SchemaVersion version) { + assertEquals("blah", expected, json); - assertEquals("top entity", topEntity, parse.getTopEntityName()); + assertEquals("top entity", topEntity, parse.getTopEntityName()); - assertEquals("entity", entity, parse.getEntityName()); + assertEquals("entity", entity, parse.getEntityName()); - assertEquals("entity object", entity, parse.getEntity().getDbName()); + assertEquals("entity object", entity, parse.getEntity().getDbName()); - assertEquals("parent list object", 1, parse.getParentList().size()); + assertEquals("parent list object", 1, parse.getParentList().size()); - assertEquals("object version", version, parse.getObjectVersion()); - } + assertEquals("object version", version, parse.getObjectVersion()); + } } diff --git a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToRelationshipObjectTest.java b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToRelationshipObjectTest.java index 29ba1c2d..4d0ec6ca 100644 --- a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToRelationshipObjectTest.java +++ b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToRelationshipObjectTest.java @@ -41,113 +41,113 @@ import static org.junit.Assert.assertTrue; public class URIToRelationshipObjectTest extends AAISetup { - private SchemaVersion latest ; - private Loader loader; + private SchemaVersion latest ; + private Loader loader; - @Rule - public ExpectedException thrown = ExpectedException.none(); + @Rule + public ExpectedException thrown = ExpectedException.none(); - @PostConstruct - public void createLoader(){ - latest = schemaVersions.getDefaultVersion(); - loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, latest); - } - /** - * Uri. - * - * @throws JAXBException the JAXB exception - * @throws AAIException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws URISyntaxException - * @throws MalformedURLException the malformed URL exception - */ - @Test + @PostConstruct + public void createLoader(){ + latest = schemaVersions.getDefaultVersion(); + loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, latest); + } + /** + * Uri. + * + * @throws JAXBException the JAXB exception + * @throws AAIException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws URISyntaxException + * @throws MalformedURLException the malformed URL exception + */ + @Test public void uri() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, URISyntaxException { - - URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build(); - URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri); - Introspector result = parse.getResult(); - String expected = "\\{\"related-to\":\"l-interface\",\"related-link\":\"/aai/" + latest + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3\",\"relationship-data\":\\[\\{\"relationship-key\":\"cloud-region.cloud-owner\",\"relationship-value\":\"mycloudregionowner\"\\},\\{\"relationship-key\":\"cloud-region.cloud-region-id\",\"relationship-value\":\"mycloudregionid\"\\},\\{\"relationship-key\":\"tenant.tenant-id\",\"relationship-value\":\"key1\"\\},\\{\"relationship-key\":\"vserver.vserver-id\",\"relationship-value\":\"key2\"\\},\\{\"relationship-key\":\"l-interface.interface-name\",\"relationship-value\":\"key3\"\\}\\]\\}"; - assertTrue("blah", result.marshal(false).matches(expected)); - - } - - /** - * Uri no version. - * - * @throws JAXBException the JAXB exception - * @throws AAIException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws URISyntaxException - * @throws MalformedURLException the malformed URL exception - */ - @Test + + URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build(); + URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri); + Introspector result = parse.getResult(); + String expected = "\\{\"related-to\":\"l-interface\",\"related-link\":\"/aai/" + latest + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3\",\"relationship-data\":\\[\\{\"relationship-key\":\"cloud-region.cloud-owner\",\"relationship-value\":\"mycloudregionowner\"\\},\\{\"relationship-key\":\"cloud-region.cloud-region-id\",\"relationship-value\":\"mycloudregionid\"\\},\\{\"relationship-key\":\"tenant.tenant-id\",\"relationship-value\":\"key1\"\\},\\{\"relationship-key\":\"vserver.vserver-id\",\"relationship-value\":\"key2\"\\},\\{\"relationship-key\":\"l-interface.interface-name\",\"relationship-value\":\"key3\"\\}\\]\\}"; + assertTrue("blah", result.marshal(false).matches(expected)); + + } + + /** + * Uri no version. + * + * @throws JAXBException the JAXB exception + * @throws AAIException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws URISyntaxException + * @throws MalformedURLException the malformed URL exception + */ + @Test public void uriNoVersion() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, URISyntaxException { - URI uri = UriBuilder.fromPath("/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build(); - URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri); - Introspector result = parse.getResult(); - String expected = "\\{\"related-to\":\"l-interface\",\"related-link\":\"/aai/" + latest + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3\",\"relationship-data\":\\[\\{\"relationship-key\":\"cloud-region.cloud-owner\",\"relationship-value\":\"mycloudregionowner\"\\},\\{\"relationship-key\":\"cloud-region.cloud-region-id\",\"relationship-value\":\"mycloudregionid\"\\},\\{\"relationship-key\":\"tenant.tenant-id\",\"relationship-value\":\"key1\"\\},\\{\"relationship-key\":\"vserver.vserver-id\",\"relationship-value\":\"key2\"\\},\\{\"relationship-key\":\"l-interface.interface-name\",\"relationship-value\":\"key3\"\\}\\]\\}"; - assertTrue("blah", result.marshal(false).matches(expected)); + URI uri = UriBuilder.fromPath("/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build(); + URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri); + Introspector result = parse.getResult(); + String expected = "\\{\"related-to\":\"l-interface\",\"related-link\":\"/aai/" + latest + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3\",\"relationship-data\":\\[\\{\"relationship-key\":\"cloud-region.cloud-owner\",\"relationship-value\":\"mycloudregionowner\"\\},\\{\"relationship-key\":\"cloud-region.cloud-region-id\",\"relationship-value\":\"mycloudregionid\"\\},\\{\"relationship-key\":\"tenant.tenant-id\",\"relationship-value\":\"key1\"\\},\\{\"relationship-key\":\"vserver.vserver-id\",\"relationship-value\":\"key2\"\\},\\{\"relationship-key\":\"l-interface.interface-name\",\"relationship-value\":\"key3\"\\}\\]\\}"; + assertTrue("blah", result.marshal(false).matches(expected)); - - } + + } - /** - * Double key relationship. - * - * @throws JAXBException the JAXB exception - * @throws AAIException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws URISyntaxException - * @throws MalformedURLException the malformed URL exception - */ - @Test - public void doubleKeyRelationship() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, URISyntaxException { - URI uri = UriBuilder.fromPath("/aai/" + latest + "/cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3/").build(); - URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri); - Introspector result = parse.getResult(); - String expected = "\\{\"related-to\":\"ctag-pool\",\"related-link\":\"/aai/" + latest + "/cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3\",\"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\"\\}\\]\\}"; - assertTrue("blah", result.marshal(false).matches(expected)); + /** + * Double key relationship. + * + * @throws JAXBException the JAXB exception + * @throws AAIException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws URISyntaxException + * @throws MalformedURLException the malformed URL exception + */ + @Test + public void doubleKeyRelationship() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, URISyntaxException { + URI uri = UriBuilder.fromPath("/aai/" + latest + "/cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3/").build(); + URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri); + Introspector result = parse.getResult(); + String expected = "\\{\"related-to\":\"ctag-pool\",\"related-link\":\"/aai/" + latest + "/cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3\",\"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\"\\}\\]\\}"; + assertTrue("blah", result.marshal(false).matches(expected)); - } - - /** - * Uri with non string key. - * - * @throws JAXBException the JAXB exception - * @throws AAIException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - * @throws URISyntaxException - * @throws MalformedURLException the malformed URL exception - */ - @Test - public void uriWithNonStringKey() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, URISyntaxException { - URI uri = UriBuilder.fromPath("/aai/" + latest + "/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/144").build(); - URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri); - Introspector result = parse.getResult(); - String expected = "\\{\"related-to\":\"cvlan-tag\",\"related-link\":\"/aai/" + latest + "/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/144\",\"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\":\"144\"\\}\\]\\}"; - assertTrue("blah", result.marshal(false).matches(expected)); - } - /** - * Bad URI. - * - * @throws JAXBException the JAXB exception - * @throws AAIException the AAI exception - * @throws IllegalArgumentException the illegal argument exception - * @throws UnsupportedEncodingException the unsupported encoding exception - */ - @Test + } + + /** + * Uri with non string key. + * + * @throws JAXBException the JAXB exception + * @throws AAIException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + * @throws URISyntaxException + * @throws MalformedURLException the malformed URL exception + */ + @Test + public void uriWithNonStringKey() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, URISyntaxException { + URI uri = UriBuilder.fromPath("/aai/" + latest + "/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/144").build(); + URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri); + Introspector result = parse.getResult(); + String expected = "\\{\"related-to\":\"cvlan-tag\",\"related-link\":\"/aai/" + latest + "/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/144\",\"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\":\"144\"\\}\\]\\}"; + assertTrue("blah", result.marshal(false).matches(expected)); + } + /** + * Bad URI. + * + * @throws JAXBException the JAXB exception + * @throws AAIException the AAI exception + * @throws IllegalArgumentException the illegal argument exception + * @throws UnsupportedEncodingException the unsupported encoding exception + */ + @Test public void badURI() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException { - URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interadsfaces/l-interface/key3").build(); - - thrown.expect(AAIException.class); - thrown.expect(hasProperty("code", is("AAI_3000"))); - - URIToObject parse = new URIToObject(loader, uri); - - } + URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interadsfaces/l-interface/key3").build(); + + thrown.expect(AAIException.class); + thrown.expect(hasProperty("code", is("AAI_3000"))); + + URIToObject parse = new URIToObject(loader, uri); + + } } |