caruby-core 1.5.5 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +9 -0
- data/History.md +5 -1
- data/lib/caruby.rb +3 -5
- data/lib/caruby/caruby-src.tar.gz +0 -0
- data/lib/caruby/database.rb +53 -69
- data/lib/caruby/database/application_service.rb +25 -0
- data/lib/caruby/database/cache.rb +60 -0
- data/lib/caruby/database/fetched_matcher.rb +52 -38
- data/lib/caruby/database/lazy_loader.rb +4 -4
- data/lib/caruby/database/operation.rb +34 -0
- data/lib/caruby/database/persistable.rb +171 -86
- data/lib/caruby/database/persistence_service.rb +32 -34
- data/lib/caruby/database/persistifier.rb +100 -43
- data/lib/caruby/database/reader.rb +107 -85
- data/lib/caruby/database/reader_template_builder.rb +60 -0
- data/lib/caruby/database/saved_matcher.rb +3 -3
- data/lib/caruby/database/sql_executor.rb +88 -17
- data/lib/caruby/database/writer.rb +213 -177
- data/lib/caruby/database/writer_template_builder.rb +334 -0
- data/lib/caruby/{util → helpers}/controlled_value.rb +0 -0
- data/lib/caruby/{util → helpers}/coordinate.rb +4 -4
- data/lib/caruby/{util → helpers}/person.rb +3 -3
- data/lib/caruby/{util → helpers}/properties.rb +7 -9
- data/lib/caruby/{util → helpers}/roman.rb +2 -2
- data/lib/caruby/{util → helpers}/version.rb +1 -1
- data/lib/caruby/json/deserializer.rb +2 -2
- data/lib/caruby/json/serializer.rb +49 -7
- data/lib/caruby/metadata.rb +30 -0
- data/lib/caruby/metadata/java_property.rb +21 -0
- data/lib/caruby/metadata/propertied.rb +191 -0
- data/lib/caruby/metadata/property.rb +22 -0
- data/lib/caruby/metadata/property_characteristics.rb +201 -0
- data/lib/caruby/migration/migratable.rb +11 -182
- data/lib/caruby/rdbi/driver/jdbc.rb +446 -0
- data/lib/caruby/resource.rb +20 -823
- data/lib/caruby/version.rb +1 -1
- data/test/lib/caruby/database/cache_test.rb +54 -0
- data/test/lib/caruby/{util → helpers}/controlled_value_test.rb +3 -5
- data/test/lib/caruby/{util → helpers}/person_test.rb +4 -6
- data/test/lib/caruby/helpers/properties_test.rb +34 -0
- data/test/lib/caruby/{util → helpers}/roman_test.rb +2 -3
- data/test/lib/caruby/{util → helpers}/version_test.rb +2 -3
- data/test/lib/helper.rb +7 -0
- metadata +161 -214
- data/lib/caruby/cli/application.rb +0 -36
- data/lib/caruby/cli/command.rb +0 -202
- data/lib/caruby/csv/csv_mapper.rb +0 -159
- data/lib/caruby/csv/csvio.rb +0 -203
- data/lib/caruby/database/search_template_builder.rb +0 -56
- data/lib/caruby/database/store_template_builder.rb +0 -278
- data/lib/caruby/domain.rb +0 -193
- data/lib/caruby/domain/attribute.rb +0 -584
- data/lib/caruby/domain/attributes.rb +0 -628
- data/lib/caruby/domain/dependency.rb +0 -225
- data/lib/caruby/domain/id_alias.rb +0 -22
- data/lib/caruby/domain/importer.rb +0 -183
- data/lib/caruby/domain/introspection.rb +0 -176
- data/lib/caruby/domain/inverse.rb +0 -172
- data/lib/caruby/domain/inversible.rb +0 -90
- data/lib/caruby/domain/java_attribute.rb +0 -173
- data/lib/caruby/domain/merge.rb +0 -185
- data/lib/caruby/domain/metadata.rb +0 -142
- data/lib/caruby/domain/mixin.rb +0 -35
- data/lib/caruby/domain/properties.rb +0 -95
- data/lib/caruby/domain/reference_visitor.rb +0 -428
- data/lib/caruby/domain/uniquify.rb +0 -50
- data/lib/caruby/import/java.rb +0 -387
- data/lib/caruby/migration/migrator.rb +0 -918
- data/lib/caruby/migration/resource_module.rb +0 -9
- data/lib/caruby/migration/uniquify.rb +0 -17
- data/lib/caruby/util/attribute_path.rb +0 -44
- data/lib/caruby/util/cache.rb +0 -56
- data/lib/caruby/util/class.rb +0 -149
- data/lib/caruby/util/collection.rb +0 -1152
- data/lib/caruby/util/domain_extent.rb +0 -46
- data/lib/caruby/util/file_separator.rb +0 -65
- data/lib/caruby/util/inflector.rb +0 -27
- data/lib/caruby/util/log.rb +0 -95
- data/lib/caruby/util/math.rb +0 -12
- data/lib/caruby/util/merge.rb +0 -59
- data/lib/caruby/util/module.rb +0 -18
- data/lib/caruby/util/options.rb +0 -97
- data/lib/caruby/util/partial_order.rb +0 -35
- data/lib/caruby/util/pretty_print.rb +0 -204
- data/lib/caruby/util/stopwatch.rb +0 -74
- data/lib/caruby/util/topological_sync_enumerator.rb +0 -62
- data/lib/caruby/util/transitive_closure.rb +0 -55
- data/lib/caruby/util/tree.rb +0 -48
- data/lib/caruby/util/trie.rb +0 -37
- data/lib/caruby/util/uniquifier.rb +0 -30
- data/lib/caruby/util/validation.rb +0 -20
- data/lib/caruby/util/visitor.rb +0 -365
- data/lib/caruby/util/weak_hash.rb +0 -36
- data/test/lib/caruby/csv/csv_mapper_test.rb +0 -40
- data/test/lib/caruby/csv/csvio_test.rb +0 -69
- data/test/lib/caruby/database/persistable_test.rb +0 -92
- data/test/lib/caruby/domain/domain_test.rb +0 -112
- data/test/lib/caruby/domain/inversible_test.rb +0 -99
- data/test/lib/caruby/domain/reference_visitor_test.rb +0 -130
- data/test/lib/caruby/import/java_test.rb +0 -80
- data/test/lib/caruby/import/mixed_case_test.rb +0 -14
- data/test/lib/caruby/migration/test_case.rb +0 -102
- data/test/lib/caruby/test_case.rb +0 -230
- data/test/lib/caruby/util/cache_test.rb +0 -23
- data/test/lib/caruby/util/class_test.rb +0 -61
- data/test/lib/caruby/util/collection_test.rb +0 -398
- data/test/lib/caruby/util/command_test.rb +0 -55
- data/test/lib/caruby/util/domain_extent_test.rb +0 -60
- data/test/lib/caruby/util/file_separator_test.rb +0 -30
- data/test/lib/caruby/util/inflector_test.rb +0 -12
- data/test/lib/caruby/util/lazy_hash_test.rb +0 -34
- data/test/lib/caruby/util/merge_test.rb +0 -83
- data/test/lib/caruby/util/module_test.rb +0 -25
- data/test/lib/caruby/util/options_test.rb +0 -59
- data/test/lib/caruby/util/partial_order_test.rb +0 -42
- data/test/lib/caruby/util/pretty_print_test.rb +0 -85
- data/test/lib/caruby/util/properties_test.rb +0 -50
- data/test/lib/caruby/util/stopwatch_test.rb +0 -18
- data/test/lib/caruby/util/topological_sync_enumerator_test.rb +0 -69
- data/test/lib/caruby/util/transitive_closure_test.rb +0 -67
- data/test/lib/caruby/util/tree_test.rb +0 -23
- data/test/lib/caruby/util/trie_test.rb +0 -14
- data/test/lib/caruby/util/visitor_test.rb +0 -278
- data/test/lib/caruby/util/weak_hash_test.rb +0 -45
- data/test/lib/examples/clinical_trials/migration/migration_test.rb +0 -58
- data/test/lib/examples/clinical_trials/migration/test_case.rb +0 -38
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'caruby/util/collection'
|
2
|
-
|
3
|
-
module CaRuby
|
4
|
-
# A WeakHash associates a key with a value until the key and value are no longer referenced elsewhere.
|
5
|
-
#
|
6
|
-
# The key and value must each be a jRuby wrapper for a Java object, i.e. a Ruby primitive such as String
|
7
|
-
# or Integer, or an instance of a Java class imported into jRuby.
|
8
|
-
class WeakHash
|
9
|
-
include Hashable
|
10
|
-
|
11
|
-
# Creates a new WeakHash.
|
12
|
-
def initialize
|
13
|
-
super
|
14
|
-
@map = Java::JavaUtil::WeakHashMap.new
|
15
|
-
end
|
16
|
-
|
17
|
-
def each
|
18
|
-
@map.each { |key, wref| yield(key, wref.get) }
|
19
|
-
end
|
20
|
-
|
21
|
-
# Returns the
|
22
|
-
def [](key)
|
23
|
-
# the weak reference mapped by the key
|
24
|
-
wref = @map.get(key)
|
25
|
-
# the referenced object
|
26
|
-
wref.get if wref
|
27
|
-
end
|
28
|
-
|
29
|
-
def []=(key, value)
|
30
|
-
# make a weak reference to the value
|
31
|
-
wref = Java::JavaLangRef::WeakReference.new(value)
|
32
|
-
# associate the object identifier with the weak reference
|
33
|
-
@map.put(key, wref)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
$:.unshift 'lib'
|
2
|
-
$:.unshift 'examples/clinical_trials/lib'
|
3
|
-
|
4
|
-
require 'set'
|
5
|
-
require "test/unit"
|
6
|
-
require 'caruby/csv/csv_mapper'
|
7
|
-
|
8
|
-
require 'caruby/util/log' and
|
9
|
-
CaRuby::Log.instance.open('test/results/log/csv.log', :shift_age => 10, :shift_size => 1048576, :debug => true)
|
10
|
-
|
11
|
-
require 'clinical_trials'
|
12
|
-
|
13
|
-
class CsvMapperTest < Test::Unit::TestCase
|
14
|
-
FIXTURES = File.join('test', 'fixtures', 'caruby', 'csv')
|
15
|
-
|
16
|
-
CONFIG_DIR = File.join(FIXTURES, 'config')
|
17
|
-
|
18
|
-
DATA_DIR = File.join(FIXTURES, 'data')
|
19
|
-
|
20
|
-
def test_read_mapper
|
21
|
-
config = File.join(CONFIG_DIR, 'study_fields.yaml')
|
22
|
-
csv = File.join(DATA_DIR, 'study.csv')
|
23
|
-
mapper = CaRuby::CsvMapper.new(config, ClinicalTrials::StudyEvent, csv)
|
24
|
-
assert_equal([ClinicalTrials::StudyEvent], mapper.classes, "Classes incorrect")
|
25
|
-
map = {[:calendar_event_point]=>:event_point, [:identifier]=>:id, [:study, :activity_status]=>:status, [:study, :name]=>:study}
|
26
|
-
paths = map.keys.to_set
|
27
|
-
path_md_sym_hash = mapper.paths(ClinicalTrials::StudyEvent).to_compact_hash { |path| path.map { |attr_md| attr_md.to_sym } }
|
28
|
-
assert_equal(paths, path_md_sym_hash.values.to_set, "Paths incorrect")
|
29
|
-
path_md_hdr_hash = mapper.paths.to_compact_hash { |path| mapper.header(path) }
|
30
|
-
actual = path_md_sym_hash.invert.join(path_md_hdr_hash).to_hash
|
31
|
-
assert_equal(map, actual, "Header map incorrect")
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_write_mapper
|
35
|
-
config = File.join(CONFIG_DIR, 'study_fields.yaml')
|
36
|
-
csv = File.join(DATA_DIR, 'dummy.csv')
|
37
|
-
headers = ['Id', 'Study', 'Status', 'Event Point']
|
38
|
-
mapper = CaRuby::CsvMapper.new(config, ClinicalTrials::StudyEvent, csv, :mode => 'w', :headers => headers)
|
39
|
-
end
|
40
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
$:.unshift 'lib'
|
2
|
-
|
3
|
-
require "test/unit"
|
4
|
-
require 'ftools'
|
5
|
-
require 'date'
|
6
|
-
require 'caruby/csv/csvio'
|
7
|
-
require 'caruby/util/log'
|
8
|
-
require 'caruby/util/file_separator'
|
9
|
-
|
10
|
-
class CsvIOTest < Test::Unit::TestCase
|
11
|
-
FIXTURES_DIR = File.join('test', 'fixtures', 'caruby', 'csv', 'data')
|
12
|
-
OUTPUT_DIR = File.join('test', 'results', 'caruby', 'csv')
|
13
|
-
LOG_FILE = File.join('test', 'results', 'log', 'csv.log')
|
14
|
-
|
15
|
-
def setup
|
16
|
-
CaRuby::Log.instance.open(LOG_FILE, :debug => true)
|
17
|
-
File.makedirs(OUTPUT_DIR)
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_read
|
21
|
-
loader = CsvIO.new(File.join(FIXTURES_DIR, 'variety.csv'))
|
22
|
-
loader.each do |row|
|
23
|
-
assert_not_nil(row[:id], "Missing id")
|
24
|
-
assert_not_nil(row[:string_field], "Missing string_field")
|
25
|
-
assert_not_nil(row[:integer], "Missing integer method")
|
26
|
-
assert(Integer === row[:integer], "Incorrect integer field value type")
|
27
|
-
assert_not_nil(row[:float], "Missing float method")
|
28
|
-
assert(Float === row[:float], "Incorrect float field value type")
|
29
|
-
assert_not_nil(row[:date], "Missing date method")
|
30
|
-
assert_equal(Date, row[:date].class, "Incorrect date field value type")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_empty
|
35
|
-
loader = CsvIO.new(File.join(FIXTURES_DIR, 'empty.csv'))
|
36
|
-
row = loader.shift
|
37
|
-
assert_nil(row[:one], "Missing value not nil")
|
38
|
-
assert_nil(row[:two], "Missing value not nil")
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_accessor
|
42
|
-
loader = CsvIO.new(File.join(FIXTURES_DIR, 'variety.csv'))
|
43
|
-
assert_equal(:id, loader.accessor('Id'), "Accessor incorrect")
|
44
|
-
assert_equal(:string_field, loader.accessor('String Field'), "Accessor incorrect")
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_write
|
48
|
-
input = File.join(FIXTURES_DIR, 'variety.csv')
|
49
|
-
output = File.join(OUTPUT_DIR, 'variety.csv')
|
50
|
-
headers = records = nil
|
51
|
-
# Read the input file content.
|
52
|
-
File.open(input) do |file|
|
53
|
-
headers = file.readline.chomp.split(/,\s*/)
|
54
|
-
records = file.map { |line| line.chomp.split(/,\s*/) }
|
55
|
-
end
|
56
|
-
# Write the output file.
|
57
|
-
CsvIO.open(output, :mode => 'w', :headers => headers) do |csvio|
|
58
|
-
records.each { |rec| csvio << rec }
|
59
|
-
end
|
60
|
-
# Compare the output to the input.
|
61
|
-
File.open(output) do |file|
|
62
|
-
assert_equal(headers, file.readline.chomp.split(/,\s*/), "Headers don't match")
|
63
|
-
file.each_with_index do |line, i|
|
64
|
-
rec = line.chomp.split(/,\s*/)
|
65
|
-
assert_equal(records[i], rec, "Line #{i.succ} doesn't match")
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
$:.unshift 'lib'
|
2
|
-
$:.unshift 'examples/clinical_trials/lib'
|
3
|
-
|
4
|
-
require 'test/unit'
|
5
|
-
|
6
|
-
require 'caruby/util/log' and
|
7
|
-
CaRuby::Log.instance.open('test/results/log/clinical_trials.log', :shift_age => 10, :shift_size => 1048576, :debug => true)
|
8
|
-
|
9
|
-
require 'clinical_trials'
|
10
|
-
|
11
|
-
class PersistableTest < Test::Unit::TestCase
|
12
|
-
|
13
|
-
def setup
|
14
|
-
@coord = ClinicalTrials::User.new(:login => 'study.coordinator@test.org')
|
15
|
-
address = ClinicalTrials::Address.new(:street => '555 Elm St', :city => 'Burlington', :state => 'VT', :zip_code => '55555')
|
16
|
-
@pnt = ClinicalTrials::Participant.new(:name => 'Test Participant')
|
17
|
-
@study = ClinicalTrials::Study.new(:name => 'Test Study')
|
18
|
-
@evt = ClinicalTrials::StudyEvent.new(:calendar_event_point => 1.0)
|
19
|
-
@consent = ClinicalTrials::Consent.new(:statement => 'Test statement')
|
20
|
-
@loader = lambda { |obj, attr| load(obj, attr) }
|
21
|
-
@@counter = 0
|
22
|
-
@study.identifier = @@counter += 1
|
23
|
-
@study.add_lazy_loader(@loader)
|
24
|
-
@references = {
|
25
|
-
@study => {:coordinator => @coord, :enrollment => [@pnt], :study_events => [@evt], :consents => [@consent]},
|
26
|
-
@pnt => {:address => address}
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_independent_reference
|
31
|
-
assert_not_nil(@study.coordinator, "Independent reference not loaded")
|
32
|
-
assert_not_nil(@study.coordinator.identifier, "Independent reference loaded but identifier not set")
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_dependent_reference
|
36
|
-
assert_not_nil(@study.events.first, "Dependent events reference not loaded")
|
37
|
-
assert_not_nil(@study.events.first.identifier, "Dependent events reference loaded but identifier not set")
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_unidirectional_dependent
|
41
|
-
assert_nil(@study.consents.first, "Unidirectional dependent consents reference incorrectly loaded")
|
42
|
-
# explicitly set the consents loader
|
43
|
-
@study.remove_lazy_loader
|
44
|
-
@study.add_lazy_loader(@loader)
|
45
|
-
# verify the load merge
|
46
|
-
assert_not_nil(@study.consents.first, "Dependent consents reference not loaded")
|
47
|
-
assert_not_nil(@study.consents.first.identifier, "Dependent consents reference loaded but identifier not set")
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_unidirectional_dependent_merge
|
51
|
-
# explicitly set the consents loader
|
52
|
-
@study.remove_lazy_loader
|
53
|
-
@study.add_lazy_loader(@loader)
|
54
|
-
# verify the load merge
|
55
|
-
assert_equal(1, @study.consents.size, "Unambiguous dependent consent not merged")
|
56
|
-
assert_not_nil(@study.consents.first.identifier, "Dependent consents reference loaded but identifier not set")
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_unidirectional_dependent_ambiguous_merge
|
60
|
-
# add the consent
|
61
|
-
@study.consents << @consent
|
62
|
-
# make an ambiguous "persistent" consent
|
63
|
-
@references[@study][:consents] << @consent.copy
|
64
|
-
# explicitly set the consents loader
|
65
|
-
@study.remove_lazy_loader
|
66
|
-
@study.add_lazy_loader(@loader)
|
67
|
-
# verify the load merge
|
68
|
-
assert_equal(3, @study.consents.size, "Ambiguous dependent consent not added")
|
69
|
-
assert_nil(@consent.identifier, "Consent identifier incorrectly merged from ambiguous dependent consent")
|
70
|
-
end
|
71
|
-
|
72
|
-
# Verifies that the loader is disabled when an attribute is set.
|
73
|
-
def test_setter_disable
|
74
|
-
@study.coordinator = @coord
|
75
|
-
assert_nil(@study.coordinator.identifier, "Independent reference loaded after set")
|
76
|
-
end
|
77
|
-
|
78
|
-
private
|
79
|
-
|
80
|
-
def load(obj, attribute)
|
81
|
-
value = @references[obj][attribute]
|
82
|
-
raise ArgumentError.new("Value not found for #{attribute}: #{obj}") if value.nil?
|
83
|
-
duplicate_with_id(value)
|
84
|
-
end
|
85
|
-
|
86
|
-
def duplicate_with_id(obj)
|
87
|
-
return obj.map { |item| duplicate_with_id(item) } if Enumerable === obj
|
88
|
-
copy = obj.copy
|
89
|
-
copy.identifier ||= @@counter += 1
|
90
|
-
copy
|
91
|
-
end
|
92
|
-
end
|
@@ -1,112 +0,0 @@
|
|
1
|
-
$:.unshift 'lib'
|
2
|
-
$:.unshift 'examples/clinical_trials/lib'
|
3
|
-
|
4
|
-
require 'test/unit'
|
5
|
-
|
6
|
-
# open the logger
|
7
|
-
require 'caruby/util/log'
|
8
|
-
CaRuby::Log.instance.open('test/results/log/clinical_trials.log', :shift_age => 10, :shift_size => 1048576, :debug => true)
|
9
|
-
|
10
|
-
require 'clinical_trials'
|
11
|
-
|
12
|
-
# CaRuby::Resource test cases.
|
13
|
-
class DomainTest < Test::Unit::TestCase
|
14
|
-
def setup
|
15
|
-
super
|
16
|
-
@crd = ClinicalTrials::User.new(:login => 'study.coordinator@test.org')
|
17
|
-
address = ClinicalTrials::Address.new(:street => '555 Elm St', :city => 'Burlington', :state => 'VT', :zip_code => '55555')
|
18
|
-
@sbj = ClinicalTrials::Subject.new(:name => 'Test Subject', :address => address)
|
19
|
-
@study = ClinicalTrials::Study.new(:name => 'Test Study', :coordinator => @crd, :enrollment => [@sbj])
|
20
|
-
@evt = ClinicalTrials::StudyEvent.new(:study => @study, :calendar_event_point => 1.0)
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_alias
|
24
|
-
assert(ClinicalTrials::Study.method_defined?(:events), "Study alias not recognized: events")
|
25
|
-
assert_equal(@sbj.address.zip_code, @sbj.address.postal_code, 'zip_code not aliased to postal_code')
|
26
|
-
assert_equal(:zip_code, @sbj.address.class.standard_attribute(:postal_code), 'postal_code does not map to a standard attribute symbol')
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_redefine
|
30
|
-
@sbj.address.zip_code = 55555
|
31
|
-
assert_equal('55555', @sbj.address.zip_code, "Address zip_code not redefined to support a numeric value")
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_merge_attributes
|
35
|
-
assert_same(@study.enrollment.first, @sbj, "Merge incorrect")
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_owner_inverse_setter
|
39
|
-
assert_equal([@evt], @study.events.to_a, 'Event not added to owner events')
|
40
|
-
# add another event
|
41
|
-
# note: calendar_event_point must be unique within the study or it won't be added to the study events set
|
42
|
-
@evt.calendar_event_point = 1.0
|
43
|
-
ClinicalTrials::StudyEvent.new(:study => @study, :calendar_event_point => 2.0)
|
44
|
-
assert_equal(2, @study.events.to_a.size, 'Second event not added to owner events')
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_study_defaults
|
48
|
-
assert_nil(@study.activity_status, 'Activity status is already set')
|
49
|
-
@study.add_defaults
|
50
|
-
assert_equal('Active', @study.activity_status, 'Activity status is not set to default')
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_event_defaults
|
54
|
-
@evt.calendar_event_point = nil
|
55
|
-
@evt.add_defaults
|
56
|
-
assert_equal(1.0, @evt.calendar_event_point, 'Event calendar_event_point is not set to default')
|
57
|
-
end
|
58
|
-
|
59
|
-
# Tests whether add_defaults method propagates to dependents.
|
60
|
-
def test_participant_defaults
|
61
|
-
assert_nil(@sbj.address.country, 'Subject address country is already set')
|
62
|
-
@sbj.add_defaults
|
63
|
-
assert_equal('US', @sbj.address.country, 'Subject address country is not set to default')
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_dependents
|
67
|
-
assert_equal([@evt], @study.dependents.to_a, "Study dependents incorrect")
|
68
|
-
assert(@evt.dependent?, "Event not dependent")
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_searchable_attributes
|
72
|
-
assert_equal([:name], @study.searchable_attributes.to_a, "Study finder attributes without identifier incorrect")
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_event_key
|
76
|
-
@evt.calendar_event_point = 1.0
|
77
|
-
assert_equal([@study, 1.0], @evt.key, "Event key incorrect")
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_address_key
|
81
|
-
assert_nil(@sbj.address.key, "Address key incorrect")
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_set_collection_attribute
|
85
|
-
consent = ClinicalTrials::Consent.new(:statement => 'Test Statement 1')
|
86
|
-
consents = @study.consents << consent
|
87
|
-
other_consent = ClinicalTrials::Consent.new(:statement => 'Test Statement 2')
|
88
|
-
@study.set_attribute(:consents, [other_consent])
|
89
|
-
assert_equal([other_consent], @study.consents.to_a, "Consents not set")
|
90
|
-
assert_same(consents, @study.consents)
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_value_hash
|
94
|
-
assert_equal({:study => @study}, @evt.value_hash([:identifier, :study]), "Event value hash incorrect")
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_reference_closure
|
98
|
-
assert_equal([@study, @evt], @study.reference_hierarchy { |ref| ref.class.dependent_attributes }.to_a, "Reference closure with block incorrect")
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_visit_path
|
102
|
-
visited = []
|
103
|
-
@study.visit_path([:enrollment, :address]) { |ref| visited << ref }
|
104
|
-
assert_equal([@study, @sbj, @sbj.address], visited, "Path visitor incorrect")
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_visit_dependents
|
108
|
-
visited = []
|
109
|
-
@study.visit_dependents { |ref| visited << ref }
|
110
|
-
assert_equal([@study, @evt], visited, "Dependents visitor incorrect")
|
111
|
-
end
|
112
|
-
end
|
@@ -1,99 +0,0 @@
|
|
1
|
-
$:.unshift 'lib'
|
2
|
-
|
3
|
-
require 'caruby'
|
4
|
-
require "test/unit"
|
5
|
-
|
6
|
-
class InversibleTest < Test::Unit::TestCase
|
7
|
-
module Domain
|
8
|
-
extend CaRuby::Domain
|
9
|
-
end
|
10
|
-
|
11
|
-
module Resource
|
12
|
-
include CaRuby::Resource
|
13
|
-
attr_accessor :identifier
|
14
|
-
end
|
15
|
-
|
16
|
-
class Person; end
|
17
|
-
|
18
|
-
class Account
|
19
|
-
include Resource
|
20
|
-
Domain.add_class(self)
|
21
|
-
|
22
|
-
attr_accessor :person
|
23
|
-
add_attribute(:person, Person)
|
24
|
-
end
|
25
|
-
|
26
|
-
class Person
|
27
|
-
include Resource
|
28
|
-
Domain.add_class(self)
|
29
|
-
|
30
|
-
attr_accessor :spouse
|
31
|
-
add_attribute(:spouse, Person)
|
32
|
-
|
33
|
-
set_attribute_inverse(:spouse, :spouse)
|
34
|
-
|
35
|
-
attr_accessor :account
|
36
|
-
add_attribute(:account, Account)
|
37
|
-
|
38
|
-
set_attribute_inverse(:account, :person)
|
39
|
-
end
|
40
|
-
|
41
|
-
class Child; end
|
42
|
-
|
43
|
-
class Parent
|
44
|
-
include Resource
|
45
|
-
Domain.add_class(self)
|
46
|
-
|
47
|
-
attr_accessor :children
|
48
|
-
add_attribute(:children, Child, :collection)
|
49
|
-
end
|
50
|
-
|
51
|
-
class Child
|
52
|
-
include Resource
|
53
|
-
Domain.add_class(self)
|
54
|
-
|
55
|
-
attr_accessor :parent
|
56
|
-
add_attribute(:parent, Parent)
|
57
|
-
|
58
|
-
set_attribute_inverse(:parent, :children)
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_1_1
|
62
|
-
p1 = Person.new
|
63
|
-
a1 = Account.new
|
64
|
-
p1.account = a1
|
65
|
-
assert_same(p1, a1.person, "1:1 inverse not set")
|
66
|
-
a2 = Account.new
|
67
|
-
p1.account = a2
|
68
|
-
assert_same(p1, a2.person, "1:1 inverse not set")
|
69
|
-
assert_nil(a1.person, "1:1 previous inverse not cleared")
|
70
|
-
p1.account = nil
|
71
|
-
assert_nil(a2.person, "1:1 previous inverse not cleared")
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_1_1_same
|
75
|
-
p1 = Person.new
|
76
|
-
p2 = Person.new
|
77
|
-
p1.spouse = p2
|
78
|
-
assert_same(p1, p2.spouse, "1:1 inverse not set")
|
79
|
-
p3 = Person.new
|
80
|
-
p1.spouse = p3
|
81
|
-
assert_same(p3, p1.spouse, "1:1 inverse not set")
|
82
|
-
assert_nil(p2.spouse, "1:1 previous inverse not cleared")
|
83
|
-
p1.spouse = nil
|
84
|
-
assert_nil(p3.spouse, "1:1 previous inverse not cleared")
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_1_m
|
88
|
-
p1 = Parent.new
|
89
|
-
c = Child.new
|
90
|
-
c.parent = p1
|
91
|
-
assert_same(c, p1.children.first, "1:M inverse not set")
|
92
|
-
p2 = Parent.new
|
93
|
-
c.parent = p2
|
94
|
-
assert_same(c, p2.children.first, "1:M inverse not set")
|
95
|
-
assert(p1.children.empty?, "1:M previous inverse not cleared")
|
96
|
-
c.parent = nil
|
97
|
-
assert(p2.children.empty?, "1:M previous inverse not cleared")
|
98
|
-
end
|
99
|
-
end
|