Skip to content

Commit

Permalink
Issue 1815: Add testing
Browse files Browse the repository at this point in the history
Signed-off-by: Will Dazey <[email protected]>
  • Loading branch information
dazey3 committed Mar 23, 2023
1 parent cde4f28 commit fcf5fbf
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2023 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

// Contributors:
package org.eclipse.persistence.jpa.test.collection;

import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Query;

import java.util.Set;

import org.eclipse.persistence.jpa.test.framework.DDLGen;
import org.eclipse.persistence.jpa.test.framework.Emf;
import org.eclipse.persistence.jpa.test.framework.EmfRunner;
import org.eclipse.persistence.jpa.test.framework.Property;
import org.eclipse.persistence.jpa.test.collection.model.CityEntity;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(EmfRunner.class)
public class TestBasicCollection {

@Emf(createTables = DDLGen.DROP_CREATE,
classes = { CityEntity.class },
properties = { @Property(name = "eclipselink.logging.level", value = "ALL"),
@Property(name = "eclipselink.logging.level.sql", value = "FINE"),
@Property(name = "eclipselink.logging.parameters", value = "true")})
private EntityManagerFactory emf;

@Test
public void testUpdateBasicCollectionWithQuery() {
EntityManager em = emf.createEntityManager();
try {
em.getTransaction().begin();
em.persist(new CityEntity("Minneapolis", Set.of(608)));
em.getTransaction().commit();
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
if(em.isOpen()) {
em.close();
}
}

em = emf.createEntityManager();
try {
em.getTransaction().begin();
Query q = em.createQuery("UPDATE City o SET o.areaCodes=?1 WHERE o.name=?2");
q.setParameter(1, Set.of(563));
q.setParameter(2, "Minneapolis");
q.executeUpdate();
em.getTransaction().commit();
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
if(em.isOpen()) {
em.close();
}
}

em = emf.createEntityManager();
try {
em.getTransaction().begin();
CityEntity find2 = em.find(CityEntity.class, "Minneapolis");
em.getTransaction().commit();
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
if(em.isOpen()) {
em.close();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2023 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

// Contributors:
package org.eclipse.persistence.jpa.test.collection.model;

import java.util.Collections;
import java.util.Set;

import jakarta.persistence.CollectionTable;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;

@Entity
public class CityEntity {

@Id
public String name;

public Set<Integer> areaCodes;

public CityEntity() {}

public CityEntity(String name, Set<Integer> areaCodes) {
this.name = name;
this.areaCodes = areaCodes;
}
}

0 comments on commit fcf5fbf

Please sign in to comment.