Published beat arrives at destination.
diff --git a/component-test/src/main/java/io/mifos/portfolio/TestAccountingInteractionInLoanWorkflow.java b/component-test/src/main/java/io/mifos/portfolio/TestAccountingInteractionInLoanWorkflow.java
index 7ec81c9..d57a5a5 100644
--- a/component-test/src/main/java/io/mifos/portfolio/TestAccountingInteractionInLoanWorkflow.java
+++ b/component-test/src/main/java/io/mifos/portfolio/TestAccountingInteractionInLoanWorkflow.java
@@ -19,6 +19,8 @@
import io.mifos.accounting.api.v1.domain.AccountType;
import io.mifos.accounting.api.v1.domain.Creditor;
import io.mifos.accounting.api.v1.domain.Debtor;
+import io.mifos.core.api.util.ApiFactory;
+import io.mifos.core.lang.DateConverter;
import io.mifos.individuallending.api.v1.domain.caseinstance.CaseParameters;
import io.mifos.individuallending.api.v1.domain.product.ChargeIdentifiers;
import io.mifos.individuallending.api.v1.domain.workflow.Action;
@@ -26,12 +28,18 @@
import io.mifos.portfolio.api.v1.domain.CostComponent;
import io.mifos.portfolio.api.v1.domain.Product;
import io.mifos.portfolio.api.v1.events.EventConstants;
+import io.mifos.rhythm.spi.v1.client.BeatListener;
+import io.mifos.rhythm.spi.v1.domain.BeatPublish;
+import io.mifos.rhythm.spi.v1.events.BeatPublishEvent;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -48,6 +56,8 @@
private static final BigDecimal LOAN_ORIGINATION_FEE_AMOUNT = BigDecimal.valueOf(100_0000, MINOR_CURRENCY_UNIT_DIGITS);
private static final BigDecimal DISBURSEMENT_FEE_AMOUNT = BigDecimal.valueOf(1_0000, MINOR_CURRENCY_UNIT_DIGITS);
+ private BeatListener portfolioBeatListener;
+
private static Product product;
private static Case customerCase;
private static CaseParameters caseParameters;
@@ -55,6 +65,11 @@
private static String customerLoanAccountIdentifier;
+ @Before
+ public void prepBeatListener() {
+ portfolioBeatListener = new ApiFactory(logger).create(BeatListener.class, testEnvironment.serverURI());
+ }
+
@Test
public void step1CreateProduct() throws InterruptedException {
//Create product and set charges to fixed fees.
@@ -154,4 +169,16 @@
AccountingFixture.verifyTransfer(ledgerManager, debtors, creditors);
}
+
+ //Perform daily interest calculation.
+ @Test
+ public void step6CalculateInterestAccrual() throws InterruptedException {
+ final String beatIdentifier = "alignment0";
+ final String midnightTimeStamp = DateConverter.toIsoString(LocalDateTime.now().truncatedTo(ChronoUnit.DAYS));
+
+ final BeatPublish interestBeat = new BeatPublish(beatIdentifier, midnightTimeStamp);
+ portfolioBeatListener.publishBeat(interestBeat);
+ Assert.assertTrue(this.eventRecorder.wait(io.mifos.rhythm.spi.v1.events.EventConstants.POST_PUBLISHEDBEAT,
+ new BeatPublishEvent(EventConstants.DESTINATION, beatIdentifier, midnightTimeStamp)));
+ }
}
\ No newline at end of file
diff --git a/component-test/src/main/java/io/mifos/portfolio/listener/BeatPublishEventListener.java b/component-test/src/main/java/io/mifos/portfolio/listener/BeatPublishEventListener.java
new file mode 100644
index 0000000..7251ff7
--- /dev/null
+++ b/component-test/src/main/java/io/mifos/portfolio/listener/BeatPublishEventListener.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.mifos.portfolio.listener;
+
+import io.mifos.core.lang.config.TenantHeaderFilter;
+import io.mifos.core.test.listener.EventRecorder;
+import io.mifos.rhythm.spi.v1.events.EventConstants;
+import io.mifos.rhythm.spi.v1.events.BeatPublishEvent;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jms.annotation.JmsListener;
+import org.springframework.messaging.handler.annotation.Header;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author Myrle Krantz
+ */
+@SuppressWarnings("unused")
+@Component
+public class BeatPublishEventListener {
+ private final EventRecorder eventRecorder;
+
+ @Autowired
+ public BeatPublishEventListener(final EventRecorder eventRecorder) {
+ super();
+ this.eventRecorder = eventRecorder;
+ }
+
+ @JmsListener(
+ subscription = io.mifos.portfolio.api.v1.events.EventConstants.DESTINATION,
+ destination = io.mifos.portfolio.api.v1.events.EventConstants.DESTINATION,
+ selector = EventConstants.SELECTOR_POST_PUBLISHEDBEAT
+ )
+ public void onPublishBeat(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
+ final String payload) {
+ this.eventRecorder.event(tenant, EventConstants.POST_PUBLISHEDBEAT, payload, BeatPublishEvent.class);
+ }
+}