function test_augment_graph_sets_content_type()
 {
     $fake_request_factory = new FakeRequestFactory();
     $fake_request = new FakeHttpRequest(new HttpResponse());
     $fake_request_factory->register('POST', "http://example.org/store/services/augment", $fake_request);
     $ss = new AugmentService("http://example.org/store/services/augment");
     $ss->request_factory = $fake_request_factory;
     $response = $ss->augment_graph(new SimpleGraph());
     $this->assertTrue(in_array('Content-Type: application/rss+xml', $fake_request->get_headers()));
 }
 function test_apply_versioned_changeset_rdfxml_uses_credentials()
 {
     $fake_request_factory = new FakeRequestFactory();
     $fake_request = new FakeHttpRequest(new HttpResponse());
     $fake_request_factory->register('POST', "http://example.org/store/meta/changesets", $fake_request);
     $g = new PrivateGraph("http://example.org/store/meta", new FakeCredentials());
     $g->request_factory = $fake_request_factory;
     $response = $g->apply_versioned_changeset_rdfxml($this->_empty_changeset);
     $this->assertEquals("user:pwd", $fake_request->get_auth());
 }
 function test_list_records_with_from_and_to_dates()
 {
     $from_date = '2010-05-29';
     $until_date = '2010-06-05';
     $fake_request_factory = new FakeRequestFactory();
     $fake_request = new FakeHttpRequest(new HttpResponse());
     $fake_request_factory->register('GET', "http://example.org/store/services/oai-pmh?verb=ListRecords&metadataPrefix=oai_dc&from={$from_date}&until={$until_date}", $fake_request);
     $oai = new OAIService("http://example.org/store/services/oai-pmh");
     $oai->request_factory = $fake_request_factory;
     $response = $oai->list_records(null, $from_date, $until_date);
     $this->assertTrue($fake_request->was_executed());
 }
 function test_get_item_uris()
 {
     $fake_request_factory = new FakeRequestFactory();
     $fake_response = new HttpResponse();
     $fake_response->body = file_get_contents(realpath(dirname(__FILE__)) . '/documents/snapshots.rdf');
     $fake_request = new FakeHttpRequest($fake_response);
     $snapshotsUri = "http://example.com/store/snapshots";
     $fake_request_factory->register('GET', $snapshotsUri, $fake_request);
     $snapshots = new Snapshots($snapshotsUri, false, $fake_request_factory);
     $expected = array("http://api.talis.com/stores/schema-cache/snapshots/20071129173353.tar");
     $actual = $snapshots->get_item_uris();
     $this->assertEquals($expected, $actual);
 }
 function test_facets_to_array()
 {
     $fake_response = new HttpResponse();
     $fake_response->status_code = 200;
     $fake_response->body = '<facet-results xmlns="http://schemas.talis.com/2007/facet-results#"><head><query>dog</query><fields>tag</fields><top>10</top><output>xml</output></head><fields><field name="tag"><term value="dogs" number="1" facet-uri="http://api.talis.com/stores/kniblet-dev1/services/facet?fields=tag&amp;top=10&amp;output=xml&amp;query=dog+AND+tag%3A%22dogs%22" search-uri="http://api.talis.com/stores/kniblet-dev1/items?query=dog+AND+tag%3A%22dogs%22" /><term value="walking" number="1" facet-uri="http://api.talis.com/stores/kniblet-dev1/services/facet?fields=tag&amp;top=10&amp;output=xml&amp;query=dog+AND+tag%3A%22walking%22" search-uri="http://api.talis.com/stores/kniblet-dev1/items?query=dog+AND+tag%3A%22walking%22" /><term value="pets" number="1" facet-uri="http://api.talis.com/stores/kniblet-dev1/services/facet?fields=tag&amp;top=10&amp;output=xml&amp;query=dog+AND+tag%3A%22pets%22" search-uri="http://api.talis.com/stores/kniblet-dev1/items?query=dog+AND+tag%3A%22pets%22" /></field></fields></facet-results>';
     $fake_request_factory = new FakeRequestFactory();
     $fake_request = new FakeHttpRequest($fake_response);
     $fake_request_factory->register('GET', "http://example.org/store/services/facet?query=dog&fields=tag&top=10&output=xml", $fake_request);
     $ss = new FacetService("http://example.org/store/services/facet");
     $ss->request_factory = $fake_request_factory;
     $facets = $ss->facets_to_array('dog', array('subject'));
     $this->assertTrue(is_array($facets));
 }
 function test_put_to_network_includes_body()
 {
     $fake_request_factory = new FakeRequestFactory();
     $fake_request = new FakeHttpRequest(new HttpResponse(200));
     $fake_request_factory->register('PUT', "http://example.org/res", $fake_request);
     $group = new NetworkResource("http://example.org/res");
     $group->add_resource_triple("http://example.org/res", "http://example.org/pred", "http://example.org/obj");
     $group->request_factory = $fake_request_factory;
     $group->put_to_network();
     $parser = ARC2::getRDFXMLParser(array("bnode_prefix" => "genid", "base" => 'http://example.org/'));
     $parser->parse('http://example.org/', $fake_request->get_body());
     $triples = $parser->getTriples();
     $this->assertEquals(1, count($triples));
 }
 function test_mirror_from_uri()
 {
     $url = "http://example.org/web-page";
     $fake_request_factory = new FakeRequestFactory();
     $webpage_response = new HttpResponse('200');
     $webpage_response->body = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'documents/after.ttl');
     $fake_webpage_request = new FakeHttpRequest($webpage_response);
     $fake_request_factory->register('GET', $url, $fake_webpage_request);
     $contentbox_copy = new HttpResponse('200');
     $contentbox_copy->body = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'documents/before.ttl');
     $fake_copy_request = new FakeHttpRequest($contentbox_copy);
     $fake_request_factory->register('GET', 'http://api.talis.com/stores/example/meta?about=' . urlencode($url) . '&output=json', $fake_copy_request);
     $postDataResponse = new HttpResponse('201');
     $fake_postData_request = new FakeHttpRequest($postDataResponse);
     $fake_request_factory->register('POST', 'http://api.talis.com/stores/example/meta', $fake_postData_request);
     $graph = new Graph("http://api.talis.com/stores/example/meta", new FakeCredentials(), $fake_request_factory);
     $response = $graph->mirror_from_uri($url);
     $this->assertTrue($fake_webpage_request->was_executed(), "The webpage {$url} should be retrieved over HTTP");
     $this->assertTrue($fake_copy_request->was_executed(), "");
     $this->assertTrue($fake_postData_request->was_executed(), "The data from {$url}  (and its metadata) should be added to the store by POSTing a document containing changesets to /meta");
     $expected_response = array('get_page' => $webpage_response, 'get_copy' => $contentbox_copy, 'update_data' => $postDataResponse, 'success' => true);
     $this->assertEquals($expected_response, $response, "");
 }
    function test_select_to_array_uses_credentials()
    {
        $fake_response = new HttpResponse();
        $fake_response->status_code = 200;
        $fake_response->body = '<?xml version="1.0"?>
<sparql
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:xs="http://www.w3.org/2001/XMLSchema#"
    xmlns="http://www.w3.org/2005/sparql-results#" >
  <head>
    <variable name="s"/>
    <variable name="p"/>
    <variable name="o"/>
  </head>
  <results ordered="false" distinct="true">
    <result>
      <binding name="s">

        <uri>http://api.talis.local/bf/stores/engagetenantstore/items/1173364330999#self</uri>
      </binding>
      <binding name="p">
        <uri>http://www.w3.org/1999/02/22-rdf-syntax-ns#subject</uri>
      </binding>
      <binding name="o">
        <uri>http://api.talis.local/bf/stores/engagetenantstore/items/1174262688178#self</uri>

      </binding>
    </result>
    <result>
      <binding name="s">
        <uri>http://api.talis.local/bf/stores/engagetenantstore/items/1173364330999#self</uri>

      </binding>
      <binding name="p">
        <uri>http://www.w3.org/1999/02/22-rdf-syntax-ns#object</uri>
      </binding>
      <binding name="o">
        <literal>1a3c47c9-fb29-4fd2-a061-a3b72328c96b</literal>
      </binding>
    </result>

  </results>
</sparql>';
        $fake_request_factory = new FakeRequestFactory();
        $fake_request = new FakeHttpRequest($fake_response);
        $fake_request_factory->register('GET', "http://example.org/store/services/multisparql?query=" . urlencode('select distinct ?s where { ?s ?p ?o .} limit 3'), $fake_request);
        $ss = new MultiSparqlService("http://example.org/store/services/multisparql", new FakeCredentials());
        $ss->request_factory = $fake_request_factory;
        $array = $ss->select_to_array('select distinct ?s where { ?s ?p ?o .} limit 3', array('http://example.org/graphs/1'));
        $this->assertEquals("user:pwd", $fake_request->get_auth());
    }
