ro-bundle 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  #------------------------------------------------------------------------------
2
- # Copyright (c) 2014 The University of Manchester, UK.
2
+ # Copyright (c) 2014, 2015 The University of Manchester, UK.
3
3
  #
4
4
  # BSD Licenced. See LICENCE.rdoc for details.
5
5
  #
@@ -13,85 +13,90 @@ require "ro-bundle"
13
13
  class TestAggregate < Test::Unit::TestCase
14
14
 
15
15
  def test_simple_file
16
- assert_nothing_raised(ROBundle::InvalidAggregateError) do
17
- file = "/good.txt"
18
- type = "text/plain"
19
- agg = ROBundle::Aggregate.new(file, type)
20
-
21
- assert_nil agg.uri
22
- assert_equal file, agg.file
23
- assert_equal type, agg.mediatype
24
- end
16
+ file = "/good.txt"
17
+ type = "text/plain"
18
+ agg = ROBundle::Aggregate.new(file, type)
19
+
20
+ assert_equal file, agg.uri
21
+ assert_equal "good.txt", agg.file_entry
22
+ assert_equal type, agg.mediatype
25
23
  end
26
24
 
27
25
  def test_simple_uri
28
- assert_nothing_raised(ROBundle::InvalidAggregateError) do
29
- uri = "http://example.com/good.txt"
30
- agg = ROBundle::Aggregate.new(uri)
31
-
32
- assert_nil agg.file
33
- assert_nil agg.mediatype
34
- assert_equal uri, agg.uri
35
- end
26
+ uri = "http://example.com/good.txt"
27
+ agg = ROBundle::Aggregate.new(uri)
28
+
29
+ assert_nil agg.mediatype
30
+ assert_nil agg.file_entry
31
+ assert_equal uri, agg.uri
36
32
  end
37
33
 
38
34
  def test_simple_uri_object
39
- assert_nothing_raised(ROBundle::InvalidAggregateError) do
40
- uri = URI.parse("http://example.com/good.txt")
41
- agg = ROBundle::Aggregate.new(uri)
42
-
43
- assert_nil agg.file
44
- assert_nil agg.mediatype
45
- assert_equal uri.to_s, agg.uri
46
- end
35
+ uri = URI.parse("http://example.com/good.txt")
36
+ agg = ROBundle::Aggregate.new(uri)
37
+
38
+ assert_nil agg.mediatype
39
+ assert_nil agg.file_entry
40
+ assert_equal uri.to_s, agg.uri
47
41
  end
48
42
 
49
- def test_bad_aggregates
50
- assert_raise(ROBundle::InvalidAggregateError) do
51
- ROBundle::Aggregate.new([])
52
- end
43
+ def test_complex_file
44
+ file = "/good.txt"
45
+ type = "text/plain"
46
+
47
+ json = {
48
+ :uri => file,
49
+ :mediatype => type,
50
+ :createdOn => "2013-02-12T19:37:32.939Z",
51
+ :createdBy => { "name" => "Robert Haines" },
52
+ :authoredOn => "2013-02-12T19:37:32.939Z",
53
+ :authoredBy => { "name" => "Robert Haines" }
54
+ }
55
+
56
+ agg = ROBundle::Aggregate.new(json)
57
+
58
+ assert_equal file, agg.uri
59
+ assert_equal type, agg.mediatype
60
+ assert agg.created_on.instance_of?(Time)
61
+ assert agg.created_by.instance_of?(ROBundle::Agent)
62
+ assert agg.authored_on.instance_of?(Time)
63
+ assert agg.authored_by.instance_of?(Array)
64
+ assert agg.authored_by[0].instance_of?(ROBundle::Agent)
65
+ end
53
66
 
54
- assert_raise(ROBundle::InvalidAggregateError) do
55
- ROBundle::Aggregate.new({})
56
- end
67
+ def test_filepath_encoding_handling
68
+ file = "file with spaces.txt"
69
+ agg = ROBundle::Aggregate.new(file)
70
+ assert_equal "/file%20with%20spaces.txt",agg.uri
71
+ assert_equal file,agg.file_entry
57
72
  end
58
73
 
59
- def test_complex_file
60
- assert_nothing_raised(ROBundle::InvalidAggregateError) do
61
- file = "/good.txt"
62
- type = "text/plain"
63
-
64
- json = {
65
- :file => file,
66
- :mediatype => type,
67
- :createdOn => "2013-02-12T19:37:32.939Z",
68
- :createdBy => { "name" => "Robert Haines" }
69
- }
70
-
71
- agg = ROBundle::Aggregate.new(json)
72
-
73
- assert_nil agg.uri
74
- assert_equal file, agg.file
75
- assert_equal type, agg.mediatype
76
- assert agg.created_on.instance_of?(Time)
77
- assert agg.created_by.instance_of?(ROBundle::Agent)
78
- end
74
+ def test_encoded_uri
75
+ uri = "http://example.com/encoded%20uri"
76
+
77
+ json = {
78
+ :uri => uri
79
+ }
80
+ agg = ROBundle::Aggregate.new(json)
81
+
82
+ assert_equal uri, agg.uri
83
+
84
+ agg = ROBundle::Aggregate.new(uri)
85
+ assert_equal uri, agg.uri
79
86
  end
