Newer
Older
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
<?php
require_once 'api/setup.php';
require_once 'api/routes.php';
require 'BaseTest.php';
class CrudTest extends BaseTest
{
public function testCreateInvalid()
{
$response = $this->app->handle($this->_createRequest('POST', '/create/test'));
$this->assertEquals(400, $response->getStatusCode());
}
public function testCreateInvalidMissingContent()
{
$response = $this->app->handle($this->_createRequest('POST', '/create/test'));
$this->assertEquals(400, $response->getStatusCode());
$this->assertContains("missing body", json_decode($response->getBody(), true)['errors']);
}
public function testCreateInvalidMissingTags()
{
$body = array("content" => ["meta" => true, "features" => []]);
$response = $this->app->handle($this->_createRequest('POST', '/create/test', $body));
$this->assertEquals(400, $response->getStatusCode());
$this->assertNotContains("content property empty", json_decode($response->getBody(), true)['errors']);
$this->assertContains("features missing tags entry", json_decode($response->getBody(), true)['errors']);
}
public function testCreateInvalidInvalidT0T1()
{
$body = array("content" => ["meta" => true], "t0" => 'a');
$response = $this->app->handle($this->_createRequest('POST', '/create/test', $body));
$this->assertEquals(400, $response->getStatusCode());
$this->assertContains("t0 and t1 must time integer timestamps", json_decode($response->getBody(), true)['errors']);
$body = array("content" => ["meta" => true], "t1" => 'a');
$response = $this->app->handle($this->_createRequest('POST', '/create/test', $body));
$this->assertEquals(400, $response->getStatusCode());
$this->assertContains("t0 and t1 must time integer timestamps", json_decode($response->getBody(), true)['errors']);
}
public function testCreate()
{
$body = array("content" => ["meta" => true], "features" => ["tags" => "sim"]);
$response = $this->app->handle($this->_createRequest('POST', '/create/test', $body));
$this->assertEquals(200, $response->getStatusCode(), json_encode($response->getBody()));
}
public function testCreateWithSmartDataUnit()
{
$body = array("content" => ["meta" => true], "features" => ["tags" => "sim"], "smartDataUnits" => [10, 12]);
$response = $this->app->handle($this->_createRequest('POST', '/create/test', $body));
$this->assertEquals(200, $response->getStatusCode(), json_encode($response->getBody()));
}
public function testCreateWithInvalidSmartDataUnit()
{
$body = array("content" => ["meta" => true], "features" => ["tags" => "sim"], "smartDataUnits" => ["aaa", "eee"]);
$response = $this->app->handle($this->_createRequest('POST', '/create/test', $body));
$this->assertEquals(400, $response->getStatusCode());
$this->assertContains("smartDataUnits should be a array of longs", json_decode($response->getBody(), true)['errors']);
}
public function testCreateWithSmartDataSources()
{
$body = array("content" => ["meta" => true], "features" => ["tags" => "sim"], "smartDataSources" => ["ffdaf2342", [1,2,3,5]]);
$response = $this->app->handle($this->_createRequest('POST', '/create/test', $body));
$this->assertEquals(200, $response->getStatusCode(), json_encode($response->getBody()));
}
public function testCreateWithSmartDataSourcesInvalidSignature()
{
$body = array("content" => ["meta" => true], "features" => ["tags" => "sim"], "smartDataSources" => ["ffds-af-2342", [1,2,3,5]]);
$response = $this->app->handle($this->_createRequest('POST', '/create/test', $body));
$this->assertEquals(400, $response->getStatusCode());
$this->assertContains("ffds-af-2342 is an invalid signature", json_decode($response->getBody(), true)['errors']);
}
public function testCreateWithSmartDataSourcesInvalidSphere()
{
$body = array("content" => ["meta" => true], "features" => ["tags" => "sim"], "smartDataSources" => ["ffdsaf2342", [1,2,3]]);
$response = $this->app->handle($this->_createRequest('POST', '/create/test', $body));
$this->assertEquals(400, $response->getStatusCode());
$this->assertContains("[1,2,3] is an invalid sphere", json_decode($response->getBody(), true)['errors']);
}
public function testCreateGetWithSmartDataUnit()
{
$body = array("content" => ["meta" => true], "features" => ["tags" => "sim"], "smartDataUnits" => [10, 12]);
$response = $this->app->handle($this->_createRequest('POST', '/create/test', $body));
$this->assertEquals(200, $response->getStatusCode(), json_encode($response->getBody()));
$response->getBody()->rewind();
$body = json_decode($response->getBody()->getContents(), true);
$this->assertTrue(array_key_exists('result', $body), 'missing result');
$this->assertTrue(array_key_exists('smartDataContextId', $body['result']), 'missing smartdataid');
$id = $body['result']['smartDataContextId'];
$response = $this->app->handle($this->_createRequest('GET', "/get/test/$id"));
$this->assertEquals(200, $response->getStatusCode(), json_encode($response->getBody()));
$response->getBody()->rewind();
$body = json_decode($response->getBody()->getContents(), true);
$this->assertTrue(array_key_exists('result', $body), 'missing result');
$this->assertTrue(array_key_exists('content', $body['result']), 'missing content');
$this->assertEquals($body['result']['id'], $id, 'wrong smartdataid');
}
public function testAssociateWithSmartDataSources()
{
$body = array("content" => ["meta" => true], "features" => ["tags" => "sim"], "smartDataSources" => ["ffdaf2342", [1,2,3,5]]);
$response = $this->app->handle($this->_createRequest('POST', '/create/test', $body));
$this->assertEquals(200, $response->getStatusCode(), json_encode($response->getBody()));
$response->getBody()->rewind();
$body = json_decode($response->getBody()->getContents(), true);
$this->assertTrue(array_key_exists('result', $body), 'missing result');
$this->assertTrue(array_key_exists('smartDataContextId', $body['result']), 'missing smartdataid');
$id = $body['result']['smartDataContextId'];
$body = ["smartDataContextIds" => [$id], "smartDataSources" => ["ae7666", [4,5,6,7], [1,2,3,5]], "smartDataUnits" => [111,222]];
$response = $this->app->handle($this->_createRequest('POST', '/associate/test', $body));
$this->assertEquals(200, $response->getStatusCode(), json_encode($response->getBody()));
$response->getBody()->rewind();
$body = json_decode($response->getBody()->getContents(), true);
$this->assertEquals(4, count($body['result'][0]['result']['smartDataSources']), "Wrong number of smartDataSources associated");
$this->assertEquals(2, count($body['result'][0]['result']['smartDataUnits']), "Wrong number of smartDataUnits associated");
}
public function testUnassociateWithSmartDataSources()
{
$body = array("content" => ["meta" => true], "features" => ["tags" => "sim"], "smartDataSources" => ["ffdaf2342", [1,2,3,5]]);
$response = $this->app->handle($this->_createRequest('POST', '/create/test', $body));
$this->assertEquals(200, $response->getStatusCode(), json_encode($response->getBody()));
$response->getBody()->rewind();
$body = json_decode($response->getBody()->getContents(), true);
$this->assertTrue(array_key_exists('result', $body), 'missing result');
$this->assertTrue(array_key_exists('smartDataContextId', $body['result']), 'missing smartdataid');
$id = $body['result']['smartDataContextId'];
$body = ["smartDataContextIds" => [$id], "smartDataSources" => ["ae7666", [4,5,6,7], [1,2,3,5]], "smartDataUnits" => [111,222]];
$response = $this->app->handle($this->_createRequest('POST', '/associate/test', $body));
$this->assertEquals(200, $response->getStatusCode(), json_encode($response->getBody()));
$response->getBody()->rewind();
$body = json_decode($response->getBody()->getContents(), true);
$this->assertEquals(4, count($body['result'][0]['result']['smartDataSources']), "Wrong number of smartDataSources associated");
$this->assertEquals(2, count($body['result'][0]['result']['smartDataUnits']), "Wrong number of smartDataUnits associated");
$body = ["smartDataContextIds" => [$id], "smartDataSources" => ["ae7666", [4,5,6,7]], "smartDataUnits" => [222]];
$response = $this->app->handle($this->_createRequest('POST', '/unassociate/test', $body));
$this->assertEquals(200, $response->getStatusCode(), json_encode($response->getBody()));
$response->getBody()->rewind();
$body = json_decode($response->getBody()->getContents(), true);
$this->assertEquals(2, count($body['result'][0]['result']['smartDataSources']), "Wrong number of smartDataSources associated");
$this->assertEquals(1, count($body['result'][0]['result']['smartDataUnits']), "Wrong number of smartDataUnits associated");
}
public function testQuery()
{
$body = array("content" => ["meta" => true], "features" => ["tags" => "sim"], "smartDataSources" => ["ffdaf2342", [1,2,3,5]]);
$response = $this->app->handle($this->_createRequest('POST', '/create/test', $body));
$this->assertEquals(200, $response->getStatusCode(), json_encode($response->getBody()));
$response->getBody()->rewind();
$body = json_decode($response->getBody()->getContents(), true);
$this->assertTrue(array_key_exists('result', $body), 'missing result');
$this->assertTrue(array_key_exists('smartDataContextId', $body['result']), 'missing smartdataid');
$id = $body['result']['smartDataContextId'];
$body = ["smartDataContextIds" => [$id], "smartDataSources" => ["ae7666", [4,5,6,7], [1,2,3,5]], "smartDataUnits" => [111,222]];
$response = $this->app->handle($this->_createRequest('POST', '/associate/test', $body));
$this->assertEquals(200, $response->getStatusCode(), json_encode($response->getBody()));
$response->getBody()->rewind();
$body = json_decode($response->getBody()->getContents(), true);
$this->assertEquals(4, count($body['result'][0]['result']['smartDataSources']), "Wrong number of smartDataSources associated");
$this->assertEquals(2, count($body['result'][0]['result']['smartDataUnits']), "Wrong number of smartDataUnits associated");
$body = ["smartDataSources" => [4,5,6,7]];
$response = $this->app->handle($this->_createRequest('POST', '/query/test', $body));
$this->assertEquals(200, $response->getStatusCode(), json_encode($response->getBody()));
$response->getBody()->rewind();
$body = json_decode($response->getBody()->getContents(), true);
$this->assertGreaterThan(0, count($body['result']), "Wrong number of results");
}
public function testContexts()
{
$domain = "performance";
$body = array("content" => ["meta" => true], "features" => ["tags" => "sim"], "smartDataSources" => ["ffdaf2342", [1,2,3,5]]);
$response = $this->app->handle($this->_createRequest('POST', "/create/$domain", $body));
$this->assertEquals(200, $response->getStatusCode(), json_encode($response->getBody()));
$response->getBody()->rewind();
$body = json_decode($response->getBody()->getContents(), true);
$this->assertTrue(array_key_exists('result', $body), 'missing result');
$this->assertTrue(array_key_exists('smartDataContextId', $body['result']), 'missing smartdataid');
$id = $body['result']['smartDataContextId'];
$body = ["smartDataContextIds" => [$id], "smartDataSources" => ["ae7666", [4,5,6,7], [1,2,3,5]], "smartDataUnits" => [111,222]];
$response = $this->app->handle($this->_createRequest('POST', "/associate/$domain", $body));
$this->assertEquals(200, $response->getStatusCode(), json_encode($response->getBody()));
$response->getBody()->rewind();
$body = json_decode($response->getBody()->getContents(), true);
$this->assertEquals(4, count($body['result'][0]['result']['smartDataSources']), "Wrong number of smartDataSources associated");
$this->assertEquals(2, count($body['result'][0]['result']['smartDataUnits']), "Wrong number of smartDataUnits associated");
$start = time();
$body = ["smartDataSources" => [[4,5,6,7]], "t0" => 10, "t1" => 300];
$response = $this->app->handle($this->_createRequest('POST', "/contexts/$domain", $body));
$this->assertEquals(200, $response->getStatusCode(), json_encode($response->getBody()));
$response->getBody()->rewind();
$body = json_decode($response->getBody()->getContents(), true);
$this->assertGreaterThan(0, count($body['result']), "Wrong number of results");
}
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
public function testUpdateWithTimestampsAndContent() {
// Step 1: Create a document
$body = ["content" => ["meta" => true], "features" => ["tags" => "sim"], "smartDataUnits" => [10, 12]];
$response = $this->app->handle($this->_createRequest('POST', '/create/test', $body));
$this->assertEquals(200, $response->getStatusCode(), json_encode($response->getBody()));
$response->getBody()->rewind();
$body = json_decode($response->getBody()->getContents(), true);
$this->assertTrue(array_key_exists('result', $body), 'missing result');
$this->assertTrue(array_key_exists('smartDataContextId', $body['result']), 'missing smartDataContextId');
$id = $body['result']['smartDataContextId'];
// Step 2: Update the document with t0 and t1
$updateBody = ["t0" => 1000, "t1" => 2000];
$response = $this->app->handle($this->_createRequest('POST', "/update/test/$id", $updateBody));
$this->assertEquals(200, $response->getStatusCode(), json_encode($response->getBody()));
$response->getBody()->rewind();
$updatedBody = json_decode($response->getBody()->getContents(), true);
$this->assertTrue(array_key_exists('result', $updatedBody), 'missing result');
$this->assertEquals($updatedBody['result']['t0'], 1000, 't0 was not updated correctly');
$this->assertEquals($updatedBody['result']['t1'], 2000, 't1 was not updated correctly');
// Step 3: Update the document with new content
$newContent = ["content" => ["meta" => "updated"]];
$response = $this->app->handle($this->_createRequest('POST', "/update/test/$id", $newContent));
$this->assertEquals(200, $response->getStatusCode(), json_encode($response->getBody()));
$response->getBody()->rewind();
$updatedContentBody = json_decode($response->getBody()->getContents(), true);
$this->assertTrue(array_key_exists('result', $updatedContentBody), 'missing result');
$this->assertEquals($updatedContentBody['result']['content']['meta'], "updated", 'content was not updated correctly');
// Step 4: Get the updated document and verify
$response = $this->app->handle($this->_createRequest('GET', "/get/test/$id"));
$this->assertEquals(200, $response->getStatusCode(), json_encode($response->getBody()));
$response->getBody()->rewind();
$finalBody = json_decode($response->getBody()->getContents(), true);
$this->assertTrue(array_key_exists('result', $finalBody), 'missing result');
$this->assertEquals($finalBody['result']['id'], $id, 'wrong smartdataid');
$this->assertEquals($finalBody['result']['t0'], 1000, 't0 mismatch');
$this->assertEquals($finalBody['result']['t1'], 2000, 't1 mismatch');
$this->assertEquals($finalBody['result']['content']['meta'], "updated", 'content meta mismatch');
}