From a82ab4dd5d83e9e015b3b8c78c7a4459e09906aa Mon Sep 17 00:00:00 2001 From: Ajay Paul Date: Tue, 21 Jan 2025 15:06:55 +0530 Subject: [PATCH] Recreate test for 30444 --- .../jpa/data/tests/models/City.java | 40 +++++++ .../jpa/data/tests/models/CityId.java | 6 + .../tests/web/JakartaDataRecreateServlet.java | 105 ++++++++++++++++++ 3 files changed, 151 insertions(+) diff --git a/dev/com.ibm.ws.jpa.tests.jpa_32_fat/test-applications/jakartadata/src/io/openliberty/jpa/data/tests/models/City.java b/dev/com.ibm.ws.jpa.tests.jpa_32_fat/test-applications/jakartadata/src/io/openliberty/jpa/data/tests/models/City.java index 180eb27b175f..a105f81b73d6 100644 --- a/dev/com.ibm.ws.jpa.tests.jpa_32_fat/test-applications/jakartadata/src/io/openliberty/jpa/data/tests/models/City.java +++ b/dev/com.ibm.ws.jpa.tests.jpa_32_fat/test-applications/jakartadata/src/io/openliberty/jpa/data/tests/models/City.java @@ -51,4 +51,44 @@ public static City of(String name, String state, int population, Set ar public String toString() { return "City of " + name + ", " + stateName + " pop " + population + " in " + areaCodes + " v" + changeCount; } + // Getters and Setters + public Set getAreaCodes() { + return areaCodes; + } + + public void setAreaCodes(Set areaCodes) { + this.areaCodes = areaCodes; + } + + public long getChangeCount() { + return changeCount; + } + + public void setChangeCount(long changeCount) { + this.changeCount = changeCount; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getPopulation() { + return population; + } + + public void setPopulation(int population) { + this.population = population; + } + + public String getStateName() { + return stateName; + } + + public void setStateName(String stateName) { + this.stateName = stateName; + } } diff --git a/dev/com.ibm.ws.jpa.tests.jpa_32_fat/test-applications/jakartadata/src/io/openliberty/jpa/data/tests/models/CityId.java b/dev/com.ibm.ws.jpa.tests.jpa_32_fat/test-applications/jakartadata/src/io/openliberty/jpa/data/tests/models/CityId.java index 4ecca16cdbb8..ee9e24640ff0 100644 --- a/dev/com.ibm.ws.jpa.tests.jpa_32_fat/test-applications/jakartadata/src/io/openliberty/jpa/data/tests/models/CityId.java +++ b/dev/com.ibm.ws.jpa.tests.jpa_32_fat/test-applications/jakartadata/src/io/openliberty/jpa/data/tests/models/CityId.java @@ -41,6 +41,9 @@ public boolean equals(Object o) { public String getStateName() { return stateName; } + public String getName(){ + return name; + } @Override public int hashCode() { @@ -54,6 +57,9 @@ public static CityId of(String name, String state) { public void setStateName(String v) { stateName = v; } + public void setName(String n){ + name = n; + } @Override public String toString() { diff --git a/dev/com.ibm.ws.jpa.tests.jpa_32_fat/test-applications/jakartadata/src/io/openliberty/jpa/data/tests/web/JakartaDataRecreateServlet.java b/dev/com.ibm.ws.jpa.tests.jpa_32_fat/test-applications/jakartadata/src/io/openliberty/jpa/data/tests/web/JakartaDataRecreateServlet.java index 2bf01916d2e1..4998f42f6725 100644 --- a/dev/com.ibm.ws.jpa.tests.jpa_32_fat/test-applications/jakartadata/src/io/openliberty/jpa/data/tests/web/JakartaDataRecreateServlet.java +++ b/dev/com.ibm.ws.jpa.tests.jpa_32_fat/test-applications/jakartadata/src/io/openliberty/jpa/data/tests/web/JakartaDataRecreateServlet.java @@ -881,6 +881,111 @@ public void testOLGH29073() throws Exception { assertEquals("Minnesota", rochesters.get(1).getStateName()); } + @Test + //Reference issue https://github.com/OpenLiberty/open-liberty/issues/30444 + public void testSelectAll_30444() throws Exception { + deleteAllEntities(City.class); + // Setup test data + City city1 = City.of("Prague", "Bohemia", 121878,Set.of(55901, 55902, 55903, 55904, 55906)); + City city2 = City.of("Brno", "Moravia", 209352,Set.of(14601, 14602, 14603, 14604, 14606)); + City city3 = City.of("Ostrava", "Silesia", 23456,Set.of(55906, 55907, 55908, 14604, 55902)); + + // Persist the cities + tx.begin(); + em.persist(city1); + em.persist(city2); + em.persist(city3); + tx.commit(); + + // Execute the JPQL query + List results; + tx.begin(); + try { + results = em.createQuery("SELECT c FROM City c", City.class) + .getResultList(); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + throw e; + } + + // Verify the results + assertEquals(3, results.size()); + assertTrue(results.stream().anyMatch(c -> c.getName().equals("Prague"))); + assertTrue(results.stream().anyMatch(c -> c.getName().equals("Brno"))); + assertTrue(results.stream().anyMatch(c -> c.getName().equals("Ostrava"))); +} + + @Test + //Reference issue https://github.com/OpenLiberty/open-liberty/issues/30444 + public void testSelectCity_30444() throws Exception { + deleteAllEntities(City.class); + // Setup test data + City city1 = City.of("Prague", "Bohemia", 1384732, Set.of(55901, 55902, 55903, 55904, 55906)); + City city2 = City.of("Brno", "Moravia", 209352, Set.of(14601, 14602, 14603, 14604, 14606)); + City city3 = City.of("Ostrava", "Silesia", 23456,Set.of(55906, 55907, 55908, 14604, 55902)); + + // Persist the cities + tx.begin(); + em.persist(city1); + em.persist(city2); + em.persist(city3); + tx.commit(); + + // Execute the JPQL query + List results; + tx.begin(); + try { + results = em.createQuery("SELECT name FROM City WHERE name = :name ORDER BY population DESC", String.class) + .setParameter("name", "Prague") + .getResultList(); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + throw e; + } + + // Verify the results + assertEquals(1, results.size()); + assertEquals("Prague", results.get(0)); +} + + @Test + //Reference issue https://github.com/OpenLiberty/open-liberty/issues/30444 + public void testSelectKeys_30444() throws Exception { + deleteAllEntities(City.class); + // Setup test data + City city1 = City.of("Prague", "Bohemia", 1384732, Set.of(55901, 55902, 55903, 55904, 55906)); + City city2 = City.of("Brno", "Moravia", 209352, Set.of(14601, 14602, 14603, 14604, 14606)); + City city3 = City.of("Ostrava", "Silesia", 23456,Set.of(55906, 55907, 55908, 14604, 55902)); + + // Persist the cities + tx.begin(); + em.persist(city1); + em.persist(city2); + em.persist(city3); + tx.commit(); + + // Execute the JPQL query + List results; + tx.begin(); + try { + results = em.createQuery( + "SELECT new io.openliberty.jpa.data.tests.models.CityId(c.name, c.stateName) FROM City c WHERE c.stateName = :stateName ORDER BY c.population DESC", + CityId.class) + .setParameter("stateName", "Bohemia") + .getResultList(); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + throw e; + } + + // Verify the results + assertEquals(1, results.size()); + assertEquals("Prague", results.get(0).getName()); + assertEquals("Bohemia", results.get(0).getStateName()); +} @Test @SkipIfSysProp(DB_Postgres) //Reference issue: https://github.com/OpenLiberty/open-liberty/issues/28368 public void testOLGH28368() throws Exception {