use of network.oxalis.outbound.transmission.TransmissionRequestFactory in project Oxalis-AS4 by OxalisCommunity.
the class AbstractMessagingProviderTest method testCreateMessagingHeader.
@Test
public void testCreateMessagingHeader() throws Exception {
TransmissionRequestFactory transmissionRequestFactory = new TransmissionRequestFactory(new NoopContentDetector(), new NoopContentWrapper(), new NoopTagGenerator(), new SbdhHeaderParser(), NoopTracerFactory.create());
TransmissionMessage transmissionMessage;
try (InputStream inputStream = getClass().getResourceAsStream(getPayloadPath())) {
transmissionMessage = transmissionRequestFactory.newInstance(inputStream);
}
Assert.assertNotNull(transmissionMessage.getHeader());
TransmissionRequest transmissionRequest = new DefaultTransmissionRequestFacade(transmissionMessage, Endpoint.of(TransportProfile.PEPPOL_AS2_2_0, null, receiverCert));
HashMap<String, List<String>> headers = new HashMap<>();
headers.put(Content_ID_KEY, Collections.singletonList(Content_ID_VALUE));
headers.put(COMPRESSION_TYPE_KEY, Collections.singletonList(COMPRESSION_TYPE_VALUE));
headers.put(MIME_TYPE_KEY, Collections.singletonList(MIME_TYPE_VALUE));
Attachment attachment = AttachmentUtil.createAttachment(transmissionRequest.getPayload(), headers);
Messaging messaging = messagingProvider.createMessagingHeader(transmissionRequest, new ArrayList<>(Collections.singletonList(attachment)));
UserMessage userMessage = messaging.getUserMessage().get(0);
// MessageInfo
XMLGregorianCalendar timestamp = userMessage.getMessageInfo().getTimestamp();
String messageId = userMessage.getMessageInfo().getMessageId();
Assert.assertNotNull(timestamp);
Assert.assertNotNull(messageId);
// PartyInfo
String to = userMessage.getPartyInfo().getTo().getPartyId().get(0).getValue();
String toType = userMessage.getPartyInfo().getTo().getPartyId().get(0).getType();
String toRole = userMessage.getPartyInfo().getTo().getRole();
String from = userMessage.getPartyInfo().getFrom().getPartyId().get(0).getValue();
String fromType = userMessage.getPartyInfo().getFrom().getPartyId().get(0).getType();
String fromRole = userMessage.getPartyInfo().getFrom().getRole();
Assert.assertEquals(to, RECEIVER);
Assert.assertEquals(toType, PARTY_TYPE);
Assert.assertEquals(toRole, TO_ROLE);
Assert.assertEquals(from, SENDER);
Assert.assertEquals(fromType, PARTY_TYPE);
Assert.assertEquals(fromRole, FROM_ROLE);
// CollaborationInfo
String action = userMessage.getCollaborationInfo().getAction();
Service service = userMessage.getCollaborationInfo().getService();
String conversationId = userMessage.getCollaborationInfo().getConversationId();
Assert.assertEquals(action, ACTION);
Assert.assertEquals(service.getType(), SERVICE_TYPE);
Assert.assertEquals(service.getValue(), SERVICE_VALUE);
Assert.assertNotNull(conversationId);
// MessageProperties
String finalRecipient = userMessage.getMessageProperties().getProperty().stream().filter(p -> "finalRecipient".equalsIgnoreCase(p.getName())).map(Property::getValue).findFirst().get();
String originalSender = userMessage.getMessageProperties().getProperty().stream().filter(p -> "originalSender".equalsIgnoreCase(p.getName())).map(Property::getValue).findFirst().get();
Assert.assertEquals(finalRecipient, FINAL_RECIPIENT);
Assert.assertEquals(originalSender, ORIGINAL_SENDER);
// PayloadInfo
int payloadCount = userMessage.getPayloadInfo().getPartInfo().size();
Assert.assertEquals(payloadCount, 1);
List<Property> partInfo = userMessage.getPayloadInfo().getPartInfo().get(0).getPartProperties().getProperty();
String compressionType = partInfo.stream().filter(pi -> COMPRESSION_TYPE_KEY.equalsIgnoreCase(pi.getName())).map(Property::getValue).findFirst().get();
String mimeType = partInfo.stream().filter(pi -> MIME_TYPE_KEY.equalsIgnoreCase(pi.getName())).map(Property::getValue).findFirst().get();
String contentID = userMessage.getPayloadInfo().getPartInfo().get(0).getHref();
Assert.assertEquals(compressionType, COMPRESSION_TYPE_VALUE);
Assert.assertEquals(mimeType, MIME_TYPE_VALUE);
Assert.assertEquals(contentID, "cid:" + Content_ID_VALUE);
}
Aggregations