def test_stereotype_attribute_delete(self):
        """
        This test was applicable to the Sanitizer service, but is now resolved
        by a tweak in the data model (Instances diagram).
        """
        factory = self.element_factory
        create = factory.create

        # Set the stage
        # metaklass = create(uml2.Class)
        # metaklass.name = 'Class'
        klass = create(uml2.Class)
        stereotype = create(uml2.Stereotype)
        st_attr = self.element_factory.create(uml2.Property)
        stereotype.ownedAttribute = st_attr
        # ext = modelfactory.create_extension(factory, metaklass, stereotype)

        # Apply stereotype to class and create slot
        instspec = modelfactory.apply_stereotype(factory, klass, stereotype)
        slot = modelfactory.add_slot(factory, instspec, st_attr)

        # Now, what happens if the attribute is deleted:
        self.assertTrue(st_attr in stereotype.ownedMember)
        self.assertTrue(slot in instspec.slot)

        st_attr.unlink()

        self.assertEquals([], list(stereotype.ownedMember))
        self.assertEquals([], list(instspec.slot))
    def test_extension_deletion_with_2_metaclasses(self):
        factory = self.element_factory
        create = factory.create

        # Set the stage
        metaklass = create(uml2.Class)
        metaklass.name = 'Class'
        metaiface = create(uml2.Class)
        metaiface.name = 'Interface'
        klass = create(uml2.Class)
        iface = create(uml2.Interface)
        stereotype = create(uml2.Stereotype)
        st_attr = self.element_factory.create(uml2.Property)
        stereotype.ownedAttribute = st_attr
        ext1 = modelfactory.create_extension(factory, metaklass, stereotype)
        ext2 = modelfactory.create_extension(factory, metaiface, stereotype)

        # Apply stereotype to class and create slot
        instspec1 = modelfactory.apply_stereotype(factory, klass, stereotype)
        instspec2 = modelfactory.apply_stereotype(factory, iface, stereotype)
        slot = modelfactory.add_slot(factory, instspec1, st_attr)

        self.assertTrue(stereotype in klass.appliedStereotype[:].classifier)
        self.assertTrue(klass in self.element_factory)

        ext1.unlink()

        self.assertEquals([], list(klass.appliedStereotype))
        self.assertTrue(klass in self.element_factory)
        self.assertEquals([instspec2], list(iface.appliedStereotype))
    def test_stereotype_attributes_status_saving(self):
        """Test stereotype attributes status saving
        """
        factory = self.element_factory
        c = self.create(ComponentItem, uml2.Component)

        c.show_stereotypes_attrs = True
        modelfactory.apply_stereotype(factory, c.subject, self.st1)
        obj = modelfactory.apply_stereotype(factory, c.subject, self.st2)

        # change attribute of 2nd stereotype
        attr = self.st2.ownedAttribute[0]
        slot = modelfactory.add_slot(self.element_factory, obj, attr)
        slot.value = 'st2 test21'

        data = self.save()
        self.load(data)

        item = self.diagram.canvas.select(
            lambda e: isinstance(e, ComponentItem))[0]
        self.assertTrue(item.show_stereotypes_attrs)
        self.assertEqual(2, len(item._compartments))
        # first stereotype has no attributes changed, so compartment
        # invisible
        self.assertFalse(item._compartments[0].visible)
        self.assertTrue(item._compartments[1].visible)
