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("v8");
+ version = new SchemaVersion("v10");
dbEngine =
new JanusGraphDBEngine(QueryStyle.GREMLIN_TRAVERSAL,
loaderFactory.createLoaderForVersion(ModelType.MOXY, version),
false);
}
-
+
/**
* Parent query.
*
*/
@Test
public void parentQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
-
+
String content =
"{"
+ "\"related-to\" : \"pserver\","
+ "\"relationship-value\" : \"key1\""
+ "}]"
+ "}";
-
+
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
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 =
+ String expected =
".has('hostname', 'key1').has('aai-node-type', 'pserver')";
assertEquals(
"gremlin query should be " + expected,
"result type should be pserver",
"pserver",
query.getResultType());
-
+
}
/**
+ "\"relationship-value\" : \"key2\""
+ "}]"
+ "}";
-
+
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
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);
"lag-interface",
query.getResultType());
}
-
+
/**
* Naming exceptions.
*
+ "\"relationship-value\" : \"655\""
+ "}]"
+ "}";
-
+
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
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 =
+ 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 =
+ 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')";
"result type should be cvlan-tag",
"cvlan-tag",
query.getResultType());
-
+
}
-
+
/**
* Scrambled relationship.
*
+ "}";
scrambledRelationshipSpec(content);
}
-
+
/**
* Reversed relationship.
*
+ "}";
scrambledRelationshipSpec(content);
}
-
+
/**
* Ordered ambiguous relationship.
*
+ "}";
scrambledRelationshipSpec(content);
}
-
+
/**
* Scrambled relationship spec.
*
*/
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);
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 =
+ 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 =
+ 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')"
"result type should be l3-interface-ipv4-address-list",
"l3-interface-ipv4-address-list",
query.getResultType());
-
+
}
-
+
/**
* Short circuit.
*
+ "\"relationship-value\" : \"655\""
+ "}]"
+ "}";
-
+
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
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 =
+ 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 =
+ 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')";
"result type should be cvlan-tag",
"cvlan-tag",
query.getResultType());
-
+
}
-
+
@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);
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 =
+ 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 =
+ 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')";
"result type should be cvlan-tag",
"cvlan-tag",
query.getResultType());
-
+
}
-
+
/**
* Double key.
*
+ "\"relationship-value\" : \"key3\""
+ "}]"
+ "}";
-
-
+
+
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
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 =
+ 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 =
+ String expectedParent =
".has('physical-location-id', 'key1').has('aai-node-type', 'complex')";
assertEquals(
"result type should be ctag-pool",
"ctag-pool",
query.getResultType());
-
+
}
-
+
/**
* Abstract type.
*
+ "\"relationship-value\" : \"key1\""
+ " }]"
+ "}";
-
-
+
+
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
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 =
+ String expected =
".has('vnf-id', 'key1')"
+ ".has('aai-node-type', P.within('vce','generic-vnf'))";
-
- String expectedParent =
+
+ String expectedParent =
".has('vnf-id', 'key1')"
+ ".has('aai-node-type', P.within('vce','generic-vnf'))";
-
+
assertEquals(
"gremlin query should be " + expected,
expected,
"result type should be vnf",
"vnf",
query.getResultType());
-
+
}
-
+
/**
* Invalid node name.
*
+ "}";
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);
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.
*
+ "}";
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);
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);