Index: ruby/branches/0.5/spec/lib/open_ehr/rm/composition/composition_spec.rb
===================================================================
--- ruby/branches/0.5/spec/lib/open_ehr/rm/composition/composition_spec.rb	(revision 345)
+++ ruby/branches/0.5/spec/lib/open_ehr/rm/composition/composition_spec.rb	(revision 345)
@@ -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/branches/0.5/spec/lib/open_ehr/rm/composition/event_context_spec.rb
===================================================================
--- ruby/branches/0.5/spec/lib/open_ehr/rm/composition/event_context_spec.rb	(revision 345)
+++ ruby/branches/0.5/spec/lib/open_ehr/rm/composition/event_context_spec.rb	(revision 345)
@@ -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
