Skip to content

Commit f9b6640

Browse files
committed
fix: ignore case in http header filter
1 parent 53d0ed1 commit f9b6640

File tree

4 files changed

+37
-12
lines changed

4 files changed

+37
-12
lines changed

simulator-spring-boot/src/main/java/org/citrusframework/simulator/service/QueryService.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ protected Specification<ENTITY> buildStringSpecification(StringFilter filter, Si
102102
protected Specification<ENTITY> buildSpecification(StringFilter filter, Function<Root<ENTITY>, Expression<String>> metaclassFunction) {
103103
if (filter.getEquals() != null) {
104104
return equalsSpecification(metaclassFunction, filter.getEquals());
105+
} else if (filter.getEqualsIgnoreCase() != null) {
106+
return equalsUpperSpecification(metaclassFunction, filter.getEqualsIgnoreCase());
105107
} else if (filter.getIn() != null) {
106108
return valueIn(metaclassFunction, filter.getIn());
107109
} else if (filter.getNotIn() != null) {
@@ -360,6 +362,17 @@ protected <X> Specification<ENTITY> equalsSpecification(Function<Root<ENTITY>, E
360362
return (root, query, builder) -> builder.equal(metaclassFunction.apply(root), value);
361363
}
362364

365+
/**
366+
* Generic method, which based on a Root&lt;ENTITY&gt; returns an Expression which type is the same as the given 'value' type, ignoring case.
367+
*
368+
* @param metaclassFunction function which returns the column which is used for filtering.
369+
* @param value the actual value to filter for.
370+
* @return a Specification.
371+
*/
372+
protected Specification<ENTITY> equalsUpperSpecification(Function<Root<ENTITY>, Expression<String>> metaclassFunction, String value) {
373+
return (root, query, builder) -> builder.equal(builder.upper(metaclassFunction.apply(root).as(String.class)), value.toUpperCase());
374+
}
375+
363376
/**
364377
* Generic method, which based on a Root&lt;ENTITY&gt; returns an Expression which type is the same as the given 'value' type.
365378
*
@@ -379,9 +392,8 @@ protected <X> Specification<ENTITY> notEqualsSpecification(Function<Root<ENTITY>
379392
* @param value a {@link java.lang.String} object.
380393
* @return a {@link org.springframework.data.jpa.domain.Specification} object.
381394
*/
382-
protected Specification<ENTITY> likeUpperSpecification(Function<Root<ENTITY>, Expression<String>> metaclassFunction,
383-
String value) {
384-
return (root, query, builder) -> builder.like(builder.upper(metaclassFunction.apply(root).as(String.class)), wrapLikeQuery(value));
395+
protected Specification<ENTITY> likeUpperSpecification(Function<Root<ENTITY>, Expression<String>> metaclassFunction, String value) {
396+
return (root, query, builder) -> builder.like(builder.upper(metaclassFunction.apply(root).as(String.class)), wrapLikeQuery(value.toUpperCase()));
385397
}
386398

387399
/**
@@ -391,9 +403,8 @@ protected Specification<ENTITY> likeUpperSpecification(Function<Root<ENTITY>, Ex
391403
* @param value a {@link java.lang.String} object.
392404
* @return a {@link org.springframework.data.jpa.domain.Specification} object.
393405
*/
394-
protected Specification<ENTITY> doesNotContainSpecification(Function<Root<ENTITY>, Expression<String>> metaclassFunction,
395-
String value) {
396-
return (root, query, builder) -> builder.not(builder.like(builder.upper(metaclassFunction.apply(root).as(String.class)), wrapLikeQuery(value)));
406+
protected Specification<ENTITY> doesNotContainSpecification(Function<Root<ENTITY>, Expression<String>> metaclassFunction, String value) {
407+
return (root, query, builder) -> builder.not(builder.like(builder.upper(metaclassFunction.apply(root).as(String.class)), wrapLikeQuery(value.toUpperCase())));
397408
}
398409

399410
/**

simulator-spring-boot/src/main/java/org/citrusframework/simulator/service/ScenarioExecutionQueryService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ private Specification<ScenarioExecution> createSpecificationFromMessageHeaderFil
252252
}
253253

254254
Specification<ScenarioExecution> messageHeaderKeyEqualsSpecification = buildSpecification(
255-
new StringFilter().setEquals(messageHeaderFilter.key),
255+
new StringFilter().setEqualsIgnoreCase(messageHeaderFilter.key),
256256
root -> joinMessageHeaders(root).get(MessageHeader_.name));
257257

258258
var messageHeaderValueSpecification = switch (messageHeaderFilter.operator) {

simulator-spring-boot/src/main/java/org/citrusframework/simulator/service/filter/StringFilter.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class StringFilter extends Filter<String> {
4040

4141
private String contains;
4242
private String doesNotContain;
43+
private String equalsIgnoreCase;
4344

4445
/**
4546
* <p>Constructor for StringFilter.</p>
@@ -104,6 +105,15 @@ public StringFilter setDoesNotContain(String doesNotContain) {
104105
return this;
105106
}
106107

108+
public String getEqualsIgnoreCase() {
109+
return equalsIgnoreCase;
110+
}
111+
112+
public StringFilter setEqualsIgnoreCase(String equalsIgnoreCase) {
113+
this.equalsIgnoreCase = equalsIgnoreCase;
114+
return this;
115+
}
116+
107117
/** {@inheritDoc} */
108118
@Override
109119
public boolean equals(Object o) {
@@ -117,14 +127,15 @@ public boolean equals(Object o) {
117127
return false;
118128
}
119129
StringFilter that = (StringFilter) o;
120-
return Objects.equals(contains, that.contains) &&
121-
Objects.equals(doesNotContain, that.doesNotContain);
130+
return Objects.equals(contains, that.contains)
131+
&& Objects.equals(doesNotContain, that.doesNotContain)
132+
&& Objects.equals(equalsIgnoreCase, that.equalsIgnoreCase);
122133
}
123134

124135
/** {@inheritDoc} */
125136
@Override
126137
public int hashCode() {
127-
return Objects.hash(super.hashCode(), contains, doesNotContain);
138+
return Objects.hash(super.hashCode(), contains, doesNotContain, equalsIgnoreCase);
128139
}
129140

130141
/** {@inheritDoc} */
@@ -138,6 +149,7 @@ public String toString() {
138149
+ (getNotIn() != null ? "notIn=" + getNotIn() + ", " : "")
139150
+ (getContains() != null ? "contains=" + getContains() + ", " : "")
140151
+ (getDoesNotContain() != null ? "doesNotContain=" + getDoesNotContain() : "")
152+
+ (getEqualsIgnoreCase() != null ? "equalsIgnoreCase=" + getEqualsIgnoreCase() : "")
141153
+ "]";
142154
}
143155
}

simulator-spring-boot/src/test/java/org/citrusframework/simulator/service/ScenarioExecutionQueryServiceIT.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,10 @@ void selectWithJoinToTestResult() {
258258
public static Stream<Arguments> selectWithJoinToMessageHeader() {
259259
return Stream.of(
260260
arguments("83def191b1dda4c79c00ae4c443f0ca2", 0),
261-
arguments(TRACEPARENT + "=" + MESSAGE_1_TRACEPARENT, 1),
262-
arguments(TRACEPARENT + "~1344094d192deb39a02025c6f9a67e3d", 2)
261+
arguments(TRACEPARENT.toLowerCase() + "=" + MESSAGE_1_TRACEPARENT.toLowerCase(), 1),
262+
arguments(TRACEPARENT.toLowerCase() + "=" + MESSAGE_1_TRACEPARENT.toUpperCase(), 1),
263+
arguments(TRACEPARENT.toUpperCase() + "=" + MESSAGE_1_TRACEPARENT.toLowerCase(), 1),
264+
arguments(TRACEPARENT.toLowerCase() + "~1344094d192deb39a02025c6f9a67e3d", 2)
263265
);
264266
}
265267

0 commit comments

Comments
 (0)