active-fedora 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (246) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/.hg/00changelog.i +0 -0
  4. data/.hg/branch +1 -0
  5. data/.hg/branch.cache +2 -0
  6. data/.hg/dirstate +0 -0
  7. data/.hg/hgrc +2 -0
  8. data/.hg/requires +2 -0
  9. data/.hg/store/00changelog.i +0 -0
  10. data/.hg/store/00manifest.i +0 -0
  11. data/.hg/store/data/.hgignore.i +0 -0
  12. data/.hg/store/data/.hgtags.i +0 -0
  13. data/.hg/store/data/_c_o_p_y_i_n_g.txt.i +0 -0
  14. data/.hg/store/data/_c_o_y_i_n_g._l_e_s_s_e_r.txt.i +0 -0
  15. data/.hg/store/data/_history.txt.i +0 -0
  16. data/.hg/store/data/_license.txt.i +0 -0
  17. data/.hg/store/data/_manifest.txt.i +0 -0
  18. data/.hg/store/data/_post_install.txt.i +0 -0
  19. data/.hg/store/data/_r_e_a_d_m_e.rdoc.i +0 -0
  20. data/.hg/store/data/_r_e_a_d_m_e.txt.i +0 -0
  21. data/.hg/store/data/_rakefile.i +0 -0
  22. data/.hg/store/data/_v_e_r_s_i_o_n.i +0 -0
  23. data/.hg/store/data/active-fedora.gemspec.i +0 -0
  24. data/.hg/store/data/active__fedora/_history.txt.i +0 -0
  25. data/.hg/store/data/active__fedora/_manifest.txt.i +0 -0
  26. data/.hg/store/data/active__fedora/_post_install.txt.i +0 -0
  27. data/.hg/store/data/active__fedora/_r_e_a_d_m_e.rdoc.i +0 -0
  28. data/.hg/store/data/active__fedora/_rakefile.i +0 -0
  29. data/.hg/store/data/active__fedora/lib/active__fedora.rb.i +0 -0
  30. data/.hg/store/data/active__fedora/script/console.i +0 -0
  31. data/.hg/store/data/active__fedora/script/destroy.i +0 -0
  32. data/.hg/store/data/active__fedora/script/generate.i +0 -0
  33. data/.hg/store/data/active__fedora/spec/active__fedora__spec.rb.i +0 -0
  34. data/.hg/store/data/active__fedora/spec/spec__helper.rb.i +0 -0
  35. data/.hg/store/data/config/fedora.yml.i +0 -0
  36. data/.hg/store/data/config/solr__mappings.yml.i +0 -0
  37. data/.hg/store/data/config/solr__mappings__af__0.1.yml.i +0 -0
  38. data/.hg/store/data/config/solr__mappings__bl__2.4.yml.i +0 -0
  39. data/.hg/store/data/lib/active-fedora.rb.i +0 -0
  40. data/.hg/store/data/lib/active__fedora.rb.i +0 -0
  41. data/.hg/store/data/lib/active__fedora/base.rb.i +0 -0
  42. data/.hg/store/data/lib/active__fedora/content__model.rb.i +0 -0
  43. data/.hg/store/data/lib/active__fedora/datastream.rb.i +0 -0
  44. data/.hg/store/data/lib/active__fedora/fedora__object.rb.i +0 -0
  45. data/.hg/store/data/lib/active__fedora/metadata__datastream.rb.i +0 -0
  46. data/.hg/store/data/lib/active__fedora/model.rb.i +0 -0
  47. data/.hg/store/data/lib/active__fedora/property.rb.i +0 -0
  48. data/.hg/store/data/lib/active__fedora/qualified__dublin__core__datastream.rb.i +0 -0
  49. data/.hg/store/data/lib/active__fedora/relationship.rb.i +0 -0
  50. data/.hg/store/data/lib/active__fedora/rels__ext__datastream.rb.i +0 -0
  51. data/.hg/store/data/lib/active__fedora/semantic__node.rb.i +0 -0
  52. data/.hg/store/data/lib/active__fedora/solr__mapper.rb.i +0 -0
  53. data/.hg/store/data/lib/active__fedora/solr__service.rb.i +0 -0
  54. data/.hg/store/data/lib/fedora/base.rb.i +0 -0
  55. data/.hg/store/data/lib/fedora/connection.rb.i +0 -0
  56. data/.hg/store/data/lib/fedora/datastream.rb.i +0 -0
  57. data/.hg/store/data/lib/fedora/fedora__object.rb.i +0 -0
  58. data/.hg/store/data/lib/fedora/formats.rb.i +0 -0
  59. data/.hg/store/data/lib/fedora/generic__search.rb.i +0 -0
  60. data/.hg/store/data/lib/fedora/repository.rb.i +0 -0
  61. data/.hg/store/data/lib/ruby-fedora.rb.i +0 -0
  62. data/.hg/store/data/lib/util/class__level__inheritable__attributes.rb.i +0 -0
  63. data/.hg/store/data/script/console.i +0 -0
  64. data/.hg/store/data/script/destroy.i +0 -0
  65. data/.hg/store/data/script/generate.i +0 -0
  66. data/.hg/store/data/solr/config/schema-1.5.xml.i +0 -0
  67. data/.hg/store/data/solr/config/schema.xml.i +0 -0
  68. data/.hg/store/data/solr/config/solrconfig-1.5.xml.i +0 -0
  69. data/.hg/store/data/spec/fixtures/changeme155.xml.i +0 -0
  70. data/.hg/store/data/spec/fixtures/dino.jpg.i +0 -0
  71. data/.hg/store/data/spec/fixtures/minivan.jpg.d +0 -0
  72. data/.hg/store/data/spec/fixtures/minivan.jpg.i +0 -0
  73. data/.hg/store/data/spec/fixtures/test__12.foxml.xml.i +0 -0
  74. data/.hg/store/data/spec/integration/active__fedora/base__spec.rb.i +0 -0
  75. data/.hg/store/data/spec/integration/active__fedora/datastream__spec.rb.i +0 -0
  76. data/.hg/store/data/spec/integration/active__fedora/fedora__object__spec.rb.i +0 -0
  77. data/.hg/store/data/spec/integration/active__fedora/full__featured__model__spec.rb.i +0 -0
  78. data/.hg/store/data/spec/integration/active__fedora/model__spec.rb.i +0 -0
  79. data/.hg/store/data/spec/integration/active__fedora/rels__ext__datastream__spec.rb.i +0 -0
  80. data/.hg/store/data/spec/integration/active__fedora/semantic__node__spec.rb.i +0 -0
  81. data/.hg/store/data/spec/integration/base__file__management__spec.rb.i +0 -0
  82. data/.hg/store/data/spec/integration/base__spec.rb.i +0 -0
  83. data/.hg/store/data/spec/integration/bug__spec.rb.i +0 -0
  84. data/.hg/store/data/spec/integration/datastream__spec.rb.i +0 -0
  85. data/.hg/store/data/spec/integration/datastreams__crud__spec.rb.i +0 -0
  86. data/.hg/store/data/spec/integration/fedora__object__spec.rb.i +0 -0
  87. data/.hg/store/data/spec/integration/full__featured__model__spec.rb.i +0 -0
  88. data/.hg/store/data/spec/integration/model__spec.rb.i +0 -0
  89. data/.hg/store/data/spec/integration/rels__ext__datastream__spec.rb.i +0 -0
  90. data/.hg/store/data/spec/integration/repository__spec.rb.i +0 -0
  91. data/.hg/store/data/spec/integration/rf__fedora__object__spec.rb.i +0 -0
  92. data/.hg/store/data/spec/integration/semantic__node__spec.rb.i +0 -0
  93. data/.hg/store/data/spec/integration/solr__service__spec.rb.i +0 -0
  94. data/.hg/store/data/spec/samples/models/audio__record.rb.i +0 -0
  95. data/.hg/store/data/spec/samples/models/image.rb.i +0 -0
  96. data/.hg/store/data/spec/samples/models/oral__history.rb.i +0 -0
  97. data/.hg/store/data/spec/samples/models/seminar.rb.i +0 -0
  98. data/.hg/store/data/spec/samples/models/seminar__audio__file.rb.i +0 -0
  99. data/.hg/store/data/spec/samples/oh__qdc.xml.i +0 -0
  100. data/.hg/store/data/spec/samples/oral__history.rb.i +0 -0
  101. data/.hg/store/data/spec/samples/oral__history__sample.xml.i +0 -0
  102. data/.hg/store/data/spec/samples/oral__history__sample__model.rb.i +0 -0
  103. data/.hg/store/data/spec/samples/oral__history__xml.xml.i +0 -0
  104. data/.hg/store/data/spec/spec.opts.i +0 -0
  105. data/.hg/store/data/spec/spec__helper.rb.i +0 -0
  106. data/.hg/store/data/spec/unit/active__fedora/base__cma__spec.rb.i +0 -0
  107. data/.hg/store/data/spec/unit/active__fedora/base__extra__spec.rb.i +0 -0
  108. data/.hg/store/data/spec/unit/active__fedora/base__spec.rb.i +0 -0
  109. data/.hg/store/data/spec/unit/active__fedora/content__model__spec.rb.i +0 -0
  110. data/.hg/store/data/spec/unit/active__fedora/datastream__spec.rb.i +0 -0
  111. data/.hg/store/data/spec/unit/active__fedora/inheritance__spec.rb.i +0 -0
  112. data/.hg/store/data/spec/unit/active__fedora/metadata__datastream__spec.rb.i +0 -0
  113. data/.hg/store/data/spec/unit/active__fedora/model__spec.rb.i +0 -0
  114. data/.hg/store/data/spec/unit/active__fedora/property__spec.rb.i +0 -0
  115. data/.hg/store/data/spec/unit/active__fedora/qualified__dublin__core__datastream__spec.rb.i +0 -0
  116. data/.hg/store/data/spec/unit/active__fedora/relationship__spec.rb.i +0 -0
  117. data/.hg/store/data/spec/unit/active__fedora/rels__ext__datastream__spec.rb.i +0 -0
  118. data/.hg/store/data/spec/unit/active__fedora/semantic__node__spec.rb.i +0 -0
  119. data/.hg/store/data/spec/unit/active__fedora/solr__service__spec.rb.i +0 -0
  120. data/.hg/store/data/spec/unit/active__fedora__spec.rb.i +0 -0
  121. data/.hg/store/data/spec/unit/base__cma__spec.rb.i +0 -0
  122. data/.hg/store/data/spec/unit/base__datastream__management__spec.rb.i +0 -0
  123. data/.hg/store/data/spec/unit/base__extra__spec.rb.i +0 -0
  124. data/.hg/store/data/spec/unit/base__file__management__spec.rb.i +0 -0
  125. data/.hg/store/data/spec/unit/base__loader__spec.rb.i +0 -0
  126. data/.hg/store/data/spec/unit/base__spec.rb.i +0 -0
  127. data/.hg/store/data/spec/unit/connection__spec.rb.i +0 -0
  128. data/.hg/store/data/spec/unit/content__model__spec.rb.i +0 -0
  129. data/.hg/store/data/spec/unit/datastream__concurrency__spec.rb.i +0 -0
  130. data/.hg/store/data/spec/unit/datastream__spec.rb.i +0 -0
  131. data/.hg/store/data/spec/unit/fedora__object__spec.rb.i +0 -0
  132. data/.hg/store/data/spec/unit/inheritance__spec.rb.i +0 -0
  133. data/.hg/store/data/spec/unit/metadata__datastream__spec.rb.i +0 -0
  134. data/.hg/store/data/spec/unit/model__spec.rb.i +0 -0
  135. data/.hg/store/data/spec/unit/property__spec.rb.i +0 -0
  136. data/.hg/store/data/spec/unit/qualified__dublin__core__datastream__spec.rb.i +0 -0
  137. data/.hg/store/data/spec/unit/relationship__spec.rb.i +0 -0
  138. data/.hg/store/data/spec/unit/rels__ext__datastream__spec.rb.i +0 -0
  139. data/.hg/store/data/spec/unit/repository__spec.rb.i +0 -0
  140. data/.hg/store/data/spec/unit/rf__datastream__spec.rb.i +0 -0
  141. data/.hg/store/data/spec/unit/semantic__node__spec.rb.i +0 -0
  142. data/.hg/store/data/spec/unit/solr__config__options__spec.rb.i +0 -0
  143. data/.hg/store/data/spec/unit/solr__mapper__spec.rb.i +0 -0
  144. data/.hg/store/data/spec/unit/solr__service__spec.rb.i +0 -0
  145. data/.hg/store/data/tasks/rspec.rake.i +0 -0
  146. data/.hg/store/undo +0 -0
  147. data/.hg/undo.branch +1 -0
  148. data/.hg/undo.dirstate +0 -0
  149. data/.hgignore +7 -0
  150. data/.hgtags +14 -0
  151. data/COPYING.txt +674 -0
  152. data/COYING.LESSER.txt +165 -0
  153. data/History.txt +34 -0
  154. data/LICENSE +20 -0
  155. data/License.txt +58 -0
  156. data/Manifest.txt +1 -1
  157. data/README.rdoc +13 -54
  158. data/README.txt +59 -0
  159. data/Rakefile +35 -0
  160. data/VERSION +1 -0
  161. data/active-fedora.gemspec +359 -0
  162. data/config/fedora.yml +16 -0
  163. data/config/solr_mappings.yml +14 -0
  164. data/config/solr_mappings_af_0.1.yml +16 -0
  165. data/config/solr_mappings_bl_2.4.yml +14 -0
  166. data/lib/active_fedora.rb +66 -6
  167. data/lib/active_fedora/base.rb +59 -23
  168. data/lib/active_fedora/datastream.rb +1 -1
  169. data/lib/active_fedora/metadata_datastream.rb +14 -7
  170. data/lib/active_fedora/model.rb +4 -4
  171. data/lib/active_fedora/rels_ext_datastream.rb +1 -1
  172. data/lib/active_fedora/semantic_node.rb +4 -3
  173. data/lib/active_fedora/solr_mapper.rb +17 -0
  174. data/lib/active_fedora/solr_service.rb +44 -2
  175. data/lib/fedora/base.rb +38 -0
  176. data/lib/fedora/connection.rb +210 -0
  177. data/lib/fedora/datastream.rb +56 -0
  178. data/lib/fedora/fedora_object.rb +161 -0
  179. data/lib/fedora/formats.rb +30 -0
  180. data/lib/fedora/generic_search.rb +71 -0
  181. data/lib/fedora/repository.rb +287 -0
  182. data/lib/ruby-fedora.rb +20 -0
  183. data/lib/util/class_level_inheritable_attributes.rb +23 -0
  184. data/script/console +15 -0
  185. data/script/destroy +14 -0
  186. data/script/generate +14 -0
  187. data/solr/config/schema-1.5.xml +468 -0
  188. data/solr/config/schema.xml +174 -212
  189. data/solr/config/solrconfig-1.5.xml +1069 -0
  190. data/spec/active_fedora_spec.rb +7 -0
  191. data/spec/fixtures/changeme155.xml +255 -0
  192. data/spec/fixtures/dino.jpg +0 -0
  193. data/spec/fixtures/minivan.jpg +0 -0
  194. data/spec/fixtures/test_12.foxml.xml +121 -0
  195. data/spec/integration/base_file_management_spec.rb +20 -0
  196. data/spec/integration/base_spec.rb +196 -0
  197. data/spec/integration/bug_spec.rb +57 -0
  198. data/spec/integration/datastream_spec.rb +60 -0
  199. data/spec/integration/datastreams_crud_spec.rb +208 -0
  200. data/spec/integration/fedora_object_spec.rb +77 -0
  201. data/spec/integration/full_featured_model_spec.rb +207 -0
  202. data/spec/integration/model_spec.rb +54 -0
  203. data/spec/integration/rels_ext_datastream_spec.rb +67 -0
  204. data/spec/integration/repository_spec.rb +297 -0
  205. data/spec/integration/rf_fedora_object_spec.rb +95 -0
  206. data/spec/integration/semantic_node_spec.rb +95 -0
  207. data/spec/integration/solr_service_spec.rb +33 -0
  208. data/spec/samples/models/audio_record.rb +29 -0
  209. data/spec/samples/models/image.rb +5 -0
  210. data/spec/samples/models/oral_history.rb +50 -0
  211. data/spec/samples/models/seminar.rb +29 -0
  212. data/spec/samples/models/seminar_audio_file.rb +34 -0
  213. data/spec/samples/oh_qdc.xml +32 -0
  214. data/spec/samples/oral_history_sample.xml +38 -0
  215. data/spec/samples/oral_history_sample_model.rb +39 -0
  216. data/spec/samples/oral_history_xml.xml +35 -0
  217. data/spec/spec.opts +5 -0
  218. data/spec/spec_helper.rb +41 -0
  219. data/spec/unit/active_fedora_spec.rb +15 -0
  220. data/spec/unit/base_cma_spec.rb +25 -0
  221. data/spec/unit/base_datastream_management_spec.rb +119 -0
  222. data/spec/unit/base_extra_spec.rb +108 -0
  223. data/spec/unit/base_file_management_spec.rb +90 -0
  224. data/spec/unit/base_loader_spec.rb +43 -0
  225. data/spec/unit/base_spec.rb +584 -0
  226. data/spec/unit/connection_spec.rb +25 -0
  227. data/spec/unit/content_model_spec.rb +51 -0
  228. data/spec/unit/datastream_concurrency_spec.rb +59 -0
  229. data/spec/unit/datastream_spec.rb +85 -0
  230. data/spec/unit/fedora_object_spec.rb +66 -0
  231. data/spec/unit/inheritance_spec.rb +46 -0
  232. data/spec/unit/metadata_datastream_spec.rb +290 -0
  233. data/spec/unit/model_spec.rb +186 -0
  234. data/spec/unit/property_spec.rb +50 -0
  235. data/spec/unit/qualified_dublin_core_datastream_spec.rb +177 -0
  236. data/spec/unit/relationship_spec.rb +77 -0
  237. data/spec/unit/rels_ext_datastream_spec.rb +99 -0
  238. data/spec/unit/repository_spec.rb +136 -0
  239. data/spec/unit/rf_datastream_spec.rb +49 -0
  240. data/spec/unit/semantic_node_spec.rb +354 -0
  241. data/spec/unit/solr_config_options_spec.rb +98 -0
  242. data/spec/unit/solr_mapper_spec.rb +31 -0
  243. data/spec/unit/solr_service_spec.rb +83 -0
  244. data/tasks/hoe.rake +0 -0
  245. data/tasks/rspec.rake +29 -0
  246. metadata +373 -55
