Exemplo n.º 1
0
 /**
  * @param string $filename
  */
 private function loadDataViaTripod($filename)
 {
     $docs = json_decode(file_get_contents(dirname(__FILE__) . $filename), true);
     foreach ($docs as $d) {
         $g = new \Tripod\Mongo\MongoGraph();
         $g->add_tripod_array($d);
         $this->tripod->saveChanges(new \Tripod\ExtendedGraph(), $g, $d['_id'][_ID_CONTEXT]);
     }
 }
Exemplo n.º 2
0
 public function testReplayTransactions_AddingAndDeleting()
 {
     $uri = 'http://example.com/resources/1';
     $g = new \Tripod\Mongo\MongoGraph();
     $g->add_literal_triple($uri, $g->qname_to_uri('searchterms:title'), 'Anything at all');
     // add the entity to the store
     $this->tripod->saveChanges(new \Tripod\ExtendedGraph(), $g, "http://talisaspire.com/");
     $this->assertDocumentVersion(array("r" => $uri, "c" => "http://talisaspire.com/"), 0);
     $this->assertEquals(1, $this->tripodTransactionLog->getTotalTransactionCount(), 'There should only be 1 transaction in the transaction log');
     // delete the entity from the store
     $this->tripod->saveChanges($g, new \Tripod\ExtendedGraph(), "http://talisaspire.com/");
     $this->assertDocumentHasBeenDeleted(array("r" => $uri, "c" => "http://talisaspire.com/"));
     $this->assertDocumentVersion(array("r" => $uri, "c" => "http://talisaspire.com/"), 1);
     $this->assertEquals(2, $this->tripodTransactionLog->getTotalTransactionCount(), 'There should only be 2 transactions in the transaction log');
     // add it again ( slightly different document for assertion)
     $g->add_literal_triple($uri, $g->qname_to_uri('searchterms:isbn'), '1234567890');
     $this->tripod->saveChanges(new \Tripod\ExtendedGraph(), $g, "http://talisaspire.com/");
     $this->assertDocumentVersion(array("r" => $uri, "c" => "http://talisaspire.com/"), 2);
     $this->assertEquals(3, $this->tripodTransactionLog->getTotalTransactionCount(), 'There should only be 3 transaction in the transaction log');
     // drop the collection so CBD collection is empty
     $this->getTripodCollection($this->tripod)->drop();
     // replay the transaction
     $this->tripod->replayTransactionLog();
     $uG = $this->tripod->describeResource($uri);
     $this->assertDocumentVersion(array("r" => $uri, "c" => "http://talisaspire.com/"), 2);
     $this->assertHasLiteralTriple($uG, $uri, $uG->qname_to_uri('searchterms:title'), 'Anything at all');
     $this->assertHasLiteralTriple($uG, $uri, $uG->qname_to_uri('searchterms:isbn'), '1234567890');
 }
 /**
  * This test verifies that if a document was previously added to mongo without any timestamps i.e. _UPDATED_TS and _CREATED_TS
  * then on a tripod write only the _UPDATED_TS will be added to the document
  */
 public function testOnlyDocumentUpdatedTimestampIsAddedToDocumentThatDidntHaveTimestampsToBeginWith()
 {
     // add the initial document, but not through Driver!
     $_id = array("r" => "http://talisaspire.com/resources/testDocument2", "c" => "http://talisaspire.com/");
     $document = array('_id' => $_id, 'dct:title' => array('l' => 'some title'), '_version' => 0);
     // verify initial document before we proceed, should have the triple we added, and a _version but not a
     // _UPDATED_TS or a _CREATED_TS
     $this->addDocument($document);
     $this->assertDocumentExists($_id);
     $this->assertDocumentHasProperty($_id, _VERSION, 0);
     $this->assertDocumentHasProperty($_id, "dct:title", array("l" => "some title"));
     $this->assertDocumentDoesNotHaveProperty($_id, _UPDATED_TS);
     $this->assertDocumentDoesNotHaveProperty($_id, _CREATED_TS);
     // change the document through tripod, for this im just doing a new addition
     $graph = new \Tripod\Mongo\MongoGraph();
     $graph->add_literal_triple($_id["r"], $graph->qname_to_uri('searchterms:title'), 'a new property');
     $this->tripod->saveChanges(new \Tripod\Mongo\MongoGraph(), $graph);
     // Now assert, document should contain the additiona triple we added, an updated _version.
     // Should now also contain an _UPDATED_TS but not a _CREATED_TS
     $this->assertDocumentExists($_id);
     $this->assertDocumentHasProperty($_id, _VERSION, 1);
     $this->assertDocumentHasProperty($_id, _UPDATED_TS);
     $this->assertDocumentHasProperty($_id, "dct:title", array("l" => "some title"));
     $this->assertDocumentHasProperty($_id, "searchterms:title", array("l" => "a new property"));
     $this->assertDocumentDoesNotHaveProperty($_id, _CREATED_TS);
 }
Exemplo n.º 4
0
 /**
  * Test to ensure that impact index contains joined ids for resources that do not yet exist in the database (i.e.
  * allow open world model)
  * @access public
  * @return void
  */
 public function testPreviouslyUnavailableDataBecomesPresentAndTriggersTableRegen()
 {
     $this->tripodTables->generateTableRows("t_join_link");
     $rows = $this->tripodTables->getTableRows("t_join_link", array("_id.r" => "baseData:bar1234"));
     $this->assertEquals(1, $rows['head']['count']);
     $this->assertEquals("user:10103", $rows['results'][0]['authorUri']);
     // Author link should not appear because resource has not yet been created
     $this->assertArrayNotHasKey('authorLink', $rows['results'][0]);
     $uri = 'http://schemas.talis.com/2005/user/schema#10103';
     // Confirm this user does not exist
     $this->assertFalse($this->tripod->describeResource($uri)->has_triples_about($uri));
     $g = new \Tripod\Mongo\MongoGraph();
     $g->add_resource_triple($uri, $g->qname_to_uri("rdf:type"), $g->qname_to_uri("foaf:Person"));
     $g->add_literal_triple($uri, $g->qname_to_uri("foaf:name"), "A. Nonymous");
     $this->tripod->saveChanges(new \Tripod\Mongo\MongoGraph(), $g, "http://talisaspire.com/", "This resource didn't exist at join time");
     $userGraph = $this->tripod->describeResource($uri);
     $this->assertTrue($userGraph->has_triples_about($uri), "new entity we created was not saved");
     // Get our table rows again
     $rows = $this->tripodTables->getTableRows("t_join_link", array("_id.r" => "baseData:bar1234"));
     // authorLink should now be populated
     $this->assertArrayHasKey('authorLink', $rows['results'][0]);
     $this->assertEquals($uri, $rows['results'][0]['authorLink']);
 }