示例#9
0
 function test_submit_turtle_sets_accept()
 {
     $fake_request_factory = new FakeRequestFactory();
     $fake_request = new FakeHttpRequest(new HttpResponse());
     $fake_request_factory->register('POST', "http://example.org/store/meta", $fake_request);
     $g = $this->make_graph("http://example.org/store/meta");
     $g->request_factory = $fake_request_factory;
     $response = $g->submit_turtle($this->_turtle_doc);
     $this->assertTrue(in_array('Accept: */*', $fake_request->get_headers()));
 }
 function test_query_uses_output_type_in_url()
 {
     $query = 'foo';
     $fake_request_factory = new FakeRequestFactory();
     $fake_request = new FakeHttpRequest(new HttpResponse());
     $fake_request_factory->register('GET', "http://example.org/store/services/sparql?query=" . urlencode($query) . '&output=bar', $fake_request);
     $ss = new SparqlServiceBase("http://example.org/store/services/sparql");
     $ss->request_factory = $fake_request_factory;
     $response = $ss->query($query, "bar");
     $this->assertTrue($fake_request->was_executed());
     $this->assertTrue(in_array('Accept: */*', $fake_request->get_headers()));
 }
示例#11
0
 function test_two_store_search_issues_gets()
 {
     $fake_request_factory = new FakeRequestFactory();
     $fake_request1 = new FakeHttpRequest(new HttpResponse());
     $fake_request_factory->register('GET', "http://example.org/store1/items?query=scooby&max=10&offset=0", $fake_request1);
     $fake_request2 = new FakeHttpRequest(new HttpResponse());
     $fake_request_factory->register('GET', "http://example.org/store2/items?query=scooby&max=10&offset=0", $fake_request2);
     $u = new Union();
     $u->add("http://example.org/store1");
     $u->add("http://example.org/store2");
     $u->request_factory = $fake_request_factory;
     $response = $u->search('scooby');
     $this->assertTrue($fake_request1->was_executed());
     $this->assertTrue($fake_request2->was_executed());
 }
 function test_update_with_zero_removals_becomes_an_insert()
 {
     $fake_request_factory = new FakeRequestFactory();
     $fake_response = new HttpResponse();
     $fake_response->status_code = 200;
     $fake_response->body = $this->_select_result_zero_results;
     $query = "select ?_uri ?name where { optional {?_uri <http://example.org/name> ?name. } }";
     $fake_request = new FakeHttpRequest($fake_response);
     $fake_request_factory->register('GET', "http://example.org/store/services/sparql?query=" . urlencode($query) . '&output=json', $fake_request);
     $fake_request_post = new FakeHttpRequest(new HttpResponse());
     $fake_request_factory->register('POST', "http://example.org/store/meta", $fake_request_post);
     $dt = new DataTable("http://example.org/store", null, $fake_request_factory);
     $dt->map('http://example.org/name', 'name');
     $dt->set('name', 'foo');
     $dt->update();
     $g = $dt->get_insert_graph();
     $this->assertEquals($g->to_turtle(), $fake_request_post->get_body());
 }
 function test_search_to_resource_list_parses_items()
 {
     $fake_response = new HttpResponse();
     $fake_response->status_code = 200;
     $fake_response->body = $this->_simple_rss_feed;
     $fake_request_factory = new FakeRequestFactory();
     $fake_request = new FakeHttpRequest($fake_response);
     $fake_request_factory->register('GET', "http://example.org/store/items?query=scooby&max=10&offset=0", $fake_request);
     $cb = new Contentbox("http://example.org/store/items", new FakeCredentials());
     $cb->request_factory = $fake_request_factory;
     $resources = $cb->search_to_resource_list('scooby', 10, 0);
     $this->assertEquals(2, count($resources->items));
     $this->assertEquals("AppDomain, process and components...", $resources->items[0]['http://purl.org/dc/elements/1.1/title'][0]);
     $this->assertEquals("Export & Import Goodie from/to Photoshop", $resources->items[1]['http://purl.org/dc/elements/1.1/title'][0]);
 }
 function test_schedule_restore_posts_rdfxml_with_a_snapshot_uri()
 {
     $fake_request_factory = new FakeRequestFactory();
     $fake_request = new FakeHttpRequest(new HttpResponse());
     $fake_request_factory->register('POST', "http://example.org/store/jobs", $fake_request);
     $queue = new JobQueue("http://example.org/store/jobs");
     $queue->request_factory = $fake_request_factory;
     $response = $queue->schedule_restore('http://example.org/snapshot');
     $parser = ARC2::getRDFXMLParser(array("bnode_prefix" => "genid", "base" => 'http://example.org/'));
     $parser->parse('http://example.org/', $fake_request->get_body());
     $triples = $parser->getTriples();
     $found_triple = false;
     foreach ($triples as $triple) {
         if ($triple['p'] == 'http://schemas.talis.com/2006/bigfoot/configuration#snapshotUri' && $triple['o_type'] == 'uri' && $triple['o'] == 'http://example.org/snapshot') {
             $found_triple = true;
             break;
         }
     }
     $this->assertTrue($found_triple);
 }
