|
19 | 19 | import com.querydsl.core.DefaultQueryMetadata; |
20 | 20 | import com.querydsl.core.JoinType; |
21 | 21 | import com.querydsl.core.QueryMetadata; |
22 | | -import com.querydsl.core.domain.QAnimal; |
23 | 22 | import com.querydsl.core.domain.QCat; |
24 | 23 | import com.querydsl.core.types.EntityPath; |
25 | 24 | import com.querydsl.core.types.Expression; |
26 | 25 | import com.querydsl.core.types.Path; |
27 | 26 | import com.querydsl.core.types.Predicate; |
28 | | -import com.querydsl.core.types.dsl.EntityPathBase; |
29 | | -import com.querydsl.core.types.dsl.Expressions; |
30 | | -import com.querydsl.core.types.dsl.NumberPath; |
31 | | -import com.querydsl.jpa.domain.JobFunction; |
32 | | -import com.querydsl.jpa.domain.Location; |
33 | | -import com.querydsl.jpa.domain.QDomesticCat; |
34 | | -import com.querydsl.jpa.domain.QEmployee; |
| 27 | +import com.querydsl.core.types.dsl.*; |
| 28 | +import com.querydsl.jpa.domain.*; |
35 | 29 | import java.util.Arrays; |
36 | 30 | import org.junit.Test; |
37 | 31 |
|
@@ -337,18 +331,55 @@ public void visitLiteral_string() { |
337 | 331 | assertThat(serializer).hasToString("'abc''''def'"); |
338 | 332 | } |
339 | 333 |
|
340 | | - @Test |
341 | | - public void visitLiteral_enum() { |
342 | | - var serializer = new JPQLSerializer(HQLTemplates.DEFAULT); |
343 | | - serializer.visitLiteral(JobFunction.MANAGER); |
344 | | - assertThat(serializer).hasToString("com.querydsl.jpa.domain.JobFunction.MANAGER"); |
345 | | - } |
346 | | - |
347 | 334 | @Test |
348 | 335 | public void substring_indexOf() { |
349 | 336 | var cat = QCat.cat; |
350 | 337 | var serializer = new JPQLSerializer(HQLTemplates.DEFAULT); |
351 | 338 | cat.name.substring(cat.name.indexOf("")).accept(serializer, null); |
352 | 339 | assertThat(serializer).hasToString("substring(cat.name,locate(?1,cat.name)-1 + ?2)"); |
353 | 340 | } |
| 341 | + |
| 342 | + @Test |
| 343 | + public void case_enumConversion() { |
| 344 | + var serializer = new JPQLSerializer(JPQLTemplates.DEFAULT); |
| 345 | + |
| 346 | + Expression<?> expr = |
| 347 | + new CaseBuilder() |
| 348 | + .when(Expressions.TRUE) |
| 349 | + .then(JobFunction.MANAGER) |
| 350 | + .otherwise(JobFunction.CONSULTANT); |
| 351 | + |
| 352 | + serializer.handle(expr); |
| 353 | + |
| 354 | + assertThat(serializer.toString()) |
| 355 | + .isEqualTo("case when true then 'MANAGER' else 'CONSULTANT' end"); |
| 356 | + } |
| 357 | + |
| 358 | + @Test |
| 359 | + public void where_enumComparison_color() { |
| 360 | + QAnimal animal = QAnimal.animal; |
| 361 | + Expression<?> predicate = animal.color.eq(Color.BLACK); |
| 362 | + JPQLSerializer serializer = new JPQLSerializer(JPQLTemplates.DEFAULT); |
| 363 | + serializer.handle(predicate); |
| 364 | + assertThat(serializer.toString()).isEqualTo("animal.color = 'BLACK'"); |
| 365 | + } |
| 366 | + |
| 367 | + @Test |
| 368 | + public void select_enumConstant() { |
| 369 | + Expression<?> projection = Expressions.constant(Color.BLACK); |
| 370 | + JPQLSerializer serializer = new JPQLSerializer(JPQLTemplates.DEFAULT); |
| 371 | + serializer.handle(projection); |
| 372 | + assertThat(serializer.toString()).isEqualTo("'BLACK'"); |
| 373 | + } |
| 374 | + |
| 375 | + @Test |
| 376 | + public void inClause_enumCollection() { |
| 377 | + QAnimal animal = QAnimal.animal; |
| 378 | + Expression<?> predicate = animal.color.in(Arrays.asList(Color.BLACK, Color.TABBY)); |
| 379 | + JPQLSerializer serializer = new JPQLSerializer(JPQLTemplates.DEFAULT); |
| 380 | + serializer.handle(predicate); |
| 381 | + assertThat(serializer.toString()).isEqualTo("animal.color in ?1"); |
| 382 | + Object constant = serializer.getConstants().get(0); |
| 383 | + assertThat(constant.toString()).isEqualTo("[BLACK, TABBY]"); |
| 384 | + } |
354 | 385 | } |
0 commit comments