diff options
Diffstat (limited to 'aai-core')
25 files changed, 3642 insertions, 3642 deletions
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/IntrospectorTestSpec.java b/aai-core/src/test/java/org/onap/aai/introspection/IntrospectorTestSpec.java index 3a875062..44cbe6cc 100644 --- a/aai-core/src/test/java/org/onap/aai/introspection/IntrospectorTestSpec.java +++ b/aai-core/src/test/java/org/onap/aai/introspection/IntrospectorTestSpec.java @@ -26,32 +26,32 @@ import static org.junit.Assert.assertEquals; public abstract class IntrospectorTestSpec extends AAISetup { - - - /** - * Container test set. - * - * @param wrappedPortGroups the wrapped port groups - * @throws AAIUnknownObjectException - */ - protected void containerTestSet(Introspector wrappedPortGroups) throws AAIUnknownObjectException { - - assertEquals( - "isContainer", - true, - wrappedPortGroups.isContainer()); - - assertEquals( - "newInstanceOfNestedProperty", - "PortGroup", - wrappedPortGroups.newInstanceOfNestedProperty("port-group").getClass().getSimpleName()); - - assertEquals( - "isComplexGenericType", - true, - wrappedPortGroups.isComplexGenericType("port-group")); - - - } - + + + /** + * Container test set. + * + * @param wrappedPortGroups the wrapped port groups + * @throws AAIUnknownObjectException + */ + protected void containerTestSet(Introspector wrappedPortGroups) throws AAIUnknownObjectException { + + assertEquals( + "isContainer", + true, + wrappedPortGroups.isContainer()); + + assertEquals( + "newInstanceOfNestedProperty", + "PortGroup", + wrappedPortGroups.newInstanceOfNestedProperty("port-group").getClass().getSimpleName()); + + assertEquals( + "isComplexGenericType", + true, + wrappedPortGroups.isComplexGenericType("port-group")); + + + } + } diff --git a/aai-core/src/test/java/org/onap/aai/introspection/MoxyEngineTest.java b/aai-core/src/test/java/org/onap/aai/introspection/MoxyEngineTest.java index e5ecaee6..463c9174 100644 --- a/aai-core/src/test/java/org/onap/aai/introspection/MoxyEngineTest.java +++ b/aai-core/src/test/java/org/onap/aai/introspection/MoxyEngineTest.java @@ -27,21 +27,21 @@ import org.springframework.test.annotation.DirtiesContext; @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) public class MoxyEngineTest extends IntrospectorTestSpec { - /** - * Container object. - * @throws AAIUnknownObjectException - */ - @Test - public void containerObject() throws AAIUnknownObjectException { - + /** + * Container object. + * @throws AAIUnknownObjectException + */ + @Test + public void containerObject() throws AAIUnknownObjectException { + Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion()); Introspector obj = loader.introspectorFromName("port-groups"); this.containerTestSet(obj); - } - - - + } + + + } diff --git a/aai-core/src/test/java/org/onap/aai/introspection/PropertyPredicatesTest.java b/aai-core/src/test/java/org/onap/aai/introspection/PropertyPredicatesTest.java index 882b67e9..190e3243 100644 --- a/aai-core/src/test/java/org/onap/aai/introspection/PropertyPredicatesTest.java +++ b/aai-core/src/test/java/org/onap/aai/introspection/PropertyPredicatesTest.java @@ -35,40 +35,40 @@ import static org.junit.Assert.assertThat; @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) public class PropertyPredicatesTest extends AAISetup { - private Loader loader; - private ModelType introspectorFactoryType = ModelType.MOXY; - private Introspector obj; - - @Before - public void setup() throws Exception { - loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion()); - obj = loader.introspectorFromName("generic-vnf"); - } - - @Test - public void includeInTestGeneration() throws AAIUnknownObjectException { - - Set<String> props = obj.getProperties(PropertyPredicates.includeInTestGeneration()); + private Loader loader; + private ModelType introspectorFactoryType = ModelType.MOXY; + private Introspector obj; + + @Before + public void setup() throws Exception { + loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion()); + obj = loader.introspectorFromName("generic-vnf"); + } + + @Test + public void includeInTestGeneration() throws AAIUnknownObjectException { + + Set<String> props = obj.getProperties(PropertyPredicates.includeInTestGeneration()); - assertThat("props not found", props, - not(hasItems("model-invariant-id", "model-version-id"))); - } - - @Test - public void isVisible() throws AAIUnknownObjectException { - - Set<String> props = obj.getProperties(PropertyPredicates.isVisible()); + assertThat("props not found", props, + not(hasItems("model-invariant-id", "model-version-id"))); + } + + @Test + public void isVisible() throws AAIUnknownObjectException { + + Set<String> props = obj.getProperties(PropertyPredicates.isVisible()); - assertThat("props not found", props, hasItems("model-invariant-id", "model-version-id")); - } - - @Test - public void all() throws AAIUnknownObjectException { - - Set<String> props = obj.getProperties(); + assertThat("props not found", props, hasItems("model-invariant-id", "model-version-id")); + } + + @Test + public void all() throws AAIUnknownObjectException { + + Set<String> props = obj.getProperties(); - assertThat("all found", props, hasItems("model-invariant-id", "model-version-id")); - } - + assertThat("all found", props, hasItems("model-invariant-id", "model-version-id")); + } + } diff --git a/aai-core/src/test/java/org/onap/aai/introspection/generator/CreateExampleTest.java b/aai-core/src/test/java/org/onap/aai/introspection/generator/CreateExampleTest.java index f0d39f9f..c7d4cf82 100644 --- a/aai-core/src/test/java/org/onap/aai/introspection/generator/CreateExampleTest.java +++ b/aai-core/src/test/java/org/onap/aai/introspection/generator/CreateExampleTest.java @@ -34,98 +34,98 @@ import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class CreateExampleTest extends AAISetup { - - private static CreateExample createExample; - private Loader loader; + + private static CreateExample createExample; + private Loader loader; - private static boolean classLoaded = false; - - - @BeforeClass - public static void setUp() { - - - } - - - @Before - public void createLoaderVersion(){ - if(!classLoaded){ - loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getAppRootVersion()); - createExample = new CreateExample(loader, "edge-prop-names"); - classLoaded = false; - } - } - - @Test - public void testGetExampleObject() throws AAIException { - Introspector introspector = loader.introspectorFromName("edge-prop-names"); - Introspector res = createExample.getExampleObject(); - assertEquals(introspector.getName(), res.getName()); - } + private static boolean classLoaded = false; + + + @BeforeClass + public static void setUp() { + + + } + + + @Before + public void createLoaderVersion(){ + if(!classLoaded){ + loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getAppRootVersion()); + createExample = new CreateExample(loader, "edge-prop-names"); + classLoaded = false; + } + } + + @Test + public void testGetExampleObject() throws AAIException { + Introspector introspector = loader.introspectorFromName("edge-prop-names"); + Introspector res = createExample.getExampleObject(); + assertEquals(introspector.getName(), res.getName()); + } - @Test - public void testProcessPrimitiveString() throws AAIUnknownObjectException { - String propName = "direction"; - Introspector introspector = loader.introspectorFromName("edge-prop-names"); - createExample.processPrimitive(propName, introspector); - } - - @Test - public void testProcessPrimitiveLong() throws AAIUnknownObjectException { - String propName = "vlan-id-inner"; - Introspector introspector = loader.introspectorFromName("ctag-assignment"); - createExample.processPrimitive(propName, introspector); - } + @Test + public void testProcessPrimitiveString() throws AAIUnknownObjectException { + String propName = "direction"; + Introspector introspector = loader.introspectorFromName("edge-prop-names"); + createExample.processPrimitive(propName, introspector); + } + + @Test + public void testProcessPrimitiveLong() throws AAIUnknownObjectException { + String propName = "vlan-id-inner"; + Introspector introspector = loader.introspectorFromName("ctag-assignment"); + createExample.processPrimitive(propName, introspector); + } - @Test - public void testProcessPrimitiveBoolean() throws AAIUnknownObjectException { - String propName = "in-maint"; - Introspector introspector = loader.introspectorFromName("vserver"); - createExample.processPrimitive(propName, introspector); - } - - @Test - public void testProcessPrimitiveInteger() throws AAIUnknownObjectException { - String propName = "module-index"; - Introspector introspector = loader.introspectorFromName("vf-module"); - createExample.processPrimitive(propName, introspector); - } - - @Test - public void testProcessPrimitiveList() throws AAIUnknownObjectException { - String propName = "ipaddress-v4-vig"; - Introspector introspector = loader.introspectorFromName("vig-server"); - createExample.processPrimitiveList(propName, introspector); - } + @Test + public void testProcessPrimitiveBoolean() throws AAIUnknownObjectException { + String propName = "in-maint"; + Introspector introspector = loader.introspectorFromName("vserver"); + createExample.processPrimitive(propName, introspector); + } + + @Test + public void testProcessPrimitiveInteger() throws AAIUnknownObjectException { + String propName = "module-index"; + Introspector introspector = loader.introspectorFromName("vf-module"); + createExample.processPrimitive(propName, introspector); + } + + @Test + public void testProcessPrimitiveList() throws AAIUnknownObjectException { + String propName = "ipaddress-v4-vig"; + Introspector introspector = loader.introspectorFromName("vig-server"); + createExample.processPrimitiveList(propName, introspector); + } - @Test - public void testProcessComplexObj() { - // empty method - Introspector introspector = Mockito.mock(Introspector.class); - createExample.processComplexObj(introspector); - } + @Test + public void testProcessComplexObj() { + // empty method + Introspector introspector = Mockito.mock(Introspector.class); + createExample.processComplexObj(introspector); + } - @Test - public void testModifyComplexList() { - // empty method - List<Introspector> introList = new ArrayList<Introspector>(); - List<Object> objList = new ArrayList<Object>(); - Introspector introspector = Mockito.mock(Introspector.class); - createExample.modifyComplexList(introList, objList, introspector, introspector); - } + @Test + public void testModifyComplexList() { + // empty method + List<Introspector> introList = new ArrayList<Introspector>(); + List<Object> objList = new ArrayList<Object>(); + Introspector introspector = Mockito.mock(Introspector.class); + createExample.modifyComplexList(introList, objList, introspector, introspector); + } - @Test - public void testCreateComplexObjIfNull() { - boolean res = createExample.createComplexObjIfNull(); - assertTrue(res); - } + @Test + public void testCreateComplexObjIfNull() { + boolean res = createExample.createComplexObjIfNull(); + assertTrue(res); + } - @Test - public void testCreateComplexListSize() { - Introspector introspector = Mockito.mock(Introspector.class); - int res = createExample.createComplexListSize(introspector, introspector); - assertEquals(1, res); - } + @Test + public void testCreateComplexListSize() { + Introspector introspector = Mockito.mock(Introspector.class); + int res = createExample.createComplexListSize(introspector, introspector); + assertEquals(1, res); + } } diff --git a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java index c94afd29..f9911295 100644 --- a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java +++ b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java @@ -63,199 +63,199 @@ import static org.mockito.Mockito.when; public class DataCopyTest extends AAISetup{ - - - private static JanusGraph graph; - private final static ModelType introspectorFactoryType = ModelType.MOXY; - private final static DBConnectionType type = DBConnectionType.REALTIME; - private static Loader loader; - private static TransactionalGraphEngine dbEngine; - @Mock private Vertex self; - @Mock private VertexProperty<String> prop; - @Mock private QueryParser uriQuery; - @Rule public ExpectedException thrown = ExpectedException.none(); + + + private static JanusGraph graph; + private final static ModelType introspectorFactoryType = ModelType.MOXY; + private final static DBConnectionType type = DBConnectionType.REALTIME; + private static Loader loader; + private static TransactionalGraphEngine dbEngine; + @Mock private Vertex self; + @Mock private VertexProperty<String> prop; + @Mock private QueryParser uriQuery; + @Rule public ExpectedException thrown = ExpectedException.none(); - - @Parameterized.Parameter(value = 0) - public QueryStyle queryStyle; + + @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} - }); - } - - - @BeforeClass - public static void setup() throws NoSuchFieldException, SecurityException, Exception { - graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); - System.setProperty("AJSC_HOME", "."); - System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local"); - - graph.traversal().addV("aai-node-type", "model", "model-invariant-id", "key1", AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key1").as("v1") - .addV("aai-node-type", "model-ver", "model-ver", "myValue", "model-version-id", "key2", "model-version", "testValue", AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key1/model-vers/model-ver/key2") - .addOutE("org.onap.relationships.inventory.BelongsTo", "v1", EdgeProperty.CONTAINS.toString(), true) - .addV("aai-node-type", "model", "model-invariant-id", "key3", AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key3").as("v2") - .addV("aai-node-type", "model-ver", "model-ver", "myValue", "model-version-id", "key4", AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key3/model-vers/model-ver/key4") - .addOutE("org.onap.relationships.inventory.BelongsTo", "v2", EdgeProperty.CONTAINS.toString(), true) - .next(); - graph.tx().commit(); - } - - @AfterClass - public static void tearDown() { - graph.tx().rollback(); - graph.close(); - } - - @Before - public void initMock() { - loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion()); - MockitoAnnotations.initMocks(this); - dbEngine = new JanusGraphDBEngine( - queryStyle, - type, - loader); - } - - @Test - public void runPopulatePersonaModelVer() throws URISyntaxException, AAIException, UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException { - - final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); - final Introspector obj = loader.introspectorFromName("generic-vnf"); - obj.setValue("vnf-id", "myId"); - obj.setValue("model-invariant-id", "key1"); - obj.setValue("model-version-id", "key2"); - TransactionalGraphEngine spy = spy(dbEngine); - TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); - Graph g = graph.newTransaction(); - GraphTraversalSource traversal = g.traversal(); - when(spy.asAdmin()).thenReturn(adminSpy); - when(adminSpy.getTraversalSource()).thenReturn(traversal); - when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop); - when(prop.orElse(null)).thenReturn(obj.getURI()); - DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); - SideEffectRunner runner = new SideEffectRunner - .Builder(spy, serializer).addSideEffect(DataCopy.class).build(); - - runner.execute(obj, self); + @Parameterized.Parameters(name = "QueryStyle.{0}") + public static Collection<Object[]> data() { + return Arrays.asList(new Object[][]{ + {QueryStyle.TRAVERSAL}, + {QueryStyle.TRAVERSAL_URI} + }); + } + + + @BeforeClass + public static void setup() throws NoSuchFieldException, SecurityException, Exception { + graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); + System.setProperty("AJSC_HOME", "."); + System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local"); + + graph.traversal().addV("aai-node-type", "model", "model-invariant-id", "key1", AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key1").as("v1") + .addV("aai-node-type", "model-ver", "model-ver", "myValue", "model-version-id", "key2", "model-version", "testValue", AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key1/model-vers/model-ver/key2") + .addOutE("org.onap.relationships.inventory.BelongsTo", "v1", EdgeProperty.CONTAINS.toString(), true) + .addV("aai-node-type", "model", "model-invariant-id", "key3", AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key3").as("v2") + .addV("aai-node-type", "model-ver", "model-ver", "myValue", "model-version-id", "key4", AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key3/model-vers/model-ver/key4") + .addOutE("org.onap.relationships.inventory.BelongsTo", "v2", EdgeProperty.CONTAINS.toString(), true) + .next(); + graph.tx().commit(); + } + + @AfterClass + public static void tearDown() { + graph.tx().rollback(); + graph.close(); + } + + @Before + public void initMock() { + loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion()); + MockitoAnnotations.initMocks(this); + dbEngine = new JanusGraphDBEngine( + queryStyle, + type, + loader); + } + + @Test + public void runPopulatePersonaModelVer() throws URISyntaxException, AAIException, UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException { + + final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); + final Introspector obj = loader.introspectorFromName("generic-vnf"); + obj.setValue("vnf-id", "myId"); + obj.setValue("model-invariant-id", "key1"); + obj.setValue("model-version-id", "key2"); + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + Graph g = graph.newTransaction(); + GraphTraversalSource traversal = g.traversal(); + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop); + when(prop.orElse(null)).thenReturn(obj.getURI()); + DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); + SideEffectRunner runner = new SideEffectRunner + .Builder(spy, serializer).addSideEffect(DataCopy.class).build(); + + runner.execute(obj, self); - assertEquals("value populated", "testValue", obj.getValue("persona-model-version")); - - g.tx().rollback(); - - - } - - @Test - public void verifyNestedSideEffect() throws URISyntaxException, AAIException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, IOException { - - final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); - final Introspector obj = loader.unmarshal("customer", this.getJsonString("nested-case.json")); - //System.out.println(obj.marshal(true)); - TransactionalGraphEngine spy = spy(dbEngine); - TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); - Graph g = graph.newTransaction(); - GraphTraversalSource traversal = g.traversal(); - when(spy.tx()).thenReturn(g); - when(spy.asAdmin()).thenReturn(adminSpy); - when(adminSpy.getTraversalSource()).thenReturn(traversal); - when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop); - when(prop.orElse(null)).thenReturn(obj.getURI()); - when(uriQuery.isDependent()).thenReturn(false); - DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); - Vertex v= serializer.createNewVertex(obj); - serializer.serializeToDb(obj, v, uriQuery, obj.getURI(), "test"); - - assertEquals("nested value populated", "testValue", g.traversal().V().has("service-instance-id", "nested-instance-key").next().property("persona-model-version").orElse("")); + assertEquals("value populated", "testValue", obj.getValue("persona-model-version")); + + g.tx().rollback(); + + + } + + @Test + public void verifyNestedSideEffect() throws URISyntaxException, AAIException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, IOException { + + final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); + final Introspector obj = loader.unmarshal("customer", this.getJsonString("nested-case.json")); + //System.out.println(obj.marshal(true)); + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + Graph g = graph.newTransaction(); + GraphTraversalSource traversal = g.traversal(); + when(spy.tx()).thenReturn(g); + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop); + when(prop.orElse(null)).thenReturn(obj.getURI()); + when(uriQuery.isDependent()).thenReturn(false); + DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); + Vertex v= serializer.createNewVertex(obj); + serializer.serializeToDb(obj, v, uriQuery, obj.getURI(), "test"); + + assertEquals("nested value populated", "testValue", g.traversal().V().has("service-instance-id", "nested-instance-key").next().property("persona-model-version").orElse("")); - g.tx().rollback(); + g.tx().rollback(); - } - - @Test - public void expectedMissingPropertyExceptionInURI() throws AAIException, UnsupportedEncodingException { - - final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); - final Introspector obj = loader.introspectorFromName("generic-vnf"); - obj.setValue("vnf-id", "myId"); - obj.setValue("model-invariant-id", "key1"); + } + + @Test + public void expectedMissingPropertyExceptionInURI() throws AAIException, UnsupportedEncodingException { + + final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); + final Introspector obj = loader.introspectorFromName("generic-vnf"); + obj.setValue("vnf-id", "myId"); + obj.setValue("model-invariant-id", "key1"); - TransactionalGraphEngine spy = spy(dbEngine); - TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); - Graph g = graph.newTransaction(); - GraphTraversalSource traversal = g.traversal(); - when(spy.asAdmin()).thenReturn(adminSpy); - when(adminSpy.getTraversalSource()).thenReturn(traversal); - when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop); - when(prop.orElse(null)).thenReturn(obj.getURI()); - DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); - SideEffectRunner runner = new SideEffectRunner - .Builder(spy, serializer).addSideEffect(DataCopy.class).build(); - - thrown.expect(AAIMissingRequiredPropertyException.class); - runner.execute(obj, self); - } - - @Test - public void expectedMissingPropertyExceptionForResultingObject() throws AAIException, UnsupportedEncodingException { - final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); - final Introspector obj = loader.introspectorFromName("generic-vnf"); - obj.setValue("vnf-id", "myId"); - obj.setValue("model-invariant-id", "key3"); - obj.setValue("model-version-id", "key4"); + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + Graph g = graph.newTransaction(); + GraphTraversalSource traversal = g.traversal(); + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop); + when(prop.orElse(null)).thenReturn(obj.getURI()); + DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); + SideEffectRunner runner = new SideEffectRunner + .Builder(spy, serializer).addSideEffect(DataCopy.class).build(); + + thrown.expect(AAIMissingRequiredPropertyException.class); + runner.execute(obj, self); + } + + @Test + public void expectedMissingPropertyExceptionForResultingObject() throws AAIException, UnsupportedEncodingException { + final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); + final Introspector obj = loader.introspectorFromName("generic-vnf"); + obj.setValue("vnf-id", "myId"); + obj.setValue("model-invariant-id", "key3"); + obj.setValue("model-version-id", "key4"); - TransactionalGraphEngine spy = spy(dbEngine); - TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); - Graph g = graph.newTransaction(); - GraphTraversalSource traversal = g.traversal(); - when(spy.asAdmin()).thenReturn(adminSpy); - when(adminSpy.getTraversalSource()).thenReturn(traversal); - when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop); - when(prop.orElse(null)).thenReturn(obj.getURI()); - DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); - SideEffectRunner runner = new SideEffectRunner - .Builder(spy, serializer).addSideEffect(DataCopy.class).build(); - - thrown.expect(AAIMissingRequiredPropertyException.class); - runner.execute(obj, self); - } - - @Test - public void expectNoProcessingWithNoProperties() throws AAIException, UnsupportedEncodingException { - final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); - final Introspector obj = loader.introspectorFromName("generic-vnf"); - obj.setValue("vnf-id", "myId"); + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + Graph g = graph.newTransaction(); + GraphTraversalSource traversal = g.traversal(); + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop); + when(prop.orElse(null)).thenReturn(obj.getURI()); + DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); + SideEffectRunner runner = new SideEffectRunner + .Builder(spy, serializer).addSideEffect(DataCopy.class).build(); + + thrown.expect(AAIMissingRequiredPropertyException.class); + runner.execute(obj, self); + } + + @Test + public void expectNoProcessingWithNoProperties() throws AAIException, UnsupportedEncodingException { + final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); + final Introspector obj = loader.introspectorFromName("generic-vnf"); + obj.setValue("vnf-id", "myId"); - TransactionalGraphEngine spy = spy(dbEngine); - TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); - Graph g = graph.newTransaction(); - GraphTraversalSource traversal = g.traversal(); - when(spy.asAdmin()).thenReturn(adminSpy); - when(adminSpy.getTraversalSource()).thenReturn(traversal); - when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop); - when(prop.orElse(null)).thenReturn(obj.getURI()); - DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); - SideEffectRunner runner = new SideEffectRunner - .Builder(spy, serializer).addSideEffect(DataCopy.class).build(); - - runner.execute(obj, self); - - assertEquals("no model-version-id", true, obj.getValue("model-version-id") == null); - assertEquals("no model-invariant-id", true, obj.getValue("model-invariant-id") == null); - - } - - private String getJsonString(String filename) throws IOException { - - - FileInputStream is = new FileInputStream("src/test/resources/oxm/sideeffect/" + filename); - String s = IOUtils.toString(is, "UTF-8"); - IOUtils.closeQuietly(is); - - return s; - } + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + Graph g = graph.newTransaction(); + GraphTraversalSource traversal = g.traversal(); + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop); + when(prop.orElse(null)).thenReturn(obj.getURI()); + DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); + SideEffectRunner runner = new SideEffectRunner + .Builder(spy, serializer).addSideEffect(DataCopy.class).build(); + + runner.execute(obj, self); + + assertEquals("no model-version-id", true, obj.getValue("model-version-id") == null); + assertEquals("no model-invariant-id", true, obj.getValue("model-invariant-id") == null); + + } + + private String getJsonString(String filename) throws IOException { + + + FileInputStream is = new FileInputStream("src/test/resources/oxm/sideeffect/" + filename); + String s = IOUtils.toString(is, "UTF-8"); + IOUtils.closeQuietly(is); + + return s; + } } diff --git a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataLinkTest.java b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataLinkTest.java index c1218298..5b9a0fa6 100644 --- a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataLinkTest.java +++ b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataLinkTest.java @@ -64,303 +64,303 @@ import static org.mockito.Mockito.when; @RunWith(value = Parameterized.class) public class DataLinkTest extends DataLinkSetup { - private static JanusGraph graph; - private final static ModelType introspectorFactoryType = ModelType.MOXY; - private final static DBConnectionType type = DBConnectionType.REALTIME; - private static Loader loader; - private static TransactionalGraphEngine dbEngine; - @Mock private QueryParser parser; - @Mock private Vertex self; - @Mock private VertexProperty<String> prop; - @Rule - public ExpectedException thrown = ExpectedException.none(); + private static JanusGraph graph; + private final static ModelType introspectorFactoryType = ModelType.MOXY; + private final static DBConnectionType type = DBConnectionType.REALTIME; + private static Loader loader; + private static TransactionalGraphEngine dbEngine; + @Mock private QueryParser parser; + @Mock private Vertex self; + @Mock private VertexProperty<String> prop; + @Rule + public ExpectedException thrown = ExpectedException.none(); - - @Parameterized.Parameter(value = 0) - public QueryStyle queryStyle; + + @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} - }); - } - - @BeforeClass - public static void setup() throws NoSuchFieldException, SecurityException, Exception { - graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); - + @Parameterized.Parameters(name = "QueryStyle.{0}") + public static Collection<Object[]> data() { + return Arrays.asList(new Object[][]{ + {QueryStyle.TRAVERSAL}, + {QueryStyle.TRAVERSAL_URI} + }); + } + + @BeforeClass + public static void setup() throws NoSuchFieldException, SecurityException, Exception { + graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); + - graph.traversal().addV("aai-node-type", "vpn-binding", "vpn-id", "addKey", AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/addKey").as("v1") - .addV("aai-node-type", "vpn-binding", "vpn-id", "modifyKey", AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/modifyKey").as("v2") - .addV("aai-node-type", "route-target", "global-route-target", "modifyTargetKey", "route-target-role", "modifyRoleKey", "linked", true, AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/modifyKey/route-targets/route-target/modifyTargetKey/modifyRoleKey") - .addOutE("org.onap.relationships.inventory.BelongsTo", "v2", EdgeProperty.CONTAINS.toString(), true) - .addV("aai-node-type", "vpn-binding", "vpn-id", "deleteKey",AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/deleteKey").as("v3" ) - .addV("aai-node-type", "route-target", "global-route-target", "deleteTargetKey", "route-target-role", "deleteRoleKey", "linked", true, AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/deleteKey/route-targets/route-target/deleteTargetKey/deleteRoleKey") - .addOutE("org.onap.relationships.inventory.BelongsTo", "v3", EdgeProperty.CONTAINS.toString(), true) - .addV("aai-node-type", "vpn-binding", "vpn-id", "getKey", AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/getKey").as("v4") - .addV("aai-node-type", "route-target", "global-route-target", "getTargetKey", "route-target-role", "getRoleKey", "linked", true, AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/getKey/route-targets/route-target/getTargetKeyNoLink/getRoleKeyNoLink") - .addOutE("org.onap.relationships.inventory.BelongsTo", "v4", EdgeProperty.CONTAINS.toString(), true) - .addV("aai-node-type", "vpn-binding", "vpn-id", "getKeyNoLink", AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/getKeyNoLink").as("v5") - .addV("aai-node-type", "route-target", "global-route-target", "getTargetKeyNoLink", "route-target-role", "getRoleKeyNoLink", AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/getKeyNoLink/route-targets/route-target/getTargetKeyNoLink/getRoleKeyNoLink") - .addOutE("org.onap.relationships.inventory.BelongsTo", "v5", EdgeProperty.CONTAINS.toString(), true) - .next(); - graph.tx().commit(); + graph.traversal().addV("aai-node-type", "vpn-binding", "vpn-id", "addKey", AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/addKey").as("v1") + .addV("aai-node-type", "vpn-binding", "vpn-id", "modifyKey", AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/modifyKey").as("v2") + .addV("aai-node-type", "route-target", "global-route-target", "modifyTargetKey", "route-target-role", "modifyRoleKey", "linked", true, AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/modifyKey/route-targets/route-target/modifyTargetKey/modifyRoleKey") + .addOutE("org.onap.relationships.inventory.BelongsTo", "v2", EdgeProperty.CONTAINS.toString(), true) + .addV("aai-node-type", "vpn-binding", "vpn-id", "deleteKey",AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/deleteKey").as("v3" ) + .addV("aai-node-type", "route-target", "global-route-target", "deleteTargetKey", "route-target-role", "deleteRoleKey", "linked", true, AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/deleteKey/route-targets/route-target/deleteTargetKey/deleteRoleKey") + .addOutE("org.onap.relationships.inventory.BelongsTo", "v3", EdgeProperty.CONTAINS.toString(), true) + .addV("aai-node-type", "vpn-binding", "vpn-id", "getKey", AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/getKey").as("v4") + .addV("aai-node-type", "route-target", "global-route-target", "getTargetKey", "route-target-role", "getRoleKey", "linked", true, AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/getKey/route-targets/route-target/getTargetKeyNoLink/getRoleKeyNoLink") + .addOutE("org.onap.relationships.inventory.BelongsTo", "v4", EdgeProperty.CONTAINS.toString(), true) + .addV("aai-node-type", "vpn-binding", "vpn-id", "getKeyNoLink", AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/getKeyNoLink").as("v5") + .addV("aai-node-type", "route-target", "global-route-target", "getTargetKeyNoLink", "route-target-role", "getRoleKeyNoLink", AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/getKeyNoLink/route-targets/route-target/getTargetKeyNoLink/getRoleKeyNoLink") + .addOutE("org.onap.relationships.inventory.BelongsTo", "v5", EdgeProperty.CONTAINS.toString(), true) + .next(); + graph.tx().commit(); - /*Commented for SysOut issues - */ - //graph.traversal().V().has("aai-uri","/network/vpn-bindings/vpn-binding/deleteKey").properties().forEachRemaining(p->System.out.println(p.key() +" : " + p.value())); - - } - - @AfterClass - public static void tearDown() { - graph.tx().rollback(); - graph.close(); - } - - @Before - public void initMock() { - loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion()); - MockitoAnnotations.initMocks(this); - dbEngine = new JanusGraphDBEngine( - queryStyle, - type, - loader); - } - - @Test - public void verifyCreationOfVertex() throws URISyntaxException, AAIException, UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException { - - final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion()); - final Introspector obj = loader.introspectorFromName("vpn-binding"); - obj.setValue("vpn-id", "addKey"); - obj.setValue("global-route-target", "key1"); - obj.setValue("route-target-role", "key2"); - TransactionalGraphEngine spy = spy(dbEngine); - TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); - Graph g = graph.newTransaction(); - GraphTraversalSource traversal = g.traversal(); -// Graph g = graph.newTransaction(); -// GraphTraversalSource traversal = g; - // System.out.println("Begin method inventory:"); - Iterator<Vertex> vertexItr = traversal.V(); - while( vertexItr != null && vertexItr.hasNext() ){ - Vertex v = vertexItr.next(); - // System.out.println("\nnodeType="+v.<String>property("aai-node-type")); - for(String key: v.keys()) { - // System.out.println("label="+v.label()+";key= "+key+";value= "+v.value(key)+";id= "+v.id()); - } - Direction d = null; - Iterator<Edge> edgeItr = v.edges(Direction.BOTH); - while( edgeItr != null && edgeItr.hasNext() ){ - Edge e = edgeItr.next(); - //System.out.println("outV="+e.outVertex().property(AAIProperties.NODE_TYPE)+"/"+e.outVertex().id()+";inV= "+e.inVertex().property(AAIProperties.NODE_TYPE)+"/"+e.inVertex().id()); - } - } - //System.out.println("End method inventory:"); - when(spy.asAdmin()).thenReturn(adminSpy); - when(adminSpy.getTraversalSource()).thenReturn(traversal); - when(spy.tx()).thenReturn(g); - when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop); - when(prop.orElse(null)).thenReturn(obj.getURI()); - DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); - SideEffectRunner runner = new SideEffectRunner - .Builder(spy, serializer).addSideEffect(DataLinkWriter.class).build(); - - runner.execute(obj, self); + /*Commented for SysOut issues + */ + //graph.traversal().V().has("aai-uri","/network/vpn-bindings/vpn-binding/deleteKey").properties().forEachRemaining(p->System.out.println(p.key() +" : " + p.value())); + + } + + @AfterClass + public static void tearDown() { + graph.tx().rollback(); + graph.close(); + } + + @Before + public void initMock() { + loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion()); + MockitoAnnotations.initMocks(this); + dbEngine = new JanusGraphDBEngine( + queryStyle, + type, + loader); + } + + @Test + public void verifyCreationOfVertex() throws URISyntaxException, AAIException, UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException { + + final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion()); + final Introspector obj = loader.introspectorFromName("vpn-binding"); + obj.setValue("vpn-id", "addKey"); + obj.setValue("global-route-target", "key1"); + obj.setValue("route-target-role", "key2"); + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + Graph g = graph.newTransaction(); + GraphTraversalSource traversal = g.traversal(); +// Graph g = graph.newTransaction(); +// GraphTraversalSource traversal = g; + // System.out.println("Begin method inventory:"); + Iterator<Vertex> vertexItr = traversal.V(); + while( vertexItr != null && vertexItr.hasNext() ){ + Vertex v = vertexItr.next(); + // System.out.println("\nnodeType="+v.<String>property("aai-node-type")); + for(String key: v.keys()) { + // System.out.println("label="+v.label()+";key= "+key+";value= "+v.value(key)+";id= "+v.id()); + } + Direction d = null; + Iterator<Edge> edgeItr = v.edges(Direction.BOTH); + while( edgeItr != null && edgeItr.hasNext() ){ + Edge e = edgeItr.next(); + //System.out.println("outV="+e.outVertex().property(AAIProperties.NODE_TYPE)+"/"+e.outVertex().id()+";inV= "+e.inVertex().property(AAIProperties.NODE_TYPE)+"/"+e.inVertex().id()); + } + } + //System.out.println("End method inventory:"); + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + when(spy.tx()).thenReturn(g); + when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop); + when(prop.orElse(null)).thenReturn(obj.getURI()); + DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); + SideEffectRunner runner = new SideEffectRunner + .Builder(spy, serializer).addSideEffect(DataLinkWriter.class).build(); + + runner.execute(obj, self); - assertEquals("route-target vertex found", true, traversal.V() - .has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "key1").has("route-target-role", "key2").has("linked", true).hasNext()); - g.tx().rollback(); - - } - - @Test - public void verifyModificationOfVertex() throws URISyntaxException, AAIException, UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException { - - final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion()); - final Introspector obj = loader.introspectorFromName("vpn-binding"); - obj.setValue("vpn-id", "modifyKey"); - obj.setValue("global-route-target", "modifyTargetKey2"); - obj.setValue("route-target-role", "modifyRoleKey2"); - TransactionalGraphEngine spy = spy(dbEngine); - TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); -// Graph g = graph.newTransaction(); -// GraphTraversalSource traversal = g; - Graph g = graph.newTransaction(); - GraphTraversalSource traversal = g.traversal(); - Iterator<Vertex> vertexItr = traversal.V(); - while( vertexItr != null && vertexItr.hasNext() ){ - Vertex v = vertexItr.next(); - //System.out.println("\nnodeType="+v.<String>property("aai-node-type")); - for(String key: v.keys()) { - //System.out.println("label="+v.label()+";key= "+key+";value= "+v.value(key)+"/"+v.id()); - } - Direction d = null; - Iterator<Edge> edgeItr = v.edges(Direction.BOTH); - while( edgeItr != null && edgeItr.hasNext() ){ - Edge e = edgeItr.next(); - // System.out.println("outV="+e.outVertex().property(AAIProperties.NODE_TYPE)+"/"+e.outVertex().id()+";inV= "+e.inVertex().property(AAIProperties.NODE_TYPE)+"/"+e.inVertex().id()); - } - } - // System.out.println("End method inventory:"); + assertEquals("route-target vertex found", true, traversal.V() + .has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "key1").has("route-target-role", "key2").has("linked", true).hasNext()); + g.tx().rollback(); + + } + + @Test + public void verifyModificationOfVertex() throws URISyntaxException, AAIException, UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException { + + final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion()); + final Introspector obj = loader.introspectorFromName("vpn-binding"); + obj.setValue("vpn-id", "modifyKey"); + obj.setValue("global-route-target", "modifyTargetKey2"); + obj.setValue("route-target-role", "modifyRoleKey2"); + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); +// Graph g = graph.newTransaction(); +// GraphTraversalSource traversal = g; + Graph g = graph.newTransaction(); + GraphTraversalSource traversal = g.traversal(); + Iterator<Vertex> vertexItr = traversal.V(); + while( vertexItr != null && vertexItr.hasNext() ){ + Vertex v = vertexItr.next(); + //System.out.println("\nnodeType="+v.<String>property("aai-node-type")); + for(String key: v.keys()) { + //System.out.println("label="+v.label()+";key= "+key+";value= "+v.value(key)+"/"+v.id()); + } + Direction d = null; + Iterator<Edge> edgeItr = v.edges(Direction.BOTH); + while( edgeItr != null && edgeItr.hasNext() ){ + Edge e = edgeItr.next(); + // System.out.println("outV="+e.outVertex().property(AAIProperties.NODE_TYPE)+"/"+e.outVertex().id()+";inV= "+e.inVertex().property(AAIProperties.NODE_TYPE)+"/"+e.inVertex().id()); + } + } + // System.out.println("End method inventory:"); - when(spy.asAdmin()).thenReturn(adminSpy); - when(adminSpy.getTraversalSource()).thenReturn(traversal); -// when(spy.tx()).thenReturn(graph); - when(spy.tx()).thenReturn(g); - when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop); - when(prop.orElse(null)).thenReturn(obj.getURI()); - DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); - SideEffectRunner runner = new SideEffectRunner - .Builder(spy, serializer).addSideEffect(DataLinkWriter.class).build(); - //System.out.println("Traversal Source: "+traversal.toString()); - vertexItr = traversal.V(); - // System.out.println("Begin method inventory:"); - while( vertexItr != null && vertexItr.hasNext() ){ - Vertex v = vertexItr.next(); - //System.out.println("\nnodeType="+v.<String>property("aai-node-type")); - for(String key: v.keys()) { - // System.out.println("label="+v.label()+";key= "+key+";value= "+v.value(key)+"/"+v.id()); - } - Iterator<Edge> edgeItr = v.edges(Direction.BOTH); - while( edgeItr != null && edgeItr.hasNext() ){ - Edge e = edgeItr.next(); - //System.out.println("outV="+e.outVertex().property(AAIProperties.NODE_TYPE)+"/"+e.outVertex().id()+";inV= "+e.inVertex().property(AAIProperties.NODE_TYPE)+"/"+e.inVertex().id()); - } - } - //System.out.println("End method inventory:"); - try { - runner.execute(obj, self); - } catch(Exception e) { + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); +// when(spy.tx()).thenReturn(graph); + when(spy.tx()).thenReturn(g); + when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop); + when(prop.orElse(null)).thenReturn(obj.getURI()); + DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); + SideEffectRunner runner = new SideEffectRunner + .Builder(spy, serializer).addSideEffect(DataLinkWriter.class).build(); + //System.out.println("Traversal Source: "+traversal.toString()); + vertexItr = traversal.V(); + // System.out.println("Begin method inventory:"); + while( vertexItr != null && vertexItr.hasNext() ){ + Vertex v = vertexItr.next(); + //System.out.println("\nnodeType="+v.<String>property("aai-node-type")); + for(String key: v.keys()) { + // System.out.println("label="+v.label()+";key= "+key+";value= "+v.value(key)+"/"+v.id()); + } + Iterator<Edge> edgeItr = v.edges(Direction.BOTH); + while( edgeItr != null && edgeItr.hasNext() ){ + Edge e = edgeItr.next(); + //System.out.println("outV="+e.outVertex().property(AAIProperties.NODE_TYPE)+"/"+e.outVertex().id()+";inV= "+e.inVertex().property(AAIProperties.NODE_TYPE)+"/"+e.inVertex().id()); + } + } + //System.out.println("End method inventory:"); + try { + runner.execute(obj, self); + } catch(Exception e) { - } -// runner.execute(obj, self); - //System.out.println("=================\n"); - vertexItr = traversal.V(); - while( vertexItr != null && vertexItr.hasNext() ){ - Vertex v = vertexItr.next(); - //System.out.println("\nnodeType="+v.<String>property("aai-node-type")); - for(String key: v.keys()) { - // System.out.println("label="+v.label()+";key= "+key+";value= "+v.value(key)+"/"+v.id()); - } - Iterator<Edge> edgeItr = v.edges(Direction.BOTH); - while( edgeItr != null && edgeItr.hasNext() ){ - Edge e = edgeItr.next(); - // System.out.println("outV="+e.outVertex().property(AAIProperties.NODE_TYPE)+"/"+e.outVertex().id()+";inV= "+e.inVertex().property(AAIProperties.NODE_TYPE)+"/"+e.inVertex().id()); - } - } - assertThat("new route-target vertex found with/or without link", traversal.V() - .has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "modifyTargetKey2").has("route-target-role", "modifyRoleKey2").hasNext(),is(true)); - assertThat("new route-target vertex found", traversal.V() - .has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "modifyTargetKey2").has("route-target-role", "modifyRoleKey2").has("linked", true).hasNext(),is(true)); - assertThat("previous link removed", traversal.V() - .has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "modifyTargetKey").has("route-target-role", "modifyRoleKey").has("linked").hasNext(),is(not(true))); - assertThat("previous vertex still exists", traversal.V() - .has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "modifyTargetKey").has("route-target-role", "modifyRoleKey").hasNext(),is(true)); - g.tx().rollback(); - - } - - @Test - public void verifyDeleteOfVertex() throws URISyntaxException, AAIException, UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException { - - final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion()); - final Introspector obj = loader.introspectorFromName("vpn-binding"); - obj.setValue("vpn-id", "deleteKey"); - TransactionalGraphEngine spy = spy(dbEngine); - TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); - Graph g = graph.newTransaction(); - GraphTraversalSource traversal = g.traversal(); - when(spy.asAdmin()).thenReturn(adminSpy); - when(adminSpy.getTraversalSource()).thenReturn(traversal); - when(adminSpy.getReadOnlyTraversalSource()).thenReturn(traversal); - when(spy.tx()).thenReturn(g); - when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop); - when(prop.orElse(null)).thenReturn(obj.getURI()); - DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); - SideEffectRunner runner = new SideEffectRunner - .Builder(spy, serializer).addSideEffect(DataLinkWriter.class).build(); - - runner.execute(obj, self); + } +// runner.execute(obj, self); + //System.out.println("=================\n"); + vertexItr = traversal.V(); + while( vertexItr != null && vertexItr.hasNext() ){ + Vertex v = vertexItr.next(); + //System.out.println("\nnodeType="+v.<String>property("aai-node-type")); + for(String key: v.keys()) { + // System.out.println("label="+v.label()+";key= "+key+";value= "+v.value(key)+"/"+v.id()); + } + Iterator<Edge> edgeItr = v.edges(Direction.BOTH); + while( edgeItr != null && edgeItr.hasNext() ){ + Edge e = edgeItr.next(); + // System.out.println("outV="+e.outVertex().property(AAIProperties.NODE_TYPE)+"/"+e.outVertex().id()+";inV= "+e.inVertex().property(AAIProperties.NODE_TYPE)+"/"+e.inVertex().id()); + } + } + assertThat("new route-target vertex found with/or without link", traversal.V() + .has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "modifyTargetKey2").has("route-target-role", "modifyRoleKey2").hasNext(),is(true)); + assertThat("new route-target vertex found", traversal.V() + .has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "modifyTargetKey2").has("route-target-role", "modifyRoleKey2").has("linked", true).hasNext(),is(true)); + assertThat("previous link removed", traversal.V() + .has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "modifyTargetKey").has("route-target-role", "modifyRoleKey").has("linked").hasNext(),is(not(true))); + assertThat("previous vertex still exists", traversal.V() + .has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "modifyTargetKey").has("route-target-role", "modifyRoleKey").hasNext(),is(true)); + g.tx().rollback(); + + } + + @Test + public void verifyDeleteOfVertex() throws URISyntaxException, AAIException, UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException { + + final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion()); + final Introspector obj = loader.introspectorFromName("vpn-binding"); + obj.setValue("vpn-id", "deleteKey"); + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + Graph g = graph.newTransaction(); + GraphTraversalSource traversal = g.traversal(); + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + when(adminSpy.getReadOnlyTraversalSource()).thenReturn(traversal); + when(spy.tx()).thenReturn(g); + when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop); + when(prop.orElse(null)).thenReturn(obj.getURI()); + DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); + SideEffectRunner runner = new SideEffectRunner + .Builder(spy, serializer).addSideEffect(DataLinkWriter.class).build(); + + runner.execute(obj, self); - assertEquals("route-target vertex not found", false, traversal.V() - .has(AAIProperties.NODE_TYPE, "route-target") - .has("global-route-target", "deleteTargetKey") - .has("route-target-role", "deleteRoleKey") - .has("linked", true) - .hasNext() - ); + assertEquals("route-target vertex not found", false, traversal.V() + .has(AAIProperties.NODE_TYPE, "route-target") + .has("global-route-target", "deleteTargetKey") + .has("route-target-role", "deleteRoleKey") + .has("linked", true) + .hasNext() + ); - g.tx().rollback(); - - } - - @Test - public void verifyPropertyPopulation() throws URISyntaxException, AAIException, UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException { - - final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion()); - final Introspector obj = loader.introspectorFromName("vpn-binding"); - obj.setValue("vpn-id", "getKey"); - TransactionalGraphEngine spy = spy(dbEngine); - TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); - Graph g = graph.newTransaction(); - GraphTraversalSource traversal = g.traversal(); - when(spy.asAdmin()).thenReturn(adminSpy); - when(adminSpy.getTraversalSource()).thenReturn(traversal); - when(spy.tx()).thenReturn(g); - when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop); - when(prop.orElse(null)).thenReturn(obj.getURI()); - DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); - SideEffectRunner runner = new SideEffectRunner - .Builder(spy, serializer).addSideEffect(DataLinkReader.class).build(); - - runner.execute(obj, self); + g.tx().rollback(); + + } + + @Test + public void verifyPropertyPopulation() throws URISyntaxException, AAIException, UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException { + + final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion()); + final Introspector obj = loader.introspectorFromName("vpn-binding"); + obj.setValue("vpn-id", "getKey"); + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + Graph g = graph.newTransaction(); + GraphTraversalSource traversal = g.traversal(); + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + when(spy.tx()).thenReturn(g); + when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop); + when(prop.orElse(null)).thenReturn(obj.getURI()); + DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); + SideEffectRunner runner = new SideEffectRunner + .Builder(spy, serializer).addSideEffect(DataLinkReader.class).build(); + + runner.execute(obj, self); - assertEquals("both properties have been populated in target object", true, obj.getValue("global-route-target").equals("getTargetKey") && obj.getValue("route-target-role").equals("getRoleKey")); - g.tx().rollback(); - - } - - @Test - public void verifyPropertyPopulationWithV10OnlyPut() throws URISyntaxException, AAIException, UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException { - final Introspector obj = loader.introspectorFromName("vpn-binding"); - obj.setValue("vpn-id", "getKeyNoLink"); - final Introspector routeTargets = loader.introspectorFromName("route-targets"); - obj.setValue("route-targets", routeTargets.getUnderlyingObject()); - List<Object> targets = routeTargets.getValue("route-target"); - final Introspector routeTargetOne = loader.introspectorFromName("route-target"); - routeTargetOne.setValue("global-route-target", "getTargetKeyNoLink"); - routeTargetOne.setValue("route-target-role", "getRoleKeyNoLink"); - targets.add(routeTargetOne.getUnderlyingObject()); - final Introspector routeTargetTwo = loader.introspectorFromName("route-target"); - routeTargetTwo.setValue("global-route-target", "getTargetKeyNoLink2"); - routeTargetTwo.setValue("route-target-role", "getRoleKeyNoLink2"); - targets.add(routeTargetTwo.getUnderlyingObject()); - TransactionalGraphEngine spy = spy(dbEngine); - TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); - Graph g = graph.newTransaction(); - GraphTraversalSource traversal = g.traversal(); - when(spy.tx()).thenReturn(g); - when(spy.asAdmin()).thenReturn(adminSpy); - when(adminSpy.getTraversalSource()).thenReturn(traversal); - when(spy.tx()).thenReturn(g); - when(parser.isDependent()).thenReturn(false); - when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop); - when(prop.orElse(null)).thenReturn(obj.getURI()); - DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); - Vertex v = serializer.createNewVertex(obj); - serializer.serializeToDb(obj, v, parser, obj.getURI(), "testing"); - Vertex routeTargetOneV = traversal.V().has("global-route-target", "getTargetKeyNoLink").next(); - Vertex routeTargetTwoV = traversal.V().has("global-route-target", "getTargetKeyNoLink2").next(); + assertEquals("both properties have been populated in target object", true, obj.getValue("global-route-target").equals("getTargetKey") && obj.getValue("route-target-role").equals("getRoleKey")); + g.tx().rollback(); + + } + + @Test + public void verifyPropertyPopulationWithV10OnlyPut() throws URISyntaxException, AAIException, UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException { + final Introspector obj = loader.introspectorFromName("vpn-binding"); + obj.setValue("vpn-id", "getKeyNoLink"); + final Introspector routeTargets = loader.introspectorFromName("route-targets"); + obj.setValue("route-targets", routeTargets.getUnderlyingObject()); + List<Object> targets = routeTargets.getValue("route-target"); + final Introspector routeTargetOne = loader.introspectorFromName("route-target"); + routeTargetOne.setValue("global-route-target", "getTargetKeyNoLink"); + routeTargetOne.setValue("route-target-role", "getRoleKeyNoLink"); + targets.add(routeTargetOne.getUnderlyingObject()); + final Introspector routeTargetTwo = loader.introspectorFromName("route-target"); + routeTargetTwo.setValue("global-route-target", "getTargetKeyNoLink2"); + routeTargetTwo.setValue("route-target-role", "getRoleKeyNoLink2"); + targets.add(routeTargetTwo.getUnderlyingObject()); + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + Graph g = graph.newTransaction(); + GraphTraversalSource traversal = g.traversal(); + when(spy.tx()).thenReturn(g); + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + when(spy.tx()).thenReturn(g); + when(parser.isDependent()).thenReturn(false); + when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop); + when(prop.orElse(null)).thenReturn(obj.getURI()); + DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); + Vertex v = serializer.createNewVertex(obj); + serializer.serializeToDb(obj, v, parser, obj.getURI(), "testing"); + Vertex routeTargetOneV = traversal.V().has("global-route-target", "getTargetKeyNoLink").next(); + Vertex routeTargetTwoV = traversal.V().has("global-route-target", "getTargetKeyNoLink2").next(); - assertEquals("first route target put has linked", true, routeTargetOneV.property(AAIProperties.LINKED).orElse(false)); - assertEquals("second route target put does not have linked", false, routeTargetTwoV.property(AAIProperties.LINKED).orElse(false)); + assertEquals("first route target put has linked", true, routeTargetOneV.property(AAIProperties.LINKED).orElse(false)); + assertEquals("second route target put does not have linked", false, routeTargetTwoV.property(AAIProperties.LINKED).orElse(false)); - g.tx().rollback(); - - } + g.tx().rollback(); + + } } diff --git a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/PrivateEdgeTest.java b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/PrivateEdgeTest.java index bfa77283..5cd1fb53 100644 --- a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/PrivateEdgeTest.java +++ b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/PrivateEdgeTest.java @@ -58,125 +58,125 @@ import static org.mockito.Mockito.when; @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) public class PrivateEdgeTest extends AAISetup{ - private static JanusGraph graph; - private final static ModelType introspectorFactoryType = ModelType.MOXY; - private final static DBConnectionType type = DBConnectionType.REALTIME; - private Loader loader; - private static TransactionalGraphEngine dbEngine; - - - - @Rule - public ExpectedException thrown = ExpectedException.none(); + private static JanusGraph graph; + private final static ModelType introspectorFactoryType = ModelType.MOXY; + private final static DBConnectionType type = DBConnectionType.REALTIME; + private Loader loader; + private static TransactionalGraphEngine dbEngine; + + + + @Rule + public ExpectedException thrown = ExpectedException.none(); - @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} - }); - } - - @BeforeClass - public static void setup() throws Exception { - - graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); - - System.setProperty("AJSC_HOME", "."); - System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local"); - - - - graph.traversal() - .addV("aai-node-type", "model", - "model-invariant-id", "key1", - AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key1").as("v1") - .addV("aai-node-type", "model-ver", - "model-ver", "myValue", - "model-version-id", "key2", - "model-version", "testValue", - AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key1/model-vers/model-ver/key2") - .addOutE("org.onap.relationships.inventory.BelongsTo", "v1", - EdgeProperty.CONTAINS.toString(), true - ) - .addV("aai-node-type", "model", - "model-invariant-id", "key100", - AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key100").as("v5") - .addV("aai-node-type", "model-ver", - "model-ver", "myValue", - "model-version-id", "key200", - "model-version", "testValue", - AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key100/model-vers/model-ver/key200") - .addOutE("org.onap.relationships.inventory.BelongsTo", "v5", - EdgeProperty.CONTAINS.toString(), true - ) - .addV("aai-node-type", "model", - "model-invariant-id", "key3", - AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key3").as("v2") - .addV("aai-node-type", "model-ver", - "model-ver", "myValue", - "model-version-id", "key4", - AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key3/model-vers/model-ver/key4") - .addOutE("org.onap.relationships.inventory.BelongsTo", "v2", - EdgeProperty.CONTAINS.toString(), true - ) - .next(); - graph.tx().commit(); - } - - @AfterClass - public static void tearDown() { - graph.tx().rollback(); - graph.close(); - } - - @Before - public void initMock() { - loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion()); - MockitoAnnotations.initMocks(this); - dbEngine = new JanusGraphDBEngine( - queryStyle, - type, - loader); - } - - @Test - public void testWhenPrivateEdgeThrowsExceptionWhenHavingOnlyOnePartOfKey() throws Exception { - - final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); - final Introspector obj = loader.introspectorFromName("generic-vnf"); - obj.setValue("vnf-id", "myId"); - obj.setValue("model-invariant-id", "key1"); - TransactionalGraphEngine spy = spy(dbEngine); - TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); - Graph g = graph.newTransaction(); - GraphTraversalSource traversal = g.traversal(); - when(spy.asAdmin()).thenReturn(adminSpy); - when(adminSpy.getTraversalSource()).thenReturn(traversal); - - Vertex selfV = traversal.addV( - "aai-node-type", "generic-vnf", - "vnf-id", "myId", - "aai-uri",obj.getURI(), - "model-invariant-id", "key1" - ).next(); - - thrown.expectMessage(containsString("Cannot complete privateEdge uri")); - DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); - PrivateEdge privateEdge = new PrivateEdge(obj, selfV, spy, serializer); - privateEdge.execute(); - - List<Edge> edgeList = traversal.E().has("private", true).toList(); - - assertNull(edgeList); - assertThat(edgeList, is(not(empty()))); - assertThat(edgeList.size(), is(1)); - - g.tx().rollback(); - } + @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} + }); + } + + @BeforeClass + public static void setup() throws Exception { + + graph = JanusGraphFactory.build().set("storage.backend","inmemory").open(); + + System.setProperty("AJSC_HOME", "."); + System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local"); + + + + graph.traversal() + .addV("aai-node-type", "model", + "model-invariant-id", "key1", + AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key1").as("v1") + .addV("aai-node-type", "model-ver", + "model-ver", "myValue", + "model-version-id", "key2", + "model-version", "testValue", + AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key1/model-vers/model-ver/key2") + .addOutE("org.onap.relationships.inventory.BelongsTo", "v1", + EdgeProperty.CONTAINS.toString(), true + ) + .addV("aai-node-type", "model", + "model-invariant-id", "key100", + AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key100").as("v5") + .addV("aai-node-type", "model-ver", + "model-ver", "myValue", + "model-version-id", "key200", + "model-version", "testValue", + AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key100/model-vers/model-ver/key200") + .addOutE("org.onap.relationships.inventory.BelongsTo", "v5", + EdgeProperty.CONTAINS.toString(), true + ) + .addV("aai-node-type", "model", + "model-invariant-id", "key3", + AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key3").as("v2") + .addV("aai-node-type", "model-ver", + "model-ver", "myValue", + "model-version-id", "key4", + AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key3/model-vers/model-ver/key4") + .addOutE("org.onap.relationships.inventory.BelongsTo", "v2", + EdgeProperty.CONTAINS.toString(), true + ) + .next(); + graph.tx().commit(); + } + + @AfterClass + public static void tearDown() { + graph.tx().rollback(); + graph.close(); + } + + @Before + public void initMock() { + loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion()); + MockitoAnnotations.initMocks(this); + dbEngine = new JanusGraphDBEngine( + queryStyle, + type, + loader); + } + + @Test + public void testWhenPrivateEdgeThrowsExceptionWhenHavingOnlyOnePartOfKey() throws Exception { + + final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); + final Introspector obj = loader.introspectorFromName("generic-vnf"); + obj.setValue("vnf-id", "myId"); + obj.setValue("model-invariant-id", "key1"); + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + Graph g = graph.newTransaction(); + GraphTraversalSource traversal = g.traversal(); + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + + Vertex selfV = traversal.addV( + "aai-node-type", "generic-vnf", + "vnf-id", "myId", + "aai-uri",obj.getURI(), + "model-invariant-id", "key1" + ).next(); + + thrown.expectMessage(containsString("Cannot complete privateEdge uri")); + DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST"); + PrivateEdge privateEdge = new PrivateEdge(obj, selfV, spy, serializer); + privateEdge.execute(); + + List<Edge> edgeList = traversal.E().has("private", true).toList(); + + assertNull(edgeList); + assertThat(edgeList, is(not(empty()))); + assertThat(edgeList.size(), is(1)); + + g.tx().rollback(); + } } diff --git a/aai-core/src/test/java/org/onap/aai/introspection/validation/IntrospectorValidationTest.java b/aai-core/src/test/java/org/onap/aai/introspection/validation/IntrospectorValidationTest.java index dac04769..0902aec8 100644 --- a/aai-core/src/test/java/org/onap/aai/introspection/validation/IntrospectorValidationTest.java +++ b/aai-core/src/test/java/org/onap/aai/introspection/validation/IntrospectorValidationTest.java @@ -39,53 +39,53 @@ import static org.junit.Assert.assertEquals; public class IntrospectorValidationTest extends AAISetup { - private final static ModelType introspectorFactoryType = ModelType.MOXY; - private Loader loader; - private IntrospectorValidator validator; - @Autowired - private LoaderFactory loaderFactory; + private final static ModelType introspectorFactoryType = ModelType.MOXY; + private Loader loader; + private IntrospectorValidator validator; + @Autowired + private LoaderFactory loaderFactory; - @Before - public void createValidator() throws Exception { - System.setProperty("AJSC_HOME", "."); - System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local"); - loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getRelatedLinkVersion()); - validator = new IntrospectorValidator.Builder() - .validateRequired(false) - .restrictDepth(10000) - .build(); - } - @Ignore - @Test - public void verifySuccessWhenEmpty() throws AAIException { - Introspector obj = loader.introspectorFromName("generic-vnf"); - obj.setValue("vnf-id", "key1"); - validator.validate(obj); - List<Issue> issues = validator.getIssues(); - assertEquals("no issues found", true, issues.isEmpty()); - } + @Before + public void createValidator() throws Exception { + System.setProperty("AJSC_HOME", "."); + System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local"); + loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getRelatedLinkVersion()); + validator = new IntrospectorValidator.Builder() + .validateRequired(false) + .restrictDepth(10000) + .build(); + } + @Ignore + @Test + public void verifySuccessWhenEmpty() throws AAIException { + Introspector obj = loader.introspectorFromName("generic-vnf"); + obj.setValue("vnf-id", "key1"); + validator.validate(obj); + List<Issue> issues = validator.getIssues(); + assertEquals("no issues found", true, issues.isEmpty()); + } - @Ignore - @Test - public void verifyRequiresSingleFieldFailure() throws AAIException { - Introspector obj = loader.introspectorFromName("generic-vnf"); - obj.setValue("vnf-id", "key1"); - obj.setValue("model-invariant-id", "id1"); - validator.validate(obj); - List<Issue> issues = validator.getIssues(); - assertEquals("issues found", true, issues.size() == 1); - Issue issue = issues.get(0); - assertEquals("found expected issue", IssueType.DEPENDENT_PROP_NOT_FOUND, issue.getType()); - } - @Ignore - @Test - public void verifyRequiresSuccess() throws AAIException { - Introspector obj = loader.introspectorFromName("generic-vnf"); - obj.setValue("vnf-id", "key1"); - obj.setValue("model-invariant-id", "id1"); - obj.setValue("model-version-id", "version-id1"); - validator.validate(obj); - List<Issue> issues = validator.getIssues(); - assertEquals("no issues found", true, issues.isEmpty()); - } + @Ignore + @Test + public void verifyRequiresSingleFieldFailure() throws AAIException { + Introspector obj = loader.introspectorFromName("generic-vnf"); + obj.setValue("vnf-id", "key1"); + obj.setValue("model-invariant-id", "id1"); + validator.validate(obj); + List<Issue> issues = validator.getIssues(); + assertEquals("issues found", true, issues.size() == 1); + Issue issue = issues.get(0); + assertEquals("found expected issue", IssueType.DEPENDENT_PROP_NOT_FOUND, issue.getType()); + } + @Ignore + @Test + public void verifyRequiresSuccess() throws AAIException { + Introspector obj = loader.introspectorFromName("generic-vnf"); + obj.setValue("vnf-id", "key1"); + obj.setValue("model-invariant-id", "id1"); + obj.setValue("model-version-id", "version-id1"); + validator.validate(obj); + List<Issue> issues = validator.getIssues(); + assertEquals("no issues found", true, issues.isEmpty()); + } } diff --git a/aai-core/src/test/java/org/onap/aai/logging/CustomLogPatternLayoutTest.java b/aai-core/src/test/java/org/onap/aai/logging/CustomLogPatternLayoutTest.java index b4d14d30..198bb064 100644 --- a/aai-core/src/test/java/org/onap/aai/logging/CustomLogPatternLayoutTest.java +++ b/aai-core/src/test/java/org/onap/aai/logging/CustomLogPatternLayoutTest.java @@ -27,24 +27,24 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; public class CustomLogPatternLayoutTest { - - /** - * Test null when defaultConverterMap doesn't have corresponding entry. - */ - @Test - public void testNull(){ - String s = CustomLogPatternLayout.defaultConverterMap.get("z"); - assertFalse("Entry not found for key 'z'", CNName.class.getName().equals(s)); - } - - /** - * Test defaultConverterMap when valid entry exists. - */ - @Test - public void testEntryFor_Z(){ - CustomLogPatternLayout layout = new CustomLogPatternLayout(); - String s = CustomLogPatternLayout.defaultConverterMap.get("z"); - assertTrue("Entry not found for key 'z'", CNName.class.getName().equals(s)); - } + + /** + * Test null when defaultConverterMap doesn't have corresponding entry. + */ + @Test + public void testNull(){ + String s = CustomLogPatternLayout.defaultConverterMap.get("z"); + assertFalse("Entry not found for key 'z'", CNName.class.getName().equals(s)); + } + + /** + * Test defaultConverterMap when valid entry exists. + */ + @Test + public void testEntryFor_Z(){ + CustomLogPatternLayout layout = new CustomLogPatternLayout(); + String s = CustomLogPatternLayout.defaultConverterMap.get("z"); + assertTrue("Entry not found for key 'z'", CNName.class.getName().equals(s)); + } } diff --git a/aai-core/src/test/java/org/onap/aai/logging/EcompErrorCategoryTest.java b/aai-core/src/test/java/org/onap/aai/logging/EcompErrorCategoryTest.java index eaa8a536..b29cf51f 100644 --- a/aai-core/src/test/java/org/onap/aai/logging/EcompErrorCategoryTest.java +++ b/aai-core/src/test/java/org/onap/aai/logging/EcompErrorCategoryTest.java @@ -29,7 +29,7 @@ import org.junit.*; public class EcompErrorCategoryTest { - EcompErrorCategory _ecompErrorCategory; + EcompErrorCategory _ecompErrorCategory; ILoggingEvent mockEvent; @Before @@ -41,7 +41,7 @@ public class EcompErrorCategoryTest { } @Test public void warn(){ - String defaultCategory = "WARN"; + String defaultCategory = "WARN"; assertEquals(_ecompErrorCategory.convert(mockEvent), defaultCategory); } diff --git a/aai-core/src/test/java/org/onap/aai/logging/EcompResponseCodeTest.java b/aai-core/src/test/java/org/onap/aai/logging/EcompResponseCodeTest.java index 0bdfc748..10edb456 100644 --- a/aai-core/src/test/java/org/onap/aai/logging/EcompResponseCodeTest.java +++ b/aai-core/src/test/java/org/onap/aai/logging/EcompResponseCodeTest.java @@ -29,7 +29,7 @@ import org.junit.*; public class EcompResponseCodeTest { - EcompResponseCode _ecompResponseCode; + EcompResponseCode _ecompResponseCode; ILoggingEvent mockEvent; @Before diff --git a/aai-core/src/test/java/org/onap/aai/logging/ErrorObjectTest.java b/aai-core/src/test/java/org/onap/aai/logging/ErrorObjectTest.java index ea361606..8db1ece9 100644 --- a/aai-core/src/test/java/org/onap/aai/logging/ErrorObjectTest.java +++ b/aai-core/src/test/java/org/onap/aai/logging/ErrorObjectTest.java @@ -26,136 +26,136 @@ import static org.junit.Assert.*; import org.junit.*; public class ErrorObjectTest { - - ErrorObject newErrorObject = new ErrorObject("disposition","category","severity", 200, "restErrorCode","errorCode","errorText"); - - //Constructor Tests - @Test - public void createObjectTest1(){ - //No HTTP Status argument - ErrorObject errorObject = new ErrorObject("severity","errorcode","errortext","disposition","category"); - assertNotNull(errorObject); - } - @Test - public void createObjectTest2(){ - //HTTP Status code as integer - ErrorObject errorObject = new ErrorObject("severity",200,"errorcode","errortext","disposition","category"); - assertNotNull(errorObject); - } - @Test - public void createObjectTest3(){ - //HTTP Status code as Status - ErrorObject errorObject = new ErrorObject("severity",Status.OK,"errorcode","errortext","disposition","category"); - assertNotNull(errorObject); - } - //Disposition Tests - @Test - public void getDispositionTest() { - assertEquals(newErrorObject.getDisposition(), "disposition"); - } - @Test - public void setDispositionTest() { - newErrorObject.setDisposition("newDisposition"); - assertEquals(newErrorObject.getDisposition(), "newDisposition"); - } - - //Category Tests - @Test - public void getCategoryTest(){ - assertEquals(newErrorObject.getCategory(), "category"); - } - @Test - public void setCategoryTest(){ - newErrorObject.setCategory("newCategory"); - assertEquals(newErrorObject.getCategory(), "newCategory"); - } - - //Severity Tests - @Test - public void getSeverityTest(){ - assertEquals(newErrorObject.getSeverity(), "severity"); - } - @Test - public void setSeverityTest(){ - newErrorObject.setSeverity("newSeverity"); - assertEquals(newErrorObject.getSeverity(), "newSeverity"); - } - - //Error Code Tests - @Test - public void getErrorCodeTest(){ - assertEquals(newErrorObject.getErrorCode(), "errorCode"); - } - @Test - public void SetErrorCodeTest(){ - newErrorObject.setErrorCode("newErrorCode"); - assertEquals(newErrorObject.getErrorCode(), "newErrorCode"); - } - - //HTTP Response Code Tests - @Test - public void getHTTPCodeTest(){ - assertEquals(newErrorObject.getHTTPResponseCode(), Status.OK); - } - @Test - public void setHTTPCodeTest(){ - newErrorObject.setHTTPResponseCode(201); - assertEquals(newErrorObject.getHTTPResponseCode(), Status.CREATED); - } - @Test(expected=IllegalArgumentException.class) - public void invalidHttpCodeTest(){ - newErrorObject.setHTTPResponseCode(6281723); - } - @Test(expected=IllegalArgumentException.class) - public void invalidHttpCodeTest2(){ - newErrorObject.setHTTPResponseCode("82901"); - } - - //Rest Error Code Tests - @Test - public void getRestErrorCodeTest(){ - assertEquals(newErrorObject.getRESTErrorCode(), "restErrorCode"); - } - @Test - public void setRestErrorCodeTest(){ - newErrorObject.setRESTErrorCode("newRestErrorCode"); - assertEquals(newErrorObject.getRESTErrorCode(), "newRestErrorCode"); - } - - //Error Text Tests - @Test - public void getErrorTextTest(){ - assertEquals(newErrorObject.getErrorText(), "errorText"); - } - @Test - public void setErrorTextTest(){ - newErrorObject.setErrorText("newErrorText"); - assertEquals(newErrorObject.getErrorText(), "newErrorText"); - } - @Test - public void getErrorCodeStringTest(){ - assertEquals(newErrorObject.getErrorCodeString(), "disposition.category.errorCode"); - } - @Test - public void getErrorCodeStringDisposition5Test(){ - //get Error Code String while Disposition = 5 - newErrorObject.setDisposition("5"); - assertEquals(newErrorObject.getErrorCodeString(), "ERR.5.category.errorCode"); - } - @Test - public void getSeverityCodeTest(){ - newErrorObject.setSeverity("WARN"); - assertEquals(newErrorObject.getSeverityCode(newErrorObject.getSeverity()), "1"); - - newErrorObject.setSeverity("ERROR"); - assertEquals(newErrorObject.getSeverityCode(newErrorObject.getSeverity()), "2"); - - newErrorObject.setSeverity("FATAL"); - assertEquals(newErrorObject.getSeverityCode(newErrorObject.getSeverity()), "3"); - } - //To String Test - @Test - public void toStringTest(){ - assertEquals(newErrorObject.toString(), "ErrorObject [errorCode=errorCode, errorText=errorText, restErrorCode=restErrorCode, httpResponseCode=OK, severity=severity, disposition=disposition, category=category]"); - } + + ErrorObject newErrorObject = new ErrorObject("disposition","category","severity", 200, "restErrorCode","errorCode","errorText"); + + //Constructor Tests + @Test + public void createObjectTest1(){ + //No HTTP Status argument + ErrorObject errorObject = new ErrorObject("severity","errorcode","errortext","disposition","category"); + assertNotNull(errorObject); + } + @Test + public void createObjectTest2(){ + //HTTP Status code as integer + ErrorObject errorObject = new ErrorObject("severity",200,"errorcode","errortext","disposition","category"); + assertNotNull(errorObject); + } + @Test + public void createObjectTest3(){ + //HTTP Status code as Status + ErrorObject errorObject = new ErrorObject("severity",Status.OK,"errorcode","errortext","disposition","category"); + assertNotNull(errorObject); + } + //Disposition Tests + @Test + public void getDispositionTest() { + assertEquals(newErrorObject.getDisposition(), "disposition"); + } + @Test + public void setDispositionTest() { + newErrorObject.setDisposition("newDisposition"); + assertEquals(newErrorObject.getDisposition(), "newDisposition"); + } + + //Category Tests + @Test + public void getCategoryTest(){ + assertEquals(newErrorObject.getCategory(), "category"); + } + @Test + public void setCategoryTest(){ + newErrorObject.setCategory("newCategory"); + assertEquals(newErrorObject.getCategory(), "newCategory"); + } + + //Severity Tests + @Test + public void getSeverityTest(){ + assertEquals(newErrorObject.getSeverity(), "severity"); + } + @Test + public void setSeverityTest(){ + newErrorObject.setSeverity("newSeverity"); + assertEquals(newErrorObject.getSeverity(), "newSeverity"); + } + + //Error Code Tests + @Test + public void getErrorCodeTest(){ + assertEquals(newErrorObject.getErrorCode(), "errorCode"); + } + @Test + public void SetErrorCodeTest(){ + newErrorObject.setErrorCode("newErrorCode"); + assertEquals(newErrorObject.getErrorCode(), "newErrorCode"); + } + + //HTTP Response Code Tests + @Test + public void getHTTPCodeTest(){ + assertEquals(newErrorObject.getHTTPResponseCode(), Status.OK); + } + @Test + public void setHTTPCodeTest(){ + newErrorObject.setHTTPResponseCode(201); + assertEquals(newErrorObject.getHTTPResponseCode(), Status.CREATED); + } + @Test(expected=IllegalArgumentException.class) + public void invalidHttpCodeTest(){ + newErrorObject.setHTTPResponseCode(6281723); + } + @Test(expected=IllegalArgumentException.class) + public void invalidHttpCodeTest2(){ + newErrorObject.setHTTPResponseCode("82901"); + } + + //Rest Error Code Tests + @Test + public void getRestErrorCodeTest(){ + assertEquals(newErrorObject.getRESTErrorCode(), "restErrorCode"); + } + @Test + public void setRestErrorCodeTest(){ + newErrorObject.setRESTErrorCode("newRestErrorCode"); + assertEquals(newErrorObject.getRESTErrorCode(), "newRestErrorCode"); + } + + //Error Text Tests + @Test + public void getErrorTextTest(){ + assertEquals(newErrorObject.getErrorText(), "errorText"); + } + @Test + public void setErrorTextTest(){ + newErrorObject.setErrorText("newErrorText"); + assertEquals(newErrorObject.getErrorText(), "newErrorText"); + } + @Test + public void getErrorCodeStringTest(){ + assertEquals(newErrorObject.getErrorCodeString(), "disposition.category.errorCode"); + } + @Test + public void getErrorCodeStringDisposition5Test(){ + //get Error Code String while Disposition = 5 + newErrorObject.setDisposition("5"); + assertEquals(newErrorObject.getErrorCodeString(), "ERR.5.category.errorCode"); + } + @Test + public void getSeverityCodeTest(){ + newErrorObject.setSeverity("WARN"); + assertEquals(newErrorObject.getSeverityCode(newErrorObject.getSeverity()), "1"); + + newErrorObject.setSeverity("ERROR"); + assertEquals(newErrorObject.getSeverityCode(newErrorObject.getSeverity()), "2"); + + newErrorObject.setSeverity("FATAL"); + assertEquals(newErrorObject.getSeverityCode(newErrorObject.getSeverity()), "3"); + } + //To String Test + @Test + public void toStringTest(){ + assertEquals(newErrorObject.toString(), "ErrorObject [errorCode=errorCode, errorText=errorText, restErrorCode=restErrorCode, httpResponseCode=OK, severity=severity, disposition=disposition, category=category]"); + } } diff --git a/aai-core/src/test/java/org/onap/aai/logging/LoggingContextTest.java b/aai-core/src/test/java/org/onap/aai/logging/LoggingContextTest.java index 1aafa4a1..0e2a1c3d 100644 --- a/aai-core/src/test/java/org/onap/aai/logging/LoggingContextTest.java +++ b/aai-core/src/test/java/org/onap/aai/logging/LoggingContextTest.java @@ -27,80 +27,80 @@ import static org.junit.Assert.*; public class LoggingContextTest { - private static final int MAX_STORED_CONTEXTS = 100; + private static final int MAX_STORED_CONTEXTS = 100; - @Test - public void testStopWatch() { - try { - LoggingContext.stopWatchStop(); - throw new AssertionError("No exception thrown when LoggingContext.stopWatchStop() called without a prior LoggingContext.stopWatchStart()"); - } catch (StopWatchNotStartedException e) { - //Expected - } + @Test + public void testStopWatch() { + try { + LoggingContext.stopWatchStop(); + throw new AssertionError("No exception thrown when LoggingContext.stopWatchStop() called without a prior LoggingContext.stopWatchStart()"); + } catch (StopWatchNotStartedException e) { + //Expected + } - LoggingContext.stopWatchStart(); + LoggingContext.stopWatchStart(); - assertTrue(LoggingContext.stopWatchStop() >= 0); + assertTrue(LoggingContext.stopWatchStop() >= 0); - try { - LoggingContext.stopWatchStop(); - throw new AssertionError("No exception thrown when LoggingContext.stopWatchStop() twice in succession"); - } catch (StopWatchNotStartedException e) { - //Expected - } - } + try { + LoggingContext.stopWatchStop(); + throw new AssertionError("No exception thrown when LoggingContext.stopWatchStop() twice in succession"); + } catch (StopWatchNotStartedException e) { + //Expected + } + } - @Test - public void testRequestId() { //AKA Transaction ID - final String sUuid = "57d51eaa-edc6-4f50-a69d-f2d4d2445120"; + @Test + public void testRequestId() { //AKA Transaction ID + final String sUuid = "57d51eaa-edc6-4f50-a69d-f2d4d2445120"; - LoggingContext.requestId(sUuid); + LoggingContext.requestId(sUuid); - assertEquals(LoggingContext.requestId(), UUID.fromString(sUuid)); + assertEquals(LoggingContext.requestId(), UUID.fromString(sUuid)); - final UUID uuid = UUID.randomUUID(); + final UUID uuid = UUID.randomUUID(); - LoggingContext.requestId(uuid); + LoggingContext.requestId(uuid); - assertEquals(LoggingContext.requestId(), uuid); + assertEquals(LoggingContext.requestId(), uuid); - LoggingContext.requestId("foo"); //Illegal - this will result in a new, randomly - //generated UUID as per the logging spec + LoggingContext.requestId("foo"); //Illegal - this will result in a new, randomly + //generated UUID as per the logging spec - assertNotNull(LoggingContext.requestId()); //Make sure ANY UUID was assigned - assertNotEquals(LoggingContext.requestId(), uuid); //Make sure it actually changed from the last - //known valid UUID - } + assertNotNull(LoggingContext.requestId()); //Make sure ANY UUID was assigned + assertNotEquals(LoggingContext.requestId(), uuid); //Make sure it actually changed from the last + //known valid UUID + } - @Test - public void testClear() { - LoggingContext.init(); - LoggingContext.clear(); + @Test + public void testClear() { + LoggingContext.init(); + LoggingContext.clear(); - assertEquals(Collections.emptyMap(), LoggingContext.getCopy()); - } + assertEquals(Collections.emptyMap(), LoggingContext.getCopy()); + } - @Test - public void testSaveRestore() { + @Test + public void testSaveRestore() { - final Deque<Map<String, String>> contexts = new LinkedList<Map<String, String>> (); + final Deque<Map<String, String>> contexts = new LinkedList<Map<String, String>> (); - LoggingContext.init(); + LoggingContext.init(); - for (int i = 0; i < MAX_STORED_CONTEXTS; i++) { - LoggingContext.customField1(String.valueOf(i)); - - assertEquals(LoggingContext.customField1(), String.valueOf(i)); + for (int i = 0; i < MAX_STORED_CONTEXTS; i++) { + LoggingContext.customField1(String.valueOf(i)); + + assertEquals(LoggingContext.customField1(), String.valueOf(i)); - LoggingContext.save(); + LoggingContext.save(); - contexts.push(LoggingContext.getCopy()); - } + contexts.push(LoggingContext.getCopy()); + } - while (contexts.peek() != null) { - LoggingContext.restore(); + while (contexts.peek() != null) { + LoggingContext.restore(); - assertEquals(LoggingContext.getCopy(), contexts.pop()); - } - } + assertEquals(LoggingContext.getCopy(), contexts.pop()); + } + } } 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); + + } } |