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))
예제 #2
0
    def test_extension_metaclass(self):
        factory = elementfactory.ElementFactory()
        c = factory.create(uml2.Class)
        c.name = 'Class'
        s = factory.create(uml2.Stereotype)
        s.name = 'Stereotype'

        e = modelfactory.create_extension(factory, c, s)

        self.assertEquals(c, e.metaclass)
예제 #3
0
def nodes(element_factory) -> Dict[int, ClassItem]:
    """Create tree using ClassItems and Stereotypes.

    All connections use UML.Generalizations, except for node 2 is connected to
    node 5 with an UML.Extension. Node 5 is the only Stereotype, the others are
    Classes.

    |- 0
    |  |- 1
    |  |- 2
    |  |  |- 3
    |  |  |- 4
    |- 5  |
    |  |- |- 6

    """
    diagram = element_factory.create(UML.Diagram)
    nodes = {
        n: diagram.create(ClassItem, subject=element_factory.create(UML.Class))
        for n in range(6)
    }
    nodes[6] = diagram.create(ClassItem, subject=element_factory.create(UML.Stereotype))
    gens = {
        n: diagram.create(
            GeneralizationItem, subject=element_factory.create(UML.Generalization)
        )
        for n in range(4)
    }
    class_connections = [0, 1, 0, 2, 2, 3, 2, 4]
    for n in range(4):
        connect(gens[n], gens[n].head, nodes[class_connections[n * 2]])
        connect(gens[n], gens[n].tail, nodes[class_connections[n * 2 + 1]])

    create_extension(nodes[2].subject, nodes[6].subject)
    create_extension(nodes[5].subject, nodes[6].subject)

    assert len(nodes) == 7
    return nodes
예제 #4
0
    def test_metaclass_extension(self):
        factory = elementfactory.ElementFactory()
        c = factory.create(uml2.Class)
        c.name = 'Class'
        s = factory.create(uml2.Stereotype)
        s.name = 'Stereotype'

        self.assertEquals([], c.extension)
        self.assertEquals([], s.extension)

        e = modelfactory.create_extension(factory, c, s)

        print(e.memberEnd)
        self.assertEquals([e], c.extension)
        self.assertEquals([], s.extension)
        assert e.ownedEnd.type is s
    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))