use of org.apache.openejb.test.entity.cmr.onetomany.SongLocal in project tomee by apache.
the class OneToManyTests method test00_AGetBExistingAB.
public void test00_AGetBExistingAB() throws Exception {
resetDB();
beginTransaction();
try {
final ArtistLocal artist = findArtist(1);
final Set bSet = artist.getPerformed();
assertEquals(2, bSet.size());
for (final Object value : bSet) {
final SongLocal song = (SongLocal) value;
if (song.getId().equals(11)) {
assertEquals("value11", song.getName());
} else if (song.getId().equals(22)) {
assertEquals("value22", song.getName());
} else {
fail();
}
}
} finally {
completeTransaction();
}
}
use of org.apache.openejb.test.entity.cmr.onetomany.SongLocal in project tomee by apache.
the class OneToManyTests method test03_BSetADropExisting.
public void test03_BSetADropExisting() throws Exception {
resetDB();
beginTransaction();
try {
SongLocal song = findSong(11);
song.setPerformer(null);
song = findSong(22);
song.setPerformer(null);
} finally {
completeTransaction();
}
assertUnlinked(1);
}
use of org.apache.openejb.test.entity.cmr.onetomany.SongLocal in project tomee by apache.
the class OneToManyTests method test05_BSetANewAB.
public void test05_BSetANewAB() throws Exception {
resetDB();
beginTransaction();
try {
final ArtistLocal artist = findArtist(2);
final SongLocal song = findSong(22);
song.setPerformer(artist);
} finally {
completeTransaction();
}
assertLinked(2, 22);
}
use of org.apache.openejb.test.entity.cmr.onetomany.SongLocal in project tomee by apache.
the class OneToManyTests method testModifyCmrCollectionInNewTx.
public void testModifyCmrCollectionInNewTx() throws Exception {
resetDB();
beginTransaction();
Set songs;
SongLocal newSong;
try {
final ArtistLocal artist = findArtist(new Integer(1));
newSong = createSong(new Integer(33));
songs = artist.getComposed();
} finally {
completeTransaction();
}
beginTransaction();
try {
// CMR collections should still be readable
assertFalse(songs.isEmpty());
assertEquals(2, songs.size());
for (final Iterator iter = songs.iterator(); iter.hasNext(); ) {
final SongLocal song = (SongLocal) iter.next();
if (song.getId().equals(new Integer(11))) {
assertEquals("value11", song.getName());
} else if (song.getId().equals(new Integer(22))) {
assertEquals("value22", song.getName());
} else {
fail();
}
}
// But CMR collections should not be modifiable
try {
songs.add(newSong);
fail("expected songs.add(newSong) to throw an IllegalStateException");
} catch (final IllegalStateException ignored) {
}
try {
songs.addAll(Arrays.asList(newSong));
fail("expected songs.addAll(Arrays.asList(newSong)) to throw an IllegalStateException");
} catch (final IllegalStateException ignored) {
}
try {
songs.remove(newSong);
fail("expected songs.remove(newSong) to throw an IllegalStateException");
} catch (final IllegalStateException ignored) {
}
try {
songs.removeAll(Arrays.asList(newSong));
fail("expected songs.removeAll(Arrays.asList(newSong)) to throw an IllegalStateException");
} catch (final IllegalStateException ignored) {
}
final Iterator iterator = songs.iterator();
try {
iterator.remove();
fail("expected iterator.remove() to throw an ConcurrentModificationException");
} catch (final ConcurrentModificationException ignored) {
}
} finally {
completeTransaction();
}
}
use of org.apache.openejb.test.entity.cmr.onetomany.SongLocal in project tomee by apache.
the class OneToManyTests method test08_ASetBExistingANewB.
public void test08_ASetBExistingANewB() throws Exception {
resetDB();
beginTransaction();
try {
final ArtistLocal artist = findArtist(1);
final SongLocal song = createSong(33);
final Set<SongLocal> songSets = artist.getPerformed();
songSets.add(song);
} finally {
completeTransaction();
}
assertLinked(1, 11, 22, 33);
}
Aggregations