Ejemplo n.º 1
0
    def connect_subject(self, handle):
        element = self.element
        line = self.line

        c1 = self.get_connected(line.head)
        c2 = self.get_connected(line.tail)
        if c1 and c2:
            head_type = c1.subject
            tail_type = c2.subject

            # First check if we do not already contain the right subject:
            if line.subject:
                end1 = line.subject.memberEnd[0]
                end2 = line.subject.memberEnd[1]
                if (end1.type is head_type and end2.type is tail_type) \
                        or (end2.type is head_type and end1.type is tail_type):
                    return

            # Create new association
            relation = modelfactory.create_association(self.element_factory,
                                                       head_type, tail_type)
            relation.package = element.canvas.diagram.namespace

            line.head_end.subject = relation.memberEnd[0]
            line.tail_end.subject = relation.memberEnd[1]

            # Do subject itself last, so event handlers can trigger
            line.subject = relation
Ejemplo n.º 2
0
    def test_creation(self):
        """Test association creation
        """
        c1 = self.factory.create(uml2.Class)
        c2 = self.factory.create(uml2.Class)
        assoc = modelfactory.create_association(self.factory, c1, c2)
        types = [p.type for p in assoc.memberEnd]
        self.assertTrue(c1 in types, assoc.memberEnd)
        self.assertTrue(c2 in types, assoc.memberEnd)

        c1 = self.factory.create(uml2.Interface)
        c2 = self.factory.create(uml2.Interface)
        assoc = modelfactory.create_association(self.factory, c1, c2)
        types = [p.type for p in assoc.memberEnd]
        self.assertTrue(c1 in types, assoc.memberEnd)
        self.assertTrue(c2 in types, assoc.memberEnd)
Ejemplo n.º 3
0
    def test_attribute_navigability(self):
        """Test navigable attribute of a class or an interface
        """
        c1 = self.factory.create(uml2.Class)
        c2 = self.factory.create(uml2.Class)
        assoc = modelfactory.create_association(self.factory, c1, c2)

        end = assoc.memberEnd[0]
        assert end.type is c1
        assert end.type is c1

        modelfactory.set_navigability(assoc, end, True)

        # class/interface navigablity, Association.navigableOwnedEnd not
        # involved
        self.assertTrue(end not in assoc.navigableOwnedEnd)
        self.assertTrue(end not in assoc.ownedEnd)
        self.assertTrue(end in c2.ownedAttribute)
        self.assertTrue(end.navigability is True)

        # uknown navigability
        modelfactory.set_navigability(assoc, end, None)
        self.assertTrue(end not in assoc.navigableOwnedEnd)
        self.assertTrue(end in assoc.ownedEnd)
        self.assertTrue(end not in c2.ownedAttribute)
        self.assertTrue(end.owner is assoc)
        self.assertTrue(end.navigability is None)

        # non-navigability
        modelfactory.set_navigability(assoc, end, False)
        self.assertTrue(end not in assoc.navigableOwnedEnd)
        self.assertTrue(end not in assoc.ownedEnd)
        self.assertTrue(end not in c2.ownedAttribute)
        self.assertTrue(end.owner is None)
        self.assertTrue(end.navigability is False)

        # check other navigability change possibilities
        modelfactory.set_navigability(assoc, end, None)
        self.assertTrue(end not in assoc.navigableOwnedEnd)
        self.assertTrue(end in assoc.ownedEnd)
        self.assertTrue(end not in c2.ownedAttribute)
        self.assertTrue(end.owner is assoc)
        self.assertTrue(end.navigability is None)

        modelfactory.set_navigability(assoc, end, True)
        self.assertTrue(end not in assoc.navigableOwnedEnd)
        self.assertTrue(end not in assoc.ownedEnd)
        self.assertTrue(end in c2.ownedAttribute)
        self.assertTrue(end.owner is c2)
        self.assertTrue(end.navigability is True)
Ejemplo n.º 4
0
    def test_property_navigability(self):
        factory = elementfactory.ElementFactory()
        p = factory.create(uml2.Property)
        assert p.navigability is None

        c1 = factory.create(uml2.Class)
        c2 = factory.create(uml2.Class)
        a = modelfactory.create_association(factory, c1, c2)
        assert a.memberEnd[0].navigability is None
        assert a.memberEnd[1].navigability is None

        modelfactory.set_navigability(a, a.memberEnd[0], True)
        assert a.memberEnd[0].navigability is True
        assert a.memberEnd[1].navigability is None

        modelfactory.set_navigability(a, a.memberEnd[0], False)
        assert a.memberEnd[0].navigability is False
        assert a.memberEnd[1].navigability is None
Ejemplo n.º 5
0
    def test_relationship_navigability(self):
        """Test navigable relationship of a classifier
        """
        n1 = self.factory.create(uml2.Node)
        n2 = self.factory.create(uml2.Node)
        assoc = modelfactory.create_association(self.factory, n1, n2)

        end = assoc.memberEnd[0]
        assert end.type is n1

        modelfactory.set_navigability(assoc, end, True)

        # class/interface navigablity, Association.navigableOwnedEnd not
        # involved
        self.assertTrue(end in assoc.navigableOwnedEnd)
        self.assertTrue(end not in assoc.ownedEnd)
        self.assertTrue(end.navigability is True)

        # uknown navigability
        modelfactory.set_navigability(assoc, end, None)
        self.assertTrue(end not in assoc.navigableOwnedEnd)
        self.assertTrue(end in assoc.ownedEnd)
        self.assertTrue(end.navigability is None)

        # non-navigability
        modelfactory.set_navigability(assoc, end, False)
        self.assertTrue(end not in assoc.navigableOwnedEnd)
        self.assertTrue(end not in assoc.ownedEnd)
        self.assertTrue(end.navigability is False)

        # check other navigability change possibilities
        modelfactory.set_navigability(assoc, end, None)
        self.assertTrue(end not in assoc.navigableOwnedEnd)
        self.assertTrue(end in assoc.ownedEnd)
        self.assertTrue(end.navigability is None)

        modelfactory.set_navigability(assoc, end, True)
        self.assertTrue(end in assoc.navigableOwnedEnd)
        self.assertTrue(end not in assoc.ownedEnd)
        self.assertTrue(end.navigability is True)