Skip to content
Permalink
Browse files
Merge branch 'develop' into FINCN-156
  • Loading branch information
ebenezergraham committed Jun 6, 2019
2 parents 13a1f55 + 6250a32 commit 339f83f092537b7fe976b10ae661831b4e98e61d
Showing 18 changed files with 217 additions and 97 deletions.
@@ -27,4 +27,8 @@ env:
- BUILD_SNAPSHOTS_BRANCH=develop
- ARTIFACTORY_URL=https://mifos.jfrog.io/mifos
- ARTIFACTORY_USER=travis-ci
- secure: "E5IyImya7x5cHLB1vGLGIJUC1M+7RxKZivb5iUM+RR/xW39/7b4Qd3JeX4yBUeiPjf9lNMMxcGVyqI/4htT95++WCNc0u6OoxwGgxQEB9JHE8OWecaYgK4uLO7+651XF4DNbSiH3NVmc2b8Q0c0jBlu3MHAeEUIQ6BOiTXSsqnewtWAW0XETBooNmo2nTqZyKvzez0698oJuuYfZeFbqm8wJ9rIwtptyJluRzqcTlzw1cH/CvcIskLDmITVqbuZxAW59j1BqUnZNQpuOFZ692iqntdxq78CxliCG1MEYy4zWY8xcIWNVp28OKkMULXdi+V80oZXY4TyTwZfH6e2oZFz6/X9GpNNR6EwaHV0tT3wZi2NrkoBokD8bEBxQubIgxDCaDAFG9VMByC+++nwm0GJzerKBV4CpNSy/93XLrFAQ8+lOVauVtkVHuzFBWleLLQYcBGAXRz/C/UF4/m0m014jvD7vTP5kKrszQB5uKSG6sG7sWAPs/K8ISFV4qjIW8yVy889wSkzsyI5pO3MxIz7L5XOk4bvr+UD8M6ruiBpzvw6YZbA3K8Ld9d6NifSGu5gAcNXllyG3Aff3ZEqIxwPmmkxEtt05EHuSC+JNxOTC5kOVt9S4OLSMj17kT3ucA2yXoMoFr41cBc05Jxatf3vvt1GbdRbM/tFqp9ac8wo="
- secure: "NHjl/OM08+Q8zRXH1GRowPmFTCarpZVgpfzvW23DnHI9kwPcAuvXHUs0liBD1FgUr3oFNlIQ8QknlWSAb2yI9CTs/+v6f7wl4t4Xx4t5gV0wFuffb3W7a41bE+m1OSUunleSGLKr4qGffjPQ63EUyAb4wrywg23iY12OHbQ3a988UvqoDg6IjK7NXKeLhkAXg6qLDRh9aHdM6NknFNUUIbYyX25PMTQj/SShDQ3xptOhrj1wOvKbBEBc2t2X4+0/3pKt36W0VwJt68HPL4YKwFNiErqSXDAmKFwcf/aZxlXAGreCYN9rNuGuP5RMpblY1bNi6sW2COG0IgTjNSvQgULfIb42GI68O9w0supKZ8OKQLnDJDIQ5q1A1rE54bqs1ey8WD9bmwc24NTUkmjKTqDMTMqCLE+gXLM7xnS2JNisOETfEfRughUFBvmHVPgnQ6fCDJ0brPWBO9Se/elPP/XWlWAkdXsynrRueGCuhplUg1dQhrWm6zSLX5VDeaqQ1vbiU5y3QpAYjJUV/HLk3J8v3Lgv4maUWzyr1Law8K9pAPMcTA2UZR6NsrgWTAsV2mSuRc+Xyf1aGpMqNMaqOHlvfJuY6DobJxdy62LjgF4ovQNY8lVSp5aVDs4TAAQBvMlyVKfJyNJLGuPOjdYkjidm9lWxjX81Y4t1Yg4khL4="

after_failure:
- ./gradlew rat
- cat api/build/reports/rat/rat-report.txt
@@ -18,7 +18,7 @@
#
FROM openjdk:8-jdk-alpine

ARG notification_port=2033
ARG notification_port=2031

