| /******************************************************************************* |
| * 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 javax.persistence.EntityManagerFactory; |
| import javax.persistence.metamodel.Attribute; |
| |
| import org.eclipse.persistence.internal.jpa.metamodel.AttributeImpl; |
| import org.junit.AfterClass; |
| import org.junit.Assert; |
| import org.junit.Before; |
| 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.Division; |
| 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.OttawaSoccerLeague; |
| |
| /** |
| * @author dclarke |
| * @since EclipseLink 2.3.0 |
| */ |
| public class TestOttawaSoccerLeague { |
| |
| private static TestingLeagueRepository repository; |
| |
| @Test |
| public void verifyAdditionalAttributes() { |
| HostedLeague leagueDef = ExampleLeagueDefinition.OSL.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()); |
| } |
| } |
| |
| @Test |
| public void loadU6Division() { |
| Division division = repository.getDivision("U6"); |
| |
| Assert.assertNotNull(division); |
| Assert.assertEquals(division.getName(), "U6"); |
| } |
| |
| @Before |
| public void clearState() { |
| EntityManagerFactory emf = repository.unwrap(EntityManagerFactory.class); |
| emf.getCache().evictAll(); |
| } |
| |
| @BeforeClass |
| public static void setup() { |
| repository = PersistenceTesting.createLeagueRepository(); |
| repository.setLeagueId(OttawaSoccerLeague.LEAGUE, null); |
| new OttawaSoccerLeague().createDivisions(repository); |
| } |
| |
| @AfterClass |
| public static void tearDown() { |
| PersistenceTesting.dropSharedMySportsSchema(repository); |
| PersistenceTesting.closeRepository(repository); |
| } |
| } |