Skip to content

Commit bf5863a

Browse files
committed
test: update scenarios with oracle NoSQL Like converter
Signed-off-by: Otavio Santana <[email protected]>
1 parent 7636546 commit bf5863a

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

jnosql-oracle-nosql/src/test/java/org/eclipse/jnosql/databases/oracle/communication/OracleNoSqlLikeConverterTest.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,77 @@ void shouldReturnEmptyForNull() {
7171
void shouldReturnEmptyForEmptyString() {
7272
assertThat(OracleNoSqlLikeConverter.INSTANCE.convert("")).isEqualTo("");
7373
}
74+
75+
@ParameterizedTest(name = "contains(\"{0}\") -> \"{1}\"")
76+
@MethodSource("containsCases")
77+
@DisplayName("contains(term) escapes meta and wraps with .* … .*")
78+
void shouldContains(String term, String expected) {
79+
String actual = OracleNoSqlLikeConverter.INSTANCE.contains(term);
80+
assertThat(actual).isEqualTo(expected);
81+
}
82+
83+
static Stream<org.junit.jupiter.params.provider.Arguments> containsCases() {
84+
return Stream.of(
85+
arguments("Lu", ".*Lu.*"),
86+
arguments("a.c", ".*a\\.c.*"),
87+
arguments("price$", ".*price\\$.*"),
88+
arguments("(hello)", ".*\\(hello\\).*"),
89+
arguments("", ".*.*")
90+
);
91+
}
92+
93+
@ParameterizedTest(name = "startsWith(\"{0}\") -> \"{1}\"")
94+
@MethodSource("startsWithCases")
95+
@DisplayName("startsWith(term) escapes meta and appends .*")
96+
void shouldStartsWith(String term, String expected) {
97+
String actual = OracleNoSqlLikeConverter.INSTANCE.startsWith(term);
98+
assertThat(actual).isEqualTo(expected);
99+
}
100+
101+
static Stream<org.junit.jupiter.params.provider.Arguments> startsWithCases() {
102+
return Stream.of(
103+
arguments("Lu", "Lu.*"),
104+
arguments("a.c", "a\\.c.*"),
105+
arguments("price$", "price\\$.*"),
106+
arguments("(hello)", "\\(hello\\).*"),
107+
arguments("", ".*")
108+
);
109+
}
110+
111+
112+
@ParameterizedTest(name = "endsWith(\"{0}\") -> \"{1}\"")
113+
@MethodSource("endsWithCases")
114+
@DisplayName("endsWith(term) escapes meta and prefixes .*")
115+
void shouldEndsWith(String term, String expected) {
116+
String actual = OracleNoSqlLikeConverter.INSTANCE.endsWith(term);
117+
assertThat(actual).isEqualTo(expected);
118+
}
119+
120+
static Stream<org.junit.jupiter.params.provider.Arguments> endsWithCases() {
121+
return Stream.of(
122+
arguments("Lu", ".*Lu"),
123+
arguments("a.c", ".*a\\.c"),
124+
arguments("price$", ".*price\\$"),
125+
arguments("(hello)", ".*\\(hello\\)"),
126+
arguments("", ".*")
127+
);
128+
}
129+
130+
@Test
131+
@DisplayName("All regex metacharacters are escaped in contains/startsWith/endsWith")
132+
void escapesAllMetaCharacters() {
133+
String term = ".^$*+?()[]{}\\|";
134+
// Expected escaped chunk: \.\^\$\*\+\?\(\)\[\]\{\}\\\|
135+
String escaped = "\\.\\^\\$\\*\\+\\?\\(\\)\\[\\]\\{\\}\\\\\\|";
136+
137+
assertThat(OracleNoSqlLikeConverter.INSTANCE.contains(term))
138+
.isEqualTo(".*" + escaped + ".*");
139+
140+
assertThat(OracleNoSqlLikeConverter.INSTANCE.startsWith(term))
141+
.isEqualTo(escaped + ".*");
142+
143+
assertThat(OracleNoSqlLikeConverter.INSTANCE.endsWith(term))
144+
.isEqualTo(".*" + escaped);
145+
}
146+
74147
}

0 commit comments

Comments
 (0)