$:.unshift(File.dirname(__FILE__)) require 'abstract_unit' class ErDiagramTest < Test::Unit::TestCase test_jude_model_dir :er_diagram def test_model001_check_model_api jude_project = jude_api_load "er001" assert jude_project.instance_of?(JudeApi::JudeModel) assert jude_project.id != nil assert_equal "er001", jude_project.name assert_equal [], jude_project.constraints assert_equal [], jude_project.constraints assert_equal [], jude_project.supplier_dependencies assert_equal [], jude_project.client_dependencies assert_equal "", jude_project.definition assert_equal nil, jude_project.is_public_visibility? assert_equal nil, jude_project.is_protected_visibility? assert_equal nil, jude_project.is_private_visibility? assert_equal nil, jude_project.is_package_visibility? assert_equal 2, jude_project.diagrams.size class_diagram = jude_project.diagrams[0] usecase_diagram = jude_project.diagrams[1] assert class_diagram.class == JudeApi::JudeClassDiagram assert usecase_diagram.class == JudeApi::JudeUseCaseDiagram assert jude_project.owned_elements[0].class == JudeApi::JudeErModel assert jude_project.owned_elements[1].class == JudeApi::JudePackage assert jude_project.owned_elements[2].class == JudeApi::JudeSubsystem assert jude_project.owned_elements[3].class == JudeApi::JudeModel assert jude_project.owned_elements[4].class == JudeApi::JudeClass assert jude_project.owned_elements[5].class == JudeApi::JudeUseCase end def test_model002_check_er_model_api jude_project = jude_api_load "er002" er_model = jude_project.er_model assert_equal jude_project.er_models[0], er_model assert er_model.instance_of?(JudeApi::JudeErModel) assert er_model.id != nil assert_equal jude_project, er_model.owner assert_equal [], er_model.comments assert_equal [], er_model.stereotypes assert_equal "er-model-value1", er_model.tagged["er_model_tag1"] assert_equal "er-model-value1", er_model.tagged[:er_model_tag1] assert_equal "er-model-value2", er_model.tagged[:er_model_tag2] assert_equal "ER-Model", er_model.name assert_equal [], er_model.constraints assert_equal [], er_model.constraints assert_equal [], er_model.supplier_dependencies assert_equal [], er_model.client_dependencies assert_equal "ER-Model-Definition", er_model.definition assert_equal true, er_model.is_public_visibility? assert_equal false, er_model.is_protected_visibility? assert_equal false, er_model.is_private_visibility? assert_equal false, er_model.is_package_visibility? assert_equal [], er_model.diagrams assert_equal JudeApi::JudeErSchema, er_model.schema.class assert_equal er_model.schemata[0], er_model.schema end def test_model003_check_er_schema_api jude_project = jude_api_load "er003" er_model = jude_project.er_model schema = er_model.schema assert schema.instance_of?(JudeApi::JudeErSchema) assert schema.id != nil assert_equal er_model, schema.owner assert_equal [], schema.comments assert_equal [], schema.stereotypes assert_equal "true", schema.tagged["jude.er.schema"] assert_equal "true", schema.tagged["jude.er.default_schema"] assert_equal "Default Schema", schema.name assert_equal [], schema.constraints assert_equal [], schema.supplier_dependencies assert_equal [], schema.client_dependencies assert_equal "", schema.definition assert_equal true, schema.is_public_visibility? assert_equal false, schema.is_protected_visibility? assert_equal false, schema.is_private_visibility? assert_equal false, schema.is_package_visibility? assert_equal 2, schema.diagrams.size er_diagram_1 = schema.diagrams[0] er_diagram_2 = schema.diagrams[1] assert_equal JudeApi::JudeErDiagram, er_diagram_1.class assert_equal JudeApi::JudeErDiagram, er_diagram_2.class assert_equal "er-diagram-1", er_diagram_1.name assert_equal "er-diagram-2", er_diagram_2.name assert_equal 2, schema.domains.size assert_equal JudeApi::JudeErDomain, schema.domains[0].class assert_equal JudeApi::JudeErDomain, schema.domains[1].class schema.datatypes.each{|x| assert_equal JudeApi::JudeErDatatype, x.class} assert_equal 2, schema.entities.size schema.entities.each{|x| assert_equal JudeApi::JudeErEntity, x.class} assert_equal "entity-1", schema.entities[0].name assert_equal "entity-2", schema.entities[1].name end def test_model004_check_er_domain_api jude_project = jude_api_load "er004" er_model = jude_project.er_model schema = er_model.schema domain1 = schema.domains[0] domain2 = schema.domains[1] [domain1, domain2].each{ |domain| assert_equal JudeApi::JudeErDomain, domain.class} assert domain1.id != nil assert_equal nil, domain1.owner assert_equal [], domain1.comments assert_equal [], domain1.stereotypes assert_equal "domain1_value1", domain1.tagged["domain1_key1"] assert_equal "domain1_value2", domain1.tagged["domain1_key2"] assert_equal "domain1", domain1.name assert_equal [], domain1.constraints assert_equal [], domain1.supplier_dependencies assert_equal [], domain1.client_dependencies assert_equal "domain1-definition", domain1.definition assert_equal true, domain1.is_public_visibility? assert_equal false, domain1.is_protected_visibility? assert_equal false, domain1.is_private_visibility? assert_equal false, domain1.is_package_visibility? assert_equal [], domain1.diagrams assert_equal "domain1", domain1.logical_name assert_equal "physical-domain1", domain1.physical_name assert_equal "CHAR", domain1.datatype_name assert_equal "NCHAR", domain2.datatype_name assert_equal "", domain1.default_value #TODO assert_equal "default2", domain2.default_value assert_equal "10", domain1.length_precision assert_equal "20", domain2.length_precision assert_equal false, domain1.is_not_null? assert_equal true, domain2.is_not_null? assert_equal 2, domain1.children.size assert_equal 2, domain2.children.size (domain1.children + domain2.children).each{ |domain| assert_equal JudeApi::JudeErDomain, domain.class} assert_equal "domain1-1", domain1.children[0].name assert_equal "domain1-2", domain1.children[1].name assert_equal "domain2-1", domain2.children[0].name assert_equal "domain2-2", domain2.children[1].name end def test_model005_check_er_datatype_api jude_project = jude_api_load "er005" er_model = jude_project.er_model schema = er_model.schema datatypes = schema.datatypes.select{|x|/^TEST/ =~ x.name} assert_equal 3, datatypes.size test_type1 = datatypes[0] test_type2 = datatypes[1] test_type3 = datatypes[2] [test_type1, test_type2, test_type3].each{ |domain| assert_equal JudeApi::JudeErDatatype, domain.class} assert test_type1.id != nil assert_equal nil, test_type1.owner assert_equal [], test_type1.comments assert_equal [], test_type1.stereotypes [test_type1, test_type2, test_type3].each do |test_type| assert_equal test_type.length_constraint, test_type.tagged["jude.datatype.length"] assert_equal test_type.precision_constraint, test_type.tagged["jude.datatype.precision"] assert_equal test_type.default_length_precision, test_type.tagged["jude.datatype.defaultLength"] end assert_equal "TEST_TYPE1", test_type1.name assert_equal [], test_type1.constraints assert_equal [], test_type1.supplier_dependencies assert_equal [], test_type1.client_dependencies assert_equal "TEST_TYPE1-definition", test_type1.definition assert_equal true, test_type1.is_public_visibility? assert_equal false, test_type1.is_protected_visibility? assert_equal false, test_type1.is_private_visibility? assert_equal false, test_type1.is_package_visibility? assert_equal [], test_type1.diagrams assert_equal "None", test_type1.length_constraint assert_equal "Optional", test_type2.length_constraint assert_equal "Required", test_type3.length_constraint assert_equal "None", test_type1.precision_constraint assert_equal "Optional", test_type2.precision_constraint assert_equal "Required", test_type3.precision_constraint assert_equal "", test_type1.default_length_precision assert_equal "10", test_type2.default_length_precision assert_equal "5,10", test_type3.default_length_precision end def test_model006_check_er_entity_api jude_project = jude_api_load "er006" er_model = jude_project.er_model schema = er_model.schema entities = schema.entities entity1 = schema.entities[0] entity2 = schema.entities[1] entity3 = schema.entities[2] entity4 = schema.entities[3] entity5 = schema.entities[4] entities.each{ |domain| assert_equal JudeApi::JudeErEntity, domain.class} assert entity1.id != nil assert_equal schema, entity1.owner assert_equal [], entity1.comments assert_equal [], entity1.stereotypes assert_equal "entity1_value1", entity1.tagged["entity1_key1"] assert_equal "entity1_value2", entity1.tagged["entity1_key2"] assert_equal "entity1", entity1.name assert_equal [], entity1.constraints assert_equal [], entity1.supplier_dependencies assert_equal [], entity1.client_dependencies assert_equal "entity1-definition", entity1.definition assert_equal true, entity1.is_public_visibility? assert_equal false, entity1.is_protected_visibility? assert_equal false, entity1.is_private_visibility? assert_equal false, entity1.is_package_visibility? assert_equal [], entity1.diagrams assert_equal "entity1", entity1.logical_name assert_equal "physical-entity1", entity1.physical_name assert_equal "Resource", entity1.type assert_equal ["pk1", "pk2", "fk2-1", "fk2-2"], entity1.primary_keys.collect{|x|x.name} assert_equal ["fk2-1", "fk2-2", "fk3-1", "fk3-2"], entity1.foreign_keys.collect{|x|x.name} assert_equal ["attr1", "attr2", "fk3-1", "fk3-2"], entity1.non_primary_keys.collect{|x|x.name} assert_equal ["relationship1", "relationship2"], entity1.parent_relationships.collect{|x|x.name} assert_equal [], entity2.parent_relationships assert_equal [], entity1.children_relationships assert_equal ["relationship1"], entity2.children_relationships.collect{|x|x.name} assert_equal ["relationship2"], entity3.children_relationships.collect{|x|x.name} assert_equal ["sub1", "sub2"], entity1.children_subtype_relationships.collect{|x|x.name} assert_equal [], entity4.children_relationships assert_equal [], entity5.children_relationships assert_equal [], entity1.parent_subtype_relationships assert_equal ["sub1"], entity4.parent_subtype_relationships.collect{|x|x.name} assert_equal ["sub2"], entity5.parent_subtype_relationships.collect{|x|x.name} end def test_model007_check_er_attribute jude_project = jude_api_load "er007" er_model = jude_project.er_model schema = er_model.schema entity1 = schema.entities[0] domain1 = schema.domains[0] varchar_type = schema.datatypes.find{|x|"VARCHAR" == x.name} primarys = entity1.primary_keys foreigns = entity1.foreign_keys non_primarys = entity1.non_primary_keys attributes = (primarys + foreigns + non_primarys).uniq pk1 = primarys[0] pk2 = primarys[1] attr1 = non_primarys[0] fk2_1 = foreigns[0] attributes.each{ |attr| assert_equal JudeApi::JudeErAttribute, attr.class} assert pk1.id != nil assert_equal entity1, pk1.owner assert_equal [], pk1.comments assert_equal [], pk1.stereotypes assert_equal "pk1_value1", pk1.tagged["pk1_key1"] assert_equal "pk1_value2", pk1.tagged["pk1_key2"] assert_equal ["pk1","pk2"], [pk1.name, pk2.name] pk_constraint = pk1.constraints[0] not_null_constraint = pk1.constraints[1] pk1.constraints.each {|x| assert_equal JudeApi::JudeConstraint, x.class } assert_equal ["PRIMARY KEY", "NOT NULL"], [pk_constraint.name, not_null_constraint.name] assert_equal [], pk1.supplier_dependencies assert_equal [], pk1.client_dependencies assert_equal "pk1-definition", pk1.definition assert_equal "pk1", pk1.logical_name assert_equal "physical_pk1", pk1.physical_name primarys.each {|x| assert_equal true, x.is_primary_key?} non_primarys.each {|x| assert_equal false, x.is_primary_key?} foreigns.each {|x| assert_equal true, x.is_foreign_key?} (attributes - foreigns).each {|x| assert_equal false, x.is_foreign_key?} assert_equal domain1, pk1.domain assert_equal [nil, varchar_type], [pk1.datatype, pk2.datatype] assert_equal ["", "10"], [pk1.length_precision, pk2.length_precision] assert_equal [true, false], [pk1.is_not_null?, attr1.is_not_null?] assert_equal ["", "pk2-default"], [pk1.default_value, pk2.default_value] assert_equal nil, pk1.constraint("hoge") assert_equal pk_constraint, pk1.constraint("PRIMARY KEY") assert_equal not_null_constraint, pk1.constraint("NOT NULL") assert_equal nil, pk1.referenced_primary_key assert_equal "e2-pk1", fk2_1.referenced_primary_key.name assert_equal ["e4-pk1", "e5-pk1"], pk1.referenced_foreign_keys.collect{|x|x.name} assert_equal [], attr1.referenced_foreign_keys assert_equal nil, pk1.referenced_relationship assert_equal "relationship1", fk2_1.referenced_relationship.name assert_equal ["sub1", "sub2"], pk1.referenced_subtype_relationships.collect{|x|x.name} assert_equal [], fk2_1.referenced_subtype_relationships e4_pk1 = pk1.referenced_foreign_keys[0] assert_equal "sub1", e4_pk1.subtype_foreign_key_inv.name assert_equal nil, pk1.subtype_foreign_key_inv end def test_model008_check_er_relationship jude_project = jude_api_load "er008" er_model = jude_project.er_model schema = er_model.schema entity1 = schema.entities[0] entity2 = schema.entities[1] relationships = entity1.parent_relationships relationship1 = entity1.parent_relationships[0] relationship2 = entity1.parent_relationships[1] relationship3 = entity1.children_relationships[0] relationships.each{ |r| assert_equal JudeApi::JudeErRelationship, r.class} assert relationship1.id != nil assert_equal schema, relationship1.owner assert_equal [], relationship1.comments assert_equal [], relationship1.stereotypes assert_equal "relationship1_value1", relationship1.tagged["relationship1_key1"] assert_equal "relationship1_value2", relationship1.tagged["relationship1_key2"] assert_equal ["relationship1","relationship2"], [relationship1.name, relationship2.name] assert_equal [], relationship1.constraints assert_equal [], relationship1.supplier_dependencies assert_equal [], relationship1.client_dependencies assert_equal "relation1-definition", relationship1.definition assert_equal true, relationship1.is_public_visibility? assert_equal false, relationship1.is_protected_visibility? assert_equal false, relationship1.is_private_visibility? assert_equal false, relationship1.is_package_visibility? assert_equal [], relationship1.diagrams assert_equal "relationship1", relationship1.logical_name assert_equal "p-r1", relationship1.physical_name assert_equal "r-child", relationship1.verb_phrase_parent assert_equal "r-parent", relationship1.verb_phrase_child assert_equal true, relationship1.is_identifying? assert_equal false, relationship2.is_identifying? assert_equal false, relationship1.is_non_identifying? assert_equal true, relationship2.is_non_identifying? assert_equal false, relationship1.is_multi_to_multi? assert_equal true, relationship3.is_multi_to_multi? assert_equal true, relationship1.is_parent_required? assert_equal false, relationship3.is_parent_required? assert_equal entity2, relationship1.parent assert_equal entity1, relationship1.child end def test_model009_check_er_subtype_relationship jude_project = jude_api_load "er009" er_model = jude_project.er_model schema = er_model.schema entity1 = schema.entities[0] entity4 = schema.entities[3] pk1 = entity1.primary_keys[0] subs = entity1.children_subtype_relationships sub1 = subs[0] sub2 = subs[1] subs.each{ |r| assert_equal JudeApi::JudeErSubtypeRelationship, r.class} assert sub1.id != nil assert_equal schema, sub1.owner assert_equal [], sub1.comments assert_equal [], sub1.stereotypes assert_equal "sub1_value1", sub1.tagged["sub1_key1"] assert_equal "sub1_value2", sub1.tagged["sub1_key2"] assert_equal ["sub1","sub2"], [sub1.name, sub2.name] assert_equal [], sub1.constraints assert_equal [], sub1.supplier_dependencies assert_equal [], sub1.client_dependencies assert_equal "sub1-definition", sub1.definition assert_equal true, sub1.is_public_visibility? assert_equal false, sub1.is_protected_visibility? assert_equal false, sub1.is_private_visibility? assert_equal false, sub1.is_package_visibility? assert_equal [], sub1.diagrams assert_equal "sub1", sub1.logical_name assert_equal "p-sub1", sub1.physical_name assert_equal pk1, sub1.discriminator_attribute assert_equal true, sub1.is_conclusive? assert_equal false, sub2.is_conclusive? assert_equal entity1, sub1.parent assert_equal entity4, sub1.child assert_equal ["e4-pk1", "e4-pk2", "fk2-1", "fk2-2"], sub1.foreign_keys.collect{|x|x.name} end end