From 2f578c5fd7108b5b2e498aca86b241d0518b11b0 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Thu, 21 Nov 2024 19:03:39 +0000 Subject: [PATCH 1/9] test: create initial structure to restrictTest Signed-off-by: Otavio Santana --- .../test/java/jakarta/data/RestrictTest.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 api/src/test/java/jakarta/data/RestrictTest.java diff --git a/api/src/test/java/jakarta/data/RestrictTest.java b/api/src/test/java/jakarta/data/RestrictTest.java new file mode 100644 index 000000000..ea4f60341 --- /dev/null +++ b/api/src/test/java/jakarta/data/RestrictTest.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package jakarta.data; + +import org.assertj.core.api.SoftAssertions; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +class RestrictTest { + + @Test + void shouldCombineAllRestrictions() { + Restriction r1 = Restrict.equalTo("value1", "field1"); + Restriction r2 = Restrict.lessThan(100, "field2"); + + Restriction combined = Restrict.all(r1, r2); + + assertThat(combined).isInstanceOf(CompositeRestrictionRecord.class); + + CompositeRestrictionRecord composite = (CompositeRestrictionRecord) combined; + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(composite.type()).isEqualTo(CompositeRestriction.Type.ALL); + soft.assertThat(composite.restrictions()).containsExactly(r1, r2); + }); + } +} From 13640fd86b37b015054c1800ee9e1330c030f3a1 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Thu, 21 Nov 2024 19:08:13 +0000 Subject: [PATCH 2/9] test: create test scenarios to restrict Signed-off-by: Otavio Santana --- .../test/java/jakarta/data/RestrictTest.java | 130 +++++++++++++++++- 1 file changed, 126 insertions(+), 4 deletions(-) diff --git a/api/src/test/java/jakarta/data/RestrictTest.java b/api/src/test/java/jakarta/data/RestrictTest.java index ea4f60341..63a63c0b0 100644 --- a/api/src/test/java/jakarta/data/RestrictTest.java +++ b/api/src/test/java/jakarta/data/RestrictTest.java @@ -21,14 +21,45 @@ import org.junit.jupiter.api.Test; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; class RestrictTest { + + @Test + void shouldCreateEqualToRestriction() { + Restriction restriction = Restrict.equalTo("value", "field"); + + assertThat(restriction).isInstanceOf(TextRestrictionRecord.class); + + TextRestrictionRecord basic = (TextRestrictionRecord) restriction; + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(basic.field()).isEqualTo("field"); + soft.assertThat(basic.comparison()).isEqualTo(Operator.EQUAL); + soft.assertThat(basic.value()).isEqualTo("value"); + soft.assertThat(basic.isNegated()).isFalse(); + }); + } + + @Test + void shouldCreateNotEqualToRestriction() { + Restriction restriction = Restrict.notEqualTo("value", "field"); + + assertThat(restriction).isInstanceOf(TextRestrictionRecord.class); + + TextRestrictionRecord basic = (TextRestrictionRecord) restriction; + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(basic.field()).isEqualTo("field"); + soft.assertThat(basic.comparison()).isEqualTo(Operator.EQUAL); + soft.assertThat(basic.value()).isEqualTo("value"); + soft.assertThat(basic.isNegated()).isTrue(); + }); + } + @Test - void shouldCombineAllRestrictions() { - Restriction r1 = Restrict.equalTo("value1", "field1"); - Restriction r2 = Restrict.lessThan(100, "field2"); + void shouldCombineAllRestrictionsWithNegation() { + Restriction r1 = Restrict.notEqualTo("value1", "field1"); + Restriction r2 = Restrict.greaterThan(100, "field2"); Restriction combined = Restrict.all(r1, r2); @@ -38,6 +69,97 @@ void shouldCombineAllRestrictions() { SoftAssertions.assertSoftly(soft -> { soft.assertThat(composite.type()).isEqualTo(CompositeRestriction.Type.ALL); soft.assertThat(composite.restrictions()).containsExactly(r1, r2); + soft.assertThat(composite.isNegated()).isFalse(); + }); + } + + @Test + void shouldCreateContainsRestriction() { + TextRestriction restriction = Restrict.contains("substring", "field"); + + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(restriction.field()).isEqualTo("field"); + soft.assertThat(restriction.comparison()).isEqualTo(Operator.LIKE); + soft.assertThat(restriction.value()).isEqualTo("%substring%"); + soft.assertThat(restriction.isNegated()).isFalse(); + }); + } + + @Test + void shouldCreateNegatedContainsRestriction() { + TextRestriction restriction = Restrict.notContains("substring", "field"); + + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(restriction.field()).isEqualTo("field"); + soft.assertThat(restriction.comparison()).isEqualTo(Operator.LIKE); + soft.assertThat(restriction.value()).isEqualTo("%substring%"); + soft.assertThat(restriction.isNegated()).isTrue(); + }); + } + + @Test + void shouldCreateStartsWithRestriction() { + TextRestriction restriction = Restrict.startsWith("prefix", "field"); + + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(restriction.field()).isEqualTo("field"); + soft.assertThat(restriction.comparison()).isEqualTo(Operator.LIKE); + soft.assertThat(restriction.value()).isEqualTo("prefix%"); + soft.assertThat(restriction.isNegated()).isFalse(); + }); + } + + @Test + void shouldCreateNegatedStartsWithRestriction() { + TextRestriction restriction = Restrict.notStartsWith("prefix", "field"); + + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(restriction.field()).isEqualTo("field"); + soft.assertThat(restriction.comparison()).isEqualTo(Operator.LIKE); + soft.assertThat(restriction.value()).isEqualTo("prefix%"); + soft.assertThat(restriction.isNegated()).isTrue(); + }); + } + + @Test + void shouldCreateEndsWithRestriction() { + TextRestriction restriction = Restrict.endsWith("suffix", "field"); + + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(restriction.field()).isEqualTo("field"); + soft.assertThat(restriction.comparison()).isEqualTo(Operator.LIKE); + soft.assertThat(restriction.value()).isEqualTo("%suffix"); + soft.assertThat(restriction.isNegated()).isFalse(); }); } + + @Test + void shouldCreateNegatedEndsWithRestriction() { + TextRestriction restriction = Restrict.notEndsWith("suffix", "field"); + + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(restriction.field()).isEqualTo("field"); + soft.assertThat(restriction.comparison()).isEqualTo(Operator.LIKE); + soft.assertThat(restriction.value()).isEqualTo("%suffix"); + soft.assertThat(restriction.isNegated()).isTrue(); + }); + } + + @Test + void shouldEscapeToLikePatternCorrectly() { + String result = invokeToLikeEscaped('_', '%', true, "test_value", false); + + assertThat(result).isEqualTo("%test\\_value"); + } + + @Test + void shouldThrowExceptionForInvalidWildcard() { + assertThatThrownBy(() -> invokeToLikeEscaped('_', '_', true, "value", false)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Cannot use the same character (_) for both types of wildcards."); + } + + private String invokeToLikeEscaped(char charWildcard, char stringWildcard, boolean allowPrevious, String literal, boolean allowSubsequent) { + return Restrict.toLikeEscaped(charWildcard, stringWildcard, allowPrevious, literal, allowSubsequent); + } } From d2f0fe03780e46b5586cd13e970bebd82aaba3d8 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Thu, 21 Nov 2024 19:08:37 +0000 Subject: [PATCH 3/9] feat: update the method to became default package Signed-off-by: Otavio Santana --- api/src/main/java/jakarta/data/Restrict.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/jakarta/data/Restrict.java b/api/src/main/java/jakarta/data/Restrict.java index faa96602e..2036a71f8 100644 --- a/api/src/main/java/jakarta/data/Restrict.java +++ b/api/src/main/java/jakarta/data/Restrict.java @@ -192,7 +192,7 @@ public static TextRestriction startsWith(String prefix, String field) { * @throws IllegalArgumentException if the same character is supplied for * both wildcard types. */ - private static String toLikeEscaped(char charWildcard, + static String toLikeEscaped(char charWildcard, char stringWildcard, boolean allowPrevious, String literal, From 6cee833f7a1e32a3c3161ffc89bd4f259b764fba Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Thu, 21 Nov 2024 19:09:21 +0000 Subject: [PATCH 4/9] docs: update documentation to Restrict Signed-off-by: Otavio Santana --- api/src/main/java/jakarta/data/Restrict.java | 1 + 1 file changed, 1 insertion(+) diff --git a/api/src/main/java/jakarta/data/Restrict.java b/api/src/main/java/jakarta/data/Restrict.java index 2036a71f8..debaee3f3 100644 --- a/api/src/main/java/jakarta/data/Restrict.java +++ b/api/src/main/java/jakarta/data/Restrict.java @@ -192,6 +192,7 @@ public static TextRestriction startsWith(String prefix, String field) { * @throws IllegalArgumentException if the same character is supplied for * both wildcard types. */ + // TODO I make default package, but it should be private when we make it as Pattern static String toLikeEscaped(char charWildcard, char stringWildcard, boolean allowPrevious, From c047e0ffa46ed402a391a5ad740acda27d2bf94a Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Thu, 21 Nov 2024 19:11:21 +0000 Subject: [PATCH 5/9] test: create structure to basicrestriction record Signed-off-by: Otavio Santana --- .../data/BasicRestrictionRecordTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 api/src/test/java/jakarta/data/BasicRestrictionRecordTest.java diff --git a/api/src/test/java/jakarta/data/BasicRestrictionRecordTest.java b/api/src/test/java/jakarta/data/BasicRestrictionRecordTest.java new file mode 100644 index 000000000..490490a93 --- /dev/null +++ b/api/src/test/java/jakarta/data/BasicRestrictionRecordTest.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package jakarta.data; + +import static org.junit.jupiter.api.Assertions.*; + +class BasicRestrictionRecordTest { + +} From e2f899eb5fba41be93c472b201d39b7d77078236 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Thu, 21 Nov 2024 19:12:25 +0000 Subject: [PATCH 6/9] test: create BasicRestrictionRecord scenarions Signed-off-by: Otavio Santana --- .../data/BasicRestrictionRecordTest.java | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/api/src/test/java/jakarta/data/BasicRestrictionRecordTest.java b/api/src/test/java/jakarta/data/BasicRestrictionRecordTest.java index 490490a93..a92c2c37c 100644 --- a/api/src/test/java/jakarta/data/BasicRestrictionRecordTest.java +++ b/api/src/test/java/jakarta/data/BasicRestrictionRecordTest.java @@ -17,8 +17,59 @@ */ package jakarta.data; -import static org.junit.jupiter.api.Assertions.*; +import org.assertj.core.api.SoftAssertions; +import org.junit.jupiter.api.Test; + class BasicRestrictionRecordTest { + @Test + void shouldCreateBasicRestrictionWithDefaultNegation() { + BasicRestrictionRecord restriction = new BasicRestrictionRecord<>("title", Operator.EQUAL, "Java Guide"); + + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(restriction.field()).isEqualTo("title"); + soft.assertThat(restriction.isNegated()).isFalse(); + soft.assertThat(restriction.comparison()).isEqualTo(Operator.EQUAL); + soft.assertThat(restriction.value()).isEqualTo("Java Guide"); + }); + } + + @Test + void shouldCreateBasicRestrictionWithExplicitNegation() { + BasicRestrictionRecord restriction = new BasicRestrictionRecord<>("title", true, Operator.EQUAL, "Java Guide"); + + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(restriction.field()).isEqualTo("title"); + soft.assertThat(restriction.isNegated()).isTrue(); + soft.assertThat(restriction.comparison()).isEqualTo(Operator.EQUAL); + soft.assertThat(restriction.value()).isEqualTo("Java Guide"); + }); + } + + @Test + void shouldCreateBasicRestrictionWithNullValue() { + // Create a restriction with a null value + BasicRestrictionRecord restriction = new BasicRestrictionRecord<>("title", Operator.EQUAL, null); + + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(restriction.field()).isEqualTo("title"); + soft.assertThat(restriction.isNegated()).isFalse(); + soft.assertThat(restriction.comparison()).isEqualTo(Operator.EQUAL); + soft.assertThat(restriction.value()).isNull(); + }); + } + + @Test + void shouldSupportNegatedRestrictionUsingDefaultConstructor() { + BasicRestrictionRecord restriction = new BasicRestrictionRecord<>("author", Operator.EQUAL, "Unknown"); + BasicRestrictionRecord negatedRestriction = new BasicRestrictionRecord<>(restriction.field(), true, restriction.comparison(), restriction.value()); + + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(negatedRestriction.field()).isEqualTo("author"); + soft.assertThat(negatedRestriction.isNegated()).isTrue(); + soft.assertThat(negatedRestriction.comparison()).isEqualTo(Operator.EQUAL); + soft.assertThat(negatedRestriction.value()).isEqualTo("Unknown"); + }); + } } From af29f92289792932e31e870c08be973b5b74a208 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Thu, 21 Nov 2024 19:13:14 +0000 Subject: [PATCH 7/9] test: create structure to composite restrictionrecord Signed-off-by: Otavio Santana --- .../data/CompositeRestrictionRecordTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 api/src/test/java/jakarta/data/CompositeRestrictionRecordTest.java diff --git a/api/src/test/java/jakarta/data/CompositeRestrictionRecordTest.java b/api/src/test/java/jakarta/data/CompositeRestrictionRecordTest.java new file mode 100644 index 000000000..f9cadee57 --- /dev/null +++ b/api/src/test/java/jakarta/data/CompositeRestrictionRecordTest.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package jakarta.data; + +import static org.junit.jupiter.api.Assertions.*; + +class CompositeRestrictionRecordTest { + +} From 8a93a8a0702247405c4d1aff5f0ab64166f3b088 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Thu, 21 Nov 2024 19:14:28 +0000 Subject: [PATCH 8/9] test: create scenarios to CompositeRestrictionREcord Signed-off-by: Otavio Santana --- .../data/CompositeRestrictionRecordTest.java | 97 ++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) diff --git a/api/src/test/java/jakarta/data/CompositeRestrictionRecordTest.java b/api/src/test/java/jakarta/data/CompositeRestrictionRecordTest.java index f9cadee57..3b88e18f3 100644 --- a/api/src/test/java/jakarta/data/CompositeRestrictionRecordTest.java +++ b/api/src/test/java/jakarta/data/CompositeRestrictionRecordTest.java @@ -17,8 +17,103 @@ */ package jakarta.data; -import static org.junit.jupiter.api.Assertions.*; + +import org.assertj.core.api.SoftAssertions; +import org.junit.jupiter.api.Test; + +import java.util.List; + class CompositeRestrictionRecordTest { + + @Test + void shouldCreateCompositeRestrictionWithDefaultNegation() { + Restriction restriction1 = new BasicRestrictionRecord<>("title", Operator.EQUAL, "Java Guide"); + Restriction restriction2 = new BasicRestrictionRecord<>("author", Operator.EQUAL, "John Doe"); + + CompositeRestrictionRecord composite = new CompositeRestrictionRecord<>( + CompositeRestriction.Type.ALL, + List.of(restriction1, restriction2) + ); + + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(composite.type()).isEqualTo(CompositeRestriction.Type.ALL); + soft.assertThat(composite.restrictions()).containsExactly(restriction1, restriction2); + soft.assertThat(composite.isNegated()).isFalse(); + }); + } + + @Test + void shouldCreateCompositeRestrictionWithExplicitNegation() { + Restriction restriction1 = new BasicRestrictionRecord<>("title", Operator.EQUAL, "Java Guide"); + Restriction restriction2 = new BasicRestrictionRecord<>("author", Operator.EQUAL, "John Doe"); + + CompositeRestrictionRecord composite = new CompositeRestrictionRecord<>( + CompositeRestriction.Type.ANY, + List.of(restriction1, restriction2), + true + ); + + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(composite.type()).isEqualTo(CompositeRestriction.Type.ANY); + soft.assertThat(composite.restrictions()).containsExactly(restriction1, restriction2); + soft.assertThat(composite.isNegated()).isTrue(); + }); + } + + @Test + void shouldHandleEmptyRestrictions() { + CompositeRestrictionRecord composite = new CompositeRestrictionRecord<>( + CompositeRestriction.Type.ALL, + List.of() + ); + + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(composite.type()).isEqualTo(CompositeRestriction.Type.ALL); + soft.assertThat(composite.restrictions()).isEmpty(); + soft.assertThat(composite.isNegated()).isFalse(); + }); + } + + @Test + void shouldPreserveRestrictionsOrder() { + Restriction restriction1 = new BasicRestrictionRecord<>("title", Operator.EQUAL, "Java Guide"); + Restriction restriction2 = new BasicRestrictionRecord<>("author", Operator.EQUAL, "John Doe"); + + CompositeRestrictionRecord composite = new CompositeRestrictionRecord<>( + CompositeRestriction.Type.ALL, + List.of(restriction1, restriction2) + ); + + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(composite.restrictions().get(0)).isEqualTo(restriction1); + soft.assertThat(composite.restrictions().get(1)).isEqualTo(restriction2); + }); + } + + @Test + void shouldSupportNegationUsingDefaultConstructor() { + // Given multiple restrictions + Restriction restriction1 = new BasicRestrictionRecord<>("title", Operator.EQUAL, "Java Guide"); + Restriction restriction2 = new BasicRestrictionRecord<>("author", Operator.EQUAL, "John Doe"); + + // When creating a composite restriction and manually setting negation + CompositeRestrictionRecord composite = new CompositeRestrictionRecord<>( + CompositeRestriction.Type.ALL, + List.of(restriction1, restriction2) + ); + CompositeRestrictionRecord negatedComposite = new CompositeRestrictionRecord<>( + composite.type(), + composite.restrictions(), + true + ); + + // Then validate the negated composite restriction + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(negatedComposite.type()).isEqualTo(CompositeRestriction.Type.ALL); + soft.assertThat(negatedComposite.restrictions()).containsExactly(restriction1, restriction2); + soft.assertThat(negatedComposite.isNegated()).isTrue(); + }); + } } From c6f835e445bfefcf7cce1b630fb6be0ee8c713fc Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Thu, 21 Nov 2024 19:17:17 +0000 Subject: [PATCH 9/9] test: create scenarios to TextRestrictionRecord Signed-off-by: Otavio Santana --- .../data/TextRestrictionRecordTest.java | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 api/src/test/java/jakarta/data/TextRestrictionRecordTest.java diff --git a/api/src/test/java/jakarta/data/TextRestrictionRecordTest.java b/api/src/test/java/jakarta/data/TextRestrictionRecordTest.java new file mode 100644 index 000000000..ebb01e248 --- /dev/null +++ b/api/src/test/java/jakarta/data/TextRestrictionRecordTest.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package jakarta.data; + +import org.assertj.core.api.SoftAssertions; +import org.junit.jupiter.api.Test; + + +class TextRestrictionRecordTest { + + @Test + void shouldCreateTextRestrictionWithDefaultValues() { + TextRestrictionRecord restriction = new TextRestrictionRecord<>( + "title", + Operator.LIKE, + "%Java%" + ); + + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(restriction.field()).isEqualTo("title"); + soft.assertThat(restriction.isNegated()).isFalse(); + soft.assertThat(restriction.comparison()).isEqualTo(Operator.LIKE); + soft.assertThat(restriction.value()).isEqualTo("%Java%"); + soft.assertThat(restriction.isCaseSensitive()).isTrue(); + soft.assertThat(restriction.isEscaped()).isFalse(); + }); + } + + @Test + void shouldCreateTextRestrictionWithExplicitNegation() { + TextRestrictionRecord restriction = new TextRestrictionRecord<>( + "title", + true, + Operator.LIKE, + "%Java%" + ); + + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(restriction.field()).isEqualTo("title"); + soft.assertThat(restriction.isNegated()).isTrue(); + soft.assertThat(restriction.comparison()).isEqualTo(Operator.LIKE); + soft.assertThat(restriction.value()).isEqualTo("%Java%"); + soft.assertThat(restriction.isCaseSensitive()).isTrue(); + soft.assertThat(restriction.isEscaped()).isFalse(); + }); + } + + @Test + void shouldIgnoreCaseForTextRestriction() { + TextRestrictionRecord restriction = new TextRestrictionRecord<>( + "title", + Operator.LIKE, + "%Java%" + ); + + Restriction caseInsensitiveRestriction = restriction.ignoreCase(); + + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(caseInsensitiveRestriction).isInstanceOf(TextRestrictionRecord.class); + TextRestrictionRecord textRestriction = (TextRestrictionRecord) caseInsensitiveRestriction; + soft.assertThat(textRestriction.field()).isEqualTo("title"); + soft.assertThat(textRestriction.isNegated()).isFalse(); + soft.assertThat(textRestriction.comparison()).isEqualTo(Operator.LIKE); + soft.assertThat(textRestriction.value()).isEqualTo("%Java%"); + soft.assertThat(textRestriction.isCaseSensitive()).isFalse(); + soft.assertThat(textRestriction.isEscaped()).isFalse(); + }); + } + + @Test + void shouldCreateTextRestrictionWithEscapedValue() { + TextRestrictionRecord restriction = new TextRestrictionRecord<>( + "title", + Operator.LIKE, + true, + "%Java%" + ); + + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(restriction.field()).isEqualTo("title"); + soft.assertThat(restriction.isNegated()).isFalse(); + soft.assertThat(restriction.comparison()).isEqualTo(Operator.LIKE); + soft.assertThat(restriction.value()).isEqualTo("%Java%"); + soft.assertThat(restriction.isCaseSensitive()).isTrue(); + soft.assertThat(restriction.isEscaped()).isTrue(); + }); + } + + @Test + void shouldSupportNegationForTextRestriction() { + TextRestrictionRecord restriction = new TextRestrictionRecord<>( + "author", + true, + Operator.EQUAL, + "John Doe" + ); + + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(restriction.field()).isEqualTo("author"); + soft.assertThat(restriction.isNegated()).isTrue(); + soft.assertThat(restriction.comparison()).isEqualTo(Operator.EQUAL); + soft.assertThat(restriction.value()).isEqualTo("John Doe"); + soft.assertThat(restriction.isCaseSensitive()).isTrue(); + soft.assertThat(restriction.isEscaped()).isFalse(); + }); + } +}