Index: /ruby/trunk/tests/models/test_archetype_model.rb
===================================================================
--- /ruby/trunk/tests/models/test_archetype_model.rb	(revision 62)
+++ /ruby/trunk/tests/models/test_archetype_model.rb	(revision 62)
@@ -0,0 +1,193 @@
+require 'test/unit'
+require 'am.rb'
+require 'rm.rb'
+
+class ArchetypeModelTest < Test::Unit::TestCase
+  def setup
+    @archetype = OpenEHR::AM::Archetype::ARCHETYPE.new
+    @validity_kind = OpenEHR::AM::Archetype::VALIDITY_KIND.new
+
+    @archetype_description = OpenEHR::AM::Archetype::Archetype_Description::ARCHETYPE_DESCRIPTION.new
+    @archetype_description_item = OpenEHR::AM::Archetype::Archetype_Description::ARCHETYPE_DESCRIPTION_ITEM.new
+  end
+  
+  def test_init
+    assert_instance_of OpenEHR::AM::Archetype::ARCHETYPE, @archetype
+    assert_instance_of OpenEHR::AM::Archetype::VALIDITY_KIND, @validity_kind
+    assert_instance_of OpenEHR::AM::Archetype::Archetype_Description::ARCHETYPE_DESCRIPTION, @archetype_description
+    assert_instance_of OpenEHR::AM::Archetype::Archetype_Description::ARCHETYPE_DESCRIPTION_ITEM, @archetype_description_item
+    assert_instance_of OpenEHR::AM::Archetype::ARCHETYPE, @archetype
+  end
+
+  def test_create
+    archetype_instance = OpenEHR::AM::Archetype::ARCHETYPE.create() do |archetype|
+      archetype.adl_version = '1.4'
+    end
+
+    assert_instance_of OpenEHR::AM::Archetype::ARCHETYPE, archetype_instance
+  end
+end
+
+class ArchetypeModelConstraintTest < Test::Unit::TestCase
+  def setup
+    @archetype_constraint = OpenEHR::AM::Archetype::Constraint_Model::ARCHETYPE_CONSTRAINT.new
+    @cardinality = OpenEHR::AM::Archetype::Constraint_Model::CARDINALITY.new    
+    
+    @archetype_constraint = OpenEHR::AM::Archetype::Constraint_Model::ARCHETYPE_CONSTRAINT.new
+    @c_object = OpenEHR::AM::Archetype::Constraint_Model::C_OBJECT.new
+    @c_defined_object = OpenEHR::AM::Archetype::Constraint_Model::C_DEFINED_OBJECT.new
+    @c_attribute = OpenEHR::AM::Archetype::Constraint_Model::C_ATTRIBUTE.new
+    @c_single_attribute = OpenEHR::AM::Archetype::Constraint_Model::C_SINGLE_ATTRIBUTE.new
+    @c_multiple_attribute = OpenEHR::AM::Archetype::Constraint_Model::C_MULTIPLE_ATTRIBUTE.new(:rm_attribute_name => 'attribute_name', :cardinality => @cardinality)
+    @c_primitive_object = OpenEHR::AM::Archetype::Constraint_Model::C_PRIMITIVE_OBJECT.new
+    @c_reference_object =  OpenEHR::AM::Archetype::Constraint_Model::C_REFERENCE_OBJECT.new
+    @archetype_internal_ref =  OpenEHR::AM::Archetype::Constraint_Model::ARCHETYPE_INTERNAL_REF.new
+    @archetype_slot = OpenEHR::AM::Archetype::Constraint_Model::ARCHETYPE_SLOT.new
+    @constraint_ref = OpenEHR::AM::Archetype::Constraint_Model::CONSTRAINT_REF.new
+    @c_domain_type = OpenEHR::AM::Archetype::Constraint_Model::C_DOMAIN_TYPE.new
+    @c_complex_object = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.new(:attributes => [@c_single_attribute])
+  end
+
+  def test_init
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::ARCHETYPE_CONSTRAINT, @archetype_constraint
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::C_OBJECT, @c_object
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::C_DEFINED_OBJECT, @c_defined_object
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::C_ATTRIBUTE, @c_attribute
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::C_SINGLE_ATTRIBUTE, @c_single_attribute
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::C_MULTIPLE_ATTRIBUTE, @c_multiple_attribute
+    assert_equal 'attribute_name', @c_multiple_attribute.rm_attribute_name
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::CARDINALITY, @c_multiple_attribute.cardinality
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::C_PRIMITIVE_OBJECT, @c_primitive_object
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::C_REFERENCE_OBJECT, @c_reference_object
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::ARCHETYPE_INTERNAL_REF, @archetype_internal_ref
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::ARCHETYPE_SLOT, @archetype_slot
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::CONSTRAINT_REF, @constraint_ref
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::C_DOMAIN_TYPE, @c_domain_type
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT, @c_complex_object
+    assert_instance_of Array, @c_complex_object.attributes
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::ARCHETYPE_CONSTRAINT, @archetype_constraint
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::CARDINALITY, @cardinality
+  end
+
+  def test_create
+    c_complex_object = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.create(:node_id => 'test_node',
+                                                                                         :attributes => [1,2],
+                                                                                         :assumed_value => Array
+                                                                                         )
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT, c_complex_object
+    assert_equal 'test_node', c_complex_object.node_id
+  end
+end
+
+class ArchetypeModelPrimitiveTest < Test::Unit::TestCase
+  def setup
+    #@c_primitive = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_PRIMITIVE.new
+    @c_boolean = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => true,
+                                                                                    :false_valid => true,
+                                                                                    :assumed_value => true)
+    @c_string = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_STRING.new
+    @c_integer = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_INTEGER.new
+    @c_real = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_REAL.new
+    @c_time = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_TIME.new
+    @c_date = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_DATE.new
+    @c_date_time = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_DATE_TIME.new
+    @c_duration = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_DURATION.new
+  end
+
+  def test_init
+    #assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_PRIMITIVE, @c_primitive
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN, @c_boolean
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_STRING, @c_string
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_INTEGER, @c_integer
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_REAL, @c_real
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_TIME, @c_time
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_DATE, @c_date
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_DATE_TIME, @c_date_time
+    assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_DURATION, @c_duration
+  end
+
+  def test_primitive
+    assert @c_boolean.true_valid
+    assert @c_boolean.false_valid
+    assert @c_boolean.assumed_value
+    assert @c_boolean.has_assumed_value?
+    assert @c_boolean.default_value
+    assert @c_boolean.default_value(true)
+    assert_raise(ArgumentError) do
+      @c_boolean.true_valid = false
+      @c_boolean.false_valid = false
+    end
+    assert_raise(ArgumentError) do 
+      OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid =>false,
+                                                                         :false_valid => false,
+                                                                         :assumed_value => false)
+    end
+  end
+  
+end
+
+class ArchetypeModelOntologyTest < Test::Unit::TestCase
+  def setup
+    @archetype_ontology = OpenEHR::AM::Archetype::Ontology::ARCHETYPE_ONTOLOGY.new
+    @archetype_term = OpenEHR::AM::Archetype::Ontology::ARCHETYPE_TERM.new(:code => '', :items => '')
+  end
+
+  def test_init
+    assert_instance_of OpenEHR::AM::Archetype::Ontology::ARCHETYPE_ONTOLOGY, @archetype_ontology
+    assert_instance_of OpenEHR::AM::Archetype::Ontology::ARCHETYPE_TERM, @archetype_term
+  end
+end
+    
+class ArchetypeModelAssertionTest < Test::Unit::TestCase
+  def setup
+    @assertion = OpenEHR::AM::Archetype::Assertion::ASSERTION.new
+    @assertion_variable = OpenEHR::AM::Archetype::Assertion::ASSERTION_VARIABLE.new
+    @operator_kind = OpenEHR::AM::Archetype::Assertion::OPERATOR_KIND.new
+    @expr_item = OpenEHR::AM::Archetype::Assertion::EXPR_ITEM.new
+    @expr_leaf = OpenEHR::AM::Archetype::Assertion::EXPR_LEAF.new
+    @expr_operator = OpenEHR::AM::Archetype::Assertion::EXPR_OPERATOR.new
+    @expr_unary_operator = OpenEHR::AM::Archetype::Assertion::EXPR_UNARY_OPERATOR.new
+    @expr_binary_operator = OpenEHR::AM::Archetype::Assertion::EXPR_BINARY_OPERATOR.new
+  end
+
+  def test_init
+    assert_instance_of OpenEHR::AM::Archetype::Assertion::ASSERTION, @assertion
+    assert_instance_of OpenEHR::AM::Archetype::Assertion::ASSERTION_VARIABLE, @assertion_variable
+    assert_instance_of OpenEHR::AM::Archetype::Assertion::OPERATOR_KIND, @operator_kind
+    assert_instance_of OpenEHR::AM::Archetype::Assertion::EXPR_ITEM, @expr_item
+    assert_instance_of OpenEHR::AM::Archetype::Assertion::EXPR_LEAF, @expr_leaf
+    assert_instance_of OpenEHR::AM::Archetype::Assertion::EXPR_OPERATOR, @expr_operator
+    assert_instance_of OpenEHR::AM::Archetype::Assertion::EXPR_UNARY_OPERATOR, @expr_unary_operator
+    assert_instance_of OpenEHR::AM::Archetype::Assertion::EXPR_BINARY_OPERATOR, @expr_binary_operator
+  end
+end
+
+class ArchetypeModelProfileTest < Test::Unit::TestCase
+  def setup
+    @c_dv_state = OpenEHR::AM::OpenEHR_Profile::Data_Types::Basic::C_DV_STATE.new
+    @state_machine = OpenEHR::AM::OpenEHR_Profile::Data_Types::Basic::STATE_MACHINE.new
+    @state = OpenEHR::AM::OpenEHR_Profile::Data_Types::Basic::STATE.new
+    @terminal_state = OpenEHR::AM::OpenEHR_Profile::Data_Types::Basic::TERMINAL_STATE.new
+    @non_terminal_state = OpenEHR::AM::OpenEHR_Profile::Data_Types::Basic::NON_TERMINAL_STATE.new
+    @transition = OpenEHR::AM::OpenEHR_Profile::Data_Types::Basic::TRANSITION.new
+
+    @c_code_phase = OpenEHR::AM::OpenEHR_Profile::Data_Types::Text::C_CODE_PHASE.new
+
+    @c_dv_quantity = OpenEHR::AM::OpenEHR_Profile::Data_Types::Quantity::C_DV_QUANTITY.new
+    @c_dv_ordinal = OpenEHR::AM::OpenEHR_Profile::Data_Types::Quantity::C_DV_ORDINAL.new
+    @c_quantity_item = OpenEHR::AM::OpenEHR_Profile::Data_Types::Quantity::C_QUANTITY_ITEM.new
+  end
+
+  def test_init
+    assert_instance_of OpenEHR::AM::OpenEHR_Profile::Data_Types::Basic::C_DV_STATE, @c_dv_state
+    assert_instance_of OpenEHR::AM::OpenEHR_Profile::Data_Types::Basic::STATE_MACHINE, @state_machine
+    assert_instance_of OpenEHR::AM::OpenEHR_Profile::Data_Types::Basic::STATE, @state
+    assert_instance_of OpenEHR::AM::OpenEHR_Profile::Data_Types::Basic::TERMINAL_STATE, @terminal_state
+    assert_instance_of OpenEHR::AM::OpenEHR_Profile::Data_Types::Basic::NON_TERMINAL_STATE, @non_terminal_state
+    assert_instance_of OpenEHR::AM::OpenEHR_Profile::Data_Types::Basic::TRANSITION, @transition
+    assert_instance_of OpenEHR::AM::OpenEHR_Profile::Data_Types::Text::C_CODE_PHASE, @c_code_phase
+    assert_instance_of OpenEHR::AM::OpenEHR_Profile::Data_Types::Quantity::C_DV_QUANTITY, @c_dv_quantity
+    assert_instance_of OpenEHR::AM::OpenEHR_Profile::Data_Types::Quantity::C_DV_ORDINAL, @c_dv_ordinal
+    assert_instance_of OpenEHR::AM::OpenEHR_Profile::Data_Types::Quantity::C_QUANTITY_ITEM, @c_quantity_item
+  end
+end
Index: /ruby/trunk/tests/models/test_assumed_library_types.rb
===================================================================
--- /ruby/trunk/tests/models/test_assumed_library_types.rb	(revision 62)
+++ /ruby/trunk/tests/models/test_assumed_library_types.rb	(revision 62)
@@ -0,0 +1,41 @@
+require 'test/unit'
+require 'assumed_library_types.rb'
+
+class Assumed_Library_Test < Test::Unit::TestCase
+  def setup
+    @interval = OpenEHR::Assumed_Library_Types::Interval.new(1,2)
+  end
+  def test_initialize
+    assert_instance_of OpenEHR::Assumed_Library_Types::Interval, @interval
+  end
+  def test_limits_comparable
+    assert @interval.lower < @interval.upper
+    @interval.set_lower(1.0)
+    @interval.set_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)
+    @interval.set_lower_included(true)
+    assert @interval.has?(1.0)
+    @interval.set_lower_included(false)
+    assert !@interval.has?(1.0)
+    @interval.set_upper_included(true)
+    assert @interval.has?(2.0)
+    @interval.set_upper_included(false)
+    assert !@interval.has?(2.0)
+  end
+  def test_lower_included_valid
+    @interval.set_lower(nil)
+    assert @interval.lower_unbounded
+    assert !@interval.lower_included
+    @interval.set_lower(1.0)
+  end
+  def test_upper_included_valid
+    @interval.set_upper(nil)
+    assert @interval.upper_unbounded
+    assert !@interval.upper_included
+  end
+end
Index: /ruby/trunk/tests/models/test_reference_model.rb
===================================================================
--- /ruby/trunk/tests/models/test_reference_model.rb	(revision 62)
+++ /ruby/trunk/tests/models/test_reference_model.rb	(revision 62)
@@ -0,0 +1,136 @@
+require 'test/unit'
+require 'set'
+require 'rm'
+
+class ReferenceModelTest < Test::Unit::TestCase
+  def setup
+    @authored_resource = OpenEHR::RM::Common::Resource::AUTHORED_RESOURCE.new(:original_language => "ja",
+                                                                              :translations => "en",
+                                                                              :description => "test")
+    @translation_details = OpenEHR::RM::Common::Resource::TRANSLATION_DETAILS.new(nil,nil,nil,nil,nil)
+#    @openehr_definitions = OpenEHR::RM::Support::Definition::OpenEHR_Definitions.new
+    @dv_boolean = OpenEHR::RM::Data_Types::Basic::DV_Boolean.new("TRUE")
+    @dv_state = OpenEHR::RM::Data_Types::Basic::DV_State.new("code1",true)
+    @dv_identifier = OpenEHR::RM::Data_Types::Basic::DV_Identifier.new("Ruby Hospital","0123456-0", "Information office", "personal id")
+    @dv_uri = OpenEHR::RM::Data_Types::URI::DV_URI.new("http://www.openehr.jp/changeset/test?cmd=93#file0")
+    @dv_ehr_uri = OpenEHR::RM::Data_Types::URI::DV_EHR_URI.new("ehr://1234567/87284370-2D4B-4e3d-A3F3-F303D2F4F34B@2005-08-02T04:30:00")
+    @dv_text = OpenEHR::RM::Data_Types::Text::DV_Text.new("valid value")
+    @dv_coded_text = OpenEHR::RM::Data_Types::Text::DV_Coded_Text.new("valid value", "AT1000")
+    @dv_paragraph = OpenEHR::RM::Data_Types::Text::DV_Paragraph.new(Set.new(["test1", "test2"]))
+  end
+  
+  def test_init
+    assert_instance_of OpenEHR::RM::Common::Resource::AUTHORED_RESOURCE, @authored_resource
+    assert_instance_of OpenEHR::RM::Common::Resource::TRANSLATION_DETAILS, @translation_details
+    assert_instance_of OpenEHR::RM::Data_Types::Basic::DV_Boolean, @dv_boolean
+    assert_instance_of OpenEHR::RM::Data_Types::Basic::DV_State, @dv_state
+    assert_instance_of OpenEHR::RM::Data_Types::Basic::DV_Identifier, @dv_identifier
+    assert_instance_of OpenEHR::RM::Data_Types::URI::DV_URI, @dv_uri
+    assert_instance_of OpenEHR::RM::Data_Types::URI::DV_EHR_URI, @dv_ehr_uri
+    assert_instance_of OpenEHR::RM::Data_Types::Text::DV_Text, @dv_text
+    assert_instance_of OpenEHR::RM::Data_Types::Text::DV_Coded_Text, @dv_coded_text
+  end
+
+  def test_constant
+    assert_equal("\r", OpenEHR::RM::Support::Definition::OpenEHR_Definitions::CR)
+    assert_equal("\n", OpenEHR::RM::Support::Definition::OpenEHR_Definitions::LF)
+    assert_equal("\r", OpenEHR::RM::Data_Types::Basic::Data_Value::CR)
+    assert_equal("\n", OpenEHR::RM::Data_Types::Basic::Data_Value::LF)
+  end
+
+  def test_dv_boolean
+    assert @dv_boolean.value?
+    @dv_boolean.value = false
+    assert !@dv_boolean.value?
+    # Constraints Value_exists
+    assert_raise(ArgumentError){@dv_boolean.value=nil}
+    assert_raise(ArgumentError){OpenEHR::RM::Data_Types::Basic::DV_Boolean.new(nil)}
+  end
+
+  def test_dv_state
+    assert_equal("code1", @dv_state.value)
+    @dv_state.value = "code2"
+    assert_equal("code2", @dv_state.value)
+    assert @dv_state.is_terminal?
+    @dv_state.terminal = false
+    assert !@dv_state.is_terminal?
+    assert_raise(ArgumentError) {OpenEHR::RM::Data_Types::Basic::DV_State.new(nil,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::Data_Types::Basic::DV_Identifier.new(nil, nil, nil, nil)}
+  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
+
+  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_dv_coded_text
+    assert_equal("valid value", @dv_coded_text.value)
+    assert_equal("AT1000", @dv_coded_text.defining_code)
+    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_terminology_mapping
+    
+  end
+end
+
+
+class ReferenceModelSupportIdentificationTest < Test::Unit::TestCase
+  def setup
+    @object_id = OpenEHR::RM::Support::Identification::OBJECT_ID.new
+    @terminology_id = OpenEHR::RM::Support::Identification::TERMINOLOGY_ID.new('terminology','version')
+    @archetype_id = OpenEHR::RM::Support::Identification::ARCHETYPE_ID.new
+  end
+  
+  def test_init
+    assert_instance_of OpenEHR::RM::Support::Identification::OBJECT_ID, @object_id
+    assert_instance_of OpenEHR::RM::Support::Identification::TERMINOLOGY_ID, @terminology_id
+    assert_instance_of OpenEHR::RM::Support::Identification::ARCHETYPE_ID, @archetype_id
+
+  end
+end
