Example #1
0
    def test_association_notification(self):
        """
        Test notifications with Class object.
        
        Tricky case where no events are fired.
        """
        dispatcher = self.dispatcher
        element = uml2.Association()
        p1 = element.memberEnd = uml2.Property()
        p2 = element.memberEnd = uml2.Property()

        assert len(element.memberEnd) == 2
        print(element.memberEnd)
        dispatcher.register_handler(self._handler, element, 'memberEnd.name')
        assert len(dispatcher._handlers) == 3, len(dispatcher._handlers)
        assert not self.events

        p1.name = 'foo'
        assert len(self.events) == 1, (self.events, dispatcher._handlers)
        assert len(dispatcher._handlers) == 3

        p1.name = 'othername'
        assert len(self.events) == 2, self.events

        p1.name = 'othername'
        assert len(self.events) == 2, self.events
    def test_association_notification_complex(self):
        """
        Test notifications with Class object.
        
        Tricky case where no events are fired.
        """
        dispatcher = self.dispatcher
        element = uml2.Association()
        p1 = element.memberEnd = uml2.Property()
        p2 = element.memberEnd = uml2.Property()
        p1.lowerValue = '0'
        p1.upperValue = '1'
        p2.lowerValue = '1'
        p2.upperValue = '*'

        assert len(element.memberEnd) == 2
        print(element.memberEnd)

        base = 'memberEnd<Property>.'
        dispatcher.register_handler(self._handler, element, base + 'name')
        dispatcher.register_handler(self._handler, element, base + 'aggregation')
        dispatcher.register_handler(self._handler, element, base + 'classifier')
        dispatcher.register_handler(self._handler, element, base + 'lowerValue')
        dispatcher.register_handler(self._handler, element, base + 'upperValue')

        assert len(dispatcher._handlers) == 11, len(dispatcher._handlers)
        assert not self.events

        p1.name = 'foo'
        assert len(self.events) == 1, (self.events, dispatcher._handlers)
        assert len(dispatcher._handlers) == 11
        
        p1.name = 'othername'
        assert len(self.events) == 2, self.events
Example #3
0
 def test_property_is_composite(self):
     p = uml2.Property()
     assert p.isComposite == False, p.isComposite
     p.aggregation = 'shared'
     assert p.isComposite == False, p.isComposite
     p.aggregation = 'composite'
     assert p.isComposite == True, p.isComposite
Example #4
0
    def test_association_endType(self):
        factory = elementfactory.ElementFactory()
        c1 = uml2.Class()
        c2 = uml2.Class()
        a = uml2.Association()
        a.memberEnd = uml2.Property()
        a.memberEnd = uml2.Property()
        a.memberEnd[0].type = c1
        a.memberEnd[1].type = c2
        c1.ownedAttribute = a.memberEnd[0]
        c2.ownedAttribute = a.memberEnd[1]

        assert c1 in a.endType
        assert c2 in a.endType

        c3 = uml2.Class()
        a.memberEnd[1].type = c3

        assert c1 in a.endType
        assert c3 in a.endType