80
87
 
81
88
  def test_complex_uri
82
- assert_nothing_raised(ROBundle::InvalidAggregateError) do
83
- uri = "http://example.com/good.txt"
89
+ uri = "http://example.com/good.txt"
84
90
 
85
- json = {
86
- :uri => uri
87
- }
91
+ json = {
92
+ :uri => uri
93
+ }
88
94
 
89
- agg = ROBundle::Aggregate.new(json)
95
+ agg = ROBundle::Aggregate.new(json)
90
96
 
91
- assert_nil agg.file
92
- assert_nil agg.mediatype
93
- assert_equal uri, agg.uri
94
- end
97
+ assert_nil agg.file_entry
98
+ assert_nil agg.mediatype
99
+ assert_equal uri, agg.uri
95
100
  end
96
101
 
97
102
  def test_json_output_file
@@ -99,7 +104,7 @@ class TestAggregate < Test::Unit::TestCase
99
104
  type = "text/plain"
100
105
  time = "2013-02-12T19:37:32.939Z"
101
106
  json = {
102
- :file => file,
107
+ :uri => file,
103
108
  :mediatype => type,
104
109
  :createdOn => time,
105
110
  :createdBy => { :name => "Robert Haines" }
@@ -108,7 +113,7 @@ class TestAggregate < Test::Unit::TestCase
108
113
  agg = ROBundle::Aggregate.new(json)
109
114
  json = JSON.parse(JSON.generate(agg))
110
115
 
111
- assert_equal file, json["file"]
116
+ assert_equal file, json["uri"]
112
117
  assert_equal type, json["mediatype"]
113
118
  assert_equal time, json["createdOn"]
114
119
  end
@@ -1,5 +1,5 @@
1
1
  #------------------------------------------------------------------------------
2
- # Copyright (c) 2014 The University of Manchester, UK.
2
+ # Copyright (c) 2014, 2015 The University of Manchester, UK.
3
3
  #
4
4
  # BSD Licenced. See LICENCE.rdoc for details.
5
5
  #
@@ -21,7 +21,7 @@ class TestAnnotation < Test::Unit::TestCase
21
21
  @json = {
22
22
  :about => @target,
23
23
  :content => @content,
24
- :annotation => @id,
24
+ :uri => @id,
25
25
  :createdBy => { :name => @creator },
26
26
  :createdOn => @time
27
27
  }
@@ -32,7 +32,10 @@ class TestAnnotation < Test::Unit::TestCase
32
32
 
33
33
  assert_equal @target, an.target
34
34
  assert_nil an.content
35
- assert_not_nil an.annotation_id
35
+ assert_not_nil an.uri
36
+ assert an.annotates?("/")
37
+ assert an.annotates?("/file.txt")
38
+ refute an.edited?
36
39
  end
37
40
 
38
41
  def test_create_with_content
@@ -40,7 +43,8 @@ class TestAnnotation < Test::Unit::TestCase
40
43
 
41
44
  assert_equal @target, an.target
42
45
  assert_equal @content, an.content
43
- assert_not_nil an.annotation_id
46
+ assert_not_nil an.uri
47
+ refute an.edited?
44
48
  end
45
49
 
46
50
  def test_create_from_json
@@ -48,9 +52,20 @@ class TestAnnotation < Test::Unit::TestCase
48
52
 
49
53
  assert_equal @target, an.target
50
54
  assert_equal @content, an.content
51
- assert_equal @id, an.annotation_id
55
+ assert_equal @id, an.uri
52
56
  assert an.created_on.instance_of?(Time)
53
57
  assert an.created_by.instance_of?(ROBundle::Agent)
58
+ refute an.edited?
59
+ end
60
+
61
+ def test_cannot_change_target_directly
62
+ an = ROBundle::Annotation.new(@json)
63
+
64
+ assert_equal 2, an.target.length
65
+ an.target << "/more.html"
66
+ assert_equal 2, an.target.length
67
+ refute an.edited?
68
+ refute an.annotates?("/more.html")
54
69
  end
55
70
 
56
71
  def test_change_content
@@ -59,26 +74,70 @@ class TestAnnotation < Test::Unit::TestCase
59
74
  an.content = new_content
60
75
 
61
76
  assert_equal new_content, an.content
77
+ assert an.edited?
62
78
  end
63
79
 
64
80
  def test_generate_annotation_id
65
81
  an = ROBundle::Annotation.new(@target)
66
- id = an.annotation_id
82
+ id = an.uri
67
83
 
68
84
  assert id.instance_of?(String)
69
85
  assert id.start_with?("urn:uuid:")
70
- assert_same id, an.annotation_id
86
+ assert_same id, an.uri
87
+ refute an.edited?
88
+ end
89
+
90
+ def test_json_output_single_target
91
+ an = ROBundle::Annotation.new("/")
92
+ json = JSON.parse(JSON.generate(an))
93
+
94
+ assert_equal "/", json["about"]
71
95
  end
72
96
 
73
- def test_json_output
74
- agent = ROBundle::Annotation.new(@json)
75
- json = JSON.parse(JSON.generate(agent))
97
+ def test_json_output_multiple_targets
98
+ an = ROBundle::Annotation.new(@target)
99
+ json = JSON.parse(JSON.generate(an))
100
+
101
+ assert_equal @target, json["about"]
102
+ end
103
+
104
+ def test_full_json_output
105
+ an = ROBundle::Annotation.new(@json)
106
+ json = JSON.parse(JSON.generate(an))
76
107
 
77
108
  assert_equal @target, json["about"]
78
109
  assert_equal @content, json["content"]
79
- assert_equal @id, json["annotation"]
110
+ assert_equal @id, json["uri"]
80
111
  assert_equal @time, json["createdOn"]
81
112
  assert_equal @creator, json["createdBy"]["name"]
82
113
  end
83
114
 
115
+ def test_add_targets
116
+ target1 = "/target.pdf"
117
+ target2 = "/more.html"
118
+ an = ROBundle::Annotation.new(target1)
119
+
120
+ assert_equal target1, an.target
121
+ an.add_target(target2)
122
+ assert an.annotates?("/more.html")
123
+ assert_equal [target1, target2], an.target
124
+ an.add_target(@target)
125
+ assert an.annotates?("/")
126
+ assert an.annotates?("/file.txt")
127
+ assert_equal [target1, target2] + @target, an.target
128
+ end
129
+
130
+ def test_remove_target
131
+ an = ROBundle::Annotation.new(@json)
132
+
133
+ assert an.target.instance_of?(Array)
134
+ assert_equal 2, an.target.length
135
+ rem = an.remove_target("/")
136
+ assert an.edited?
137
+ refute an.annotates?("/")
138
+ assert_equal "/", rem
139
+ assert an.target.instance_of?(String)
140
+ assert_equal "/file.txt", an.target
141
+ end
142
+
84
143
  end
@@ -1,5 +1,5 @@
1
1
  #------------------------------------------------------------------------------
2
- # Copyright (c) 2014 The University of Manchester, UK.
2
+ # Copyright (c) 2014, 2015 The University of Manchester, UK.
3
3
  #
4
4
  # BSD Licenced. See LICENCE.rdoc for details.
5
5
  #
@@ -15,6 +15,20 @@ require "helpers/list_tests"
15
15
  class TestCreation < Test::Unit::TestCase
16
16
 
17
17
  def test_create_empty_bundle
18
+ Dir.mktmpdir do |dir|
19
+ filename = File.join(dir, "test.bundle")
20
+
21
+ bundle = ROBundle::File.create(filename)
22
+ refute bundle.commit_required?
23
+ bundle.close
24
+
25
+ assert_nothing_raised(ZipContainer::MalformedContainerError, ZipContainer::Error) do
26
+ ROBundle::File.verify!(filename)
27
+ end
28
+ end
29
+ end
30
+
31
+ def test_check_empty_bundle
18
32
  Dir.mktmpdir do |dir|
19
33
  filename = File.join(dir, "test.bundle")
20
34
 
@@ -32,16 +46,12 @@ class TestCreation < Test::Unit::TestCase
32
46
  b.id
33
47
  end
34
48
 
35
- # Manifest has been accessed so has been populated with defaults.
36
- assert b.commit_required?
37
-
38
- b.file.open(".ro/manifest.json", "w") do |m|
39
- m.puts "{ }"
40
- end
49
+ # Manifest has been accessed but not changed.
50
+ refute b.commit_required?
41
51
  end
42
52
  end
43
53
 
44
- assert_nothing_raised(ZipContainer::MalformedContainerError, ZipContainer::ZipError) do
54
+ assert_nothing_raised(ZipContainer::MalformedContainerError, ZipContainer::Error) do
45
55
  ROBundle::File.verify!(filename)
46
56
  end
47
57
  end
@@ -56,10 +66,10 @@ class TestCreation < Test::Unit::TestCase
56
66
  entry3 = "test3.json"
57
67
 
58
68
  assert_nothing_raised do
59
- ROBundle::File.create(filename) do |b|
69
+ bundle = ROBundle::File.create(filename) do |b|
60
70
  assert b.aggregates.empty?
61
71
  assert_nil b.find_entry(entry1)
62
- assert b.commit_required?
72
+ refute b.commit_required?
63
73
 
64
74
  agg = b.add(entry1, $man_ex3, :aggregate => false)
65
75
  assert b.aggregates.empty?
@@ -80,6 +90,8 @@ class TestCreation < Test::Unit::TestCase
80
90
  b.add_aggregate(new_agg)
81
91
  assert b.aggregate?(entry1)
82
92
  end
93
+
94
+ refute bundle.commit_required?
83
95
  end
84
96
 
85
97
  ROBundle::File.open(filename) do |b|
@@ -106,7 +118,7 @@ class TestCreation < Test::Unit::TestCase
106
118
  entry2 = URI.parse(entry1)
107
119
 
108
120
  assert_nothing_raised do
109
- ROBundle::File.create(filename) do |b|
121
+ bundle = ROBundle::File.create(filename) do |b|
110
122
  agg = b.add_aggregate(entry1)
111
123
  assert b.aggregate?(entry1)
112
124
  assert_nil b.find_entry(entry1)
@@ -115,7 +127,10 @@ class TestCreation < Test::Unit::TestCase
115
127
  b.add_aggregate(entry2)
116
128
  assert b.aggregate?(entry2)
117
129
  assert_nil b.find_entry(entry2)
130
+ assert b.commit_required?
118
131
  end
132
+
133
+ refute bundle.commit_required?
119
134
  end
120
135
 
121
136
  ROBundle::File.open(filename) do |b|
@@ -139,7 +154,7 @@ class TestCreation < Test::Unit::TestCase
139
154
  entry2 = ".ro/test2.json"
140
155
 
141
156
  assert_nothing_raised do
142
- ROBundle::File.create(filename) do |b|
157
+ bundle = ROBundle::File.create(filename) do |b|
143
158
  assert b.history.empty?
144
159
  assert_nil b.find_entry(entry1)
145
160
 
@@ -152,7 +167,10 @@ class TestCreation < Test::Unit::TestCase
152
167
 
153
168
  b.add_history(entry1)
154
169
  assert entry_in_history_list(entry1, b.history)
170
+ assert b.commit_required?
155
171
  end
172
+
173
+ refute bundle.commit_required?
156
174
  end
157
175
 
158
176
  ROBundle::File.open(filename) do |b|
@@ -1,5 +1,5 @@
1
1
  #------------------------------------------------------------------------------
2
- # Copyright (c) 2014 The University of Manchester, UK.
2
+ # Copyright (c) 2014, 2015 The University of Manchester, UK.
3
3
  #
4
4
  # BSD Licenced. See LICENCE.rdoc for details.
5
5
  #
@@ -50,7 +50,7 @@ class TestManifest < Test::Unit::TestCase
50
50
  end
51
51
 
52
52
  def test_ensure_copied_lists
53
- %w(authored_by history aggregates annotations).map(&:to_sym).each do |m|
53
+ %w(authored_by history).map(&:to_sym).each do |m|
54
54
  list = @manifest.send(m)
55
55
  list << "new item"
56
56
  assert_not_equal list, @manifest.send(m)
@@ -77,6 +77,22 @@ class TestManifest < Test::Unit::TestCase
77
77
  assert @manifest.edited?
78
78
  end
79
79
 
80
+ def test_change_aggregate
81
+ change = @manifest.aggregates[0]
82
+ change.add_author "Robert Haines"
83
+
84
+ assert @manifest.aggregates[0].edited?
85
+ assert @manifest.edited?
86
+ end
87
+
88
+ def test_change_annotation
89
+ change = @manifest.annotations[1]
90
+ change.content = "http://example.com/different"
91
+
92
+ assert @manifest.annotations[1].edited?
93
+ assert @manifest.edited?
94
+ end
95
+
80
96
  def test_remove_annotation_by_object
81
97
  remove = @manifest.annotations[0]
82
98
  assert_equal 3, @manifest.annotations.length
@@ -218,4 +234,11 @@ class TestManifest < Test::Unit::TestCase
218
234
  end
219
235
  end
220
236
 
237
+ def test_manifest_graph_statement_preserved
238
+ manifest = FakeManifest.new($man_ex6)
239
+
240
+ json = JSON.parse(JSON.generate(manifest))
241
+ assert_not_nil json["@graph"]
242
+ end
243
+
221
244
  end