Skip to content

Commit

Permalink
[patch] Fix bad file names for windows (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
manikmagar authored Jun 11, 2020
1 parent a497d6f commit 6503998
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ You can specify `-gs` or `--genSingles` option to generate individual flow diagr

These diagrams are generated at `{targetPath}/single-flow-diagrams/{currentDateTime}` directory. Each generated diagram has the same name as flow it represents.

NOTE: Some flow names, especially the APIKit generated flows can contain characters not valid for some OS. Names are thus sanitized. Any character not in `a-zA-Z0-9.-` is replaced with `_`.

=== Flowname
If you just want to generate diagram for a single flow then specify it with `-fl` or `--flowname` option. This will exclude all flows and subflows that are not related to this target flow.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.javastreets.muleflowdiagrams.drawings;

import static com.javastreets.muleflowdiagrams.util.FileUtil.sanitizeFilename;
import static guru.nidi.graphviz.attribute.Arrow.*;
import static guru.nidi.graphviz.model.Factory.*;

Expand Down Expand Up @@ -71,7 +72,8 @@ boolean writeFlowGraph(Component flowComponent, Path targetDirectory, MutableGra
if (!flowComponent.isaFlow())
return false;
String flowName = flowComponent.getName();
Path targetPath = Paths.get(targetDirectory.toString(), flowName.concat(".png"));
Path targetPath =
Paths.get(targetDirectory.toString(), sanitizeFilename(flowName.concat(".png")));
log.info("Writing individual flow graph for {} at {}", flowName, targetPath);
try {
flowGraph.setName(flowComponent.qualifiedName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ static Stream<Arguments> componentConfigProvider() throws IOException {
.map(path -> Arguments.of(path.toAbsolutePath().toString(), path.getFileName().toString()));
}

@Test
void renderFileWithBadFlowNamesForFiles() throws Exception {
Path filePath = Paths.get("src/test/resources/test-api.xml");
String[] args = new String[] {filePath.toAbsolutePath().toString(), "--out",
filePath.getFileName().toString(), "-t", tempDir.getAbsolutePath(), "-gs"};
Application application = new Application();
new CommandLine(application).parseArgs(args);
application.call();
String outputFilename = filePath.getFileName().toString() + ".png";
assertThat(Paths.get(tempDir.getAbsolutePath(), outputFilename)).exists();
// .hasSameBinaryContentAs(Paths.get(toAbsolutePath("./renderer/component-configs/"),
// outputFilename)); // This fails due to time stamp difference
}

@Test
@DisplayName("Render Mule 3 exmple config")
void mule3Rendering() throws Exception {
Expand Down
148 changes: 148 additions & 0 deletions src/test/resources/test-api.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit="http://www.mulesoft.org/schema/mule/mule-apikit" xmlns:http="http://www.mulesoft.org/schema/mule/http" 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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/mule-apikit http://www.mulesoft.org/schema/mule/mule-apikit/current/mule-apikit.xsd ">
<http:listener-config name="test-api-httpListenerConfig">
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<apikit:config name="test-api-config" api="test-api.raml" outboundHeadersMapName="outboundHeaders" httpStatusVarName="httpStatus" />
<flow name="test-api-main">
<http:listener config-ref="test-api-httpListenerConfig" path="/api/*">
<http:response statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<apikit:router config-ref="test-api-config" />
<error-handler>
<on-error-propagate type="APIKIT:BAD_REQUEST">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Bad request"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">400</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_FOUND">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">404</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:METHOD_NOT_ALLOWED">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Method not allowed"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">405</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_ACCEPTABLE">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Not acceptable"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">406</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:UNSUPPORTED_MEDIA_TYPE">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Unsupported media type"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">415</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_IMPLEMENTED">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Not Implemented"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">501</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
</error-handler>
</flow>
<flow name="test-api-console">
<http:listener config-ref="test-api-httpListenerConfig" path="/console/*">
<http:response statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<apikit:console config-ref="test-api-config" />
<error-handler>
<on-error-propagate type="APIKIT:NOT_FOUND">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">404</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
</error-handler>
</flow>
<flow name="put:\users\(userId):test-api-config">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core">
<ee:variables>
<ee:set-variable variableName="userId">attributes.uriParams.'userId'</ee:set-variable>
</ee:variables>
</ee:transform>
<logger level="INFO" message="put:\users\(userId):test-api-config" />
</flow>
<flow name="get:\users:test-api-config">
<logger level="INFO" message="get:\users:test-api-config" />
</flow>
<flow name="get:\users\(userId):test-api-config">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core">
<ee:variables>
<ee:set-variable variableName="userId">attributes.uriParams.'userId'</ee:set-variable>
</ee:variables>
</ee:transform>
<logger level="INFO" message="get:\users\(userId):test-api-config" />
</flow>
<flow name="post:\users:test-api-config">
<logger level="INFO" message="post:\users:test-api-config" />
</flow>
</mule>

0 comments on commit 6503998

Please sign in to comment.