Skip to content

Commit 349f2e2

Browse files
committed
Incorporate dmitrii's review
Signed-off-by: Ricardo Zanini <[email protected]>
1 parent 31f4d85 commit 349f2e2

File tree

2 files changed

+56
-64
lines changed

2 files changed

+56
-64
lines changed

mermaid/src/test/java/io/serverlessworkflow/mermaid/ClasspathYamlFinder.java

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import java.io.File;
1919
import java.io.IOException;
20-
import java.io.UncheckedIOException;
2120
import java.net.JarURLConnection;
2221
import java.net.URL;
2322
import java.net.URLDecoder;
@@ -63,58 +62,50 @@ private static String normalizeBase(String base) {
6362
return b;
6463
}
6564

66-
private static Collection<String> scanFileUrl(URL url, String prefix) {
67-
try {
68-
Path root = Paths.get(URLDecoder.decode(url.getPath(), StandardCharsets.UTF_8));
69-
if (!Files.exists(root)) return List.of();
65+
private static Collection<String> scanFileUrl(URL url, String prefix) throws IOException {
66+
Path root = Paths.get(URLDecoder.decode(url.getPath(), StandardCharsets.UTF_8));
67+
if (!Files.exists(root)) return List.of();
7068

71-
// If we resolved exactly "<classpathRoot>/<prefix>/", we should prepend "prefix/"
72-
// to the relativized filenames to mirror the JAR behaviour.
73-
String rootStr = root.normalize().toString().replace('\\', '/');
74-
boolean rootIsPrefixDir = !prefix.isEmpty() && rootStr.endsWith("/" + prefix);
69+
// If we resolved exactly "<classpathRoot>/<prefix>/", we should prepend "prefix/"
70+
// to the relativized filenames to mirror the JAR behaviour.
71+
String rootStr = root.normalize().toString().replace('\\', '/');
72+
boolean rootIsPrefixDir = !prefix.isEmpty() && rootStr.endsWith("/" + prefix);
7573

76-
try (Stream<Path> s = Files.walk(root)) {
77-
return s.filter(Files::isRegularFile)
78-
.filter(
79-
p -> {
80-
String name = p.getFileName().toString().toLowerCase(Locale.ROOT);
81-
return name.endsWith(".yaml") || name.endsWith(".yml");
82-
})
83-
.map(
84-
p -> {
85-
String rel = root.relativize(p).toString().replace(File.separatorChar, '/');
86-
// When scanning the specific prefix directory, add "prefix/" so callers get
87-
// paths relative to the classpath root, e.g. "workflows-samples/foo.yaml".
88-
return rootIsPrefixDir ? (prefix + "/" + rel) : rel;
89-
})
90-
.collect(Collectors.toCollection(LinkedHashSet::new));
91-
}
92-
} catch (IOException e) {
93-
throw new UncheckedIOException(e);
74+
try (Stream<Path> s = Files.walk(root)) {
75+
return s.filter(Files::isRegularFile)
76+
.filter(
77+
p -> {
78+
String name = p.getFileName().toString().toLowerCase(Locale.ROOT);
79+
return name.endsWith(".yaml") || name.endsWith(".yml");
80+
})
81+
.map(
82+
p -> {
83+
String rel = root.relativize(p).toString().replace(File.separatorChar, '/');
84+
// When scanning the specific prefix directory, add "prefix/" so callers get
85+
// paths relative to the classpath root, e.g. "workflows-samples/foo.yaml".
86+
return rootIsPrefixDir ? (prefix + "/" + rel) : rel;
87+
})
88+
.collect(Collectors.toCollection(LinkedHashSet::new));
9489
}
9590
}
9691

97-
private static Collection<String> scanJarUrl(URL url) {
98-
try {
99-
JarURLConnection conn = (JarURLConnection) url.openConnection();
100-
try (JarFile jar = conn.getJarFile()) {
101-
String dir = ensureDirPrefix(conn.getEntryName());
102-
List<String> out = new ArrayList<>();
103-
Enumeration<JarEntry> entries = jar.entries();
104-
while (entries.hasMoreElements()) {
105-
JarEntry je = entries.nextElement();
106-
if (je.isDirectory()) continue;
107-
String name = je.getName();
108-
if (!name.startsWith(dir)) continue;
109-
String lower = name.toLowerCase(Locale.ROOT);
110-
if (lower.endsWith(".yaml") || lower.endsWith(".yml")) {
111-
out.add(name);
112-
}
92+
private static Collection<String> scanJarUrl(URL url) throws IOException {
93+
JarURLConnection conn = (JarURLConnection) url.openConnection();
94+
try (JarFile jar = conn.getJarFile()) {
95+
String dir = ensureDirPrefix(conn.getEntryName());
96+
List<String> out = new ArrayList<>();
97+
Enumeration<JarEntry> entries = jar.entries();
98+
while (entries.hasMoreElements()) {
99+
JarEntry je = entries.nextElement();
100+
if (je.isDirectory()) continue;
101+
String name = je.getName();
102+
if (!name.startsWith(dir)) continue;
103+
String lower = name.toLowerCase(Locale.ROOT);
104+
if (lower.endsWith(".yaml") || lower.endsWith(".yml")) {
105+
out.add(name);
113106
}
114-
return out;
115107
}
116-
} catch (IOException e) {
117-
throw new UncheckedIOException(e);
108+
return out;
118109
}
119110
}
120111

mermaid/src/test/java/io/serverlessworkflow/mermaid/MermaidSmokeTest.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,38 @@
1515
*/
1616
package io.serverlessworkflow.mermaid;
1717

18+
import static org.assertj.core.api.Assertions.assertThat;
19+
20+
import io.serverlessworkflow.api.WorkflowReader;
21+
import java.io.IOException;
22+
import java.util.stream.Stream;
1823
import org.junit.jupiter.params.ParameterizedTest;
1924
import org.junit.jupiter.params.provider.MethodSource;
2025

2126
class MermaidSmokeTest {
2227

2328
private static final String BASE = "workflows-samples"; // folder on test classpath
2429

25-
static java.util.stream.Stream<String> yamlSamples() {
26-
try {
27-
// First try the folder you expect, then rely on the fallback baked into the finder
28-
var list = ClasspathYamlFinder.listYamlResources(BASE);
29-
if (list.isEmpty()) {
30-
throw new IllegalStateException(
31-
"""
32-
No YAML resources found on the test classpath.
33-
- Is serverlessworkflow-impl-test built and its *-tests.jar on the test classpath?
34-
- Are YAMLs under src/test/resources in that module?
35-
- Path inside JAR may differ from '/'.
36-
""");
37-
}
38-
return list.stream();
39-
} catch (java.io.IOException e) {
40-
throw new java.io.UncheckedIOException(e);
30+
static Stream<String> yamlSamples() throws IOException {
31+
// First try the folder you expect, then rely on the fallback baked into the finder
32+
var list = ClasspathYamlFinder.listYamlResources(BASE);
33+
if (list.isEmpty()) {
34+
throw new IllegalStateException(
35+
"""
36+
No YAML resources found on the test classpath.
37+
- Is serverlessworkflow-impl-test built and its *-tests.jar on the test classpath?
38+
- Are YAMLs under src/test/resources in that module?
39+
- Path inside JAR may differ from '/'.
40+
""");
4141
}
42+
return list.stream();
4243
}
4344

4445
@ParameterizedTest(name = "{index} => {0}")
4546
@MethodSource("yamlSamples")
4647
void rendersBasicMermaidStructure(String resourcePath) throws Exception {
47-
var wf = io.serverlessworkflow.api.WorkflowReader.readWorkflowFromClasspath(resourcePath);
48+
var wf = WorkflowReader.readWorkflowFromClasspath(resourcePath);
4849
var mermaid = new io.serverlessworkflow.mermaid.Mermaid().from(wf);
49-
org.assertj.core.api.Assertions.assertThat(mermaid).isNotBlank().contains("flowchart TD");
50+
assertThat(mermaid).isNotBlank().contains("flowchart TD");
5051
}
5152
}

0 commit comments

Comments
 (0)