Index: ruby/branches/0.5/test/unit/open_ehr/assumed_library_types_test.rb
===================================================================
--- ruby/branches/0.5/test/unit/open_ehr/assumed_library_types_test.rb	(revision 191)
+++ ruby/branches/0.5/test/unit/open_ehr/assumed_library_types_test.rb	(revision 191)
@@ -0,0 +1,355 @@
+require 'test/unit'
+
+#include Lib::OpenEhr::AssumedLibraryTypes
+
+class Assumed_Library_Test < Test::Unit::TestCase
+  def setup
+    assert_nothing_raised(Exception){@interval = OpenEhr::AssumedLibraryTypes::Interval.new(1,2)}
+    assert_nothing_raised(Exception){@iso8601_date = OpenEhr::AssumedLibraryTypes::ISO8601_DATE.new('2009-04-27')}
+    assert_nothing_raised(Exception){@iso8601_time = OpenEhr::AssumedLibraryTypes::ISO8601_TIME.new('15:55:37.32+0900')}
+    assert_nothing_raised(Exception){@iso8601_date_time = OpenEhr::AssumedLibraryTypes::ISO8601_DATE_TIME.new('2009-04-27T15:55:37.32+0900')}
+    assert_nothing_raised(Exception){@iso8601_duration = OpenEhr::AssumedLibraryTypes::ISO8601_DURATION.new('P1Y2M3W4DT5H6M7.8S')}
+    assert_nothing_raised(Exception){@iso8601_timezone = OpenEhr::AssumedLibraryTypes::ISO8601_TIMEZONE.new}
+  end
+
+  def test_initialize
+    assert_instance_of OpenEhr::AssumedLibraryTypes::Interval, @interval
+    assert_instance_of OpenEhr::AssumedLibraryTypes::ISO8601_DATE, @iso8601_date
+    assert_instance_of OpenEhr::AssumedLibraryTypes::ISO8601_TIME, @iso8601_time
+    assert_instance_of OpenEhr::AssumedLibraryTypes::ISO8601_DATE_TIME, @iso8601_date_time
+    assert_instance_of OpenEhr::AssumedLibraryTypes::ISO8601_DURATION, @iso8601_duration
+    assert_instance_of OpenEhr::AssumedLibraryTypes::ISO8601_TIMEZONE, @iso8601_timezone
+  end
+
+  def test_limits_comparable
+    assert @interval.lower < @interval.upper
+    assert_nothing_raised(Exception){@interval.lower=1.0}
+    assert_nothing_raised(Exception){@interval.upper=2.0}
+    assert @interval.lower < @interval.upper
+  end
+
+  def test_limits_consistent
+    assert @interval.has?(1.5)
+    assert !@interval.has?(3.0)
+    assert !@interval.has?(0.5)
+    assert_nothing_raised(Exception){@interval.lower_included=true}
+    assert @interval.has?(1.0)
+    assert_nothing_raised(Exception){@interval.lower_included=false}
+    assert !@interval.has?(1.0)
+    assert_nothing_raised(Exception){@interval.upper_included=true}
+    assert @interval.has?(2.0)
+    assert_nothing_raised(Exception){@interval.upper_included=false}
+    assert !@interval.has?(2.0)
+  end
+
+  def test_lower_included_valid
+    assert_nothing_raised(Exception){@interval.lower=nil}
+    assert @interval.lower_unbounded?
+    assert !@interval.lower_included?
+    assert_nothing_raised(Exception){@interval.lower=1.0}
+  end
+
+  def test_upper_included_valid
+    assert_nothing_raised(Exception){@interval.upper=nil}
+    assert @interval.upper_unbounded?
+    assert !@interval.upper_included?
+  end
+
+  def test_time_definitions
+    assert_equal OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS::DAYS_IN_LEAP_YEAR, 366
+    assert_equal OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS::DAYS_IN_WEEK, 7
+    assert_equal OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS::DAYS_IN_YEAR, 365
+    assert_equal OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS::HOURS_IN_DAY, 24
+    assert_equal OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS::MAX_DAYS_IN_MONTH, 31
+    assert_equal OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS::MAX_DAYS_IN_YEAR, 366
+    assert_equal OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS::MINUTES_IN_HOUR, 60
+    assert_equal OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS::MONTH_IN_YEAR, 12
+    assert_equal OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS::NOMINAL_DAYS_IN_MONTH, 30.42
+    assert_equal OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS::NOMINAL_DAYS_IN_YEAR, 365.24
+    assert_equal OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS::SECONDS_IN_MINUTE, 60
+  end
+
+  def test_time_definition_validity
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_year?(2008)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_year?(-20)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_year?(0)
+# today
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,6,19)
+# test valid_day lower limit
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(0,0,0)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(0,1,1)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(-1,1,1)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(0,1,0)
+# test valid_day upper and lowerlimit of each month
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(0,0,1)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,1,1)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,1,0)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,0,1)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,1,31)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,1,32)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,2,1)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,2,0)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,2,31)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,3,1)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,3,0)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,3,31)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,3,32)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,4,1)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,4,0)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,4,30)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,4,31)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,5,1)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,5,0)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,5,31)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,5,32)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,6,1)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,6,0)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,6,30)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,6,31)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,7,1)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,7,0)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,7,31)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,7,32)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,8,1)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,8,0)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,8,31)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,8,32)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,9,1)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,9,0)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,9,30)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,9,31)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,10,1)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,10,0)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,10,31)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,10,32)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,11,1)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,11,0)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,11,30)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,11,31)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,12,1)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,12,0)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,12,31)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,12,32)
+# test valid_day leap year
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(1900,2,28)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(1900,2,29)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2000,2,29)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_day?(2008,2,29)
+# test valid_hour lower limit
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_hour?(0,0,0)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_hour?(-1,0,0)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_hour?(0,-1,0)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_hour?(0,0,-1)
+# test valid_hour upper limit
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_hour?(0,59,0)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_hour?(0,60,0)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_hour?(0,0,59)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_hour?(0,0,60)
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_hour?(24,0,0)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_hour?(24,0,1)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_hour?(24,1,0)
+# test valid_minute method lower limit
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_minute?(0)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_minute?(-1)
+# test valid_minute method upper limit
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_minute?(59)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_minute?(60)
+# test valid_second method lower limit
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_second?(0)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_second?(-1)
+# test valid_second method upper limit
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_second?(59)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_second?(60)
+# test valid_month method lower limit
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_month?(1)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_month?(0)
+# test valid_month method upper limit
+    assert OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_month?(12)
+    assert !OpenEhr::AssumedLibraryTypes::TIME_DEFINITIONS.valid_month?(13)
+  end
+  def test_iso8601_date
+    assert_equal 2009, @iso8601_date.year
+    assert_equal 4,@iso8601_date.month
+    assert_equal 27,@iso8601_date.day
+    assert_nothing_raised(Exception){@iso8601_date = OpenEhr::AssumedLibraryTypes::ISO8601_DATE.new('2008')}
+    assert @iso8601_date.day_unknown?
+    assert @iso8601_date.month_unknown?
+    assert @iso8601_date.is_partial?
+    assert @iso8601_date.is_extended?
+    assert_nothing_raised(Exception){@iso8601_date.year = 2008}
+    assert_raise(ArgumentError){@iso8601_date.year = -1}
+    assert_equal "2008", @iso8601_date.as_string
+    assert_nothing_raised(Exception){@iso8601_date.month = 6}
+    assert_equal 6, @iso8601_date.month
+    assert_raise(ArgumentError){@iso8601_date.month = 13}
+    assert_raise(ArgumentError){@iso8601_date.month = 0}
+    assert !@iso8601_date.month_unknown?
+    assert_equal "2008-06", @iso8601_date.as_string
+    assert_nothing_raised(Exception){@iso8601_date.day = 14}
+    assert_equal 14, @iso8601_date.day
+    assert_raise(ArgumentError){@iso8601_date.day = 0}
+    assert_raise(ArgumentError){@iso8601_date.day = 31}
+    assert !@iso8601_date.day_unknown?
+    assert !@iso8601_date.is_partial?
+    assert_equal "2008-06-14", @iso8601_date.as_string
+    assert OpenEhr::AssumedLibraryTypes::ISO8601_DATE.valid_iso8601_date?("2006-06-14")
+    assert !OpenEhr::AssumedLibraryTypes::ISO8601_DATE.valid_iso8601_date?("ABCDEFG")
+  end
+
+  def test_iso8601_time
+    assert_equal 15, @iso8601_time.hour
+    assert_equal 55, @iso8601_time.minute
+    assert_equal 37, @iso8601_time.second
+    assert_equal 0.32, @iso8601_time.fractional_second
+    assert_equal '+0900', @iso8601_time.timezone
+
+#    assert_nothing_raised(Exception){@iso8601_time = OpenEHR::Assumed_Library_Types::ISO8601_TIME.new('15:55:37.32+0900')}
+
+    assert_nothing_raised(Exception){@iso8601_time = OpenEhr::AssumedLibraryTypes::ISO8601_TIME.new('01')}
+    assert_equal 1, @iso8601_time.hour
+    assert @iso8601_time.is_partial?
+    assert_equal "01", @iso8601_time.as_string
+    assert_raise(ArgumentError){@iso8601_time.hour = -1}
+    assert_raise(ArgumentError){@iso8601_time.hour = 24}
+    assert_nothing_raised(Exception){@iso8601_time.hour = 0}
+    assert_equal 0, @iso8601_time.hour
+    assert_equal "00", @iso8601_time.as_string
+    assert_nothing_raised(Exception){@iso8601_time.hour = 23}
+    assert_equal 23, @iso8601_time.hour
+    assert_equal "23", @iso8601_time.as_string
+    assert @iso8601_time.minute_unknown?
+    assert @iso8601_time.second_unknown?
+    assert !@iso8601_time.has_fractional_second?
+    assert_raise(ArgumentError){@iso8601_time.fractional_second = 0.012}
+    assert_raise(ArgumentError){@iso8601_time.second = 10}
+    assert_raise(ArgumentError){@iso8601_time.minute = -1}
+    assert_raise(ArgumentError){@iso8601_time.minute = 60}
+    assert_nothing_raised(Exception){@iso8601_time.minute = 0}
+    assert_equal 0, @iso8601_time.minute
+    assert_equal "23:00", @iso8601_time.as_string
+    assert_nothing_raised(Exception){@iso8601_time.minute = 59}
+    assert_equal 59, @iso8601_time.minute
+    assert_equal "23:59", @iso8601_time.as_string
+    assert !@iso8601_time.minute_unknown?
+    assert @iso8601_time.second_unknown?
+    assert @iso8601_time.is_partial?
+    assert_raise(ArgumentError){@iso8601_time.fractional_second = 0.012}
+    assert_raise(ArgumentError){@iso8601_time.second = -1}
+    assert_raise(ArgumentError){@iso8601_time.second = 60}
+    assert_nothing_raised(Exception){@iso8601_time.second = 0}
+    assert !@iso8601_time.second_unknown?
+    assert_equal 0, @iso8601_time.second
+    assert_equal "23:59:00", @iso8601_time.as_string
+    assert_nothing_raised(Exception){@iso8601_time.second = 59}
+    assert_equal 59, @iso8601_time.second
+    assert_equal "23:59:59", @iso8601_time.as_string
+    assert !@iso8601_time.is_partial?
+    assert_raise(ArgumentError){@iso8601_time.fractional_second = 1.23}
+    assert_nothing_raised(Exception){@iso8601_time.fractional_second = 0.23}
+    assert @iso8601_time.has_fractional_second?
+    assert_equal 0.23, @iso8601_time.fractional_second
+    assert_equal "23:59:59.23", @iso8601_time.as_string
+    assert @iso8601_time.is_extended?
+    assert !@iso8601_time.is_decimal_sign_comma?
+    assert OpenEhr::AssumedLibraryTypes::ISO8601_TIME.valid_iso8601_time?("012345Z")
+    assert OpenEhr::AssumedLibraryTypes::ISO8601_TIME.valid_iso8601_time?("012345.67+0900")
+    assert !OpenEhr::AssumedLibraryTypes::ISO8601_TIME.valid_iso8601_time?("242345.67+0900")
+    assert !OpenEhr::AssumedLibraryTypes::ISO8601_TIME.valid_iso8601_time?("242345.67+0900")
+    assert OpenEhr::AssumedLibraryTypes::ISO8601_TIME.valid_iso8601_time?("240000")
+    assert OpenEhr::AssumedLibraryTypes::ISO8601_TIME.valid_iso8601_time?("240000Z")
+    assert !OpenEhr::AssumedLibraryTypes::ISO8601_TIME.valid_iso8601_time?("240000.011Z")
+  end
+
+  def test_iso_8601_date_time
+    assert_equal 2009, @iso8601_date_time.year
+    assert_equal 4, @iso8601_date_time.month
+    assert_equal 27, @iso8601_date_time.day
+    assert_equal 15, @iso8601_date_time.hour
+    assert_equal 55, @iso8601_date_time.minute
+    assert_equal 37, @iso8601_date_time.second
+    assert_equal 0.32, @iso8601_date_time.fractional_second
+    assert_equal '+0900', @iso8601_date_time.timezone
+    assert_equal '2009-04-27T15:55:37.32+0900', @iso8601_date_time.as_string
+    assert_nothing_raised(Exception){
+      @iso8601_date_time.year = 2008 }
+    assert_equal 2008, @iso8601_date_time.year
+  end
+
+  def test_iso8601_timezone
+    @iso8601_timezone.sign = "+1"
+    @iso8601_timezone.hour = 0
+    @iso8601_timezone.minute = 0
+    assert @iso8601_timezone.is_gmt?
+    assert_equal "Z+0000", @iso8601_timezone.as_string
+    @iso8601_timezone.hour = 9
+    assert_equal "Z+0900", @iso8601_timezone.as_string
+    assert !@iso8601_timezone.is_gmt?
+    @iso8601_timezone.sign = "-1"
+    @iso8601_timezone.hour = 4
+    @iso8601_timezone.minute = 30
+    assert_equal "Z-0430", @iso8601_timezone.as_string
+  end
+
+  def test_iso8601_duration
+    assert_equal 1, @iso8601_duration.years
+    assert_equal 2, @iso8601_duration.months
+    assert_equal 3, @iso8601_duration.weeks
+    assert_equal 4, @iso8601_duration.days
+    assert_equal 5, @iso8601_duration.hours
+    assert_equal 6, @iso8601_duration.minutes
+    assert_equal 7, @iso8601_duration.seconds
+    assert_equal 0.8, @iso8601_duration.fractional_second
+    assert_equal 'P1Y2M3W4DT5H6M7.8S', @iso8601_duration.as_string
+    assert_raise(ArgumentError){@iso8601_duration.years = -1}
+    assert_nothing_raised(Exception){@iso8601_duration.years = nil}
+    assert_nil @iso8601_duration.years
+    assert_equal 'P2M3W4DT5H6M7.8S', @iso8601_duration.as_string
+    assert_nothing_raised(Exception){@iso8601_duration.years = 2}
+    assert_equal 2, @iso8601_duration.years
+    assert_nothing_raised(Exception){@iso8601_duration.months = nil}
+    assert_nil @iso8601_duration.months
+    assert_equal 'P2Y3W4DT5H6M7.8S', @iso8601_duration.as_string
+    assert_raise(ArgumentError){@iso8601_duration.months = -1}
+    assert_nothing_raised(Exception){@iso8601_duration.months = 3}
+    assert_equal 3, @iso8601_duration.months
+    assert_nothing_raised(Exception){@iso8601_duration.weeks = nil}
+    assert_nil @iso8601_duration.weeks
+    assert_equal 'P2Y3M4DT5H6M7.8S', @iso8601_duration.as_string
+    assert_raise(ArgumentError){@iso8601_duration.weeks = -1}
+    assert_nothing_raised(Exception){@iso8601_duration.weeks = 1}
+    assert_equal 'P2Y3M1W4DT5H6M7.8S', @iso8601_duration.as_string
+    assert_raise(ArgumentError){@iso8601_duration.days = -1}
+    assert_nothing_raised(Exception){@iso8601_duration.days = nil}
+    assert_nil @iso8601_duration.days
+    assert_equal 'P2Y3M1WT5H6M7.8S', @iso8601_duration.as_string
+    assert_nothing_raised(Exception){@iso8601_duration.hours = nil}
+    assert_nil @iso8601_duration.hours
+    assert_equal 'P2Y3M1W', @iso8601_duration.as_string
+    assert_raise(ArgumentError){@iso8601_duration.hours = -1}
+    assert_nothing_raised(Exception){@iso8601_duration.hours = 5}
+    assert_equal 5, @iso8601_duration.hours
+    assert_equal 'P2Y3M1WT5H6M7.8S', @iso8601_duration.as_string
+    assert_raise(ArgumentError){@iso8601_duration.minutes = -1}
+    assert_nothing_raised(Exception){@iso8601_duration.minutes = nil}
+    assert_nil @iso8601_duration.minutes
+    assert_equal 'P2Y3M1WT5H', @iso8601_duration.as_string
+    assert_nothing_raised(Exception){@iso8601_duration.minutes = 0}
+    assert_equal 0, @iso8601_duration.minutes
+    assert_equal 'P2Y3M1WT5H0M7.8S', @iso8601_duration.as_string
+    assert_raise(ArgumentError){@iso8601_duration.seconds = -1}
+    assert_nothing_raised(Exception){@iso8601_duration.seconds = nil}
+    assert_nil @iso8601_duration.seconds
+    assert_equal 'P2Y3M1WT5H0M', @iso8601_duration.as_string
+    assert_nothing_raised(Exception){@iso8601_duration.seconds = 10}
+    assert_equal 10, @iso8601_duration.seconds
+    assert_equal 'P2Y3M1WT5H0M10.8S', @iso8601_duration.as_string
+    assert_raise(ArgumentError){@iso8601_duration.fractional_second = 1.0}
+    assert_raise(ArgumentError){@iso8601_duration.fractional_second = -0.1}
+    assert_nothing_raised(Exception){@iso8601_duration.fractional_second = nil}
+    assert_nil @iso8601_duration.fractional_second
+    assert_equal 'P2Y3M1WT5H0M10S', @iso8601_duration.as_string
+    assert_nothing_raised(Exception){@iso8601_duration.fractional_second = 0.2}
+    assert_equal 0.2, @iso8601_duration.fractional_second
+    assert_equal 'P2Y3M1WT5H0M10.2S', @iso8601_duration.as_string
+  end
+end
Index: ruby/branches/0.5/test/unit/open_ehr/rm/common/archetyped_test.rb
===================================================================
--- ruby/branches/0.5/test/unit/open_ehr/rm/common/archetyped_test.rb	(revision 191)
+++ ruby/branches/0.5/test/unit/open_ehr/rm/common/archetyped_test.rb	(revision 191)
@@ -0,0 +1,139 @@
+require 'test/unit'
+require 'set'
+
+#include OpenEhr::RM::Common::Archetyped
+class RM_Common_Archetyped_Test < Test::Unit::TestCase
+  def setup
+    @dv_text = OpenEhr::RM::DataTypes::Text::DvText.new('Test')
+    @uid_based_id = OpenEhr::RM::Support::Identification::UidBasedId.new('rrip::0.0.5')
+    @archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol","0.0.3")
+    @template_id = OpenEhr::RM::Support::Identification::TemplateId.new('1.0.1')
+    assert_nothing_raised(Exception){@archetyped = OpenEhr::RM::Common::Archetyped::Archetyped.new(@archetype_id, '1.0.1')}
+    assert_nothing_raised(Exception){@link = OpenEhr::RM::Common::Archetyped::Link.new(OpenEhr::RM::DataTypes::Text::DvText.new("generic"), OpenEhr::RM::DataTypes::Uri::DvEhrUri.new("ehr://test/"),OpenEhr::RM::DataTypes::Text::DvText.new("problem"))}
+    assert_nothing_raised(Exception){
+      @pathable = OpenEhr::RM::Common::Archetyped::Pathable.new }
+    name = OpenEhr::RM::DataTypes::Text::DvText.new('blood')
+    links = Set.new([@uid_based_id])
+    assert_nothing_raised(Exception){
+      @locatable = OpenEhr::RM::Common::Archetyped::Locatable.new(:archetype_node_id => 'at0001',
+                                 :name => name,
+                                 :links => links)}
+    provider = OpenEhr::RM::Common::Generic::PartyIdentified.new(:name => 'NERV')
+    location = OpenEhr::RM::Common::Generic::PartyIdentified.new(:name => 'GEOFRONT')
+    object_version_id = OpenEhr::RM::Support::Identification::ObjectVersionId.new('ABC::DEF::1.3.4')
+    party_ref = OpenEhr::RM::Support::Identification::PartyRef.new('local', 'ORGANISATION', object_id)
+    assert_nothing_raised(Exception){
+      @feeder_audit_details = OpenEhr::RM::Common::Archetyped::FeederAuditDetails.new(:system_id => 'MAGI',
+                                                       :provider => provider,
+                                                       :location => location,
+                                                       :time => OpenEhr::RM::DataTypes::Quantity::DateTime::DvDateTime.new('2009-07-03T12:16:31'),
+                                                       :subject => OpenEhr::RM::Common::Generic::PartyProxy.new(:external_ref => party_ref),
+                                                       :version_id => '0.0.4')}
+    feeder_audit_details = OpenEhr::RM::Common::Archetyped::FeederAuditDetails.new(:system_id => 'AKAGI')
+    dv_identifier = DvIdentifier.new('NERV', 'MELCHIOR', 'RITSUKO', 'COMPUTER')
+    feeder_audit_details2 = OpenEhr::RM::Common::Archetyped::FeederAuditDetails.new(:system_id => 'KATSURAGI')
+    dv_identifier2 = DvIdentifier.new('NERV', 'SHOGOUKI', 'MISATO', 'EVANGELION')
+    charset = OpenEhr::RM::DataTypes::Text::CodePhrase.new('UTF-8','character-sets')
+    language = OpenEhr::RM::DataTypes::Text::CodePhrase.new('ja', 'languages')
+
+    dv_encapsulated = OpenEhr::RM::DataTypes::Encapsulated::DvEncapsulated.new(charset, language, 10)
+    assert_nothing_raised(Exception){
+      @feeder_audit = OpenEhr::RM::Common::Archetyped::FeederAudit.new(:originating_system_audit => feeder_audit_details,
+                                       :originating_system_item_ids => [dv_identifier],
+                                       :feeder_system_audit => feeder_audit_details2,
+                                       :feeder_system_item_ids => [dv_identifier2],
+                                       :original_content => dv_encapsulated)}
+  end
+
+  def test_init
+    assert_instance_of OpenEhr::RM::Common::Archetyped::Archetyped, @archetyped
+    assert_instance_of OpenEhr::RM::Common::Archetyped::Link, @link
+    assert_instance_of OpenEhr::RM::Common::Archetyped::Pathable, @pathable
+    assert_instance_of OpenEhr::RM::Common::Archetyped::Locatable, @locatable
+    assert_instance_of OpenEhr::RM::Common::Archetyped::FeederAuditDetails, @feeder_audit_details
+    assert_instance_of OpenEhr::RM::Common::Archetyped::FeederAudit, @feeder_audit
+  end
+
+  def test_archetyped
+    assert_equal @archetype_id, @archetyped.archetype_id
+    assert_equal '1.0.1', @archetyped.rm_version
+    assert_raise(ArgumentError){@archetyped.archetype_id = nil}
+    assert_raise(ArgumentError){@archetyped.rm_version = nil}
+    assert_raise(ArgumentError){@archetyped.rm_version = ''}
+    assert_nothing_raised(Exception){@archetyped.template_id = @template_id}
+    assert_equal @template_id, @archetyped.template_id
+    archetype_id2 = OpenEhr::RM::Support::Identification::ArchetypeId.new("1.0.2", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol","0.0.3")
+    assert_nothing_raised(ArgumentError){@archetyped.archetype_id = archetype_id2}
+    assert_equal archetype_id2, @archetyped.archetype_id
+    assert_nothing_raised(ArgumentError){@archetyped.rm_version = '1.0.2'}
+    assert_equal '1.0.2', @archetyped.rm_version
+  end
+
+  def test_pathable_parent
+    assert_nil @pathable.parent
+  end
+
+  def test_locatable_archetype_node_id
+    assert_equal 'at0001', @locatable.archetype_node_id
+  end
+
+  def test_locatable_name
+    assert_equal 'blood', @locatable.name.value
+  end
+
+  def test_locatable_link
+    assert_equal 'rrip::0.0.5', @locatable.links.to_a[0].value
+  end
+
+  def test_locatable_name_valid
+    assert_raise(ArgumentError){@locatable.name = nil }
+  end
+
+  def test_locatable_link_valid
+    assert_raise(ArgumentError){@locatable.links = Set[]}
+  end
+
+  def test_locatable_archetype_id_not_nil
+    assert_raise(ArgumentError){@locatable.archetype_node_id = nil}
+  end
+
+  def test_locatable_archetype_id_not_empty
+    assert_raise(ArgumentError){@locatable.archetype_node_id = ''}
+  end
+
+  def test_link
+    # test constructor
+    assert_equal 'generic', @link.meaning.value
+    assert_equal 'ehr://test/', @link.target.value
+    assert_equal 'problem', @link.type.value
+    # test meaning
+    assert_nothing_raised(Exception){@link.meaning = OpenEhr::RM::DataTypes::Text::DvText.new('clinical')}
+    assert_equal 'clinical', @link.meaning.value
+    assert_raise(ArgumentError){@link.meaning = nil}
+    # test target
+    assert_nothing_raised(Exception){@link.target = OpenEhr::RM::DataTypes::Uri::DvEhrUri.new("ehr://try/")}
+    assert_equal 'ehr://try/', @link.target.value
+    assert_raise(ArgumentError){@link.target = nil}
+    # test type
+    assert_nothing_raised(Exception){@link.type = OpenEhr::RM::DataTypes::Text::DvText.new("issue")}
+    assert_equal 'issue', @link.type.value
+    assert_raise(ArgumentError){@link.type = nil}
+  end
+
+  def test_feeder_audit
+    assert_equal 'AKAGI', @feeder_audit.originating_system_audit.system_id
+    assert_equal 'RITSUKO', @feeder_audit.originating_system_item_ids[0].issuer
+    assert_equal 'KATSURAGI', @feeder_audit.feeder_system_audit.system_id
+    assert_equal 'MISATO', @feeder_audit.feeder_system_item_ids[0].issuer
+    assert_equal 'UTF-8', @feeder_audit.original_content.charset.code_string
+  end
+
+  def test_feeder_audit_detail
+    assert_equal 'MAGI', @feeder_audit_details.system_id
+    assert_equal 'NERV', @feeder_audit_details.provider.name
+    assert_equal 'GEOFRONT', @feeder_audit_details.location.name
+    assert_equal 2009, @feeder_audit_details.time.year
+    assert_equal 'local', @feeder_audit_details.subject.external_ref.namespace
+    assert_equal '0.0.4', @feeder_audit_details.version_id
+  end
+end
Index: ruby/branches/0.5/test/unit/open_ehr/rm/common/change_control_test.rb
===================================================================
--- ruby/branches/0.5/test/unit/open_ehr/rm/common/change_control_test.rb	(revision 191)
+++ ruby/branches/0.5/test/unit/open_ehr/rm/common/change_control_test.rb	(revision 191)
@@ -0,0 +1,185 @@
+require 'test/unit'
+require 'set'
+
+class RM_Common_Change_Control_Test < Test::Unit::TestCase
+  def setup
+    object_version_id1 = ObjectVersionId.new('ABC::DEF::2.2.3')
+    object_version_id2 = ObjectVersionId.new('GHI::JKL::4.5.6')
+    object_id = ObjectId.new('ehr://uniqueid1020')
+    dv_date_time = OpenEhr::RM::DataTypes::Quantity::DateTime::DvDateTime.new('2009-07-06T21:10:12')
+    party_ref = PartyRef.new('unknown', 'ORGANISATION', object_id)
+    party_proxy = OpenEhr::RM::Common::Generic::PartyProxy.new(:external_ref => party_ref)
+    terminology_id = TerminologyId.new('openehr(1.0.2)')
+    code_phrase = OpenEhr::RM::DataTypes::Text::CodePhrase.new('249', terminology_id)
+    dv_coded_text = OpenEhr::RM::DataTypes::Text::DvCodedText.new('creation', code_phrase)
+    audit_details = OpenEhr::RM::Common::Generic::AuditDetails.new(:system_id => 'MAGI',
+                                      :committer => party_proxy,
+                                      :time_committed => dv_date_time,
+                                      :change_type => dv_coded_text)
+    code_phrase = OpenEhr::RM::DataTypes::Text::CodePhrase.new('532', terminology_id)
+    dv_coded_text = OpenEhr::RM::DataTypes::Text::DvCodedText.new('complete', code_phrase)
+    object_id = ObjectId.new('ehr://test_location')
+    object_ref = ObjectRef.new('local', 'PARTY', object_id)
+    hier_object_id = HierObjectId.new('ABC')
+    assert_nothing_raised(Exception){
+      @version = OpenEhr::RM::Common::ChangeControl::Version.new(:uid => object_version_id1,
+                             :preceding_version_uid => object_version_id2,
+                             :lifecycle_state => dv_coded_text,
+                             :commit_audit => audit_details,
+                             :contribution => object_ref,
+                             :signature => 'test_version',
+                             :data => 'data')}
+    object_version_id3 = ObjectVersionId.new('MNO::PQR::7.8.9')
+    object_version_id4 = ObjectVersionId.new('STU::VWX::1.2.3')
+    code_phrase = OpenEhr::RM::DataTypes::Text::CodePhrase.new('240', terminology_id)
+    dv_coded_text2 = OpenEhr::RM::DataTypes::Text::DvCodedText.new('signed', code_phrase)
+    attestation = OpenEhr::RM::Common::Generic::Attestation.new(:system_id => 'NERV',
+                                  :committer => party_proxy,
+                                  :time_committed => dv_date_time,
+                                  :change_type => dv_coded_text,
+                                  :reason => OpenEhr::RM::DataTypes::Text::DvText.new('signed'))
+    dv_date_time = OpenEhr::RM::DataTypes::Quantity::DateTime::DvDateTime.new('2009-07-07T21:10:12')
+    audit_details = OpenEhr::RM::Common::Generic::AuditDetails.new(:system_id => 'MAGI',
+                                      :committer => party_proxy,
+                                      :time_committed => dv_date_time,
+                                      :change_type => dv_coded_text)
+    assert_nothing_raised(Exception){
+      @original_version = OpenEhr::RM::Common::ChangeControl::OriginalVersion.new(:uid => object_version_id3,
+                                               :preceding_version_uid => object_version_id4,
+                                               :other_input_version_uids => Set[object_version_id1, object_version_id2],
+                                               :commit_audit => audit_details,
+                                               :contribution => object_ref,
+                                               :attestations => [attestation],
+                                               :data => 'data',
+                                               :lifecycle_state => dv_coded_text)}
+    dv_date_time = OpenEhr::RM::DataTypes::Quantity::DateTime::DvDateTime.new('2009-07-08T21:10:12')
+    audit_details = OpenEhr::RM::Common::Generic::AuditDetails.new(:system_id => 'CASPER',
+                                      :committer => party_proxy,
+                                      :time_committed => dv_date_time,
+                                      :change_type => dv_coded_text,
+                                      :description => 'for contribution')
+    object_ref = ObjectRef.new('unknown', 'PARTY', object_id)
+    assert_nothing_raised(Exception){
+      @imported_version = OpenEhr::RM::Common::ChangeControl::ImportedVersion.new(:item => @original_version,
+                                               :commit_audit => audit_details,
+                                               :contribution => object_ref,
+                                               :signature => 'import test')}
+    assert_nothing_raised(Exception){
+      @contribution = OpenEhr::RM::Common::ChangeControl::Contribution.new(:uid => hier_object_id,
+                                       :versions => Set[object_ref],
+                                       :audit => audit_details)}
+    dv_date_time = OpenEhr::RM::DataTypes::Quantity::DateTime::DvDateTime.new('2009-07-08T18:10:12')
+    audit_details = OpenEhr::RM::Common::Generic::AuditDetails.new(:system_id => 'MAGI',
+                                      :committer => party_proxy,
+                                      :time_committed => dv_date_time,
+                                      :change_type => dv_coded_text)
+    @trunk_version = OpenEhr::RM::Common::ChangeControl::Version.new(:uid => object_version_id4,
+                                :lifecycle_state => dv_coded_text,
+                                :commit_audit => audit_details,
+                                :contribution => object_ref,
+                                :change_type => dv_coded_text)
+    assert_nothing_raised(Exception){
+      @versioned_object = OpenEhr::RM::Common::ChangeControl::VersionedObject.new(:uid => hier_object_id,
+                                               :owner_id => object_ref,
+                                               :time_created => dv_date_time,
+                                               :all_versions => [@version,@original_version,@imported_version,@trunk_version])}
+  end
+
+  def test_init
+    assert_instance_of OpenEhr::RM::Common::ChangeControl::Version, @version
+    assert_instance_of OpenEhr::RM::Common::ChangeControl::OriginalVersion, @original_version
+    assert_instance_of OpenEhr::RM::Common::ChangeControl::ImportedVersion, @imported_version
+    assert_instance_of OpenEhr::RM::Common::ChangeControl::Contribution, @contribution
+    assert_instance_of OpenEhr::RM::Common::ChangeControl::VersionedObject, @versioned_object
+  end
+
+  def test_version
+    assert_equal 'ABC::DEF::2.2.3', @version.uid.value
+    assert !@version.uid.version_tree_id.is_first?
+    assert_equal 'GHI::JKL::4.5.6', @version.preceding_version_uid.value
+    assert_equal '532', @version.lifecycle_state.defining_code.code_string
+    assert_equal 'MAGI', @version.commit_audit.system_id
+    assert_equal 'local', @version.contribution.namespace
+    assert_equal 'test_version', @version.signature
+    assert_equal 'ABC', @version.owner_id.value
+    assert_equal 'data', @version.data
+    assert @version.is_branch?
+  end
+
+  def test_original_version
+    assert_equal 'MNO::PQR::7.8.9', @original_version.uid.value
+    assert_equal 'NERV', @original_version.attestations[0].system_id
+  end
+
+  def test_imported_version
+    assert_equal 'import test', @imported_version.signature
+    assert_equal 'MNO::PQR::7.8.9', @imported_version.item.uid.value
+    assert_equal 'CASPER', @imported_version.commit_audit.system_id
+    assert_equal 'unknown', @imported_version.contribution.namespace
+    assert_equal 'STU::VWX::1.2.3', @imported_version.preceding_version_uid.value
+    assert_equal '532', @imported_version.lifecycle_state.defining_code.code_string
+  end
+
+  def test_contribution
+    assert_equal 'ABC', @contribution.uid.value
+    assert_equal 'PARTY', @contribution.versions.to_a[0].type
+    assert_equal 'for contribution', @contribution.audit.description
+  end
+
+  def test_versioned_object
+    assert_equal 'ABC', @versioned_object.uid.value
+    assert_equal 'unknown', @versioned_object.owner_id.namespace
+    assert_equal 18, @versioned_object.time_created.hour
+    assert_equal [@version, @original_version, @imported_version, @trunk_version],
+                    @versioned_object.all_versions
+    assert_equal 4, @versioned_object.version_count
+    assert_equal [@version.uid, @original_version.uid, @imported_version.uid, @trunk_version.uid],
+                   @versioned_object.all_version_ids
+    assert @versioned_object.has_version_id?(@version.uid)
+    assert !@versioned_object.is_original_version?(@version.uid)
+    assert @versioned_object.is_original_version?(@original_version.uid)
+    assert @versioned_object.has_version_at_time?(OpenEhr::RM::DataTypes::Quantity::DateTime::DvDateTime.new('2009-07-06T21:10:12'))
+    assert_equal @version, @versioned_object.version_with_id(@version.uid)
+    assert_equal @version, @versioned_object.version_at_time(@version.commit_audit.time_committed)
+    assert_equal @imported_version, @versioned_object.latest_version
+    assert_equal @trunk_version, @versioned_object.latest_trunk_version
+    assert_equal 'complete', @versioned_object.trunk_lifecycle_state.value
+    assert_equal '2009-07-08T18:10:12', @versioned_object.revision_history.most_recent_version_time_committed
+    assert_nothing_raised(Exception){
+      @versioned_object.commit_original_version(:contribution => @original_version.contribution,
+                                                :uid => @original_version.uid,
+                                                :preceding_version_uid => @original_version.preceding_version_uid,
+                                                :commit_audit => @original_version.commit_audit,
+                                                :attestations => @original_version.attestations,
+                                                :lifecycle_state => @original_version.lifecycle_state,
+                                                :data => 'commit original',
+                                                :signature => 'testtett')}
+    assert_equal 5, @versioned_object.version_count
+    assert_nothing_raised(Exception){
+      @versioned_object.commit_original_merged_version(:contribution => @original_version.contribution,
+                                                       :uid => @original_version.uid,
+                                                       :preceding_version_uid => @original_version.preceding_version_uid,
+                                                       :commit_audit => @original_version.commit_audit,
+                                                       :lifecycle_state => @original_version.lifecycle_state,
+                                                       :attestations => @original_version.attestations,
+                                                       :data => @original_version.data,
+                                                       :other_input_version_uids => @original_version.other_input_version_uids,
+                                                       :signature => @original_version.signature)}
+    assert_equal 6, @versioned_object.version_count
+    assert_nothing_raised(Exception){
+      @versioned_object.commit_imported_version(:contribution => @imported_version.contribution,
+                                                :commit_audit => @imported_version.commit_audit,
+                                                :item => @imported_version.item)}
+    assert_equal 7, @versioned_object.version_count
+    dv_date_time = OpenEhr::RM::DataTypes::Quantity::DateTime::DvDateTime.new('2009-07-07T22:11:31')
+    attestation = Attestation.new(:system_id => 'NERV2',
+                                  :committer => @version.contribution,
+                                  :time_committed => dv_date_time,
+                                  :change_type => @original_version.commit_audit.change_type,
+                                  :reason => OpenEhr::RM::DataTypes::Text::DvText.new('signed'))
+    assert_nothing_raised(Exception){
+      @versioned_object.commit_attestation(:attestation => attestation,
+                                           :uid => @original_version.uid,
+                                           :signature => 'new signature')}
+  end
+end
Index: ruby/branches/0.5/test/unit/open_ehr/rm/common/dierctory_test.rb
===================================================================
--- ruby/branches/0.5/test/unit/open_ehr/rm/common/dierctory_test.rb	(revision 191)
+++ ruby/branches/0.5/test/unit/open_ehr/rm/common/dierctory_test.rb	(revision 191)
@@ -0,0 +1,26 @@
+require 'test/unit'
+require 'set'
+
+class RM_Common_Directory_Test < Test::Unit::TestCase
+  def setup
+    archetype_node_id = 'at0001'
+    name = OpenEhr::RM::DataTypes::Text::DvText.new('folder_test')
+    object_id = ObjectId.new('1.1.1')
+    object_ref = ObjectRef.new('local', 'PARTY', object_id)
+    assert_nothing_raised(Exception){
+      @folder = OpenEhr::RM::Common::Directory::Folder.new(:archetype_node_id => archetype_node_id,
+                           :name => name,
+                           :items => [object_ref])}
+    
+
+  end
+  
+  def test_init
+    assert_instance_of OpenEhr::RM::Common::Directory::Folder, @folder
+  end
+
+  def test_folder
+    assert_equal 'at0001', @folder.archetype_node_id
+    assert_equal 'local', @folder.items[0].namespace
+  end
+end
Index: ruby/branches/0.5/test/unit/open_ehr/rm/common/generic_test.rb
===================================================================
--- ruby/branches/0.5/test/unit/open_ehr/rm/common/generic_test.rb	(revision 191)
+++ ruby/branches/0.5/test/unit/open_ehr/rm/common/generic_test.rb	(revision 191)
@@ -0,0 +1,182 @@
+require 'test/unit'
+require 'set'
+
+class RM_Common_Generic_Test < Test::Unit::TestCase
+  def setup
+    assert_nothing_raised(Exception){party_proxy = PartyProxy.new}
+    object_id = ObjectId.new('0.0.4')
+    party_ref = PartyRef.new('unknown', 'ORGANISATION', object_id)
+    assert_nothing_raised(Exception){
+      @party_proxy = PartyProxy.new(:external_ref => party_ref)}
+    assert_nothing_raised(Exception){party_self = PartySelf.new}
+    assert_nothing_raised(Exception){
+      @party_self = PartySelf.new(:external_ref => party_ref)}
+    assert_raise(ArgumentError){
+      party_identified = PartyIdentified.new}
+
+    identifiers = []
+    identifiers << DvIdentifier.new('NERV', 'MELCHIOR', 'GENDO', 'COMPUTER')
+    identifiers << DvIdentifier.new('NERV', 'CASPER', 'GENDO', 'COMPUTER')
+    identifiers << DvIdentifier.new('NERV', 'BALTHAZAR', 'GENDO', 'COMPUTER')
+    assert_nothing_raised(Exception){
+      @party_identified = PartyIdentified.new(:name => 'NERV',
+                                               :external_ref => party_ref,
+                                               :identifier => identifiers)}
+
+    terminology_id = TerminologyId.new('test(0.04)')
+    code_phrase = CodePhrase.new('self', terminology_id)
+    dv_coded_text = DvCodedText.new('Seele',code_phrase)
+    assert_nothing_raised(Exception){
+      @party_related = PartyRelated.new(:name => 'GEHIRN',
+                                         :relationship => dv_coded_text)}
+    dv_text = DvText.new('commiter')
+    dv_coded_text = DvCodedText.new('present',terminology_id)
+    dv_date_time1 = OpenEhr::RM::DataTypes::Quantity::DateTime::DvDateTime.new('2009-07-04T16:30:00')
+    dv_date_time2 = OpenEhr::RM::DataTypes::Quantity::DateTime::DvDateTime.new('2009-07-14T00:00:00')
+    dv_interval = OpenEhr::RM::DataTypes::Quantity::DvInterval.new(dv_date_time1, dv_date_time2)
+    assert_nothing_raised(Exception){
+      @participation = Participation.new(:performer => @party_proxy,
+                                         :function => dv_text,
+                                         :mode => dv_coded_text,
+                                         :time => dv_interval)}
+    dv_date_time = OpenEhr::RM::DataTypes::Quantity::DateTime::DvDateTime.new('2009-07-04T18:56:00')
+    terminology_id = TerminologyId.new('openehr(1.0.2)')
+    code_phrase = CodePhrase.new('249', terminology_id)
+    dv_coded_text = DvCodedText.new('creation', code_phrase)
+    dv_text = DvText.new('test environment')
+    assert_nothing_raised(Exception){
+      @audit_details = AuditDetails.new(:system_id => 'MAGI',
+                                         :committer => @party_proxy,
+                                         :time_committed => dv_date_time,
+                                         :change_type => dv_coded_text,
+                                         :description => dv_text)}
+    dv_text = DvText.new('authorisation')
+    dv_ehr_uri = OpenEhr::RM::DataTypes::Uri::DvEhrUri.new('ehr://test/')
+    assert_nothing_raised(Exception){
+      @attestation = Attestation.new(:system_id => 'NERV',
+                                     :committer => @party_proxy,
+                                     :time_committed => dv_date_time,
+                                     :change_type => dv_coded_text,
+                                     :reason => dv_text,
+                                     :description => dv_text,
+                                     :proof => 'hashedstring',
+                                     :items => Set[dv_ehr_uri])}
+    object_version_id = ObjectVersionId.new('SHOGOUKI::NERV::1.1.1')
+    audit_details2 = AuditDetails.new(:system_id => 'MAGI',
+                                       :committer => @party_proxy,
+                                       :time_committed => dv_date_time2,
+                                       :change_type => dv_coded_text)
+    assert_nothing_raised(Exception){
+      @revision_history_item = RevisionHistoryItem.new(:audits => [@audit_details, audit_details2],
+                                                         :version_id => object_version_id)}
+    dv_date_time3 = OpenEhr::RM::DataTypes::Quantity::DateTime::DvDateTime.new('2009-07-14T12:00:00')
+    dv_date_time4 = OpenEhr::RM::DataTypes::Quantity::DateTime::DvDateTime.new('2009-07-15T00:00:00')
+    audit_details3 = AuditDetails.new(:system_id => 'MAGI',
+                                     :committer => @party_proxy,
+                                     :time_committed => dv_date_time3,
+                                     :change_type => dv_coded_text)
+    audit_details4 = AuditDetails.new(:system_id => 'MAGI',
+                                     :committer => @party_proxy,
+                                     :time_committed => dv_date_time4,
+                                     :change_type => dv_coded_text)
+    object_version_id = ObjectVersionId.new('NIGOUKI::NERV::2.2.2')
+    revision_history_item2 = RevisionHistoryItem.new(:audits => [audit_details3, audit_details4],
+                                                      :version_id => object_version_id)
+    assert_nothing_raised(Exception){
+      @revision_history = RevisionHistory.new([@revision_history_item, revision_history_item2])}
+  end
+
+  def test_init
+    assert_instance_of PartyProxy, @party_proxy
+    assert_instance_of PartySelf, @party_self
+    assert_instance_of PartyIdentified, @party_identified
+    assert_instance_of Participation, @participation
+    assert_instance_of AuditDetails, @audit_details
+    assert_instance_of Attestation, @attestation
+    assert_instance_of RevisionHistoryItem, @revision_history_item
+    assert_instance_of RevisionHistory, @revision_history
+  end
+
+  def test_party_proxy
+    assert_equal 'unknown', @party_proxy.external_ref.namespace
+  end
+
+  def test_party_self
+    assert_equal 'ORGANISATION', @party_self.external_ref.type
+  end
+
+  def test_party_identified
+    assert_equal 'NERV', @party_identified.name
+    assert_equal '0.0.4', @party_identified.external_ref.id.value
+    identifiers = @party_identified.identifier
+    ids = [ ]
+    identifiers.each do |id|
+      ids << id.id
+    end
+    assert_equal %w[MELCHIOR CASPER BALTHAZAR], ids
+  end
+
+  def test_party_related
+    assert_equal 'GEHIRN', @party_related.name
+  end
+
+  def test_participation
+    assert_equal 'unknown', @participation.performer.external_ref.namespace
+    assert_equal 'commiter', @participation.function.value
+    assert_equal 'present', @participation.mode.value
+    assert_equal 2009, @participation.time.lower.year
+  end
+
+  def test_audit_details
+    assert_equal 'MAGI', @audit_details.system_id
+    assert_equal 'unknown', @audit_details.committer.external_ref.namespace
+    assert_equal '2009-07-04T18:56:00', @audit_details.time_committed.as_string
+    assert_equal 'creation', @audit_details.change_type.value
+    assert_equal 'test environment', @audit_details.description.value
+  end
+
+  def test_attestation
+    assert_equal 'NERV', @attestation.system_id
+    assert_equal 'unknown', @attestation.committer.external_ref.namespace
+    assert_equal '249', @attestation.change_type.defining_code.code_string
+    assert_equal 7, @attestation.time_committed.month
+    assert_equal 'authorisation', @attestation.reason.value
+    assert_equal 'authorisation', @attestation.description.value
+    assert_equal 'hashedstring', @attestation.proof
+    assert_equal 'ehr://test/', @attestation.items.to_a[0].value
+  end
+
+  def test_revision_history_item
+    assert_equal 'SHOGOUKI::NERV::1.1.1', @revision_history_item.version_id.value
+    assert_equal 'MAGI', @revision_history_item.audits[0].system_id
+  end
+
+  def test_revision_history
+    assert_equal 'NIGOUKI::NERV::2.2.2', @revision_history.most_recent_version
+    assert_equal '2009-07-14T12:00:00', @revision_history.most_recent_version_time_committed
+  end
+end
+
+class RM_Common_Directory_Test < Test::Unit::TestCase
+  def setup
+    archetype_node_id = 'at0001'
+    name = DvText.new('folder_test')
+    object_id = ObjectId.new('1.1.1')
+    object_ref = ObjectRef.new('local', 'PARTY', object_id)
+    assert_nothing_raised(Exception){
+      @folder = Folder.new(:archetype_node_id => archetype_node_id,
+                           :name => name,
+                           :items => [object_ref])}
+    
+
+  end
+  
+  def test_init
+    assert_instance_of OpenEhr::RM::Common::Directory::Folder, @folder
+  end
+
+  def test_folder
+    assert_equal 'at0001', @folder.archetype_node_id
+    assert_equal 'local', @folder.items[0].namespace
+  end
+end
Index: ruby/branches/0.5/test/unit/open_ehr/rm/common/resource_test.rb
===================================================================
--- ruby/branches/0.5/test/unit/open_ehr/rm/common/resource_test.rb	(revision 191)
+++ ruby/branches/0.5/test/unit/open_ehr/rm/common/resource_test.rb	(revision 191)
@@ -0,0 +1,71 @@
+require 'test/unit'
+require 'set'
+
+class RM_Common_Resource_Test < Test::Unit::TestCase
+  def setup
+    terminology_id = TerminologyId.new('openehr')
+    code_phrase = CodePhrase.new('ja', terminology_id)
+    @translation_details = OpenEhr::RM::Common::Resource::TranslationDetails.new(:language => code_phrase, :author => {'KOBAYASHI, Shinji', 'Ehime Univ'},
+  :accreditation => 'jp', :other_details => {'ruby', 'test'})
+    @authored_resource = OpenEhr::RM::Common::Resource::AuthoredResource.new(:original_language => code_phrase, :translations => {'ja', @translation_details}, :description => "test")
+    @resource_description_item = OpenEhr::RM::Common::Resource::ResourceDescriptionItem.new(:language => code_phrase,
+              :purpose => 'test',
+              :keywords => %w[test ruby],
+              :use => 'unit test',
+              :misuse => 'real use',
+              :copyright => 'openEHR.jp',
+              :original_resource_uri => {'issuer', 'http://openehr.jp/'},
+              :other_details => {'samos', 'icicth7'})
+    @resource_description = OpenEhr::RM::Common::Resource::ResourceDescription.new(:original_author => {'KOBAYASHI, Shinji' => 'Ehime University'},
+    :lifecycle_state => 'experimental',
+    :details => {'ja', @resource_description_item},
+    :other_contributors => %w[aki tim hugh],
+    :resource_package_uri => 'http://openehr.jp/svn/ruby',
+    :other_details => {'ja', 'shikoku'},
+    :parent_resource => @authored_resource)
+    @authored_resource = OpenEhr::RM::Common::Resource::AuthoredResource.new(:original_language => code_phrase, :translations => {'ja', @translation_details}, :description => @resource_description)
+  end
+
+  def test_init
+    assert_instance_of OpenEhr::RM::Common::Resource::AuthoredResource, @authored_resource
+    assert_instance_of OpenEhr::RM::Common::Resource::TranslationDetails, @translation_details
+    assert_instance_of OpenEhr::RM::Common::Resource::ResourceDescriptionItem, @resource_description_item
+    assert_instance_of OpenEhr::RM::Common::Resource::ResourceDescription, @resource_description
+  end
+
+  def test_translation_details
+    assert_equal 'ja', @translation_details.language.code_string
+    assert_equal 'Ehime Univ', @translation_details.author['KOBAYASHI, Shinji']
+    assert_equal 'jp', @translation_details.accreditation
+    assert_equal 'test', @translation_details.other_details['ruby']
+  end
+
+  def test_authoured_resource
+    assert_equal 'ja', @authored_resource.original_language.code_string
+    assert_equal @translation_details, @authored_resource.translations['ja']
+    assert_equal 'experimental', @authored_resource.description.lifecycle_state
+    assert !@authored_resource.is_controlled?
+    assert_equal(Set['ja'], @authored_resource.languages_available)
+  end
+
+  def test_resource_description_item
+    assert_equal 'ja', @resource_description_item.language.code_string
+    assert_equal 'test', @resource_description_item.purpose
+    assert_equal %w[test ruby], @resource_description_item.keywords
+    assert_equal 'unit test', @resource_description_item.use
+    assert_equal 'real use', @resource_description_item.misuse
+    assert_equal 'openEHR.jp', @resource_description_item.copyright
+    assert_equal 'http://openehr.jp/', @resource_description_item.original_resource_uri['issuer']
+    assert_equal 'icicth7', @resource_description_item.other_details['samos']
+  end
+
+  def test_resource_description
+    assert_equal 'Ehime University', @resource_description.original_author['KOBAYASHI, Shinji']
+    assert_equal 'experimental', @resource_description.lifecycle_state
+    assert_equal 'test', @resource_description.details['ja'].purpose
+    assert_equal %w[aki tim hugh], @resource_description.other_contributors
+    assert_equal 'http://openehr.jp/svn/ruby', @resource_description.resource_package_uri
+    assert_equal 'shikoku', @resource_description.other_details['ja']
+    assert_equal 'ja', @resource_description.parent_resource.original_language.code_string
+  end
+end
Index: ruby/branches/0.5/test/unit/open_ehr/rm/data_structures/item_structure_test.rb
===================================================================
--- ruby/branches/0.5/test/unit/open_ehr/rm/data_structures/item_structure_test.rb	(revision 191)
+++ ruby/branches/0.5/test/unit/open_ehr/rm/data_structures/item_structure_test.rb	(revision 191)
@@ -0,0 +1,60 @@
+# refs #54
+#include OpenEhr::RM::DataStructures::ItemStructure
+#include OpenEhr::RM::DataStructures::ItemStructure::Representation
+#include OpenEhr::RM::DataTypes::Text
+
+class TestItemStructre < Test::Unit::TestCase
+  def setup
+    name = DvText.new('item structure')
+    @item_structure = OpenEhr::RM::DataStructures::ItemStructure::ItemStructure.new(:name => name,
+                                        :archetype_node_id => 'test')
+  end
+
+  def test_init
+    assert_instance_of OpenEhr::RM::DataStructures::ItemStructure::ItemStructure, @item_structure
+  end
+end
+
+class TestItemSingle < Test::Unit::TestCase
+  def setup
+    name = DvText.new('test_element')
+    @element = OpenEhr::RM::DataStructures::ItemStructure::Representation::Element.new(:name => name,
+                           :archetype_node_id => 'test_element')
+    item_single_name = DvText.new('item single')
+    @item_single = OpenEhr::RM::DataStructures::ItemStructure::ItemSingle.new(:name => item_single_name,
+                                  :archetype_node_id => 'test',
+                                  :item => @element)
+  end
+
+  def test_init
+    assert_instance_of OpenEhr::RM::DataStructures::ItemStructure::ItemSingle, @item_single
+  end
+
+  def test_element
+    assert_equal @element, @item_single.item
+  end
+
+  def test_as_hierarchy
+    @item_single.item = @element
+    assert_equal 'test_element', @item_single.as_hierarchy.name.value
+  end
+
+  def test_item_valid
+    invalid_element = nil
+    assert_raise(ArgumentError){@item_single.item = invalid_element}
+  end
+end
+class TestItemList < Test::Unit::TestCase
+  def setup
+    element_name = DvText.new('test_element')
+    @element = OpenEhr::RM::DataStructures::ItemStructure::Representation::Element.new(:name => element_name,
+                           :archetype_node_id => 'test_element')
+    item_list_name = DvText.new('item list name')
+    @item_list = OpenEhr::RM::DataStructures::ItemStructure::ItemList.new(:name => item_list_name,
+                              :archetype_node_id => 'item list')
+  end
+
+  def test_init
+    assert_instance_of OpenEhr::RM::DataStructures::ItemStructure::ItemList, @item_list
+  end
+end
Index: ruby/branches/0.5/test/unit/open_ehr/rm/data_structures_test.rb
===================================================================
--- ruby/branches/0.5/test/unit/open_ehr/rm/data_structures_test.rb	(revision 191)
+++ ruby/branches/0.5/test/unit/open_ehr/rm/data_structures_test.rb	(revision 191)
@@ -0,0 +1,25 @@
+require 'test/unit'
+require 'set'
+
+#include OpenEhr::RM::DataStructures
+#include OpenEhr::RM::DataStructures::ItemStructure
+
+class RmDataStructureTest < Test::Unit::TestCase
+  def setup
+    name = OpenEhr::RM::DataTypes::Text::DvText.new('blood')
+    uid = OpenEhr::RM::Support::Identification::UidBasedId.new('ehr::test-1')
+    links = Set.new([uid])
+    assert_nothing_raised(Exception){
+      @data_structure = OpenEhr::RM::DataStructures::DataStructure.new(:archetype_node_id => 'test',
+                                                                         :name => name,
+                                                                         :links => links) }
+  end
+
+  def test_init
+    assert_instance_of OpenEhr::RM::DataStructures::DataStructure, @data_structure
+  end
+
+  def test_data_structure
+    assert_raise(NotImplementedError){@data_structure.as_hierarchy}
+  end
+end
Index: ruby/branches/0.5/test/unit/open_ehr/rm/data_types/quantity/date_time_test.rb
===================================================================
--- ruby/branches/0.5/test/unit/open_ehr/rm/data_types/quantity/date_time_test.rb	(revision 191)
+++ ruby/branches/0.5/test/unit/open_ehr/rm/data_types/quantity/date_time_test.rb	(revision 191)
@@ -0,0 +1,83 @@
+require 'test/unit'
+
+class DateTimeTest < Test::Unit::TestCase
+#  include OpenEhr::RM::DataTypes::Quantity::DateTime
+  def setup
+    assert_nothing_raised(Exception){
+      @dv_temporal = OpenEhr::RM::DataTypes::Quantity::DateTime::DvTemporal.new('2008')}
+    assert_nothing_raised(Exception){
+      @dv_date = OpenEhr::RM::DataTypes::Quantity::DateTime::DvDate.new('2009-06-29')}
+    assert_nothing_raised(Exception){
+      @dv_time = OpenEhr::RM::DataTypes::Quantity::DateTime::DvTime.new('12:34:56.78')}
+    assert_nothing_raised(Exception){
+      @dv_date_time = OpenEhr::RM::DataTypes::Quantity::DateTime::DvDateTime.new('2009-06-29T12:34:56.78')}
+    assert_nothing_raised(Exception){
+      @dv_duration = OpenEhr::RM::DataTypes::Quantity::DateTime::DvDuration.new('P1Y2M3W4DT5H6M7.8S')}
+  end
+
+  def test_init
+    assert_instance_of OpenEhr::RM::DataTypes::Quantity::DateTime::DvTemporal, @dv_temporal
+    assert_instance_of OpenEhr::RM::DataTypes::Quantity::DateTime::DvDate, @dv_date
+    assert_instance_of OpenEhr::RM::DataTypes::Quantity::DateTime::DvTime, @dv_time
+    assert_instance_of OpenEhr::RM::DataTypes::Quantity::DateTime::DvDateTime, @dv_date_time
+    assert_instance_of OpenEhr::RM::DataTypes::Quantity::DateTime::DvDuration, @dv_duration
+  end
+
+  def test_dv_temporal
+    assert_equal '2008', @dv_temporal.value
+    assert_raise(NotImplementedError){@dv_temporal.diff('2009')}
+  end
+
+  def test_dv_date
+    assert_equal '2009-06-29', @dv_date.value
+    assert_equal 2009, @dv_date.year
+    assert_equal 6, @dv_date.month
+    assert_equal 29, @dv_date.day
+    assert_equal 733954, @dv_date.magnitude
+    date2 = OpenEhr::RM::DataTypes::Quantity::DateTime::DvDate.new('2009-07-08')
+    assert_equal 'P0Y0M1W9D',@dv_date.diff(date2).value
+    date2 = OpenEhr::RM::DataTypes::Quantity::DateTime::DvDate.new('2004-02-28')
+    date3 = OpenEhr::RM::DataTypes::Quantity::DateTime::DvDate.new('2004-03-01')
+    assert_equal 'P0Y0M0W2D', date2.diff(date3).value
+    date4 = OpenEhr::RM::DataTypes::Quantity::DateTime::DvDate.new('2003-12-31')
+    assert_equal 'P0Y1M4W28D', date2.diff(date4).value
+    birthday = OpenEhr::RM::DataTypes::Quantity::DateTime::DvDate.new('1970-04-19')
+    assert_equal 'P39Y2M1W11D', birthday.diff(OpenEhr::RM::DataTypes::Quantity::DateTime::DvDate.new('2009-06-30')).value
+  end
+
+  def test_dv_time
+    assert_equal '12:34:56.78', @dv_time.value
+    assert_equal 12, @dv_time.hour
+    assert_equal 34, @dv_time.minute
+    assert_equal 56, @dv_time.second
+    assert_equal 0.78, @dv_time.fractional_second
+    assert_equal((12*60*60 + 34 * 60 + 56 + 0.78), @dv_time.magnitude)
+    dv_time2 = OpenEhr::RM::DataTypes::Quantity::DateTime::DvTime.new('15:36:48.05')
+    assert_equal 'P0Y0M0W0DT3H1M51.27S', @dv_time.diff(dv_time2).value
+  end
+
+  def test_dv_date_time
+    assert_equal '2009-06-29T12:34:56.78', @dv_date_time.value
+    assert_equal 2009, @dv_date_time.year
+    assert_equal 6, @dv_date_time.month
+    assert_equal 29, @dv_date_time.day
+    assert_equal 12, @dv_date_time.hour
+    assert_equal 34, @dv_date_time.minute
+    assert_equal 56, @dv_date_time.second
+    assert_equal 0.78, @dv_date_time.fractional_second
+    dv_date_time2 = OpenEhr::RM::DataTypes::Quantity::DateTime::DvDateTime.new('1970-04-19T13:55:30.12')
+    assert_equal 'P39Y2M1W9DT22H39M26.66S', @dv_date_time.diff(dv_date_time2).value
+  end
+
+  def test_dv_duration
+    assert_equal 'P1Y2M3W4DT5H6M7.8S', @dv_duration.value
+    assert_equal 1, @dv_duration.years
+    assert_equal 2, @dv_duration.months
+    assert_equal 3, @dv_duration.weeks
+    assert_equal 4, @dv_duration.days
+    assert_equal 5, @dv_duration.hours
+    assert_equal 6, @dv_duration.minutes
+    assert_equal 7, @dv_duration.seconds
+    assert_equal 0.8, @dv_duration.fractional_second
+  end
+end
Index: ruby/branches/0.5/test/unit/open_ehr/rm/data_types_test.rb
===================================================================
--- ruby/branches/0.5/test/unit/open_ehr/rm/data_types_test.rb	(revision 191)
+++ ruby/branches/0.5/test/unit/open_ehr/rm/data_types_test.rb	(revision 191)
@@ -0,0 +1,446 @@
+require 'test/unit'
+require 'set'
+
+class RM_Data_Types_Basic_Test < Test::Unit::TestCase
+  def setup
+    assert_nothing_raised(Exception){@dv_boolean = OpenEhr::RM::DataTypes::Basic::DvBoolean.new("TRUE")}
+    @terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new('openEHR(1.0.2)')
+    @code_phrase = OpenEhr::RM::DataTypes::Text::CodePhrase.new('PROPOSED', @terminology_id)
+    @dv_coded_text = OpenEhr::RM::DataTypes::Text::DvCodedText.new("Blood examination", @code_phrase)
+    assert_nothing_raised(Exception){@dv_state = OpenEhr::RM::DataTypes::Basic::DvState.new(@dv_coded_text, false)}
+    assert_nothing_raised(Exception){@dv_identifier = OpenEhr::RM::DataTypes::Basic::DvIdentifier.new("Ruby Hospital","0123456-0", "Information office", "personal id")}
+  end
+
+  def test_init
+    assert_instance_of OpenEhr::RM::DataTypes::Basic::DvBoolean, @dv_boolean
+    assert_instance_of OpenEhr::RM::DataTypes::Basic::DvState, @dv_state
+    assert_instance_of OpenEhr::RM::DataTypes::Basic::DvIdentifier, @dv_identifier
+  end
+
+  def test_constant
+    assert_equal("\r", OpenEhr::RM::DataTypes::Basic::DataValue::CR)
+    assert_equal("\n", OpenEhr::RM::DataTypes::Basic::DataValue::LF)
+  end
+
+  def test_dv_boolean
+    assert @dv_boolean.value?
+    @dv_boolean.value = false
+    assert !@dv_boolean.value?
+    # inv: Value_exists
+    assert_raise(ArgumentError){@dv_boolean.value=nil}
+    assert_raise(ArgumentError){OpenEhr::RM::DataTypes::Basic::DvBoolean.new(nil)}
+  end
+
+  def test_dv_state
+    assert_equal 'Blood examination', @dv_state.value.value
+    assert_equal 'PROPOSED', @dv_state.value.defining_code.code_string
+    assert_equal 'openEHR', @dv_state.value.defining_code.terminology_id.name
+    assert_equal '1.0.2', @dv_state.value.defining_code.terminology_id.version_id
+    assert !@dv_state.is_terminal?
+    assert_nothing_raised(Exception){@dv_state.value.defining_code.code_string = "COMPLETED"}
+    assert_nothing_raised(Exception){@dv_state.is_terminal = true}
+    assert_equal 'COMPLETED', @dv_state.value.defining_code.code_string
+    assert @dv_state.is_terminal?
+    assert_raise(ArgumentError) {OpenEhr::RM::DataTypes::Basic::DvState.new(nil,nil)}
+    assert_raise(ArgumentError) {@dv_state.value=nil}
+    assert_raise(ArgumentError) {@dv_state.is_terminal=nil}
+  end
+
+  def test_dv_identifier
+    assert_equal("Ruby Hospital", @dv_identifier.assigner)
+    assert_equal("0123456-0", @dv_identifier.id)
+    assert_equal("Information office", @dv_identifier.issuer)
+    assert_equal("personal id", @dv_identifier.type)
+    @dv_identifier.assigner = "Test Hospital"
+    assert_equal("Test Hospital", @dv_identifier.assigner)
+    @dv_identifier.id = "TEST-0987"
+    assert_equal("TEST-0987", @dv_identifier.id)
+    @dv_identifier.issuer = "Security office"
+    assert_equal("Security office", @dv_identifier.issuer)
+    @dv_identifier.type = "test id"
+    assert_equal("test id", @dv_identifier.type)
+    assert_raise(ArgumentError) {OpenEhr::RM::DataTypes::Basic::DvIdentifier.new(nil, nil, nil, nil)}
+  end
+end
+
+# fixed
+class RM_Data_Types_URI_Test < Test::Unit::TestCase
+  def setup
+    @dv_uri = OpenEhr::RM::DataTypes::Uri::DvUri.new("http://www.openehr.jp/changeset/test?cmd=93#file0")
+    @dv_ehr_uri = OpenEhr::RM::DataTypes::Uri::DvEhrUri.new("ehr://1234567/87284370-2D4B-4e3d-A3F3-F303D2F4F34B@2005-08-02T04:30:00")
+  end
+
+  def test_init
+    assert_instance_of OpenEhr::RM::DataTypes::Uri::DvUri, @dv_uri
+    assert_instance_of OpenEhr::RM::DataTypes::Uri::DvEhrUri, @dv_ehr_uri
+  end
+
+  def test_dv_uri
+    assert_equal("file0", @dv_uri.fragment_id)
+    assert_equal("/changeset/test", @dv_uri.path)
+    assert_equal("cmd=93", @dv_uri.query)
+    assert_equal("http", @dv_uri.scheme)
+    assert_equal("http://www.openehr.jp/changeset/test?cmd=93#file0", @dv_uri.value)
+    @dv_uri.value="svn://www.openehr.jp/openehr-jp/"
+    assert_equal("svn://www.openehr.jp/openehr-jp/", @dv_uri.value)
+    assert_equal("/openehr-jp/", @dv_uri.path)
+  end
+
+  def test_dv_ehr_uri
+    assert_equal("ehr", @dv_ehr_uri.scheme)
+    assert_raise(ArgumentError){
+      @dv_ehr_uri.value="svn://www.openehr.jp/openehr-jp/" }
+  end
+end
+
+class RM_Data_Types_Text_Test < Test::Unit::TestCase
+  def setup
+    assert_nothing_raised(Exception){@dv_text = OpenEhr::RM::DataTypes::Text::DvText.new("valid value")}
+    @terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new('ICD10')
+    
+    assert_nothing_raised(Exception){@code_phrase = OpenEhr::RM::DataTypes::Text::CodePhrase.new('C92.0', @terminology_id)}
+    assert_nothing_raised(Exception){@dv_coded_text = OpenEhr::RM::DataTypes::Text::DvCodedText.new("Acute Myeloid Leukemia", @code_phrase)}
+    @dv_paragraph = OpenEhr::RM::DataTypes::Text::DvParagraph.new(Set.new(["test1", "test2"]))
+    @term_mapping = OpenEhr::RM::DataTypes::Text::TermMapping.new('=',@dv_coded_text,"TEST")
+  end
+
+  def test_init
+    assert_instance_of OpenEhr::RM::DataTypes::Text::DvText, @dv_text
+    assert_instance_of OpenEhr::RM::DataTypes::Text::CodePhrase, @code_phrase
+    assert_instance_of OpenEhr::RM::DataTypes::Text::DvCodedText, @dv_coded_text
+    assert_instance_of OpenEhr::RM::DataTypes::Text::TermMapping, @term_mapping
+  end
+
+  def test_dv_text
+    assert_equal("valid value", @dv_text.value)
+    assert_raise(ArgumentError){@dv_text.value = "not valid value\n"}
+    assert_raise(ArgumentError){@dv_text.value = nil }
+    assert_raise(ArgumentError){@dv_text.value = "" }
+    assert_raise(ArgumentError){@dv_text.formatting = "" }
+    assert_raise(ArgumentError){@dv_text.encoding = ""}
+    assert_raise(ArgumentError){@dv_text.language = ""}
+    assert_raise(ArgumentError){@dv_text.mappings = Set.new}
+    assert_raise(ArgumentError){@dv_text.mappings = ""}
+    assert_raise(ArgumentError){@dv_text.language = ""}
+  end
+
+  def test_code_phrase
+    assert_equal 'C92.0', @code_phrase.code_string
+    assert_equal 'ICD10', @code_phrase.terminology_id.value
+    assert_nothing_raised(Exception){@code_phrase.code_string = 'C93.0'}
+    assert_equal 'C93.0', @code_phrase.code_string
+  end
+
+  def test_dv_coded_text
+    assert_equal("Acute Myeloid Leukemia", @dv_coded_text.value)
+    assert_equal("ICD10", @dv_coded_text.defining_code.terminology_id.name)
+    assert_raise(ArgumentError){@dv_coded_text.defining_code=nil}
+  end
+
+  def test_dv_paragraph
+    assert_equal((Set.new ["test1", "test2"]), @dv_paragraph.items)
+    assert_raise(ArgumentError){@dv_paragraph.items=Set.new}
+  end
+
+  def test_term_mapping
+    assert_equal '=', @term_mapping.match
+    assert OpenEhr::RM::DataTypes::Text::TermMapping.is_valid_mach_code?('>')
+    assert OpenEhr::RM::DataTypes::Text::TermMapping.is_valid_mach_code?('=')
+    assert OpenEhr::RM::DataTypes::Text::TermMapping.is_valid_mach_code?('<')
+    assert OpenEhr::RM::DataTypes::Text::TermMapping.is_valid_mach_code?('?')
+    assert !OpenEhr::RM::DataTypes::Text::TermMapping.is_valid_mach_code?('!')
+    assert_equal @dv_coded_text, @term_mapping.purpose
+    assert_equal "TEST", @term_mapping.target
+    assert_raise(ArgumentError){OpenEhr::RM::DataTypes::Text::TermMapping.new}
+    assert_raise(ArgumentError){OpenEhr::RM::DataTypes::Text::TermMapping.new('!',@dv_coded_text, "invalid case")}
+    assert_raise(ArgumentError){OpenEhr::RM::DataTypes::Text::TermMapping.new('=',nil , "invalid case")}
+    assert_raise(ArgumentError){OpenEhr::RM::DataTypes::Text::TermMapping.new('=',@dv_coded_text, nil)}
+  end
+end
+
+class QuantityTest < Test::Unit::TestCase
+  def setup
+    assert_nothing_raised(Exception){
+      @dv_ordered = OpenEhr::RM::DataTypes::Quantity::DvOrdered.new }
+    assert_nothing_raised(Exception){
+      terminology = OpenEhr::RM::Support::Identification::TerminologyId.new('urine')
+      code_phrase = OpenEhr::RM::DataTypes::Text::CodePhrase.new('protein',terminology)
+      urinary_protein = OpenEhr::RM::DataTypes::Text::DvCodedText.new('+', code_phrase)
+      @dv_ordinal1 = OpenEhr::RM::DataTypes::Quantity::DvOrdinal.new(1, urinary_protein)
+      code_phrase = OpenEhr::RM::DataTypes::Text::CodePhrase.new('protein',terminology)
+      urinary_protein = OpenEhr::RM::DataTypes::Text::DvCodedText.new('+++', code_phrase)
+      @dv_ordinal2 = OpenEhr::RM::DataTypes::Quantity::DvOrdinal.new(3, urinary_protein)}
+    assert_nothing_raised(Exception){
+      @dv_interval = OpenEhr::RM::DataTypes::Quantity::DvInterval.new(@dv_ordinal1, @dv_ordinal2)}
+    meaning = OpenEhr::RM::DataTypes::Text::DvText.new('normal')
+    assert_nothing_raised(Exception){
+      @reference_range = OpenEhr::RM::DataTypes::Quantity::ReferenceRange.new(meaning, @dv_interval)}
+    assert_nothing_raised(Exception){
+      @dv_quantified = OpenEhr::RM::DataTypes::Quantity::DvQuantified.new(1,'=')}
+    assert_nothing_raised(Exception){
+      @dv_amount = OpenEhr::RM::DataTypes::Quantity::DvAmount.new(2,'<')}
+    assert_nothing_raised(Exception){
+      @dv_quantity = OpenEhr::RM::DataTypes::Quantity::DvQuantity.new(3, 'mg', '~')}
+    assert_nothing_raised(Exception){
+      @dv_count = OpenEhr::RM::DataTypes::Quantity::DvCount.new(1)}
+    assert_nothing_raised(Exception){
+      @dv_proportion = OpenEhr::RM::DataTypes::Quantity::DvProportion.new(2,3,0)}
+    assert_nothing_raised(Exception){
+      @dv_absolute_quantity = OpenEhr::RM::DataTypes::Quantity::DvAbsoluteQuantity.new(7,'=')}
+   end
+
+   def test_init
+     assert_instance_of OpenEhr::RM::DataTypes::Quantity::DvOrdered, @dv_ordered
+     assert_instance_of OpenEhr::RM::DataTypes::Quantity::DvQuantified, @dv_quantified
+     assert_instance_of OpenEhr::RM::DataTypes::Quantity::DvInterval, @dv_interval
+     assert_instance_of OpenEhr::RM::DataTypes::Quantity::ReferenceRange, @reference_range
+     assert_instance_of OpenEhr::RM::DataTypes::Quantity::DvOrdinal, @dv_ordinal1
+     assert_instance_of OpenEhr::RM::DataTypes::Quantity::DvOrdinal, @dv_ordinal2
+     assert_instance_of OpenEhr::RM::DataTypes::Quantity::DvQuantified, @dv_quantified
+     assert_instance_of OpenEhr::RM::DataTypes::Quantity::DvAmount, @dv_amount
+     assert_instance_of OpenEhr::RM::DataTypes::Quantity::DvQuantity, @dv_quantity
+     assert_instance_of OpenEhr::RM::DataTypes::Quantity::DvCount, @dv_count
+     assert_instance_of OpenEhr::RM::DataTypes::Quantity::DvProportion, @dv_proportion
+     assert_instance_of OpenEhr::RM::DataTypes::Quantity::DvAbsoluteQuantity, @dv_absolute_quantity
+  end
+
+  def test_dv_ordered
+    assert !@dv_ordered.is_normal?
+    assert_nil @dv_ordered.normal_status
+    assert_nil @dv_ordered.normal_range
+    assert_nil @dv_ordered.other_refference_ranges
+    assert @dv_ordered.is_simple?
+    assert_raise(NotImplementedError){@dv_ordered<=>1}
+    openehr_terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new('openEHR')
+    normal_code = OpenEhr::RM::DataTypes::Text::CodePhrase.new('N', openehr_terminology_id)
+    assert_equal 'N', normal_code.code_string
+    assert_nothing_raised(Exception){
+      @dv_ordered.normal_status = normal_code }
+    assert @dv_ordered.is_normal?
+    other = OpenEhr::RM::DataTypes::Quantity::DvOrdered.new
+    assert_raise(NotImplementedError){
+      @dv_ordered.is_strictly_comparable_to?(other)}
+  end
+
+  def test_dv_interval
+    assert @dv_interval.lower < @dv_interval.upper
+  end
+
+  def test_reference_range
+    assert_equal 'normal', @reference_range.meaning.value
+    assert_equal 1, @reference_range.range.lower.value
+    terminology = OpenEhr::RM::Support::Identification::TerminologyId.new('urine')
+    code_phrase = OpenEhr::RM::DataTypes::Text::CodePhrase.new('protein',terminology)
+    urinary_protein = OpenEhr::RM::DataTypes::Text::DvCodedText.new('++', code_phrase)
+    dv_ordinal = OpenEhr::RM::DataTypes::Quantity::DvOrdinal.new(2, urinary_protein)
+    assert @reference_range.is_in_range?(dv_ordinal)
+    dv_ordinal.value = 6
+    assert !@reference_range.is_in_range?(dv_ordinal)
+  end
+
+  def test_dv_quantified
+    assert_equal 1, @dv_quantified.magnitude
+    assert_equal '=', @dv_quantified.magnitude_status
+    assert !OpenEhr::RM::DataTypes::Quantity::DvQuantified.valid_magnitude_status?('*')
+    assert OpenEhr::RM::DataTypes::Quantity::DvQuantified.valid_magnitude_status?('>')
+    assert OpenEhr::RM::DataTypes::Quantity::DvQuantified.valid_magnitude_status?('<')
+    assert OpenEhr::RM::DataTypes::Quantity::DvQuantified.valid_magnitude_status?('>=')
+    assert OpenEhr::RM::DataTypes::Quantity::DvQuantified.valid_magnitude_status?('<=')
+    assert OpenEhr::RM::DataTypes::Quantity::DvQuantified.valid_magnitude_status?('~')
+    assert_nothing_raised(Exception){@dv_quantified.magnitude = 0}
+    assert_equal 0, @dv_quantified.magnitude
+    assert_nothing_raised(Exception){@dv_quantified.magnitude_status = nil}
+    assert_equal '=',  @dv_quantified.magnitude_status
+  end
+
+  def test_dv_absolute_quantity
+    assert_equal 7, @dv_absolute_quantity.magnitude
+    assert @dv_absolute_quantity.accuracy_unknown?
+    assert_nothing_raised(Exception){@dv_absolute_quantity.accuracy = 0.5}
+    assert_equal 0.5, @dv_absolute_quantity.accuracy
+    assert !@dv_absolute_quantity.accuracy_unknown?
+  end
+
+  def test_dv_amount
+    assert_equal 2, @dv_amount.magnitude
+    assert_equal '<', @dv_amount.magnitude_status
+    assert @dv_amount.accuracy_unknown?
+    assert_nothing_raised(Exception){@dv_amount.set_accuracy(50,true)}
+    assert_equal 50, @dv_amount.accuracy
+    assert @dv_amount.accuracy_is_percent?
+    assert_nothing_raised(Exception){@dv_amount.set_accuracy(0.3, false)}
+    assert_equal 0.3, @dv_amount.accuracy
+    assert !@dv_amount.accuracy_is_percent?
+    assert !@dv_amount.accuracy_unknown?
+  end
+
+  def test_dv_ordinal
+    assert_equal 1, @dv_ordinal1.value
+    assert_equal '+', @dv_ordinal1.symbol.value
+    assert_raise(ArgumentError){@dv_ordinal1.symbol = nil}
+    assert_raise(ArgumentError){@dv_ordinal1.value = nil}
+    assert @dv_ordinal1.is_strictly_comparable_to?(@dv_ordinal2)
+    assert @dv_ordinal1 < @dv_ordinal2
+    assert @dv_ordinal2 > @dv_ordinal1
+    @dv_ordinal1.value = 4
+    assert 4, @dv_ordinal1.value
+    assert @dv_ordinal1 > @dv_ordinal2
+    assert_raise(ArgumentError){@dv_ordinal1.limits = @reference_range}
+    meaning = OpenEhr::RM::DataTypes::Text::DvText.new('limits')
+    limit_reference_range = OpenEhr::RM::DataTypes::Quantity::ReferenceRange.new(meaning, @dv_interval)
+    assert_nothing_raised(Exception){@dv_ordinal1.limits = limit_reference_range}
+    assert_equal 'limits', @dv_ordinal1.limits.meaning.value
+  end
+
+  def test_dv_quantity
+    assert_equal 3, @dv_quantity.magnitude
+    assert_equal 'mg', @dv_quantity.units
+    assert_equal '~', @dv_quantity.magnitude_status
+    dv_quantity2 = OpenEhr::RM::DataTypes::Quantity::DvQuantity.new(4, 'mg', '~')
+    assert_equal 'mg', dv_quantity2.units
+    assert @dv_quantity.is_strictly_comparable_to?(dv_quantity2)
+    assert_nothing_raised(Exception){@dv_quantity.precision = -1}
+    assert_equal(-1, @dv_quantity.precision)
+    assert !@dv_quantity.is_integral?
+    assert_raise(ArgumentError){@dv_quantity.precision = -1.1}
+    @dv_quantity.precision = 0
+    assert @dv_quantity.is_integral?
+    dv_quantity3 = @dv_quantity + dv_quantity2
+    assert_equal 7, dv_quantity3.magnitude
+    assert_equal 'mg', dv_quantity3.units
+    dv_quantity3 = @dv_quantity - dv_quantity2
+    assert_equal(-1, dv_quantity3.magnitude)
+    assert_equal 'mg', dv_quantity3.units
+  end
+
+  def test_dv_count
+    assert_equal 1, @dv_count.magnitude
+    dv_count2 = OpenEhr::RM::DataTypes::Quantity::DvCount.new(2)
+    dv_count3 = @dv_count + dv_count2
+    assert 3, dv_count3.magnitude
+    dv_count3 = dv_count2 - @dv_count
+    assert 1, dv_count3.magnitude
+  end
+
+  def test_proportion_kind
+    assert_equal 0, OpenEhr::RM::DataTypes::Quantity::ProportionKind::PK_RATIO
+    assert_equal 1, OpenEhr::RM::DataTypes::Quantity::ProportionKind::PK_UNITARY
+    assert_equal 2, OpenEhr::RM::DataTypes::Quantity::ProportionKind::PK_PERCENT
+    assert_equal 3, OpenEhr::RM::DataTypes::Quantity::ProportionKind::PK_FRACTION
+    assert_equal 4, OpenEhr::RM::DataTypes::Quantity::ProportionKind::PK_INTEGER_FRACTION
+    assert OpenEhr::RM::DataTypes::Quantity::ProportionKind.valid_proportion_kind?(0)
+    assert OpenEhr::RM::DataTypes::Quantity::ProportionKind.valid_proportion_kind?(4)
+    assert !OpenEhr::RM::DataTypes::Quantity::ProportionKind.valid_proportion_kind?(-1)
+    assert !OpenEhr::RM::DataTypes::Quantity::ProportionKind.valid_proportion_kind?(5)
+  end
+
+  def test_dv_proportion
+    assert_equal 2.0, @dv_proportion.numerator
+    assert_equal 3.0, @dv_proportion.denominator
+    assert_equal 0, @dv_proportion.type
+    assert_equal 2.0/3.0, @dv_proportion.magnitude
+    assert @dv_proportion.is_integral?
+    dv_proportion2 = OpenEhr::RM::DataTypes::Quantity::DvProportion.new(1,3,0)
+    assert @dv_proportion.is_strictly_comparable_to?(dv_proportion2)
+    dv_proportion2 = OpenEhr::RM::DataTypes::Quantity::DvProportion.new(1,3,4)
+    assert !@dv_proportion.is_strictly_comparable_to?(dv_proportion2)
+    assert_raise(ArgumentError){
+      dv_proportion2 = OpenEhr::RM::DataTypes::Quantity::DvProportion.new(1.5,2.3,3)}
+    assert_raise(ArgumentError){
+      dv_proportion2 = OpenEhr::RM::DataTypes::Quantity::DvProportion.new(10,10,1)}
+    assert_nothing_raised(Exception){
+      dv_proportion2 = OpenEhr::RM::DataTypes::Quantity::DvProportion.new(10,1,1)}
+    assert_raise(ArgumentError){
+      dv_proportion2 = OpenEhr::RM::DataTypes::Quantity::DvProportion.new(10,10,2)}
+    assert_nothing_raised(Exception){
+      dv_proportion2 = OpenEhr::RM::DataTypes::Quantity::DvProportion.new(10,100,2)}
+  end
+
+end
+
+class EncapsulatedTest < Test::Unit::TestCase
+  def setup
+    charset = OpenEhr::RM::DataTypes::Text::CodePhrase.new('UTF-8','character-sets')
+    language = OpenEhr::RM::DataTypes::Text::CodePhrase.new('ja', 'languages')
+    assert_nothing_raised(Exception){
+      @dv_encapsulated = OpenEhr::RM::DataTypes::Encapsulated::DvEncapsulated.new(charset, language, 10)}
+    assert_nothing_raised(Exception){
+      @dv_parsable = OpenEhr::RM::DataTypes::Encapsulated::DvParsable.new(charset, language, 10, 'XML','<TEST>test</TEST>')}
+    media_type = OpenEhr::RM::DataTypes::Text::CodePhrase.new('text/html', 'media-types')
+    uri = OpenEhr::RM::DataTypes::Uri::DvUri.new("http://www.openehr.jp/changeset/test?cmd=93#file0")
+    assert_nothing_raised(Exception){
+      @dv_multimedia = OpenEhr::RM::DataTypes::Encapsulated::DvMultimedia.new(charset, language, 10, media_type, uri)}
+  end
+
+  def test_init
+    assert_instance_of OpenEhr::RM::DataTypes::Encapsulated::DvEncapsulated, @dv_encapsulated
+    assert_instance_of OpenEhr::RM::DataTypes::Encapsulated::DvParsable, @dv_parsable
+    assert_instance_of OpenEhr::RM::DataTypes::Encapsulated::DvMultimedia, @dv_multimedia
+  end
+
+  def test_dv_encapsulated
+    assert_equal 'UTF-8', @dv_encapsulated.charset.code_string
+    assert_equal 'ja', @dv_encapsulated.language.code_string
+    assert_equal 10, @dv_encapsulated.size
+    wrong_charset = OpenEhr::RM::DataTypes::Text::CodePhrase.new('USO8000', 'character-sets')
+    assert_raise(ArgumentError){@dv_encapsulated.charset = wrong_charset}
+    charset = OpenEhr::RM::DataTypes::Text::CodePhrase.new('EUC-JP', 'character-sets')
+    assert_nothing_raised(Exception){@dv_encapsulated.charset = charset}
+    assert_equal 'EUC-JP', @dv_encapsulated.charset.code_string
+    wrong_language = OpenEhr::RM::DataTypes::Text::CodePhrase.new('jpg', 'language')
+    assert_raise(ArgumentError){@dv_encapsulated.language = wrong_language}
+    language = OpenEhr::RM::DataTypes::Text::CodePhrase.new('eng', 'language')
+    assert_nothing_raised(Exception){@dv_encapsulated.language = language}
+    assert_equal 'eng', @dv_encapsulated.language.code_string
+    assert_raise(ArgumentError){@dv_encapsulated.size = -1}
+    assert_nothing_raised(Exception){@dv_encapsulated.size = 0}
+    assert_equal 0, @dv_encapsulated.size
+  end
+
+  def test_dv_parsable
+    assert_equal 'UTF-8', @dv_parsable.charset.code_string
+    assert_equal 'ja', @dv_parsable.language.code_string
+    assert_equal 10, @dv_parsable.size
+    assert_equal 'XML', @dv_parsable.formalism
+    assert_equal '<TEST>test</TEST>', @dv_parsable.value
+    assert_raise(ArgumentError){
+      @dv_parsable.formalism = nil }
+    assert_nothing_raised(Exception){
+      @dv_parsable.formalism = 'HTML' }
+    assert_equal 'HTML', @dv_parsable.formalism
+    assert_raise(ArgumentError){
+      @dv_parsable.value = nil }
+    assert_nothing_raised(Exception){
+      @dv_parsable.value = '<H1>test</H1>' }
+    assert_equal '<H1>test</H1>', @dv_parsable.value
+  end
+
+  def test_dv_multimedia
+    assert_equal 'UTF-8', @dv_multimedia.charset.code_string
+    assert_equal 'ja', @dv_multimedia.language.code_string
+    assert_equal 10, @dv_multimedia.size
+    assert_equal 'text/html', @dv_multimedia.media_type.code_string
+    assert_equal 'http://www.openehr.jp/changeset/test?cmd=93#file0', @dv_multimedia.uri.value
+  end
+end
+
+
+class TestDvTimeSpecification < Test::Unit::TestCase
+  def setup
+    charset = OpenEhr::RM::DataTypes::Text::CodePhrase.new('UTF-8','character-sets')
+    language = OpenEhr::RM::DataTypes::Text::CodePhrase.new('ja', 'languages')
+    assert_nothing_raised(Exception){
+      dv_parsable = OpenEhr::RM::DataTypes::Encapsulated::DvParsable.new(charset, language, 10, 'XML','<TEST>test</TEST>')
+      @dv_time_specification = OpenEhr::RM::DataTypes::TimeSpecification::DvTimeSpecification.new(dv_parsable)}
+#    assert_nothing_raised(Exception){
+#      @dv_periodic_time_specification = DV_Periodic_Time_Specification.new('[200004181100;200004181110]/(7d)@DWIST', charset, language, 10, 'HL7:PIVL')}
+  end
+
+  def test_init
+    assert_instance_of OpenEhr::RM::DataTypes::TimeSpecification::DvTimeSpecification, @dv_time_specification
+  end
+
+  def test_dv_time_specification
+    assert_equal '<TEST>test</TEST>', @dv_time_specification.value.value
+  end
+end
Index: ruby/branches/0.5/test/unit/open_ehr/rm/security_test.rb
===================================================================
--- ruby/branches/0.5/test/unit/open_ehr/rm/security_test.rb	(revision 191)
+++ ruby/branches/0.5/test/unit/open_ehr/rm/security_test.rb	(revision 191)
@@ -0,0 +1,12 @@
+require 'test/unit'
+
+class RM_Security_Test < Test::Unit::TestCase
+  def setup
+    assert_nothing_raised(Exception){
+      @access_control_setting = OpenEhr::RM::Security::AccessControlSettings.new}
+  end
+
+  def test_init
+    assert_instance_of OpenEhr::RM::Security::AccessControlSettings, @access_control_setting
+  end
+end
Index: ruby/branches/0.5/test/unit/open_ehr/rm/support_test.rb
===================================================================
--- ruby/branches/0.5/test/unit/open_ehr/rm/support_test.rb	(revision 191)
+++ ruby/branches/0.5/test/unit/open_ehr/rm/support_test.rb	(revision 191)
@@ -0,0 +1,282 @@
+require 'test/unit'
+require 'set'
+
+class RM_Support_Definition_Test < Test::Unit::TestCase
+    def test_constant
+    assert_equal("\r", OpenEhr::RM::Support::Definition::OpenEHRDefinitions::CR)
+    assert_equal("\n", OpenEhr::RM::Support::Definition::OpenEHRDefinitions::LF)
+  end
+end
+
+
+class RM_Support_Identification_Test < Test::Unit::TestCase
+  def setup
+    assert_nothing_raised(Exception){@object_id = OpenEhr::RM::Support::Identification::ObjectId.new("0.0.3")}
+    assert_nothing_raised(Exception){@object_ref = OpenEhr::RM::Support::Identification::ObjectRef.new('local', 'ANY', @object_id)}
+    assert_nothing_raised(Exception){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol","0.0.3")}
+    assert_nothing_raised(Exception){@terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new('ICD10(2003)')}
+    assert_nothing_raised(Exception){@generic_id = OpenEhr::RM::Support::Identification::GenericId.new("0.0.3", "openehr")}
+    assert_nothing_raised(Exception){@uid_based_id = OpenEhr::RM::Support::Identification::UidBasedId.new('rrip::0.0.3')}
+    assert_nothing_raised(Exception){@hier_object_id = OpenEhr::RM::Support::Identification::HierObjectId.new('0.0.4')}
+    assert_nothing_raised(Exception){@locatable_ref = OpenEhr::RM::Support::Identification::LocatableRef.new('unknown', 'PERSON', @uid_based_id, 'data/event[at0001, standing]')}
+    assert_nothing_raised(Exception){@party_ref = OpenEhr::RM::Support::Identification::PartyRef.new('unknown', 'ORGANISATION', @object_id)}
+    assert_nothing_raised(Exception){@access_group_ref = OpenEhr::RM::Support::Identification::AccessGroupRef.new('unknown', 'ACCESS_GROUP', @object_id)}
+    assert_nothing_raised(Exception){@version_tree_id = OpenEhr::RM::Support::Identification::VersionTreeId.new('1.2.3')}
+    assert_nothing_raised(Exception){@object_version_id = OpenEhr::RM::Support::Identification::ObjectVersionId.new('ABC::DEF::1.2.3')}
+  end
+  
+  def test_init
+    assert_instance_of OpenEhr::RM::Support::Identification::ObjectId, @object_id
+    assert_instance_of OpenEhr::RM::Support::Identification::ObjectRef, @object_ref
+    assert_instance_of OpenEhr::RM::Support::Identification::ArchetypeId, @archetype_id
+    assert_instance_of OpenEhr::RM::Support::Identification::TerminologyId, @terminology_id
+    assert_instance_of OpenEhr::RM::Support::Identification::ObjectId, @object_id
+    assert_instance_of OpenEhr::RM::Support::Identification::GenericId, @generic_id
+    assert_instance_of OpenEhr::RM::Support::Identification::UidBasedId, @uid_based_id
+    assert_instance_of OpenEhr::RM::Support::Identification::HierObjectId, @hier_object_id
+    assert_instance_of OpenEhr::RM::Support::Identification::LocatableRef, @locatable_ref
+    assert_instance_of OpenEhr::RM::Support::Identification::PartyRef, @party_ref
+    assert_instance_of OpenEhr::RM::Support::Identification::AccessGroupRef, @access_group_ref
+    assert_instance_of OpenEhr::RM::Support::Identification::VersionTreeId, @version_tree_id
+    assert_instance_of OpenEhr::RM::Support::Identification::ObjectVersionId, @object_version_id
+  end
+
+  def test_object_id
+    assert_equal "0.0.3", @object_id.value
+    assert_nothing_raised(Exception){@object_id.value = "0.0.4"}
+    assert_equal "0.0.4", @object_id.value
+    assert_raise(ArgumentError){@object_id.value=nil}
+    assert_raise(ArgumentError){@object_id.value=""}
+    assert_raise(ArgumentError){@object_id = OpenEhr::RM::Support::Identification::ObjectId.new}
+    assert_raise(ArgumentError){@object_id = OpenEhr::RM::Support::Identification::ObjectId.new(nil)}
+    assert_raise(ArgumentError){@object_id = OpenEhr::RM::Support::Identification::ObjectId.new("")}
+    assert_equal @object_id, OpenEhr::RM::Support::Identification::ObjectId.new("0.0.4")
+  end
+
+  def test_object_refs
+    assert_equal 'local', @object_ref.namespace
+    assert_equal 'ANY', @object_ref.type
+    assert_equal @object_id, @object_ref.id
+
+    assert_raise(ArgumentError){@object_ref = OpenEhr::RM::Support::Identification::ArchetypeId.new}
+    assert_raise(ArgumentError){@object_ref = OpenEhr::RM::Support::Identification::ArchetypeId.new(nil, 'ANY', @object_id)}
+    assert_raise(ArgumentError){@object_ref = OpenEhr::RM::Support::Identification::ArchetypeId.new('', 'ANY', @object_id)}
+    assert_raise(ArgumentError){@object_ref = OpenEhr::RM::Support::Identification::ArchetypeId.new('local', nil, @object_id)}
+    assert_raise(ArgumentError){@object_ref = OpenEhr::RM::Support::Identification::ArchetypeId.new('local', '', @object_id)}
+    assert_raise(ArgumentError){@object_ref = OpenEhr::RM::Support::Identification::ArchetypeId.new('local', 'ANY', nil)}
+
+    assert_nothing_raised(Exception){@object_ref.namespace = 'terminology'}
+    assert_equal 'terminology', @object_ref.namespace
+    assert_raise(ArgumentError){@object_ref.namespace = nil}
+    assert_raise(ArgumentError){@object_ref.namespace = ''}
+    assert_raise(ArgumentError){@object_ref.namespace = '?&&'}
+    assert_raise(ArgumentError){@object_ref.namespace = '843'}
+
+    assert_nothing_raised(Exception){@object_ref.type = 'GUIDELINE'}
+    assert_equal 'GUIDELINE', @object_ref.type
+    assert_raise(ArgumentError){@object_ref.type = nil}
+    assert_raise(ArgumentError){@object_ref.type = ''}
+
+    assert_nothing_raised(Exception){@object_ref.id = OpenEhr::RM::Support::Identification::ObjectId.new("0.0.5")}
+    assert_equal OpenEhr::RM::Support::Identification::ObjectId.new("0.0.5"), @object_ref.id
+    assert_raise(ArgumentError){@object_ref.id = nil}
+  end
+
+  def test_archetype_id
+    assert_equal "0.0.5", @archetype_id.value
+    assert_nothing_raised(Exception){@archetype_id.value = "0.0.6"}
+    assert_equal "0.0.6", @archetype_id.value
+    assert_raise(ArgumentError){@archetype_id.value=nil}
+    assert_raise(ArgumentError){@archetype_id.value=""}
+    assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new}
+    assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new(nil, "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol","0.0.3")}
+    assert_raise(ArgumentError){@object_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol","0.0.3")}
+    assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", nil, "entry", "ehr_rm", "openehr","cholesterol","0.0.3")}
+    assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "", "entry", "ehr_rm", "openehr","cholesterol","0.0.3")}
+    assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", nil, "ehr_rm", "openehr","cholesterol","0.0.3")}
+    assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "", "ehr_rm", "openehr","cholesterol","0.0.3")}
+    assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", nil, "openehr","cholesterol","0.0.3")}
+    assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "", "openehr","cholesterol","0.0.3")}
+    assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", nil,"cholesterol","0.0.3")}
+    assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "","cholesterol","0.0.3")}
+    assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr",nil ,"0.0.3")}
+    assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","","0.0.3")}
+    assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol", nil)}
+    assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol","")}
+
+    assert_equal "biochemistry result_cholesterol", @archetype_id.domain_concept
+    assert_nothing_raised(Exception){(@archetype_id.domain_concept = "biochemistry result_triglyceride")}
+    assert_equal "biochemistry result_triglyceride", @archetype_id.domain_concept
+    assert_raise(ArgumentError){@archetype_id.domain_concept = nil}
+    assert_raise(ArgumentError){@archetype_id.domain_concept = ""}
+
+    assert_equal "entry", @archetype_id.rm_name
+    assert_nothing_raised(Exception){@archetype_id.rm_name = "section"}
+    assert_equal "section", @archetype_id.rm_name
+    assert_raise(ArgumentError){@archetype_id.rm_name = nil}
+    assert_raise(ArgumentError){@archetype_id.rm_name = ""}
+
+    assert_equal "ehr_rm", @archetype_id.rm_entity
+    assert_nothing_raised(Exception){@archetype_id.rm_entity = "13606"}
+    assert_equal "13606", @archetype_id.rm_entity
+    assert_raise(ArgumentError){@archetype_id.rm_entity = nil}
+    assert_raise(ArgumentError){@archetype_id.rm_entity = ""}
+
+    assert_equal "openehr", @archetype_id.rm_originator
+    assert_nothing_raised(Exception){@archetype_id.rm_originator = "cen"}
+    assert_equal "cen", @archetype_id.rm_originator
+    assert_raise(ArgumentError){@archetype_id.rm_originator = nil}
+    assert_raise(ArgumentError){@archetype_id.rm_originator = ""}
+
+    assert_equal "cholesterol", @archetype_id.specialisation
+    assert_nothing_raised(Exception){@archetype_id.specialisation = "triglyceride"}
+    assert_equal "triglyceride", @archetype_id.specialisation
+    assert_raise(ArgumentError){@archetype_id.specialisation = nil}
+    assert_raise(ArgumentError){@archetype_id.specialisation = ""}
+
+    assert_equal "0.0.3", @archetype_id.version_id
+    assert_nothing_raised(Exception){@archetype_id.version_id = "0.0.7"}
+    assert_equal "0.0.7", @archetype_id.version_id
+    assert_raise(ArgumentError){@archetype_id.version_id = nil}
+    assert_raise(ArgumentError){@archetype_id.version_id = ""}
+  end
+
+  def test_terminology_id
+    assert_equal "ICD10(2003)", @terminology_id.value
+    assert_nothing_raised(Exception){@terminology_id.value = "ICD9(1999)"}
+    assert_equal "ICD9", @terminology_id.name
+    assert_equal "1999", @terminology_id.version_id
+    assert_raise(ArgumentError){@terminology_id.value = nil}
+    assert_raise(ArgumentError){@terminology_id.value = ""}
+
+    assert_raise(ArgumentError){@terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new}
+    assert_raise(ArgumentError){@terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new(nil,'2008')}
+    assert_raise(ArgumentError){@terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new('','02008')}
+    assert_raise(ArgumentError){@terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new("SNOMED", nil)}
+    assert_nothing_raised(Exception){@terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new("SNOMED")}
+
+    assert_equal "SNOMED", @terminology_id.name
+    assert_nothing_raised(Exception){@terminology_id.name = "LOINC"}
+    assert_equal "LOINC", @terminology_id.name
+    assert_raise(ArgumentError){@terminology_id.name = nil}
+    assert_raise(ArgumentError){@terminology_id.name = ""}
+
+    assert_equal "", @terminology_id.version_id
+    assert_nothing_raised(Exception){@terminology_id.version_id = "2008"}
+    assert_equal "2008", @terminology_id.version_id
+    assert_equal 'LOINC(2008)', @terminology_id.value
+    assert_raise(ArgumentError){@terminology_id.version_id = nil}
+    assert_nothing_raised(Exception){@terminology_id.version_id = ''}
+  end
+
+  def test_generic_id
+    assert_equal "0.0.3", @generic_id.value
+    assert_equal "openehr", @generic_id.scheme
+
+    assert_raise(ArgumentError){@generic_id = OpenEhr::RM::Support::Identification::GenericId.new(nil, "openehr")}
+    assert_raise(ArgumentError){@generic_id = OpenEhr::RM::Support::Identification::GenericId.new("", "openehr")}
+    assert_raise(ArgumentError){@generic_id = OpenEhr::RM::Support::Identification::GenericId.new("0.0.3", nil)}
+    assert_raise(ArgumentError){@generic_id = OpenEhr::RM::Support::Identification::GenericId.new("0.0.3", "")}
+
+    assert_raise(ArgumentError){@generic_id.value = nil}
+    assert_raise(ArgumentError){@generic_id.value = ""}
+    assert_nothing_raised(Exception){@generic_id.value = "0.0.5"}
+    assert_equal "0.0.5", @generic_id.value
+
+    assert_raise(ArgumentError){@generic_id.scheme = nil}
+    assert_raise(ArgumentError){@generic_id.scheme = ""}
+    assert_nothing_raised(Exception){@generic_id.scheme = "cen"}
+    assert_equal "cen", @generic_id.scheme
+  end
+
+  def test_uid_based_id
+    assert_equal "rrip::0.0.3", @uid_based_id.value
+    assert_equal "rrip", @uid_based_id.root
+    assert_equal '0.0.3', @uid_based_id.extension
+    assert @uid_based_id.has_extension?
+
+    assert_raise(ArgumentError){@uid_based_id = OpenEhr::RM::Support::Identification::UidBasedId.new(nil)}
+    assert_raise(ArgumentError){@uid_based_id = OpenEhr::RM::Support::Identification::UidBasedId.new('')}
+    assert_raise(ArgumentError){@uid_based_id.value = nil}
+    assert_raise(ArgumentError){@uid_based_id.value = ''}
+
+    assert_nothing_raised(Exception){@uid_based_id.value = 'rrip'}
+    assert_equal 'rrip', @uid_based_id.value
+    assert_equal 'rrip', @uid_based_id.root
+    assert_equal '', @uid_based_id.extension
+  end
+
+  def test_hier_object_id
+    assert_equal '0.0.4', @hier_object_id.value
+    assert !@hier_object_id.root.nil?
+    assert !@hier_object_id.has_extension?
+# in the specification 1.0.1 has_extension? xor extention != Void void is not nil?
+    assert @hier_object_id.extension.empty?
+    assert_nothing_raised(Exception){@hier_object_id.value = "ehr::test"}
+    assert !@hier_object_id.root.nil?
+    assert @hier_object_id.has_extension?
+    assert !@hier_object_id.extension.empty?
+  end
+
+  def test_object_version_id
+    assert_equal 'ABC::DEF::1.2.3', @object_version_id.value
+    assert_equal 'ABC', @object_version_id.object_id.value
+    assert_equal 'DEF', @object_version_id.creating_system_id.value
+    assert_equal '1', @object_version_id.version_tree_id.trunk_version
+  end
+
+  def test_locatable_ref
+# test constructor
+    assert_equal 'unknown', @locatable_ref.namespace
+    assert_equal 'PERSON', @locatable_ref.type
+    assert_equal @uid_based_id, @locatable_ref.id
+    assert_equal 'data/event[at0001, standing]', @locatable_ref.path
+    assert_equal 'ehr://rrip::0.0.3/data/event[at0001, standing]', @locatable_ref.as_uri
+#test path
+    assert_nothing_raised(Exception){@locatable_ref.path = 'data/event[at0002, tilting]'}
+    assert_equal 'data/event[at0002, tilting]', @locatable_ref.path
+    assert_equal 'ehr://rrip::0.0.3/data/event[at0002, tilting]', @locatable_ref.as_uri
+  end
+
+  def test_party_ref
+# test constructor
+    assert_equal 'unknown', @party_ref.namespace
+    assert_equal 'ORGANISATION', @party_ref.type
+    assert_equal @object_id, @party_ref.id
+# test type validation
+    assert_raise(ArgumentError){@party_ref.type = 'GUIDELINE'}
+    assert_nothing_raised(Exception){@party_ref.type = 'PERSON'}
+    assert_equal 'PERSON', @party_ref.type
+    assert_nothing_raised(Exception){@party_ref.type = 'GROUP'}
+    assert_nothing_raised(Exception){@party_ref.type = 'AGENT'}
+    assert_nothing_raised(Exception){@party_ref.type = 'ROLE'}
+    assert_nothing_raised(Exception){@party_ref.type = 'PARTY'}
+    assert_nothing_raised(Exception){@party_ref.type = 'ACTOR'}
+  end
+
+  def test_access_group_ref
+# test constructor
+    assert_equal 'unknown', @access_group_ref.namespace
+    assert_equal 'ACCESS_GROUP', @access_group_ref.type
+    assert_equal @object_id, @access_group_ref.id
+# test type validation
+    assert_raise(ArgumentError){@access_group_ref.type = 'PERSON'}
+    assert_nothing_raised(Exception){@access_group_ref.type = 'ACCESS_GROUP'}
+  end
+
+  def test_version_tree_id
+    assert_equal '1.2.3', @version_tree_id.value
+    assert_equal '1', @version_tree_id.trunk_version
+    assert_equal '2', @version_tree_id.branch_number
+    assert_equal '3', @version_tree_id.branch_version
+    assert @version_tree_id.is_first?
+    assert @version_tree_id.is_branch?
+    assert_nothing_raised(Exception){@version_tree_id.value = '2'}
+    assert_equal '2', @version_tree_id.trunk_version
+    assert !@version_tree_id.is_first?
+    assert !@version_tree_id.is_branch?
+    assert_nil @version_tree_id.branch_number
+    assert_nil @version_tree_id.branch_version
+    assert_raise(ArgumentError){@version_tree_id.branch_version = '5'}
+  end
+end
Index: ruby/branches/0.5/test/unit/open_ehr_test.rb
===================================================================
--- ruby/branches/0.5/test/unit/open_ehr_test.rb	(revision 190)
+++ ruby/branches/0.5/test/unit/open_ehr_test.rb	(revision 191)
@@ -6,4 +6,4 @@
 # Add your testcases here
 
-require 'unit/lib/open_ehr/ts_rm'
-require 'unit/lib/open_ehr/tc_assumed_library_types'
+#require 'unit/lib/open_ehr/ts_rm'
+#require 'unit/lib/open_ehr/tc_assumed_library_types'
