$:.unshift(File.dirname(__FILE__)) require 'abstract_unit' class ClassDiagramTest < Test::Unit::TestCase test_jude_model_dir :class_diagram def setup super # Luruju::Configuration.install do |config| # config.access_jruby_with = :command # end end def test_model001_check_class_api jude_project = jude_api_load("model001") assert(jude_project.instance_of?(JudeApi::JudeModel)) assert(jude_project.id != nil) assert_equal("model001", jude_project.name) human_class = jude_project.find_class_by_name("Human") animal_class = jude_project.find_class_by_name("Animal") programmer_if = jude_project.find_class_by_name("IProgrammer") assert(human_class.instance_of?(JudeApi::JudeClass)) #IElement assert(human_class.id) assert_same(jude_project, human_class.owner) assert_equal(0, human_class.comments.size) assert_equal(2, human_class.stereotypes.size) assert_equal("stereotype1", human_class.stereotypes[0]) assert_equal("stereotype2", human_class.stereotypes[1]) assert_equal(0, human_class.tagged_values.size) #INamedElement assert_equal("Human", human_class.name) assert_equal(0, human_class.constraints.size) assert_equal(0, human_class.comments.size) assert_equal(0, human_class.supplier_dependencies.size) assert_equal(0, human_class.client_dependencies.size) assert_equal("ClassDefinition", human_class.definition) assert_equal(true, human_class.is_public_visibility?) assert_equal(false, human_class.is_protected_visibility?) assert_equal(false, human_class.is_private_visibility?) assert_equal(false, human_class.is_package_visibility?) assert_equal(false, animal_class.is_public_visibility?) assert_equal(true, animal_class.is_protected_visibility?) assert_equal(false, animal_class.is_private_visibility?) assert_equal(false, animal_class.is_package_visibility?) assert_equal(0, human_class.diagrams.size) #IClass assert_equal(false, human_class.is_abstract?) assert_equal(true, animal_class.is_abstract?) assert_equal(true, human_class.is_leaf?) assert_equal(false, animal_class.is_leaf?) assert_equal(false, human_class.is_active?) assert_equal(true, animal_class.is_active?) assert_equal(4, human_class.attributes.size) assert_equal(1, human_class.select_attributes_by_name("attr1").size) assert_equal(1, human_class.select_attributes_by_name("attr2").size) assert_equal(1, human_class.select_attributes_by_name("has-car").size) assert_equal(1, human_class.select_attributes_by_name("has-pc").size) assert_equal(2, human_class.operations.size) assert_equal(1, human_class.select_operations_by_name("ope1").size) assert_equal(1, human_class.select_operations_by_name("ope2").size) assert_equal(0, human_class.nested_classes.size) assert_equal(2, human_class.generalizations.size) assert_equal("Animal-Human", human_class.generalizations[0].name) assert_equal("Dream-Human", human_class.generalizations[1].name) assert_equal(0, human_class.specializations.size) assert_equal(2, animal_class.specializations.size) assert_equal("Animal-Human", animal_class.specializations[0].name) assert_equal("Animal-Dog", animal_class.specializations[1].name) assert_equal(0, human_class.supplier_realizations.size) assert_equal(2, programmer_if.supplier_realizations.size) assert_equal("IProgrammer-Human", programmer_if.supplier_realizations[0].name) assert_equal("IProgrammer-Dog", programmer_if.supplier_realizations[1].name) assert_equal(2, human_class.client_realizations.size) assert_equal("IProgrammer-Human", human_class.client_realizations[0].name) assert_equal("IDriver-Human", human_class.client_realizations[1].name) end def test_model002_check_attribute_api jude_project = jude_api_load("model002") human_class = jude_project.find_class_by_name("Human") name_attr = human_class.find_attribute_by_name("name") age_attr = human_class.find_attribute_by_name("age") weight_attr = human_class.find_attribute_by_name("weight") from_attr = human_class.find_attribute_by_name("from") car_attr = human_class.find_attributes_by_name("has-car") assert(name_attr.instance_of?(JudeApi::JudeAttribute)) #IElement assert(name_attr.id) assert_same(human_class, name_attr.owner) assert_equal(0, name_attr.comments.size) assert_equal(2, name_attr.stereotypes.size) assert_equal("stereotype1", name_attr.stereotypes[0]) assert_equal("stereotype2", name_attr.stereotypes[1]) assert_equal(0, name_attr.tagged_values.size) # NamedElement assert_equal("name", name_attr.name) assert_equal(2, name_attr.constraints.size) assert_equal("constraint1", name_attr.constraints[0].name) assert_equal("constraint2", name_attr.constraints[1].name) assert_equal(0, name_attr.comments.size) assert_equal(0, name_attr.supplier_dependencies.size) assert_equal(0, name_attr.client_dependencies.size) assert_equal("AttributeDefinition", name_attr.definition) assert_equal(true, name_attr.is_private_visibility?) assert_equal(false, name_attr.is_package_visibility?) assert_equal(false, name_attr.is_protected_visibility?) assert_equal(false, name_attr.is_public_visibility?) assert_equal(false, age_attr.is_private_visibility?) assert_equal(true, age_attr.is_package_visibility?) assert_equal(false, age_attr.is_protected_visibility?) assert_equal(false, age_attr.is_public_visibility?) assert_equal(false, weight_attr.is_private_visibility?) assert_equal(false, weight_attr.is_package_visibility?) assert_equal(true, weight_attr.is_protected_visibility?) assert_equal(false, weight_attr.is_public_visibility?) assert_equal(false, from_attr.is_private_visibility?) assert_equal(false, from_attr.is_package_visibility?) assert_equal(false, from_attr.is_protected_visibility?) assert_equal(true, from_attr.is_public_visibility?) assert_equal(0, name_attr.diagrams.size) #IAttribute assert_equal("String", name_attr.type.name) assert_equal("String", name_attr.type_expression) assert_equal("", name_attr.initial_value) assert_equal("0", age_attr.initial_value) assert_equal(true, name_attr.is_changeable?) assert_equal(false, weight_attr.is_changeable?) assert_equal(nil, name_attr.association) assert_equal("Human-has-Car", car_attr.association.name) assert_equal(0, name_attr.qualifiers.size) # TODO qualifierは何者? assert_equal(0, name_attr.multiplicity.size) assert_equal(1, car_attr.multiplicity.size) assert_equal(false, name_attr.is_derived?) assert_equal(true, from_attr.is_derived?) assert_equal(false, name_attr.is_composite?) # TODO 本当はtrue #assert_equal(true, weight_attr.is_composite?) assert_equal(false, name_attr.is_aggregate?) # TODO 本当はtrue #assert_equal(true, age_attr.is_aggregate?) assert_equal(true, name_attr.is_enable?) assert_equal(false, name_attr.is_static?) assert_equal(true, age_attr.is_static?) end def test_model003_check_opperation_api jude_project = jude_api_load("model003") human_class = jude_project.find_class_by_name("Human") assert_equal 4, human_class.operations.size eat_ope = human_class.find_operation_by_name("eat") drink_ope = human_class.find_operation_by_name("drink") work_ope = human_class.find_operation_by_name("work") play_ope = human_class.find_operation_by_name("play") assert(eat_ope.instance_of?(JudeApi::JudeOperation)) #IElement assert(eat_ope.id) assert_same(human_class, eat_ope.owner) assert_equal(0, eat_ope.comments.size) assert_equal(2, eat_ope.stereotypes.size) assert_equal("stereotype1", eat_ope.stereotypes[0]) assert_equal("stereotype2", eat_ope.stereotypes[1]) assert_equal(0, eat_ope.tagged_values.size) # NamedElement assert_equal("eat", eat_ope.name) assert_equal(2, eat_ope.constraints.size) assert_equal("constraint1", eat_ope.constraints[0].name) assert_equal("constraint2", eat_ope.constraints[1].name) assert_equal(0, eat_ope.comments.size) assert_equal(0, eat_ope.supplier_dependencies.size) assert_equal(0, eat_ope.client_dependencies.size) assert_equal("OperationDefinition", eat_ope.definition) assert_equal(false, eat_ope.is_private_visibility?) assert_equal(false, eat_ope.is_package_visibility?) assert_equal(false, eat_ope.is_protected_visibility?) assert_equal(true, eat_ope.is_public_visibility?) assert_equal(false, drink_ope.is_private_visibility?) assert_equal(false, drink_ope.is_package_visibility?) assert_equal(true, drink_ope.is_protected_visibility?) assert_equal(false, drink_ope.is_public_visibility?) assert_equal(false, work_ope.is_private_visibility?) assert_equal(true, work_ope.is_package_visibility?) assert_equal(false, work_ope.is_protected_visibility?) assert_equal(false, work_ope.is_public_visibility?) assert_equal(true, play_ope.is_private_visibility?) assert_equal(false, play_ope.is_package_visibility?) assert_equal(false, play_ope.is_protected_visibility?) assert_equal(false, play_ope.is_public_visibility?) assert_equal(0, eat_ope.diagrams.size) #IOperation assert_equal(0, eat_ope.parameters.size) assert_equal(2, drink_ope.parameters.size) assert_equal("param0", drink_ope.parameters[0].name) assert_equal("param1", drink_ope.parameters[1].name) assert_equal("void", eat_ope.return_type.name) assert_equal("int", drink_ope.return_type.name) assert_equal("String", work_ope.return_type.name) assert_equal("void", eat_ope.return_type_expression) assert_equal("int", drink_ope.return_type_expression) assert_equal("String", work_ope.return_type_expression) assert_equal(false, eat_ope.is_leaf?) assert_equal(true, play_ope.is_leaf?) assert_equal(false, eat_ope.is_abstract?) assert_equal(true, work_ope.is_abstract?) assert_equal(false, eat_ope.is_static?) assert_equal(true, drink_ope.is_static?) end def test_model003_check_parameter_api jude_project = jude_api_load("model003") human_class = jude_project.find_class_by_name("Human") string_class = jude_project.find_class_by_name("String") drink_ope = human_class.find_operation_by_name("drink") param1_param = drink_ope.parameters[0] param2_param = drink_ope.parameters[1] assert(param1_param.instance_of?(JudeApi::JudeParameter)) assert_equal("int", param1_param.type.name) assert_equal(string_class, param2_param.type) assert_equal("int", param1_param.type_expression) assert_equal("String", param2_param.type_expression) end def test_model04_check_constraint_api jude_project = jude_api_load("model004") human_class = jude_project.find_class_by_name("Human") soul_attr = human_class.find_attribute_by_name("soul") body_attr = human_class.find_attribute_by_name("body") notnull_constraint = soul_attr.constraints[0] assert(notnull_constraint.instance_of?(JudeApi::JudeConstraint)) assert_equal("notnull", notnull_constraint.specification) assert_equal(1, notnull_constraint.constrained_element.size) assert_same(soul_attr, notnull_constraint.constrained_element[0]) end def test_model005_check_dependency_api jude_project = jude_api_load("model005") human_class = jude_project.find_class_by_name("Human") food_class = jude_project.find_class_by_name("Food") eat_dependency = human_class.client_dependencies[0] cook_dependency = human_class.client_dependencies[1] assert_same(eat_dependency, food_class.supplier_dependencies[0]) assert_same(cook_dependency, food_class.supplier_dependencies[1]) assert(eat_dependency.instance_of?(JudeApi::JudeDependency)) assert(cook_dependency.instance_of?(JudeApi::JudeDependency)) assert_equal("eat", eat_dependency.name) assert_equal("cook", cook_dependency.name) assert_same(human_class, eat_dependency.client) assert_same(human_class, cook_dependency.client) assert_same(food_class, eat_dependency.supplier) assert_same(food_class, cook_dependency.supplier) end def test_model006_check_genaralization_api jude_project = jude_api_load("model006") human_class = jude_project.find_class_by_name("Human") animal_class = jude_project.find_class_by_name("Animal") generalization = human_class.generalizations[0] assert(generalization.instance_of?(JudeApi::JudeGeneralization)) assert_same(generalization, animal_class.specializations[0]) assert_equal("Human_is_a_kind_of_Animal", generalization.name) assert_same(human_class, generalization.sub_type) assert_same(animal_class, generalization.super_type) end def test_model007_check_association_api jude_project = jude_api_load("model007") human_class = jude_project.find_class_by_name("Human") car_class = jude_project.find_class_by_name("Car") pet_class = jude_project.find_class_by_name("Pet") foot_class = jude_project.find_class_by_name("Foot") heart_class = jude_project.find_class_by_name("Heart") dream_class = jude_project.find_class_by_name("Dream") love_class = jude_project.find_class_by_name("Love") car_attr = human_class.find_attribute_by_name("car") pet_attr = human_class.find_attribute_by_name("pet") foot_attr = human_class.find_attribute_by_name("foot") heart_attr = human_class.find_attribute_by_name("heart") dream_attr = human_class.find_attribute_by_name("dream") love_attr = human_class.find_attribute_by_name("love") owner_attr = car_class.attributes[0] master_attr = pet_class.attributes[0] ordered_attr = foot_class.attributes[0] belonged_attr = heart_class.attributes[0] dreamed_attr = dream_class.attributes[0] loved_attr = love_class.attributes[0] car_association = car_attr.association pet_association = pet_attr.association foot_association = foot_attr.association heart_association = heart_attr.association dream_association = dream_attr.association love_association = love_attr.association assert(car_association.instance_of?(JudeApi::JudeAssociation)) assert_equal("Human_has_Car", car_association.name) assert_equal("Human_has_Pet", pet_association.name) assert_equal("Foot_is_a_part_of_Human", foot_association.name) assert_equal("Heart_is_a_part_of_Human", heart_association.name) assert_equal("Human_should_have_Dream", dream_association.name) assert_equal("Human_should_have_Love", love_association.name) assert_same(owner_attr, car_association.attributes[0]) assert_same(master_attr, pet_association.attributes[0]) assert_same(ordered_attr, foot_association.attributes[0]) assert_same(belonged_attr, heart_association.attributes[0]) assert_same(dreamed_attr, dream_association.attributes[0]) assert_same(loved_attr, love_association.attributes[0]) assert_same(car_attr, car_association.attributes[1]) assert_same(pet_attr, pet_association.attributes[1]) assert_same(foot_attr, foot_association.attributes[1]) assert_same(heart_attr, heart_association.attributes[1]) assert_same(dream_attr, dream_association.attributes[1]) assert_same(love_attr, love_association.attributes[1]) end def test_model007_check_multiplicities jude_project = jude_api_load("model007") human_class = jude_project.find_class_by_name("Human") car_attr = human_class.find_attribute_by_name("car") pet_attr = human_class.find_attribute_by_name("pet") foot_attr = human_class.find_attribute_by_name("foot") heart_attr = human_class.find_attribute_by_name("heart") dream_attr = human_class.find_attribute_by_name("dream") love_attr = human_class.find_attribute_by_name("love") car_multiplicity = car_attr.multiplicity[0] pet_multiplicity = pet_attr.multiplicity[0] foot_multiplicity = foot_attr.multiplicity[0] heart_multiplicity = heart_attr.multiplicity[0] dream_multiplicity = dream_attr.multiplicity[0] love_multiplicity = love_attr.multiplicity[0] assert(car_multiplicity.instance_of?(JudeApi::JudeMultiplicityRange)) undefined = JudeApi::JudeMultiplicityRange::UNDEFINED unlimited = JudeApi::JudeMultiplicityRange::UNLIMITED assert_equal(-100, undefined) assert_equal(-1, unlimited) assert_equal(0, car_multiplicity.lower) assert_equal(unlimited, car_multiplicity.upper) assert_equal(unlimited, pet_multiplicity.lower) assert_equal(unlimited, pet_multiplicity.upper) assert_equal(undefined, foot_multiplicity.lower) assert_equal(undefined, foot_multiplicity.upper) assert_equal(1, heart_multiplicity.lower) assert_equal(1, heart_multiplicity.upper) assert_equal(1, dream_multiplicity.lower) assert_equal(unlimited, dream_multiplicity.upper) assert_equal(0, love_multiplicity.lower) assert_equal(1, love_multiplicity.upper) end def test_model008_check_association_class_api jude_project = jude_api_load("model008") contract_association_class = jude_project.find_association_class_by_name("Contract") employee_class = jude_project.find_class_by_name("Employee") employer_class = jude_project.find_class_by_name("Employer") assert(contract_association_class.instance_of?(JudeApi::JudeAssociationClass)) assert_same(contract_association_class, employee_class.attributes[0].association) assert_same(contract_association_class, employer_class.attributes[0].association) assert contract_association_class.kind_of_class? end def test_model009_check_model_api model009_model = jude_api_load("model009") assert(model009_model.instance_of?(JudeApi::JudeModel)) assert_equal("model009", model009_model.name) assert_equal(6, model009_model.owned_elements.size) assert_equal("package1", model009_model.owned_elements[0].name) assert_equal("subsystem1", model009_model.owned_elements[1].name) assert_equal("model1", model009_model.owned_elements[2].name) assert_equal("Class1", model009_model.owned_elements[3].name) assert_equal("actor1", model009_model.owned_elements[4].name) assert_equal("usecase1", model009_model.owned_elements[5].name) assert_equal(1, model009_model.diagrams.size) assert_equal("class-diagram1", model009_model.diagrams[0].name) end def test_model010_check_subsystem_api model010_model = jude_api_load("model010") subsystem1 = model010_model.owned_elements[0] actor1 = subsystem1.owned_elements[0] usecase1 = subsystem1.owned_elements[1] model1 = subsystem1.owned_elements[2] package1 = subsystem1.owned_elements[3] class1 = subsystem1.owned_elements[4] interface1 = subsystem1.owned_elements[5] subsystem2 = subsystem1.owned_elements[6] assert(subsystem1.instance_of?(JudeApi::JudeSubsystem)) assert(subsystem2.instance_of?(JudeApi::JudeSubsystem)) assert_equal("subsystem1", subsystem1.name) assert_equal("subsystem2", subsystem2.name) assert_equal("actor1", actor1.name) assert_equal("usecase1", usecase1.name) assert_equal("model1", model1.name) assert_equal("package1", package1.name) assert_equal("Class1", class1.name) assert_equal("interface1", interface1.name) assert_equal("operation1", subsystem1.operations[0].name) assert_equal("operation2", subsystem1.operations[1].name) assert_same(subsystem2, subsystem1.generalizations[0].super_type) assert_same(subsystem1, subsystem2.specializations[0].sub_type) assert_same(interface1, subsystem1.client_realizations[0].supplier) end def test_model011_check_package_api model011_model = jude_api_load("model011") package1 = model011_model.owned_elements[0] assert(package1.instance_of?(JudeApi::JudePackage)) assert_equal("package1", package1.name) assert_equal("package2", package1.owned_elements[0].name) assert_equal("Class1", package1.owned_elements[1].name) assert_equal("actor1", package1.owned_elements[2].name) assert_equal("usecase1", package1.owned_elements[3].name) assert_equal("subsystem1", package1.owned_elements[4].name) assert_equal(1, package1.diagrams.size) assert_equal("class-diagram1", package1.diagrams[0].name) package1.owned_elements.each{|child| assert_equal(package1, child.owner)} end def test_model012_check_usecase_api model012_model = jude_api_load("model012") usecase1 = model012_model.owned_elements[0] usecase2 = model012_model.owned_elements[1] usecase3 = model012_model.owned_elements[2] usecase4 = model012_model.owned_elements[3] usecase5 = model012_model.owned_elements[4] assert(usecase1.instance_of?(JudeApi::JudeUseCase)) assert(usecase2.instance_of?(JudeApi::JudeUseCase)) assert(usecase3.instance_of?(JudeApi::JudeUseCase)) assert(usecase4.instance_of?(JudeApi::JudeUseCase)) assert(usecase5.instance_of?(JudeApi::JudeUseCase)) assert_equal("usecase1", usecase1.name) assert_equal("usecase2", usecase2.name) assert_equal("usecase3", usecase3.name) assert_equal("usecase4", usecase4.name) assert_equal("usecase5", usecase5.name) assert_equal("extention-point1", usecase1.extension_points[0].name) assert_equal("extention-point2", usecase1.extension_points[1].name) assert_equal("include1", usecase1.includes[0].name) assert_equal("include2", usecase1.includes[1].name) assert_equal("include1", usecase2.addition_invs[0].name) assert_equal("include2", usecase3.addition_invs[0].name) assert_equal("extend1", usecase1.extends[0].name) assert_equal("extend2", usecase1.extends[1].name) assert_equal("extend1", usecase4.extended_case_invs[0].name) assert_equal("extend2", usecase5.extended_case_invs[0].name) end def test_model012_check_extention_point_api model012_model = jude_api_load("model012") usecase1 = model012_model.owned_elements[0] usecase2 = model012_model.owned_elements[1] usecase3 = model012_model.owned_elements[2] usecase4 = model012_model.owned_elements[3] usecase5 = model012_model.owned_elements[4] extention_point1 = usecase1.extension_points[0] extention_point2 = usecase1.extension_points[1] assert(extention_point1.instance_of?(JudeApi::JudeExtentionPoint)) assert(extention_point2.instance_of?(JudeApi::JudeExtentionPoint)) assert_equal("extention-point1", extention_point1.name) assert_equal("extention-point2", extention_point2.name) end def test_model012_check_extend_api model012_model = jude_api_load("model012") usecase1 = model012_model.owned_elements[0] usecase4 = model012_model.owned_elements[3] usecase5 = model012_model.owned_elements[4] extend1 = usecase1.extends[0] extend2 = usecase1.extends[1] assert(extend1.instance_of?(JudeApi::JudeExtend)) assert(extend2.instance_of?(JudeApi::JudeExtend)) assert_equal("extend1", extend1.name) assert_equal("extend2", extend2.name) assert_same(usecase1, extend1.extension) assert_same(usecase1, extend2.extension) assert_same(usecase4, extend1.extended_case) assert_same(usecase5, extend2.extended_case) end def test_model012_check_include_api model012_model = jude_api_load("model012") usecase1 = model012_model.owned_elements[0] usecase2 = model012_model.owned_elements[1] usecase3 = model012_model.owned_elements[2] include1 = usecase1.includes[0] include2 = usecase1.includes[1] assert(include1.instance_of?(JudeApi::JudeInclude)) assert(include2.instance_of?(JudeApi::JudeInclude)) assert_equal("include1", include1.name) assert_equal("include2", include2.name) assert_same(usecase2, include1.addition) assert_same(usecase3, include2.addition) assert_same(usecase1, include1.including_case) assert_same(usecase1, include2.including_case) end def test_model013_check_japanese jude_project = jude_api_load("model013") human_class = jude_project.classes[0] assert_equal("日本語テスト", human_class.name) end end