Skip to content

Commit

Permalink
Issue jakartaee#458 TCK tests for literals in query language
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Rauh <[email protected]>
  • Loading branch information
njr-11 committed Mar 25, 2024
1 parent 2f82fe0 commit c0f6a80
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import jakarta.data.repository.By;
import jakarta.data.repository.DataRepository;
import jakarta.data.repository.Find;
import jakarta.data.repository.Query;
import jakarta.data.repository.Repository;
import jakarta.data.repository.Save;

Expand Down Expand Up @@ -70,11 +71,17 @@ Stream<AsciiCharacter> findByHexadecimalIgnoreCaseBetweenAndHexadecimalNotIn(Str

Optional<AsciiCharacter> findFirstByHexadecimalStartsWithAndIsControlOrderByIdAsc(String firstHexDigit, boolean isControlChar);

@Query("WHERE hexadecimal <> ' ORDER BY isn''t a keyword when inside a literal' AND hexadecimal IN ('4a', '4b', '4c', ?1)")
Stream<AsciiCharacter> jklOr(String hex);

default Stream<AsciiCharacter> retrieveAlphaNumericIn(long minId, long maxId) {
return findByIdBetween(minId, maxId, Sort.asc("id"))
.filter(c -> Character.isLetterOrDigit(c.getThisCharacter()));
}

@Save
Iterable<AsciiCharacter> saveAll(Iterable<AsciiCharacter> characters);

@Query("SELECT COUNT(THIS) WHERE numericValue <= 97 AND numericValue >= 74")
int twentyFour();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package ee.jakarta.tck.data.framework.read.only;

import java.util.Optional;
import java.util.stream.Stream;

import jakarta.data.Limit;
Expand All @@ -23,6 +24,7 @@
import jakarta.data.page.Page;
import jakarta.data.page.PageRequest;
import jakarta.data.repository.BasicRepository;
import jakarta.data.repository.Query;
import jakarta.data.repository.Repository;

import ee.jakarta.tck.data.framework.read.only.NaturalNumber.NumberType;
Expand Down Expand Up @@ -58,4 +60,9 @@ Page<NaturalNumber> findByNumTypeAndFloorOfSquareRootLessThanEqual(NumberType ty
long maxSqrtFloor,
PageRequest<NaturalNumber> pagination);

@Query("SELECT id WHERE isOdd = true AND id BETWEEN 21 AND ?1 ORDER BY id ASC")
Page<Long> oddsFrom21To(long max, PageRequest<NaturalNumber> pageRequest);

@Query("WHERE isOdd = false AND numType = ee.jakarta.tck.data.framework.read.only.NaturalNumber.NumberType.PRIME")
Optional<NaturalNumber> two();
}
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,54 @@ public void testLimitToOneResult() {
assertEquals(false, it.hasNext());
}

@Assertion(id = "458", strategy = "Use a repository method with a JDQL Query that specifies an enum literal and a boolean false literal.")
public void testLiteralEnumAndLiteralFalse() {

NaturalNumber two = numbers.two().orElseThrow();

assertEquals(2L, two.getId());
assertEquals(NumberType.PRIME, two.getNumType());
assertEquals(Short.valueOf((short) 2), two.getNumBitsRequired());
}

@Assertion(id = "458", strategy = "Use a repository method with a JDQL Query that specifies literal Integer values.")
public void testLiteralInteger() {

assertEquals(24, characters.twentyFour());
}

@Assertion(id = "458", strategy = "Use a repository method with a JDQL Query that specifies literal String values.")
public void testLiteralString() {

assertEquals(List.of('J', 'K', 'L', 'M'),
characters.jklOr("4d")
.map(AsciiCharacter::getThisCharacter)
.sorted()
.collect(Collectors.toList()));
}

@Assertion(id = "458", strategy = "Use a repository method with a JDQL Query that specifies a boolean true literal.")
public void testLiteralTrue() {
Page<Long> page1 = numbers.oddsFrom21To(40L, PageRequest.ofSize(5));

assertEquals(10L, page1.totalElements());
assertEquals(2L, page1.totalPages());

assertEquals(List.of(21L, 23L, 25L, 27L, 29L), page1.content());

assertEquals(true, page1.hasNext());

Page<Long> page2 = numbers.oddsFrom21To(40L, page1.nextPageRequest(NaturalNumber.class));

assertEquals(List.of(31L, 33L, 35L, 37L, 39L), page2.content());

if (page2.hasNext()) {
Page<Long> page3 = numbers.oddsFrom21To(40L, page2.nextPageRequest(NaturalNumber.class));
assertEquals(false, page3.hasContent());
assertEquals(false, page3.hasNext());
}
}

@Assertion(id = "133",
strategy = "Use a repository method with two Sort parameters specifying a mixture of ascending and descending order, " +
"and verify all results are returned and are ordered according to the sort criteria.")
Expand Down

0 comments on commit c0f6a80

Please sign in to comment.