Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ List<Country> asLargeOrBigger(
List<Country> byCountryCodes(
@By(_Country.CODE) @Is(In.class) Collection<String> codes);

@Find
List<Country> byCountryCodeUpTo(
@By(_Country.CODE) @Is(AtMost.class) String maxCode,
Order<Country> ordering);

long count();

@Find
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation
* Copyright (c) 2025,2026 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -28,9 +28,9 @@ public interface _City {
String NAME = "name";
String POPULATION = "population";

TextAttribute<Country> name = //
TextAttribute.of(Country.class, NAME);
TextAttribute<City> name = //
TextAttribute.of(City.class, NAME);

NumericAttribute<Country, Integer> poulation = //
NumericAttribute.of(Country.class, POPULATION, int.class);
NumericAttribute<City, Integer> population = //
NumericAttribute.of(City.class, POPULATION, int.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.function.Function;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.function.Function;
import java.util.logging.Logger;

import org.jboss.arquillian.container.test.api.Deployment;
Expand All @@ -35,14 +35,21 @@
import ee.jakarta.tck.data.framework.read.only.Countries;
import ee.jakarta.tck.data.framework.read.only.Country;
import ee.jakarta.tck.data.framework.read.only.CountryPopulator;
import ee.jakarta.tck.data.framework.read.only._City;
import ee.jakarta.tck.data.framework.read.only._Country;
import ee.jakarta.tck.data.framework.utilities.DatabaseType;
import ee.jakarta.tck.data.framework.utilities.TestProperty;
import jakarta.data.Order;
import jakarta.data.Sort;
import jakarta.data.constraint.AtLeast;
import jakarta.data.repository.By;
import jakarta.data.repository.Find;
import jakarta.data.repository.Is;
import jakarta.inject.Inject;

/**
* Tests for various Expressions used within Restrictions that are
* supplied to Repository methods.
* Tests for various Expressions used within Restrictions and Sorts
* that are supplied to Repository methods.
*/
@AnyEntity
@ReadOnlyTest
Expand Down Expand Up @@ -443,6 +450,167 @@ public void testRight3() {
.toList());
}

@Assertion(id = "829", strategy = """
Supply multiple expressions by which to sort.
""")
public void testSortByMultipleExpressions() {
Sort<Country> secondCharAsc = _Country.code.right(1).asc();
Sort<Country> firstCharDesc = _Country.code.left(1).desc();

List<Country> found;
try {
found = countries.byCountryCodeUpTo("CZ",
Order.by(secondCharAsc,
firstCharDesc));
} catch (UnsupportedOperationException x) {
if (type.capableOfLeft() &&
type.capableOfLessThanEqual() &&
type.capableOfMultipleSort() &&
type.capableOfRight()) {
throw x;
} else {
return;
}
}

assertEquals(List.of("CA: Canada",
"BA: Bosnia and Herzegovina",
"BB: Barbados",
"CD: Congo",
"BD: Bangladesh",
"AD: Andorra",
"BE: Belgium",
"AE: United Arab Emirates",
"CF: Central African Republic",
"BF: Burkina Faso",
"AF: Afghanistan",
"BG: Bulgaria",
"AG: Antigua and Barbuda",
"CH: Switzerland",
"BH: Bahrain",
"CI: Ivory Coast",
"BI: Burundi",
"BJ: Benin",
"CL: Chile",
"AL: Albania",
"CM: Cameroon",
"BM: Bermuda",
"AM: Armenia",
"CN: China",
"BN: Brunei",
"CO: Colombia",
"BO: Bolivia",
"AO: Angola",
"CR: Costa Rica",
"BR: Brazil",
"AR: Argentina",
"BS: Bahamas",
"AS: American Samoa",
"BT: Bhutan",
"AT: Austria",
"CU: Cuba",
"AU: Australia",
"CV: Cape Verde",
"BW: Botswana",
"AW: Aruba",
"CY: Cyprus",
"BY: Belarus",
"CZ: Czech Republic",
"BZ: Belize",
"AZ: Azerbaijan"),
found.stream()
.map(c -> c.getCode() + ": " + c.getName())
.toList());
}

@Assertion(id = "829", strategy = """
Sort based on a navigable expression.
""")
public void testSortByNavigableExpression() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about use: shouldBe...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about use: shouldBe...

I'd rather not change just this one test. Hundreds of other tests in the TCK all start with test, including all of the other test methods within this class.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we decide to rename tests from test* to shouldBe*, let's do that in a separate PR that can cover all occurrences.


Sort<Country> capitalNameAsc = //
_Country.capital.navigate(_City.name).asc();

List<Country> found;
try {
found = countries.findLargest(100000000L,
Order.by(capitalNameAsc));
} catch (UnsupportedOperationException x) {
if (type.capableOfConstraintsOnNonIdAttributes() &&
type.capableOfGreaterThanEqual() &&
type.capableOfSingleSort()) {
throw x;
} else {
return;
}
}

assertEquals(List.of("Abuja, Nigeria",
"Addis Ababa, Ethiopia",
"Beijing, China",
"Brasilia, Brazil",
"Brazzaville, Congo",
"Cairo, Egypt",
"Dhaka, Bangladesh",
"Hanoi, Vietnam",
"Islamabad, Pakistan",
"Jakarta, Indonesia",
"Manila, Philippines",
"Mexico City, Mexico",
"Moscow, Russia",
"New Delhi, India",
"Tokyo, Japan",
"Washington, D.C., United States of America"),
found.stream()
.map(c -> c.getCapital().getName() + ", " + c.getName())
.toList());
}

@Assertion(id = "829", strategy = """
Supply a single expression by which to sort.
""")
public void testSortBySingleExpression() {

Sort<Country> populationDensityDesc = //
_Country.population.dividedBy(_Country.area).desc();

List<Country> found;
try {
found = countries.findLargest(100000000L,
Order.by(populationDensityDesc));
} catch (UnsupportedOperationException x) {
if (type.capableOfConstraintsOnNonIdAttributes() &&
type.capableOfDivision() &&
type.capableOfGreaterThanEqual() &&
type.capableOfSingleSort()) {
throw x;
} else {
return;
}
}

assertEquals(List.of("Bangladesh: 1307",
"India: 477",
"Philippines: 402",
"Vietnam: 344",
"Japan: 336",
"Pakistan: 333",
"Nigeria: 266",
"Indonesia: 156",
"China: 150",
"Egypt: 113",
"Ethiopia: 110",
"Mexico: 67",
"Congo: 52",
"United States of America: 36",
"Brazil: 26",
"Russia: 8"),
found.stream()
.map(c -> c.getName() + ": " +
(c.getPopulation() / c.getArea()))
.toList());
}

@Assertion(id = "829", strategy = """
Use the upper TextExpression to consider characters of a
String attribute as upper case when compared to a value.
Expand Down
Loading