triannon-client 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env_example +16 -2
- data/.rspec +1 -0
- data/README.md +49 -18
- data/Rakefile +15 -2
- data/lib/triannon-client.rb +12 -6
- data/lib/triannon-client/configuration.rb +26 -14
- data/lib/triannon-client/triannon_client.rb +139 -44
- data/spec/fixtures/vcr_cassettes/{TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/gets_an_open_annotation_by_ID_with_content_type_application/x-turtle_.yml → CRUD/create_annotation.yml} +192 -132
- data/spec/fixtures/vcr_cassettes/TriannonClientAUTH/with_authentication/behaves_like_authenticate/-_authenticate_returns_true.yml +343 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientCREATE/_post_annotation/with_authentication/behaves_like_create_annotations/POST_401_response_retries_and_logs_RestClient_Exception_message.yml +170 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientCREATE/_post_annotation/with_authentication/behaves_like_create_annotations/POST_403_response_does_not_retry_and_logs_RestClient_Exception_message.yml +170 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientCREATE/_post_annotation/with_authentication/behaves_like_create_annotations/POST_500_response_does_not_retry_and_logs_RestClient_Exception_message.yml +170 -0
- data/spec/fixtures/vcr_cassettes/{TriannonClient/_get_annotations/returns_an_annotation_list_with_an_annotation_created_by_a_prior_POST.yml → TriannonClientCREATE/_post_annotation/with_authentication/behaves_like_create_annotations/does_not_raise_an_error_when_submitting_a_valid_open_annotation.yml} +203 -319
- data/spec/fixtures/vcr_cassettes/TriannonClientCREATE/_post_annotation/with_authentication/behaves_like_create_annotations/logs_RuntimeError_message.yml +170 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientCREATE/_post_annotation/with_authentication/behaves_like_create_annotations/returns_a_RestClient_Response_object.yml +170 -0
- data/spec/fixtures/vcr_cassettes/{TriannonClient/_post_annotation → TriannonClientCREATE/_post_annotation/without_authentication/behaves_like_create_annotations}/does_not_raise_an_error_when_submitting_a_valid_open_annotation.yml +29 -27
- data/spec/fixtures/vcr_cassettes/TriannonClientCREATE/clear_annotations.yml +590 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientDELETE/_delete_annotation/with_authentication/behaves_like_delete_annotations/returns_TRUE_when_deleting_an_annotation_that_does_NOT_exist.yml +349 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientDELETE/_delete_annotation/with_authentication/behaves_like_delete_annotations/returns_TRUE_when_deleting_an_annotation_that_exists.yml +332 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientDELETE/_delete_annotation/with_authentication/behaves_like_delete_annotations/validates_the_annotation_ID.yml +288 -0
- data/spec/fixtures/vcr_cassettes/{TriannonClient/_delete_annotation/returns_TRUE_when_deleting_an_open_annotation_that_does_NOT_exist.yml → TriannonClientDELETE/_delete_annotation/without_authentication/behaves_like_delete_annotations/returns_TRUE_when_deleting_an_annotation_that_does_NOT_exist.yml} +13 -9
- data/spec/fixtures/vcr_cassettes/TriannonClientDELETE/_delete_annotation/without_authentication/behaves_like_delete_annotations/returns_TRUE_when_deleting_an_annotation_that_exists.yml +127 -0
- data/spec/fixtures/vcr_cassettes/{TriannonClient/_delete_annotation → TriannonClientDELETE/_delete_annotation/without_authentication/behaves_like_delete_annotations}/validates_the_annotation_ID.yml +7 -5
- data/spec/fixtures/vcr_cassettes/TriannonClientDELETE/clear_annotations.yml +594 -0
- data/spec/fixtures/vcr_cassettes/{TriannonClient → TriannonClientREAD/GET}/_get_annotations/returns_an_RDF_Graph.yml +30 -23
- data/spec/fixtures/vcr_cassettes/{TriannonClient → TriannonClientREAD/GET}/_get_annotations/returns_an_RDF_Graph_that_contains_an_AnnotationList.yml +30 -23
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/_get_annotations/returns_an_annotation_list_with_an_annotation_created_by_a_prior_POST.yml +302 -0
- data/spec/fixtures/vcr_cassettes/{TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/n-quads_.yml → TriannonClientREAD/GET/_get_iiif_annotation/returns_an_RDF_Graph_of_an_open_annotation.yml} +25 -78
- data/spec/fixtures/vcr_cassettes/{TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/n-triples_.yml → TriannonClientREAD/GET/_get_oa_annotation/returns_an_RDF_Graph_of_an_open_annotation.yml} +25 -78
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/_response2graph/accepts_a_RestClient_Response_instance.yml +2399 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/csvm_json_.yml +1231 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/n-quads_.yml +1231 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/n-triples_.yml +1231 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/rdf_json_.yml +1231 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/rdf_n3_.yml +1231 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/trig_.yml +1231 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/trix_.yml +1231 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/turtle_.yml +1231 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/x-ld_json_.yml +1231 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/x-trig_.yml +1231 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/csv_.yml +1231 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/n3_.yml +1231 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/plain_.yml +1231 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/rdf_n3_.yml +1231 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/rdf_turtle_.yml +1231 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/tab-separated-values_.yml +1231 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/x-nquads_.yml +1231 -0
- data/spec/fixtures/vcr_cassettes/{TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application → TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/gets_an_open_annotation_by_ID_with_content_type_application}/ld_json_.yml +25 -78
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/gets_an_open_annotation_by_ID_with_content_type_application/rdf_xml_.yml +68 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/gets_an_open_annotation_by_ID_with_content_type_application/x-turtle_.yml +69 -0
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/gets_an_open_annotation_by_ID_with_content_type_text/turtle_.yml +69 -0
- data/spec/fixtures/vcr_cassettes/{TriannonClient/GET_annotation_by_ID_/_get_annotation/without_content_type → TriannonClientREAD/GET/annotation_by_ID/using_default_content_type}/checks_the_annotation_ID.yml +25 -78
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_default_content_type/returns_an_EMPTY_RDF_graph_with_a_valid_ID_for_NO_annotation_on_the_server.yml +186 -0
- data/spec/fixtures/vcr_cassettes/{TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/rdf_json_.yml → TriannonClientREAD/GET/annotation_by_ID/using_default_content_type/returns_an_RDF_graph_with_a_valid_ID_for_an_annotation_on_the_server.yml} +25 -78
- data/spec/fixtures/vcr_cassettes/TriannonClientREAD/clear_annotations.yml +648 -0
- data/spec/fixtures/vcr_cassettes/{TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/gets_an_open_annotation_by_ID_with_content_type_application/rdf_xml_.yml → TriannonClientREAD/create_annotation.yml} +192 -131
- data/spec/lib/triannon-client/configuration_spec.rb +83 -27
- data/spec/lib/triannon-client/triannon_client_auth_spec.rb +61 -0
- data/spec/lib/triannon-client/triannon_client_class_spec.rb +104 -0
- data/spec/lib/triannon-client/triannon_client_create_spec.rb +119 -0
- data/spec/lib/triannon-client/triannon_client_delete_spec.rb +117 -0
- data/spec/lib/triannon-client/triannon_client_read_spec.rb +342 -0
- data/spec/spec_helper.rb +140 -4
- data/triannon-client.gemspec +1 -1
- metadata +112 -153
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/n-quads_.yml +0 -3995
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/n-triples_.yml +0 -3995
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/rdf_json_.yml +0 -3995
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/rdf_n3_.yml +0 -3995
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/trig_.yml +0 -3995
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/trix_.yml +0 -3995
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/turtle_.yml +0 -3995
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/x-ld_json_.yml +0 -3995
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/x-trig_.yml +0 -3995
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/n3_.yml +0 -3995
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/rdf_n3_.yml +0 -3995
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/rdf_turtle_.yml +0 -3995
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/x-nquads_.yml +0 -3995
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/gets_an_open_annotation_by_ID_with_content_type_application/ld_json_.yml +0 -4946
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/gets_an_open_annotation_by_ID_with_content_type_text/turtle_.yml +0 -2566
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/rdf_n3_.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/rdf_xml_.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/trig_.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/trix_.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/turtle_.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/x-ld_json_.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/x-trig_.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/x-turtle_.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_text/n3_.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_text/rdf_n3_.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_text/rdf_turtle_.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_text/turtle_.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_text/x-nquads_.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/without_content_type/logs_exceptions.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/without_content_type/raises_an_argument_error_with_a_nil_ID.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/without_content_type/raises_an_argument_error_with_an_empty_string_ID.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/without_content_type/raises_an_argument_error_with_an_integer_ID.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/without_content_type/requests_an_open_annotation_by_ID_accepting_a_default_JSON-LD_content.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/without_content_type/returns_an_EMPTY_RDF_graph_for_a_500_server_response.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/without_content_type/returns_an_EMPTY_RDF_graph_with_a_valid_ID_for_NO_annotation_on_the_server.yml +0 -2561
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/without_content_type/returns_an_RDF_graph_with_a_valid_ID_for_an_annotation_on_the_server.yml +0 -4946
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_iiif_annotation/requests_an_open_annotation_by_ID_using_a_IIIF_profile.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_iiif_annotation/returns_an_RDF_Graph_of_an_open_annotation.yml +0 -2746
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_oa_annotation/requests_an_open_annotation_by_ID_using_an_OA_profile.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_oa_annotation/returns_an_RDF_Graph_of_an_open_annotation.yml +0 -4946
- data/spec/fixtures/vcr_cassettes/TriannonClient/_delete_annotation/does_not_log_exceptions_for_missing_annotations_404_responses_.yml +0 -64
- data/spec/fixtures/vcr_cassettes/TriannonClient/_delete_annotation/does_not_log_exceptions_for_missing_annotations_410_responses_.yml +0 -64
- data/spec/fixtures/vcr_cassettes/TriannonClient/_delete_annotation/logs_exceptions.yml +0 -64
- data/spec/fixtures/vcr_cassettes/TriannonClient/_delete_annotation/returns_FALSE_for_a_500_response_to_a_DELETE_request.yml +0 -64
- data/spec/fixtures/vcr_cassettes/TriannonClient/_delete_annotation/returns_TRUE_for_a_200_response_to_a_DELETE_request.yml +0 -64
- data/spec/fixtures/vcr_cassettes/TriannonClient/_delete_annotation/returns_TRUE_for_a_202_response_to_a_DELETE_request.yml +0 -64
- data/spec/fixtures/vcr_cassettes/TriannonClient/_delete_annotation/returns_TRUE_for_a_204_response_to_a_DELETE_request.yml +0 -64
- data/spec/fixtures/vcr_cassettes/TriannonClient/_delete_annotation/returns_TRUE_for_a_404_response_to_a_DELETE_request.yml +0 -64
- data/spec/fixtures/vcr_cassettes/TriannonClient/_delete_annotation/returns_TRUE_for_a_410_response_to_a_DELETE_request.yml +0 -64
- data/spec/fixtures/vcr_cassettes/TriannonClient/_delete_annotation/returns_TRUE_when_deleting_an_open_annotation_that_exists.yml +0 -2549
- data/spec/fixtures/vcr_cassettes/TriannonClient/_post_annotation/logs_exceptions.yml +0 -5355
- data/spec/fixtures/vcr_cassettes/TriannonClient/_post_annotation/logs_exceptions_for_RestClient_Exception.yml +0 -5355
- data/spec/fixtures/vcr_cassettes/TriannonClient/_post_annotation/returns_a_RestClient_Response_object.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/response_processing_utilities/_annotation_id/returns_a_String_ID_from_the_RDF_URI_of_an_annotation.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/response_processing_utilities/_annotation_id/returns_a_String_ID_that_is_not_empty.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/response_processing_utilities/_annotation_uris/returns_an_RDF_URI_that_is_a_valid_URI.yml +0 -2551
- data/spec/fixtures/vcr_cassettes/TriannonClient/response_processing_utilities/_annotation_uris/returns_an_array_of_RDF_URI_from_an_RDF_Graph_of_an_annotation.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/response_processing_utilities/_response2graph/accepts_a_RestClient_Response_instance.yml +0 -4898
- data/spec/fixtures/vcr_cassettes/TriannonClient/response_processing_utilities/_response2graph/raises_ArgumentError_when_given_an_empty_String.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/response_processing_utilities/_response2graph/raises_ArgumentError_when_given_nil.yml +0 -2502
- data/spec/fixtures/vcr_cassettes/TriannonClient/response_processing_utilities/_response2graph/returns_an_RDF_Graph.yml +0 -2502
- data/spec/lib/triannon-client/triannon_client_spec.rb +0 -546
@@ -1,546 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
# ::TriannonClient::TriannonClient class specs
|
4
|
-
|
5
|
-
describe TriannonClient, :vcr do
|
6
|
-
|
7
|
-
let(:tc) { TriannonClient::TriannonClient.new }
|
8
|
-
# Note: not using `let` approach for these methods because it
|
9
|
-
# makes it very difficult to delete any annotations created by
|
10
|
-
# the `tc.post_annotation`; so the `create_annotation` and the
|
11
|
-
# `delete_annotation` methods are used in several before/after
|
12
|
-
# blocks within describe blocks, as required.
|
13
|
-
# let(:post_response) { tc.post_annotation(@oa_jsonld) }
|
14
|
-
# let(:anno_graph) { tc.response2graph(post_response) }
|
15
|
-
# let(:anno_uri) { tc.annotation_uri(anno_graph) }
|
16
|
-
# let(:anno_id) { tc.annotation_id(anno_uri) }
|
17
|
-
|
18
|
-
before :all do
|
19
|
-
Dotenv.load
|
20
|
-
@oa_jsonld = '{"@context":"http://iiif.io/api/presentation/2/context.json","@graph":[{"@id":"_:g70349699654640","@type":["dctypes:Text","cnt:ContentAsText"],"chars":"I love this!","format":"text/plain","language":"en"},{"@type":"oa:Annotation","motivation":"oa:commenting","on":"http://purl.stanford.edu/kq131cs7229","resource":"_:g70349699654640"}]}'
|
21
|
-
clear_annotations
|
22
|
-
end
|
23
|
-
|
24
|
-
def clear_annotations
|
25
|
-
client = TriannonClient::TriannonClient.new
|
26
|
-
annos = client.get_annotations
|
27
|
-
q = [nil, RDF.type, RDF::Vocab::OA.Annotation]
|
28
|
-
anno_ids = annos.query(q).each_subject.collect {|s| tc.annotation_id(s)}
|
29
|
-
anno_ids.each {|id| client.delete_annotation(id) }
|
30
|
-
end
|
31
|
-
|
32
|
-
def create_annotation
|
33
|
-
r = tc.post_annotation(@oa_jsonld)
|
34
|
-
g = tc.response2graph(r)
|
35
|
-
uri = tc.annotation_uris(g).first
|
36
|
-
id = tc.annotation_id(uri)
|
37
|
-
{
|
38
|
-
response: r,
|
39
|
-
graph: g,
|
40
|
-
uri: uri,
|
41
|
-
id: id
|
42
|
-
}
|
43
|
-
end
|
44
|
-
|
45
|
-
def delete_annotation(id)
|
46
|
-
tc.delete_annotation(id)
|
47
|
-
end
|
48
|
-
|
49
|
-
def graph_has_statements(graph)
|
50
|
-
expect(graph).to be_instance_of RDF::Graph
|
51
|
-
expect(graph).not_to be_empty
|
52
|
-
expect(graph.size).to be > 2
|
53
|
-
end
|
54
|
-
|
55
|
-
def graph_is_empty(graph)
|
56
|
-
expect(graph).to be_instance_of RDF::Graph
|
57
|
-
expect(graph).to be_empty
|
58
|
-
end
|
59
|
-
|
60
|
-
def graph_contains_open_annotation(graph, uri)
|
61
|
-
result = graph.query([nil, RDF.type, RDF::Vocab::OA.Annotation])
|
62
|
-
expect(result.size).to be > 0
|
63
|
-
expect(result.each_subject.collect{|s| s}).to include(uri)
|
64
|
-
end
|
65
|
-
|
66
|
-
describe 'has constants:' do
|
67
|
-
it 'CONTENT_TYPES' do
|
68
|
-
const = TriannonClient::TriannonClient::CONTENT_TYPES
|
69
|
-
expect(const).to be_instance_of Array
|
70
|
-
expect(const).to include('application/ld+json')
|
71
|
-
end
|
72
|
-
it 'PROFILE_TYPE_IIIF' do
|
73
|
-
const = TriannonClient::TriannonClient::PROFILE_IIIF
|
74
|
-
expect(const).to be_instance_of String
|
75
|
-
expect(const).to include('http://iiif.io/api/presentation/2/context.json')
|
76
|
-
end
|
77
|
-
it 'PROFILE_TYPE_OA' do
|
78
|
-
const = TriannonClient::TriannonClient::PROFILE_OA
|
79
|
-
expect(const).to be_instance_of String
|
80
|
-
expect(const).to include('http://www.w3.org/ns/oa-context-20130208.json')
|
81
|
-
end
|
82
|
-
it 'CONTENT_TYPE_IIIF' do
|
83
|
-
const = TriannonClient::TriannonClient::CONTENT_TYPE_IIIF
|
84
|
-
expect(const).to be_instance_of String
|
85
|
-
expect(const).to include('application/ld+json')
|
86
|
-
expect(const).to include('http://iiif.io/api/presentation/2/context.json')
|
87
|
-
end
|
88
|
-
it 'CONTENT_TYPE_OA' do
|
89
|
-
const = TriannonClient::TriannonClient::CONTENT_TYPE_OA
|
90
|
-
expect(const).to be_instance_of String
|
91
|
-
expect(const).to include('application/ld+json')
|
92
|
-
expect(const).to include('http://www.w3.org/ns/oa-context-20130208.json')
|
93
|
-
end
|
94
|
-
it 'JSONLD_TYPE' do
|
95
|
-
const = TriannonClient::TriannonClient::JSONLD_TYPE
|
96
|
-
expect(const).to be_instance_of String
|
97
|
-
expect(const).to eql('application/ld+json')
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe 'has public methods:' do
|
102
|
-
it 'delete_annotation' do
|
103
|
-
expect(tc).to respond_to(:delete_annotation)
|
104
|
-
end
|
105
|
-
it 'get_annotations' do
|
106
|
-
expect(tc).to respond_to(:get_annotations)
|
107
|
-
end
|
108
|
-
it 'get_annotation' do
|
109
|
-
expect(tc).to respond_to(:get_annotation)
|
110
|
-
end
|
111
|
-
it 'get_iiif_annotation' do
|
112
|
-
expect(tc).to respond_to(:get_iiif_annotation)
|
113
|
-
end
|
114
|
-
it 'get_oa_annotation' do
|
115
|
-
expect(tc).to respond_to(:get_oa_annotation)
|
116
|
-
end
|
117
|
-
it 'site' do
|
118
|
-
expect(tc).to respond_to(:site)
|
119
|
-
end
|
120
|
-
# utilities
|
121
|
-
it 'response2graph' do
|
122
|
-
expect(tc).to respond_to(:response2graph)
|
123
|
-
end
|
124
|
-
it 'annotation_id' do
|
125
|
-
expect(tc).to respond_to(:annotation_id)
|
126
|
-
end
|
127
|
-
it 'annotation_uris' do
|
128
|
-
expect(tc).to respond_to(:annotation_uris)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
describe 'has private methods:' do
|
133
|
-
it 'check_id' do
|
134
|
-
expect(tc).not_to respond_to(:check_id)
|
135
|
-
end
|
136
|
-
it 'check_content_type' do
|
137
|
-
expect(tc).not_to respond_to(:check_content_type)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
describe "#delete_annotation" do
|
142
|
-
def test_delete_for_response_code(anno_id, status, response)
|
143
|
-
allow_any_instance_of(RestClient::Response).to receive(:code).and_return(status)
|
144
|
-
expect(tc.delete_annotation(anno_id)).to be response
|
145
|
-
end
|
146
|
-
it "returns FALSE for a 500 response to a DELETE request" do
|
147
|
-
test_delete_for_response_code('500_is_false', 500, false)
|
148
|
-
end
|
149
|
-
it "returns TRUE for a 200 response to a DELETE request" do
|
150
|
-
test_delete_for_response_code('200_is_true', 200, true)
|
151
|
-
end
|
152
|
-
it "returns TRUE for a 202 response to a DELETE request" do
|
153
|
-
test_delete_for_response_code('202_is_true', 202, true)
|
154
|
-
end
|
155
|
-
it "returns TRUE for a 204 response to a DELETE request" do
|
156
|
-
test_delete_for_response_code('204_is_true', 204, true)
|
157
|
-
end
|
158
|
-
it "returns TRUE for a 404 response to a DELETE request" do
|
159
|
-
test_delete_for_response_code('404_is_true', 404, true)
|
160
|
-
end
|
161
|
-
it "returns TRUE for a 410 response to a DELETE request" do
|
162
|
-
test_delete_for_response_code('410_is_true', 410, true)
|
163
|
-
end
|
164
|
-
it 'validates the annotation ID' do
|
165
|
-
expect(tc).to receive(:check_id)
|
166
|
-
tc.delete_annotation('checking_anno_id')
|
167
|
-
end
|
168
|
-
it 'quits after detecting an invalid annotation ID' do
|
169
|
-
expect_any_instance_of(RestClient::Resource).not_to receive(:delete)
|
170
|
-
tc.delete_annotation('') rescue nil
|
171
|
-
tc.delete_annotation(nil) rescue nil
|
172
|
-
end
|
173
|
-
it 'uses RestClient::Resource.delete to DELETE a valid annotation ID' do
|
174
|
-
expect_any_instance_of(RestClient::Resource).to receive(:delete)
|
175
|
-
tc.delete_annotation(SecureRandom.uuid)
|
176
|
-
end
|
177
|
-
it 'returns TRUE when deleting an open annotation that exists' do
|
178
|
-
anno = create_annotation
|
179
|
-
expect( tc.delete_annotation(anno[:id]) ).to be true
|
180
|
-
graph = tc.get_annotation(anno[:id])
|
181
|
-
graph_is_empty(graph)
|
182
|
-
end
|
183
|
-
it 'returns TRUE when deleting an open annotation that does NOT exist' do
|
184
|
-
id = 'anno_does_not_exist'
|
185
|
-
graph = tc.get_annotation(id)
|
186
|
-
graph_is_empty(graph)
|
187
|
-
expect( tc.delete_annotation(id) ).to be true
|
188
|
-
end
|
189
|
-
it 'logs exceptions' do
|
190
|
-
allow_any_instance_of(RestClient::Response).to receive(:code).and_return(450)
|
191
|
-
allow_any_instance_of(RestClient::Response).to receive(:body).and_return('delete_logs_exceptions')
|
192
|
-
expect(TriannonClient.configuration.logger).to receive(:error).with(/delete_logs_exceptions/)
|
193
|
-
tc.delete_annotation('delete_logs_exceptions')
|
194
|
-
end
|
195
|
-
it 'does not log exceptions for missing annotations (404 responses)' do
|
196
|
-
allow_any_instance_of(RestClient::Response).to receive(:code).and_return(404)
|
197
|
-
allow_any_instance_of(RestClient::Response).to receive(:body).and_return('delete_does_not_log_404_exceptions')
|
198
|
-
expect(TriannonClient.configuration.logger).not_to receive(:error)
|
199
|
-
tc.delete_annotation('delete_does_not_log_404_exceptions')
|
200
|
-
end
|
201
|
-
it 'does not log exceptions for missing annotations (410 responses)' do
|
202
|
-
allow_any_instance_of(RestClient::Response).to receive(:code).and_return(410)
|
203
|
-
allow_any_instance_of(RestClient::Response).to receive(:body).and_return('delete_does_not_log_410_exceptions')
|
204
|
-
expect(TriannonClient.configuration.logger).not_to receive(:error)
|
205
|
-
tc.delete_annotation('delete_does_not_log_410_exceptions')
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
describe "#get_annotations" do
|
210
|
-
it 'returns an RDF::Graph' do
|
211
|
-
graph = tc.get_annotations
|
212
|
-
graph_has_statements(graph)
|
213
|
-
end
|
214
|
-
it 'returns an RDF::Graph that contains an AnnotationList' do
|
215
|
-
graph = tc.get_annotations
|
216
|
-
anno_list_uri = RDF::URI.parse('http://iiif.io/api/presentation/2#AnnotationList')
|
217
|
-
result = graph.query([nil, nil, anno_list_uri])
|
218
|
-
expect(result.size).to eql(1)
|
219
|
-
end
|
220
|
-
it 'returns an annotation list with an annotation created by a prior POST' do
|
221
|
-
anno = create_annotation
|
222
|
-
graph = tc.get_annotations
|
223
|
-
graph_contains_open_annotation(graph, anno[:uri])
|
224
|
-
delete_annotation(anno[:id])
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
describe "GET annotation by ID:" do
|
229
|
-
before(:example) do
|
230
|
-
# create a new annotation and call all the response processing utils.
|
231
|
-
@anno = create_annotation
|
232
|
-
end
|
233
|
-
after(:example) do
|
234
|
-
delete_annotation(@anno[:id]) # cleanup after create_annotation
|
235
|
-
end
|
236
|
-
|
237
|
-
describe "#get_annotation" do
|
238
|
-
context 'with content_type' do
|
239
|
-
# Content types could be supported for RDF::Format.content_types.keys,
|
240
|
-
# but not all of them are supported. The supported content types for
|
241
|
-
# triannon are defined in
|
242
|
-
# https://github.com/sul-dlss/triannon/blob/master/config/initializers/mime_types.rb
|
243
|
-
# https://github.com/sul-dlss/triannon/blob/master/app/controllers/triannon/annotations_controller.rb
|
244
|
-
# https://github.com/sul-dlss/triannon/blob/master/app/controllers/triannon/search_controller.rb
|
245
|
-
# The default content type is "application/ld+json" and, at the time of
|
246
|
-
# writing, triannon also supports:
|
247
|
-
# turtle as: ["application/x-turtle", "text/turtle"]
|
248
|
-
# rdf+xml as: ["application/rdf+xml", "text/rdf+xml", "text/rdf"]
|
249
|
-
# json as: ["application/json", "text/x-json", "application/jsonrequest"]
|
250
|
-
# xml as: ["application/xml", "text/xml", "application/x-xml"]
|
251
|
-
# html
|
252
|
-
def request_anno_with_content_type(content_type)
|
253
|
-
expect_any_instance_of(RestClient::Resource).to receive(:get).with(hash_including(:accept => content_type) )
|
254
|
-
tc.get_annotation(@anno[:id], content_type)
|
255
|
-
end
|
256
|
-
def gets_anno_with_content_type(content_type)
|
257
|
-
graph = tc.get_annotation(@anno[:id], content_type)
|
258
|
-
graph_has_statements(graph)
|
259
|
-
graph_contains_open_annotation(graph, @anno[:uri])
|
260
|
-
end
|
261
|
-
def cannot_get_anno_with_content_type(content_type)
|
262
|
-
graph = tc.get_annotation(@anno[:id], content_type)
|
263
|
-
graph_is_empty(graph)
|
264
|
-
end
|
265
|
-
# "text/plain",
|
266
|
-
# "text/html",
|
267
|
-
# "application/xhtml+xml",
|
268
|
-
it 'requests an open annotation by ID, with content type "application/ld+json"' do
|
269
|
-
request_anno_with_content_type("application/ld+json")
|
270
|
-
end
|
271
|
-
it 'gets an open annotation by ID, with content type "application/ld+json"' do
|
272
|
-
gets_anno_with_content_type("application/ld+json")
|
273
|
-
end
|
274
|
-
it 'requests an open annotation by ID, with content type "application/x-ld+json"' do
|
275
|
-
request_anno_with_content_type("application/x-ld+json")
|
276
|
-
end
|
277
|
-
it 'cannot get an open annotation by ID, with content type "application/x-ld+json"' do
|
278
|
-
cannot_get_anno_with_content_type("application/x-ld+json")
|
279
|
-
end
|
280
|
-
it 'requests an open annotation by ID, with content type "application/rdf+json"' do
|
281
|
-
request_anno_with_content_type("application/rdf+json")
|
282
|
-
end
|
283
|
-
it 'cannot get an open annotation by ID, with content type "application/rdf+json"' do
|
284
|
-
cannot_get_anno_with_content_type("application/rdf+json")
|
285
|
-
end
|
286
|
-
it 'requests an open annotation by ID, with content type "application/rdf+xml"' do
|
287
|
-
request_anno_with_content_type("application/rdf+xml")
|
288
|
-
end
|
289
|
-
it 'gets an open annotation by ID, with content type "application/rdf+xml"' do
|
290
|
-
gets_anno_with_content_type("application/rdf+xml")
|
291
|
-
end
|
292
|
-
it 'requests an open annotation by ID, with content type "text/turtle"' do
|
293
|
-
request_anno_with_content_type("text/turtle")
|
294
|
-
end
|
295
|
-
it 'gets an open annotation by ID, with content type "text/turtle"' do
|
296
|
-
gets_anno_with_content_type("text/turtle")
|
297
|
-
end
|
298
|
-
it 'requests an open annotation by ID, with content type "text/rdf+turtle"' do
|
299
|
-
request_anno_with_content_type("text/rdf+turtle")
|
300
|
-
end
|
301
|
-
it 'cannot get an open annotation by ID, with content type "text/rdf+turtle"' do
|
302
|
-
cannot_get_anno_with_content_type("text/rdf+turtle")
|
303
|
-
end
|
304
|
-
it 'requests an open annotation by ID, with content type "application/turtle"' do
|
305
|
-
request_anno_with_content_type("application/turtle")
|
306
|
-
end
|
307
|
-
it 'cannot get an open annotation by ID, with content type "application/turtle"' do
|
308
|
-
cannot_get_anno_with_content_type("application/turtle")
|
309
|
-
end
|
310
|
-
it 'requests an open annotation by ID, with content type "application/x-turtle"' do
|
311
|
-
request_anno_with_content_type("application/x-turtle")
|
312
|
-
end
|
313
|
-
it 'gets an open annotation by ID, with content type "application/x-turtle"' do
|
314
|
-
gets_anno_with_content_type("application/x-turtle")
|
315
|
-
end
|
316
|
-
it 'requests an open annotation by ID, with content type "application/n-triples"' do
|
317
|
-
request_anno_with_content_type("application/n-triples")
|
318
|
-
end
|
319
|
-
it 'cannot get an open annotation by ID, with content type "application/n-triples"' do
|
320
|
-
cannot_get_anno_with_content_type("application/n-triples")
|
321
|
-
end
|
322
|
-
it 'requests an open annotation by ID, with content type "application/rdf+n3"' do
|
323
|
-
request_anno_with_content_type("application/rdf+n3")
|
324
|
-
end
|
325
|
-
it 'cannot get an open annotation by ID, with content type "application/rdf+n3"' do
|
326
|
-
cannot_get_anno_with_content_type("application/rdf+n3")
|
327
|
-
end
|
328
|
-
it 'requests an open annotation by ID, with content type "text/n3"' do
|
329
|
-
request_anno_with_content_type("text/n3")
|
330
|
-
end
|
331
|
-
it 'cannot get an open annotation by ID, with content type "text/n3"' do
|
332
|
-
cannot_get_anno_with_content_type("text/n3")
|
333
|
-
end
|
334
|
-
it 'requests an open annotation by ID, with content type "text/rdf+n3"' do
|
335
|
-
request_anno_with_content_type("text/rdf+n3")
|
336
|
-
end
|
337
|
-
it 'cannot get an open annotation by ID, with content type "text/rdf+n3"' do
|
338
|
-
cannot_get_anno_with_content_type("text/rdf+n3")
|
339
|
-
end
|
340
|
-
it 'requests an open annotation by ID, with content type "application/n-quads"' do
|
341
|
-
request_anno_with_content_type("application/n-quads")
|
342
|
-
end
|
343
|
-
it 'cannot get an open annotation by ID, with content type "application/n-quads"' do
|
344
|
-
cannot_get_anno_with_content_type("application/n-quads")
|
345
|
-
end
|
346
|
-
it 'requests an open annotation by ID, with content type "text/x-nquads"' do
|
347
|
-
request_anno_with_content_type("text/x-nquads")
|
348
|
-
end
|
349
|
-
it 'cannot get an open annotation by ID, with content type "text/x-nquads"' do
|
350
|
-
cannot_get_anno_with_content_type("text/x-nquads")
|
351
|
-
end
|
352
|
-
it 'requests an open annotation by ID, with content type "application/trig"' do
|
353
|
-
request_anno_with_content_type("application/trig")
|
354
|
-
end
|
355
|
-
it 'cannot get an open annotation by ID, with content type "application/trig"' do
|
356
|
-
cannot_get_anno_with_content_type("application/trig")
|
357
|
-
end
|
358
|
-
it 'requests an open annotation by ID, with content type "application/x-trig"' do
|
359
|
-
request_anno_with_content_type("application/x-trig")
|
360
|
-
end
|
361
|
-
it 'cannot get an open annotation by ID, with content type "application/x-trig"' do
|
362
|
-
cannot_get_anno_with_content_type("application/x-trig")
|
363
|
-
end
|
364
|
-
it 'requests an open annotation by ID, with content type "application/trix"' do
|
365
|
-
request_anno_with_content_type("application/trix")
|
366
|
-
end
|
367
|
-
it 'cannot get an open annotation by ID, with content type "application/trix"' do
|
368
|
-
cannot_get_anno_with_content_type("application/trix")
|
369
|
-
end
|
370
|
-
end
|
371
|
-
context 'without content_type' do
|
372
|
-
it 'requests an open annotation by ID, accepting a default JSON-LD content' do
|
373
|
-
graph_contains_open_annotation(@anno[:graph], @anno[:uri])
|
374
|
-
content_type = TriannonClient::TriannonClient::JSONLD_TYPE
|
375
|
-
expect_any_instance_of(RestClient::Resource).to receive(:get).with(hash_including(:accept => content_type) )
|
376
|
-
tc.get_annotation(@anno[:id])
|
377
|
-
end
|
378
|
-
it 'checks the annotation ID' do
|
379
|
-
expect(tc).to receive(:check_id) # tested by #create_annotation
|
380
|
-
graph_has_statements(@anno[:graph]) # check #create_annotation worked
|
381
|
-
end
|
382
|
-
it 'raises an argument error with a nil ID' do
|
383
|
-
expect{tc.get_annotation(nil)}.to raise_error(ArgumentError)
|
384
|
-
end
|
385
|
-
it 'raises an argument error with an integer ID' do
|
386
|
-
expect{tc.get_annotation(0)}.to raise_error(ArgumentError)
|
387
|
-
end
|
388
|
-
it 'raises an argument error with an empty string ID' do
|
389
|
-
expect{tc.get_annotation('')}.to raise_error(ArgumentError)
|
390
|
-
end
|
391
|
-
it 'returns an RDF graph with a valid ID for an annotation on the server' do
|
392
|
-
graph = tc.get_annotation(@anno[:id])
|
393
|
-
graph_has_statements(graph)
|
394
|
-
graph_contains_open_annotation(@anno[:graph], @anno[:uri])
|
395
|
-
end
|
396
|
-
it 'returns an EMPTY RDF graph with a valid ID for NO annotation on the server' do
|
397
|
-
id = SecureRandom.uuid
|
398
|
-
graph = tc.get_annotation(id)
|
399
|
-
graph_is_empty(graph)
|
400
|
-
end
|
401
|
-
it 'returns an EMPTY RDF graph for a 500 server response' do
|
402
|
-
response = double
|
403
|
-
allow(response).to receive(:is_a?).and_return(RestClient::Response)
|
404
|
-
allow(response).to receive(:headers).and_return({content_type: 'application/ld+json'})
|
405
|
-
allow(response).to receive(:code).and_return(500)
|
406
|
-
allow_any_instance_of(RestClient::Resource).to receive(:get).and_return(response)
|
407
|
-
graph = tc.get_annotation(@anno[:id])
|
408
|
-
graph_is_empty(graph)
|
409
|
-
end
|
410
|
-
it 'logs exceptions' do
|
411
|
-
allow_any_instance_of(RestClient::Resource).to receive(:get).and_raise('get_exception')
|
412
|
-
expect(TriannonClient.configuration.logger).to receive(:error).with(/get_exception/)
|
413
|
-
tc.get_annotation('raise_get_exception')
|
414
|
-
end
|
415
|
-
end
|
416
|
-
end
|
417
|
-
|
418
|
-
describe "#get_iiif_annotation" do
|
419
|
-
# the mime type is fixed for this method
|
420
|
-
it 'requests an open annotation by ID, using a IIIF profile' do
|
421
|
-
graph_contains_open_annotation(@anno[:graph], @anno[:uri])
|
422
|
-
content_type = TriannonClient::TriannonClient::CONTENT_TYPE_IIIF
|
423
|
-
expect(tc).to receive(:get_annotation).with(@anno[:id], content_type)
|
424
|
-
tc.get_iiif_annotation(@anno[:id])
|
425
|
-
end
|
426
|
-
it 'returns an RDF::Graph of an open annotation' do
|
427
|
-
graph = tc.get_iiif_annotation(@anno[:id])
|
428
|
-
graph_has_statements(graph)
|
429
|
-
graph_contains_open_annotation(@anno[:graph], @anno[:uri])
|
430
|
-
end
|
431
|
-
end
|
432
|
-
|
433
|
-
describe "#get_oa_annotation" do
|
434
|
-
# the mime type is fixed for this method
|
435
|
-
it 'requests an open annotation by ID, using an OA profile' do
|
436
|
-
graph_contains_open_annotation(@anno[:graph], @anno[:uri])
|
437
|
-
content_type = TriannonClient::TriannonClient::CONTENT_TYPE_OA
|
438
|
-
expect(tc).to receive(:get_annotation).with(@anno[:id], content_type)
|
439
|
-
tc.get_oa_annotation(@anno[:id])
|
440
|
-
end
|
441
|
-
it 'returns an RDF::Graph of an open annotation' do
|
442
|
-
graph = tc.get_oa_annotation(@anno[:id])
|
443
|
-
graph_has_statements(graph)
|
444
|
-
graph_contains_open_annotation(@anno[:graph], @anno[:uri])
|
445
|
-
end
|
446
|
-
end
|
447
|
-
|
448
|
-
end
|
449
|
-
|
450
|
-
describe "#post_annotation" do
|
451
|
-
it 'does not raise an error when submitting a valid open annotation' do
|
452
|
-
response = nil
|
453
|
-
expect do
|
454
|
-
response = tc.post_annotation(@oa_jsonld)
|
455
|
-
end.not_to raise_error
|
456
|
-
# Double check the POST by deleting the annotation.
|
457
|
-
# If the POST was successful, the DELETE should work too.
|
458
|
-
graph = tc.response2graph(response)
|
459
|
-
uri = tc.annotation_uris(graph).first
|
460
|
-
id = tc.annotation_id(uri)
|
461
|
-
expect(tc.delete_annotation(id)).to be true
|
462
|
-
end
|
463
|
-
it 'returns a RestClient::Response object' do
|
464
|
-
# The response behaves primarily as a String, so it can not be tested
|
465
|
-
# as an instance of RestClient::Response, but it can be tested to respond
|
466
|
-
# to RestClient::Response methods.
|
467
|
-
anno = create_annotation
|
468
|
-
r = anno[:response]
|
469
|
-
expect(r.is_a? RestClient::Response).to be true
|
470
|
-
expect(r).to respond_to(:code)
|
471
|
-
expect(r).to respond_to(:body)
|
472
|
-
expect(r).to respond_to(:headers)
|
473
|
-
delete_annotation(anno[:id]) # cleanup after create_annotation
|
474
|
-
end
|
475
|
-
it 'logs exceptions for RestClient::Exception' do
|
476
|
-
exception_response = double()
|
477
|
-
allow(exception_response).to receive(:code).and_return(500)
|
478
|
-
allow(exception_response).to receive(:body).and_return('post_logs_exceptions')
|
479
|
-
allow_any_instance_of(RestClient::Exception).to receive(:response).and_return(exception_response)
|
480
|
-
expect(TriannonClient.configuration.logger).to receive(:error).with(/post_logs_exceptions/)
|
481
|
-
tc.post_annotation('post_logs_exceptions')
|
482
|
-
end
|
483
|
-
it 'logs exceptions' do
|
484
|
-
exception_response = double()
|
485
|
-
allow(exception_response).to receive(:code).and_return(500)
|
486
|
-
allow(exception_response).to receive(:body).and_return('post_logs_exceptions')
|
487
|
-
allow_any_instance_of(RestClient::Exception).to receive(:response).and_return(exception_response)
|
488
|
-
expect(TriannonClient.configuration.logger).to receive(:error).with(/post_logs_exceptions/)
|
489
|
-
tc.post_annotation('post_logs_exceptions')
|
490
|
-
end
|
491
|
-
end
|
492
|
-
|
493
|
-
|
494
|
-
describe 'response processing utilities' do
|
495
|
-
|
496
|
-
before(:example) do
|
497
|
-
# create a new annotation and call all the response processing utils.
|
498
|
-
@anno = create_annotation
|
499
|
-
end
|
500
|
-
after(:example) do
|
501
|
-
delete_annotation(@anno[:id]) # cleanup after create_annotation
|
502
|
-
end
|
503
|
-
|
504
|
-
describe '#response2graph' do
|
505
|
-
it 'accepts a RestClient::Response instance' do
|
506
|
-
r = @anno[:response]
|
507
|
-
expect{tc.response2graph(r)}.not_to raise_error
|
508
|
-
end
|
509
|
-
it 'raises ArgumentError when given nil' do
|
510
|
-
expect{tc.response2graph(nil)}.to raise_error(ArgumentError)
|
511
|
-
end
|
512
|
-
it 'raises ArgumentError when given an empty String' do
|
513
|
-
expect{tc.response2graph('')}.to raise_error(ArgumentError)
|
514
|
-
end
|
515
|
-
it 'returns an RDF::Graph' do
|
516
|
-
expect(@anno[:graph]).to be_instance_of RDF::Graph
|
517
|
-
end
|
518
|
-
end
|
519
|
-
|
520
|
-
describe "#annotation_uris" do
|
521
|
-
it "returns an array of RDF::URI from an RDF::Graph of an annotation" do
|
522
|
-
expect(@anno[:graph]).to be_instance_of RDF::Graph
|
523
|
-
expect(tc.annotation_uris(@anno[:graph])).to be_instance_of Array
|
524
|
-
expect(@anno[:uri]).to be_instance_of RDF::URI
|
525
|
-
end
|
526
|
-
it "returns an RDF::URI that is a valid URI" do
|
527
|
-
expect(@anno[:uri]).to match(/\A#{URI::regexp}\z/)
|
528
|
-
delete_annotation(@anno[:id]) # cleanup after create_annotation
|
529
|
-
end
|
530
|
-
end
|
531
|
-
|
532
|
-
describe "#annotation_id" do
|
533
|
-
it "returns a String ID from the RDF::URI of an annotation" do
|
534
|
-
expect(@anno[:uri]).to be_instance_of RDF::URI
|
535
|
-
expect(@anno[:id]).to be_instance_of String
|
536
|
-
end
|
537
|
-
it "returns a String ID that is not empty" do
|
538
|
-
expect(@anno[:id]).to be_instance_of String
|
539
|
-
expect(@anno[:id].empty?).to be false
|
540
|
-
end
|
541
|
-
end
|
542
|
-
|
543
|
-
end
|
544
|
-
|
545
|
-
end
|
546
|
-
|