Skip to content
This repository was archived by the owner on Apr 5, 2022. It is now read-only.

Commit b10e4f0

Browse files
cppwfsmminella
authored andcommitted
Tests for basic tokens of job composition if parsing fails.
1 parent 84108d2 commit b10e4f0

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

spring-xd-dirt/src/main/java/org/springframework/xd/dirt/job/dsl/ComposedJobUtil.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,16 @@ public class ComposedJobUtil {
2929

3030
public static final String MODULE_SUFFIX = "_COMPOSED";
3131

32+
private static String orchestrationPatternString = "(\\|\\|" +//search for || in the definition
33+
"(?=([^\\\"']*[\\\"'][^\\\"']*[\\\"'])*[^\\\"']*$))" + //make sure its not in quotes
34+
"|(\\&" + //or find a & in the definition
35+
"(?=([^\\\"']*[\\\"'][^\\\"']*[\\\"'])*[^\\\"']*$))";// make sure its not in quotes
36+
3237
private static String parameterPatternString = "(--" +//search for -- in the definition
3338
"(?=([^\\\"']*[\\\"'][^\\\"']*[\\\"'])*[^\\\"']*$))"; //make sure its not in quotes
3439

40+
private static Pattern orchestrationPattern = Pattern.compile(orchestrationPatternString);
41+
3542
private static Pattern parameterPattern = Pattern.compile(parameterPatternString);
3643

3744
/**
@@ -64,7 +71,10 @@ public static boolean isComposedJobDefinition(String definition){
6471
}
6572
}
6673
} catch (JobSpecificationException e) {
67-
result = false; //failed to parse, could be a stream.
74+
//failed to parse, could still be a composed job. Look for basic components
75+
// such as || or & if found return true.
76+
Matcher matcher = orchestrationPattern.matcher(definition);
77+
result = matcher.find();
6878
}
6979
return result;
7080
}

spring-xd-dirt/src/test/java/org/springframework/xd/dirt/rest/JobsControllerIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void testComposedJobCreation() throws Exception {
122122
public void testComposedJobCreationBadDSL() throws Exception {
123123
mockMvc.perform(
124124
post("/jobs/definitions").param("name", "job1").param("definition", "A || B >").accept(
125-
MediaType.APPLICATION_JSON)).andExpect(status().is4xxClientError());
125+
MediaType.APPLICATION_JSON)).andExpect(status().isInternalServerError());
126126
}
127127

128128
@Test

0 commit comments

Comments
 (0)