Esempio n. 1
0
  /** Test if setSender correctly changes the Sender */
  @Test
  public void test05_ChangeSender() {
    em.getTransaction().begin();
    List<UserMessage> tps = em.createQuery("from UserMessage", UserMessage.class).getResultList();
    UserMessage instance;
    TradingPartner sender = new TradingPartner(T_SENDER2_ID, T_SENDER2_ROLE);

    assertTrue(tps.size() == 1);

    instance = tps.get(0);

    instance.setSender(sender);

    em.persist(sender);
    em.persist(instance);
    em.getTransaction().commit();

    em.getTransaction().begin();
    tps = em.createQuery("from UserMessage", UserMessage.class).getResultList();

    instance = tps.get(0);

    assertEquals(T_SENDER2_ROLE, instance.getSender().getRole());

    Iterator<IPartyId> pids = instance.getSender().getPartyIds().iterator();
    if (pids.hasNext()) {
      assertEquals(T_SENDER2_ID, pids.next().getId());
    } else
      // There should be a partyid
      fail("Not retrieved the correct Sender");

    em.getTransaction().commit();
  }