use of org.apache.openejb.test.entity.cmr.onetomany.SongLocal in project tomee by apache.
the class OneToManyTests method test06_ASetBExistingBNewA.
public void test06_ASetBExistingBNewA() throws Exception {
resetDB();
beginTransaction();
try {
final ArtistLocal artist = findArtist(2);
final SongLocal song = findSong(11);
final Set<SongLocal> songSets = artist.getPerformed();
songSets.add(song);
} finally {
completeTransaction();
}
assertLinked(2, 11);
}
use of org.apache.openejb.test.entity.cmr.onetomany.SongLocal in project tomee by apache.
the class OneToManyTests method TODO_testSetCMPMappedToForeignKeyColumn.
// uncomment when cmp to cmr is supported
public void TODO_testSetCMPMappedToForeignKeyColumn() throws Exception {
resetDB();
beginTransaction();
try {
final SongLocal song = findSong(11);
song.setBpm(2);
final ArtistLocal artist = song.getPerformer();
assertEquals(new Integer(2), artist.getId());
assertEquals("value2", artist.getName());
} finally {
completeTransaction();
}
}
use of org.apache.openejb.test.entity.cmr.onetomany.SongLocal in project tomee by apache.
the class OneToManyTests method testIteratorAndRemove.
public void testIteratorAndRemove() throws Exception {
resetDB();
beginTransaction();
try {
final ArtistLocal artist = findArtist(new Integer(1));
final SongLocal song = findSong(new Integer(11));
final Set games = artist.getComposed();
assertFalse(games.isEmpty());
assertEquals(2, games.size());
final Iterator iterator = games.iterator();
assertTrue(games.contains(song));
artist.remove();
assertFalse(games.contains(song));
assertEquals(0, games.size());
try {
iterator.next();
fail("expected iterator.next() 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 resetDB.
private synchronized void resetDB() throws Exception {
final Connection connection = ds.getConnection();
Statement statement = null;
try {
statement = connection.createStatement();
try {
statement.execute("DELETE FROM Artist");
} catch (final SQLException ignored) {
}
try {
statement.execute("DELETE FROM Song");
} catch (final SQLException ignored) {
}
} finally {
close(statement);
close(connection);
}
final ArtistLocal artist1 = createArtist(1);
createArtist(2);
final SongLocal song1 = createSong(11);
final SongLocal song2 = createSong(22);
song1.setPerformer(artist1);
song2.setPerformer(artist1);
song1.setComposer(artist1);
song2.setComposer(artist1);
}
use of org.apache.openejb.test.entity.cmr.onetomany.SongLocal in project tomee by apache.
the class OneToManyTests method test09_BSetAExistingANewB.
public void test09_BSetAExistingANewB() throws Exception {
resetDB();
beginTransaction();
try {
final ArtistLocal artist = findArtist(1);
final SongLocal song = createSong(33);
song.setPerformer(artist);
} finally {
completeTransaction();
}
assertLinked(1, 11, 22, 33);
}
Aggregations