From 778454ba2e51e883959a4d8e284de0bdbe4945fb Mon Sep 17 00:00:00 2001 From: Douwe <d.geurtjens@students.uu.nl> Date: Thu, 4 Nov 2021 11:12:10 +0100 Subject: [PATCH] Unit tests now use new new json format --- aql/convertQuery_test.go | 1079 +++++++++++++++++++++++--------------- 1 file changed, 657 insertions(+), 422 deletions(-) diff --git a/aql/convertQuery_test.go b/aql/convertQuery_test.go index 70b0165..c2768ea 100644 --- a/aql/convertQuery_test.go +++ b/aql/convertQuery_test.go @@ -31,6 +31,8 @@ func TestEmptyQueryConversion(t *testing.T) { }, "entities": [], "relations": [], + "groupBys": [], + "filters": [], "limit": 5000 }`) @@ -63,55 +65,59 @@ func TestMultipleEntityTypes(t *testing.T) { query := []byte(`{ "databaseName": "test", "return": { - "entities": [ - 0, - 1 - ], - "relations": [ - 0 - ] + "entities": [ + 0, + 1 + ], + "relations": [ + 0 + ] }, "entities": [ - { - "type": "kamerleden", - "ID": 0 - ] - }, - { - "type": "partijen", - "ID": 1 - ] - } + { + "type": "kamerleden", + "ID": 0 + }, + { + "type": "partijen", + "ID": 1 + } ], "relations": [ - { - "type": "lid_van", - "depth": { - "min": 1, - "max": 1 - }, - "FromType": "entity", - "FromID": 0, - "ToType": "entity", - "ToID": 1 - } + { + "ID": 0 + "type": "lid_van", + "depth": { + "min": 1, + "max": 1 + }, + "fromType": "entity", + "fromID": 0, + "toType": "entity", + "toID": 1 + } ], + "groupBys": [], "filters": [ { "ID": 0, - "FilteredType": "entity", - "FilteredID": 0, - "Attribute": "partij", - "Value": "GL", - "DataType": "string", - "MatchType": "exact" , - "InType": "", - "InID": -1 + "fromType": "entity", + "fromID": 0, + "toType": "relation", + "toID": 0, + "attribute": "partij", + "value": "GL", + "dataType": "string", + "matchType": "exact", + "inType": "", + "inID": -1 }, { "ID": 1, - "filteredType": "entity", - "filteredID": 1, + "fromType": "entity", + "fromID": 1, + "toType": "relation", + "toID": 0, "attribute": "zetels", "value": "6", "dataType": "int", @@ -119,10 +125,10 @@ func TestMultipleEntityTypes(t *testing.T) { "inType": "", "inID": -1 } - ] + ], "limit": 5000, "modifiers": [] - }`) + }`) // Unmarshall the incoming message into an IncomingJSONQuery object var JSONQuery entity.IncomingQueryJSON @@ -163,17 +169,26 @@ func TestEntityOneAttributeQuery(t *testing.T) { "entities": [ { "type": "airports", - "constraints": [ - { - "attribute": "state", - "value": "HI", - "dataType": "string", - "matchType": "exact" - } - ] + "ID": 0 } ], + "groupBys": [], "relations": [], + "filters": [ + { + "ID": 0, + "fromType": "entity", + "fromID": 0, + "toType": "", + "toID": -1, + "attribute": "state", + "value": "HI", + "dataType": "string", + "matchType": "exact", + "inType": "", + "inID": -1 + } + ], "limit": 5000 }`) @@ -213,6 +228,7 @@ func TestRelationWithConstraint(t *testing.T) { }, "entities": [ { + "ID": 0, "type": "airports", "constraints": [ { @@ -226,23 +242,39 @@ func TestRelationWithConstraint(t *testing.T) { ], "relations": [ { + "ID": 0, "type": "flights", "depth": { "min": 1, "max": 1 }, - "entityFrom": 0, - "entityTo": -1, + "FromType": "entity", + "fromID": 0, + "ToType": "", + "toID": -1, "constraints": [ { - "attribute": "Day", - "value": "15", - "dataType": "int", - "matchType": "EQ" + } ] } ], + "groupBys": [], + "filters": [ + { + "ID": 0, + "fromType": "entity", + "fromID": 0, + "toType": "relation", + "toID": 0, + "attribute": "Day", + "value": "15", + "dataType": "int", + "matchType": "EQ", + "inType": "", + "inID": -1 + } + ], "limit": 5000 }`) @@ -280,18 +312,30 @@ func TestModifierCountEntity(t *testing.T) { }, "entities": [ { + "ID": 0, "type": "airports", "constraints": [ - { - "attribute": "state", - "value": "HI", - "dataType": "string", - "matchType": "exact" - } + {} ] } ], "relations": [], + "groupBys": [], + "filters": [ + { + "ID": 0, + "fromType": "entity", + "fromID": 0, + "toType": "relation", + "toID": 0, + "attribute": "state", + "value": "HI", + "dataType": "string", + "matchType": "exact", + "inType": "", + "inID": -1 + } + ], "limit": 5000, "modifiers": [ { @@ -337,18 +381,27 @@ func TestModifierCountEntityAttribute(t *testing.T) { }, "entities": [ { - "type": "airports", - "constraints": [ - { - "attribute": "state", - "value": "HI", - "dataType": "string", - "matchType": "exact" - } - ] + "ID": 0, + "type": "airports" } ], "relations": [], + "groupBys": [], + "filters": [ + { + "ID": 0, + "fromType": "entity", + "fromID": 0, + "toType": "", + "toID": -1, + "attribute": "state", + "value": "HI", + "dataType": "string", + "matchType": "exact", + "inType": "", + "inID": -1 + } + ], "limit": 5000, "modifiers": [ { @@ -396,34 +449,51 @@ func TestModifierCountRelation(t *testing.T) { }, "entities": [ { - "type": "airports", - "constraints": [ - { - "attribute": "state", - "value": "HI", - "dataType": "string", - "matchType": "exact" - } - ] + "ID": 0, + "type": "airports" } ], "relations": [ { + "ID": 0, "type": "flights", "depth": { "min": 1, "max": 1 }, - "entityFrom": 0, - "entityTo": -1, - "constraints": [ - { - "attribute": "Day", - "value": "15", - "dataType": "int", - "matchType": "EQ" - } - ] + "fromType": "entity", + "fromID": 0, + "toType": "", + "toID": -1 + } + ], + "groupBys": [], + "filters": [ + { + "ID": 0, + "fromType": "entity", + "fromID": 0, + "toType": "relation", + "toID": 0, + "attribute": "state", + "value": "HI", + "dataType": "string", + "matchType": "exact", + "inType": "", + "inID": -1 + }, + { + "ID": 1, + "fromType": "relation", + "fromID": 0, + "toType": "entity", + "toID": 0, + "attribute": "Day", + "value": "15", + "dataType": "int", + "matchType": "EQ", + "inType": "", + "inID": -1 } ], "limit": 5000, @@ -465,46 +535,50 @@ func TestModifierCountEntitySwap(t *testing.T) { query := []byte(`{ "databaseName": "TweedeKamer", "return": { - "entities": [ - 0, - 1 - ], - "relations": [ - 0 - ] + "entities": [ + 0, + 1 + ], + "relations": [ + 0 + ] }, "entities": [ - { - "type": "partijen", - "constraints": [] - }, - { - "type": "kamerleden", - "constraints": [] - } + { + "ID": 0, + "type": "partijen" + }, + { + "ID": 1, + "type": "kamerleden" + } ], "relations": [ - { - "type": "lid_van", - "depth": { - "min": 1, - "max": 1 - }, - "entityFrom": 1, - "entityTo": 0, - "constraints": [] - } + { + "ID": 0, + "type": "lid_van", + "depth": { + "min": 1, + "max": 1 + }, + "fromType": "entity", + "fromID": 1, + "toType": "entity", + "toID": 0 + } ], + "groupBys": [], + "filters": [], "limit": 5000, "modifiers": [ - { - "type": "COUNT", - "selectedType": "entity", - "selectedTypeId": 1, - "attributeIndex": -1 - } + { + "type": "COUNT", + "selectedType": "entity", + "selectedTypeId": 1, + "attributeIndex": -1 + } ] - }`) + }`) // Unmarshall the incoming message into an IncomingJSONQuery object var JSONQuery entity.IncomingQueryJSON @@ -541,34 +615,53 @@ func TestModifierCountRelationAttribute(t *testing.T) { }, "entities": [ { - "type": "airports", - "constraints": [ - { - "attribute": "state", - "value": "HI", - "dataType": "string", - "matchType": "exact" - } - ] + "ID": 0, + "type": "airports" } ], "relations": [ { + "ID":0, "type": "flights", "depth": { "min": 1, "max": 1 }, - "entityFrom": 0, - "entityTo": -1, - "constraints": [ - { - "attribute": "Day", - "value": "15", - "dataType": "int", - "matchType": "EQ" - } - ] + "fromType": "entity", + "fromID": 0, + "toType": "", + "toID": -1 + } + ], + "groupBys": [ + + ], + "filters": [ + { + "ID": 0, + "fromType": "entity", + "fromID": 0, + "toType": "relation", + "toID": 0, + "attribute": "state", + "value": "HI", + "dataType": "string", + "matchType": "exact", + "inType": "", + "inID": -1 + }, + { + "ID": 1, + "fromType": "relation", + "fromID": 0, + "toType": "", + "toID": -1, + "attribute": "Day", + "value": "15", + "dataType": "int", + "matchType": "EQ", + "inType": "", + "inID": -1 } ], "limit": 5000, @@ -619,6 +712,7 @@ func TestRelationWithInOutConstraint(t *testing.T) { }, "entities": [ { + "ID": 0, "type": "airports", "constraints": [ { @@ -630,6 +724,7 @@ func TestRelationWithInOutConstraint(t *testing.T) { ] }, { + "ID": 1, "type": "airports", "constraints": [ { @@ -643,22 +738,60 @@ func TestRelationWithInOutConstraint(t *testing.T) { ], "relations": [ { + "ID":0, "type": "flights", "depth": { "min": 1, "max": 3 }, - "entityFrom": 1, - "entityTo": 0, - "constraints": [ - { - "attribute": "Day", - "value": "15", - "dataType": "int", - "matchType": "EQ" - } - ] + "fromType": "entity", + "fromID": 1, + "toType": "entity", + "toID": 0 } + ], + "groupBys": [], + "filters": [ + { + "ID": 0, + "fromType": "entity", + "fromID": 0, + "toType": "relation", + "toID": 0, + "attribute": "city", + "value": "San Francisco", + "dataType": "string", + "matchType": "exact", + "inType": "", + "inID": -1 + }, + { + "ID": 1, + "fromType": "entity", + "fromID": 1, + "toType": "relation", + "toID": 0, + "attribute": "state", + "value": "HI", + "dataType": "string", + "matchType": "exact", + "inType": "", + "inID": -1 + }, { + "ID": 2, + "fromType": "relation", + "fromID": 0, + "toType": "", + "toID": -1, + "attribute": "Day", + "value": "15", + "dataType": "int", + "matchType": "EQ", + "inType": "", + "inID": -1 + } + + ], "limit": 5000 }`) @@ -702,67 +835,100 @@ func TestTwoRelations(t *testing.T) { }, "entities": [ { - "type": "airports", - "constraints": [ - { - "attribute": "city", - "value": "New York", - "dataType": "string", - "matchType": "exact" - } - ] + "ID": 0, + "type": "airports" }, { - "type": "airports", - "constraints": [ - { - "attribute": "city", - "value": "San Francisco", - "dataType": "string", - "matchType": "exact" - } - ] + "ID": 1, + "type": "airports" }, { - "type": "airports", - "constraints": [ - { - "attribute": "state", - "value": "HI", - "dataType": "string", - "matchType": "exact" - } - ] + "ID": 2, + "type": "airports" } ], "relations": [ { + "ID": 0, "type": "flights", "depth": { "min": 1, "max": 3 }, - "entityFrom": 2, - "entityTo": 1, - "constraints": [ - { - "attribute": "Day", - "value": "15", - "dataType": "int", - "matchType": "EQ" - } - ] + "fromType": "entity", + "fromID": 2, + "toType": "entity", + "toID": 1 }, { + "ID":1, "type": "flights", "depth": { "min": 1, "max": 1 }, - "entityFrom": 0, - "entityTo": -1, - "constraints": [] + "fromType": "entity", + "fromID": 0, + "toType": "", + "toID": -1 } + ], + "groupBys": [], + "filters": [ + { + "ID": 0, + "fromType": "entity", + "fromID": 0, + "toType": "relation", + "toID": 1, + "attribute": "city", + "value": "New York", + "dataType": "string", + "matchType": "exact", + "inType": "", + "inID": -1 + }, + { + "ID": 1, + "fromType": "entity", + "fromID": 1, + "toType": "relation", + "toID": 0, + "attribute": "city", + "value": "San Francisco", + "dataType": "string", + "matchType": "exact", + "inType": "", + "inID": -1 + }, + { + "ID": 2, + "fromType": "entity", + "fromID": 2, + "toType": "relation", + "toID": 0, + "attribute": "state", + "value": "HI", + "dataType": "string", + "matchType": "exact", + "inType": "", + "inID": -1 + }, + { + "ID": 3, + "fromType": "relation", + "fromID": 0, + "toType": "", + "toID": -1, + "attribute": "Day", + "value": "15", + "dataType": "int", + "matchType": "EQ", + "inType": "", + "inID": -1 + } + + ], "limit": 5000 }`) @@ -793,41 +959,52 @@ func TestRelationWithOnlyToNode(t *testing.T) { service := NewService() query := []byte(`{ - "return": { - "entities": [ - 0 - ], - "relations": [ - 0 - ] - }, + "return": { "entities": [ - { - "type": "airports", - "constraints": [ - { - "attribute": "city", - "value": "San Francisco", - "dataType": "string", - "matchType": "exact" - } - ] - } + 0 ], "relations": [ - { - "type": "flights", - "depth": { - "min": 1, - "max": 1 - }, - "entityFrom": -1, - "entityTo": 0, - "constraints": [] - } - ], - "limit": 5000 - }`) + 0 + ] + }, + "entities": [ + { + "ID": 0, + "type": "airports" + } + ], + "relations": [ + { + "ID": 0, + "type": "flights", + "depth": { + "min": 1, + "max": 1 + }, + "fromType": "", + "fromID": -1, + "toType": "entity", + "toID": 0 + } + ], + "groupBys": [], + "filters": [ + { + "ID": 0, + "fromType": "entity", + "fromID": 0, + "toType": "relation", + "toID": 0, + "attribute": "city", + "value": "San Francisco", + "dataType": "string", + "matchType": "exact", + "inType": "", + "inID": -1 + } + ], + "limit": 5000 + }`) // Unmarshall the incoming message into an IncomingJSONQuery object var JSONQuery entity.IncomingQueryJSON @@ -855,43 +1032,54 @@ func TestTooManyReturnEntities(t *testing.T) { service := NewService() query := []byte(`{ - "return": { - "entities": [ - 0, - 1, - 2 - ], - "relations": [ - 0 - ] - }, + "return": { "entities": [ - { - "type": "airports", - "constraints": [ - { - "attribute": "city", - "value": "San Francisco", - "dataType": "string", - "matchType": "exact" - } - ] - } + 0, + 1, + 2 ], "relations": [ - { - "type": "flights", - "depth": { - "min": 1, - "max": 1 - }, - "entityFrom": -1, - "entityTo": 0, - "constraints": [] - } - ], - "limit": 5000 - }`) + 0 + ] + }, + "entities": [ + { + "ID": 0, + "type": "airports" + } + ], + "relations": [ + { + "ID": 0, + "type": "flights", + "depth": { + "min": 1, + "max": 1 + }, + "fromType": "", + "fromID": -1, + "toType": "entity", + "toID": 0 + } + ], + "groupBys": [], + "filters": [ + { + "ID": 0, + "fromType": "entity", + "fromID": 0, + "toType": "relation", + "toID": 0, + "attribute": "city", + "value": "San Francisco", + "dataType": "string", + "matchType": "exact", + "inType": "", + "inID": -1 + } + ], + "limit": 5000 + }`) // Unmarshall the incoming message into an IncomingJSONQuery object var JSONQuery entity.IncomingQueryJSON @@ -913,43 +1101,54 @@ func TestTooManyReturnRelations(t *testing.T) { service := NewService() query := []byte(`{ - "return": { - "entities": [ - 0 - ], - "relations": [ - 0, - 1, - 2 - ] - }, + "return": { "entities": [ - { - "type": "airports", - "constraints": [ - { - "attribute": "city", - "value": "San Francisco", - "dataType": "string", - "matchType": "exact" - } - ] - } + 0 ], "relations": [ - { - "type": "flights", - "depth": { - "min": 1, - "max": 1 - }, - "entityFrom": -1, - "entityTo": 0, - "constraints": [] - } - ], - "limit": 5000 - }`) + 0, + 1, + 2 + ] + }, + "entities": [ + { + "ID": 0, + "type": "airports" + } + ], + "relations": [ + { + "ID": 0, + "type": "flights", + "depth": { + "min": 1, + "max": 1 + }, + "fromType": "", + "fromID": -1, + "toType": "entity", + "toID": 0 + } + ], + "groupBys": [], + "filters": [ + { + "ID": 0, + "fromType": "entity", + "fromID": 0, + "toType": "relation", + "toID": 0, + "attribute": "city", + "value": "San Francisco", + "dataType": "string", + "matchType": "exact", + "inType": "", + "inID": -1 + } + ], + "limit": 5000 + }`) // Unmarshall the incoming message into an IncomingJSONQuery object var JSONQuery entity.IncomingQueryJSON @@ -971,44 +1170,55 @@ func TestNegativeReturnEntities(t *testing.T) { service := NewService() query := []byte(`{ - "return": { - "entities": [ - 0, - -1 - ], - "relations": [ - 0, - 1, - 2 - ] - }, + "return": { "entities": [ - { - "type": "airports", - "constraints": [ - { - "attribute": "city", - "value": "San Francisco", - "dataType": "string", - "matchType": "exact" - } - ] - } + 0, + -1 ], "relations": [ - { - "type": "flights", - "depth": { - "min": 1, - "max": 1 - }, - "entityFrom": -1, - "entityTo": 0, - "constraints": [] - } - ], - "limit": 5000 - }`) + 0, + 1, + 2 + ] + }, + "entities": [ + { + "ID": 0, + "type": "airports" + } + ], + "relations": [ + { + "ID": 0, + "type": "flights", + "depth": { + "min": 1, + "max": 1 + }, + "fromType": "", + "fromID": -1, + "toType": "entity", + "toID": 0 + } + ], + "groupBys": [], + "filters": [ + { + "ID": 0, + "fromType": "entity", + "fromID": 0, + "toType": "relation", + "toID": 0, + "attribute": "city", + "value": "San Francisco", + "dataType": "string", + "matchType": "exact", + "inType": "", + "inID": -1 + } + ], + "limit": 5000 + }`) // Unmarshall the incoming message into an IncomingJSONQuery object var JSONQuery entity.IncomingQueryJSON @@ -1037,15 +1247,24 @@ func TestNoRelationsField(t *testing.T) { }, "entities": [ { - "type": "airports", - "constraints": [ - { - "attribute": "city", - "value": "San Francisco", - "dataType": "string", - "matchType": "exact" - } - ] + "ID": 0, + "type": "airports" + } + ], + "groupBys": [], + "filters": [ + { + "ID": 0, + "fromType": "entity", + "fromID": 0, + "toType": "relation", + "toID": 0, + "attribute": "city", + "value": "San Francisco", + "dataType": "string", + "matchType": "exact", + "inType": "", + "inID": -1 } ], "limit": 5000 @@ -1077,63 +1296,68 @@ func TestDoubleWITH(t *testing.T) { service := NewService() query := []byte(`{ - "databaseName": "test", - "return": { - "entities": [ - 0, - 1, - 2, - 3 - ], - "relations": [ - 0, - 1 - ] - }, - "entities": [ - { - "type": "kamerleden", - "constraints": [] - }, - { - "type": "partijen", - "constraints": [] - } - , - { - "type": "kamerleden", - "constraints": [] - }, - { - "type": "commissies", - "constraints": [] - } - ], - "relations": [ - { - "type": "lid_van", - "depth": { - "min": 1, - "max": 1 - }, - "entityFrom": 0, - "entityTo": 1, - "constraints": [] - }, - { - "type": "onderdeel_van", - "depth": { - "min": 1, - "max": 1 - }, - "entityFrom": 2, - "entityTo": 3, - "constraints": [] - } - ], - "limit": 5000, - "modifiers": [] - }`) + "databaseName": "test", + "return": { + "entities": [ + 0, + 1, + 2, + 3 + ], + "relations": [ + 0, + 1 + ] + }, + "entities": [ + { + "ID": 0, + "type": "kamerleden" + }, + { + "ID": 1, + "type": "partijen" + }, + { + "ID": 2, + "type": "kamerleden" + }, + { + "ID": 3, + "type": "commissies" + } + ], + "relations": [ + { + "ID": 0, + "type": "lid_van", + "depth": { + "min": 1, + "max": 1 + }, + "fromType": "entity", + "fromID": 0, + "toType": "entity", + "toID": 1 + }, + { + "ID": 1, + "type": "onderdeel_van", + "depth": { + "min": 1, + "max": 1 + }, + "fromType": "entity", + "fromID": 2, + "toType": "entity", + "toID": 3 + } + ], + "groupBys": [], + "filters": [], + "limit": 5000, + "modifiers": [] + }`) // Unmarshall the incoming message into an IncomingJSONQuery object var JSONQuery entity.IncomingQueryJSON @@ -1161,41 +1385,52 @@ func TestEntityFromLowerThanNegativeOneInRelation(t *testing.T) { service := NewService() query := []byte(`{ - "return": { - "entities": [ - 0 - ], - "relations": [ - 0 - ] - }, + "return": { "entities": [ - { - "type": "airports", - "constraints": [ - { - "attribute": "city", - "value": "San Francisco", - "dataType": "string", - "matchType": "exact" - } - ] - } + 0 ], "relations": [ - { - "type": "flights", - "depth": { - "min": 1, - "max": 1 - }, - "entityFrom": -4, - "entityTo": 0, - "constraints": [] - } - ], - "limit": 5000 - }`) + 0 + ] + }, + "entities": [ + { + "ID": 0, + "type": "airports" + } + ], + "relations": [ + { + "ID": 0, + "type": "flights", + "depth": { + "min": 1, + "max": 1 + }, + "fromType": "", + "fromID": -4, + "toType": "entity", + "toID": 0 + } + ], + "groupBys": [], + "filters": [ + { + "ID": 0, + "fromType": "entity", + "fromID": 0, + "toType": "relation", + "toID": 0, + "attribute": "city", + "value": "San Francisco", + "dataType": "string", + "matchType": "exact", + "inType": "", + "inID": -1 + } + ], + "limit": 5000 + }`) // Unmarshall the incoming message into an IncomingJSONQuery object var JSONQuery entity.IncomingQueryJSON -- GitLab