Skip to content

Commit

Permalink
Issue OpenLiberty#28366 tests for multiple results of ElementCollecti…
Browse files Browse the repository at this point in the history
…on attribute
  • Loading branch information
njr-11 committed Jan 17, 2025
1 parent 749b349 commit 845b04c
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ArrayList<String>> 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<String>(List.of("X", "L", "I")),
new ArrayList<String>(List.of("X", "L", "I", "I", "I")),
new ArrayList<String>(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<ArrayList<String>> 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<String>(List.of("X", "L", "I")),
new ArrayList<String>(List.of("X", "L", "I", "I", "I")),
new ArrayList<String>(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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -433,6 +434,14 @@ Page<String> romanNumeralsWithin(long min1, long max1,
@Query("SELECT romanNumeralSymbols WHERE numberId = ?1")
Optional<Collection<String>> romanNumeralSymbolsAsCollection(long num);

@Query("SELECT romanNumeralSymbols WHERE romanNumeral LIKE ?1")
@OrderBy(ID)
List<ArrayList<String>> romanNumeralSymbolsAsListOfArrayList(String pattern);

@Query("SELECT romanNumeralSymbols WHERE romanNumeral LIKE ?1")
@OrderBy(ID)
LinkedHashSet<ArrayList<String>> romanNumeralSymbolsAsSetOfArrayList(String pattern);

@Query("SELECT hex WHERE numberId=:id")
Optional<Character> singleHexDigit(long id);

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1197,21 +1197,34 @@ public void testEmbeddableCollection() {
.sorted()
.collect(Collectors.toList()));

List<Set<AccountId>> 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<AccountId> 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<Set<AccountId>> 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<AccountId> 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)
Expand Down

0 comments on commit 845b04c

Please sign in to comment.