Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: node connectors with different paths #302 #303

Merged
merged 1 commit into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ public class KnownMuleComponent extends MuleComponent {
public KnownMuleComponent(String type, String name) {
super(type, name);
}

@Override
public String qualifiedName() {
String name = super.qualifiedName();
if (getPath() != null && getPath().getValue() != null) {
name = name + ":" + getPath().getValue();
}
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ void drawToValidateGraph_APIKIT() throws Exception {
ArgumentCaptor<MutableGraph> graphArgumentCaptor = ArgumentCaptor.forClass(MutableGraph.class);
verify(graphDiagram).writGraphToFile(any(File.class), graphArgumentCaptor.capture());
MutableGraph generatedGraph = graphArgumentCaptor.getValue();
GraphvizEngineHelper.generate(generatedGraph, Format.DOT,
Paths.get("test-output2.dot").toFile());
String generated = GraphvizEngineHelper.generate(generatedGraph, Format.DOT);
String ref = new String(Files.readAllBytes(Paths.get(
"src/test/java/com/javastreets/mulefd/drawings/drawToValidateGraph_APIKIT_Expected.dot")));
Expand Down Expand Up @@ -393,4 +395,37 @@ void writeFlowGraphWithSubFlow() {
}


@Test
@DisplayName("Distinguish same connector with different path")
void github_issue_302() throws Exception {

List flows =
DiagramRendererTestUtil.getFlows(Paths.get("src/test/resources/gh-issues/iss-302.xml"));
File output = new File(".", "output.png");
DrawingContext context = new DrawingContext();
context.setDiagramType(DiagramType.GRAPH);
context.setOutputFile(output);
context.setComponents(flows);

ComponentItem item = new ComponentItem();
item.setPrefix("vm");
item.setOperation("publish");
item.setSource(false);
item.setConfigAttributeName("config-ref");
item.setPathAttributeName("queueName");
context.setKnownComponents(Collections.singletonMap(item.qualifiedName(), item));

GraphDiagram graphDiagram = Mockito.spy(new GraphDiagram());
when(graphDiagram.getDiagramHeaderLines()).thenReturn(new String[] {"Test Diagram"});
graphDiagram.draw(context);
ArgumentCaptor<MutableGraph> graphArgumentCaptor = ArgumentCaptor.forClass(MutableGraph.class);
verify(graphDiagram).writGraphToFile(any(File.class), graphArgumentCaptor.capture());
MutableGraph generatedGraph = graphArgumentCaptor.getValue();
String generated = GraphvizEngineHelper.generate(generatedGraph, Format.DOT);
String ref =
new String(Files.readAllBytes(Paths.get("src/test/resources/gh-issues/iss-302.dot")));
assertThat(generated).as("DOT Graph").isEqualToNormalizingNewlines(ref);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ subgraph "cluster_mule" {
edge ["dir"="forward"]
graph ["rankdir"="LR","splines"="spline","pad"="1.0,0.5","dpi"="150","label"=<Application graph<br/>>,"labelloc"="t","style"="invis"]
edge ["arrowhead"="vee","dir"="forward"]
"http:listener" ["shape"="hexagon","style"="filled","color"="cyan","sourceNode"="true","label"=<<b>http: listener</b><br/>/api/*<br/>>]
"http:listener:/api/*" ["shape"="hexagon","style"="filled","color"="cyan","sourceNode"="true","label"=<<b>http: listener</b><br/>/api/*<br/>>]
"flow:test-api-main" ["label"=<<b>flow</b>: test-api-main>,"shape"="rectangle","color"="blue"]
"apikittest-api-config" ["shape"="doublecircle","color"="cyan","style"="filled","label"=<<b>apikit</b><br/>test-api-config<br/>>]
"flow:put:\users\(userId):test-api-config" ["label"=<<b>flow</b>: put:\users\(userId):test-api-config>,"shape"="rectangle","color"="blue"]
"flow:get:\users:test-api-config" ["label"=<<b>flow</b>: get:\users:test-api-config>,"shape"="rectangle","color"="blue"]
"flow:get:\users\(userId):test-api-config" ["label"=<<b>flow</b>: get:\users\(userId):test-api-config>,"shape"="rectangle","color"="blue"]
"flow:post:\users:test-api-config" ["label"=<<b>flow</b>: post:\users:test-api-config>,"shape"="rectangle","color"="blue"]
"http:listener:/console/*" ["shape"="hexagon","style"="filled","color"="cyan","sourceNode"="true","label"=<<b>http: listener</b><br/>/console/*<br/>>]
"flow:test-api-console" ["label"=<<b>flow</b>: test-api-console>,"shape"="rectangle","color"="blue"]
"sub-flow:test-sub-flow" ["label"=<<b>sub-flow</b>: test-sub-flow>,"color"="black","shape"="ellipse"]
"sub-flow:test-sub-flow1" ["label"=<<b>sub-flow</b>: test-sub-flow1>,"color"="black","shape"="ellipse"]
"http:listener" -> "flow:test-api-console" ["style"="bold"]
"http:listener" -> "flow:test-api-main" ["style"="bold"]
"http:listener:/api/*" -> "flow:test-api-main" ["style"="bold"]
"flow:test-api-main" -> "apikittest-api-config" ["style"="solid","label"="(1)"]
"apikittest-api-config" -> "flow:put:\users\(userId):test-api-config" ["style"="solid"]
"apikittest-api-config" -> "flow:get:\users:test-api-config" ["style"="solid"]
Expand All @@ -55,6 +55,7 @@ edge ["arrowhead"="vee","dir"="forward"]
"flow:get:\users:test-api-config" -> "sub-flow:test-sub-flow" ["style"="solid","label"="(1)"]
"flow:get:\users\(userId):test-api-config" -> "sub-flow:test-sub-flow" ["style"="solid","label"="(1)"]
"flow:post:\users:test-api-config" -> "sub-flow:test-sub-flow" ["style"="solid","label"="(1)"]
"http:listener:/console/*" -> "flow:test-api-console" ["style"="bold"]
"flow:test-api-console" -> "apikittest-api-config" ["style"="solid","label"="(1)"]
"sub-flow:test-sub-flow" -> "sub-flow:test-sub-flow1" ["style"="solid","label"="(1)"]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.javastreets.mulefd.model;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

class KnownMuleComponentTest {

@Test
@DisplayName("Qualified name with no path attribute")
void qualifiedName_no_path() {
KnownMuleComponent component = new KnownMuleComponent("prefix", "operation");
assertThat(component.qualifiedName()).isEqualTo("prefix:operation");
}

@Test
@DisplayName("Qualified name with null path value")
void qualifiedName_null_path() {
KnownMuleComponent component = new KnownMuleComponent("prefix", "operation");
component.setPath(Attribute.with("tag", null));
assertThat(component.qualifiedName()).isEqualTo("prefix:operation");
}

@Test
@DisplayName("Qualified name with path value")
void qualifiedName_some_path() {
KnownMuleComponent component = new KnownMuleComponent("prefix", "operation");
component.setPath(Attribute.with("tag", "pathValue"));
assertThat(component.qualifiedName()).isEqualTo("prefix:operation:pathValue");
}
}
4 changes: 2 additions & 2 deletions src/test/resources/gh-issues/iss-256.dot
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ subgraph "cluster_mule" {
edge ["dir"="forward"]
graph ["rankdir"="LR","splines"="spline","pad"="1.0,0.5","dpi"="150","label"=<Application graph<br/>>,"labelloc"="t","style"="invis"]
edge ["arrowhead"="vee","dir"="forward"]
"http:listener" ["shape"="hexagon","style"="filled","color"="cyan","sourceNode"="true","label"=<<b>http: listener</b><br/>/api/*<br/>>]
"http:listener:/api/*" ["shape"="hexagon","style"="filled","color"="cyan","sourceNode"="true","label"=<<b>http: listener</b><br/>/api/*<br/>>]
"flow:test-api-main" ["label"=<<b>flow</b>: test-api-main>,"shape"="rectangle","color"="blue"]
"apikittest-api-config" ["shape"="doublecircle","color"="cyan","style"="filled","label"=<<b>apikit</b><br/>test-api-config<br/>>]
"flow:put:\users\(userId):test-api-config" ["label"=<<b>flow</b>: put:\users\(userId):test-api-config>,"shape"="rectangle","color"="blue"]
"flow:get:\users:test-api-config" ["label"=<<b>flow</b>: get:\users:test-api-config>,"shape"="rectangle","color"="blue"]
"sub-flow:test-sub-flow" ["label"=<<b>sub-flow</b>: test-sub-flow>,"color"="black","shape"="ellipse"]
"http:listener" -> "flow:test-api-main" ["style"="bold"]
"http:listener:/api/*" -> "flow:test-api-main" ["style"="bold"]
"flow:test-api-main" -> "apikittest-api-config" ["style"="solid","label"="(1)"]
"apikittest-api-config" -> "flow:put:\users\(userId):test-api-config" ["style"="solid"]
"apikittest-api-config" -> "flow:get:\users:test-api-config" ["style"="solid"]
Expand Down
43 changes: 43 additions & 0 deletions src/test/resources/gh-issues/iss-302.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
digraph "mule" {
edge ["dir"="forward"]
graph ["rankdir"="LR","splines"="spline","pad"="1.0,0.5","dpi"="150","label"=<Test Diagram<br/>>,"labelloc"="t"]
edge ["arrowhead"="vee","dir"="forward"]
subgraph "cluster_legend" {
edge ["dir"="forward"]
graph ["label"=<<b>Legend</b>>,"style"="dashed"]
"flow" ["fixedsize"="true","width"="1.0","height"="0.25","shape"="rectangle","color"="blue"]
"sub-flow" ["fixedsize"="true","width"="1.0","height"="0.25","color"="black","shape"="ellipse"]
"connector:operation" ["shape"="component"]
"Unused sub/-flow" ["fixedsize"="true","width"="2.0","height"="0.25","color"="gray","style"="filled"]
"Flow A" ["fixedsize"="true","width"="1.0","height"="0.25"]
"sub-flow-1" ["fixedsize"="true","width"="1.25","height"="0.25"]
"Flow C" ["fixedsize"="true","width"="1.0","height"="0.25"]
"sub-flow-C1" ["fixedsize"="true","width"="1.25","height"="0.25"]
"flow source" ["fixedsize"="true","width"="1.5","height"="0.25","shape"="hexagon","style"="filled","color"="cyan","sourceNode"="true"]
"flow self-call" ["fixedsize"="true","width"="1.25","height"="0.25","shape"="rectangle","color"="blue"]
"sub-flow self-call" ["fixedsize"="true","width"="2.0","height"="0.25","color"="black","shape"="ellipse"]
"flow" -> "sub-flow" ["style"="invis"]
"sub-flow" -> "Unused sub/-flow" ["style"="invis"]
"Flow A" -> "sub-flow-1" ["style"="solid","label"="(1)","taillabel"="Call Sequence\n","labelangle"="-5.0","labeldistance"="8.0"]
"Flow C" -> "sub-flow-C1" ["style"="dashed,bold","xlabel"="(1) Async","color"="lightblue3","taillabel"="Asynchronous call\n","labelangle"="-5.0","labeldistance"="8.0"]
"flow source" -> "flow self-call" ["style"="invis"]
"flow self-call" -> "flow self-call"
"flow self-call" -> "sub-flow self-call" ["style"="invis"]
"sub-flow self-call" -> "sub-flow self-call"
}
subgraph "cluster_legend-space" {
edge ["dir"="none"]
graph ["label"="","style"="invis"]
"" ["shape"="none","width"="2.0","height"="1.0"]
}
subgraph "cluster_mule" {
edge ["dir"="forward"]
graph ["rankdir"="LR","splines"="spline","pad"="1.0,0.5","dpi"="150","label"=<Application graph<br/>>,"labelloc"="t","style"="invis"]
edge ["arrowhead"="vee","dir"="forward"]
"flow:mulefdFlow" ["label"=<<b>flow</b>: mulefdFlow>,"shape"="rectangle","color"="blue"]
"vm:publish:queue1" ["shape"="component","label"=<<b>vm</b>: publish <br/><i>queue1</i>>]
"vm:publish:queue2" ["shape"="component","label"=<<b>vm</b>: publish <br/><i>queue2</i>>]
"flow:mulefdFlow" -> "vm:publish:queue1" ["style"="solid","label"="(1)"]
"flow:mulefdFlow" -> "vm:publish:queue2" ["style"="solid","label"="(2)"]
}
}
14 changes: 14 additions & 0 deletions src/test/resources/gh-issues/iss-302.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd">
<vm:config name="VM_Config" doc:name="VM Config" doc:id="9768a4c1-08a2-4a54-aece-e48a59369459">
<vm:queues />
</vm:config>
<flow name="mulefdFlow" doc:id="07e45c06-9cad-4ddb-bc36-36c6c2b6affa" >
<vm:publish queueName="queue1" doc:name="Publish" doc:id="d531be43-d544-4f6c-8423-d674675dbbc2" config-ref="VM_Config"/>
<vm:publish doc:name="Publish" doc:id="3b96a3fd-7a95-427b-945c-4dcc9461ac53" config-ref="VM_Config" queueName="queue2"/>
</flow>
</mule>
12 changes: 6 additions & 6 deletions src/test/resources/kafka-flows-mulefd-components-example.dot
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ subgraph "cluster_mule" {
edge ["dir"="forward"]
graph ["rankdir"="LR","splines"="spline","pad"="1.0,0.5","dpi"="150","label"=<Application graph<br/>>,"labelloc"="t","style"="invis"]
edge ["arrowhead"="vee","dir"="forward"]
"http:listener" ["shape"="hexagon","style"="filled","color"="cyan","sourceNode"="true","label"=<<b>http: listener</b><br/>/pushMessage<br/>>]
"http:listener:/pushMessage" ["shape"="hexagon","style"="filled","color"="cyan","sourceNode"="true","label"=<<b>http: listener</b><br/>/pushMessage<br/>>]
"flow:Producer-Flow" ["label"=<<b>flow</b>: Producer-Flow>,"shape"="rectangle","color"="blue"]
"kafka:publish" ["shape"="component","label"=<<b>kafka</b>: publish <br/><i>#[payload.topic]</i>>]
"kafka:message-listener" ["shape"="hexagon","style"="filled","color"="cyan","sourceNode"="true","label"=<<b>kafka: message-listener</b><br/><br/>>]
"kafka:publish:#[payload.topic]" ["shape"="component","label"=<<b>kafka</b>: publish <br/><i>#[payload.topic]</i>>]
"kafka:message-listener:" ["shape"="hexagon","style"="filled","color"="cyan","sourceNode"="true","label"=<<b>kafka: message-listener</b><br/><br/>>]
"flow:Consumer-Flow" ["label"=<<b>flow</b>: Consumer-Flow>,"shape"="rectangle","color"="blue"]
"http:listener" -> "flow:Producer-Flow" ["style"="bold"]
"flow:Producer-Flow" -> "kafka:publish" ["style"="dashed,bold","xlabel"="(1) Async","color"="lightblue3"]
"kafka:message-listener" -> "flow:Consumer-Flow" ["style"="bold"]
"http:listener:/pushMessage" -> "flow:Producer-Flow" ["style"="bold"]
"flow:Producer-Flow" -> "kafka:publish:#[payload.topic]" ["style"="dashed,bold","xlabel"="(1) Async","color"="lightblue3"]
"kafka:message-listener:" -> "flow:Consumer-Flow" ["style"="bold"]
}
}