UpdateManager implements IUpdateManager { @Override public <T extends IMessageUnit, V extends IMessageUnitEntity> V storeMessageUnit(final T messageUnit) throws PersistenceException { if (messageUnit.getDirection() == Direction.OUT && !Utils.isNullOrEmpty(HolodeckB2BCoreInterface.getQueryManager() .getMessageUnitsWithId(messageUnit.getMessageId(), Direction.OUT))) throw new PersistenceException("The messageId of the message unit (" + messageUnit.getMessageId() + ") already exists!"); EntityManager em = null; MessageUnit jpaMsgUnit = null; EntityTransaction tx = null; try { Class jpaEntityClass = JPAEntityHelper.determineJPAClass(messageUnit); Constructor cons = jpaEntityClass.getConstructor(MessageUnitUtils.getMessageUnitType(messageUnit)); jpaMsgUnit = (MessageUnit) cons.newInstance(messageUnit); em = EntityManagerUtil.getEntityManager(); tx = em.getTransaction(); tx.begin(); em.persist(jpaMsgUnit); tx.commit(); } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { if (tx!=null && tx.isActive()) { tx.rollback(); } throw new PersistenceException("An error occurred while saving the message unit's meta-data!", ex); } finally { if (em != null && em.isOpen()) em.close(); } return JPAEntityHelper.wrapInEntity(jpaMsgUnit, true); }  @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 storeUserMessage() throws PersistenceException { UserMessageEntity userMsg = updManager.storeMessageUnit(new org.holodeckb2b.common.messagemodel.UserMessage(TestData.userMsg1)); assertNotNull(userMsg); assertNotNull(userMsg.getOID()); assertEquals(TestData.userMsg1.getPModeId(), userMsg.getPModeId()); assertEquals(TestData.userMsg1.getMessageId(), userMsg.getMessageId()); assertEquals(TestData.userMsg1.getRefToMessageId(), userMsg.getRefToMessageId()); assertEquals(TestData.userMsg1.getDirection(), userMsg.getDirection()); assertTrue(CompareUtils.areEqual(TestData.userMsg1.getSender(), userMsg.getSender())); assertTrue(CompareUtils.areEqual(TestData.userMsg1.getReceiver(), userMsg.getReceiver())); assertFalse(Utils.isNullOrEmpty(userMsg.getProcessingStates())); assertEquals(TestData.userMsg1.getCurrentProcessingState().getStartTime(), userMsg.getCurrentProcessingState().getStartTime()); assertEquals(TestData.userMsg1.getCurrentProcessingState().getState(), userMsg.getCurrentProcessingState().getState()); assertFalse(Utils.isNullOrEmpty(userMsg.getPayloads())); assertEquals(1, userMsg.getPayloads().size()); IPayload savedPayload = userMsg.getPayloads().iterator().next(); IPayload orgPayload = TestData.userMsg1.getPayloads().iterator().next(); assertEquals(orgPayload.getContainment(), savedPayload.getContainment()); assertFalse(Utils.isNullOrEmpty(savedPayload.getProperties())); assertEquals(1, savedPayload.getProperties().size()); assertTrue(CompareUtils.areEqual(orgPayload.getProperties().iterator().next(), savedPayload.getProperties().iterator().next())); assertEquals(orgPayload.getSchemaReference().getNamespace(), savedPayload.getSchemaReference().getNamespace()); assertNull(savedPayload.getSchemaReference().getLocation()); assertNotNull(savedPayload.getDescription()); assertTrue(CompareUtils.areEqual(TestData.userMsg1.getCollaborationInfo().getService(), userMsg.getCollaborationInfo().getService())); assertFalse(Utils.isNullOrEmpty(userMsg.getMessageProperties())); assertEquals(1, userMsg.getMessageProperties().size()); assertTrue(CompareUtils.areEqual(TestData.userMsg1.getMessageProperties().iterator().next(), userMsg.getMessageProperties().iterator().next())); }
@Test public void storeReceipt() throws PersistenceException { ReceiptEntity receiptEntity = updManager.storeMessageUnit(new org.holodeckb2b.common.messagemodel.Receipt(TestData.receipt6)); assertNotNull(receiptEntity); assertEquals(TestData.receipt6.getMessageId(), receiptEntity.getMessageId()); assertEquals(TestData.receipt6.getRefToMessageId(), receiptEntity.getRefToMessageId()); assertEquals(TestData.receipt6.getTimestamp(), receiptEntity.getTimestamp()); assertFalse(Utils.isNullOrEmpty(receiptEntity.getContent())); assertEquals(TestData.receipt6.getContent().get(0).getQName(), receiptEntity.getContent().get(0).getQName()); assertEquals(TestData.receipt6.getContent().get(0).getText(), receiptEntity.getContent().get(0).getText()); }
@Test public void storePullRequest() throws PersistenceException { PullRequestEntity pullEntity = updManager.storeMessageUnit(TestData.pull5); assertNotNull(pullEntity); assertEquals(TestData.pull5.getMessageId(), pullEntity.getMessageId()); assertEquals(TestData.pull5.getRefToMessageId(), pullEntity.getRefToMessageId()); assertEquals(TestData.pull5.getTimestamp(), pullEntity.getTimestamp()); pullEntity = updManager.storeMessageUnit(TestData.pull6); assertNotNull(pullEntity); assertTrue(pullEntity instanceof ISelectivePullRequest); assertEquals(TestData.pull6.getMessageId(), pullEntity.getMessageId()); assertEquals(TestData.pull6.getRefToMessageId(), pullEntity.getRefToMessageId()); assertEquals(TestData.pull6.getTimestamp(), pullEntity.getTimestamp()); assertEquals(TestData.pull6.getReferencedMessageId(), ((ISelectivePullRequest) pullEntity).getReferencedMessageId()); assertNull(((ISelectivePullRequest) pullEntity).getConversationId()); assertNull(((ISelectivePullRequest) pullEntity).getAgreementRef()); assertNull(((ISelectivePullRequest) pullEntity).getService()); assertNull(((ISelectivePullRequest) pullEntity).getAction()); pullEntity = updManager.storeMessageUnit(TestData.pull7); assertNotNull(pullEntity); assertTrue(pullEntity instanceof ISelectivePullRequest); assertEquals(TestData.pull7.getMessageId(), pullEntity.getMessageId()); assertEquals(TestData.pull7.getRefToMessageId(), pullEntity.getRefToMessageId()); assertEquals(TestData.pull7.getTimestamp(), pullEntity.getTimestamp()); assertNull(((ISelectivePullRequest) pullEntity).getReferencedMessageId()); assertEquals(TestData.pull7.getConversationId() ,((ISelectivePullRequest) pullEntity).getConversationId()); assertNotNull(((ISelectivePullRequest) pullEntity).getAgreementRef()); assertEquals(TestData.pull7.getAgreementRef().getName(), ((ISelectivePullRequest) pullEntity).getAgreementRef().getName()); assertEquals(TestData.pull7.getAgreementRef().getType(), ((ISelectivePullRequest) pullEntity).getAgreementRef().getType()); assertNotNull(((ISelectivePullRequest) pullEntity).getService()); assertTrue(CompareUtils.areEqual(TestData.pull7.getService(), ((ISelectivePullRequest) pullEntity).getService())); assertNull(((ISelectivePullRequest) pullEntity).getAction()); }