Index: ruby/trunk/spec/lib/open_ehr/rm/common/archetyped/archetyped_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/archetyped/archetyped_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/archetyped/archetyped_spec.rb	(revision 369)
@@ -0,0 +1,50 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::Archetyped
+include OpenEHR::RM::Support::Identification
+
+describe Archetyped do
+  before(:each) do
+    archetype_id = ArchetypeID.new(:value => 
+                      'openEHR-EHR-SECTION.physical_examination.v2')
+    template_id = TemplateID.new(:value =>
+                   'uk.nhs.cfh:openehr-EHR-COMPOSITION.admission_ed.v5')
+    @archetyped = Archetyped.new(:archetype_id => archetype_id,
+                                 :rm_version => '1.2.4',
+                                 :template_id => template_id)
+  end
+
+  it 'should be an instance of Archetyped' do
+    @archetyped.should be_an_instance_of Archetyped
+  end
+
+  it 'archetype id concept rm_name should be EHR' do
+    @archetyped.archetype_id.rm_name.should == 'EHR'
+  end
+
+  it 'rm_version should 1.2.4' do
+    @archetyped.rm_version.should == '1.2.4'
+  end
+
+  it 'template_id.value should be uk.nhs.cfh:openehr-EHR-COMPOSITION.admission_ed.v5' do
+    @archetyped.template_id.value.should ==
+      'uk.nhs.cfh:openehr-EHR-COMPOSITION.admission_ed.v5'
+  end
+
+  it 'should raise ArgumentError with nil rm_version' do
+    lambda {
+      @archetyped.rm_version = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with empty rm_version' do
+    lambda {
+      @archetyped.rm_version = ''
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with nil ArchetypeID' do
+    lambda {
+      @archetyped.archetype_id = nil
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/archetyped/feeder_audit_details_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/archetyped/feeder_audit_details_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/archetyped/feeder_audit_details_spec.rb	(revision 369)
@@ -0,0 +1,60 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::Archetyped
+include OpenEHR::RM::Common::Generic
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+
+describe FeederAuditDetails do
+  before(:each) do
+    provider = stub(PartyIdentified, :name => 'NERV')
+    location = stub(PartyIdentified, :name => '3rd Tokyo')
+    time = stub(DvDateTime, :value => '2009-09-28T19:40')
+    subject = stub(PartyProxy, :type => 'PARTY')
+    @feeder_audit_details =
+      FeederAuditDetails.new(:system_id => 'MELCHIOR',
+                             :provider => provider,
+                             :location => location,
+                             :time => time,
+                             :subject => subject,
+                             :version_id => '0.5.0')
+  end
+
+  it 'should be an instance of FeederAuditDetails' do
+    @feeder_audit_details.should be_an_instance_of FeederAuditDetails
+  end
+
+  it 'system_id should be MELCHIOR' do
+    @feeder_audit_details.system_id.should == 'MELCHIOR'
+  end
+
+  it 'provider.name should be NERV' do
+    @feeder_audit_details.provider.name.should == 'NERV'
+  end
+
+  it 'location.name should be 3rd Tokyo' do
+    @feeder_audit_details.location.name.should == '3rd Tokyo'
+  end
+
+  it 'time.value should be 2009-09-28T19:40' do
+    @feeder_audit_details.time.value.should == '2009-09-28T19:40'
+  end
+
+  it 'subject.type should be PARTY' do
+    @feeder_audit_details.subject.type.should == 'PARTY'
+  end
+
+  it 'version_id should be 0.5.0' do
+    @feeder_audit_details.version_id.should == '0.5.0'
+  end
+
+  it 'should reise ArgumentError with nil system_id' do
+    lambda {
+      @feeder_audit_details.system_id = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with empty syste_id' do
+    lambda {
+      @feeder_audit_details.system_id = ''
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/archetyped/feeder_audit_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/archetyped/feeder_audit_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/archetyped/feeder_audit_spec.rb	(revision 369)
@@ -0,0 +1,51 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::Archetyped
+include OpenEHR::RM::DataTypes::Encapsulated
+include OpenEHR::RM::DataTypes::Basic
+
+describe FeederAudit do
+  before(:each) do
+    originating_system_audit = stub(FeederAuditDetails, :system_id => 'CASPAR')
+    originating_system_item_ids = stub(Array, :size => 10)
+    feeder_system_audit = stub(FeederAuditDetails, :system_id => 'BARTHASAR')
+    feeder_system_item_ids = stub(Array, :size => 5)
+    original_content = stub(DvEncapsulated, :charset => 'UTF-8')
+    @feeder_audit = FeederAudit.new(
+       :originating_system_audit => originating_system_audit,
+       :originating_system_item_ids => originating_system_item_ids,
+       :feeder_system_audit => feeder_system_audit,
+       :feeder_system_item_ids => feeder_system_item_ids,
+       :original_content => original_content)
+  end
+
+  it 'should be an instance of FeederAudit' do
+    @feeder_audit.should be_an_instance_of FeederAudit
+  end
+
+  it 'originating_system_audit.system_id should be CASPAR' do
+    @feeder_audit.originating_system_audit.system_id.should == 'CASPAR'
+  end
+
+  it 'originating_system_item_ids.size should be equal 10' do
+    @feeder_audit.originating_system_item_ids.size.should be_equal 10
+  end
+
+  it 'feeder_system_audit.system_id should BARTHASAR' do
+    @feeder_audit.feeder_system_audit.system_id.should == 'BARTHASAR'
+  end
+
+  it 'feeder_system_item_ids.size should be equal 5' do
+    @feeder_audit.feeder_system_item_ids.size.should be_equal 5
+  end
+
+  it 'original_content.charset should be UTF-8' do
+    @feeder_audit.original_content.charset.should == 'UTF-8'
+  end
+
+  it 'should raise ArgumentError with nil originating_system_audit' do
+    lambda {
+      @feeder_audit.originating_system_audit = nil
+    }.should raise_error ArgumentError
+  end
+end
+
Index: ruby/trunk/spec/lib/open_ehr/rm/common/archetyped/link_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/archetyped/link_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/archetyped/link_spec.rb	(revision 369)
@@ -0,0 +1,43 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::Archetyped
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataTypes::Uri
+
+describe Link do
+  before(:each) do
+    @link = Link.new(:meaning => DvText.new(:value => 'generic'),
+                     :type => DvText.new(:value => 'problem'),
+                     :target => DvEhrUri.new(:value => 'ehr://test'))
+  end
+
+  it 'should be an instance of Link' do
+    @link.should be_an_instance_of Link
+  end
+
+  it 'meaning should be generic' do
+    @link.meaning.value.should == 'generic'
+  end
+
+  it 'target should be ehr://test' do
+    @link.target.value.should == 'ehr://test'
+  end
+
+  it 'should raise ArgumentError with nil meaning' do
+    lambda {
+      @link.meaning = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with nil type' do
+    lambda {
+      @link.type = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with nil target' do
+    lambda {
+      @link.target = nil
+    }.should raise_error ArgumentError
+  end
+
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/archetyped/locatable_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/archetyped/locatable_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/archetyped/locatable_spec.rb	(revision 369)
@@ -0,0 +1,89 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::Archetyped
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::Support::Identification
+
+describe Locatable do
+  before(:each) do
+    name = DvText.new(:value => 'problem/SOAP')
+    link = stub(Set, :size => 10, :empty? => false)
+    uid = UIDBasedID.new(:value => 'ehr::localhost/3030')
+    archetype_id = ArchetypeID.new(:value =>
+                           'openEHR-EHR-SECTION.physical_examination.v2')
+    archetype_details = stub(Archetyped, :rm_version =>  '1.2.4',
+                             :archetype_id => archetype_id)
+    feeder_audit = stub(FeederAudit, :system_id => 'MAGI')
+    @locatable = Locatable.new(:archetype_node_id => 'at001',
+                               :name => name,
+                               :links => link,
+                               :uid => uid,
+                               :feeder_audit => feeder_audit,
+                               :archetype_details => archetype_details)
+  end
+
+  it 'should be_an_instance_of Locatable' do
+    @locatable.should be_an_instance_of Locatable
+  end
+
+  it 'archetype_node_id should be at001' do
+    @locatable.archetype_node_id.should == 'at001'
+  end
+
+  it 'is_archetype_root? should be true' do
+    @locatable.is_archetype_root?.should be_true
+  end
+
+  it 'is_archetype_root? should be false when archetype_details is nil' do
+    @locatable.archetype_details = nil
+    @locatable.is_archetype_root?.should be_false
+  end
+
+  it 'link size should be 10' do
+    @locatable.links.size.should == 10
+  end
+
+  it 'name.value should problem/soap' do
+    @locatable.name.value.should == 'problem/SOAP'
+  end
+
+  it 'uid.value should be ehr::localhost/3030' do
+    @locatable.uid.value.should == 'ehr::localhost/3030'
+  end
+
+  it 'archetype_details.rm_version should be 1.2.4' do
+    @locatable.archetype_details.rm_version.should == '1.2.4'
+  end
+
+  it 'feeer_audit.system_id should MAGI' do
+    @locatable.feeder_audit.system_id.should == 'MAGI'
+  end
+
+  it 'concept should be physical_examination' do
+    @locatable.concept.value.should == 'physical_examination'
+  end
+
+  it 'should raise ArgumentError with nil archetype_node_id' do
+    lambda {
+      @locatable.archetype_node_id = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with nil name' do
+    lambda {
+      @locatable.name = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with empty links' do
+    lambda {
+      @locatable.links = Set.new
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError Archetyped invalid' do
+    @locatable.archetype_details = nil
+    lambda {
+      @locatable.concept
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/archetyped/pathable_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/archetyped/pathable_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/archetyped/pathable_spec.rb	(revision 369)
@@ -0,0 +1,42 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::Archetyped
+
+describe Pathable do
+  before(:each) do
+    @pathable = Pathable.new
+  end
+
+  it 'should be an instance of Pathable' do
+    @pathable.should be_an_instance_of Pathable
+  end
+
+  it 'item_at_path should raise NotImplementedError' do
+    lambda {
+      @pathable.item_at_path('/')
+    }.should raise_error NotImplementedError
+  end
+
+  it 'items_at_path should raise NotImplementedError' do
+    lambda {
+      @pathable.items_at_path('/')
+    }.should raise_error NotImplementedError
+  end
+
+  it 'path_exists? should raise NotImplementedError' do
+    lambda {
+      @pathable.path_exists?('/')
+    }.should raise_error NotImplementedError
+  end
+
+  it 'path_of_item should raise NotImplementedError' do
+    lambda {
+      @pathable.path_of_item('/')
+    }.should raise_error NotImplementedError
+  end
+
+  it 'path_unique? should raise NotImplementedError' do
+    lambda {
+      @pathable.path_unique?('/')
+    }.should raise_error NotImplementedError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/change_control/contribution_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/change_control/contribution_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/change_control/contribution_spec.rb	(revision 369)
@@ -0,0 +1,56 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::ChangeControl
+include OpenEHR::RM::DataTypes::Text
+
+describe Contribution do
+  before(:each) do
+    uid = HierObjectID.new(:value => 'ABC::DEF::2')
+    versions = stub(Set, :size => 2, :empty? => false)
+    description = DvText.new(:value => 'test')
+    audit = stub(AuditDetails, :empty? => false, :description => description)
+    @contribution = Contribution.new(:uid => uid,
+                                     :versions => versions,
+                                     :audit => audit)
+  end
+
+  it 'should be an instance of Contribution' do
+    @contribution.should be_an_instance_of Contribution
+  end
+
+  it 'uid.value should be ABC::DEF::2' do
+    @contribution.uid.value.should == 'ABC::DEF::2'
+  end
+
+  it 'audit.description should test' do
+    @contribution.audit.description.value.should == 'test'
+  end
+
+  it 'versions size should be 2' do
+    @contribution.versions.size.should == 2
+  end
+
+  it 'should raise ArgumentError when version is empty' do
+    lambda {
+      @contribution.versions = Set.new
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError when uid is nil' do
+    lambda {
+      @contribution.uid = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError audit is nil' do
+    lambda {
+      @contribution.audit = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'shoudl raise ArgumentError audit.description is empty' do
+    nil_audit = stub(AuditDetails, :description => nil)
+    lambda {
+      @contribution.audit = nil_audit
+    }.should raise_error ArgumentError
+  end 
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/change_control/imported_version_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/change_control/imported_version_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/change_control/imported_version_spec.rb	(revision 369)
@@ -0,0 +1,29 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+require File.dirname(__FILE__) + '/shared_examples_spec'
+include OpenEHR::RM::Common::ChangeControl
+
+describe ImportedVersion do
+  it_should_behave_like 'change_control'
+
+  it 'should be an instance of ImportedVersion' do
+    @imported_version.should be_an_instance_of ImportedVersion
+  end
+
+  it 'uid should be item.uid' do
+    @imported_version.uid.value.should == 'ABCD::EFG::2'
+  end
+
+  it 'lifecycle_state should be item.lifecycle' do
+    @imported_version.lifecycle_state.defining_code.code_string.should == '532'
+  end
+
+  it 'preceding_version_uid should be item.preceding_version_uid' do
+    @imported_version.preceding_version_uid.value.should == 'HIJ::KLM::1'
+  end
+
+  it 'should raise ArgumentError when item is nil' do
+    lambda {
+      @imported_version.item = nil
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/change_control/original_version_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/change_control/original_version_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/change_control/original_version_spec.rb	(revision 369)
@@ -0,0 +1,41 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+require File.dirname(__FILE__) + '/shared_examples_spec'
+include OpenEHR::RM::Common::ChangeControl
+include OpenEHR::RM::DataTypes::Text
+
+describe OriginalVersion do
+  it_should_behave_like 'change_control'
+
+  it 'should be an isntance of OriginalVersion' do
+    @original_version.should be_an_instance_of OriginalVersion
+  end
+
+  it 'attestation size should be 12' do
+    @original_version.attestations.size.should == 12
+  end
+
+  it 'other_version_input_uids size should be 5' do
+    @original_version.other_input_version_uids.size.should == 5
+  end
+
+  it 'is_merged? should be true when other_input_version_uids is nil' do
+    @original_version.is_merged?.should be_true
+  end
+
+  it 'is_merged? should not be true when other_input_version_uids is not nil' do
+    @original_version.other_input_version_uids = nil
+    @original_version.is_merged?.should be_false
+  end
+
+  it 'should raise ArgumentError when attestations is nil' do
+    lambda {
+      @original_version.attestations = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError when other_input_version_uids is empty' do
+    lambda {
+      @original_version.other_input_version_uids = Set.new
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/change_control/shared_examples_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/change_control/shared_examples_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/change_control/shared_examples_spec.rb	(revision 369)
@@ -0,0 +1,37 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::ChangeControl
+include OpenEHR::RM::DataTypes::Text
+
+shared_examples_for 'change_control', :shared => true do
+  before(:each) do
+    uid = ObjectVersionID.new(:value => 'ABCD::EFG::2')
+    preceding_version_uid = ObjectVersionID.new(:value => 'HIJ::KLM::1')
+    commit_audit = stub(AuditDetails, :committer => 'UNKNOWN', :empty? => false)
+    object_id = stub(ObjectID, :value => 'unique')
+    contribution = ObjectRef.new(:namespace => 'local',
+                                 :type => 'CONTRIBUTION',
+                                 :id => object_id)
+    defining_code = stub(CodePhrase, :code_string => '532')
+    lifecycle_state = stub(DvCodedText, :defining_code => defining_code)
+    signature = '4760271533c2866579dde347ad28dd79e4aad933'
+    @version = Version.new(:uid => uid,
+                           :preceding_version_uid => preceding_version_uid,
+                           :data => 'data',
+                           :contribution => contribution,
+                           :lifecycle_state => lifecycle_state,
+                           :commit_audit => commit_audit,
+                           :signature => signature)
+    attestations = stub(Array, :empty? => false, :size => 12)
+    other_input_version_uids = stub(Set, :empty? => false, :size => 5)
+    @original_version = OriginalVersion.new(:uid => uid,
+                                            :lifecycle_state => lifecycle_state,
+                                            :attestations => attestations,
+                                            :commit_audit => commit_audit,
+                                            :contribution => contribution,
+                                            :other_input_version_uids => other_input_version_uids,
+                                            :preceding_version_uid => preceding_version_uid)
+    @imported_version = ImportedVersion.new(:item => @original_version,
+                                            :commit_audit => commit_audit,
+                                            :contribution => contribution)
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/change_control/version_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/change_control/version_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/change_control/version_spec.rb	(revision 369)
@@ -0,0 +1,72 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+require File.dirname(__FILE__) + '/shared_examples_spec'
+include OpenEHR::RM::Common::ChangeControl
+include OpenEHR::RM::Common::Generic
+include OpenEHR::RM::DataTypes::Text
+
+describe Version do
+  it_should_behave_like 'change_control'
+
+  it 'should be an instance of Version' do
+    @version.should be_an_instance_of Version
+  end
+
+  it 'uid value should be ABCD::EFG::1' do
+    @version.uid.value.should == 'ABCD::EFG::2'
+  end
+
+  it 'commit_audit.committer.should be UNKNOWN' do
+    @version.commit_audit.committer.should == 'UNKNOWN'
+  end
+
+  it 'lifecycle_state should be 532' do
+    @version.lifecycle_state.defining_code.code_string.should == '532'
+  end
+
+  it 'contribution namespece should be local' do
+    @version.contribution.namespace.should == 'local'
+  end
+
+  it 'contribution type should be CONTRIBUTION' do
+    contribution = @version.contribution
+    contribution.type = 'PARTY'
+    lambda {
+      @version.contribution = contribution
+    }.should raise_error ArgumentError
+  end
+
+  it 'signature should be 4760271533c2866579dde347ad28dd79e4aad933' do
+    @version.signature.should == '4760271533c2866579dde347ad28dd79e4aad933'
+  end
+
+  it 'should not be a branch' do
+    @version.is_branch?.should_not be true
+  end
+
+  it 'should be a branch' do
+    @version.uid.value = 'ABCD::EFG::1.2.3'
+    @version.is_branch?.should be true
+  end
+
+  it 'data should be data' do
+    @version.data.should == 'data'
+  end
+
+  it 'owner_id value should be ABCD::EFG::2' do
+    @version.owner_id.value.should == 'ABCD::EFG::2'
+  end
+
+  it 'canonical form is not well determined' do
+    lambda {
+      @version.canonical_form
+    }.should raise_error NotImplementedError
+  end
+
+  it 'should raise ArgumentError when preceding version id exists and uid version tree is first' do
+    @version.uid.value = 'ABC::DEF::1'
+    preceding_version_uid = ObjectVersionID.new(:value => 'GHI::JKL::2')
+    lambda {
+      @version.preceding_version_uid = preceding_version_uid
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/change_control/versioned_object_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/change_control/versioned_object_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/change_control/versioned_object_spec.rb	(revision 369)
@@ -0,0 +1,284 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+require File.dirname(__FILE__) + '/shared_examples_spec'
+include OpenEHR::RM::Common::ChangeControl
+include OpenEHR::RM::Common::Generic
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+
+describe VersionedObject do
+  before(:each) do
+    uid1 = ObjectVersionID.new(:value => 'ABC::DEF::1')
+    defining_code1 = stub(CodePhrase, :code_string => '532')
+    lifecycle_state1 = stub(DvCodedText, :defining_code => defining_code1)
+    time_committed1 = DvDateTime.new(:value => '2008-11-12T18:24:32')
+    audit_details1 = stub(AuditDetails, :time_committed => time_committed1)
+    version1 = stub(Version, :commit_audit => audit_details1,
+                             :lifecycle_state => lifecycle_state1,
+                             :uid => uid1)
+    uid2 = ObjectVersionID.new(:value => 'GHI::JKL::2')
+    defining_code2 = stub(CodePhrase, :code_string => '553')
+    lifecycle_state2 = stub(DvCodedText, :defining_code => defining_code2)
+    time_committed2 = DvDateTime.new(:value => '2008-12-12T19:32:14')
+    audit_details2 = stub(AuditDetails, :time_committed => time_committed2)
+    attestation = stub(Attestation)
+    attestations = Array.new([attestation])
+    contribution = stub(ObjectRef, :empty? => false, :type => 'CONTRIBUTION')
+    version2 = OriginalVersion.new(:commit_audit => audit_details2,
+                                   :lifecycle_state => lifecycle_state2,
+                                   :preceding_version_uid => uid1,
+                                   :uid => uid2,
+                                   :contribution => contribution,
+                                   :attestations => attestations)
+    uid3 = ObjectVersionID.new(:value => 'MNO::PQR::3')
+    defining_code3 = stub(CodePhrase, :code_string => '523')
+    lifecycle_state3 = stub(DvCodedText, :defining_code => defining_code3)
+    time_committed3 = DvDateTime.new(:value => '2009-07-15T09:24:26')
+    audit_details3 = stub(AuditDetails, :time_committed => time_committed3)
+    version3 = stub(Version, :commit_audit => audit_details3,
+                             :lifecycle_state => lifecycle_state3,
+                             :uid => uid3)
+    uid = HierObjectID.new(:value => 'STU::VWX::5')
+    owner_id = stub(ObjectRef, :namespace => 'test')
+    time_created = DvDateTime.new(:value => '2009-11-09T09:53:22')
+    object_id = stub(ObjectID, :value => 'unique')
+    all_versions = [version1, version2, version3]
+    @versioned_object = VersionedObject.new(:uid => uid,
+                                            :owner_id => owner_id,
+                                            :time_created => time_created,
+                                            :all_versions => all_versions)
+  end
+
+  it 'should be an instance of VersionedObject' do
+    @versioned_object.should be_an_instance_of VersionedObject
+  end
+
+  it 'uid value should be STU::VWX::5' do
+    @versioned_object.uid.value.should == 'STU::VWX::5'
+  end
+
+  it 'owner_id namespace should be test' do
+    @versioned_object.owner_id.namespace.should == 'test'
+  end
+
+  it 'all_versions.size should be 3' do
+    @versioned_object.all_versions.size.should == 3
+  end
+
+  it 'version_count should be 3' do
+    @versioned_object.version_count.should == 3
+  end
+
+  it 'time_created should equal 2009-11-09T09:53:22' do
+    @versioned_object.time_created.value.should == '2009-11-09T09:53:22'
+  end
+
+  it 'all_version_ids should return all ids of versions' do
+    ids = @versioned_object.all_version_ids
+    ids.each do |id|
+      %w(ABC::DEF::1 GHI::JKL::2 MNO::PQR::3).should include id.value
+    end
+  end
+
+  it 'should have version id ABC::DEF::1' do
+    object_version_id = ObjectVersionID.new(:value => 'ABC::DEF::1')
+    @versioned_object.has_version_id?(object_version_id).should be_true
+  end
+
+  it 'should not have version id BCD::EFG::12' do
+    object_version_id = ObjectVersionID.new(:value => 'BCD::EFG::12')
+    @versioned_object.has_version_id?(object_version_id).should be_false
+  end
+
+  it 'ABC::DEF::1 should not be original version' do
+    object_version_id = ObjectVersionID.new(:value => 'ABC::DEF::1')
+    @versioned_object.is_original_version?(object_version_id).should be_false
+  end
+
+  it 'GHI::JKL::2 should be original version' do
+    object_version_id = ObjectVersionID.new(:value => 'GHI::JKL::2')
+    @versioned_object.is_original_version?(object_version_id).should be_true
+  end
+
+  it 'should have 2009-07-15T09:24:26 committed version' do
+    exist_time = DvDateTime.new(:value => '2009-07-15T09:24:26')
+    @versioned_object.has_version_at_time?(exist_time).should be_true
+  end
+
+  it 'should retrun version3 with id MNO::PQR::3' do
+    uid = ObjectVersionID.new(:value => 'MNO::PQR::3')
+    @versioned_object.version_with_id(uid).commit_audit.time_committed.
+      should == DvDateTime.new(:value => '2009-07-15T09:24:26')
+  end
+
+  it 'should return version2 with 2008-12-12T19:32:14' do
+    exist_date = DvDateTime.new(:value => '2008-12-12T19:32:14')
+    @versioned_object.version_at_time(exist_date).lifecycle_state.
+      defining_code.code_string.should == '553'
+  end
+
+  it 'latest_version should return version3' do
+    @versioned_object.latest_version.uid.value.should == 'MNO::PQR::3'
+  end
+
+  it 'latest_trunk_version should return ABC::DEF::1' do
+    @versioned_object.latest_trunk_version.uid.value.should ==
+      'ABC::DEF::1'
+  end
+
+  it 'trunk_lifecycle_state should return 532' do
+    @versioned_object.trunk_lifecycle_state.defining_code.
+      code_string.should == '532'
+  end
+
+  it 'revision_history items are 3' do
+    @versioned_object.revision_history.items.size.should == 3
+  end
+
+  it 'should be able to commit original version' do
+    contribution = stub(ObjectRef, :empty? => false, :type => 'CONTRIBUTION')
+    uid = ObjectVersionID.new(:value => 'EFG::HIJ::7')
+    preceding_version_uid = ObjectVersionID.new(:value => 'ABC::DEF::1')
+    audit = stub(AuditDetails)
+    defining_code = stub(CodePhrase, :code_string => '523')
+    lifecycle_state = stub(DvCodedText, :defining_code => defining_code)
+    attestations = stub(Array, :empty? => false)
+    @versioned_object.
+      commit_original_version(:contribution => contribution,
+                              :uid => uid,
+                              :preceding_version_uid => preceding_version_uid,
+                              :commit_audit => audit,
+                              :lifecycle_state => lifecycle_state,
+                              :data => 'data',
+                              :attestations => attestations,
+                              :signature => 'A41bdad')
+    @versioned_object.all_versions.size.should == 4
+  end
+
+  it 'should raise ArgumentError with invalid preceeding version' do
+    contribution = stub(ObjectRef, :empty? => false, :type => 'CONTRIBUTION')
+    uid = ObjectVersionID.new(:value => 'EFG::HIJ::7')
+    preceding_version_uid = ObjectVersionID.new(:value => 'BCD::EFG::8')
+    audit = stub(AuditDetails)
+    defining_code = stub(CodePhrase, :code_string => '523')
+    lifecycle_state = stub(DvCodedText, :defining_code => defining_code)
+    attestations = stub(Array, :empty? => false)
+    lambda {
+      @versioned_object.
+      commit_original_version(:contribution => contribution,
+                              :uid => uid,
+                              :preceding_version_uid => preceding_version_uid,
+                              :commit_audit => audit,
+                              :lifecycle_state => lifecycle_state,
+                              :data => 'data',
+                              :attestations => attestations,
+                              :signature => 'A41bdad')
+    }.should raise_error ArgumentError
+  end
+
+  it 'should be able to commit original merged version' do
+    contribution = stub(ObjectRef, :empty? => false, :type => 'CONTRIBUTION')
+    uid = ObjectVersionID.new(:value => 'KLM::NOP::9')
+    preceding_version_uid = ObjectVersionID.new(:value => 'ABC::DEF::1')
+    time_committed = DvDateTime.new(:value => '2009-11-09T23:42:18')
+    audit = stub(AuditDetails, :time_committed => time_committed)
+    defining_code = stub(CodePhrase, :code_string => '523')
+    lifecycle_state = stub(DvCodedText, :defining_code => defining_code)
+    attestations = stub(Array, :empty? => false)
+    @versioned_object.
+      commit_original_merged_version(:contribution => contribution,
+                              :uid => uid,
+                              :preceding_version_uid => preceding_version_uid,
+                              :commit_audit => audit,
+                              :lifecycle_state => lifecycle_state,
+                              :data => 'merged data',
+                              :attestations => attestations,
+                              :signature => 'dc3dbdad')
+    @versioned_object.latest_version.data.should == 'merged data'
+  end
+
+  it 'should be able to commit imported_version' do
+    contribution = stub(ObjectRef, :empty? => false, :type => 'CONTRIBUTION')
+    time_committed = DvDateTime.new(:value => '2009-11-09T23:42:18')
+    audit = stub(AuditDetails, :time_committed => time_committed)
+    uid = ObjectVersionID.new(:value => 'QRS::TUV::10')
+    preceding_version_uid = ObjectVersionID.new(:value => 'ABC::DEF::1')
+    defining_code = stub(CodePhrase, :code_string => '523')
+    lifecycle_state = stub(DvCodedText, :defining_code => defining_code)
+    attestations = stub(Array, :empty? => false)
+    original_version = OriginalVersion.new(:uid => uid,
+                            :contribution => contribution,
+                            :commit_audit => audit,
+                            :preceding_version_uid => preceding_version_uid,
+                            :data => 'original data',
+                            :lifecycle_state => lifecycle_state,
+                            :attestations => attestations)
+    @versioned_object.commit_imported_version(:contribution => contribution,
+                                              :commit_audit => audit,
+                                              :item => original_version)
+    @versioned_object.latest_version.commit_audit.time_committed.value.
+      should == '2009-11-09T23:42:18'
+  end
+
+  it 'should be able to commit attestation' do
+    attestation = stub(Attestation)
+    uid = ObjectVersionID.new(:value => 'GHI::JKL::2')
+    @versioned_object.commit_attestation(:attestation => attestation,
+                                         :uid => uid,
+                                         :signature => 'CDAEbad')
+    @versioned_object.version_with_id(uid).signature.
+      should == 'CDAEbad'
+  end
+
+  it 'should raise ArgumentError when time_created is nil' do
+    lambda {
+      @versioned_object.time_created = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError when all_versions are nil' do
+    lambda {
+      @versioned_object.all_versions = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError when is_original_version argument is nil' do
+    lambda {
+      @versioned_object.is_original_version?(nil)
+    }.should raise_error ArgumentError
+  end
+
+  it 'should not has time data' do
+    unexisted_time = DvDateTime.new(:value => '2009-11-10T00:43:59')
+    lambda {
+      @versioned_object.version_at_time(unexisted_time)
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with nil argument to commit_attestations' do
+    lambda {
+      @versioned_object.commit_attestation(:attestation => nil)
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with not orinigal version id' do
+    uid = ObjectVersionID.new(:value => 'ABC::DEF::1')
+    attestation = stub(Attestation)
+    lambda {
+      @versioned_object.commit_attestation(:attestation => attestation,
+                                           :uid => uid,
+                                           :signature => 'DEADBEAFE81')
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with nil argument to version with id' do
+    lambda {
+      @versioned_object.version_with_id(nil)
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with unexsited version with id ' do
+    uid = ObjectVersionID.new(:value => 'CBA::FED::1')
+    lambda {
+      @versioned_object.version_with_id(uid)
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/directory/folder_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/directory/folder_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/directory/folder_spec.rb	(revision 369)
@@ -0,0 +1,26 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::Directory
+include OpenEHR::RM::DataTypes::Text
+
+describe Folder do
+  before(:each) do
+    items = stub(Array, :size => 3)
+    folders = stub(Array, :size => 5, :empty? => false)
+    @folder = Folder.new(:archetype_node_id => 'at0001',
+                         :name => DvText.new(:value => 'test'),
+                         :items => items,
+                         :folders => folders)
+  end
+
+  it 'should an instance of Folder' do
+    @folder.should be_an_instance_of Folder
+  end
+
+  it 'items size should be 3' do
+    @folder.items.size.should == 3
+  end
+
+  it 'folders size should be 5' do
+    @folder.folders.size.should == 5
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/generic/attestation_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/generic/attestation_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/generic/attestation_spec.rb	(revision 369)
@@ -0,0 +1,62 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::Generic
+include OpenEHR::RM::Support::Identification
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+include OpenEHR::RM::DataTypes::Encapsulated
+
+describe Attestation do
+  before(:each) do
+    committer = stub(PartyProxy, :namespace => 'UNKNOWN')
+    change_type = stub(DvCodedText, :value =>'creation')
+    time = stub(DvDateTime, :value => '2009-10-03T16:24:19.0Z')
+    reason = DvText.new(:value => 'signed')
+    items = stub(Set, :empty? => false, :size => 3)
+    attested_view = stub(DvMultimedia, :size => 300)
+    @attestation = Attestation.new(:committer => committer,
+                                   :change_type => change_type,
+                                   :time_committed => time,
+                                   :system_id => 'test',
+                                   :reason => reason,
+                                   :proof => 'DEADBEEFBABE',
+                                   :is_pending => true,
+                                   :attested_view => attested_view,
+                                   :items => items)
+  end
+
+  it 'should be an instance of Attestation' do
+    @attestation.should be_an_instance_of Attestation
+  end
+
+  it 'reason should be signed' do
+    @attestation.reason.value.should == 'signed'
+  end
+
+  it 'proof should DEADBEEFBABE' do
+    @attestation.proof.should == 'DEADBEEFBABE'
+  end
+
+  it 'attested view size should be 300' do
+    @attestation.attested_view.size.should == 300
+  end
+
+  it 'is_pending? should true' do
+    @attestation.is_pending?.should be_true
+  end
+
+  it 'items size should be 30' do
+    @attestation.items.size.should == 3
+  end
+
+  it 'should raise ArgumentError when items are empty' do
+    lambda {
+      @attestation.items = Set.new
+    }.should raise_error ArgumentError
+  end
+
+  it 'should not raise ArgumentErro when items are nil' do
+    lambda {
+      @attestation.items = nil
+    }.should_not raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/generic/audit_details_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/generic/audit_details_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/generic/audit_details_spec.rb	(revision 369)
@@ -0,0 +1,51 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::Generic
+include OpenEHR::RM::Support::Identification
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+
+describe AuditDetails do
+  before(:each) do
+    committer = stub(PartyProxy, :namespace => 'UNKNOWN')
+    change_type = stub(DvCodedText, :value =>'creation')
+    time = stub(DvDateTime, :value => '2009-10-03T16:24:19.0Z')
+    desc = DvText.new(:value => 'test environment')
+    @audit_details = AuditDetails.new(:system_id => 'MAGI',
+                                      :committer => committer,
+                                      :time_committed => time,
+                                      :change_type => change_type,
+                                      :description => desc)
+  end
+
+  it 'should be an instance of AuditDetails' do
+    @audit_details.should be_an_instance_of AuditDetails
+  end
+
+  it 'system_id should be MAGI' do
+    @audit_details.system_id.should == 'MAGI'
+  end
+
+  it 'committer namespece should be UNKNOWN' do
+    @audit_details.committer.namespace.should == 'UNKNOWN'
+  end
+
+  it 'change_type.value should be creation' do
+    @audit_details.change_type.value.should == 'creation'
+  end
+
+  it 'description should be test environment' do
+    @audit_details.description.value.should == 'test environment'
+  end
+
+  it 'should raise ArgumentError when system_id was assigned nil' do
+    lambda {
+      @audit_details.system_id = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError when time_commited is nil' do
+    lambda {
+      @audit_details.time_committed = nil
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/generic/participation_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/generic/participation_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/generic/participation_spec.rb	(revision 369)
@@ -0,0 +1,36 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::Generic
+
+describe Participation do
+  before(:each) do
+    performer = stub(PartyProxy, :name => 'GEHIRN')
+    function = stub(DvText, :value => 'committer')
+    mode = stub(DvCodedText, :value => 'present')
+    lower = stub(DvDateTime, :value => '2009-10-03T20:33:05')
+    time = stub(DvInterval, :lower => lower)
+    @participation = Participation.new(:performer => performer,
+                                       :function => function,
+                                       :mode => mode,
+                                       :time => time)
+  end
+
+  it 'should be an instance of Participation' do
+    @participation.should be_an_instance_of Participation
+  end
+
+  it 'should assign performer properly' do
+    @participation.performer.name.should == 'GEHIRN'
+  end
+
+  it 'should assign function properly' do
+    @participation.function.value.should == 'committer'
+  end
+
+  it 'should assign mode properly' do
+    @participation.mode.value.should == 'present'
+  end
+
+  it 'should assign time properly' do
+    @participation.time.lower.value.should == '2009-10-03T20:33:05'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/generic/party_identified_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/generic/party_identified_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/generic/party_identified_spec.rb	(revision 369)
@@ -0,0 +1,64 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::Generic
+
+describe PartyIdentified do
+  before(:each) do
+    external_ref = stub(PartyRef, :namespace => 'unknown')
+    identifiers = stub(Array, :size => 5, :empty? => false)
+    @party_identified = PartyIdentified.new(:name => 'NERV',
+                                            :external_ref => external_ref,
+                                            :identifier => identifiers)
+  end
+
+  it 'should be an instance of PartyIdentified' do
+    @party_identified.should be_an_instance_of PartyIdentified
+  end
+
+  it 'should assign name properly' do
+    @party_identified.name.should == 'NERV'
+  end
+
+  it 'should assign external_ref properly' do
+    @party_identified.external_ref.namespace.should == 'unknown'
+  end
+
+  it 'should assign identifier properly' do
+    @party_identified.identifier.size.should be_equal 5
+  end
+
+  it 'should raise ArgumentError with all nil' do
+    lambda {
+      PartyIdentified.new
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with nil name when ex_r and id nil' do
+    @party_identified.identifier = nil
+    @party_identified.external_ref = nil
+    lambda {
+      @party_identified.name = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with nil external_ref when name and id nil' do
+    @party_identified.name = nil
+    @party_identified.identifier = nil
+    lambda {
+      @party_identified.external_ref = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with nil identifier when name and ex_r nil' do
+    @party_identified.name = nil
+    @party_identified.external_ref = nil
+    lambda {
+      @party_identified.identifier = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with empty identifier' do
+    lambda {
+      @party_identified.identifier = Array.new
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/generic/party_proxy_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/generic/party_proxy_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/generic/party_proxy_spec.rb	(revision 369)
@@ -0,0 +1,18 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::Generic
+include OpenEHR::RM::Support::Identification
+
+describe PartyProxy do
+  before(:each) do
+    external_ref = stub(PartyRef, :namespace => 'NERV')
+    @party_proxy = PartyProxy.new(:external_ref => external_ref)
+  end
+
+  it 'should be an isntance of PartyProxy' do
+    @party_proxy.should be_an_instance_of PartyProxy
+  end
+
+  it 'exnternal_ref.namespace should be NERV' do
+    @party_proxy.external_ref.namespace.should == 'NERV'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/generic/party_related_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/generic/party_related_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/generic/party_related_spec.rb	(revision 369)
@@ -0,0 +1,24 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::Generic
+include OpenEHR::RM::DataTypes::Text
+describe PartyRelated do
+  before(:each) do
+    relationship = stub(DvCodedText, :value => 'self')
+    @party_related = PartyRelated.new(:name => 'TEST',
+                                      :relationship => relationship)
+  end
+
+  it 'should be an instance of PartyRelated' do
+    @party_related.should be_an_instance_of PartyRelated
+  end
+
+  it 'should assign relationship properly' do
+    @party_related.relationship.value.should == 'self'
+  end
+
+  it 'should raise ArgumentError when nil is assigned to relationship' do
+    lambda {
+      @party_related.relationship = nil
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/generic/revision_history_item_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/generic/revision_history_item_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/generic/revision_history_item_spec.rb	(revision 369)
@@ -0,0 +1,43 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::Generic
+include OpenEHR::RM::Support::Identification
+
+describe RevisionHistoryItem do
+  before(:each)do
+    version_id = stub(ObjectVersionID, :object_id => 'RIO')
+    audits = stub(Array, :size => 30, :empty? => false)
+    @revision_history_item =
+      RevisionHistoryItem.new(:version_id => version_id,
+                              :audits => audits)
+  end
+
+  it 'should be an instance of RevisionHistoryItem' do
+    @revision_history_item.should be_an_instance_of RevisionHistoryItem
+  end
+
+  it 's version_id.object_id should be RIO' do
+    @revision_history_item.version_id.object_id.should == 'RIO'
+  end
+
+  it 's audits.size should be 30' do
+    @revision_history_item.audits.size.should be_equal 30
+  end
+
+  it 'should raise ArgumentError when nil is assigned to version id' do
+    lambda {
+      @revision_history_item.version_id = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError when nil is assinged to audits' do
+    lambda {
+      @revision_history_item.audits = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError when empty is assinged to audits' do
+    lambda {
+      @revision_history_item.audits = Array.new
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/generic/revision_history_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/generic/revision_history_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/generic/revision_history_spec.rb	(revision 369)
@@ -0,0 +1,45 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::Generic
+include OpenEHR::RM::Support::Identification
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+
+describe RevisionHistory do
+  before(:each) do
+    version_id = stub(ObjectVersionID, :value => 'ABCD::EFGH::1')
+    committed_time = stub(DvDateTime, :value => '2009-11-02T22:19:34')
+    audit = stub(AuditDetails, :time_committed => committed_time)
+    audits = stub(Array, :first => audit)
+    last_item = stub(RevisionHistoryItem, :version_id => version_id,
+                     :audits => audits)
+    items = stub(Array, :size => 128, :empty? => false, :last => last_item)
+    @revision_history = RevisionHistory.new(:items => items)
+  end
+
+  it 'should be an instance of RevisionHistory' do
+    @revision_history.should be_an_instance_of RevisionHistory
+  end
+
+  it 'items size should return size 128' do
+    @revision_history.items.size.should be_equal 128
+  end
+
+  it 'should return the most recent version string' do
+    @revision_history.most_recent_version.should == 'ABCD::EFGH::1'
+  end
+
+  it 'should return the most recent commited version time string' do
+    @revision_history.most_recent_version_time_committed == '2009-11-02T22:19:34'
+  end
+
+  it 'should raise ArgumentError when item is nil' do
+    lambda {
+      @revision_history.items = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError when item is empty' do
+    lambda {
+      @revision_history.items = Array.new
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/resource/authored_resource_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/resource/authored_resource_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/resource/authored_resource_spec.rb	(revision 369)
@@ -0,0 +1,68 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::Resource
+include OpenEHR::RM::Common::ChangeControl
+include OpenEHR::RM::DataTypes::Text
+
+describe AuthoredResource do
+  before(:each) do
+    original_language = stub(CodePhrase, :code_string => 'ja')
+    translation_language = stub(CodePhrase, :code_string => 'en')
+    translation_details = stub(TranslationDetails,
+                               :language => translation_language)
+    translations = Hash['en', translation_details]
+    description = stub(ResourceDescription, :lifecycle_state => 'initial')
+    revision_history = stub(RevisionHistory, :most_recent_version => '0.0.3')
+    languages_available = Set.new %w(ja en)
+    @authored_resource = AuthoredResource.new(
+                  :original_language => original_language,
+                  :translations => translations,
+                  :description => description,
+                  :revision_history => revision_history)
+  end
+
+  it 'should be an instance of AuthoredResource' do
+    @authored_resource.should be_an_instance_of AuthoredResource
+  end
+
+  it 'original language should be ja' do
+    @authored_resource.original_language.code_string.should == 'ja'
+  end
+
+  it 'translations hash en returns en detail' do
+    @authored_resource.translations['en'].language.code_string.should == 'en'
+  end
+
+  it 'description lifecycle_state should e initial' do
+    @authored_resource.description.lifecycle_state.should == 'initial'
+  end
+
+  it 'language_available should be Set(%(ja en))' do
+    languages_set = Set.new ['ja', 'en']
+    @authored_resource.languages_available.should == languages_set
+  end
+
+  it 'current_revision should be 0.0.3' do
+    @authored_resource.current_revision.should == '0.0.3'
+  end
+
+  it 'should be controlled' do
+    @authored_resource.is_controlled?.should be_true
+  end
+
+  it 'should not be controlled' do
+    @authored_resource.revision_history = nil
+    @authored_resource.is_controlled?.should be_false
+  end
+
+  it 'should raise ArgumentError with empty translations' do
+    lambda {
+      @authored_resource.translations = Array.new
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError when original language is nil' do
+    lambda {
+      @authored_resource.original_language = nil
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/resource/resource_description_item_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/resource/resource_description_item_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/resource/resource_description_item_spec.rb	(revision 369)
@@ -0,0 +1,105 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::Resource
+include OpenEHR::RM::DataTypes::Text
+
+describe ResourceDescriptionItem do
+  before(:each) do
+    language = stub(CodePhrase, :defining_code => 'ja')
+    original_resource_uri = {'jp', 'http://openehr.jp/'}
+    @resource_description_item =
+      ResourceDescriptionItem.new(:language => language,
+                                  :purpose => 'test',
+                                  :keywords => ['openehr'],
+                                  :use => 'development',
+                                  :misuse => 'none',
+                                  :copyright => 'Shinji KOBAYASHI',
+                                  :original_resource_uri => original_resource_uri,
+                                  :other_details => {'charset', 'UTF-8'})
+  end
+
+  it 'should be an instance of ResourceDescriptionItem' do
+    @resource_description_item.should be_an_instance_of ResourceDescriptionItem
+  end
+
+  it 'language should ja' do
+    @resource_description_item.language.defining_code.should == 'ja'
+  end
+
+  it 'purpose should be test' do
+    @resource_description_item.purpose.should == 'test'
+  end
+
+  it 'should raise ArgumentError with nil purpose' do
+    lambda {
+      @resource_description_item.purpose = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with empty purpose' do
+    lambda {
+      @resource_description_item.purpose = ''
+    }.should raise_error ArgumentError
+  end
+
+  it 'keywords should [openehr]' do
+    @resource_description_item.keywords.should == ['openehr']
+  end
+
+  it 'use should be development' do
+    @resource_description_item.use.should == 'development'
+  end
+
+  it 'should raise ArgumentError with use is empty' do
+    lambda {
+      @resource_description_item.use = ''
+    }.should raise_error ArgumentError
+  end
+
+  it 'should not raise ArgumentError with nil use' do
+    lambda {
+      @resource_description_item.use = nil
+    }.should_not raise_error ArgumentError
+  end
+
+  it 'misuse should be none' do
+    @resource_description_item.misuse.should == 'none'
+  end
+
+  it 'should raise ArgumentError with empty misuse' do
+    lambda {
+      @resource_description_item.misuse = ''
+    }.should raise_error ArgumentError
+  end
+
+  it 'should not raise ArgumentError with nil misuse' do
+    lambda {
+      @resource_description_item.misuse = nil
+    }.should_not raise_error ArgumentError
+  end
+
+  it 'copyright should be Shinji KOBAYASHI' do
+    @resource_description_item.copyright.should == 'Shinji KOBAYASHI'
+  end
+
+  it 'should raise error with empty copyright' do
+    lambda {
+      @resource_description_item.copyright = ''
+    }.should raise_error ArgumentError
+  end
+
+  it 'should not raise ArgumentError with nil copyright' do
+    lambda {
+      @resource_description_item.copyright = nil
+    }.should_not raise_error ArgumentError
+  end
+
+  it 'original_resource_uri should {jp, http://openehr.jp/}' do
+    @resource_description_item.original_resource_uri.should ==
+      {'jp', 'http://openehr.jp/'}
+  end
+
+  it 'other_details should {charset, UTF-8}' do
+    @resource_description_item.other_details.should ==
+      {'charset', 'UTF-8'}
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/resource/resource_description_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/resource/resource_description_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/resource/resource_description_spec.rb	(revision 369)
@@ -0,0 +1,74 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::Resource
+
+describe ResourceDescription do
+  before(:each) do
+    original_author = {'Shinji KOBAYASHI', 'Ehime University'}
+    other_contributors = ['Akimichi TATSUKAWA']
+    resource_description_item =
+      stub(ResourceDescriptionItem, :purpose => 'test')
+    details = {'case', resource_description_item}
+    other_details = {'charset', 'UTF-8'}
+    parent_resource = stub(AuthoredResource, :current_revision => '0.0.3')
+    @resource_description =
+      ResourceDescription.new(:original_author => original_author,
+                              :other_contributors => other_contributors,
+                              :lifecycle_state => 'initial',
+                              :details => details,
+                              :other_details => other_details,
+                              :resource_package_uri => 'http://openehr.jp/',
+                              :parent_resource => parent_resource)
+  end
+
+  it 'should be an instance of ResourceDescription' do
+    @resource_description.should be_an_instance_of ResourceDescription
+  end
+
+  it 'original author should be Shinji KOBAYASHI' do
+    @resource_description.original_author.keys[0].should ==
+      'Shinji KOBAYASHI'
+  end
+
+  it 'other_contributors should be Akimichi TATSUKAWA' do
+    @resource_description.other_contributors[0].should == 
+      'Akimichi TATSUKAWA'
+  end
+
+  it 'lifecycle_state should be initial' do
+    @resource_description.lifecycle_state.should == 'initial'
+  end
+
+  it 'details key should be case' do
+    @resource_description.details.keys[0].should == 'case'
+  end
+
+  it 'other_details value should be charset, UTF-8' do
+    @resource_description.other_details.should == {'charset', 'UTF-8'}
+  end
+
+  it 'resource package uri should be http://openehr.jp/' do
+    @resource_description.resource_package_uri.should == 'http://openehr.jp/'
+  end
+
+  it 'parent_resource current_revision should be 0.0.3' do
+    @resource_description.parent_resource.current_revision.should == '0.0.3'
+  end
+
+  it 'should raise ArgumentError with nil original author' do
+    lambda {
+      @resource_description.original_author = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with nil lifecycle_state' do
+    lambda {
+      @resource_description.lifecycle_state = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with nil details' do
+    lambda {
+      @resource_description.details = {}
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/common/resource/translation_details_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/common/resource/translation_details_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/common/resource/translation_details_spec.rb	(revision 369)
@@ -0,0 +1,35 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Common::Resource
+include OpenEHR::RM::DataTypes::Text
+
+describe TranslationDetails do
+  before(:each) do
+    language = stub(CodePhrase, :code_string => 'ja')
+    author = Hash['Shinji KOBAYASHI', 'Ehime University']
+    @translation_details =
+      TranslationDetails.new(:language => language,
+                             :author => author,
+                             :accreditation => 'skoba@moss.gr.jp',
+                             :other_details => {'ja', 'Japanese'})
+  end
+
+  it 'should be an instance of TranslationDetails' do
+    @translation_details.should be_an_instance_of TranslationDetails
+  end
+
+  it 'language should be ja' do
+    @translation_details.language.code_string.should == 'ja'
+  end
+
+  it 'authour should be Shinji KOBAYASHI' do
+    @translation_details.author.keys[0].should == 'Shinji KOBAYASHI'
+  end
+
+  it 'accreditation should be skoba@moss.gr.jp' do
+    @translation_details.accreditation.should == 'skoba@moss.gr.jp'
+  end
+
+  it 'other_details should ja, Japanese' do
+    @translation_details.other_details.values[0].should == 'Japanese'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/composition/composition_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/composition/composition_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/composition/composition_spec.rb	(revision 369)
@@ -0,0 +1,92 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::Composition
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::Support::Identification
+include OpenEHR::RM::Common::Generic
+
+describe Composition do
+  before(:each) do
+    name = DvText.new(:value => 'composition test')
+    language = stub(CodePhrase, :code_string => 'ja')
+    category = stub(DvCodedText, :value => 'event')
+    territory = stub(CodePhrase, :code_string => 'jpn')
+    external_ref = stub(PartyRef, :type =>  'ROLE')
+    composer = stub(PartyProxy, :external_ref => external_ref)
+    content = stub(Array, :size => 3)
+    context = stub(EventContext, :location => 'lab1')
+    @composition = Composition.new(:archetype_node_id => 'at0001',
+                                   :name => name,
+                                   :language => language,
+                                   :category => category,
+                                   :territory => territory,
+                                   :composer => composer,
+                                   :content => content,
+                                   :context => context)
+  end
+
+  it 'should be an instance of Composition' do
+    @composition.should be_an_instance_of Composition
+  end
+
+  it 'language should be assigned properly' do
+    @composition.language.code_string.should == 'ja'
+  end
+
+  it 'should validate language with Termonology service'
+
+  it 'should raise ArgumentError with nil language' do
+    lambda {
+      @composition.language = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'category should be assigned properly' do
+    @composition.category.value.should == 'event'
+  end
+
+  it 'should validate category with Terminology service'
+
+  it 'should raise ArgumentError with nil category' do
+    lambda {
+      @composition.category = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'territory should be assined properly' do
+    @composition.territory.code_string.should == 'jpn'
+  end
+
+  it 'should raise ArgumentError with nil territory' do
+    lambda {
+      @composition.territory = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'composer should be assigned properly' do
+    @composition.composer.external_ref.type.should == 'ROLE'
+  end
+
+  it 'should raise ArgumentError with nil comosser' do
+    lambda {
+      @composition.composer = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'is_persistent? should be false when category is not persistent' do
+    @composition.is_persistent?.should be_false
+  end
+
+  it 'is_persistent? should be true when category is persistent' do
+    category = stub(DvCodedText, :value => 'persistent')
+    @composition.category = category
+    @composition.is_persistent?.should be_true
+  end
+
+  it 'content should be assigned properly' do
+    @composition.content.size.should == 3
+  end
+
+  it 'context should be assigned properly' do
+    @composition.context.location.should == 'lab1'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/composition/content/content_item_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/composition/content/content_item_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/composition/content/content_item_spec.rb	(revision 369)
@@ -0,0 +1,14 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Composition::Content
+include OpenEHR::RM::DataTypes::Text
+
+describe ContentItem do
+  before(:each) do
+    @content_item = ContentItem.new(:name => DvText.new(:value => 'item'),
+                                    :archetype_node_id => 'at0001')
+  end
+
+  it 'should be an instance of ContentItem' do
+    @content_item.should be_an_instance_of ContentItem
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/action_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/action_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/action_spec.rb	(revision 369)
@@ -0,0 +1,65 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+require File.dirname(__FILE__) + '/shared_examples_spec'
+include OpenEHR::RM::Composition::Content::Entry
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataStructures::ItemStructure
+
+describe Action do
+  it_should_behave_like 'entry'
+
+  before(:each) do
+    time = DvDateTime.new(:value => '2009-11-18T20:17:18')
+    description = stub(ItemStructure, :archetype_node_id => 'at0002')
+    current_state = stub(DvCodedText, :value => 'planned')
+    ism_transition = stub(IsmTransition, :current_state => current_state)
+    instruction_details = stub(InstructionDetails, :activity_id => 'at0003')
+    @action= Action.new(:archetype_node_id => 'at0001',
+                        :name => @name,
+                        :language => @language,
+                        :encoding => @encoding,
+                        :subject => @subject,
+                        :time => time,
+                        :description => description,
+                        :ism_transition => ism_transition,
+                        :instruction_details => instruction_details)
+  end
+
+  it 'should be an instance of Action' do
+    @action.should be_an_instance_of Action
+  end
+
+  it 'time should be assigned properly' do
+    @action.time.value.should == '2009-11-18T20:17:18'
+  end
+
+  it 'should raise ArgumentError with nil assigned to time' do
+    lambda {
+      @action.time = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'description should assigned properly' do
+    @action.description.archetype_node_id.should == 'at0002'
+  end
+
+  it 'should raise ArgumentError with nil description' do
+    lambda {
+      @action.description = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'ism_transition should be assigned properly' do
+    @action.ism_transition.current_state.value.should == 'planned'
+  end
+
+  it 'should raise ArgumentError with nil ism_transition' do
+    lambda {
+      @action.ism_transition = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'instruction_details should be assigned properly' do
+    @action.instruction_details.activity_id.should == 'at0003'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/activity_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/activity_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/activity_spec.rb	(revision 369)
@@ -0,0 +1,59 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+require File.dirname(__FILE__) + '/shared_examples_spec'
+include OpenEHR::RM::DataStructures::ItemStructure
+include OpenEHR::RM::Composition::Content::Entry
+include OpenEHR::RM::DataTypes::Encapsulated
+
+describe Activity do
+  it_should_behave_like 'entry'
+
+  before(:each) do
+    description = stub(ItemStructure, :archetype_node_id => 'at0002')
+    timing = stub(DvParsable, :value => '2009-11-18T19:35:11')
+    @activity = Activity.new(:archetype_node_id => 'at0001',
+                             :name => @name,
+                             :description => description,
+                             :timing => timing,
+                             :action_archetype_id => '/at.+/')
+  end
+
+  it 'should be an instance of Activity' do
+    @activity.should be_an_instance_of Activity
+  end
+
+  it 'description should be assigned properly' do
+    @activity.description.archetype_node_id.should == 'at0002'
+  end
+
+  it 'should raise ArgumentError with nil description' do
+    lambda {
+      @activity.description = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'timing should be assigned properly' do
+    @activity.timing.value.should == '2009-11-18T19:35:11'
+  end
+
+  it 'should raise ArgumentError with nil timing' do
+    lambda {
+      @activity.timing = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'action_archetype_id should be assigned properly' do
+    @activity.action_archetype_id.should == '/at.+/'
+  end
+
+  it 'should raise ArgumentError with nil action_archetype_id' do
+    lambda {
+      @activity.action_archetype_id = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with empty action_archetype_id' do
+    lambda {
+      @activity.action_archetype_id = ''
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/admin_entry_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/admin_entry_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/admin_entry_spec.rb	(revision 369)
@@ -0,0 +1,34 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+require File.dirname(__FILE__) + '/shared_examples_spec'
+include OpenEHR::RM::Composition::Content::Entry
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::Common::Generic
+include OpenEHR::RM::DataStructures::ItemStructure
+
+describe AdminEntry do
+  it_should_behave_like 'entry'
+
+  before(:each) do
+    data = stub(ItemStructure, :archetype_node_id => 'at0002')
+    @admin_entry = AdminEntry.new(:archetype_node_id => 'at0001',
+                                  :name => DvText.new(:value => 'admin entry'),
+                                  :language => @language,
+                                  :encoding => @encoding,
+                                  :subject => @subject,
+                                  :data => data)
+  end
+
+  it 'should be an instance of AdminEntry' do
+    @admin_entry.should be_an_instance_of AdminEntry
+  end
+
+  it 'data should be assigned properly' do
+    @admin_entry.data.archetype_node_id.should == 'at0002'
+  end
+
+  it 'should raise ArgumentError when nil assigned to data' do
+    lambda {
+      @admin_entry.data = nil
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/care_entry_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/care_entry_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/care_entry_spec.rb	(revision 369)
@@ -0,0 +1,35 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+require File.dirname(__FILE__) + '/shared_examples_spec'
+include OpenEHR::RM::Composition::Content::Entry
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataStructures::ItemStructure
+include OpenEHR::RM::Support::Identification
+
+describe CareEntry do
+  it_should_behave_like 'entry'
+
+  before(:each) do
+    protocol = stub(ItemStructure, :archetype_node_id => 'at0003')
+    guideline_id = stub(ObjectRef, :type => 'care guideline')
+    @care_entry = CareEntry.new(:archetype_node_id => 'at0001',
+                                :name => DvText.new(:value => 'care entry'),
+                                :language => @language,
+                                :encoding => @encoding,
+                                :subject => @subject,
+                                :protocol => protocol,
+                                :guideline_id => guideline_id)
+  end
+
+  it 'should be an instance of CareEntry' do
+    @care_entry.should be_an_instance_of CareEntry
+  end
+
+  it 'protocol should be assigned properly' do
+    @care_entry.protocol.archetype_node_id.should == 'at0003'
+  end
+
+  it 'guideline should be assined properly' do
+    @care_entry.guideline_id.type.should == 'care guideline'
+  end
+end
+
Index: ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/entry_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/entry_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/entry_spec.rb	(revision 369)
@@ -0,0 +1,85 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+require File.dirname(__FILE__) + '/shared_examples_spec'
+include OpenEHR::RM::Composition::Content::Entry
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::Common::Generic
+
+describe Entry do
+  it_should_behave_like 'entry'
+
+  before(:each) do
+    external_ref = stub(PartyRef, :type => 'entry')
+    subject = PartyProxy.new(:external_ref => external_ref)
+    provider_external_ref = stub(PartyRef, :type => 'provider')
+    provider = PartyProxy.new(:external_ref => provider_external_ref)
+    other_participations = stub(Array, :size => 3, :empty? => false)
+    workflow_id = stub(ObjectRef, :type => 'workflow')
+    @entry = Entry.new(:archetype_node_id => 'at0001',
+                       :name => DvText.new(:value => 'entry test'),
+                       :language => @language,
+                       :encoding => @encoding,
+                       :subject => subject,
+                       :provider => provider,
+                       :other_participations => other_participations,
+                       :workflow_id => workflow_id)
+  end
+
+  it 'should be an instance of Entry' do
+    @entry.should be_an_instance_of Entry
+  end
+
+  it 'language should be assigned properly' do
+    @entry.language.code_string.should == 'ja'
+  end
+
+  it 'should raise ArgumentError when nil assign to language' do
+    lambda {
+      @entry.language = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with invalid language code'
+
+  it 'encoding should be assigned properly' do
+    @entry.encoding.code_string.should == 'UTF-8'
+  end
+
+  it 'should raise ArgumentError when nil assign to encoding' do
+    lambda {
+      @entry.encoding = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with invalid encoding'
+
+  it 'subject should be assigned properly' do
+    @entry.subject.external_ref.type.should == 'entry'
+  end
+
+  it 'should raise ArgumentError when nil assigned to subject' do
+    lambda {
+      @entry.subject = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'provider should be assigned properly' do
+    @entry.provider.external_ref.type.should == 'provider'
+  end
+
+  it 'other_participations should be assigned properly' do
+    @entry.other_participations.size.should be_equal 3
+  end
+
+  it 'workflow_id should assigned properly' do
+    @entry.workflow_id.type.should == 'workflow'
+  end
+
+  it 'subject_is_self? should be determined by subject class' do
+    @entry.subject_is_self?.should be_false
+  end
+
+  it 'subject_is_self? should be true when subject is instance of PartySelf' do
+    @entry.subject = PartySelf.new
+    @entry.subject_is_self?.should be_true
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/evaluation_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/evaluation_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/evaluation_spec.rb	(revision 369)
@@ -0,0 +1,32 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+require File.dirname(__FILE__) + '/shared_examples_spec'
+include OpenEHR::RM::DataStructures::ItemStructure
+include OpenEHR::RM::Composition::Content::Entry
+
+describe Evaluation do
+  it_should_behave_like 'entry'
+
+  before(:each) do
+    data = stub(ItemStructure, :archetype_node_id => 'at0002')
+    @evaluation = Evaluation.new(:archetype_node_id => 'at0001',
+                                 :name => @name,
+                                 :language => @language,
+                                 :encoding => @encoding,
+                                 :subject => @subject,
+                                 :data => data)
+  end
+
+  it 'should be an instance of Evaluation' do
+    @evaluation.should be_an_instance_of Evaluation
+  end
+
+  it 'data should be properly assigned' do
+    @evaluation.data.archetype_node_id.should == 'at0002'
+  end
+
+  it 'should raise ArgumentError when nil assigned to data' do
+    lambda {
+      @evaluation.data = nil
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/instruction_details_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/instruction_details_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/instruction_details_spec.rb	(revision 369)
@@ -0,0 +1,51 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+include OpenEHR::RM::DataStructures::ItemStructure
+include OpenEHR::RM::Composition::Content::Entry
+include OpenEHR::RM::Support::Identification
+
+describe InstructionDetails do
+  before(:each) do
+    instruction_id = stub(LocatableRef, :path => '[instruction]/[test]')
+    wf_details = stub(ItemStructure, :archetype_node_id => 'at0004')
+    @instruction_details =
+      InstructionDetails.new(:instruction_id => instruction_id,
+                             :activity_id => 'at0003',
+                             :wf_details => wf_details)
+  end
+
+  it 'should be an instance of InstructionDetails' do
+    @instruction_details.should be_an_instance_of InstructionDetails
+  end
+
+  it 'instruction_id should be assigned properly' do
+    @instruction_details.instruction_id.path.should ==
+      '[instruction]/[test]'
+  end
+
+  it 'should raise ArgumentError with nil instruction_id' do
+    lambda {
+      @instruction_details.instruction_id = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'activity_id should be assigned properly' do
+    @instruction_details.activity_id.should == 'at0003'
+  end
+
+  it 'should raise ArgumentError with nil activity_id' do
+    lambda {
+      @instruction_details.activity_id = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with empty activity_id' do
+    lambda {
+      @instruction_details.activity_id = ''
+    }.should raise_error ArgumentError
+  end
+
+  it 'wf_details should be assigned properly' do
+    @instruction_details.wf_details.archetype_node_id.should == 
+      'at0004'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/instruction_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/instruction_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/instruction_spec.rb	(revision 369)
@@ -0,0 +1,58 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+require File.dirname(__FILE__) + '/shared_examples_spec'
+include OpenEHR::RM::Composition::Content::Entry
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+include OpenEHR::RM::DataTypes::Encapsulated
+
+describe Instruction do
+  it_should_behave_like 'entry'
+
+  before(:each) do
+    narrative = DvText.new(:value => 'instruction test')
+    activities = stub(Array, :size => 5, :empty? => false)
+    expiry_time = DvDateTime.new(:value => '2009-11-18T20:58:34')
+    wf_definition = stub(DvParsable, :value => 'behavior driven')
+    @instruction= Instruction.new(:archetype_node_id => 'at0001',
+                                  :name => @name,
+                                  :language => @language,
+                                  :encoding => @encoding,
+                                  :subject => @subject,
+                                  :narrative => narrative,
+                                  :activities => activities,
+                                  :expiry_time => expiry_time,
+                                  :wf_definition => wf_definition)
+  end
+
+  it 'should be an instance of Instruction' do
+    @instruction.should be_an_instance_of Instruction
+  end
+
+  it 'narrative should be assigned properly' do
+    @instruction.narrative.value.should == 'instruction test'
+  end
+
+  it 'should raise ArgumentError when narrative is assined with nil' do
+    lambda {
+      @instruction.narrative = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'activities should be assigned properly' do
+    @instruction.activities.size.should be_equal 5
+  end
+
+  it 'should raise ArgumentError with empty activities' do
+    lambda {
+      @instruction.activities = [ ]
+    }.should raise_error ArgumentError
+  end
+
+  it 'expiry_time should be assigned properly' do
+    @instruction.expiry_time.value.should == '2009-11-18T20:58:34'
+  end
+
+  it 'wf_definition should be assigned properly' do
+    @instruction.wf_definition.value.should == 'behavior driven'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/ism_transition_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/ism_transition_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/ism_transition_spec.rb	(revision 369)
@@ -0,0 +1,46 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+include OpenEHR::RM::Composition::Content::Entry
+include OpenEHR::RM::DataTypes::Text
+
+describe IsmTransition do
+  before(:each) do
+    current_state = stub(DvCodedText, :value => 'planned')
+    transition = stub(DvCodedText, :value => 'scheduled')
+    careflow_step = stub(DvCodedText, :value => 'completed')
+    @ism_transition = IsmTransition.new(:current_state => current_state,
+                                        :transition => transition,
+                                        :careflow_step => careflow_step)
+  end
+
+  it 'should be an instance of IsmTransition' do
+    @ism_transition.should be_an_instance_of IsmTransition
+  end
+
+  it 'current_status should be assigned properly' do
+    @ism_transition.current_state.value.should == 'planned'
+  end
+
+  it 'should raise ArgumentError with nil current state' do
+    lambda {
+      @ism_transition.current_state = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError when current_state has invalid code'
+
+  it 'transition should be assined properly' do
+    @ism_transition.transition.value.should == 'scheduled'
+  end
+
+  it 'should raise ArgumentError with nil transition' do
+    lambda {
+      @ism_transition.transition = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArugmentError with invalid transition code'
+
+  it 'careflow_step should be assigned properly' do
+    @ism_transition.careflow_step.value.should == 'completed'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/observation_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/observation_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/observation_spec.rb	(revision 369)
@@ -0,0 +1,38 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+require File.dirname(__FILE__) + '/shared_examples_spec'
+include OpenEHR::RM::DataStructures::History
+include OpenEHR::RM::Composition::Content::Entry
+
+describe Observation do
+  it_should_behave_like 'entry'
+
+  before(:each) do
+    data = stub(History, :archetype_node_id => 'at0002')
+    state = stub(History, :archetype_node_id => 'at0003')
+    @observation = Observation.new(:archetype_node_id => 'at0001',
+                                   :name => @name,
+                                   :language => @language,
+                                   :encoding => @encoding,
+                                   :subject => @subject,
+                                   :data => data,
+                                   :state => state)
+  end
+
+  it 'should be an instance of Observation' do
+    @observation.should be_an_instance_of Observation
+  end
+
+  it 'data should be assigned properly' do
+    @observation.data.archetype_node_id.should == 'at0002'
+  end
+
+  it 'should raise ArgumentError when nil assigned to data' do
+    lambda {
+      @observation.data = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'state should be assigned properly' do
+    @observation.state.archetype_node_id.should == 'at0003'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/shared_examples_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/shared_examples_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/composition/content/entry/shared_examples_spec.rb	(revision 369)
@@ -0,0 +1,12 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::Common::Generic
+
+shared_examples_for 'entry', :shared => true do
+  before(:each) do
+    @name = DvText.new(:value => 'entry package')
+    @language = stub(CodePhrase, :code_string => 'ja')
+    @encoding = stub(CodePhrase, :code_string => 'UTF-8')
+    @subject = stub(PartyProxy)
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/composition/content/navigation/section_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/composition/content/navigation/section_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/composition/content/navigation/section_spec.rb	(revision 369)
@@ -0,0 +1,32 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+include OpenEHR::RM::Composition::Content::Navigation
+include OpenEHR::RM::DataTypes::Text
+
+describe Section do
+  before(:each) do
+    items = stub(Array, :empty? => false, :size => 10)
+    @section = Section.new(:archetype_node_id => 'at0001',
+                           :name => DvText.new(:value => 'section'),
+                           :items => items)
+  end
+
+  it 'should be an instance of Section' do
+    @section.should be_an_instance_of Section
+  end
+
+  it 'items should be assigned properly' do
+    @section.items.size.should be_equal 10
+  end
+
+  it 'empty items should raise ArgumentError' do
+    lambda {
+      @section.items = [ ]
+    }.should raise_error ArgumentError
+  end
+
+  it 'nil items should not raise ArgumentError' do
+    lambda {
+      @section.items = nil
+    }.should_not raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/composition/event_context_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/composition/event_context_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/composition/event_context_spec.rb	(revision 369)
@@ -0,0 +1,88 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::Composition
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataStructures::ItemStructure
+
+describe EventContext do
+  before(:each) do
+    start = DvDateTime.new(:value => '2009-11-13T20:46:57')
+    setting_group = stub(CodePhrase, :code_string => '225')
+    setting = stub(DvCodedText, :defining_code => setting_group)
+    ending = DvDateTime.new(:value => '2010-10-14T09:00:00')
+    participations = stub(Array, :size => 5, :empty? => false)
+    other_context = stub(ItemStructure, :archetype_node_id => 'at0002')
+    @event_context = EventContext.new(:start_time => start,
+                                      :end_time => ending,
+                                      :setting => setting,
+                                      :participations => participations,
+                                      :location => 'ehime',
+                                      :other_context => other_context)
+  end
+
+  it 'should be an instance of EventContext' do
+    @event_context.should be_an_instance_of EventContext
+  end
+
+  it 'start_time should be assigned properly' do
+    @event_context.start_time.value.should == '2009-11-13T20:46:57'
+  end
+
+  it 'should raise ArgumentError with nil start_time' do
+    lambda {
+      @event_context.start_time = nil
+    }.should raise_error ArgumentError
+  end
+  
+  it 'setting should be assigned properly' do
+    @event_context.setting.defining_code.code_string.should == '225'
+  end
+
+  it 'should raise ArgumentError with nil setting' do
+    lambda {
+      @event_context.setting = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should vaildate setting code with Terminology service'
+
+  it 'end_time should be assigned properly' do
+    @event_context.end_time.value.should == '2010-10-14T09:00:00'
+  end
+
+  it 'participations should be properly assigned' do
+    @event_context.participations.size.should be_equal 5
+  end
+
+  it 'should raise ArgumentError with empty participations' do
+    lambda {
+      @event_context.participations = [ ]
+    }.should raise_error ArgumentError
+  end
+
+  it 'should not raise ArgumentError with nil participations' do
+    lambda {
+      @event_context.participations = nil
+    }.should_not raise_error ArgumentError
+  end
+
+  it 'location should be assigned properly' do
+    @event_context.location.should == 'ehime'
+  end
+
+  it 'should raise ArgumentError with empty location' do
+    lambda {
+      @event_context.location = ''
+    }.should raise_error ArgumentError
+  end
+
+  it 'should not raise ArgumentError with nil location' do
+    lambda {
+      @event_context.location = nil
+    }.should_not raise_error ArgumentError
+  end
+
+  it 'other_context should be assigned properly' do
+    @event_context.other_context.archetype_node_id.should == 'at0002'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/data_structures/data_structure_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_structures/data_structure_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_structures/data_structure_spec.rb	(revision 369)
@@ -0,0 +1,21 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::DataStructures
+include OpenEHR::RM::DataTypes::Text
+
+describe DataStructure do
+  before(:each) do
+    name = DvText.new(:value => 'test')
+    @data_structure = DataStructure.new(:archetype_node_id => 'at0001',
+                                        :name => name)
+  end
+
+  it 'should be an instance of DataStructure' do
+    @data_structure.should be_an_instance_of DataStructure
+  end
+
+  it 'should raise NotImplementedError' do
+    lambda {
+      @data_structure.as_hierarchy
+    }.should raise_error NotImplementedError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/data_structures/history/event_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_structures/history/event_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_structures/history/event_spec.rb	(revision 369)
@@ -0,0 +1,44 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::DataStructures::History
+include OpenEHR::RM::DataStructures::ItemStructure
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+
+describe Event do
+  before(:each) do
+    time = DvDateTime.new(:value => '2009-11-12T10:19:33')
+    state = stub(ItemStructure, :archetype_node_id => 'at0002')
+    origin = DvDateTime.new(:value => '2009-11-11T10:20:40')
+    parent = stub(History, :origin => origin)
+    @event = Event.new(:archetype_node_id => 'at0001',
+                       :name => DvText.new(:value => 'Event test'),
+                       :time => time,
+                       :data => 'data',
+                       :state => state,
+                       :parent => parent)
+  end
+
+  it 'should be an instance of Event' do
+    @event.should be_an_instance_of Event
+  end
+
+  it 'data should be assigned properly' do
+    @event.data.should == 'data'
+  end
+
+  it 'time should be assigned properly' do
+    @event.time.value.should == '2009-11-12T10:19:33'
+  end
+
+  it 'state should be assigned properly' do
+    @event.state.archetype_node_id.should == 'at0002'
+  end
+
+  it 'parent should be properly assigned' do
+    @event.parent.origin.value.should == '2009-11-11T10:20:40'
+  end
+
+  it 'offset should be diff of parent.origin from time' do
+    @event.offset.value.should == 'P0Y0M0W0DT23H58M53S'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/data_structures/history/history_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_structures/history/history_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_structures/history/history_spec.rb	(revision 369)
@@ -0,0 +1,67 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::DataStructures::History
+include OpenEHR::RM::DataStructures::ItemStructure
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+
+describe History do
+  before(:each) do
+    origin = DvDateTime.new(:value => '2009-11-01T00:00:00')
+    period = DvDuration.new(:value => 'P1Y2M3W4D')
+    duration = DvDuration.new(:value => 'P0Y0M0W6D')
+    events = [stub(Event, :archetype_node_id => 'at0002')]
+    summary = stub(ItemStructure, :archetype_node_id => 'at0003')
+    @history = History.new(:archetype_node_id => 'at0001',
+                           :name => DvText.new(:value => 'history test'),
+                           :origin => origin,
+                           :period => period,
+                           :duration => duration,
+                           :events => events,
+                           :summary => summary)
+  end
+
+  it 'should be an instance of History' do
+    @history.should be_an_instance_of History
+  end
+
+  it 'origin should be properly assigned' do
+    @history.origin.value.should == '2009-11-01T00:00:00'
+  end
+
+  it 'should raise ArgumentError with nil origin' do
+    lambda {
+      @history.origin = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'period should be properly assigned' do
+    @history.period.value.should == 'P1Y2M3W4D'
+  end
+
+  it 'duration should be properly assigned' do
+    @history.duration.value.should == 'P0Y0M0W6D'
+  end
+
+  it 'is_periodic? should be true when period is not nil' do
+    @history.is_periodic?.should be_true
+  end
+
+  it 'is_periodic? should be false when period is nil' do
+    @history.period = nil
+    @history.is_periodic?.should be_false
+  end
+
+  it 'events should be properly assigned' do
+    @history.events[0].archetype_node_id.should == 'at0002'
+  end
+
+  it 'empty events should raise ArgumentError' do
+    lambda {
+      @history.events = []
+    }.should raise_error ArgumentError
+  end
+
+  it 'summary should be properly assigned' do
+    @history.summary.archetype_node_id.should == 'at0003'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/data_structures/history/interval_event_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_structures/history/interval_event_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_structures/history/interval_event_spec.rb	(revision 369)
@@ -0,0 +1,43 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::DataStructures::History
+include OpenEHR::RM::DataStructures::ItemStructure
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+
+describe IntervalEvent do
+  before(:each) do
+    time = DvDateTime.new(:value => '2009-11-12T10:19:33')
+    state = stub(ItemStructure, :archetype_node_id => 'at0002')
+    origin = DvDateTime.new(:value => '2009-11-11T10:20:40')
+    parent = stub(History, :origin => origin)
+    math_function = stub(DvCodedText, :value => 'mean')
+    width = DvDuration.new(:value => 'P0Y2M1W3DT5H7M3S')
+    @interval_event = IntervalEvent.new(:archetype_node_id => 'at0001',
+                                :name => DvText.new(:value => 'Event test'),
+                                :time => time,
+                                :data => 'data',
+                                :width => width,
+                                :math_function => math_function, 
+                                :sample_count => 1234)
+  end
+
+  it 'should be an instance of IntervalEvent' do
+    @interval_event.should be_an_instance_of IntervalEvent
+  end
+
+  it 'width should be assigned properly' do
+    @interval_event.width.value.should == 'P0Y2M1W3DT5H7M3S'
+  end
+
+  it 'math_function should be assigned properly' do
+    @interval_event.math_function.value.should == 'mean'
+  end
+
+  it 'sample_count should be assigned properly' do
+    @interval_event.sample_count.should be_equal 1234
+  end
+
+  it 'should subtract time for interval start time' do
+    @interval_event.interval_start_time.value.should == '2009-09-09T05:12:30+09:00'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_list_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_list_spec.rb	(revision 291)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_list_spec.rb	(revision 369)
@@ -36,6 +36,10 @@
   end
 
-  it 'retrieve the item with a name' do
+  it 'should return the item with a name' do
     @item_list.named_item('one').name.value.should == 'one'
+  end
+
+  it 'should return nil when item is not exist' do
+    @item_list.named_item('four').should be_nil
   end
 
Index: ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_single_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_single_spec.rb	(revision 291)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_single_spec.rb	(revision 369)
@@ -6,16 +6,24 @@
 
 describe ItemSingle do
-  before(:all) do
-    name = 
-    @element = Element.new(:name => DvText.new('item'),
-                           :archetype_node_id => 'AT0000',
-                           :value => DvQuantity.new())
-    item_single_name = DvText.new('item single')
+  before(:each) do
+    element = stub(Element, :archetype_node_id => 'at0002')
+    item_single_name = DvText.new(:value => 'item single')
     @item_single = ItemSingle.new(:name => item_single_name,
-                                  :archetype_node_id => 'test',
-                                  :item => @element)
-    
+                                  :archetype_node_id => 'at0001',
+                                  :item => element)
   end
 
+  it 'should be an instance of ItemSingle' do
+    @item_single.should be_an_instance_of ItemSingle
+  end
 
+  it 'should raise ArgumentError with nil item' do
+    lambda {
+      @item_single.item = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should return as_hierarchy' do
+    @item_single.as_hierarchy.archetype_node_id.should == 'at0002'
+  end
 end
Index: ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_table_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_table_spec.rb	(revision 291)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_table_spec.rb	(revision 369)
@@ -45,4 +45,8 @@
   end
 
+  it 'column_count should be 0 when @rows == nil' do
+    @item_table.rows = nil
+    @item_table.column_count.should be_equal 0
+  end
 
   it 's row_names should be cluster cluster' do
@@ -96,4 +100,8 @@
   end
 
+  it 'should be false it has_column with name ten' do
+    @item_table.has_column_with_name?('ten').should be_false
+  end
+
   it 'second row should be named_row four' do
     @item_table.named_row('four').items[1].name.value = 'five'
@@ -126,5 +134,10 @@
 
   it 'should be two element at named cell by row column' do
-    @item_table.element_at_named_cell('cluster', 'two').name.value == 'two'
+    @item_table.element_at_named_cell('cluster', 'three').name.value == 'three'
+  end
+
+  it 'should return nil when rows are nil' do
+    @item_table.rows = nil
+    @item_table.row_count.should be_equal 0
   end
 
Index: ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_tree_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_tree_spec.rb	(revision 291)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_tree_spec.rb	(revision 369)
@@ -7,11 +7,13 @@
 describe ItemTree do
   before(:each) do
-    items = %w{one two}.collect do |name|
+    i = 1
+    items = %w{one two three}.collect do |name|
+      i += 1
       Element.new(:name => DvText.new(:value => name),
-                  :archetype_node_id => 'test')
+                  :archetype_node_id => 'at000' + i.to_s)
     end
     name = DvText.new(:value => 'item tree')
     @item_tree = ItemTree.new(:name => name,
-                              :archetype_node_id => 'test',
+                              :archetype_node_id => 'at0001',
                               :items => items)
   end
@@ -26,4 +28,21 @@
 
   it 'has valid element path' do
+    @item_tree.has_element_path?('at0002').should be_true
+  end
+
+  it 'should return false with wrong node' do
+    @item_tree.has_element_path?('at0005').should be_false
+  end
+
+  it 'path at002 should return two' do
+    @item_tree.element_at_path('at0003').name.value.should == 'two'
+  end
+
+  it 'path at005 should return nil' do
+    @item_tree.element_at_path('at0005').should be_nil
+  end
+
+  it 'should returns ItemTree as Cluster' do
+    @item_tree.as_hierarchy.name.value.should == 'item tree'
   end
 end
Index: ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/representation/cluster_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/representation/cluster_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/representation/cluster_spec.rb	(revision 369)
@@ -0,0 +1,26 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+include OpenEHR::RM::DataStructures::ItemStructure::Representation
+include OpenEHR::RM::DataTypes::Text
+
+describe Cluster do
+  before(:each) do
+    item = stub(Item)
+    @cluster = Cluster.new(:archetype_node_id => 'at0001',
+                           :name => DvText.new(:value => 'cluster'),
+                           :items => [item, item])
+  end
+
+  it 'should be an isntance of Cluster' do
+    @cluster.should be_an_instance_of Cluster
+  end
+
+  it 'item size should be 2' do
+    @cluster.items.size.should == 2
+  end
+
+  it 'should raise ArgumentError with empty items' do
+    lambda {
+      @cluster.items = []
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/representation/element_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/representation/element_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/representation/element_spec.rb	(revision 369)
@@ -0,0 +1,22 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+include OpenEHR::RM::DataStructures::ItemStructure::Representation
+include OpenEHR::RM::DataTypes::Text
+
+describe Element do
+  before(:each) do
+    value = DvText.new(:value => 'test')
+    @element = Element.new(:archetype_node_id => 'at0001',
+                           :name => DvText.new(:value => 'element'),
+                           :value => value)
+  end
+
+  it 'should be an instance of Element' do
+    @element.should be_an_instance_of Element
+  end
+
+  it 'value should be assigned as test' do
+    @element.value.value.should == 'test'
+  end
+
+  it 'nullflavor should be assigned'
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_date_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_date_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_date_spec.rb	(revision 369)
@@ -0,0 +1,64 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+
+describe DvDate do
+  before(:each) do
+    @dv_date = DvDate.new(:value => '2009-09-28')
+  end
+
+  it 'should be an instance of DvDate' do
+    @dv_date.should be_an_instance_of DvDate
+  end
+
+  it 'value should be' do
+    @dv_date.value.should == '2009-09-28'
+  end
+
+  it 'year should be 2009' do
+    @dv_date.year.should be_equal 2009
+  end
+
+  it 'month should be 9' do
+    @dv_date.month.should be_equal 9
+  end
+
+  it 'day should be 28' do
+    @dv_date.day.should be_equal 28
+  end
+
+  it 'magnitude should 734045' do
+    @dv_date.magnitude.should == 734045
+  end
+
+  it 'diff should P0Y0M1W11D' do
+    diff_date = DvDate.new(:value => '2009-10-09')
+    @dv_date.diff(diff_date).value.should == 'P0Y0M1W11D'
+  end
+
+  it 'should process leap year' do
+    @dv_date.value = '2004-02-28'
+    diff_date = DvDate.new(:value => '2004-03-01')
+    @dv_date.diff(diff_date).value.should == 'P0Y0M0W2D'
+  end
+
+  it 'should process year'do
+    diff_date = DvDate.new(:value => '2007-12-31')
+    @dv_date.diff(diff_date).value.should == 'P1Y8M4W28D'
+  end
+
+  it 'should be P0Y11M4W31D' do
+    diff_date = DvDate.new(:value => '2008-09-30')
+    @dv_date.diff(diff_date).value.should == 'P0Y11M4W29D'
+  end
+
+  it 'should be P1Y0M0W1D' do
+    diff_date = DvDate.new(:value => '2010-09-29')
+    @dv_date.diff(diff_date).value.should == 'P1Y0M0W1D'
+  end
+
+  it 'should be P0Y0M0W1D' do
+    past_date = DvDate.new(:value => '2009-12-31')
+    future_date=DvDate.new(:value => '2010-01-01')
+    past_date.diff(future_date).value.should == 'P0Y0M0W1D'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_date_time_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_date_time_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_date_time_spec.rb	(revision 369)
@@ -0,0 +1,25 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+
+describe DvDateTime do
+  before(:each) do
+    @dv_date_time = DvDateTime.new(:value => '2009-09-29T15:03:22.3')
+  end
+
+  it 'should be an instance of DvDateTime' do
+    @dv_date_time.should be_an_instance_of DvDateTime
+  end
+
+  it 'magnitude should be 63425495002.3' do
+    @dv_date_time.magnitude.should be_close 63423697018.3, 0.001
+  end
+
+  it 'should be equal when magnitude is same' do
+    @dv_date_time.should == DvDateTime.new(:value => '2009-09-29T15:03:22.3')
+  end
+
+  it 'diff should be caluculated from past to future' do
+    future = DvDateTime.new(:value => '2009-10-29T16:23:30.3')
+    @dv_date_time.diff(future).value.should == 'P0Y1M0W0DT1H20M8.0S'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_tempral_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_tempral_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_tempral_spec.rb	(revision 369)
@@ -0,0 +1,24 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+
+describe DvTemporal do
+  before(:each) do
+    @dv_temporal = DvTemporal.new(:value => '2009-09-28T23:36')
+  end
+
+  it 'should be an instance of DvTemporal' do
+    @dv_temporal.should be_an_instance_of DvTemporal
+  end
+
+  it 'should raise ArgumentError with nil value' do
+    lambda {
+      @dv_temporal.value = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with empty value' do
+    lambda {
+      @dv_temporal.value = ''
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_time_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_time_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_time_spec.rb	(revision 369)
@@ -0,0 +1,37 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+
+describe DvTime do
+  before(:each) do
+    @dv_time = DvTime.new(:value => '11:17:30.2')
+  end
+
+  it 'should be an instance of DvTime' do
+    @dv_time.should be_an_instance_of DvTime
+  end
+
+  it 'hour should be 11' do
+    @dv_time.hour.should == 11
+  end
+
+  it 'minute should be 17' do
+    @dv_time.minute.should == 17
+  end
+
+  it 'second should be 30' do
+    @dv_time.second.should == 30
+  end
+
+  it 'fractional_second should be 0.2' do
+    @dv_time.fractional_second.should == 0.2
+  end
+
+  it 'magnitude should 40650.2' do
+    @dv_time.magnitude.should == 40650.2
+  end
+
+  it 'should be ' do
+    diff_time = DvTime.new(:value => '15:36:48.05')
+    @dv_time.diff(diff_time).value.should =='P0Y0M0W0DT4H19M17.85S'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/demographic/actor_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/demographic/actor_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/demographic/actor_spec.rb	(revision 369)
@@ -0,0 +1,79 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::Demographic
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::Support::Identification
+
+describe Actor do
+  before(:each) do
+    name = DvText.new(:value => 'actor')
+    uid = HierObjectID.new(:value => '01')
+    identities = stub(Set, :empty? => false)
+    roles = stub(Set, :size => 2, :empty? => false)
+    languages = stub(Array, :size => 3, :empty? => false)
+    @actor = Actor.new(:archetype_node_id => 'at0000',
+                       :name => name,
+                       :uid => uid,
+                       :identities => identities,
+                       :roles => roles,
+                       :languages => languages)
+  end
+
+  it 'should be an instance of Actor' do
+    @actor.should be_an_instance_of Actor
+  end
+
+  it 'roles should be assigned properly' do
+    @actor.roles.size.should be_equal 2
+  end
+
+  it 'should raise ArgumentError with empty roles' do
+    lambda {
+      @actor.roles = Set.new
+    }.should raise_error ArgumentError
+  end
+
+  it 'should not raise ArgumentError with nil roles' do
+    lambda {
+      @actor.roles = nil
+    }.should_not raise_error ArgumentError
+  end
+
+  it 'languages should be assigned properly' do
+    @actor.languages.size.should be_equal 3
+  end
+
+  it 'should raise ArgumentError with empty languages' do
+    lambda {
+      @actor.languages = Set.new
+    }.should raise_error ArgumentError
+  end
+
+  it 'should not raise ArgumentError with nil languages' do
+    lambda {
+      @actor.languages = nil
+    }.should_not raise_error ArgumentError
+  end
+
+  describe 'has_legal_identity' do
+    before(:each) do
+      @dummy_purpose = DvText.new(:value => 'dummy')
+      @dummy_identity = stub(PartyIdentity, :purpose => @dummy_purpose)
+    end
+
+    it 'should not have legal identity' do
+      identity = stub(PartyIdentity, :purpose => @dummy_purpose)
+      identities = [identity, @dummy_identity].to_set
+      @actor.identities = identities
+      @actor.has_legal_identity?.should be_false
+    end
+
+    it 'should have legal identity' do
+      legal_purpose = DvText.new(:value => 'legal identity')
+      legal_identity = stub(PartyIdentity, :purpose => legal_purpose)
+      identities = [@dummy_identity, legal_identity].to_set
+      @actor.identities = identities
+      @actor.has_legal_identity?.should be_true
+    end
+  end
+end
+
Index: ruby/trunk/spec/lib/open_ehr/rm/demographic/address_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/demographic/address_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/demographic/address_spec.rb	(revision 369)
@@ -0,0 +1,33 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::Demographic
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataStructures::ItemStructure
+
+describe Address do
+  before(:each) do
+    name = DvText.new(:value => 'address')
+    details = stub(ItemStructure, :archetype_node_id => 'at0001')
+    @address = Address.new(:archetype_node_id => 'at0000',
+                           :name => name,
+                           :details => details)
+  end
+
+  it 'should be an instance of Address' do
+    @address.should be_an_instance_of Address
+  end
+
+  it 'type is inherit from name' do
+    @address.type.value.should == 'address'
+  end
+
+  it 'details should be assigned properly' do
+    @address.details.archetype_node_id.should == 'at0001'
+  end
+
+  it 'should raise ArgumentError with nil details' do
+    lambda {
+      @address.details = nil
+    }.should raise_error ArgumentError
+  end
+end
+
Index: ruby/trunk/spec/lib/open_ehr/rm/demographic/capability_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/demographic/capability_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/demographic/capability_spec.rb	(revision 369)
@@ -0,0 +1,37 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::Demographic
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+include OpenEHR::RM::Support::Identification
+include OpenEHR::RM::DataStructures::ItemStructure
+
+describe Capability do
+  before(:each) do
+    name = DvText.new(:value => 'party relation')
+    credentials = stub(ItemStructure, :archetype_node_id => 'at0001')
+    lower = DvDate.new(:value => '2009-11-21')
+    time_validity = stub(DvInterval, :lower => lower)
+    @capability = Capability.new(:archetype_node_id => 'at0000',
+                                 :name => name,
+                                 :credentials => credentials,
+                                 :time_validity => time_validity)
+  end
+
+  it 'should be an instance of Capability' do
+    @capability.should be_an_instance_of Capability
+  end
+
+  it 'credential should be assigned properly' do
+    @capability.credentials.archetype_node_id.should == 'at0001'
+  end
+
+  it 'should raise ArgumentError when nil assigned to credentials' do
+    lambda {
+      @capability.credentials = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'time_validity should be assigned properly' do
+    @capability.time_validity.lower.value.should == '2009-11-21'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/demographic/contact_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/demographic/contact_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/demographic/contact_spec.rb	(revision 369)
@@ -0,0 +1,45 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::Demographic
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+include OpenEHR::RM::DataTypes::Text
+
+describe Contact do
+  before(:each) do
+    name = DvText.new(:value => 'contact')
+    addresses = stub(Array, :size => 2, :empty? => false)
+    upper = DvDate.new(:value => '2009-11-20')
+    time_validity = stub(DvInterval, :upper => upper)
+    @contact = Contact.new(:archetype_node_id => 'at0000',
+                           :name => name,
+                           :addresses => addresses,
+                           :time_validity => time_validity)
+  end
+
+  it 'should be an instance of Contact' do
+    @contact.should be_an_instance_of Contact
+  end
+
+  it 'addresses should be assigned properly' do
+    @contact.addresses.size.should == 2
+  end
+
+  it 'should raise ArgumentError with nil address' do
+    lambda {
+      @contact.addresses = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with empty addresses' do
+    lambda {
+      @contact.addresses = [ ]
+    }.should raise_error ArgumentError
+  end
+
+  it 'time_validity should be assigned properly' do
+    @contact.time_validity.upper.value.should == '2009-11-20'
+  end
+
+  it 'purpose should be inherit as name' do
+    @contact.purpose.value.should == 'contact'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/demographic/party_identity_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/demographic/party_identity_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/demographic/party_identity_spec.rb	(revision 369)
@@ -0,0 +1,32 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::Demographic
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataStructures::ItemStructure
+
+describe PartyIdentity do
+  before(:each) do
+    name = DvText.new(:value => 'test')
+    details = stub(ItemStructure, :archetype_node_id => 'at0002')
+    @party_identity = PartyIdentity.new(:archetype_node_id => 'at0001',
+                                        :name => name,
+                                        :details => details)
+  end
+
+  it 'should be an instance of PartyIdentity' do
+    @party_identity.should be_an_instance_of PartyIdentity
+  end
+
+  it 'details should be assigned properly' do
+    @party_identity.details.archetype_node_id.should == 'at0002'
+  end
+
+  it 'should raise ArgumentError with nil details' do
+    lambda {
+      @party_identity.details = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'purpose should return as same as name' do
+    @party_identity.purpose.value.should == 'test'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/demographic/party_relationship_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/demographic/party_relationship_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/demographic/party_relationship_spec.rb	(revision 369)
@@ -0,0 +1,84 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::Demographic
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+include OpenEHR::RM::Support::Identification
+include OpenEHR::RM::DataStructures::ItemStructure
+
+describe PartyRelationship do
+  before(:each) do
+    name = DvText.new(:value => 'party relation')
+    uid = HierObjectID.new(:value => '01')
+    details = stub(ItemStructure, :archetype_node_id => 'at0002')
+    upper = DvDate.new(:value => '2009-11-21')
+    time_validity = stub(DvInterval, :upper => upper)
+    source_id = ObjectID.new(:value => '01')
+    source = stub(PartyRef, :id => source_id, :type => 'source')
+    target_id = ObjectID.new(:value => '02')
+    target = stub(PartyRef, :id => target_id)
+    @party_relationship =
+      PartyRelationship.new(:archetype_node_id => 'at0000',
+                            :name => name,
+                            :uid => uid,
+                            :details => details,
+                            :time_validity => time_validity,
+                            :source => source,
+                            :target => target)
+  end
+
+  it 'should be an instance of PartyRelationship' do
+    @party_relationship.should be_an_instance_of PartyRelationship
+  end
+
+  it 'uid should be assigned properly' do
+    @party_relationship.uid.value.should == '01'
+  end
+
+  it 'should raise ArgumentError when nil assigned to uid' do
+    lambda {
+      @party_relationship.uid = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'details should be assigned properly' do
+    @party_relationship.details.archetype_node_id.should == 'at0002'
+  end
+
+  it 'time_validity should be assigned properly' do
+    @party_relationship.time_validity.upper.value.should == '2009-11-21'
+  end
+
+  it 'source should be_assigned properly' do
+    @party_relationship.source.type.should == 'source'
+  end
+
+  it 'should raise ArgumentError when source is assinged nil' do
+    lambda {
+      @party_relationship.source = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError when source is not matched with source' do
+    invalid_id = ObjectID.new(:value => '10')
+    invalid_source = stub(PartyRef, :id => invalid_id)
+    lambda {
+      @party_relationship.source = invalid_source
+    }.should raise_error ArgumentError
+  end
+
+  it 'target should be assined properly' do
+    @party_relationship.target.id.value.should == '02'
+  end
+
+  it 'should raise ArgumentError with target is assigned by nil' do
+    lambda {
+      @party_relationship.target =nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'type should be inherited of name' do
+    @party_relationship.type.value.should == 'party relation'
+  end
+end
+  
+                            
Index: ruby/trunk/spec/lib/open_ehr/rm/demographic/party_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/demographic/party_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/demographic/party_spec.rb	(revision 369)
@@ -0,0 +1,133 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::Demographic
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::Support::Identification
+include OpenEHR::RM::DataStructures::ItemStructure
+
+describe Party do
+  before(:each) do
+    name = DvText.new(:value => 'PARTY')
+    uid = HierObjectID.new(:value => '01')
+    identities = stub(Set, :empty? => false, :size => 2)
+    contacts = stub(Set, :size => 3, :empty? => false)
+    cur_id = stub(ObjectID, :value => '01')
+    cur_source = stub(PartyRef, :id => cur_id)
+    id1 = stub(ObjectID, :value => '03')
+    targ1 = stub(PartyRef, :id => id1)
+    rel1 = stub(PartyRelationship, :source => cur_source,
+                :target => targ1)
+    id2 = stub(ObjectID, :value => '04')
+    targ2 = stub(PartyRef, :id => id2)
+    rel2 = stub(PartyRelationship, :source => cur_source,
+                :target => targ2)
+    id3 = stub(ObjectID, :value => '05')
+    targ3 = stub(PartyRef, :id => id3) 
+    rel3 = stub(PartyRelationship, :source => cur_source,
+                :target => targ3)
+    id4 = stub(ObjectID, :value => '06')
+    targ4 = stub(PartyRef, :id => id4)
+    rel4 = stub(PartyRelationship, :source => cur_source,
+                :target => targ4)
+    relationships = [rel1, rel2, rel3, rel4].to_set
+    reverse_relationships = stub(Set, :empty? => false, :size => 5)
+    details = stub(ItemStructure, :archetype_node_id => 'at0005')
+    @party = Party.new(:archetype_node_id => 'at0001',
+                       :name => name,
+                       :uid => uid,
+                       :identities => identities,
+                       :contacts => contacts,
+                       :relationships => relationships,
+                       :reverse_relationships => reverse_relationships,
+                       :details => details)
+  end
+
+  it 'should be an instance of Party' do
+    @party.should be_an_instance_of Party
+  end
+
+  it 'uid should be assigned properly' do
+    @party.uid.value.should == '01'
+  end
+
+  it 'should raise ArgumentError with nil uid' do
+    lambda {
+      @party.uid = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'identities should be assigned properly' do
+    @party.identities.size.should be_equal 2
+  end
+
+  it 'should raise ArgumentError when nil identities are assigned' do
+    lambda {
+      @party.identities = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError when identities are empty' do
+    lambda {
+      @party.identities = Set.new
+    }
+  end
+
+  it 'type should be alias of name' do
+    @party.type.value.should == 'PARTY'
+  end
+
+  it 'contacts should be assigned properly' do
+    @party.contacts.size.should be_equal 3
+  end
+
+  it 'should raise ArgumentError with empty contacts' do
+    lambda {
+      @party.contacts = Set.new
+    }.should raise_error ArgumentError
+  end
+
+  it 'relationships should be assigned properly' do
+    target_ids = Set.new
+    @party.relationships.each do |rel|
+      target_ids << rel.target.id.value
+    end
+    target_ids.should == %w{03 04 05 06}.to_set
+  end
+
+  it 'should not raise ArgumentError with nil relationships' do
+    lambda {
+      @party.relationships = nil
+    }.should_not raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with empty relationships' do
+    lambda {
+      @party.relationships = Set.new
+    }.should raise_error ArgumentError
+  end
+
+  it 'invaild relationship raise ArgumentError' do
+    invalid_id = stub(ObjectID, :value => '10')
+    invalid_source = stub(PartyRef, :id => invalid_id)
+    invalid_rel = stub(PartyRelationship, :source => invalid_source)
+    lambda {
+      @party.relationships = [invalid_rel].to_set
+    }.should raise_error ArgumentError
+  end
+
+  it 'reverse relationship should be assigned properly' do
+    @party.reverse_relationships.size.should be_equal 5
+  end
+
+  it 'reverse_relationships should not be empty' do
+    lambda {
+      @party.reverse_relationships = Set.new
+    }.should raise_error ArgumentError
+  end
+
+  it 'should validate reverse_relationships'
+
+  it 'details should be assigned properly' do
+    @party.details.archetype_node_id.should == 'at0005'
+  end
+end
+
Index: ruby/trunk/spec/lib/open_ehr/rm/demographic/role_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/demographic/role_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/demographic/role_spec.rb	(revision 369)
@@ -0,0 +1,58 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::Demographic
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+include OpenEHR::RM::Support::Identification
+
+describe Role do
+  before(:each) do
+    name = DvText.new(:value => 'role')
+    uid = HierObjectID.new(:value => '01')
+    identities = stub(Set, :empty? => false)
+    capabilities = stub(Array, :size => 2, :empty? => false)
+    lower = DvDate.new(:value => '2009-11-21')
+    time_validity = stub(DvInterval, :lower => lower)
+    performer = stub(PartyRef, :type => 'ROLE')
+    @role = Role.new(:archetype_node_id => 'at0000',
+                     :name => name,
+                     :uid => uid,
+                     :identities => identities,
+                     :performer => performer,
+                     :capabilities => capabilities,
+                     :time_validity => time_validity)
+  end
+
+  it 'should be an instance of Role' do
+    @role.should be_an_instance_of Role
+  end
+
+  it 'performer should assigned properly' do
+    @role.performer.type.should == 'ROLE'
+  end
+
+  it 'should raise ArgumentError with nil performer' do
+    lambda {
+      @role.performer = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'capabilities should be assigned properly' do
+    @role.capabilities.size.should be_equal 2
+  end
+
+  it 'should raise ArgumentError with empty capabilities' do
+    lambda {
+      @role.capabilities = [ ]
+    }.should raise_error ArgumentError
+  end
+
+  it 'should not raise ArgumentError with nil capabilities' do
+    lambda {
+      @role.capabilities = nil
+    }.should_not raise_error ArgumentError
+  end
+
+  it 'time_validity should be properly assigned' do
+    @role.time_validity.lower.value.should == '2009-11-21'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/ehr/ehr_access_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/ehr/ehr_access_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/ehr/ehr_access_spec.rb	(revision 369)
@@ -0,0 +1,33 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::EHR
+include OpenEHR::RM::Security
+include OpenEHR::RM::DataTypes::Text
+
+describe EHRAccess do
+  before(:each) do
+    name = DvText.new(:value => 'EHRAccess')
+    settings = stub(AccessControlSettings)
+    @ehr_access = EHRAccess.new(:archetype_node_id => 'at0001',
+                                :name => name,
+                                :settings => settings,
+                                :scheme => 'SSL')
+  end
+
+  it 'should be an instance of EHRAccess' do
+    @ehr_access.should be_an_instance_of EHRAccess
+  end
+
+  it 'settings should be assigned, but Security package is not determined' do
+    @ehr_access.settings.should_not be_nil
+  end
+
+  it 'schema should be assigned properly' do
+    @ehr_access.scheme.should == 'SSL'
+  end
+
+  it 'should raise ArgumentError with nil schema' do
+    lambda {
+      @ehr_access.scheme = nil
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/ehr/ehr_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/ehr/ehr_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/ehr/ehr_spec.rb	(revision 369)
@@ -0,0 +1,139 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::EHR
+include OpenEHR::RM::Support::Identification
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+
+describe EHR do
+  before(:each) do
+    system_id = HierObjectID.new(:value => 'ABC::DEF')
+    ehr_id = HierObjectID.new(:value => 'GHI::JKL')
+    time_created = DvDateTime.new(:value => '2009-11-14T19:01:11')
+    ehr_access = stub(ObjectRef, :type => 'VERSIONED_EHR_ACCESS')
+    ehr_status = stub(ObjectRef, :type => 'VERSIONED_EHR_STATUS')
+    contribution1 = stub(ObjectRef, :type => 'CONTRIBUTION')
+    contribution2 = stub(ObjectRef, :type => 'CONTRIBUTION')
+    contributions = [contribution1, contribution2]
+    directory = stub(ObjectRef, :type => 'VERSIONED_FOLDER')
+    composition1 = stub(ObjectRef, :type => 'VERSIONED_COMPOSITION')
+    composition2 = stub(ObjectRef, :type => 'VERSIONED_COMPOSITION')
+    composition3 = stub(ObjectRef, :type => 'VERSIONED_COMPOSITION')
+    compositions = [composition1, composition2, composition3]
+    @ehr = EHR.new(:system_id => system_id,
+                   :ehr_id => ehr_id,
+                   :time_created => time_created,
+                   :contributions => contributions,
+                   :ehr_access => ehr_access,
+                   :ehr_status => ehr_status,
+                   :directory => directory,
+                   :compositions => compositions)
+  end
+
+  it 'should be an instance of EHR' do
+    @ehr.should be_an_instance_of EHR
+  end
+
+  it 'system_id should be assigned properly' do
+    @ehr.system_id.value.should == 'ABC::DEF'
+  end
+
+  it 'should raise ArgumentError with nil system_id' do
+    lambda {
+      @ehr.system_id = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'ehr_id should be assigned properly' do
+    @ehr.ehr_id.value.should == 'GHI::JKL'
+  end
+
+  it 'should raise ArgumentError with nil ehr_id' do
+    lambda {
+      @ehr.ehr_id = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'time_created should be assigned properly' do
+    @ehr.time_created.value.should == '2009-11-14T19:01:11'
+  end
+
+  it 'should raise ArgumentError with nil time_created' do
+    lambda {
+      @ehr.time_created = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'contributions should properly assigned' do
+    @ehr.contributions.size.should be_equal 2
+  end
+
+  it 'type contributions should be CONTRIBUTION' do
+    contributions = [stub(ObjectRef, :type => 'PARTY')]
+    lambda {
+      @ehr.contributions = contributions
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with nil contributions' do
+    lambda {
+      @ehr.contributions = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'ehr_access should be assigned properly' do
+    @ehr.ehr_access.type.should == 'VERSIONED_EHR_ACCESS'
+  end
+
+  it 'should raise ArgumentError with nil ehr_access' do
+    lambda {
+      @ehr.ehr_access = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArguemntError with invalid ehr_access type' do
+    lambda {
+      @ehr.ehr_access = stub(ObjectRef, :type => 'VERSIONED_EHR_STATUS')
+    }.should raise_error ArgumentError
+  end
+    
+  it 'ehr_status should be assigned properly' do
+    @ehr.ehr_status.type.should == 'VERSIONED_EHR_STATUS'
+  end
+
+  it 'should raise ArgumentError with nil ehr_status' do
+    lambda {
+      @ehr.ehr_status = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with invalid ehr_statsu type' do
+    lambda {
+      @ehr.ehr_status = stub(ObjectRef, :type => 'VERSIONED_EHR_ACCESS')
+    }.should raise_error ArgumentError
+  end
+
+  it 'should assigned compositions properly' do
+    @ehr.compositions.size.should be_equal 3
+  end
+
+  it 'should raise ArgumentError with nil compositions' do
+    lambda {
+      @ehr.compositions = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with invalid type composition' do
+    lambda {
+      @ehr.compositions = [stub(ObjectRef, :type => 'INVALID_COMPOSITION')]
+    }.should raise_error ArgumentError
+  end
+
+  it 'should assigned directory properly' do
+    @ehr.directory.type.should == 'VERSIONED_FOLDER'
+  end
+
+  it 'should raise ArgumentError with invalid type' do
+    lambda {
+      @ehr.directory = stub(ObjectRef, :type => 'INVALID_FOLDER')
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/ehr/ehr_status_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/ehr/ehr_status_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/ehr/ehr_status_spec.rb	(revision 369)
@@ -0,0 +1,52 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::EHR
+include OpenEHR::RM::Common::Generic
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::Support::Identification
+include OpenEHR::RM::DataStructures::ItemStructure
+
+describe EHRStatus do
+  before(:each) do
+    external_ref = stub(PartyRef, :namespace => 'ehr status')
+    subject = PartySelf.new(:external_ref => external_ref)
+    other_details = stub(ItemStructure, :archetype_node_id => 'at0005')
+    @ehr_status = EHRStatus.new(:archetype_node_id => 'at0001',
+                                :name => DvText.new(:value => 'ehrstatus'),
+                                :subject => subject,
+                                :is_queryable => false,
+                                :is_modifiable => true,
+                                :other_details => other_details)
+  end
+
+  it 'should be an instance of EHRStatus' do
+    @ehr_status.should be_an_instance_of EHRStatus
+  end
+
+  it 'subject should be assigned properly' do
+    @ehr_status.subject.external_ref.namespace.should == 'ehr status'
+  end
+
+  it 'should raise ArgumentError with nil subject' do
+    lambda {
+      @ehr_status.subject = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'is_queryable should be properly assigned' do
+    @ehr_status.is_queryable?.should be_false
+  end
+
+  it 'is_modifiable should be assigned properly' do
+    @ehr_status.is_modifiable?.should be_true
+  end
+
+  it 'other_details should be assigned properly' do
+    @ehr_status.other_details.archetype_node_id.should == 'at0005'
+  end
+
+  it 'should raise ArgumentError when parant is not nil' do
+    lambda {
+      @ehr_status.parent = 'parent'
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/ehr/versioned_composition_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/ehr/versioned_composition_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/ehr/versioned_composition_spec.rb	(revision 369)
@@ -0,0 +1,33 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::EHR
+include OpenEHR::RM::Composition
+include OpenEHR::RM::Common::ChangeControl
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+
+describe VersionedComposition do
+  before(:each) do
+    composition1 = stub(Composition, :archetype_node_id => 'at0002',
+                        :is_persistent? => true)
+    version1 = stub(Version, :data => composition1)
+    composition2 = stub(Composition, :archetype_node_id => 'at0002',
+                        :is_persistent? => false)
+    version2 = stub(Version, :data => composition2)
+    uid = HierObjectID.new(:value => 'opeehr.jp::350')
+    owner_id = stub(ObjectRef, :type => 'EHR')
+    time_created = DvDateTime.new(:value => '2009-11-16T15:14:33')
+    @versioned_composition = 
+      VersionedComposition.new(:uid => uid,
+                               :owner_id => owner_id,
+                               :time_created => time_created,
+                               :all_versions => [version1, version2])
+  end
+
+  it 'should be an instance of VersionedComposition' do
+    @versioned_composition.should be_an_instance_of VersionedComposition
+  end
+
+  it 'is_persistent? should be evaluated by first version' do
+    @versioned_composition.is_persistent?.should be_true
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/integration/generic_entry_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/integration/generic_entry_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/integration/generic_entry_spec.rb	(revision 369)
@@ -0,0 +1,31 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::Integration
+include OpenEHR::RM::DataStructures::ItemStructure
+include OpenEHR::RM::DataTypes::Text
+
+describe GenericEntry do
+  before(:each) do
+    data = stub(ItemTree, :archetype_node_id => 'at0003')
+    name = DvText.new(:value => 'generic entry')
+    @generic_entry = GenericEntry.new(:archetype_node_id => 'at0001',
+                                      :name => name,
+                                      :data => data)
+  end
+
+  it 'should be an instance of GenericEntry' do
+    @generic_entry.should be_an_instance_of GenericEntry
+  end
+
+  it 'data should be assigned properly' do
+    @generic_entry.data.archetype_node_id.should == 'at0003'
+  end
+
+  it 'should raise ArgumentError when data are nil' do
+    lambda {
+      @generic_entry.data = nil
+    }.should raise_error ArgumentError
+  end
+end
+                                      
+
+  
