Search in sources :

Example 6 with ArtistLocal

use of org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal in project tomee by apache.

the class OneToManyComplexPkTests method testIllegalCmrCollectionArgument.

public void testIllegalCmrCollectionArgument() throws Exception {
    resetDB();
    beginTransaction();
    try {
        final ArtistLocal artist = findArtist(new Integer(1));
        final Set songs = artist.getComposed();
        try {
            songs.add(new Object());
            fail("expected games.add(new Object()) to throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        }
        try {
            songs.addAll(Arrays.asList(new Object()));
            fail("expected games.addAll(Arrays.asList(new Object())) to throw an IllegalArgumentException");
        } catch (final IllegalArgumentException expected) {
        }
    } finally {
        completeTransaction();
    }
}
Also used : ArtistLocal(org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal) Set(java.util.Set) HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet)

Example 7 with ArtistLocal

use of org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal in project tomee by apache.

the class OneToManyComplexPkTests 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();
    }
}
Also used : ArtistLocal(org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal) SongLocal(org.apache.openejb.test.entity.cmr.onetomany.SongLocal)

Example 8 with ArtistLocal

use of org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal in project tomee by apache.

the class OneToManyComplexPkTests 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);
}
Also used : ArtistLocal(org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal) SongLocal(org.apache.openejb.test.entity.cmr.onetomany.SongLocal)

Example 9 with ArtistLocal

use of org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal in project tomee by apache.

the class OneToManyComplexPkTests 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);
        assertFalse(songs.isEmpty());
        artist.remove();
        assertTrue(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 ComplexSong");
    assertTrue(rs.next());
    assertEquals(2, rs.getInt(1));
    rs.close();
    s.close();
    c.close();
}
Also used : ArtistLocal(org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal) SongLocal(org.apache.openejb.test.entity.cmr.onetomany.SongLocal) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) HashSet(java.util.HashSet)

Example 10 with ArtistLocal

use of org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal in project tomee by apache.

the class OneToManyTests method test07_BSetAExistingBNewA.

public void test07_BSetAExistingBNewA() throws Exception {
    resetDB();
    beginTransaction();
    try {
        final ArtistLocal artist = findArtist(2);
        final SongLocal song = findSong(11);
        song.setPerformer(artist);
    } finally {
        completeTransaction();
    }
    assertLinked(2, 11);
}
Also used : ArtistLocal(org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal) SongLocal(org.apache.openejb.test.entity.cmr.onetomany.SongLocal)

Aggregations

ArtistLocal (org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal)39 SongLocal (org.apache.openejb.test.entity.cmr.onetomany.SongLocal)36 ResultSet (java.sql.ResultSet)16 HashSet (java.util.HashSet)16 Set (java.util.Set)12 ConcurrentModificationException (java.util.ConcurrentModificationException)8 Iterator (java.util.Iterator)8 Connection (java.sql.Connection)6 Statement (java.sql.Statement)6 SQLException (java.sql.SQLException)2