-
Notifications
You must be signed in to change notification settings - Fork 5
/
query_entities_with_ld_context_test.js
143 lines (115 loc) · 4.81 KB
/
query_entities_with_ld_context_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
const testedResource = require('../common.js').testedResource;
const http = require('../http.js');
const entitiesResource = testedResource + '/entities/';
const assertResultsQuery = require('../common.js').assertResultsQuery;
const assertNoResultsQuery = require('../common.js').assertNoResultsQuery;
const serializeParams = require('../common.js').serializeParams;
const assertRetrievedQueryAlternatives = require('../common.js').assertRetrievedQueryAlternatives;
const JSON_LD = /application\/ld\+json(;.*)?/;
const JSON_LD_HEADER_CONTEXT =
'<https://fiware.github.io/NGSI-LD_TestSuite/ldContext/testFullContext.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"';
const ACCEPT_JSON_LD = {
Accept: 'application/ld+json'
};
// Note - the testFullContext.json also includes the core context. This is not returned
// in the subscription since it is assumed by default.
describe('Query Entity. JSON-LD. @context', () => {
const entity = {
id: 'urn:ngsi-ld:T:I123k467:Context',
type: 'T_Query',
P100: {
type: 'Property',
value: 12
},
R100: {
type: 'Relationship',
object: 'urn:ngsi-ld:T2:6789'
},
'@context': 'https://fiware.github.io/NGSI-LD_TestSuite/ldContext/testContext.jsonld'
};
const contexts = [
'https://fiware.github.io/NGSI-LD_TestSuite/ldContext/testContext.jsonld',
['https://fiware.github.io/NGSI-LD_TestSuite/ldContext/testFullContext.jsonld']
];
const entityId = encodeURIComponent(entity.id);
beforeAll(() => {
const JSON_LD_HEADERS = {
'Content-Type': 'application/ld+json'
};
return http.post(entitiesResource, entity, JSON_LD_HEADERS);
});
afterAll(() => {
return http.delete(entitiesResource + entityId);
});
it('query by type name. Default @context. Not found as @context does not match. 045', async function() {
const queryParams = {
type: entity.type
};
const response = await http.get(entitiesResource + '?' + serializeParams(queryParams), ACCEPT_JSON_LD);
assertNoResultsQuery(response, JSON_LD);
});
it('query by type name. Right @context 046', async function() {
const queryParams = {
type: entity.type
};
const headers = {
Accept: 'application/ld+json',
Link: JSON_LD_HEADER_CONTEXT
};
const response = await http.get(entitiesResource + '?' + serializeParams(queryParams), headers);
assertRetrievedQueryAlternatives(response, entity, JSON_LD, contexts);
});
it('query by type URI 047', async function() {
const queryParams = {
type: 'http://example.org/T_Query'
};
const headers = {
Accept: 'application/ld+json',
Link: JSON_LD_HEADER_CONTEXT
};
const response = await http.get(entitiesResource + '?' + serializeParams(queryParams), headers);
assertRetrievedQueryAlternatives(response, entity, JSON_LD, contexts);
});
it('query by type URI. No @context supplied but matches 048', async function() {
const queryParams = {
type: 'http://example.org/T_Query'
};
const headers = {
Accept: 'application/ld+json'
};
const response = await http.get(entitiesResource + '?' + serializeParams(queryParams), headers);
assertResultsQuery(response, 1);
});
it('query by type URI. No matching 049', async function() {
const queryParams = {
type: 'http://example.com/T_Query'
};
const headers = {
Accept: 'application/ld+json',
Link: JSON_LD_HEADER_CONTEXT
};
const response = await http.get(entitiesResource + '?' + serializeParams(queryParams), headers);
assertNoResultsQuery(response, JSON_LD);
});
it('query by condition over value. Default @context. Not found as @context does not match for the attribute. 050', async function() {
const queryParams = {
type: entity.type,
q: 'P100>5'
};
const response = await http.get(entitiesResource + '?' + serializeParams(queryParams), ACCEPT_JSON_LD);
// Response here shall be JSON
assertNoResultsQuery(response, JSON_LD);
});
it('query by condition over value. Right @context. 051', async function() {
const queryParams = {
type: entity.type,
q: 'P100>5'
};
const headers = {
Accept: 'application/ld+json',
Link: JSON_LD_HEADER_CONTEXT
};
const response = await http.get(entitiesResource + '?' + serializeParams(queryParams), headers);
assertRetrievedQueryAlternatives(response, entity, JSON_LD, contexts);
});
});