Example #4
0
    def set_slot_value(self, iter, value):
        """
        Set value of stereotype property applied to an UML element.

        Slot is created if instance Create valuChange value of instance spe
        """
        path = self.get_path(iter)
        row = self[path]
        name, old_value, is_applied, attr, obj, slot = row
        if isinstance(attr, uml2.Stereotype):
            return  # don't edit stereotype rows

        log.debug('editing %s' % list(row))

        if slot is None and not value:
            return  # nothing to do and don't create slot without value

        if slot is None:
            slot = modelfactory.add_slot(self.element_factory, obj, attr)

        assert slot

        if value:
            slot.value = value
        else:
            # no value, then remove slot
            del obj.slot[slot]
            slot = None
            value = ''

        row[1] = value
        row[5] = slot
        log.debug('slots %s' % obj.slot)
    def test_removing_stereotype_attribute(self):
        """Test if stereotype instance specification is destroyed when stereotype attribute is removed
        """
        factory = self.element_factory
        c = self.create(ComponentItem, uml2.Component)

        c.show_stereotypes_attrs = True

        # test precondition
        self.assertEqual(0, len(c._compartments))
        obj = modelfactory.apply_stereotype(factory, c.subject, self.st1)
        # test precondition
        self.assertEqual(1, len(c._compartments))

        self.assertEqual(0, len(self.kindof(uml2.Slot)))

        attr = self.st1.ownedAttribute[0]
        slot = modelfactory.add_slot(factory, obj, attr)
        self.assertEqual(1, len(obj.slot))
        self.assertEqual(1, len(self.kindof(uml2.Slot)))
        self.assertTrue(slot.definingFeature)

        compartment = c._compartments[0]
        self.assertTrue(compartment.visible)

        attr.unlink()
        self.assertEqual(0, len(obj.slot))
        self.assertEqual(0, len(self.kindof(uml2.Slot)))
        self.assertFalse(compartment.visible)
    def test_saving_stereotype_attributes(self):
        """Test stereotype attributes saving
        """
        factory = self.element_factory
        c = self.create(ComponentItem, uml2.Component)

        c.show_stereotypes_attrs = True

        modelfactory.apply_stereotype(factory, c.subject, self.st1)
        modelfactory.apply_stereotype(factory, c.subject, self.st2)

        self.assertEqual(3, len(self.st1.ownedAttribute))
        attr1, attr2, attr3 = self.st1.ownedAttribute
        self.assertEqual(attr1.name, 'st1_attr_1', attr1.name)
        self.assertEqual(attr2.name, 'st1_attr_2', attr2.name)
        self.assertEqual(attr3.name, 'baseClass', attr3.name)

        obj = c.subject.appliedStereotype[0]
        slot = modelfactory.add_slot(self.element_factory, obj, attr1)
        slot.value = 'st1 test1'
        slot = modelfactory.add_slot(self.element_factory, obj, attr2)
        slot.value = 'st1 test2'

        data = self.save()
        self.load(data)

        item = self.diagram.canvas.select(
            lambda e: isinstance(e, ComponentItem))[0]
        el = item.subject
        self.assertEqual(2, len(el.appliedStereotype))

        # check if stereotypes are properly applied
        names = sorted(obj.classifier[0].name for obj in el.appliedStereotype)
        self.assertEqual(['st1', 'st2'], names)

        # two attributes were changed for stereotype st1, so 2 slots
        obj = el.appliedStereotype[0]
        self.assertEqual(2, len(obj.slot))
        self.assertEqual('st1_attr_1', obj.slot[0].definingFeature.name)
        self.assertEqual('st1 test1', obj.slot[0].value)
        self.assertEqual('st1_attr_2', obj.slot[1].definingFeature.name)
        self.assertEqual('st1 test2', obj.slot[1].value)

        # no stereotype st2 attribute changes, no slots
        obj = el.appliedStereotype[1]
        self.assertEqual(0, len(obj.slot))
Example #7
0
 def create_slot(key, val):
     for attr in st.ownedAttribute:
         if attr.name == key:
             break
     else:
         attr = st.ownedAttribute = factory.create(uml2.Property)
         attr.name = str(key)
         update_elements(attr)
     slot = modelfactory.add_slot(factory, instspec, attr)
     slot.value.value = str(val)
     update_elements(slot)
    def test_removing_last_slot(self):
        """Test removing last slot
        """
        factory = self.element_factory
        c = self.create(ComponentItem, uml2.Component)

        c.show_stereotypes_attrs = True
        obj = modelfactory.apply_stereotype(factory, c.subject, self.st1)

        slot = modelfactory.add_slot(factory, obj, self.st1.ownedAttribute[0])

        compartment = c._compartments[0]
        # test precondition
        self.assertTrue(compartment.visible)

        del obj.slot[slot]
        self.assertFalse(compartment.visible)
    def test_adding_slot(self):
        """Test if stereotype attribute information is added when slot is added
        """
        factory = self.element_factory
        c = self.create(ComponentItem, uml2.Component)

        c.show_stereotypes_attrs = True
        obj = modelfactory.apply_stereotype(factory, c.subject, self.st1)

        # test precondition
        self.assertFalse(c._compartments[0].visible)

        slot = modelfactory.add_slot(factory, obj, self.st1.ownedAttribute[0])

        compartment = c._compartments[0]
        self.assertTrue(compartment.visible)
        self.assertEqual(1, len(compartment), slot)
    def test_stereotype_deletion(self):
        factory = self.element_factory
        create = factory.create

        # Set the stage
        metaklass = create(uml2.Class)
        metaklass.name = 'Class'
        klass = create(uml2.Class)
        stereotype = create(uml2.Stereotype)
        st_attr = self.element_factory.create(uml2.Property)
        stereotype.ownedAttribute = st_attr
        ext = modelfactory.create_extension(factory, metaklass, stereotype)

        # Apply stereotype to class and create slot
        instspec = modelfactory.apply_stereotype(factory, klass, stereotype)
        slot = modelfactory.add_slot(factory, instspec, st_attr)

        self.assertTrue(stereotype in klass.appliedStereotype[:].classifier)

        stereotype.unlink()

        self.assertEquals([], list(klass.appliedStereotype))