Skip to content
Permalink
Browse files
Merge branch 'dev-merge' into permitted-feign-client-auth
  • Loading branch information
ebenezergraham committed May 9, 2019
2 parents 6b136f4 + 3dc6d31 commit e4e258567c9746098194a9e62584f3eec7a2132a
Showing 6 changed files with 259 additions and 7 deletions.
@@ -59,6 +59,13 @@ asciidoctor {
'snippets': file('build/doc/generated-snippets/')
}

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) {
@@ -44,8 +44,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);
@@ -63,13 +63,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")
)
));
}
}
@@ -34,7 +34,7 @@
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

public class TestEmailService extends TestNotification {
public class TestEmailService extends AbstractNotificationTest {

final EmailConfiguration emailConfiguration;
@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;
@@ -34,7 +33,7 @@
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

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

final SMSConfiguration smsConfiguration;
@Autowired

0 comments on commit e4e2585

Please sign in to comment.