public void testAddIndirectElimination() { EntityManager em = createEntityManager(); try { beginTransaction(em); Assassin assassin = em.find(Assassin.class, assassinId); Bomb bomb = new Bomb(); bomb.setBombType(Bomb.BOMBTYPE.DIRTY); bomb.setDescription("Nasty blasty"); em.persist(bomb); // Must set the correct weapon before an elimination. assassin.setWeapon(bomb); IndirectElimination indirectElimination = new IndirectElimination(); indirectElimination.setId(new Long(System.currentTimeMillis()).intValue()); indirectElimination.setName("Jill Smuck"); indirectElimination.setDescription("Because she has a big mouth"); indirectElimination.setAssassin(assassin); em.persist(indirectElimination); indirectEliminationPK = indirectElimination.getPK(); assassin.getEliminations().add(indirectElimination); commitTransaction(em); } catch (Exception e) { fail("Error adding new indirect elimination: " + e.getMessage()); } finally { closeEntityManager(em); } }
public void testCreateAssassinWithGun() { EntityManager em = createEntityManager(); try { beginTransaction(em); Assassin assassin = new Assassin(); assassin.setName("Assassin1"); Gun gun = new Gun(); gun.setCaliber(new Integer(50)); gun.setDescription("Sniper rifle"); gun.setModel("9-112"); assassin.setWeapon(gun); em.persist(assassin); assassinId = assassin.getId(); gunSerialNumber = gun.getSerialNumber(); commitTransaction(em); } catch (Exception exception) { exception.printStackTrace(); fail("Error persisting new assassin: " + exception.getMessage()); } finally { closeEntityManager(em); } }