3939import org .eclipse .syson .services .diagrams .api .IGivenDiagramReference ;
4040import org .eclipse .syson .services .diagrams .api .IGivenDiagramSubscription ;
4141import org .eclipse .syson .util .SysONRepresentationDescriptionIdentifiers ;
42+ import org .jetbrains .annotations .NotNull ;
4243import org .junit .jupiter .api .AfterEach ;
4344import org .junit .jupiter .api .BeforeEach ;
4445import org .junit .jupiter .api .Test ;
@@ -136,14 +137,16 @@ public void addExistingElementsOnDiagram() {
136137 Consumer <DiagramRefreshedEventPayload > updatedDiagramConsumer = payload -> Optional .of (payload )
137138 .map (DiagramRefreshedEventPayload ::diagram )
138139 .ifPresentOrElse (newDiagram -> {
139- assertThat (newDiagram .getNodes ()).as ("3 nodes should be visible on the diagram" ).hasSize (3 );
140+ assertThat (newDiagram .getNodes ()).as ("3 nodes should be visible on the diagram" ).hasSize (4 );
140141 assertThat (newDiagram .getNodes ())
141142 .as (MessageFormat .format (NODE_SHOULD_BE_ON_DIAGRAM_MESSAGE , PACKAGE1 ))
142143 .anyMatch (n -> Objects .equals (n .getTargetObjectLabel (), PACKAGE1 ))
143144 .as (MessageFormat .format (NODE_SHOULD_BE_ON_DIAGRAM_MESSAGE , ACTION1 ))
144145 .anyMatch (n -> Objects .equals (n .getTargetObjectLabel (), ACTION1 ))
145146 .as (MessageFormat .format (NODE_SHOULD_BE_ON_DIAGRAM_MESSAGE , PART1 ))
146- .anyMatch (n -> Objects .equals (n .getTargetObjectLabel (), PART1 ));
147+ .anyMatch (n -> Objects .equals (n .getTargetObjectLabel (), PART1 ))
148+ .as (MessageFormat .format (NODE_SHOULD_BE_ON_DIAGRAM_MESSAGE , "RequirementUsage" ))
149+ .anyMatch (n -> Objects .equals (n .getTargetObjectLabel (), "RequirementUsage" ));
147150 }, () -> fail ("Missing diagram" ));
148151 this .verifier .consumeNextWith (updatedDiagramConsumer );
149152
@@ -161,7 +164,7 @@ public void addExistingElementsRecursiveOnDiagram() {
161164 Consumer <DiagramRefreshedEventPayload > updatedDiagramConsumer = payload -> Optional .of (payload )
162165 .map (DiagramRefreshedEventPayload ::diagram )
163166 .ifPresentOrElse (newDiagram -> {
164- assertThat (newDiagram .getNodes ()).as ("6 nodes should be visible on the diagram" ).hasSize (6 );
167+ assertThat (newDiagram .getNodes ()).as ("6 nodes should be visible on the diagram" ).hasSize (7 );
165168 assertThat (newDiagram .getEdges ().stream ().filter (e -> ViewModifier .Normal .equals (e .getState ())).toList ())
166169 .as ("3 edges should be visible on the diagram" )
167170 .hasSize (3 )
@@ -179,78 +182,115 @@ public void addExistingElementsRecursiveOnDiagram() {
179182 .as (MessageFormat .format (NODE_SHOULD_BE_ON_DIAGRAM_MESSAGE , PART1 ))
180183 .anyMatch (n -> Objects .equals (n .getTargetObjectLabel (), PART1 ))
181184 .as (MessageFormat .format (NODE_SHOULD_BE_ON_DIAGRAM_MESSAGE , PART2 ))
182- .anyMatch (n -> Objects .equals (n .getTargetObjectLabel (), PART2 ));
183-
184- var optPackageNode = newDiagram .getNodes ().stream ()
185- .filter (n -> Objects .equals (n .getTargetObjectLabel (), PACKAGE1 ))
186- .findFirst ();
187- assertThat (optPackageNode ).isPresent ();
188- assertThat (optPackageNode .get ().getChildNodes ())
189- .as ("Node " + PACKAGE1 + " should contain 1 child" )
190- .hasSize (1 )
191- .as ("Node " + ATTRIBUTE_DEFINITION + " should exist inside " + PACKAGE1 )
192- .anyMatch (n -> Objects .equals (n .getTargetObjectLabel (), ATTRIBUTE_DEFINITION ));
193-
194- var optAction1Node = newDiagram .getNodes ().stream ()
195- .filter (n -> Objects .equals (n .getTargetObjectLabel (), ACTION1 ))
196- .findFirst ();
197- assertThat (optAction1Node ).isPresent ();
198- var action1Node = optAction1Node .get ();
199- var action1ActionsCompartment = this .getCompartment (action1Node , "actions" );
200- assertThat (action1ActionsCompartment )
201- .as (ACTION1 + " should contain an actions compartment" )
202- .isPresent ();
203- assertThat (action1ActionsCompartment .get ().getChildNodes ())
204- .as (ACTION1 + " actions compartment should contain 1 child" )
205- .hasSize (1 )
206- .as (ACTION1 + " actions compartment should contain " + ACTION2 )
207- .anyMatch (n -> Objects .equals (n .getTargetObjectLabel (), ACTION2 ));
208-
209- var action1ActionFlowCompartment = this .getCompartment (action1Node , "action flow" );
210- assertThat (action1ActionFlowCompartment )
211- .as (ACTION1 + " should contain an action flow compartment" )
212- .isPresent ();
213- assertThat (action1ActionFlowCompartment .get ().getChildNodes ())
214- .as (ACTION1 + " action flow compartment should contain 2 children" )
215- .hasSize (1 ) // @technical-debt should be 2 when start node will be synchronized
216- .as (ACTION1 + " action flow compartment should contain " + ACTION2 )
217- .anyMatch (n -> Objects .equals (n .getTargetObjectLabel (), ACTION2 ))
218- ;
185+ .anyMatch (n -> Objects .equals (n .getTargetObjectLabel (), PART2 ))
186+ .as (MessageFormat .format (NODE_SHOULD_BE_ON_DIAGRAM_MESSAGE , "RequirementUsage" ))
187+ .anyMatch (n -> Objects .equals (n .getTargetObjectLabel (), "RequirementUsage" ));
188+
189+ checkPackageNode (newDiagram );
190+
191+
219192 // @technical-debt enable this part when start node will be synchronized
220193 // .as(ACTION1 + " action flow compartment should contain a start node")
221194 // .anyMatch(n -> n.getStyle() instanceof ImageNodeStyle imageStyle &&
222195 // Objects.equals(imageStyle.getImageURL(), "images/start_action.svg")
223196 // && Objects.equals("start", n.getTargetObjectLabel()));
224197
225- var optAction2Node = action1ActionFlowCompartment .get ().getChildNodes ().stream ()
226- .filter (n -> Objects .equals (n .getTargetObjectLabel (), ACTION2 ))
227- .findFirst ();
228- assertThat (optAction2Node ).isPresent ();
229- var action2Node = optAction2Node .get ();
230- var action2ActionsCompartment = this .getCompartment (action2Node , "actions" );
231- assertThat (action2ActionsCompartment )
232- .as (ACTION2 + " should contain an actions compartment" )
233- .isPresent ();
234- assertThat (action2ActionsCompartment .get ().getChildNodes ())
235- .as (ACTION2 + " actions compartment should contain 1 child" )
236- .hasSize (1 )
237- .as (ACTION2 + " actions compartment should contain " + ACTION3 )
238- .anyMatch (n -> Objects .equals (n .getTargetObjectLabel (), ACTION3 ));
239-
240- var action2ActionFlowCompartment = this .getCompartment (action2Node , "action flow" );
241- assertThat (action2ActionFlowCompartment )
242- .as (ACTION2 + " should contain an action flow compartment" )
243- .isPresent ();
244- assertThat (action2ActionFlowCompartment .get ().getChildNodes ())
245- .as (ACTION2 + " action flow compartment should contain 1 child" )
246- .hasSize (1 )
247- .as (ACTION2 + " action flow compartment should contain " + ACTION3 )
248- .anyMatch (n -> Objects .equals (n .getTargetObjectLabel (), ACTION3 ));
198+ checkAction2 (action1ActionFlowCompartment );
199+
200+ checkRequirementUsage (newDiagram );
249201
250202 }, () -> fail ("Missing diagram" ));
251203 this .verifier .consumeNextWith (updatedDiagramConsumer );
252204 }
253205
206+ private void checkPackageNode (Diagram newDiagram ) {
207+ var optPackageNode = newDiagram .getNodes ().stream ()
208+ .filter (n -> Objects .equals (n .getTargetObjectLabel (), PACKAGE1 ))
209+ .findFirst ();
210+ assertThat (optPackageNode ).isPresent ();
211+ assertThat (optPackageNode .get ().getChildNodes ())
212+ .as ("Node " + PACKAGE1 + " should contain 1 child" )
213+ .hasSize (1 )
214+ .as ("Node " + ATTRIBUTE_DEFINITION + " should exist inside " + PACKAGE1 )
215+ .anyMatch (n -> Objects .equals (n .getTargetObjectLabel (), ATTRIBUTE_DEFINITION ));
216+ }
217+
218+ private void checkAction2 (Diagram newDiagram ) {
219+
220+ var action1ActionFlowCompartment = checkAction1 (newDiagram );
221+ var optAction2Node = action1ActionFlowCompartment .getChildNodes ().stream ()
222+ .filter (n -> Objects .equals (n .getTargetObjectLabel (), ACTION2 ))
223+ .findFirst ();
224+ assertThat (optAction2Node ).isPresent ();
225+ var action2Node = optAction2Node .get ();
226+ var action2ActionsCompartment = this .getCompartment (action2Node , "actions" );
227+ assertThat (action2ActionsCompartment )
228+ .as (ACTION2 + " should contain an actions compartment" )
229+ .isPresent ();
230+ assertThat (action2ActionsCompartment .get ().getChildNodes ())
231+ .as (ACTION2 + " actions compartment should contain 1 child" )
232+ .hasSize (1 )
233+ .as (ACTION2 + " actions compartment should contain " + ACTION3 )
234+ .anyMatch (n -> Objects .equals (n .getTargetObjectLabel (), ACTION3 ));
235+
236+ var action2ActionFlowCompartment = this .getCompartment (action2Node , "action flow" );
237+ assertThat (action2ActionFlowCompartment )
238+ .as (ACTION2 + " should contain an action flow compartment" )
239+ .isPresent ();
240+ assertThat (action2ActionFlowCompartment .get ().getChildNodes ())
241+ .as (ACTION2 + " action flow compartment should contain 1 child" )
242+ .hasSize (1 )
243+ .as (ACTION2 + " action flow compartment should contain " + ACTION3 )
244+ .anyMatch (n -> Objects .equals (n .getTargetObjectLabel (), ACTION3 ));
245+ }
246+
247+ private @ NotNull Node checkAction1 (Diagram newDiagram ) {
248+ var optAction1Node = newDiagram .getNodes ().stream ()
249+ .filter (n -> Objects .equals (n .getTargetObjectLabel (), ACTION1 ))
250+ .findFirst ();
251+ assertThat (optAction1Node ).isPresent ();
252+ var action1Node = optAction1Node .get ();
253+ var action1ActionsCompartment = this .getCompartment (action1Node , "actions" );
254+ assertThat (action1ActionsCompartment )
255+ .as (ACTION1 + " should contain an actions compartment" )
256+ .isPresent ();
257+ assertThat (action1ActionsCompartment .get ().getChildNodes ())
258+ .as (ACTION1 + " actions compartment should contain 1 child" )
259+ .hasSize (1 )
260+ .as (ACTION1 + " actions compartment should contain " + ACTION2 )
261+ .anyMatch (n -> Objects .equals (n .getTargetObjectLabel (), ACTION2 ));
262+
263+ var action1ActionFlowCompartment = this .getCompartment (action1Node , "action flow" );
264+ assertThat (action1ActionFlowCompartment )
265+ .as (ACTION1 + " should contain an action flow compartment" )
266+ .isPresent ();
267+ assertThat (action1ActionFlowCompartment .get ().getChildNodes ())
268+ .as (ACTION1 + " action flow compartment should contain 2 children" )
269+ .hasSize (1 ) // @technical-debt should be 2 when start node will be synchronized
270+ .as (ACTION1 + " action flow compartment should contain " + ACTION2 )
271+ .anyMatch (n -> Objects .equals (n .getTargetObjectLabel (), ACTION2 ));
272+ return action1ActionFlowCompartment .get ();
273+ }
274+
275+ private void checkRequirementUsage (Diagram newDiagram ) {
276+ var optRequirementNode = newDiagram .getNodes ().stream ()
277+ .filter (n -> Objects .equals (n .getTargetObjectId (), GeneralViewAddExistingElementsTestProjectData .SemanticIds .SN_REQUIREMENT_ELEMENT_ID ))
278+ .findFirst ();
279+
280+ assertThat (optRequirementNode ).isPresent ();
281+ assertThat (optRequirementNode .get ().getChildNodes ())
282+ .as ("Node RequirementUsage should contain 6 children" )
283+ .hasSize (8 );
284+
285+ var requirementDocCompartment = this .getCompartment (optRequirementNode .get (), "doc" );
286+ assertThat (requirementDocCompartment ).isPresent ();
287+ assertThat (requirementDocCompartment .get ())
288+ .as ("The doc compartment should be visible" )
289+ .matches (node -> !node .getModifiers ().contains (ViewModifier .Hidden ))
290+ .as ("The doc compartment should contain a document item" )
291+ .matches (node -> node .getChildNodes ().size () == 1 );
292+ }
293+
254294 private Optional <Node > getCompartment (Node node , String compartmentName ) {
255295 return node .getChildNodes ().stream ()
256296 .filter (n -> Objects .equals (n .getInsideLabel ().getText (), compartmentName ))
0 commit comments