示例#15
0
 function test_mirror_from_url_resubmits_before_graph_if_changeset_409s()
 {
     $url = "http://example.org/web-page";
     $fake_request_factory = new FakeRequestFactory();
     $webpage_response = new HttpResponse('200');
     $webpage_response->body = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'documents/after.ttl');
     $fake_webpage_request = new FakeHttpRequest($webpage_response);
     $fake_request_factory->register('GET', $url, $fake_webpage_request);
     $contentbox_copy = new HttpResponse('200');
     $contentbox_copy->body = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'documents/before.ttl');
     $fake_contentbox_request = new FakeHttpRequest($contentbox_copy);
     $fake_request_factory->register('GET', 'http://api.talis.com/stores/example/items/mirrors/' . $url, $fake_contentbox_request);
     $putResponse = new HttpResponse('201');
     $fake_postContent_request = new FakeHttpRequest($putResponse);
     $fake_request_factory->register('PUT', 'http://api.talis.com/stores/example/items/mirrors/' . $url, $fake_postContent_request);
     $postDataResponse = new HttpResponse('409');
     $fake_postData_request = new FakeHttpRequest($postDataResponse);
     $fake_request_factory->register('POST', 'http://api.talis.com/stores/example/meta', $fake_postData_request);
     $submitDataToMetaboxResponse = new HttpResponse('204');
     $fake_submitDataToMetabox_request = new FakeHttpRequest($submitDataToMetaboxResponse);
     $fake_request_factory->register('POST', 'http://api.talis.com/stores/example/meta', $fake_submitDataToMetabox_request);
     $resubmitChangesetResponse = new HttpResponse('202');
     $fake_resubmitChangeset_request = new FakeHttpRequest($resubmitChangesetResponse);
     $fake_request_factory->register('POST', 'http://api.talis.com/stores/example/meta', $fake_resubmitChangeset_request);
     $store = new Store("http://api.talis.com/stores/example", new FakeCredentials(), $fake_request_factory);
     $response = $store->mirror_from_url($url);
     $this->assertTrue($fake_webpage_request->was_executed(), "The webpage {$url} should be retrieved over HTTP");
     $this->assertTrue($fake_contentbox_request->was_executed(), "Store:mirror_from_url should attempt to retrieve a copy of {$url} from the content box at {storeuri}/items/mirrors/{$url} if it exists yet.");
     $this->assertTrue($fake_postData_request->was_executed(), "The data from {$url}  (and its metadata) should be added to the store by POSTing a document containing changesets to /meta");
     $this->assertTrue($fake_submitDataToMetabox_request->was_executed(), "The before graph should be resubmitted when the changeset returns 409");
     $this->assertTrue($fake_resubmitChangeset_request->was_executed(), "The changeset should be resubmitted");
     $this->assertTrue($fake_postContent_request->was_executed(), "The contents of {$url} should be POSTed to the contentbox");
     $expected_response = array('get_page' => $webpage_response, 'get_copy' => $contentbox_copy, 'put_page' => $putResponse, 'update_data' => $resubmitChangesetResponse, 'success' => true, 'reapply_before_triples' => $submitDataToMetaboxResponse);
     $this->assertEquals($expected_response, $response, "");
 }
