Newer
Older
"inType": "",
"inID": -1
}
],
"limit": 5000
}`)
// Unmarshall the incoming message into an IncomingJSONQuery object
var JSONQuery entity.IncomingQueryJSON
json.Unmarshal(query, &JSONQuery)
convertedResult, err := service.ConvertQuery(&JSONQuery)
// Assert that there is no error
assert.NoError(t, err)
// Assert that the result and the expected result are the same
correctConvertedResult := `LET n0 = (FOR x IN airports FILTER x.city == "San Francisco" RETURN x)LET r0 = (FOR x IN n0 FOR v, e, p IN 1..1 INBOUND x flights OPTIONS { uniqueEdges: "path" }LIMIT 5000 RETURN DISTINCT p )LET nodes = first(RETURN UNION_DISTINCT(flatten(r0[**].vertices), [],[]))LET edges = first(RETURN UNION_DISTINCT(flatten(r0[**].edges), [],[]))RETURN {"vertices":nodes, "edges":edges }`
cleanedResult := strings.ReplaceAll(*convertedResult, "\n", "")
cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
assert.Equal(t, correctConvertedResult, cleanedResult)
}
/*
Tests too manu return entities
t: *testing.T, makes go recognise this as a test
*/
func TestTooManyReturnEntities(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
0,
1,
2
],
"relations": [
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
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
json.Unmarshal(query, &JSONQuery)
_, err := service.ConvertQuery(&JSONQuery)
// Assert that there is no error
assert.Equal(t, errors.New("non-existing entity referenced in return"), err)
}
/*
Tests too manu return relations
t: *testing.T, makes go recognise this as a test
*/
func TestTooManyReturnRelations(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
],
"relations": [
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
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
json.Unmarshal(query, &JSONQuery)
_, err := service.ConvertQuery(&JSONQuery)
// Assert that there is no error
assert.Equal(t, errors.New("non-existing relation referenced in return"), err)
}
/*
Tests negative return entities
t: *testing.T, makes go recognise this as a test
*/
func TestNegativeReturnEntities(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
],
"relations": [
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
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
json.Unmarshal(query, &JSONQuery)
_, err := service.ConvertQuery(&JSONQuery)
// Assert that there is no error
assert.Equal(t, errors.New("non-existing entity referenced in return"), err)
}
/*
Tests a query with no relation field
t: *testing.T, makes go recognise this as a test
*/
func TestNoRelationsField(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
"return": {
"entities": [
0
]
},
"entities": [
{
"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
}`)
// Unmarshall the incoming message into an IncomingJSONQuery object
var JSONQuery entity.IncomingQueryJSON
json.Unmarshal(query, &JSONQuery)
convertedResult, err := service.ConvertQuery(&JSONQuery)
// Assert that there is no error
assert.NoError(t, err)
// Assert that the result and the expected result are the same
correctConvertedResult := `LET n0 = (FOR x IN airports FILTER x.city == "San Francisco" RETURN x)LET nodes = first(RETURN UNION_DISTINCT(n0,[],[]))LET edges = first(RETURN UNION_DISTINCT([],[]))RETURN {"vertices":nodes, "edges":edges }`
cleanedResult := strings.ReplaceAll(*convertedResult, "\n", "")
cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
assert.Equal(t, correctConvertedResult, cleanedResult)
}
/*
Tests a query with double WITH
t: *testing.T, makes go recognise this as a test
*/
func TestDoubleWITH(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
"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
json.Unmarshal(query, &JSONQuery)
convertedResult, err := service.ConvertQuery(&JSONQuery)
// Assert that there is no error
assert.NoError(t, err)
// Assert that the result and the expected result are the same
correctConvertedResult := "WITH partijen, commissiesLET n0 = (FOR x IN kamerleden RETURN x)LET r0 = (FOR x IN n0 FOR v, e, p IN 1..1 OUTBOUND x lid_van OPTIONS { uniqueEdges: \"path\" }LIMIT 5000 RETURN DISTINCT p )LET n2 = (FOR x IN kamerleden RETURN x)LET r1 = (FOR x IN n2 FOR v, e, p IN 1..1 OUTBOUND x onderdeel_van OPTIONS { uniqueEdges: \"path\" }LIMIT 5000 RETURN DISTINCT p )LET nodes = first(RETURN UNION_DISTINCT(flatten(r0[**].vertices), flatten(r1[**].vertices), [],[]))LET edges = first(RETURN UNION_DISTINCT(flatten(r0[**].edges), flatten(r1[**].edges), [],[]))RETURN {\"vertices\":nodes, \"edges\":edges }"
cleanedResult := strings.ReplaceAll(*convertedResult, "\n", "")
cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
assert.Equal(t, correctConvertedResult, cleanedResult)
}
/*
Tests an entity with a lower than -1 in a relation
t: *testing.T, makes go recognise this as a test
*/
func TestEntityFromLowerThanNegativeOneInRelation(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
],
"relations": [
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
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
json.Unmarshal(query, &JSONQuery)
_, err := service.ConvertQuery(&JSONQuery)
// Assert that there is no error
assert.NoError(t, err)
}