use of org.apache.openejb.test.entity.cmr.manytomany.GameLocal in project tomee by apache.
the class ManyToManyTests method testModifyCmrCollectionOusideTx.
public void testModifyCmrCollectionOusideTx() throws Exception {
resetDB();
beginTransaction();
Set games;
GameLocal newGame;
try {
final PlatformLocal platform = findPlatform(new Integer(1));
newGame = createGame(new Integer(33));
games = platform.getGames();
} finally {
completeTransaction();
}
// CMR collections should still be readable
assertFalse(games.isEmpty());
assertEquals(2, games.size());
for (final Iterator iter = games.iterator(); iter.hasNext(); ) {
final GameLocal game = (GameLocal) iter.next();
if (game.getId().equals(new Integer(11))) {
assertEquals("value11", game.getName());
} else if (game.getId().equals(new Integer(22))) {
assertEquals("value22", game.getName());
} else {
fail();
}
}
// But CMR collections should not be modifiable
try {
games.add(newGame);
fail("expected games.add(game) to throw an IllegalStateException");
} catch (final IllegalStateException expected) {
}
try {
games.addAll(Arrays.asList(newGame));
fail("expected games.addAll(Arrays.asList(game)) to throw an IllegalStateException");
} catch (final IllegalStateException expected) {
}
try {
games.remove(newGame);
fail("expected games.remove(game) to throw an IllegalStateException");
} catch (final IllegalStateException expected) {
}
try {
games.removeAll(Arrays.asList(newGame));
fail("expected games.removeAll(game) to throw an IllegalStateException");
} catch (final IllegalStateException expected) {
}
final Iterator iterator = games.iterator();
try {
iterator.remove();
fail("expected iterator.remove() to throw an ConcurrentModificationException");
} catch (final ConcurrentModificationException expected) {
}
}
use of org.apache.openejb.test.entity.cmr.manytomany.GameLocal in project tomee by apache.
the class ManyToManyTests method resetDB.
private void resetDB() throws Exception {
final Connection connection = ds.getConnection();
Statement statement = null;
try {
statement = connection.createStatement();
try {
statement.execute("DELETE FROM Game_Platform");
} catch (final SQLException ignored) {
}
try {
statement.execute("DELETE FROM Game");
} catch (final SQLException ignored) {
}
try {
statement.execute("DELETE FROM Platform");
} 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 ManyToManyTests method testASetBExistingBNewA.
public void testASetBExistingBNewA() throws Exception {
resetDB();
beginTransaction();
try {
final PlatformLocal platform = createPlatform(new Integer(4));
final GameLocal game = findGame(new Integer(11));
final Set<GameLocal> gameSets = platform.getGames();
gameSets.add(game);
} finally {
completeTransaction();
}
assertLinked(4, 11);
}
use of org.apache.openejb.test.entity.cmr.manytomany.GameLocal in project tomee by apache.
the class ManyToManyTests method testIteratorConcurrentModification.
public void testIteratorConcurrentModification() 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();
games.remove(game);
assertEquals(1, 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 ManyToManyTests method testModifyCmrCollectionInNewTx.
public void testModifyCmrCollectionInNewTx() throws Exception {
resetDB();
beginTransaction();
Set games;
GameLocal newGame;
try {
final PlatformLocal platform = findPlatform(new Integer(1));
newGame = createGame(new Integer(33));
games = platform.getGames();
} finally {
completeTransaction();
}
beginTransaction();
try {
// CMR collections should still be readable
assertFalse(games.isEmpty());
assertEquals(2, games.size());
for (final Iterator iter = games.iterator(); iter.hasNext(); ) {
final GameLocal game = (GameLocal) iter.next();
if (game.getId().equals(new Integer(11))) {
assertEquals("value11", game.getName());
} else if (game.getId().equals(new Integer(22))) {
assertEquals("value22", game.getName());
} else {
fail();
}
}
// But CMR collections should not be modifiable
try {
games.add(newGame);
fail("expected games.add(game) to throw an IllegalStateException");
} catch (final IllegalStateException expected) {
}
try {
games.addAll(Arrays.asList(newGame));
fail("expected games.addAll(Arrays.asList(game)) to throw an IllegalStateException");
} catch (final IllegalStateException expected) {
}
try {
games.remove(newGame);
fail("expected games.remove(game) to throw an IllegalStateException");
} catch (final IllegalStateException expected) {
}
try {
games.removeAll(Arrays.asList(newGame));
fail("expected games.removeAll(game) to throw an IllegalStateException");
} catch (final IllegalStateException expected) {
}
final Iterator iterator = games.iterator();
try {
iterator.remove();
fail("expected iterator.remove() to throw an ConcurrentModificationException");
} catch (final ConcurrentModificationException expected) {
}
} finally {
completeTransaction();
}
}
Aggregations