Search in sources :

Example 1 with MessageBody

use of com.iluwatar.claimcheckpattern.domain.MessageBody in project java-design-patterns by iluwatar.

the class UsageCostProcessorFunctionTest method setUp.

@BeforeEach
public void setUp() {
    var messageBodyUsageDetail = new MessageBody<UsageDetail>();
    var usageDetailsList = new ArrayList<UsageDetail>();
    var messageBodyUsageCostDetail = new MessageBody<UsageCostDetail>();
    var usageCostDetailsList = new ArrayList<UsageCostDetail>();
    for (int i = 0; i < 2; i++) {
        var usageDetail = new UsageDetail();
        usageDetail.setUserId("userId" + i);
        usageDetail.setData(i + 1);
        usageDetail.setDuration(i + 1);
        usageDetailsList.add(usageDetail);
        var usageCostDetail = new UsageCostDetail();
        usageCostDetail.setUserId(usageDetail.getUserId());
        usageCostDetail.setDataCost(usageDetail.getData() * 0.20);
        usageCostDetail.setCallCost(usageDetail.getDuration() * 0.30);
        usageCostDetailsList.add(usageCostDetail);
    }
    messageBodyUsageDetail.setData(usageDetailsList);
    messageBodyUsageCostDetail.setData(usageCostDetailsList);
    // Create message header
    var messageHeader = new MessageHeader();
    messageHeader.setId(UUID.randomUUID().toString());
    messageHeader.setSubject("UsageDetailPublisher");
    messageHeader.setTopic("usagecostprocessorfunction-topic");
    messageHeader.setEventType("UsageDetail");
    messageHeader.setEventTime(OffsetDateTime.now().toString());
    this.messageReference = new MessageReference("callusageapp", "d8284456-dfff-4bd4-9cef-ea99f70f4835/input.json");
    messageHeader.setData(messageReference);
    messageHeader.setDataVersion("v1.0");
    // Create entire message
    messageToRead = new Message<>();
    messageToRead.setMessageHeader(messageHeader);
    messageToRead.setMessageBody(messageBodyUsageDetail);
    messageToDrop = new Message<>();
    messageToDrop.setMessageHeader(messageHeader);
    messageToDrop.setMessageBody(messageBodyUsageCostDetail);
}
Also used : UsageDetail(com.iluwatar.claimcheckpattern.domain.UsageDetail) MessageHeader(com.iluwatar.claimcheckpattern.domain.MessageHeader) UsageCostDetail(com.iluwatar.claimcheckpattern.domain.UsageCostDetail) MessageReference(com.iluwatar.claimcheckpattern.domain.MessageReference) MessageBody(com.iluwatar.claimcheckpattern.domain.MessageBody) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

MessageBody (com.iluwatar.claimcheckpattern.domain.MessageBody)1 MessageHeader (com.iluwatar.claimcheckpattern.domain.MessageHeader)1 MessageReference (com.iluwatar.claimcheckpattern.domain.MessageReference)1 UsageCostDetail (com.iluwatar.claimcheckpattern.domain.UsageCostDetail)1 UsageDetail (com.iluwatar.claimcheckpattern.domain.UsageDetail)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1