From a08be1770c031f31efbecc23e06f925b07d066d1 Mon Sep 17 00:00:00 2001 From: Anija KA Date: Mon, 16 Dec 2024 10:21:41 +0530 Subject: [PATCH 1/3] Test Recreate 29893 --- .../jpa/data/tests/models/Vehicle.java | 86 +++++++++++++++++++ .../tests/web/JakartaDataRecreateServlet.java | 39 +++++++++ 2 files changed, 125 insertions(+) create mode 100644 dev/com.ibm.ws.jpa.tests.jpa_32_fat/test-applications/jakartadata/src/io/openliberty/jpa/data/tests/models/Vehicle.java diff --git a/dev/com.ibm.ws.jpa.tests.jpa_32_fat/test-applications/jakartadata/src/io/openliberty/jpa/data/tests/models/Vehicle.java b/dev/com.ibm.ws.jpa.tests.jpa_32_fat/test-applications/jakartadata/src/io/openliberty/jpa/data/tests/models/Vehicle.java new file mode 100644 index 00000000000..08441fe4534 --- /dev/null +++ b/dev/com.ibm.ws.jpa.tests.jpa_32_fat/test-applications/jakartadata/src/io/openliberty/jpa/data/tests/models/Vehicle.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2024 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 + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ + +package io.openliberty.jpa.data.tests.models; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; + +@Entity +public class Vehicle { + + @Id + private String id; // Add id field (with @Id annotation for JPA) + + private String make; + private String model; + private int numSeats; + private float price; + private String vinId; + private String color; // Add color field + + // Getters and setters for the fields + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getMake() { + return make; + } + + public void setMake(String make) { + this.make = make; + } + + public String getModel() { + return model; + } + + public void setModel(String model) { + this.model = model; + } + + public int getNumSeats() { + return numSeats; + } + + public void setNumSeats(int numSeats) { + this.numSeats = numSeats; + } + + public float getPrice() { + return price; + } + + public void setPrice(float price) { + this.price = price; + } + + public String getVinId() { + return vinId; + } + + public void setVinId(String vinId) { + this.vinId = vinId; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } +} 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 56a34ebf11f..48f84d96038 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 @@ -71,6 +71,7 @@ import io.openliberty.jpa.data.tests.models.Segment; import io.openliberty.jpa.data.tests.models.Store; import io.openliberty.jpa.data.tests.models.Triangle; +import io.openliberty.jpa.data.tests.models.Vehicle; import jakarta.annotation.Resource; import jakarta.persistence.EntityManager; import jakarta.persistence.LockModeType; @@ -1671,6 +1672,44 @@ public void testOLGH29443ZonedDateTime() throws Exception { } } + @Test + // @Ignore("Reference issue: https://github.com/OpenLiberty/open-liberty/issues/29893") + public void testOLGH29893() throws Exception { + // Prepare the test data + String vehicleId = "V1234"; // This is the ID that will be used + Vehicle vehicle = new Vehicle(); + vehicle.setId(vehicleId); + vehicle.setModel("Toyota Corolla"); + vehicle.setColor("Blue"); + + // Persist the vehicle + tx.begin(); + em.persist(vehicle); + tx.commit(); + + // Execute the query with a case-insensitive ID + String idToSearch = "v1234"; // The ID with a different case + Vehicle result; + + tx.begin(); + try { + // Corrected JPQL query + result = em.createQuery("FROM Vehicle v WHERE LOWER(v.id) = :id", Vehicle.class) + .setParameter("id", idToSearch.toLowerCase()) + .getSingleResult(); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + throw e; + } + + // Assertions + assertNotNull(result); + assertEquals(vehicleId, result.getId()); // Ensure that the correct vehicle is returned + assertEquals("Toyota Corolla", result.getModel()); // Ensure other properties are correct + assertEquals("Blue", result.getColor()); + } + @Test @Ignore("Reference issue: https://github.com/OpenLiberty/open-liberty/issues/29475") public void testOLGH29475() throws Exception { From 05e51ecec6d82e02f370e6a83f2057f856b5ca53 Mon Sep 17 00:00:00 2001 From: Anija KA Date: Tue, 17 Dec 2024 20:56:48 +0530 Subject: [PATCH 2/3] Test case for OpenLiberty issue 29893. --- .../jpa/data/tests/models/Vehicle.java | 7 +++--- .../tests/web/JakartaDataRecreateServlet.java | 23 ++++++++----------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/dev/com.ibm.ws.jpa.tests.jpa_32_fat/test-applications/jakartadata/src/io/openliberty/jpa/data/tests/models/Vehicle.java b/dev/com.ibm.ws.jpa.tests.jpa_32_fat/test-applications/jakartadata/src/io/openliberty/jpa/data/tests/models/Vehicle.java index 08441fe4534..9d58c5c69cc 100644 --- a/dev/com.ibm.ws.jpa.tests.jpa_32_fat/test-applications/jakartadata/src/io/openliberty/jpa/data/tests/models/Vehicle.java +++ b/dev/com.ibm.ws.jpa.tests.jpa_32_fat/test-applications/jakartadata/src/io/openliberty/jpa/data/tests/models/Vehicle.java @@ -17,17 +17,16 @@ public class Vehicle { @Id - private String id; // Add id field (with @Id annotation for JPA) + private String id; private String make; private String model; private int numSeats; private float price; private String vinId; - private String color; // Add color field - - // Getters and setters for the fields + private String color; + public String getId() { return id; } 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 48f84d96038..f1d3ba77c59 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 @@ -1672,41 +1672,38 @@ public void testOLGH29443ZonedDateTime() throws Exception { } } + @Test - // @Ignore("Reference issue: https://github.com/OpenLiberty/open-liberty/issues/29893") + //Reference issue: https://github.com/OpenLiberty/open-liberty/issues/29893 public void testOLGH29893() throws Exception { - // Prepare the test data - String vehicleId = "V1234"; // This is the ID that will be used + String vehicleId = "V1234"; Vehicle vehicle = new Vehicle(); vehicle.setId(vehicleId); vehicle.setModel("Toyota Corolla"); vehicle.setColor("Blue"); - // Persist the vehicle tx.begin(); em.persist(vehicle); tx.commit(); - // Execute the query with a case-insensitive ID - String idToSearch = "v1234"; // The ID with a different case + + String idToSearch = "v1234"; Vehicle result; tx.begin(); try { - // Corrected JPQL query - result = em.createQuery("FROM Vehicle v WHERE LOWER(v.id) = :id", Vehicle.class) - .setParameter("id", idToSearch.toLowerCase()) - .getSingleResult(); + result = em.createQuery("FROM Vehicle WHERE LOWER(ID(THIS)) = ?1", Vehicle.class) + .setParameter(1, idToSearch.toLowerCase()) + .getSingleResult(); tx.commit(); } catch (Exception e) { tx.rollback(); throw e; } - // Assertions assertNotNull(result); - assertEquals(vehicleId, result.getId()); // Ensure that the correct vehicle is returned - assertEquals("Toyota Corolla", result.getModel()); // Ensure other properties are correct + assertEquals(vehicleId, result.getId()); + assertEquals("Toyota Corolla", result.getModel()); assertEquals("Blue", result.getColor()); } From 0210e7fbd9526982022d15935cd6d5aa9870374c Mon Sep 17 00:00:00 2001 From: Anija KA Date: Mon, 23 Dec 2024 11:00:30 +0530 Subject: [PATCH 3/3] Test for OpenLiberty issue 29893. --- .../data/tests/web/JakartaDataRecreateServlet.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) 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 f1d3ba77c59..c53918ef752 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 @@ -1672,9 +1672,8 @@ public void testOLGH29443ZonedDateTime() throws Exception { } } - @Test - //Reference issue: https://github.com/OpenLiberty/open-liberty/issues/29893 + //Reference issue: https://github.com/OpenLiberty/open-liberty/issues/29893 public void testOLGH29893() throws Exception { String vehicleId = "V1234"; Vehicle vehicle = new Vehicle(); @@ -1686,15 +1685,13 @@ public void testOLGH29893() throws Exception { em.persist(vehicle); tx.commit(); - - String idToSearch = "v1234"; Vehicle result; tx.begin(); try { result = em.createQuery("FROM Vehicle WHERE LOWER(ID(THIS)) = ?1", Vehicle.class) - .setParameter(1, idToSearch.toLowerCase()) - .getSingleResult(); + .setParameter(1, vehicleId.toLowerCase()) + .getSingleResult(); tx.commit(); } catch (Exception e) { tx.rollback(); @@ -1702,8 +1699,8 @@ public void testOLGH29893() throws Exception { } assertNotNull(result); - assertEquals(vehicleId, result.getId()); - assertEquals("Toyota Corolla", result.getModel()); + assertEquals(vehicleId, result.getId()); + assertEquals("Toyota Corolla", result.getModel()); assertEquals("Blue", result.getColor()); }