@@ -0,0 +1,54 @@
1
+ require File.join( File.dirname(__FILE__), "..", "spec_helper" )
2
+
3
+ require 'active_fedora'
4
+ require 'active_fedora/model'
5
+ require "rexml/document"
6
+ require 'ftools'
7
+ require 'mocha'
8
+
9
+ include ActiveFedora::Model
10
+ include Mocha::Standalone
11
+
12
+ describe ActiveFedora::Model do
13
+
14
+
15
+ before(:each) do
16
+ module SpecModel
17
+
18
+ class Basic < ActiveFedora::Base
19
+ #include ActiveFedora::Model
20
+ end
21
+
22
+ end
23
+ @test_instance = SpecModel::Basic.new
24
+ @test_instance.save
25
+
26
+ end
27
+
28
+ after(:each) do
29
+ @test_instance.delete
30
+ Object.send(:remove_const, :SpecModel)
31
+ end
32
+
33
+ describe '#find' do
34
+ it "should return an array of instances of the calling Class" do
35
+ pending
36
+ result = SpecModel::Basic.find(:all)
37
+ result.should be_instance_of(Array)
38
+ result.each do |obj|
39
+ obj.class.should == SpecModel::Basic
40
+ end
41
+ end
42
+ end
43
+
44
+ describe '#find_model' do
45
+
46
+ it "should return an object of the given Model whose inner object is nil" do
47
+ #result = SpecModel::Basic.find_model(@test_instance.pid, SpecModel::Basic)
48
+ result = Fedora::Repository.instance.find_model(@test_instance.pid, SpecModel::Basic)
49
+ result.class.should == SpecModel::Basic
50
+ result.inner_object.new_object?.should be_false
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,67 @@
1
+ require File.join( File.dirname(__FILE__), "../spec_helper" )
2
+
3
+ require 'active_fedora'
4
+ require "rexml/document"
5
+ require 'ftools'
6
+
7
+ describe ActiveFedora::RelsExtDatastream do
8
+
9
+ before(:all) do
10
+ @sample_relationships_hash = Hash.new(:is_member_of => ["info:fedora/demo:5", "info:fedora/demo:10"])
11
+ @sample_xml_string = <<-EOS
12
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
13
+ <rdf:Description rdf:about="info:fedora/changeme:475">
14
+ <isMemberOf xmlns="info:fedora/fedora-system:def/relations-external#" rdf:resource="info:fedora/demo:5"></isMemberOf>
15
+ <isMemberOf xmlns="info:fedora/fedora-system:def/relations-external#" rdf:resource="info:fedora/demo:10"></isMemberOf>
16
+ </rdf:Description>
17
+ </rdf:RDF>
18
+ EOS
19
+
20
+ @sample_xml = REXML::Document.new(@sample_xml_string)
21
+ end
22
+
23
+ before(:each) do
24
+ @test_datastream = ActiveFedora::RelsExtDatastream.new
25
+ @test_object = ActiveFedora::Base.new
26
+ @test_object.save
27
+ @test_relationships = [ActiveFedora::Relationship.new(:subject => :self, :predicate => :is_member_of, :object => "info:fedora/demo:5"),
28
+ ActiveFedora::Relationship.new(:subject => :self, :predicate => :is_member_of, :object => "info:fedora/demo:10")]
29
+ end
30
+
31
+ after(:each) do
32
+ @test_object.delete
33
+ end
34
+
35
+
36
+ describe '#save' do
37
+
38
+ it "should generate new rdf/xml as the datastream content if the object has been changed" do
39
+ @test_object.add_datastream(@test_datastream)
40
+ @test_relationships.each do |rel|
41
+ @test_datastream.add_relationship(rel)
42
+ end
43
+ rexml1 = REXML::Document.new(@test_datastream.to_rels_ext(@test_object.pid))
44
+ @test_datastream.dirty = true
45
+ @test_datastream.save
46
+ rexml2 = REXML::Document.new(@test_object.datastreams["RELS-EXT"].content)
47
+ rexml1.root.elements["rdf:Description"].inspect.should eql(rexml2.root.elements["rdf:Description"].inspect)
48
+ #rexml1.root.elements["rdf:Description"].to_s.should eql(rexml2.root.elements["rdf:Description"].to_s)
49
+
50
+ #rexml1.root.elements["rdf:Description"].each_element do |el|
51
+ # el.inspect.should eql(rexml2.root.elements["rdf:Description"][el.index_in_parent].inspect)
52
+ #end
53
+
54
+ end
55
+
56
+ end
57
+
58
+ it "should load relationships from fedora into parent object" do
59
+ ActiveFedora::SemanticNode::PREDICATE_MAPPINGS.each_key do |p|
60
+ @test_object.add_relationship(p, "demo:#{rand(100)}")
61
+ end
62
+ @test_object.save
63
+ # make sure that _something_ was actually added to the object's relationships hash
64
+ @test_object.relationships[:self].should have_key(:is_member_of)
65
+ ActiveFedora::Base.load_instance(@test_object.pid).relationships.should == @test_object.relationships
66
+ end
67
+ end
@@ -0,0 +1,297 @@
1
+ require File.join( File.dirname(__FILE__), "../spec_helper" )
2
+
3
+ # - Objects API - http://www.fedora-commons.org/documentation/3.0b1/userdocs/server/webservices/rest/index.html
4
+
5
+ # - Object profile
6
+ #
7
+ # curl -i http://localhost:8080/fedora/objects/demo:10
8
+ # curl -i http://localhost:8080/fedora/objects/demo:10.xml
9
+ # curl -i http://localhost:8080/fedora/objects/demo:10?resultFormat=xml
10
+ #
11
+ # - Object history
12
+ # curl -i http://localhost:8080/fedora/objects/demo:10/versions
13
+ # curl -i http://localhost:8080/fedora/objects/demo:10/versions.xml
14
+ # curl -i http://localhost:8080/fedora/objects/demo:10/versions/2007-07-25T17:08:11.915Z
15
+ # curl -i http://localhost:8080/fedora/objects/demo:10/versions/2007-07-25T17:08:11.915Z.xml
16
+ # curl -i http://localhost:8080/fedora/objects/demo:10/versions/2007-07-25T17:08:11.915Z?resultFormat=xml
17
+ #
18
+ # - Object export
19
+ # curl -i -u fedoraAdmin:fedoraAdmin http://localhost:8080/fedora/objects/demo:10/export?resultFormat=foxml1.0&context=private
20
+ #
21
+ # - Object XML
22
+ # curl -i http://localhost:8080/fedora/objects/demo:10/objectXML
23
+ # curl -i http://localhost:8080/fedora/objects/demo:10/objectXML?resultFormat=xml
24
+ #
25
+ # - Object methods
26
+ # curl -i http://localhost:8080/fedora/objects/demo:10/methods
27
+ # curl -i http://localhost:8080/fedora/objects/demo:10/methods?resultFormat=xml
28
+ # curl -i http://localhost:8080/fedora/objects/demo:10/methods/2007-07-25T17:08:11.915Z
29
+ # curl -i http://localhost:8080/fedora/objects/demo:10/methods/2007-07-25T17:08:11.915Z.xml
30
+ #
31
+ # invalid: curl -i http://localhost:8080/fedora/objects/demo:10/methods.xml
32
+ #
33
+ # - Create
34
+ # curl -i -H "Content-type: text/xml" -XPOST "http://localhost:8080/fedora/objects/new?label=Test&namespace=test" --data "" -u fedoraAdmin:fedoraAdmin
35
+ # curl -i -H "Content-type: text/xml" -XPOST "http://localhost:9090/fedora/objects/new" --data "" -u fedoraAdmin:fedoraAdmin
36
+ #
37
+ # curl -i -H "Content-type: text/xml" -XPOST "http://localhost:8080/fedora/objects/test:02?label=Test" --data "" -u fedoraAdmin:fedoraAdmin
38
+ # curl -i -H "Content-type: text/xml" -XPOST "http://localhost:8080/fedora/objects/test:01?label=Test&altIDs=3333" --data-binary @foxml.xml -u fedoraAdmin:fedoraAdmin
39
+ #
40
+ # - Delete
41
+ # curl -i -u fedoraAdmin:fedoraAdmin -XDELETE http://localhost:8080/fedora/objects/demo:10
42
+ #
43
+ # Objects API
44
+ # curl -i http://localhost:8080/fedora/objects
45
+ # curl -i http://localhost:8080/fedora/objects?resultFormat=xml
46
+ # curl -i http://localhost:8080/fedora/objects/nextPID -u fedoraAdmin:fedoraAdmin
47
+ # curl -i http://localhost:8080/fedora/objects/nextPID.xml -u fedoraAdmin:fedoraAdmin
48
+
49
+ describe Fedora::Repository, "constructor" do
50
+ it "should accept URL as string" do
51
+ fedora_url = "http://fedoraAdmin:fedoraAdmin@127.0.0.1:8080/fedora"
52
+ repository = Fedora::Repository.register(fedora_url)
53
+
54
+ repository.fedora_url.should == URI.parse(fedora_url)
55
+ end
56
+
57
+ it "should accept URL as URI object" do
58
+ fedora_url = URI.parse("http://fedoraAdmin:fedoraAdmin@127.0.0.1:8080/fedora")
59
+ repository = Fedora::Repository.register(fedora_url)
60
+
61
+ repository.fedora_url.should == fedora_url
62
+ end
63
+
64
+ it "should reject invalid url format" do
65
+ lambda { Fedora::Repository.register("http://:8080/") }.should raise_error
66
+ end
67
+ end
68
+
69
+ describe Fedora::Repository, "CRUD" do
70
+ before(:all) do
71
+ Fedora::Repository.register(ActiveFedora.fedora_config[:url])
72
+ end
73
+
74
+ before(:each) do
75
+ @test_object = Fedora::FedoraObject.new(:label => 'test',
76
+ :state => 'A',
77
+ :ownerID => 'fedoraAdmin')
78
+ end
79
+
80
+ after(:each) do
81
+ if !@test_object.new_object?
82
+ begin
83
+ Fedora::Repository.instance.delete(@test_object)
84
+ end
85
+ end
86
+ end
87
+
88
+ it "should create new fedora object with auto pid" do
89
+ Fedora::Repository.instance.save(@test_object).should be_true
90
+
91
+ @test_object.should have(0).errors
92
+ @test_object.pid.should_not be_nil
93
+ @test_object.label.should == 'test'
94
+ @test_object.state.should == 'A'
95
+ @test_object.owner_id.should == 'fedoraAdmin'
96
+ end
97
+
98
+ it "should create new fedora object with assigned pid" do
99
+ @test_object.pid = "demo:1000"
100
+ Fedora::Repository.instance.save(@test_object).should be_true
101
+ @test_object.should have(0).errors
102
+ @test_object.pid.should == "demo:1000"
103
+ end
104
+
105
+ it "should update object state" do
106
+ Fedora::Repository.instance.save(@test_object).should be_true
107
+
108
+ @test_object.state = 'I'
109
+ Fedora::Repository.instance.update(@test_object).should be_true
110
+ @test_object.state.should == 'I'
111
+ end
112
+
113
+ it "should delete object by ref" do
114
+ Fedora::Repository.instance.create(@test_object).should be_true
115
+ Fedora::Repository.instance.delete(@test_object).should be_true
116
+ # prevent after statement from attempting to delete again
117
+ @test_object.new_object = true
118
+ end
119
+
120
+ it "should delete object by pid" do
121
+ Fedora::Repository.instance.create(@test_object).should be_true
122
+ Fedora::Repository.instance.delete(@test_object.uri).should be_true
123
+ # prevent after statement from attempting to delete again
124
+ @test_object.new_object = true
125
+ end
126
+
127
+ =begin
128
+ it "should fetch object profile Image of Coliseum in Rome" do
129
+ xml = Fedora::Repository.instance.fetch_content("demo:5")
130
+ validate_xml(xml, 'objectProfile')
131
+ xml.should =~ %r{Data Object (Coliseum) for Local Simple Image Demo}
132
+ end
133
+ =end
134
+ end
135
+
136
+ describe Fedora::Repository, "find_objects" do
137
+ before(:all) do
138
+ Fedora::Repository.register(ActiveFedora.fedora_config[:url])
139
+ end
140
+
141
+ def fields_to_s(fields)
142
+ fields.inject("") { |s, f| s += '&' + f.to_s + '=true' }
143
+ end
144
+
145
+ def when_find_objects(*args)
146
+ fake_connection = mock("Connection")
147
+ Fedora::Repository.instance.expects(:connection).returns(fake_connection)
148
+ yield fake_connection
149
+
150
+ Fedora::Repository.instance.find_objects(*args)
151
+ end
152
+
153
+ it "should include all fields by default" do
154
+ when_find_objects('label~Image*') { |conn|
155
+ conn.expects(:get).with('/fedora/objects?query=label%7EImage%2A&resultFormat=xml' + fields_to_s(Fedora::ALL_FIELDS))
156
+ }
157
+ end
158
+
159
+ it "should include all fields when :include => :all " do
160
+ when_find_objects('label~Image*', :include => :all) { |conn|
161
+ conn.expects(:get).with('/fedora/objects?query=label%7EImage%2A&resultFormat=xml' + fields_to_s(Fedora::ALL_FIELDS))
162
+ }
163
+ end
164
+
165
+ it "should fetch results with limit" do
166
+ when_find_objects('label~Image*', :limit => 10) { |conn|
167
+ conn.expects(:get).with('/fedora/objects?maxResults=10&query=label%7EImage%2A&resultFormat=xml' + fields_to_s(Fedora::ALL_FIELDS))
168
+ }
169
+ end
170
+
171
+ it "should fetch results with some fields but not :pid" do
172
+ when_find_objects('label~Image*', :select => [:label, :mDate]) { |conn|
173
+ conn.expects(:get).with('/fedora/objects?query=label%7EImage%2A&resultFormat=xml' + fields_to_s([:pid, :label, :mDate]))
174
+ }
175
+ end
176
+
177
+ it "should fetch results with some fields with :pid" do
178
+ when_find_objects('label~Image*', :select => [:pid, :label, :mDate]) { |conn|
179
+ conn.expects(:get).with('/fedora/objects?query=label%7EImage%2A&resultFormat=xml' + fields_to_s([:pid, :label, :mDate]))
180
+ }
181
+ end
182
+
183
+ def sample_response_xml(n = 1)
184
+ header = %Q(<result xmlns="http://www.fedora.info/definitions/1/0/types/">
185
+ <listSession>
186
+ <token>aToken</token>
187
+ <cursor>0</cursor>
188
+ </listSession>
189
+ <resultList>)
190
+
191
+ body = %Q(<objectFields>
192
+ <pid>demo:10</pid>
193
+ <label>Column Detail, Pavillion III, IVA Image Collection - University of Virginia</label>
194
+ </objectFields>) * n
195
+
196
+ header + body + %Q(</resultList></result>)
197
+ end
198
+
199
+ it "should convert xml response with 0 objectFields into array of FedoraObject" do
200
+ objects = when_find_objects('label~Image*', :select => [:pid, :label, :mDate]) { |conn|
201
+ conn.expects(:get).with('/fedora/objects?query=label%7EImage%2A&resultFormat=xml' + fields_to_s([:pid, :label, :mDate])).
202
+ returns(Fedora::XmlFormat.decode(sample_response_xml))
203
+ }
204
+
205
+ objects.session_token.should == 'aToken'
206
+ objects.should_not be_empty
207
+ end
208
+
209
+ it "should return FedoraObjects with new_object set to false" do
210
+ objects = when_find_objects('label~Image*', :select => [:pid, :label, :mDate]) { |conn|
211
+ conn.expects(:get).with('/fedora/objects?query=label%7EImage%2A&resultFormat=xml' + fields_to_s([:pid, :label, :mDate])).
212
+ returns(Fedora::XmlFormat.decode(sample_response_xml))
213
+ }
214
+ objects.each do |obj|
215
+ obj.should_not be_new_object
216
+ end
217
+
218
+ end
219
+
220
+ it "should convert xml response with single objectFields into array of FedoraObject" do
221
+ objects = when_find_objects('label~Image*', :select => [:pid, :label, :mDate]) { |conn|
222
+ conn.expects(:get).with('/fedora/objects?query=label%7EImage%2A&resultFormat=xml' + fields_to_s([:pid, :label, :mDate])).
223
+ returns(Fedora::XmlFormat.decode(sample_response_xml(1)))
224
+ }
225
+
226
+ objects.session_token.should == 'aToken'
227
+ objects.should have(1).record
228
+ objects.first.pid.should == 'demo:10'
229
+ objects.first.should be_kind_of(Fedora::FedoraObject)
230
+ end
231
+
232
+ it "should convert xml response 2 objectFields into array of FedoraObject" do
233
+ objects = when_find_objects('label~Image*', :select => [:pid, :label, :mDate]) { |conn|
234
+ conn.expects(:get).with('/fedora/objects?query=label%7EImage%2A&resultFormat=xml' + fields_to_s([:pid, :label, :mDate])).
235
+ returns(Fedora::XmlFormat.decode(sample_response_xml(2)))
236
+ }
237
+
238
+ objects.session_token.should == 'aToken'
239
+ objects.should have(2).records
240
+ end
241
+ end
242
+
243
+ describe Fedora::Repository, "ingest" do
244
+
245
+ after(:each) do
246
+ begin
247
+ Fedora::Repository.instance.delete("test:12")
248
+ end
249
+ end
250
+
251
+ it "should successfully ingest foxml" do
252
+ foxml_file = fixture("test_12.foxml.xml")
253
+ foxml = fixture("test_12.foxml.xml").read
254
+ response = Fedora::Repository.instance.ingest(foxml_file)
255
+ response.code.should == "201"
256
+ response.body.should == "test:12"
257
+ end
258
+
259
+ end
260
+
261
+ describe Fedora::Repository do
262
+ before(:all) do
263
+ require 'rexml/document'
264
+ end
265
+
266
+ it "should fetch history" do
267
+ xml = Fedora::Repository.instance.fetch_custom("demo:20", :versions)
268
+ validate_xml(xml, 'fedoraObjectHistory')
269
+ xml.should =~ /pid="demo:20"/
270
+ end
271
+
272
+ it "should fetch profile" do
273
+ xml = Fedora::Repository.instance.fetch_custom("demo:20", :profile)
274
+ validate_xml(xml, 'objectProfile')
275
+ xml.should =~ /pid="demo:20"/
276
+ end
277
+
278
+ it "should fetch export" do
279
+ xml = Fedora::Repository.instance.fetch_custom("demo:20", :export)
280
+ validate_xml(xml, 'digitalObject')
281
+ xml.should =~ /demo:20/
282
+ xml.should =~ /datastream/
283
+ end
284
+
285
+ it "should fetch objectXML" do
286
+ xml = Fedora::Repository.instance.fetch_custom("demo:20", :objectXML)
287
+ xml.should =~ /digitalObject/
288
+ xml.should =~ /pid="demo:20"/i
289
+ end
290
+
291
+ it "should list object methods" do
292
+ xml = Fedora::Repository.instance.fetch_custom("demo:20", :methods)
293
+ xml.should =~ /objectMethods/
294
+ xml.should =~ /pid="demo:20"/i
295
+ end
296
+
297
+ end
@@ -0,0 +1,95 @@
1
+ require File.join( File.dirname(__FILE__), "../spec_helper" )
2
+
3
+ require "rexml/document"
4
+
5
+ describe Fedora::FedoraObject do
6
+
7
+ before(:each) do
8
+ Fedora::Repository.register(ActiveFedora.fedora_config[:url])
9
+ @test_object = Fedora::FedoraObject.new(:pid=>"demo:1000")
10
+ Fedora::Repository.instance.save(@test_object)
11
+ end
12
+
13
+ after(:each) do
14
+ Fedora::Repository.instance.delete(@test_object)
15
+ end
16
+
17
+ describe '#object_xml' do
18
+ it "should return XML with a root of digitalObject with namespace info:fedora/fedora-system:def/foxml#" do
19
+ object_rexml = REXML::Document.new(@test_object.object_xml)
20
+ object_rexml.root.name.should == "digitalObject"
21
+ object_rexml.root.namespace.should == "info:fedora/fedora-system:def/foxml#"
22
+ object_rexml.root.elements["foxml:objectProperties/foxml:property[@NAME='info:fedora/fedora-system:def/model#state']"].attributes["VALUE"].should_not be_nil
23
+ end
24
+ end
25
+
26
+ describe '#profile' do
27
+ it "should return an array with misc Fedora Object attributes" do
28
+ profile = @test_object.profile
29
+ profile.class.should == Hash
30
+ profile.empty?.should_not == true
31
+ #profile.class.should_not be_empty
32
+ profile.should have_key(:owner_id)
33
+ profile[:owner_id].should == "fedoraAdmin"
34
+ #profile.should have_key(:content_model)
35
+ profile.should have_key(:label)
36
+ profile.should have_key(:create_date)
37
+ profile.should have_key(:modified_date)
38
+ profile.should have_key(:methods_list_url)
39
+ profile.should have_key(:datastreams_list_url)
40
+ profile.should have_key(:state)
41
+ profile[:state].should == "A"
42
+
43
+ end
44
+ end
45
+
46
+ it "should allow access to fedora object info" do
47
+ @test_object.label = "test"
48
+ Fedora::Repository.instance.save(@test_object)
49
+ obj = Fedora::Repository.instance.find_objects("pid=#{@test_object.pid}").first
50
+ obj.pid.should == "demo:1000"
51
+ obj.label.should == 'test'
52
+ obj.state.should == 'A'
53
+ obj.owner_id.should == 'fedoraAdmin'
54
+ end
55
+
56
+ describe "properties_from_fedora" do
57
+ it" should return the object properties from fedora" do
58
+ @test_object.label = "test"
59
+ Fedora::Repository.instance.save(@test_object)
60
+ properties = @test_object.properties_from_fedora
61
+ properties[:pid].should == "demo:1000"
62
+ properties[:state].should == 'A'
63
+ properties[:create_date].should == @test_object.profile[:create_date]
64
+ properties[:modified_date].should == @test_object.profile[:modified_date]
65
+ properties[:label].should == 'test'
66
+ properties[:owner_id].should == 'fedoraAdmin'
67
+ end
68
+ it "should not set :label if it is not there in the object_xml" do
69
+ object_rexml = REXML::Document.new(@test_object.object_xml)
70
+ # The label node will be missing from the FOXML because label was never set.
71
+ object_rexml.root.elements["//foxml:property[@NAME='info:fedora/fedora-system:def/model#label']"].should == nil
72
+ properties = @test_object.properties_from_fedora
73
+ properties[:label].should == nil
74
+ end
75
+ end
76
+
77
+ describe "load_attr_from_fedora" do
78
+ it "should push all of the properties from fedora into the objects attributes" do
79
+ @test_object.label = "test"
80
+ Fedora::Repository.instance.save(@test_object)
81
+ @test_object.attributes.should == {:pid=>"demo:1000", :label=>"test"}
82
+ @test_object.load_attributes_from_fedora
83
+ #{:create_date=>"2009-07-16T17:42:33.548Z", :label=>"test", :modified_date=>"2009-07-16T17:42:33.548Z", :state=>"Active", :pid=>"demo:1000", :owner_id=>"fedoraAdmin"}
84
+ @test_object.attributes[:pid].should == "demo:1000"
85
+ @test_object.attributes[:state].should == 'A'
86
+ #@test_object.attributes[:state].should == 'Active'
87
+ @test_object.attributes[:create_date].should == @test_object.profile[:create_date]
88
+ @test_object.attributes[:modified_date].should == @test_object.profile[:modified_date]
89
+ @test_object.attributes[:label].should == 'test'
90
+ @test_object.attributes[:owner_id].should == 'fedoraAdmin'
91
+ end
92
+ end
93
+
94
+
95
+ end