Skip to content

Commit

Permalink
OPT-1019 - MTMT fails when TrustZone, Components or Dataflow has no n…
Browse files Browse the repository at this point in the history
…ame (#327)

Co-authored-by: PacoCid <117292868+PacoCid@users.noreply.github.com>
  • Loading branch information
jmgarcia-iriusrisk and PacoCid authored Oct 16, 2023
1 parent bbae099 commit 7aaae49
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 6 deletions.
2 changes: 1 addition & 1 deletion slp_mtmt/slp_mtmt/parse/mtmt_component_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __create_component(self, border: MTMBorder) -> Component:
representation = calculator.calculate_representation()
if mtmt_type is not None:
component = Component(component_id=border.id,
name=border.name,
name=border.name or '',
component_type=mtmt_type,
parent_type=parent_type,
parent=parent_id,
Expand Down
2 changes: 1 addition & 1 deletion slp_mtmt/slp_mtmt/parse/mtmt_connector_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __create_dataflow(line: MTMLine) -> Dataflow:
source_node_id = line.source_guid
target_node_id = line.target_guid
return Dataflow(dataflow_id=line.id,
name=line.name,
name=line.name or '',
attributes=line.properties,
source_node=source_node_id,
destination_node=target_node_id,
Expand Down
2 changes: 1 addition & 1 deletion slp_mtmt/slp_mtmt/parse/mtmt_trustzone_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def create_trustzone(self, border) -> Trustzone:
calculator = TrustzoneRepresentationCalculator(self.diagram_representation, border)
representations = calculator.calculate_representation()
tz = Trustzone(trustzone_id=border.id,
name=border.name,
name=border.name or '',
type=mtmt_type,
parent_type=parent_type,
parent=parent_id,
Expand Down
2 changes: 1 addition & 1 deletion slp_mtmt/slp_mtmt/util/representation_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def calculate_representation(self):
if not x or not y or not width or not height:
return
representation_id = self.element.id + '-representation'
representation_name = self.element.name + ' Representation'
representation_name = (self.element.name or self.element.id) + ' Representation'
position = {"x": x, "y": y}
size = {"width": width, "height": height}
return RepresentationElement(id_=representation_id, name=representation_name,
Expand Down

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions slp_mtmt/tests/resources/test_resource_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
nested_trustzones_tm7 = f'{path}/mtmt/MTMT_nested_tz.tm7'
nested_trustzones_line_tm7 = f'{path}/mtmt/MTMT_nested_tz_line.tm7'
one_trustzone_tm7 = f'{path}/mtmt/one-trustzone.tm7'
model_with_figures_without_name_file = f'{path}/mtmt/model_with_figures_without_name.tm7'

# OTM
example_position_otm = f'{path}/mtmt/MTMT_example_coordinates.otm'
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest.mock import MagicMock

from otm.otm.entity.representation import DiagramRepresentation, RepresentationType
from sl_util.sl_util.file_utils import get_byte_data
from slp_mtmt.slp_mtmt.mtmt_loader import MTMTLoader
Expand All @@ -6,7 +8,7 @@
from slp_mtmt.slp_mtmt.parse.mtmt_trustzone_parser import MTMTTrustzoneParser
from slp_mtmt.tests.resources import test_resource_paths
from slp_mtmt.tests.resources.test_resource_paths import mtmt_default_mapping, \
nested_trustzones_tm7
nested_trustzones_tm7, model_with_figures_without_name_file

diagram_representation = DiagramRepresentation(id_='project-test-diagram',
name='Project Test Diagram Representation',
Expand Down Expand Up @@ -164,3 +166,25 @@ def test_nested_trust_zones(self):
assert current.id == '9668ae2e-403f-4182-8c4c-d83948ffc31b'
assert current.parent == '351f4038-244d-4de5-bfa0-00c17f2a1fa2'
assert current.parent_type == 'trustZone'

def test_model_components_without_name_file(self):
# GIVEN the provider loader
source_file = get_byte_data(model_with_figures_without_name_file)
mtmt: MTMTLoader = MTMTLoader(source_file)
mtmt.load()

# AND a valid MTMT mapping file
mapping_file = get_byte_data(mtmt_default_mapping)

# AND the mapping file loaded
mtmt_mapping_file_loader = MTMTMappingFileLoader([mapping_file])
mtmt_mapping_file_loader.load()

# WHEN we parse the components
mtmt_mapping = mtmt_mapping_file_loader.get_mtmt_mapping()
mtmt_data = mtmt.get_mtmt()
component_parser = MTMTComponentParser(mtmt_data, mtmt_mapping, MagicMock(), diagram_representation.id)
components = component_parser.parse()
# THEN no component has None as name
for c in components:
assert c.name is not None
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest.mock import MagicMock

from pytest import mark

from otm.otm.entity.representation import DiagramRepresentation, RepresentationType
from sl_util.sl_util.file_utils import get_byte_data
from slp_mtmt.slp_mtmt.entity.mtmt_entity_line import MTMLine
from slp_mtmt.slp_mtmt.mtmt_entity import MTMT
Expand Down Expand Up @@ -95,3 +96,15 @@ def test_parse_orphan_connectors(self, source, target, expected):

# Then we check the otm dataflows created
assert len(dataflows) == expected

def test_model_dataflow_without_name_file(self):
# GIVEN a line without name
line = MagicMock()
line.name = None
mtmt = MTMT(None, [line], None, None)

# WHEN MTMTConnectorParser::parse is invoked
dataflows = MTMTConnectorParser(mtmt).parse()

# THEN no dataflow has None as name
assert dataflows[0].name is not None
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,17 @@ def test_mapping_trust_zones_by_name(self, mapping_file):
assert trustzones[0].name == 'The TrustZone'
assert trustzones[0].type == 'f0ba7722-39b6-4c81-8290-a30a248bb8d9'

def test_model_trustzones_without_name(self):
# GIVEN the Mtmt data with one trustzone
mtmt = get_mtmt_from_file(test_resource_paths.model_with_figures_without_name_file)

# AND the mapping data without the mapping of the trustzone
mtmt_mapping = get_mapping_from_file(mtmt_default_mapping)

# THEN a MtmtMapping is returned with the default trustzone
trustzones = MTMTTrustzoneParser(mtmt, mtmt_mapping, diagram_representation.id).parse()

# THEN no trustzone has None as name
for tz in trustzones:
assert tz.name is not None

0 comments on commit 7aaae49

Please sign in to comment.