From 845b04ce80b2b26fc37bddac87c55e05fadb307a Mon Sep 17 00:00:00 2001 From: Nathan Rauh Date: Fri, 17 Jan 2025 11:35:44 -0600 Subject: [PATCH] Issue #28366 tests for multiple results of ElementCollection attribute --- .../fat/src/test/jakarta/data/DataTest.java | 8 +++- .../jakarta/data/web/DataTestServlet.java | 47 +++++++++++++++++++ .../src/test/jakarta/data/web/Primes.java | 9 ++++ .../test/jakarta/data/jpa/DataJPATest.java | 7 ++- .../data/jpa/web/DataJPATestServlet.java | 43 +++++++++++------ 5 files changed, 95 insertions(+), 19 deletions(-) diff --git a/dev/io.openliberty.data.internal_fat/fat/src/test/jakarta/data/DataTest.java b/dev/io.openliberty.data.internal_fat/fat/src/test/jakarta/data/DataTest.java index 0fedde060532..ff313b28f60b 100644 --- a/dev/io.openliberty.data.internal_fat/fat/src/test/jakarta/data/DataTest.java +++ b/dev/io.openliberty.data.internal_fat/fat/src/test/jakarta/data/DataTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2022, 2024 IBM Corporation and others. + * Copyright (c) 2022, 2025 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -63,7 +63,11 @@ public class DataTest extends FATServletClient { "CWWKD1054E.*findAsLongBetween", "CWWKD1054E.*findByNumberIdBetween", "CWWKD1075E.*Apartment2", - "CWWKD1075E.*Apartment3" + "CWWKD1075E.*Apartment3", + // work around to prevent bad behavior from EclipseLink (see #30575) + "CWWKD1103E.*romanNumeralSymbolsAsListOfArrayList", + // work around to prevent bad behavior from EclipseLink (see #30575) + "CWWKD1103E.*romanNumeralSymbolsAsSetOfArrayList" }; @ClassRule diff --git a/dev/io.openliberty.data.internal_fat/test-applications/DataTestApp/src/test/jakarta/data/web/DataTestServlet.java b/dev/io.openliberty.data.internal_fat/test-applications/DataTestApp/src/test/jakarta/data/web/DataTestServlet.java index 323ea31f8709..4c0d6fd6a7b4 100644 --- a/dev/io.openliberty.data.internal_fat/test-applications/DataTestApp/src/test/jakarta/data/web/DataTestServlet.java +++ b/dev/io.openliberty.data.internal_fat/test-applications/DataTestApp/src/test/jakarta/data/web/DataTestServlet.java @@ -36,6 +36,7 @@ import java.util.Deque; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -4383,6 +4384,52 @@ public void testQueryReturnsArrayListAttributeAsCollection() { primes.romanNumeralSymbolsAsCollection(37).orElseThrow()); } + /** + * Repository Query method that selects and returns a multiple results of an + * ArrayList attribute + */ + @Test + public void testQueryReturnsArrayListAttributeAsListOfArrayList() { + List> results; + try { + results = primes.romanNumeralSymbolsAsListOfArrayList("XL%"); + } catch (UnsupportedOperationException x) { + if (x.getMessage().startsWith("CWWKD1103E")) + // work around for bad behavior from EclipseLink when selecting + // ElementCollection attributes (see #30575) + return; + else + throw x; + } + assertEquals(List.of(new ArrayList(List.of("X", "L", "I")), + new ArrayList(List.of("X", "L", "I", "I", "I")), + new ArrayList(List.of("X", "L", "V", "I", "I"))), + results); + } + + /** + * Repository Query method that selects and returns a multiple results of an + * ArrayList attribute as a Set. + */ + @Test + public void testQueryReturnsArrayListAttributeAsSetOfArrayList() { + LinkedHashSet> results; + try { + results = primes.romanNumeralSymbolsAsSetOfArrayList("XL%"); + } catch (UnsupportedOperationException x) { + if (x.getMessage().startsWith("CWWKD1103E")) + // work around for bad behavior from EclipseLink when selecting + // ElementCollection attributes (see #30575) + return; + else + throw x; + } + assertEquals(Set.of(new ArrayList(List.of("X", "L", "I")), + new ArrayList(List.of("X", "L", "I", "I", "I")), + new ArrayList(List.of("X", "L", "V", "I", "I"))), + results); + } + /** * Use a Repository method that has the Query annotation and has a return type * that uses a Java record indicating to select a subset of entity attributes. diff --git a/dev/io.openliberty.data.internal_fat/test-applications/DataTestApp/src/test/jakarta/data/web/Primes.java b/dev/io.openliberty.data.internal_fat/test-applications/DataTestApp/src/test/jakarta/data/web/Primes.java index 738cf3679734..6afadb9a2c21 100644 --- a/dev/io.openliberty.data.internal_fat/test-applications/DataTestApp/src/test/jakarta/data/web/Primes.java +++ b/dev/io.openliberty.data.internal_fat/test-applications/DataTestApp/src/test/jakarta/data/web/Primes.java @@ -20,6 +20,7 @@ import java.util.Collection; import java.util.Deque; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Optional; @@ -433,6 +434,14 @@ Page romanNumeralsWithin(long min1, long max1, @Query("SELECT romanNumeralSymbols WHERE numberId = ?1") Optional> romanNumeralSymbolsAsCollection(long num); + @Query("SELECT romanNumeralSymbols WHERE romanNumeral LIKE ?1") + @OrderBy(ID) + List> romanNumeralSymbolsAsListOfArrayList(String pattern); + + @Query("SELECT romanNumeralSymbols WHERE romanNumeral LIKE ?1") + @OrderBy(ID) + LinkedHashSet> romanNumeralSymbolsAsSetOfArrayList(String pattern); + @Query("SELECT hex WHERE numberId=:id") Optional singleHexDigit(long id); diff --git a/dev/io.openliberty.data.internal_fat_jpa/fat/src/test/jakarta/data/jpa/DataJPATest.java b/dev/io.openliberty.data.internal_fat_jpa/fat/src/test/jakarta/data/jpa/DataJPATest.java index a40c2ec5c268..22bc3294f250 100644 --- a/dev/io.openliberty.data.internal_fat_jpa/fat/src/test/jakarta/data/jpa/DataJPATest.java +++ b/dev/io.openliberty.data.internal_fat_jpa/fat/src/test/jakarta/data/jpa/DataJPATest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2022, 2024 IBM Corporation and others. + * Copyright (c) 2022, 2025 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -54,7 +54,10 @@ public class DataJPATest extends FATServletClient { "CWWKD1054E.*findByIsControlTrueAndNumericValueBetween", "CWWKD1075E.*Apartment2", "CWWKD1075E.*Apartment3", - "CWWKD1091E.*countBySurgePriceGreaterThanEqual" + "CWWKD1091E.*countBySurgePriceGreaterThanEqual", + // work around to prevent bad behavior from EclipseLink (see #30575) + "CWWKD1103E.*findBankAccountsByFilingStatus" + }; @ClassRule diff --git a/dev/io.openliberty.data.internal_fat_jpa/test-applications/DataJPATestApp/src/test/jakarta/data/jpa/web/DataJPATestServlet.java b/dev/io.openliberty.data.internal_fat_jpa/test-applications/DataJPATestApp/src/test/jakarta/data/jpa/web/DataJPATestServlet.java index 746ed180d9b7..ca93b668c3a2 100644 --- a/dev/io.openliberty.data.internal_fat_jpa/test-applications/DataJPATestApp/src/test/jakarta/data/jpa/web/DataJPATestServlet.java +++ b/dev/io.openliberty.data.internal_fat_jpa/test-applications/DataJPATestApp/src/test/jakarta/data/jpa/web/DataJPATestServlet.java @@ -1197,21 +1197,34 @@ public void testEmbeddableCollection() { .sorted() .collect(Collectors.toList())); - List> list = taxpayers.findBankAccountsByFilingStatus(TaxPayer.FilingStatus.HeadOfHousehold); - // TODO EclipseLink bug where - // SELECT o.bankAccounts FROM TaxPayer o WHERE (o.filingStatus=?1) ORDER BY o.numDependents, o.ssn - // combines the two Set values that ought to be the result into a single combined list of AccountId. - //assertEquals(list.toString(), 2, list.size()); - //assertEquals(Set.of("AccountId:43014400:410224"), - // list.get(0) - // .stream() - // .map(AccountId::toString) - // .collect(Collectors.toSet())); - //assertEquals(Set.of("AccountId:10105600:560237", "AccountId:15561600:391588"), - // list.get(1) - // .stream() - // .map(AccountId::toString) - // .collect(Collectors.toSet())); + List> list; + try { + list = taxpayers.findBankAccountsByFilingStatus(TaxPayer.FilingStatus.HeadOfHousehold); + assertEquals(list.toString(), 2, list.size()); + assertEquals(Set.of("AccountId:43014400:410224"), + list.get(0) + .stream() + .map(AccountId::toString) + .collect(Collectors.toSet())); + assertEquals(Set.of("AccountId:10105600:560237", + "AccountId:15561600:391588"), + list.get(1) + .stream() + .map(AccountId::toString) + .collect(Collectors.toSet())); + } catch (UnsupportedOperationException x) { + if (x.getMessage() != null && + x.getMessage().startsWith("CWWKD1103E:")) + // Works around bad behavior from EclipseLink (see #30575) + // for ElementCollection: + // SELECT o.bankAccounts FROM TaxPayer o WHERE (o.filingStatus=?1) + // ORDER BY o.numDependents, o.ssn + // combines the two Set values that ought to be the result + // into a single combined list of AccountId. + ; + else + throw x; + } // TODO report EclipseLink bug that occurs on the following if (false)