blob: 64b380619d19d7ce55b61836f62f76d365ba9944 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2010-2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* dclarke - EclipseLink 2.3 - MySports Demo Bug 344608
******************************************************************************/
package eclipselink.example.mysports.admin.test;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.junit.Assert;
import org.eclipse.persistence.jpa.JpaHelper;
import org.eclipse.persistence.sessions.server.Server;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import eclipselink.example.mysports.admin.model.DataIsolation;
import eclipselink.example.mysports.admin.model.HostedLeague;
/**
* Create initial league entities.
*
* @author dclarke
* @since EclipseLink 2.3.0
*/
public class CreateLeagues {
private static EntityManagerFactory emf;
@Test
public void verifySession() {
Assert.assertNotNull(emf);
Server session = JpaHelper.getServerSession(emf);
Assert.assertNotNull(session);
Assert.assertTrue(session.isServerSession());
}
@Test
public void createLeagues() {
EntityManager em = emf.createEntityManager();
try {
em.getTransaction().begin();
HostedLeague osl = new HostedLeague("OSL", "Ottawa Soccer League", "black");
osl.setLogoUrl("/logos/osl.png");
osl.setDatasourceName("jdbc/MySportsMHL");
osl.addPlayerExtension("allergies", "java.lang.String", "flex_1");
em.persist(osl);
HostedLeague hthl = new HostedLeague("HTHL", "High Tech Hockey League", "red");
hthl.setLogoUrl("/logos/hthl.png");
hthl.setDatasourceName("jdbc/MySports");
hthl.addPlayerExtension("penaltyMinutes", "java.lang.Integer", "flex_1");
hthl.addPlayerExtension("position", "java.lang.String", "flex_2");
em.persist(hthl);
HostedLeague kfl = new HostedLeague("KFL", "Kid's Football League", "green");
kfl.setLogoUrl("/logos/kfl.png");
kfl.setDatasourceName("jdbc/MySports");
kfl.setDataIsolation(DataIsolation.TABLE);
kfl.addPlayerExtension("position", "java.lang.String", "flex_1");
em.persist(kfl);
HostedLeague mhl = new HostedLeague("MHL", "Minor Hockey League", "red");
mhl.setShared(false);
mhl.setDataIsolation(DataIsolation.DATABASE);
mhl.setLogoUrl("/logos/hthl.png");
mhl.setDatasourceName("jdbc/MySports");
mhl.addPlayerExtension("position", "java.lang.String", "flex_1");
em.persist(mhl);
em.getTransaction().commit();
} finally {
em.close();
}
}
@BeforeClass
public static void createEMF() {
emf = Persistence.createEntityManagerFactory("MySportsAdmin", PersistenceTesting.get());
EntityManager em = emf.createEntityManager();
try {
em.getTransaction().begin();
em.createNativeQuery("DELETE FROM mys_admin_player_ext").executeUpdate();
em.createNativeQuery("DELETE FROM mys_admin_team_ext").executeUpdate();
em.createNativeQuery("DELETE FROM mys_admin_div_ext").executeUpdate();
em.createQuery("DELETE FROM HostedLeague").executeUpdate();
em.getTransaction().commit();
} finally {
em.close();
}
}
@AfterClass
public static void closeEMF() {
emf.close();
}
}