|
15 | 15 | package org.eclipse.jnosql.mapping.semistructured.query;
|
16 | 16 |
|
17 | 17 | import jakarta.data.constraint.GreaterThan;
|
| 18 | +import jakarta.data.constraint.In; |
| 19 | +import jakarta.data.constraint.LessThan; |
18 | 20 | import jakarta.data.repository.By;
|
19 | 21 | import jakarta.data.repository.CrudRepository;
|
20 | 22 | import jakarta.data.repository.Find;
|
|
48 | 50 |
|
49 | 51 | import static org.eclipse.jnosql.communication.Condition.EQUALS;
|
50 | 52 | import static org.eclipse.jnosql.communication.Condition.GREATER_THAN;
|
| 53 | +import static org.eclipse.jnosql.communication.Condition.IN; |
| 54 | +import static org.eclipse.jnosql.communication.Condition.LESSER_THAN; |
51 | 55 | import static org.mockito.Mockito.any;
|
52 | 56 | import static org.mockito.Mockito.verify;
|
53 | 57 | import static org.mockito.Mockito.when;
|
@@ -127,13 +131,61 @@ void shouldAtLeast() {
|
127 | 131 | });
|
128 | 132 | }
|
129 | 133 |
|
| 134 | + @Test |
| 135 | + void shouldLesser() { |
| 136 | + |
| 137 | + when(template.select(any(SelectQuery.class))) |
| 138 | + .thenReturn(Stream.of(new Product())); |
| 139 | + |
| 140 | + repository.lesserThan(BigDecimal.TEN); |
| 141 | + ArgumentCaptor<SelectQuery> captor = ArgumentCaptor.forClass(SelectQuery.class); |
| 142 | + verify(template).select(captor.capture()); |
| 143 | + SelectQuery query = captor.getValue(); |
| 144 | + |
| 145 | + SoftAssertions.assertSoftly(softly -> { |
| 146 | + softly.assertThat(query.name()).isEqualTo("Product"); |
| 147 | + softly.assertThat(query.condition()).isPresent(); |
| 148 | + CriteriaCondition condition = query.condition().orElseThrow(); |
| 149 | + softly.assertThat(condition).isInstanceOf(CriteriaCondition.class); |
| 150 | + softly.assertThat(condition.condition()).isEqualTo(LESSER_THAN); |
| 151 | + softly.assertThat(condition.element()).isEqualTo(Element.of(_Product.PRICE, BigDecimal.TEN)); |
| 152 | + }); |
| 153 | + } |
| 154 | + |
| 155 | + @Test |
| 156 | + void shouldIn() { |
| 157 | + |
| 158 | + when(template.select(any(SelectQuery.class))) |
| 159 | + .thenReturn(Stream.of(new Product())); |
| 160 | + |
| 161 | + repository.in(List.of("Mac", "Iphone")); |
| 162 | + ArgumentCaptor<SelectQuery> captor = ArgumentCaptor.forClass(SelectQuery.class); |
| 163 | + verify(template).select(captor.capture()); |
| 164 | + SelectQuery query = captor.getValue(); |
| 165 | + |
| 166 | + SoftAssertions.assertSoftly(softly -> { |
| 167 | + softly.assertThat(query.name()).isEqualTo("Product"); |
| 168 | + softly.assertThat(query.condition()).isPresent(); |
| 169 | + CriteriaCondition condition = query.condition().orElseThrow(); |
| 170 | + softly.assertThat(condition).isInstanceOf(CriteriaCondition.class); |
| 171 | + softly.assertThat(condition.condition()).isEqualTo(IN); |
| 172 | + softly.assertThat(condition.element()).isEqualTo(Element.of(_Product.NAME, List.of("Mac", "Iphone"))); |
| 173 | + }); |
| 174 | + } |
| 175 | + |
130 | 176 |
|
131 | 177 | public interface ProductRepository extends CrudRepository<Product, String> {
|
132 | 178 | @Find
|
133 | 179 | List<Product> equals(@By(_Product.NAME) @Is String name);
|
134 | 180 |
|
135 | 181 | @Find
|
136 | 182 | List<Product> greaterThan(@By(_Product.PRICE) @Is(GreaterThan.class) BigDecimal price);
|
| 183 | + |
| 184 | + @Find |
| 185 | + List<Product> lesserThan(@By(_Product.PRICE) @Is(LessThan.class) BigDecimal price); |
| 186 | + |
| 187 | + @Find |
| 188 | + List<Product> in(@By(_Product.NAME) @Is(In.class) List<String> names); |
137 | 189 | }
|
138 | 190 |
|
139 | 191 | }
|
0 commit comments