use of org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal in project tomee by apache.
the class OneToManyTests method test01_BGetAExistingAB.
public void test01_BGetAExistingAB() throws Exception {
resetDB();
beginTransaction();
try {
SongLocal song = findSong(11);
ArtistLocal artist = song.getPerformer();
assertNotNull(artist);
assertEquals(new Integer(1), artist.getId());
assertEquals("value1", artist.getName());
song = findSong(22);
artist = song.getPerformer();
assertNotNull(artist);
assertEquals(new Integer(1), artist.getId());
assertEquals("value1", artist.getName());
} finally {
completeTransaction();
}
}
use of org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal in project tomee by apache.
the class OneToManyTests method test02_ASetBDropExisting.
public void test02_ASetBDropExisting() throws Exception {
resetDB();
beginTransaction();
try {
final ArtistLocal artist = findArtist(1);
artist.setPerformed(new HashSet<SongLocal>());
} finally {
completeTransaction();
}
assertUnlinked(1);
}
use of org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal in project tomee by apache.
the class OneToManyTests method test10_RemoveRelationships.
public void test10_RemoveRelationships() throws Exception {
resetDB();
beginTransaction();
try {
final SongLocal song = findSong(11);
final ArtistLocal artist = song.getPerformer();
final Set<SongLocal> songs = artist.getPerformed();
assertTrue(songs.contains(song));
song.remove();
assertFalse(songs.contains(song));
} finally {
completeTransaction();
}
assertLinked(1, 22);
assertUnlinked(2);
}
use of org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal in project tomee by apache.
the class OneToManyTests method test04_ASetBNewAB.
public void test04_ASetBNewAB() throws Exception {
resetDB();
beginTransaction();
try {
final ArtistLocal artist = findArtist(2);
final SongLocal song = findSong(22);
final Set<SongLocal> songSets = new HashSet<SongLocal>();
songSets.add(song);
artist.setPerformed(songSets);
} finally {
completeTransaction();
}
assertLinked(2, 22);
}
use of org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal in project tomee by apache.
the class OneToManyTests method test11_Delete.
public void test11_Delete() throws Exception {
resetDB();
beginTransaction();
try {
final ArtistLocal artist = findArtist(1);
artist.setPerformed(new HashSet<SongLocal>());
final Set<SongLocal> songs = artist.getComposed();
final Set<SongLocal> bsCopies = new HashSet<SongLocal>(songs);
assertSame(songs, artist.getComposed());
artist.remove();
assertTrue("CMR collection is not empty " + System.identityHashCode(songs), songs.isEmpty());
for (final SongLocal songLocal : bsCopies) {
assertNull(songLocal.getComposer());
}
} finally {
completeTransaction();
}
final Connection c = ds.getConnection();
final Statement s = c.createStatement();
final ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM Song");
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
rs.close();
s.close();
c.close();
}
Aggregations