use of org.apache.openejb.test.entity.cmr.manytomany.GameLocal in project tomee by apache.
the class ManyToManyComplexPkTests 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();
}
}
use of org.apache.openejb.test.entity.cmr.manytomany.GameLocal in project tomee by apache.
the class ManyToManyTests method testBSetANewAB.
public void testBSetANewAB() throws Exception {
resetDB();
beginTransaction();
try {
final PlatformLocal platform = createPlatform(new Integer(4));
final GameLocal game = createGame(new Integer(33));
final Set<PlatformLocal> platformSets = game.getPlatforms();
platformSets.add(platform);
} finally {
completeTransaction();
}
assertLinked(4, 33);
}
use of org.apache.openejb.test.entity.cmr.manytomany.GameLocal in project tomee by apache.
the class ManyToManyTests method testBSetAExistingBNewA.
public void testBSetAExistingBNewA() throws Exception {
resetDB();
beginTransaction();
try {
final PlatformLocal platform = createPlatform(new Integer(4));
final GameLocal game = findGame(new Integer(11));
final Set<PlatformLocal> platformSets = game.getPlatforms();
platformSets.add(platform);
} finally {
completeTransaction();
}
assertLinked(4, 11);
}
use of org.apache.openejb.test.entity.cmr.manytomany.GameLocal in project tomee by apache.
the class ManyToManyTests method testBSetADropExisting.
public void testBSetADropExisting() throws Exception {
resetDB();
beginTransaction();
try {
GameLocal game = findGame(new Integer(11));
game.setPlatforms(new HashSet<PlatformLocal>());
game = findGame(new Integer(22));
game.setPlatforms(new HashSet<PlatformLocal>());
} finally {
completeTransaction();
}
assertAllUnlinked();
}
use of org.apache.openejb.test.entity.cmr.manytomany.GameLocal in project tomee by apache.
the class ManyToManyTests method testAGetBExistingAB.
public void testAGetBExistingAB() throws Exception {
resetDB();
beginTransaction();
try {
final PlatformLocal platform = findPlatform(new Integer(1));
final Set<GameLocal> gameSets = platform.getGames();
assertEquals(2, gameSets.size());
for (final Iterator iter = gameSets.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();
}
}
} finally {
completeTransaction();
}
}
Aggregations