public void testOrderColumnNoviceBeerConsumerDesignations() { EntityManager em = createEntityManager(); beginTransaction(em); NoviceBeerConsumer beerConsumer; try { // These are the designations we have right now ... // index: 0 - 1 - 2 - 3 - 4 // item: 5 - 4 - 2 - 3 - 1 beerConsumer = em.find(NoviceBeerConsumer.class, m_noviceBeerConsumerId); String stringFour = beerConsumer.getDesignations().remove(1); String stringTwo = beerConsumer.getDesignations().remove(1); beerConsumer.getDesignations().add(stringTwo); // This is what we have done // index: 0 - 1 - 2 - 3 // item: 5 - 3 - 1 - 2 commitTransaction(em); } catch (RuntimeException e) { if (isTransactionActive(em)) { rollbackTransaction(em); } closeEntityManager(em); throw e; } closeEntityManager(em); clearCache(); em = createEntityManager(); BeerConsumer refreshedBC = em.find(BeerConsumer.class, m_noviceBeerConsumerId); assertTrue( "The novice beer consumer read back did not match the original", getServerSession().compareObjects(beerConsumer, refreshedBC)); }
public void testReadNoviceBeerConsumer() { NoviceBeerConsumer consumer = createEntityManager().find(NoviceBeerConsumer.class, m_noviceBeerConsumerId); assertTrue("Error on reading back a NoviceBeerConsumer", consumer != null); assertTrue("IQ Level was not persisted.", consumer.getIQ() == 100); assertTrue("Incorrect number of acclaims returned.", consumer.getAcclaims().size() == 3); assertTrue("Missing acclaim - 1", consumer.getAcclaims().contains(1)); assertTrue("Missing acclaim - 2", consumer.getAcclaims().contains(2)); assertTrue("Missing acclaim - 3", consumer.getAcclaims().contains(3)); assertTrue("Incorrect number of awards returned.", consumer.getAwards().size() == 3); Integer awardCode = consumer.getAwards().get(1); assertFalse("Missing award code - 1", awardCode == null); assertTrue("Award code 1 is incorrect", awardCode.equals(1)); awardCode = consumer.getAwards().get(2); assertFalse("Missing award code - 2", awardCode == null); assertTrue("Award code 2 is incorrect", awardCode.equals(2)); awardCode = consumer.getAwards().get(3); assertFalse("Missing award code - 3", awardCode == null); assertTrue("Award code 3 is incorrect", awardCode.equals(3)); assertTrue( "Incorrect number of designations returned.", consumer.getDesignations().size() == 5); assertTrue("Missing designation - 5 at index 0", consumer.getDesignations().get(0).equals("5")); assertTrue("Missing designation - 4 at index 1", consumer.getDesignations().get(1).equals("4")); assertTrue("Missing designation - 2 at index 2", consumer.getDesignations().get(2).equals("2")); assertTrue("Missing designation - 3 at index 3", consumer.getDesignations().get(3).equals("3")); assertTrue("Missing designation - 1 at index 4", consumer.getDesignations().get(4).equals("1")); assertTrue("Incorrect number of records returned.", consumer.getRecords().size() == 1); }
public void testCreateNoviceBeerConsumer() { EntityManager em = createEntityManager(); beginTransaction(em); NoviceBeerConsumer beerConsumer = new NoviceBeerConsumer(); try { beerConsumer.setName("Novice Beer Consumer"); beerConsumer.setIQ(100); beerConsumer.getAcclaims().add(1); beerConsumer.getAcclaims().add(2); beerConsumer.getAcclaims().add(3); beerConsumer.getAwards().put(1, 1); beerConsumer.getAwards().put(2, 2); beerConsumer.getAwards().put(3, 3); beerConsumer.getDesignations().add("5"); beerConsumer.getDesignations().add("4"); beerConsumer.getDesignations().add("2"); beerConsumer.getDesignations().add("3"); beerConsumer.getDesignations().add("1"); Record record1 = new Record(); record1.setDescription("Slowest beer ever consumed - 10 hours"); record1.setDate(Helper.dateFromYearMonthDate(2008, 1, 1)); record1.setLocation(new Location("Paris", "France")); beerConsumer.getRecords().add(record1); Accredidation accredidation = new Accredidation(); accredidation.setDetails("Superb, just superb!"); Witness witness1 = new Witness(); witness1.setName("Mickey Blue Eyes"); accredidation.addWitness(witness1); Witness witness2 = new Witness(); witness2.setName("Donny Trafalgo"); accredidation.addWitness(witness2); beerConsumer.setAccredidation(accredidation); Committee committee1 = new Committee(); committee1.setDescription("Moral labelling"); beerConsumer.addCommittee(committee1); Committee committee2 = new Committee(); committee2.setDescription("Crimes against beer"); beerConsumer.addCommittee(committee2); Committee committee3 = new Committee(); committee3.setDescription("BADD - Beers against drunk dorks"); beerConsumer.addCommittee(committee3); em.persist(beerConsumer); m_noviceBeerConsumerId = beerConsumer.getId(); commitTransaction(em); } catch (RuntimeException e) { if (isTransactionActive(em)) { rollbackTransaction(em); } closeEntityManager(em); fail( "An exception was caught during create operation for a novice beer consumer: [" + e.getMessage() + "]"); } closeEntityManager(em); clearCache(); em = createEntityManager(); BeerConsumer refreshedBC = em.find(BeerConsumer.class, m_noviceBeerConsumerId); assertTrue( "The novice beer consumer read back did not match the original", getServerSession().compareObjects(beerConsumer, refreshedBC)); }