Wrote first iteration of test for BalanceSegmentSets.
diff --git a/api/src/main/java/io/mifos/portfolio/api/v1/events/BalanceSegmentSetEvent.java b/api/src/main/java/io/mifos/portfolio/api/v1/events/BalanceSegmentSetEvent.java
new file mode 100644
index 0000000..8cbaf75
--- /dev/null
+++ b/api/src/main/java/io/mifos/portfolio/api/v1/events/BalanceSegmentSetEvent.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2017 Kuelap, Inc.
+ *
+ * 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.api.v1.events;
+
+import java.util.Objects;
+
+/**
+ * @author Myrle Krantz
+ */
+public class BalanceSegmentSetEvent {
+ private String productIdentifier;
+ private String balanceSegmentSetIdentifier;
+
+ public BalanceSegmentSetEvent() {
+ }
+
+ public BalanceSegmentSetEvent(String productIdentifier, String balanceSegmentSetIdentifier) {
+ this.productIdentifier = productIdentifier;
+ this.balanceSegmentSetIdentifier = balanceSegmentSetIdentifier;
+ }
+
+ public String getProductIdentifier() {
+ return productIdentifier;
+ }
+
+ public void setProductIdentifier(String productIdentifier) {
+ this.productIdentifier = productIdentifier;
+ }
+
+ public String getBalanceSegmentSetIdentifier() {
+ return balanceSegmentSetIdentifier;
+ }
+
+ public void setBalanceSegmentSetIdentifier(String balanceSegmentSetIdentifier) {
+ this.balanceSegmentSetIdentifier = balanceSegmentSetIdentifier;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ BalanceSegmentSetEvent that = (BalanceSegmentSetEvent) o;
+ return Objects.equals(productIdentifier, that.productIdentifier) &&
+ Objects.equals(balanceSegmentSetIdentifier, that.balanceSegmentSetIdentifier);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(productIdentifier, balanceSegmentSetIdentifier);
+ }
+
+ @Override
+ public String toString() {
+ return "BalanceSegmentSetEvent{" +
+ "productIdentifier='" + productIdentifier + '\'' +
+ ", balanceSegmentSetIdentifier='" + balanceSegmentSetIdentifier + '\'' +
+ '}';
+ }
+}
diff --git a/api/src/main/java/io/mifos/portfolio/api/v1/events/EventConstants.java b/api/src/main/java/io/mifos/portfolio/api/v1/events/EventConstants.java
index 9412d57..4db9c5f 100644
--- a/api/src/main/java/io/mifos/portfolio/api/v1/events/EventConstants.java
+++ b/api/src/main/java/io/mifos/portfolio/api/v1/events/EventConstants.java
@@ -29,6 +29,9 @@
String PUT_PRODUCT_ENABLE = "put-enable";
String POST_CASE = "post-case";
String PUT_CASE = "put-case";
+ String POST_BALANCE_SEGMENT_SET = "post-balance-segment-set";
+ String PUT_BALANCE_SEGMENT_SET = "put-balance-segment-set";
+ String DELETE_BALANCE_SEGMENT_SET = "delete-balance-segment-set";
String POST_TASK_DEFINITION = "post-task-definition";
String PUT_TASK_DEFINITION = "put-task-definition";
String DELETE_TASK_DEFINITION = "delete-task-definition";
@@ -44,6 +47,9 @@
String SELECTOR_PUT_PRODUCT_ENABLE = SELECTOR_NAME + " = '" + PUT_PRODUCT_ENABLE + "'";
String SELECTOR_POST_CASE = SELECTOR_NAME + " = '" + POST_CASE + "'";
String SELECTOR_PUT_CASE = SELECTOR_NAME + " = '" + PUT_CASE + "'";
+ String SELECTOR_POST_BALANCE_SEGMENT_SET = SELECTOR_NAME + " = '" + POST_BALANCE_SEGMENT_SET + "'";
+ String SELECTOR_PUT_BALANCE_SEGMENT_SET = SELECTOR_NAME + " = '" + PUT_BALANCE_SEGMENT_SET + "'";
+ String SELECTOR_DELETE_BALANCE_SEGMENT_SET = SELECTOR_NAME + " = '" + DELETE_BALANCE_SEGMENT_SET + "'";
String SELECTOR_POST_TASK_DEFINITION = SELECTOR_NAME + " = '" + POST_TASK_DEFINITION + "'";
String SELECTOR_PUT_TASK_DEFINITION = SELECTOR_NAME + " = '" + PUT_TASK_DEFINITION + "'";
String SELECTOR_DELETE_TASK_DEFINITION = SELECTOR_NAME + " = '" + DELETE_TASK_DEFINITION + "'";
diff --git a/component-test/src/main/java/io/mifos/portfolio/TestBalanceSegmentSets.java b/component-test/src/main/java/io/mifos/portfolio/TestBalanceSegmentSets.java
new file mode 100644
index 0000000..001be34
--- /dev/null
+++ b/component-test/src/main/java/io/mifos/portfolio/TestBalanceSegmentSets.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2017 Kuelap, Inc.
+ *
+ * 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;
+
+import io.mifos.portfolio.api.v1.client.ProductInUseException;
+import io.mifos.portfolio.api.v1.domain.BalanceSegmentSet;
+import io.mifos.portfolio.api.v1.domain.Product;
+import io.mifos.portfolio.api.v1.events.BalanceSegmentSetEvent;
+import io.mifos.portfolio.api.v1.events.EventConstants;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.TreeSet;
+
+/**
+ * @author Myrle Krantz
+ */
+public class TestBalanceSegmentSets extends AbstractPortfolioTest {
+ @Test
+ public void test() throws InterruptedException {
+ final Product product = createProduct();
+
+ final BalanceSegmentSet balanceSegmentSet = new BalanceSegmentSet();
+ balanceSegmentSet.setIdentifier(testEnvironment.generateUniqueIdentifer("bss"));
+ balanceSegmentSet.setSegments(new TreeSet<>(Arrays.asList(BigDecimal.TEN, BigDecimal.valueOf(10_000))));
+ balanceSegmentSet.setSegmentIdentifiers(Arrays.asList("a", "b", "c"));
+
+ portfolioManager.createBalanceSegmentSet(product.getIdentifier(), balanceSegmentSet);
+ Assert.assertTrue(this.eventRecorder.wait(EventConstants.POST_BALANCE_SEGMENT_SET, new BalanceSegmentSetEvent(product.getIdentifier(), balanceSegmentSet.getIdentifier())));
+
+ final BalanceSegmentSet createdBalanceSegmentSet = portfolioManager.getBalanceSegmentSet(product.getIdentifier(), balanceSegmentSet.getIdentifier());
+ Assert.assertEquals(balanceSegmentSet, createdBalanceSegmentSet);
+
+ balanceSegmentSet.setSegments(new TreeSet<>(Arrays.asList(BigDecimal.valueOf(100), BigDecimal.valueOf(10_000))));
+ balanceSegmentSet.setSegmentIdentifiers(Arrays.asList("a", "b", "c"));
+
+ portfolioManager.changeBalanceSegmentSet(product.getIdentifier(), balanceSegmentSet.getIdentifier(), balanceSegmentSet);
+ Assert.assertTrue(this.eventRecorder.wait(EventConstants.PUT_BALANCE_SEGMENT_SET, new BalanceSegmentSetEvent(product.getIdentifier(), balanceSegmentSet.getIdentifier())));
+
+ final BalanceSegmentSet changedBalanceSegmentSet = portfolioManager.getBalanceSegmentSet(product.getIdentifier(), balanceSegmentSet.getIdentifier());
+ Assert.assertEquals(balanceSegmentSet, changedBalanceSegmentSet);
+
+ portfolioManager.deleteBalanceSegmentSet(product.getIdentifier(), balanceSegmentSet.getIdentifier());
+ Assert.assertTrue(this.eventRecorder.wait(EventConstants.DELETE_BALANCE_SEGMENT_SET, new BalanceSegmentSetEvent(product.getIdentifier(), balanceSegmentSet.getIdentifier())));
+
+ enableProduct(product);
+
+ createCase(product.getIdentifier());
+
+ try {
+ portfolioManager.createBalanceSegmentSet(product.getIdentifier(), balanceSegmentSet);
+ Assert.fail("shouldn't be able to create a balance segment set in a product in use.");
+ }
+ catch (final ProductInUseException ignored) { }
+ }
+}
diff --git a/component-test/src/main/java/io/mifos/portfolio/TestSuite.java b/component-test/src/main/java/io/mifos/portfolio/TestSuite.java
index e7bd386..44d8cc3 100644
--- a/component-test/src/main/java/io/mifos/portfolio/TestSuite.java
+++ b/component-test/src/main/java/io/mifos/portfolio/TestSuite.java
@@ -24,6 +24,7 @@
@RunWith(Suite.class)
@Suite.SuiteClasses({
TestAccountingInteractionInLoanWorkflow.class,
+ TestBalanceSegmentSets.class,
TestCases.class,
TestChargeDefinitions.class,
TestCommands.class,
diff --git a/component-test/src/main/java/io/mifos/portfolio/listener/BalanceSegmentSetEventListener.java b/component-test/src/main/java/io/mifos/portfolio/listener/BalanceSegmentSetEventListener.java
new file mode 100644
index 0000000..528fc7c
--- /dev/null
+++ b/component-test/src/main/java/io/mifos/portfolio/listener/BalanceSegmentSetEventListener.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2017 Kuelap, Inc.
+ *
+ * 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.portfolio.api.v1.events.BalanceSegmentSetEvent;
+import io.mifos.portfolio.api.v1.events.EventConstants;
+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
+ */
+@Component
+public class BalanceSegmentSetEventListener {
+ private final EventRecorder eventRecorder;
+
+ @SuppressWarnings("SpringJavaAutowiringInspection")
+ @Autowired
+ public BalanceSegmentSetEventListener(final EventRecorder eventRecorder) {
+ super();
+ this.eventRecorder = eventRecorder;
+ }
+
+ @JmsListener(
+ subscription = EventConstants.DESTINATION,
+ destination = EventConstants.DESTINATION,
+ selector = EventConstants.SELECTOR_POST_BALANCE_SEGMENT_SET
+ )
+ public void onCreateBalanceSegmentSet(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
+ final String payload) {
+ this.eventRecorder.event(tenant, EventConstants.POST_BALANCE_SEGMENT_SET, payload, BalanceSegmentSetEvent.class);
+ }
+
+ @JmsListener(
+ subscription = EventConstants.DESTINATION,
+ destination = EventConstants.DESTINATION,
+ selector = EventConstants.SELECTOR_PUT_BALANCE_SEGMENT_SET
+ )
+ public void onChangeBalanceSegmentSet(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
+ final String payload) {
+ this.eventRecorder.event(tenant, EventConstants.PUT_BALANCE_SEGMENT_SET, payload, BalanceSegmentSetEvent.class);
+ }
+
+ @JmsListener(
+ subscription = EventConstants.DESTINATION,
+ destination = EventConstants.DESTINATION,
+ selector = EventConstants.SELECTOR_DELETE_BALANCE_SEGMENT_SET
+ )
+ public void onDeleteBalanceSegmentSet(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
+ final String payload) {
+ this.eventRecorder.event(tenant, EventConstants.DELETE_BALANCE_SEGMENT_SET, payload, BalanceSegmentSetEvent.class);
+ }
+}
\ No newline at end of file