blob: b598f5696cd56d2fd2b43607a146a8c972bc9e14 [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.application.test.model;
import java.util.List;
import java.util.Vector;
import javax.persistence.metamodel.Attribute;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.internal.jpa.metamodel.AttributeImpl;
import org.eclipse.persistence.internal.sessions.ArrayRecord;
import org.eclipse.persistence.sessions.server.Server;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import eclipselink.example.mysports.admin.examples.ExampleLeagueDefinition;
import eclipselink.example.mysports.admin.model.Extension;
import eclipselink.example.mysports.admin.model.HostedLeague;
import eclipselink.example.mysports.application.model.Player;
import eclipselink.example.mysports.application.test.PersistenceTesting;
import eclipselink.example.mysports.application.test.TestingLeagueRepository;
import eclipselink.example.mysports.examples.KidsFootballLeague;
/**
* @author dclarke
* @since EclipseLink 2.3.0
*/
public class TestKidsFootballLeague {
private static TestingLeagueRepository repository;
@Test
public void verifyKFLMySportsSchema() throws Exception {
Server session = repository.unwrap(Server.class);
for (ClassDescriptor desc : session.getDescriptors().values()) {
Object result = session.executeSQL("SELECT COUNT(*) FROM " + desc.getTableName());
Assert.assertNotNull(result);
@SuppressWarnings("unchecked")
ArrayRecord record = (ArrayRecord) ((Vector<Object>) result).get(0);
// TODO Assert.assertEquals(3, ((Number) record.getValues().get(0)).intValue());
}
}
@Test
public void verifyAdditionalAttributes() {
HostedLeague leagueDef = ExampleLeagueDefinition.KFL.getLeague();
List<Attribute<?, ?>> attrs = repository.getAdditionalAttributes(Player.class);
Assert.assertNotNull(attrs);
Assert.assertEquals(leagueDef.getPlayerExtensions().size(), attrs.size());
int index = 0;
for (Extension ext: leagueDef.getPlayerExtensions()) {
Attribute<?, ?> mnAttr = attrs.get(index++);
Assert.assertEquals(ext.getName(), mnAttr.getName());
Assert.assertFalse(mnAttr.isAssociation());
Assert.assertEquals(String.class, mnAttr.getJavaType());
Assert.assertTrue(((AttributeImpl<?, ?>) mnAttr).getMapping().getAttributeAccessor().isVirtualAttributeAccessor());
}
}
@BeforeClass
public static void setup() {
repository = PersistenceTesting.createLeagueRepository();
repository.setLeagueId(KidsFootballLeague.LEAGUE, null);
PersistenceTesting.dropLeagueTables(repository, KidsFootballLeague.LEAGUE);
new KidsFootballLeague().createDivisions(repository);
}
@AfterClass
public static void tearDown() {
PersistenceTesting.dropLeagueTables(repository, KidsFootballLeague.LEAGUE);
PersistenceTesting.dropSharedMySportsSchema(repository);
PersistenceTesting.closeRepository(repository);
}
}