You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by aw...@apache.org on 2019/06/06 07:10:09 UTC
[fineract-cn-notifications] 18/36: Document the notifications
service
This is an automated email from the ASF dual-hosted git repository.
awasum pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-notifications.git
commit 6063af7975bae9defbfd1bb6b108e82fda3d4fef
Author: Isaac Kamga <u2...@gmail.com>
AuthorDate: Wed Jan 2 21:52:06 2019 +0100
Document the notifications service
---
component-test/build.gradle | 11 ++
...fication.java => AbstractNotificationTest.java} | 8 +-
.../cn/notification/EmailApiDocumentation.java | 128 +++++++++++++++++++++
.../cn/notification/SmsApiDocumentation.java | 118 +++++++++++++++++++
.../fineract/cn/notification/TestEmailService.java | 2 +-
.../fineract/cn/notification/TestSMSService.java | 3 +-
.../service/listener/CustomerEventListener.java | 18 +++
7 files changed, 281 insertions(+), 7 deletions(-)
diff --git a/component-test/build.gradle b/component-test/build.gradle
index 2e29cf4..55f1d42 100644
--- a/component-test/build.gradle
+++ b/component-test/build.gradle
@@ -26,6 +26,7 @@ buildscript {
dependencies {
classpath ("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
+ classpath("org.asciidoctor:asciidoctor-gradle-plugin:1.5.3")
}
}
@@ -34,6 +35,7 @@ plugins {
id("org.nosphere.apache.rat") version "0.3.1"
}
apply from: '../shared.gradle'
+apply plugin: 'org.asciidoctor.convert'
dependencies {
compile(
@@ -44,9 +46,18 @@ dependencies {
[group: 'org.apache.fineract.cn', name: 'test', version: versions.frameworktest],
[group: 'org.apache.fineract.cn', name: 'lang', version: versions.frameworklang],
[group: 'org.springframework.boot', name: 'spring-boot-starter-test'],
+ [group: 'org.springframework.restdocs', name: 'spring-restdocs-mockmvc'],
+ [group: 'junit', name: 'junit', version: '4.12']
)
}
+asciidoctor {
+ sourceDir 'build/doc/asciidoc/'
+ outputDir 'build/doc/html5'
+ options backend: "html", doctype: "book"
+ attributes "source-highlighter": "highlightjs", 'snippets': file('build/doc/generated-snippets/')
+}
+
publishing {
publications {
mavenJava(MavenPublication) {
diff --git a/component-test/src/main/java/org/apache/fineract/cn/notification/TestNotification.java b/component-test/src/main/java/org/apache/fineract/cn/notification/AbstractNotificationTest.java
similarity index 95%
rename from component-test/src/main/java/org/apache/fineract/cn/notification/TestNotification.java
rename to component-test/src/main/java/org/apache/fineract/cn/notification/AbstractNotificationTest.java
index 6a6bf6b..545d4f5 100644
--- a/component-test/src/main/java/org/apache/fineract/cn/notification/TestNotification.java
+++ b/component-test/src/main/java/org/apache/fineract/cn/notification/AbstractNotificationTest.java
@@ -47,8 +47,8 @@ import java.security.interfaces.RSAPrivateKey;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
- classes = {TestNotification.TestConfiguration.class})
-public class TestNotification extends SuiteTestEnvironment {
+ classes = {AbstractNotificationTest.TestConfiguration.class})
+public class AbstractNotificationTest extends SuiteTestEnvironment {
@ClassRule
public final static TenantDataStoreContextTestRule tenantDataStoreContext = TenantDataStoreContextTestRule.forRandomTenantName(cassandraInitializer, mariaDBInitializer);
@@ -65,13 +65,13 @@ public class TestNotification extends SuiteTestEnvironment {
public final TenantApplicationSecurityEnvironmentTestRule tenantApplicationSecurityEnvironment
= new TenantApplicationSecurityEnvironmentTestRule(testEnvironment, this::waitForInitialize);
- public TestNotification() {
+ public AbstractNotificationTest() {
super();
}
@Before
public void prepTest() {
- userContext = tenantApplicationSecurityEnvironment.createAutoUserContext(TestNotification.TEST_USER);
+ userContext = tenantApplicationSecurityEnvironment.createAutoUserContext(AbstractNotificationTest.TEST_USER);
final RSAPrivateKey tenantPrivateKey = tenantApplicationSecurityEnvironment.getSystemSecurityEnvironment().tenantPrivateKey();
logger.info("tenantPrivateKey = {}", tenantPrivateKey);
}
diff --git a/component-test/src/main/java/org/apache/fineract/cn/notification/EmailApiDocumentation.java b/component-test/src/main/java/org/apache/fineract/cn/notification/EmailApiDocumentation.java
new file mode 100644
index 0000000..1632f0c
--- /dev/null
+++ b/component-test/src/main/java/org/apache/fineract/cn/notification/EmailApiDocumentation.java
@@ -0,0 +1,128 @@
+/*
+ * 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;
+
+import com.google.gson.Gson;
+import org.apache.commons.lang.RandomStringUtils;
+import org.apache.fineract.cn.notification.api.v1.client.NotificationManager;
+import org.apache.fineract.cn.notification.api.v1.domain.EmailConfiguration;
+import org.apache.fineract.cn.notification.api.v1.events.NotificationEventConstants;
+import org.apache.fineract.cn.notification.util.DomainObjectGenerator;
+import org.apache.fineract.cn.test.listener.EventRecorder;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
+import org.springframework.restdocs.JUnitRestDocumentation;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import org.springframework.web.context.WebApplicationContext;
+
+import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
+import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
+import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
+import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
+import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
+import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
+import static org.springframework.restdocs.payload.PayloadDocumentation.*;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+public class EmailApiDocumentation extends AbstractNotificationTest {
+ @Rule
+ public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("build/doc/generated-snippets/document-email");
+
+ @Autowired
+ private WebApplicationContext context;
+
+ private MockMvc mockMvc;
+
+ @Autowired
+ private NotificationManager notificationManager;
+
+ @Autowired
+ private EventRecorder eventRecorder;
+
+ @Before
+ public void setUp() {
+
+ this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
+ .apply(documentationConfiguration(this.restDocumentation))
+ .build();
+ }
+
+ @Test
+ public void documentCreateEmailConfiguration() throws Exception {
+ final EmailConfiguration emailConfiguration = DomainObjectGenerator.emailConfiguration();
+
+ Gson gson = new Gson();
+ this.mockMvc.perform(post("/notification/email/create")
+ .accept(MediaType.APPLICATION_JSON_VALUE)
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .content(gson.toJson(emailConfiguration)))
+ .andExpect(status().isAccepted())
+ .andDo(document("document-create-emailconfiguration", preprocessRequest(prettyPrint()),
+ requestFields(
+ fieldWithPath("identifier").description("EmailConfiguration's identifier"),
+ fieldWithPath("host").description("EmailConfiguration's host"),
+ fieldWithPath("port").description("EmailConfiguration's port"),
+ fieldWithPath("protocol").description("EmailConfiguration's protocol"),
+ fieldWithPath("username").description("EmailConfiguration's username"),
+ fieldWithPath("app_password").description("EmailConfiguration's app_password"),
+ fieldWithPath("smtp_auth").description("EmailConfiguration's smtp authentication"),
+ fieldWithPath("start_tls").description("EmailConfiguration's start tls"),
+ fieldWithPath("state").description("EmailConfiguration's state")
+ )
+ ));
+ }
+
+ @Test
+ public void documentFindEmailConfiguration() throws Exception {
+ final EmailConfiguration emailConfiguration = EmailConfiguration.create("emailtesty",
+ "smtp.google.com",
+ "1233",
+ "smtp",
+ "example",
+ RandomStringUtils.randomAlphanumeric(16),
+ "true",
+ "true",
+ "ACTIVE");
+
+ this.notificationManager.createEmailConfiguration(emailConfiguration);
+ eventRecorder.wait(NotificationEventConstants.POST_EMAIL_CONFIGURATION, EmailConfiguration.class);
+
+ this.mockMvc.perform(get("/notification/email/" + emailConfiguration.getIdentifier())
+ .accept(MediaType.ALL_VALUE)
+ .contentType(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(status().isOk())
+ .andDo(document("document-find-emailconfiguration", preprocessRequest(prettyPrint()),
+ responseFields(
+ fieldWithPath("identifier").description("EmailConfiguration's identifier"),
+ fieldWithPath("host").description("EmailConfiguration's host"),
+ fieldWithPath("port").description("EmailConfiguration's port"),
+ fieldWithPath("protocol").description("EmailConfiguration's protocol"),
+ fieldWithPath("username").description("EmailConfiguration's username"),
+ fieldWithPath("app_password").description("EmailConfiguration's app_password"),
+ fieldWithPath("smtp_auth").description("EmailConfiguration's smtp authentication"),
+ fieldWithPath("start_tls").description("EmailConfiguration's start tls"),
+ fieldWithPath("state").description("EmailConfiguration's state")
+ )
+ ));
+ }
+}
diff --git a/component-test/src/main/java/org/apache/fineract/cn/notification/SmsApiDocumentation.java b/component-test/src/main/java/org/apache/fineract/cn/notification/SmsApiDocumentation.java
new file mode 100644
index 0000000..1655289
--- /dev/null
+++ b/component-test/src/main/java/org/apache/fineract/cn/notification/SmsApiDocumentation.java
@@ -0,0 +1,118 @@
+/*
+ * 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;
+
+import com.google.gson.Gson;
+import org.apache.commons.lang.RandomStringUtils;
+import org.apache.fineract.cn.notification.api.v1.client.NotificationManager;
+import org.apache.fineract.cn.notification.api.v1.domain.SMSConfiguration;
+import org.apache.fineract.cn.notification.api.v1.events.NotificationEventConstants;
+import org.apache.fineract.cn.notification.util.DomainObjectGenerator;
+import org.apache.fineract.cn.test.listener.EventRecorder;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
+import org.springframework.restdocs.JUnitRestDocumentation;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import org.springframework.web.context.WebApplicationContext;
+
+import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
+import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
+import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
+import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
+import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
+import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
+import static org.springframework.restdocs.payload.PayloadDocumentation.*;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+public class SmsApiDocumentation extends AbstractNotificationTest {
+ @Rule
+ public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("build/doc/generated-snippets/document-sms");
+
+ @Autowired
+ private WebApplicationContext context;
+
+ private MockMvc mockMvc;
+
+ @Autowired
+ private NotificationManager notificationManager;
+
+ @Autowired
+ private EventRecorder eventRecorder;
+
+ @Before
+ public void setUp() {
+
+ this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
+ .apply(documentationConfiguration(this.restDocumentation))
+ .build();
+ }
+
+ @Test
+ public void documentCreateSMSConfiguration() throws Exception {
+ final SMSConfiguration smsConfiguration = DomainObjectGenerator.smsConfiguration();
+
+ Gson gson = new Gson();
+ this.mockMvc.perform(post("/notification/sms/create")
+ .accept(MediaType.APPLICATION_JSON_VALUE)
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .content(gson.toJson(smsConfiguration)))
+ .andExpect(status().isAccepted())
+ .andDo(document("document-create-smsconfiguration", preprocessRequest(prettyPrint()),
+ requestFields(
+ fieldWithPath("identifier").description("SMSConfiguration's identifier"),
+ fieldWithPath("auth_token").description("SMSConfiguration's auth_token"),
+ fieldWithPath("account_sid").description("SMSConfiguration's account_sid"),
+ fieldWithPath("sender_number").description("Sender's number"),
+ fieldWithPath("state").description("SMSConfiguration's state")
+ )
+ ));
+ }
+
+ @Test
+ public void documentFindSMSConfiguration() throws Exception {
+
+ final SMSConfiguration smsConfiguration = SMSConfiguration.create(RandomStringUtils.randomAlphanumeric(4),
+ RandomStringUtils.randomAlphanumeric(8),
+ RandomStringUtils.randomAlphanumeric(8),
+ "+309483932",
+ "ACTIVE");
+
+ this.notificationManager.createSMSConfiguration(smsConfiguration);
+ this.eventRecorder.wait(NotificationEventConstants.POST_SMS_CONFIGURATION, SMSConfiguration.class);
+
+ this.mockMvc.perform(get("/notification/sms/" + smsConfiguration.getIdentifier())
+ .accept(MediaType.ALL_VALUE)
+ .contentType(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(status().isOk())
+ .andDo(document("document-find-smsconfiguration", preprocessRequest(prettyPrint()),
+ responseFields(
+ fieldWithPath("type").description("SMSConfiguration's type"),
+ fieldWithPath("identifier").description("SMSConfiguration's identifier"),
+ fieldWithPath("auth_token").description("SMSConfiguration's auth_token"),
+ fieldWithPath("account_sid").description("SMSConfiguration's account_sid"),
+ fieldWithPath("sender_number").description("Sender's number"),
+ fieldWithPath("state").description("SMSConfiguration's state")
+ )
+ ));
+ }
+}
diff --git a/component-test/src/main/java/org/apache/fineract/cn/notification/TestEmailService.java b/component-test/src/main/java/org/apache/fineract/cn/notification/TestEmailService.java
index 90f73c7..2855f68 100644
--- a/component-test/src/main/java/org/apache/fineract/cn/notification/TestEmailService.java
+++ b/component-test/src/main/java/org/apache/fineract/cn/notification/TestEmailService.java
@@ -32,7 +32,7 @@ import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
-public class TestEmailService extends TestNotification {
+public class TestEmailService extends AbstractNotificationTest {
private final String configIdentifier = "Gmail";
@Autowired
diff --git a/component-test/src/main/java/org/apache/fineract/cn/notification/TestSMSService.java b/component-test/src/main/java/org/apache/fineract/cn/notification/TestSMSService.java
index e25a3e8..33536ed 100644
--- a/component-test/src/main/java/org/apache/fineract/cn/notification/TestSMSService.java
+++ b/component-test/src/main/java/org/apache/fineract/cn/notification/TestSMSService.java
@@ -23,7 +23,6 @@ import org.apache.fineract.cn.api.util.NotFoundException;
import org.apache.fineract.cn.customer.api.v1.client.CustomerNotFoundException;
import org.apache.fineract.cn.notification.api.v1.client.ConfigurationNotFoundException;
import org.apache.fineract.cn.notification.api.v1.client.NotificationManager;
-import org.apache.fineract.cn.notification.api.v1.domain.EmailConfiguration;
import org.apache.fineract.cn.notification.api.v1.domain.SMSConfiguration;
import org.apache.fineract.cn.notification.api.v1.events.NotificationEventConstants;
import org.apache.fineract.cn.notification.service.internal.service.NotificationService;
@@ -33,7 +32,7 @@ import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
-public class TestSMSService extends TestNotification {
+public class TestSMSService extends AbstractNotificationTest {
@Autowired
private NotificationService notificationService;
diff --git a/service/src/main/java/org/apache/fineract/cn/notification/service/listener/CustomerEventListener.java b/service/src/main/java/org/apache/fineract/cn/notification/service/listener/CustomerEventListener.java
index d1cb4d6..78889a3 100644
--- a/service/src/main/java/org/apache/fineract/cn/notification/service/listener/CustomerEventListener.java
+++ b/service/src/main/java/org/apache/fineract/cn/notification/service/listener/CustomerEventListener.java
@@ -1,3 +1,21 @@
+/*
+ * 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