Skip to content

Commit

Permalink
<Enhancement>[UnTangleOglLinks]: <Multi Implementor Lollipop fix>
Browse files Browse the repository at this point in the history
[
* Unit Test
* Unit test file
]

[#78]
  • Loading branch information
Humberto Sanchez II committed Jun 8, 2024
1 parent 5efb61d commit 343ddb6
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 7 deletions.
40 changes: 33 additions & 7 deletions src/untanglepyut/UnTangleOglLinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,8 @@ def _graphicLollipopToOglInterface(self, graphicLollipop: Element, linkableOglOb

assert len(linkableOglObjects) != 0, 'Developer forgot to create dictionary'

#
# TODO: Do not use these x,y positions; They are diagram relative
#
# x: int = int(graphicLollipop['x'])
# y: int = int(graphicLollipop['y'])
x: int = int(graphicLollipop['x'])
y: int = int(graphicLollipop['y'])
attachmentLocationStr: str = graphicLollipop['attachmentPoint']
attachmentSide: AttachmentSide = AttachmentSide.toEnum(attachmentLocationStr)

Expand All @@ -231,13 +228,19 @@ def _graphicLollipopToOglInterface(self, graphicLollipop: Element, linkableOglOb

pyutInterface: PyutInterface = self._untanglePyut.interfaceToPyutInterface(oglInterface2=graphicLollipop)

oglClass: OglClass = self._getOglClassFromName(pyutInterface.implementors[0], linkableOglObjects)
self.logger.debug(f'{pyutInterface.name} {pyutInterface.id=} {pyutInterface.implementors=}')

# oglClass: OglClass = self._getOglClassFromName(pyutInterface.implementors[0], linkableOglObjects)

oglClass: OglClass = self._determineAttachedToClass(x=x, y=y, linkableOglObjects=linkableOglObjects)
oglPosition: OglPosition = self._determineAttachmentPoint(attachmentSide, oglClass)
self.logger.debug(f'{oglPosition.x=},{oglPosition.y=}')

self.logger.debug(f'{oglClass.id=} {oglPosition.x=} {oglPosition.y=}')

anchorPoint: SelectAnchorPoint = SelectAnchorPoint(x=oglPosition.x, y=oglPosition.y, attachmentSide=attachmentSide, parent=oglClass)
oglInterface2: OglInterface2 = OglInterface2(pyutInterface=pyutInterface, destinationAnchor=anchorPoint)

self.logger.debug(f'{oglInterface2.id=} {oglInterface2.destinationAnchor=}')
return oglInterface2

def _getOglClassFromName(self, className: str, linkableOglObjects: LinkableOglObjects) -> OglClass:
Expand Down Expand Up @@ -377,3 +380,26 @@ def _createALabel(self, parentAssociation: OglAssociation, graphicLink: Element,
oglAssociationLabel: OglAssociationLabel = OglAssociationLabel(x=x, y=y, text=updatedLabelText, parent=parentAssociation)

return oglAssociationLabel

def _determineAttachedToClass(self, x: int, y: int, linkableOglObjects: LinkableOglObjects) -> OglClass:
"""
I cannot store a pointer to the class the lollipop is attached to. However, I need to know the lollipop's
parent because of
Args:
x:
y:
linkableOglObjects:
Returns: The OglClass that the lollipop is attached to
"""

foundClass: OglClass = cast(OglClass, None)

for linkableObject in linkableOglObjects.values():
oglClass: OglClass = cast(OglClass, linkableObject)
if oglClass.Inside(x=x, y=y) is True:
foundClass = oglClass
break

assert foundClass is not None, 'XML must be in error'
return foundClass
41 changes: 41 additions & 0 deletions tests/resources/v11/LollipopInterfaceMultiImplementor.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version='1.0' encoding='iso-8859-1'?>
<PyutProject version="11" CodePath="">
<PyutDocument type="CLASS_DIAGRAM" title="SampleIFace" scrollPositionX="0" scrollPositionY="0" pixelsPerUnitX="20" pixelsPerUnitY="20">
<OglClass width="66" height="60" x="120" y="60">
<PyutClass id="3" name="NameA" stereotype="noStereotype" displayMethods="True" displayParameters="Unspecified" displayConstructor="Unspecified" displayDunderMethods="Unspecified" displayFields="True" displayStereotype="True" fileName="" description="">
<PyutMethod name="method" visibility="PUBLIC" returnType="">
<SourceCode />
</PyutMethod>
<PyutField name="field" visibility="PRIVATE" type="" defaultValue="" />
</PyutClass>
</OglClass>
<OglClass width="114" height="60" x="150" y="250">
<PyutClass id="4" name="SouthLollipopClass" stereotype="noStereotype" displayMethods="True" displayParameters="Unspecified" displayConstructor="Unspecified" displayDunderMethods="Unspecified" displayFields="True" displayStereotype="True" fileName="" description="">
<PyutMethod name="method" visibility="PUBLIC" returnType="">
<SourceCode />
</PyutMethod>
<PyutField name="field" visibility="PRIVATE" type="" defaultValue="" />
</PyutClass>
</OglClass>
<OglInterface2 attachmentPoint="WEST" x="120" y="90">
<PyutInterface id="9" name="IWest" description="">
<PyutMethod name="MethodName1" visibility="PUBLIC" returnType="int">
<SourceCode />
<PyutParameter name="parameter1" type="str" defaultValue="bogus" />
</PyutMethod>
<Implementor implementingClassName="NameA" />
<Implementor implementingClassName="SouthLollipopClass" />
</PyutInterface>
</OglInterface2>
<OglInterface2 attachmentPoint="WEST" x="150" y="280">
<PyutInterface id="9" name="IWest" description="">
<PyutMethod name="MethodName1" visibility="PUBLIC" returnType="int">
<SourceCode />
<PyutParameter name="parameter1" type="str" defaultValue="bogus" />
</PyutMethod>
<Implementor implementingClassName="NameA" />
<Implementor implementingClassName="SouthLollipopClass" />
</PyutInterface>
</OglInterface2>
</PyutDocument>
</PyutProject>
80 changes: 80 additions & 0 deletions tests/untanglepyut/TestUnTangler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

from typing import cast

from unittest import TestSuite
from unittest import main as unitTestMain

from codeallybasic.UnitTestBase import UnitTestBase

from pyutmodelv2.PyutInterface import PyutInterface

from ogl.OglInterface2 import OglInterface2

from untanglepyut.Types import Document
from untanglepyut.Types import DocumentTitle
from untanglepyut.Types import Documents
from untanglepyut.Types import UntangledOglLinks

from untanglepyut.UnTangler import UnTangler
from untanglepyut.XmlVersion import XmlVersion

from tests.ProjectTestBase import TestBase


class TestUnTangler(TestBase):
"""
Auto generated by the one and only:
Gato Malo – Humberto A. Sanchez II
Generated: 06 June 2024
"""

@classmethod
def setUpClass(cls):
super().setUpClass()

def setUp(self):
super().setUp()

def tearDown(self):
super().tearDown()

def testLollipopInterfaceMultiImplementor(self):

fqFileName: str = UnitTestBase.getFullyQualifiedResourceFileName(package=TestBase.V11_TEST_FILES_PACKAGE_NAME,
fileName='LollipopInterfaceMultiImplementor.xml')
untangler: UnTangler = UnTangler(xmlVersion=XmlVersion.V11)

untangler.untangleFile(fqFileName=fqFileName)

documents: Documents = untangler.documents

self.assertTrue(len(documents) == 1, 'Should only have a single document')

document: Document = documents[DocumentTitle('SampleIFace')]

untangledOglLinks: UntangledOglLinks = document.oglLinks

self.assertTrue(len(untangledOglLinks) == 2, 'Not enough lollipops')

interface1: OglInterface2 = cast(OglInterface2, untangledOglLinks[0])
interface2: OglInterface2 = cast(OglInterface2, untangledOglLinks[1])

pyutInterface1: PyutInterface = interface1.pyutInterface
pyutInterface2: PyutInterface = interface2.pyutInterface

self.assertEqual(pyutInterface1.name, pyutInterface2.name, 'Names should match')
self.assertEqual(pyutInterface1.id, pyutInterface2.id, 'IDs should match')


def suite() -> TestSuite:
import unittest

testSuite: TestSuite = TestSuite()

testSuite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(testCaseClass=TestUnTangler))

return testSuite


if __name__ == '__main__':
unitTestMain()

0 comments on commit 343ddb6

Please sign in to comment.