use of org.apache.openejb.test.entity.cmr.manytomany.GameLocal in project tomee by apache.
the class ManyToManyTests method testASetBDropExisting.
public void testASetBDropExisting() throws Exception {
resetDB();
beginTransaction();
try {
PlatformLocal platform = findPlatform(new Integer(1));
platform.setGames(new HashSet<GameLocal>());
platform = findPlatform(new Integer(2));
platform.setGames(new HashSet<GameLocal>());
platform = findPlatform(new Integer(3));
platform.setGames(new HashSet<GameLocal>());
} finally {
completeTransaction();
}
assertAllUnlinked();
}
use of org.apache.openejb.test.entity.cmr.manytomany.GameLocal in project tomee by apache.
the class ManyToManyComplexPkTests method resetDB.
private void resetDB() throws Exception {
final Connection connection = ds.getConnection();
Statement statement = null;
try {
statement = connection.createStatement();
try {
statement.execute("DELETE FROM ComplexGame_ComplexPlatform");
} catch (final SQLException ignored) {
}
try {
statement.execute("DELETE FROM ComplexGame");
} catch (final SQLException ignored) {
}
try {
statement.execute("DELETE FROM ComplexPlatform");
} catch (final SQLException ignored) {
}
} finally {
close(statement);
close(connection);
}
beginTransaction();
try {
final PlatformLocal platform1 = createPlatform(1);
assertNotNull("platform1.getGames() is null", platform1.getGames());
final PlatformLocal platform2 = createPlatform(2);
assertNotNull("platform2.getGames() is null", platform2.getGames());
final PlatformLocal platform3 = createPlatform(3);
assertNotNull("platform3.getGames() is null", platform3.getGames());
final GameLocal game1 = createGame(11);
assertNotNull("game1.getPlatforms() is null", game1.getPlatforms());
final GameLocal game2 = createGame(22);
assertNotNull("game2.getPlatforms() is null", game2.getPlatforms());
platform1.getGames().add(game1);
platform1.getGames().add(game2);
platform2.getGames().add(game2);
platform3.getGames().add(game2);
} finally {
completeTransaction();
}
}
use of org.apache.openejb.test.entity.cmr.manytomany.GameLocal in project tomee by apache.
the class ManyToManyComplexPkTests method testBGetAExistingAB.
public void testBGetAExistingAB() throws Exception {
resetDB();
beginTransaction();
try {
final GameLocal game = findGame(new Integer(22));
final Set aSet = game.getPlatforms();
assertEquals(3, aSet.size());
for (final Iterator iter = aSet.iterator(); iter.hasNext(); ) {
final PlatformLocal platform = (PlatformLocal) iter.next();
if (platform.getId().equals(new Integer(1))) {
assertEquals("value1", platform.getName());
} else if (platform.getId().equals(new Integer(2))) {
assertEquals("value2", platform.getName());
} else if (platform.getId().equals(new Integer(3))) {
assertEquals("value3", platform.getName());
} else {
fail();
}
}
} finally {
completeTransaction();
}
}
use of org.apache.openejb.test.entity.cmr.manytomany.GameLocal in project tomee by apache.
the class ManyToManyComplexPkTests method testIteratorAndRemove.
public void testIteratorAndRemove() throws Exception {
resetDB();
beginTransaction();
final Set games;
try {
final PlatformLocal platform = findPlatform(new Integer(1));
final GameLocal game = findGame(new Integer(11));
games = platform.getGames();
assertFalse(games.isEmpty());
assertEquals(2, games.size());
final Iterator iterator = games.iterator();
assertTrue(games.contains(game));
platform.remove();
assertFalse(games.contains(game));
assertEquals(0, games.size());
try {
iterator.next();
fail("expected iterator.next() to throw an ConcurrentModificationException");
} catch (final ConcurrentModificationException expected) {
}
} finally {
completeTransaction();
}
}
use of org.apache.openejb.test.entity.cmr.manytomany.GameLocal in project tomee by apache.
the class ManyToManyComplexPkTests method testASetBNewAB.
public void testASetBNewAB() throws Exception {
resetDB();
beginTransaction();
try {
final PlatformLocal platform = createPlatform(new Integer(4));
final GameLocal game = createGame(new Integer(33));
final Set<GameLocal> gameSets = platform.getGames();
gameSets.add(game);
} finally {
completeTransaction();
}
assertLinked(4, 33);
}
Aggregations