示例#16
0
 function test_read_data_fetches_multiple_urls()
 {
     $fake_request_factory = new FakeRequestFactory();
     $fake_response = new HttpResponse();
     $fake_response->status_code = 200;
     $fake_response->body = $this->_single_triple;
     $fake_response->headers['content-type'] = 'application/rdf+xml';
     $fake_request1 = new FakeHttpRequest($fake_response);
     $fake_request_factory->register('GET', 'http://example.org/thing1', $fake_request1);
     $fake_request2 = new FakeHttpRequest($fake_response);
     $fake_request_factory->register('GET', 'http://example.org/thing2', $fake_request2);
     $fake_request3 = new FakeHttpRequest($fake_response);
     $fake_request_factory->register('GET', 'http://example.org/thing3', $fake_request3);
     $g = new SimpleGraph();
     $g->set_request_factory($fake_request_factory);
     $g->read_data(array('http://example.org/thing1', 'http://example.org/thing2', 'http://example.org/thing3'));
     $this->assertTrue($fake_request1->was_executed());
     $this->assertTrue($fake_request2->was_executed());
     $this->assertTrue($fake_request3->was_executed());
 }
 function test_retrieve_sets_accept()
 {
     $fake_request_factory = new FakeRequestFactory();
     $fake_request = new FakeHttpRequest(new HttpResponse());
     $fake_request_factory->register('GET', "http://example.org/stores", $fake_request);
     $coll = new StoreCollection("http://example.org/stores");
     $coll->request_factory = $fake_request_factory;
     $coll->retrieve();
     $this->assertTrue(in_array('Accept: application/rdf+xml', $fake_request->get_headers()));
 }