source: ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/party_spec.rb@ 362

Last change on this file since 362 was 362, checked in by KOBAYASHI, Shinji, 14 years ago

refs #45 PartyIdentity, Contact, Address

File size: 3.6 KB
Line 
1require File.dirname(__FILE__) + '/../../../../spec_helper'
2include OpenEHR::RM::Demographic
3include OpenEHR::RM::DataTypes::Text
4include OpenEHR::RM::Support::Identification
5include OpenEHR::RM::DataStructures::ItemStructure
6
7describe Party do
8 before(:each) do
9 name = DvText.new(:value => 'PARTY')
10 uid = HierObjectID.new(:value => '01')
11 identities = stub(Set, :empty? => false, :size => 2)
12 contacts = stub(Set, :size => 3, :empty? => false)
13 cur_id = stub(ObjectID, :value => '01')
14 cur_source = stub(PartyRef, :id => cur_id)
15 id1 = stub(ObjectID, :value => '03')
16 targ1 = stub(PartyRef, :id => id1)
17 rel1 = stub(PartyRelationship, :source => cur_source,
18 :target => targ1)
19 id2 = stub(ObjectID, :value => '04')
20 targ2 = stub(PartyRef, :id => id2)
21 rel2 = stub(PartyRelationship, :source => cur_source,
22 :target => targ2)
23 id3 = stub(ObjectID, :value => '05')
24 targ3 = stub(PartyRef, :id => id3)
25 rel3 = stub(PartyRelationship, :source => cur_source,
26 :target => targ3)
27 id4 = stub(ObjectID, :value => '06')
28 targ4 = stub(PartyRef, :id => id4)
29 rel4 = stub(PartyRelationship, :source => cur_source,
30 :target => targ4)
31 relationships = [rel1, rel2, rel3, rel4].to_set
32 reverse_relationships = stub(Set, :empty? => false, :size => 5)
33 details = stub(ItemStructure, :archetype_node_id => 'at0005')
34 @party = Party.new(:archetype_node_id => 'at0001',
35 :name => name,
36 :uid => uid,
37 :identities => identities,
38 :contacts => contacts,
39 :relationships => relationships,
40 :reverse_relationships => reverse_relationships,
41 :details => details)
42 end
43
44 it 'should be an instance of Party' do
45 @party.should be_an_instance_of Party
46 end
47
48 it 'uid should be assigned properly' do
49 @party.uid.value.should == '01'
50 end
51
52 it 'should raise ArgumentError with nil uid' do
53 lambda {
54 @party.uid = nil
55 }.should raise_error ArgumentError
56 end
57
58 it 'identities should be assigned properly' do
59 @party.identities.size.should be_equal 2
60p end
61
62 it 'should raise ArgumentError when nil identities are assigned' do
63 lambda {
64 @party.identities = nil
65 }.should raise_error ArgumentError
66 end
67
68 it 'should raise ArgumentError when identities are empty' do
69 lambda {
70 @party.identities = Set.new
71 }
72 end
73
74 it 'type should be alias of name' do
75 @party.type.value.should == 'PARTY'
76 end
77
78 it 'contacts should be assigned properly' do
79 @party.contacts.size.should be_equal 3
80 end
81
82 it 'relationships should be assigned properly' do
83 target_ids = Set.new
84 @party.relationships.each do |rel|
85 target_ids << rel.target.id.value
86 end
87 target_ids.should == %w{03 04 05 06}.to_set
88 end
89
90 it 'should not raise ArgumentError with nil relationships' do
91 lambda {
92 @party.relationships = nil
93 }.should_not raise_error ArgumentError
94 end
95
96 it 'should raise ArgumentError with empty relationships' do
97 lambda {
98 @party.relationships = Set.new
99 }.should raise_error ArgumentError
100 end
101
102
103 it 'reverse relationship should be assigned properly' do
104 @party.reverse_relationships.size.should be_equal 5
105 end
106
107 it 'reverse_relationships should not be empty' do
108 lambda {
109 @party.reverse_relationships = Set.new
110 }.should raise_error ArgumentError
111 end
112
113 it 'should validate reverse_relationships'
114
115 it 'details should be assigned properly' do
116 @party.details.archetype_node_id.should == 'at0005'
117 end
118end
119
Note: See TracBrowser for help on using the repository browser.