Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCK tests for find queries using parameter names #277

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@
<configuration>
<source>17</source>
<target>17</target>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public interface AsciiCharacters extends DataRepository<AsciiCharacter, Long>, I

boolean existsByThisCharacter(char ch);

AsciiCharacter find(char thisCharacter);

Collection<AsciiCharacter> findByHexadecimalContainsAndIsControlNot(String substring, boolean isPrintable);

Stream<AsciiCharacter> findByHexadecimalIgnoreCaseBetweenAndHexadecimalNotIn(String minHex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
*/
package ee.jakarta.tck.data.framework.read.only;

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

import ee.jakarta.tck.data.framework.read.only.NaturalNumber.NumberType;
import jakarta.data.Limit;
import jakarta.data.Sort;
import jakarta.data.Streamable;
import jakarta.data.page.KeysetAwarePage;
import jakarta.data.page.Page;
import jakarta.data.page.Pageable;
import jakarta.data.repository.PageableRepository;
import jakarta.data.repository.Repository;
Expand All @@ -48,4 +52,10 @@ KeysetAwarePage<NaturalNumber> findByFloorOfSquareRootNotAndIdLessThanOrderByBit
Stream<NaturalNumber> findByNumTypeInOrderByIdAsc(Set<NumberType> types, Limit limit);

Stream<NaturalNumber> findByNumTypeOrFloorOfSquareRoot(NumberType type, long floor);

Page<NaturalNumber> findMatching(long floorOfSquareRoot, Short numBitsRequired, NumberType numType, Pageable pagination);

Optional<NaturalNumber> findNumber(long id);

List<NaturalNumber> findOdd(boolean isOdd, NumberType numType, Limit limit, Sort... sorts);
}
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,89 @@ public void testFindFirst3() {
assertEquals('T', found[2].getThisCharacter());
}

@Assertion(id = "133",
strategy = "Find a list of entities, querying by entity attributes with names that match the method parameter names," +
" with results capped by a Limit parameter and sorted according to a variable arguments Sort parameter.")
public void testFindList() {
List<NaturalNumber> oddCompositeNumbers = positives.findOdd(true, NumberType.COMPOSITE,
Limit.of(10),
Sort.asc("floorOfSquareRoot"),
Sort.desc("numBitsRequired"),
Sort.asc("id"));
assertEquals(List.of(9L, 15L, // 3 <= sqrt < 4, 4 bits
21L, // 4 <= sqrt < 5, 5 bits
33L, 35L, // 5 <= sqrt < 6, 6 bits
25L, 27L, // 5 <= sqrt < 6, 5 bits
39L, 45L, // 6 <= sqrt < 7, 6 bits
49L), // 7 <= sqrt < 8, 6 bits
oddCompositeNumbers
.stream()
.map(NaturalNumber::getId)
.collect(Collectors.toList()));

List<NaturalNumber> evenPrimeNumbers = positives.findOdd(false, NumberType.PRIME, Limit.of(9));

assertEquals(1, evenPrimeNumbers.size());
NaturalNumber num = evenPrimeNumbers.get(0);
assertEquals(2L, num.getId());
assertEquals(1L, num.getFloorOfSquareRoot());
assertEquals(Short.valueOf((short) 2), num.getNumBitsRequired());
assertEquals(NumberType.PRIME, num.getNumType());
assertEquals(false, num.isOdd());
}

@Assertion(id = "133",
strategy = "Find a single entity, querying by entity attributes with names that match the method parameter names.")
public void testFindOne() {
AsciiCharacter j = characters.find('j');

assertEquals("6a", j.getHexadecimal());
assertEquals(106L, j.getId());
assertEquals(106, j.getNumericValue());
assertEquals('j', j.getThisCharacter());
}

@Assertion(id = "133",
strategy = "Find a single entity that might or might not exist, querying by entity attributes" +
" with names that match the method parameter names.")
public void testFindOptional() {
NaturalNumber num = positives.findNumber(67L).orElseThrow();

assertEquals(67L, num.getId());
assertEquals(8L, num.getFloorOfSquareRoot());
assertEquals(Short.valueOf((short) 7), num.getNumBitsRequired());
assertEquals(NumberType.PRIME, num.getNumType());
assertEquals(true, num.isOdd());

Optional<NaturalNumber> opt = positives.findNumber(-40L);

assertEquals(false, opt.isPresent());
}

@Assertion(id = "133",
strategy = "Find a page of entities, with entity attributes identified by the parameter names and matching the parameter values.")
public void testFindPage() {
Pageable page1Request = Pageable.ofSize(7).sortBy(Sort.desc("id"));

Page<NaturalNumber> page1 = positives.findMatching(9L, Short.valueOf((short) 7), NumberType.COMPOSITE,
page1Request);

assertEquals(List.of(99L, 98L, 96L, 95L, 94L, 93L, 92L),
page1.stream().map(NaturalNumber::getId).collect(Collectors.toList()));

Page<NaturalNumber> page2 = positives.findMatching(9L, Short.valueOf((short) 7), NumberType.COMPOSITE,
page1.nextPageable());

assertEquals(List.of(91L, 90L, 88L, 87L, 86L, 85L, 84L),
page2.stream().map(NaturalNumber::getId).collect(Collectors.toList()));

Page<NaturalNumber> page3 = positives.findMatching(9L, Short.valueOf((short) 7), NumberType.COMPOSITE,
page2.nextPageable());

assertEquals(List.of(82L, 81L),
page3.stream().map(NaturalNumber::getId).collect(Collectors.toList()));
}

@Assertion(id = "133",
strategy = "Request the first KeysetAwarePage of 8 results, expecting to find all 8, " +
"then request the next KeysetAwarePage and the KeysetAwarePage after that, " +
Expand Down