ENV server.max-http-header-size=16384 \
cassandra.clusterName="Test Cluster" \
@@ -28,4 +28,4 @@ ENV server.max-http-header-size=16384 \
WORKDIR /tmp
COPY notification-service-boot-0.1.0-BUILD-SNAPSHOT.jar .

CMD ["java", "-jar", "customer-service-boot-0.1.0-BUILD-SNAPSHOT.jar"]
CMD ["java", "-jar", "notification-service-boot-0.1.0-BUILD-SNAPSHOT.jar"]
@@ -1,6 +1,7 @@
# Apache Fineract CN Notification [![Build Status](https://api.travis-ci.com/apache/fineract-cn-notification.svg?branch=develop)](https://travis-ci.com/apache/fineract-cn-notification)

This mircroservice contains all the functionalities for SMS and Email Notification
# Apache Fineract CN Notification [![Build Status](https://api.travis-ci.com/apache/fineract-cn-notifications.svg?branch=develop)](https://travis-ci.com/apache/fineract-cn-notifications)

This mircroservice implements SMS and Email Notification functionalities

## Abstract
Apache Fineract CN is an application framework for digital financial services, a system to support nationwide and cross-national financial transactions and help to level and speed the creation of an inclusive, interconnected digital economy for every nation in the world.
@@ -74,6 +74,9 @@ public interface NotificationManager {
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE
)
@ThrowsExceptions({
@ThrowsException(status = HttpStatus.UNPROCESSABLE_ENTITY, exception = TemplateAlreadyExistException.class)
})
String createTemplate(final Template template);

