Skip to content
Permalink
Browse files
Merge pull request #7 from Izakey/develop
Document the notifications service
  • Loading branch information
Izakey committed Jan 2, 2019
2 parents 425c6ae + 6063af7 commit 3dc6d3147bd966cbb09a507f876eedba162a7c96
Showing 7 changed files with 281 additions and 7 deletions.
@@ -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) {
@@ -47,8 +47,8 @@

@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);
}
@@ -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")
)
));
}
}
@@ -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")
)
));
}
}
@@ -32,7 +32,7 @@
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
@@ -23,7 +23,6 @@
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.Test;
import org.springframework.beans.factory.annotation.Autowired;

public class TestSMSService extends TestNotification {
public class TestSMSService extends AbstractNotificationTest {

@Autowired
private NotificationService notificationService;
@@ -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

1 comment on commit 3dc6d31

@ebenezergraham
Copy link
Member

@ebenezergraham ebenezergraham commented on 3dc6d31 Jan 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Izakey

Please sign in to comment.