Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recreate test for 30444 #30595

Open
wants to merge 1 commit into
base: integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -51,4 +51,44 @@ public static City of(String name, String state, int population, Set<Integer> ar
public String toString() {
return "City of " + name + ", " + stateName + " pop " + population + " in " + areaCodes + " v" + changeCount;
}
// Getters and Setters
public Set<Integer> getAreaCodes() {
return areaCodes;
}

public void setAreaCodes(Set<Integer> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public boolean equals(Object o) {
public String getStateName() {
return stateName;
}
public String getName(){
return name;
}
ajaypaul-ibm marked this conversation as resolved.
Show resolved Hide resolved

@Override
public int hashCode() {
Expand All @@ -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;
}
ajaypaul-ibm marked this conversation as resolved.
Show resolved Hide resolved

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<City> 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")));
}
Comment on lines +887 to +917
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks fine, although a slightly different scenario and not properly indented

Suggested change
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<City> 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")));
}
deleteAllEntities(City.class);
// Set up 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<City> 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<String> 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));
}
Comment on lines +919 to +951
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks fine, although a slightly different scenario and not properly indented

Suggested change
@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<String> 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 testSelectCity_30444() throws Exception {
deleteAllEntities(City.class);
// Set up 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<String> 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<CityId> 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());
}
Comment on lines +953 to +988
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks fine, although a slightly different scenario and not properly indented. This one seems to be the closest to the failing Jakarta Data test, although still has some differences such as ordering on the population attribute rather than the name attribute which is a component of the IdClass.

Suggested change
@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<CityId> 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
//Reference issue https://github.com/OpenLiberty/open-liberty/issues/30444
public void testSelectKeys_30444() throws Exception {
deleteAllEntities(City.class);
// Set up 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<CityId> 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 {
Expand Down