UpdateManager implements IUpdateManager { @Override public void setPayloadInformation(final IUserMessageEntity userMessage, final Collection<IPayload> payloadInfo) throws PersistenceException { performUpdate((MessageUnitEntity) userMessage, (MessageUnit jpaObject) -> { ((UserMessage) jpaObject).setPayloads(payloadInfo); }); }  @Override V storeMessageUnit(final T messageUnit); @Override boolean setProcessingState(final IMessageUnitEntity msgUnit, final ProcessingState currentProcState,
                                      final ProcessingState newProcState); @Override boolean setProcessingState(final IMessageUnitEntity msgUnit, final ProcessingState currentProcState,
                                      final ProcessingState newProcState, final String description); @Override void deleteMessageUnit(final IMessageUnitEntity messageUnit); @Override void setPModeId(final IMessageUnitEntity msgUnit, final String pmodeId); @Override void setMultiHop(final IMessageUnitEntity msgUnit, final boolean isMultihop); @Override void setPayloadInformation(final IUserMessageEntity userMessage, final Collection<IPayload> payloadInfo); @Override void setAddSOAPFault(final IErrorMessageEntity errorMessage, final boolean addSOAPFault);  }
@Test public void setPayloadInformation() throws PersistenceException { QueryManager queryManager = new QueryManager(); em.getTransaction().begin(); UserMessage userMsgJPA = new UserMessage(TestData.userMsg5); em.persist(userMsgJPA); UserMessageEntity userMsg = new UserMessageEntity(userMsgJPA); em.getTransaction().commit(); queryManager.ensureCompletelyLoaded(userMsg); assertTrue(Utils.isNullOrEmpty(userMsg.getPayloads())); Collection<IPayload> newPayloads = new ArrayList<>(); newPayloads.add(TestData.payload2); newPayloads.add(TestData.payload3); updManager.setPayloadInformation(userMsg, newPayloads); assertFalse(Utils.isNullOrEmpty(userMsg.getPayloads())); assertEquals(2, userMsg.getPayloads().size()); em.refresh(userMsgJPA); assertFalse(Utils.isNullOrEmpty(userMsgJPA.getPayloads())); assertEquals(2, userMsgJPA.getPayloads().size()); Iterator<IPayload> it = userMsg.getPayloads().iterator(); Payload p1 = new Payload(it.next()); p1.addProperty(new Property(T_NEW_PL_PROP_NAME, T_NEW_PL_PROP_VALUE)); Payload p2 = new Payload(it.next()); p2.setContentLocation(T_NEW_CONTENT_LOC); newPayloads = new ArrayList<>(2); newPayloads.add(p1); newPayloads.add(p2); updManager.setPayloadInformation(userMsg, newPayloads); assertFalse(Utils.isNullOrEmpty(userMsg.getPayloads())); assertEquals(2, userMsg.getPayloads().size()); for (IPayload p : userMsg.getPayloads()) { if (p.getContainment() == p1.getContainment()) { assertFalse(Utils.isNullOrEmpty(p.getProperties())); assertEquals(1, p.getProperties().size()); assertTrue(CompareUtils.areEqual(p.getProperties().iterator().next(), p1.getProperties().iterator().next())); } else if (p.getContainment() == p2.getContainment()) { assertTrue(Utils.isNullOrEmpty(p.getProperties())); assertEquals(p2.getContentLocation(), p.getContentLocation()); } else fail("unknown payload"); } em.refresh(userMsgJPA); assertFalse(Utils.isNullOrEmpty(userMsgJPA.getPayloads())); assertEquals(2, userMsgJPA.getPayloads().size()); for (IPayload p : userMsgJPA.getPayloads()) { if (p.getContainment() == p1.getContainment()) { assertFalse(Utils.isNullOrEmpty(p.getProperties())); assertEquals(1, p.getProperties().size()); assertTrue(CompareUtils.areEqual(p.getProperties().iterator().next(), p1.getProperties().iterator().next())); } else if (p.getContainment() == p2.getContainment()) { assertTrue(Utils.isNullOrEmpty(p.getProperties())); assertEquals(p2.getContentLocation(), p.getContentLocation()); } else fail("unknown payload"); } }