@RequestMapping(
@@ -36,8 +36,8 @@ public interface NotificationEventConstants {
String DELETE_TEMPLATE = "delete-template";
String DELETE_SOURCE_APPLICATION = "delete-source-application";

String POST_SEND_EMAIL_NOTIFICATION = "post-send-email-notification";
String POST_SEND_SMS_NOTIFICATION = "post-send-sms-notification";
String SEND_EMAIL_NOTIFICATION = "post-send-email-notification";
String SEND_SMS_NOTIFICATION = "post-send-sms-notification";

String POST_ENABLE_CUSTOMER_CREATED_EVENT = "post-enable-customer-created-event";
String POST_ENABLE_CUSTOMER_UPDATED_EVENT = "post-enable-customer-updated-event";
@@ -57,6 +57,6 @@ public interface NotificationEventConstants {
String SELECTOR_POST_SOURCE_APPLICATION = SELECTOR_NAME + " = '" + POST_SOURCE_APPLICATION + "'";
String SELECTOR_DELETE_SOURCE_APPLICATION = SELECTOR_NAME + " = '" + DELETE_SOURCE_APPLICATION + "'";

String SELECTOR_POST_SEND_EMAIL_NOTIFICATION = SELECTOR_NAME + " = '" + POST_SEND_EMAIL_NOTIFICATION + "'";
String SELECTOR_POST_SEND_SMS_NOTIFICATION = SELECTOR_NAME + " = '" + POST_SEND_SMS_NOTIFICATION + "'";
String SELECTOR_SEND_EMAIL_NOTIFICATION = SELECTOR_NAME + " = '" + SEND_EMAIL_NOTIFICATION + "'";
String SELECTOR_SEND_SMS_NOTIFICATION = SELECTOR_NAME + " = '" + SEND_SMS_NOTIFICATION + "'";
}
@@ -54,7 +54,7 @@ public class AbstractNotificationTest extends SuiteTestEnvironment {
public static final String LOGGER_NAME = "test-logger";
public static final String TEST_USER = "homer";
public static final String TEST_ADDRESS = "egraham15@alustudent.com";
public static final String TEST_TEMPLATE= "test_sample";
public static final String TEST_TEMPLATE= "sample";

@SuppressWarnings("WeakerAccess")
@Autowired
@@ -64,7 +64,7 @@ public class AbstractNotificationTest extends SuiteTestEnvironment {
@Autowired
public EventRecorder eventRecorder;
@Autowired
public NotificationManager testSubject;
public NotificationManager notificationManager;
@Autowired
public NotificationService notificationService;

@@ -49,33 +49,19 @@ public TestEmailService() {
emailConfiguration = DomainObjectGenerator.emailConfiguration();
}


@Test
public void shouldSendAnEmail() throws InterruptedException, IOException {
public void shouldSendAnEmail() throws InterruptedException,IOException {
this.logger.info("Send Email Notification");
final TemplateImporter importer = new TemplateImporter(testSubject, logger);
final URL uri = ClassLoader.getSystemResource("importdata/test-templates.csv");
importer.importCSV(uri);
// Assert.assertTrue(eventRecorder.wait(NotificationEventConstants.POST_TEMPLATE, TEST_TEMPLATE));
eventRecorder.wait(NotificationEventConstants.POST_TEMPLATE, TEST_TEMPLATE);

notificationService.sendEmail(
TEST_ADDRESS,
TEST_TEMPLATE,
null);
//Assert.assertTrue(this.eventRecorder.wait(NotificationEventConstants.POST_SEND_EMAIL_NOTIFICATION,TEST_ADDRESS ));
this.eventRecorder.wait(NotificationEventConstants.POST_SEND_EMAIL_NOTIFICATION,TEST_ADDRESS );
//Assert.assertTrue(this.eventRecorder.wait(NotificationEventConstants.SEND_EMAIL_NOTIFICATION,TEST_ADDRESS ));
}

@Test
public void shouldSendFormattedEmail() throws InterruptedException, IOException {
this.logger.info("Send Email Notification");
final TemplateImporter importer = new TemplateImporter(testSubject, logger);
final URL uri = ClassLoader.getSystemResource("importdata/test-templates.csv");
importer.importCSV(uri);

//Assert.assertTrue(eventRecorder.wait(NotificationEventConstants.POST_TEMPLATE, TEST_TEMPLATE));
eventRecorder.wait(NotificationEventConstants.POST_TEMPLATE, TEST_TEMPLATE);

Customer customerPayload = new Customer();
customerPayload.setGivenName("Test");
@@ -98,15 +84,14 @@ public void shouldSendFormattedEmail() throws InterruptedException, IOException
templateVariables
);

//Assert.assertTrue(this.eventRecorder.wait(NotificationEventConstants.POST_SEND_EMAIL_NOTIFICATION,TEST_ADDRESS ));
this.eventRecorder.wait(NotificationEventConstants.POST_SEND_EMAIL_NOTIFICATION,TEST_ADDRESS );
//Assert.assertTrue(this.eventRecorder.wait(NotificationEventConstants.SEND_EMAIL_NOTIFICATION,TEST_ADDRESS ));
}

@Test(expected = NotFoundException.class)
public void emailConfigurationNotFound() throws ConfigurationNotFoundException {
logger.info("Configuration not found");
try {
this.testSubject.findEmailConfigurationByIdentifier(RandomStringUtils.randomAlphanumeric(8));
notificationManager.findEmailConfigurationByIdentifier(RandomStringUtils.randomAlphanumeric(8));
} catch (final ConfigurationNotFoundException ex) {
logger.info("Error Asserted");
}
@@ -115,21 +100,19 @@ public void emailConfigurationNotFound() throws ConfigurationNotFoundException {
@Test
public void shouldCreateAndRetrieveEmailConfigurationEntity() throws InterruptedException {
logger.info("Create and Retrieve Email Gateway configuration");
this.testSubject.createEmailConfiguration(emailConfiguration);
notificationManager.createEmailConfiguration(emailConfiguration);

this.eventRecorder.wait(NotificationEventConstants.POST_EMAIL_CONFIGURATION, emailConfiguration.getIdentifier());
Assert.assertTrue(this.eventRecorder.wait(NotificationEventConstants.POST_EMAIL_CONFIGURATION, emailConfiguration.getIdentifier()));

EmailConfiguration sampleRetrieved = this.testSubject.findEmailConfigurationByIdentifier(emailConfiguration.getIdentifier());
Assert.assertNotNull(sampleRetrieved);
Assert.assertEquals(sampleRetrieved.getIdentifier(), emailConfiguration.getIdentifier());
EmailConfiguration sampleRetrieved = notificationManager.findEmailConfigurationByIdentifier(emailConfiguration.getIdentifier());
Assert.assertEquals(sampleRetrieved.getIdentifier(),emailConfiguration.getIdentifier());
}

@Test
public void checkEmailConfigurationEntityExist() throws InterruptedException {
logger.info("Email Gateway configuration Exist");
this.testSubject.createEmailConfiguration(emailConfiguration);
super.eventRecorder.wait(NotificationEventConstants.POST_EMAIL_CONFIGURATION, emailConfiguration.getIdentifier());

notificationManager.createEmailConfiguration(emailConfiguration);
Assert.assertTrue(eventRecorder.wait(NotificationEventConstants.POST_EMAIL_CONFIGURATION, emailConfiguration.getIdentifier()));
Assert.assertTrue(this.emailService.emailConfigurationExists(emailConfiguration.getIdentifier()));
}

@@ -59,10 +59,9 @@ public void shouldCreateAndRetrieveSMSConfigurationEntity() throws InterruptedEx
logger.info("Create and Retrieve SMS Gateway configuration");
this.notificationManager.createSMSConfiguration(smsConfiguration);

this.eventRecorder.wait(NotificationEventConstants.POST_SMS_CONFIGURATION, smsConfiguration.getIdentifier());
Assert.assertTrue(this.eventRecorder.wait(NotificationEventConstants.POST_SMS_CONFIGURATION, smsConfiguration.getIdentifier()));

SMSConfiguration sampleRetrieved = this.notificationManager.findSMSConfigurationByIdentifier(smsConfiguration.getIdentifier());
Assert.assertNotNull(sampleRetrieved);
Assert.assertEquals(sampleRetrieved.getIdentifier(), smsConfiguration.getIdentifier());
}

@@ -83,10 +82,10 @@ public void checkIfConfigurationAlreadyExists() throws InterruptedException{
}

@Test
public void shouldSendAnSMS() {
public void shouldSendAnSMS(){
this.logger.info("Send SMS Notification");
String messageHash = this.notificationService.sendSMS("+23058409206",
String to = this.notificationService.sendSMS("+23058409206",
"Dear Valued Customer\n\nTalk is cheap show me the code\n\nBest Regards\nYour MFI");
Assert.assertNotNull(messageHash);
Assert.assertNotNull(to);
}
}
@@ -44,14 +44,12 @@ public void testTemplateImportHappyCase() throws IOException, InterruptedExcepti
template.setMessage("Message");
template.setUrl("test/url");

testSubject.createTemplate(template);
//Assert.assertTrue(eventRecorder.wait(NotificationEventConstants.POST_TEMPLATE, template.getTemplateIdentifier()));
eventRecorder.wait(NotificationEventConstants.POST_TEMPLATE, template.getTemplateIdentifier());
notificationManager.createTemplate(template);
Assert.assertTrue(eventRecorder.wait(NotificationEventConstants.POST_TEMPLATE, template.getTemplateIdentifier()));

final TemplateImporter importer = new TemplateImporter(testSubject, logger);
final TemplateImporter importer = new TemplateImporter(notificationManager, logger);
final URL uri = ClassLoader.getSystemResource("importdata/test-templates.csv");
importer.importCSV(uri);
//Assert.assertTrue(eventRecorder.wait(NotificationEventConstants.POST_TEMPLATE, "sample"));
eventRecorder.wait(NotificationEventConstants.POST_TEMPLATE, "sample");
Assert.assertTrue(eventRecorder.wait(NotificationEventConstants.POST_TEMPLATE, "test_sample"));
}
}
@@ -0,0 +1,153 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.fineract.cn.notification.listener;

import org.apache.fineract.cn.lang.config.TenantHeaderFilter;
import org.apache.fineract.cn.notification.api.v1.events.NotificationEventConstants;
import org.apache.fineract.cn.notification.service.ServiceConstants;
import org.apache.fineract.cn.test.listener.EventRecorder;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

@SuppressWarnings("unused")
@Component
public class EventListener {
private final EventRecorder eventRecorder;
private final Logger logger;

@Autowired
public EventListener(final EventRecorder eventRecorder,
@Qualifier(ServiceConstants.LOGGER_NAME) final Logger logger) {
this.logger = logger;
this.eventRecorder = eventRecorder;
}

@JmsListener(
subscription = NotificationEventConstants.DESTINATION,
destination = NotificationEventConstants.DESTINATION,
selector = NotificationEventConstants.SELECTOR_POST_EMAIL_CONFIGURATION
)
public void postEmailConfiguration(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.eventRecorder.event(tenant, NotificationEventConstants.POST_EMAIL_CONFIGURATION, payload, String.class);
}

@JmsListener(
subscription = NotificationEventConstants.DESTINATION,
destination = NotificationEventConstants.DESTINATION,
selector = NotificationEventConstants.SELECTOR_POST_SMS_CONFIGURATION
)
public void postSMSConfiguration(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.eventRecorder.event(tenant, NotificationEventConstants.POST_SMS_CONFIGURATION, payload, String.class);
}

@JmsListener(
subscription = NotificationEventConstants.DESTINATION,
destination = NotificationEventConstants.DESTINATION,
selector = NotificationEventConstants.SELECTOR_SEND_EMAIL_NOTIFICATION
)
public void onSendEmailTrigger(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.eventRecorder.event(tenant, NotificationEventConstants.SEND_EMAIL_NOTIFICATION, payload, String.class);
}

@JmsListener(
subscription = NotificationEventConstants.DESTINATION,
destination = NotificationEventConstants.DESTINATION,
selector = NotificationEventConstants.SELECTOR_SEND_SMS_NOTIFICATION
)
public void onSendSmsTrigger(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.eventRecorder.event(tenant, NotificationEventConstants.SEND_SMS_NOTIFICATION, payload, String.class);
}

@JmsListener(
subscription = NotificationEventConstants.DESTINATION,
destination = NotificationEventConstants.DESTINATION,
selector = NotificationEventConstants.SELECTOR_DELETE_EMAIL_CONFIGURATION
)
public void onDeleteEmailConfiguration(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.eventRecorder.event(tenant, NotificationEventConstants.DELETE_EMAIL_CONFIGURATION, payload, String.class);
}

@JmsListener(
subscription = NotificationEventConstants.DESTINATION,
destination = NotificationEventConstants.DESTINATION,
selector = NotificationEventConstants.SELECTOR_DELETE_SMS_CONFIGURATION
)
public void onDeleteSmsConfiguration(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.eventRecorder.event(tenant, NotificationEventConstants.DELETE_SMS_CONFIGURATION, payload, String.class);
}

@JmsListener(
subscription = NotificationEventConstants.DESTINATION,
destination = NotificationEventConstants.DESTINATION,
selector = NotificationEventConstants.SELECTOR_UPDATE_EMAIL_CONFIGURATION
)
public void onUpdateEmailConfiguration(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.eventRecorder.event(tenant, NotificationEventConstants.UPDATE_EMAIL_CONFIGURATION, payload, String.class);
}

@JmsListener(
subscription = NotificationEventConstants.DESTINATION,
destination = NotificationEventConstants.DESTINATION,
selector = NotificationEventConstants.SELECTOR_UPDATE_SMS_CONFIGURATION
)
public void onUpdateSmsConfiguration(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.eventRecorder.event(tenant, NotificationEventConstants.UPDATE_SMS_CONFIGURATION, payload, String.class);
}

@JmsListener(
subscription = NotificationEventConstants.DESTINATION,
destination = NotificationEventConstants.DESTINATION,
selector = NotificationEventConstants.SELECTOR_POST_TEMPLATE
)
public void onPostTemplate(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.eventRecorder.event(tenant, NotificationEventConstants.POST_TEMPLATE, payload, String.class);
}

}
@@ -1,20 +1,2 @@
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you 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.
-
template_identifier,sender_email,subject,message,url
test_sample,DEFAULT,Test Sample,This is a test message,template

0 comments on commit 339f83f

Please sign in to comment.