Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ plugins {
// Apply the application plugin to add support for building an application
id 'application'

id 'com.gradle.build-scan' version '1.16'
id 'com.gradle.build-scan' version '2.0.2'
id 'org.springframework.boot' version '2.0.5.RELEASE'
// Apply asciidoctor plugin to add support for genereating ascii docs
id 'org.asciidoctor.convert' version '1.5.3'
//id 'org.junit.platform.gradle.plugin' version '1.2.0'
}

repositories {
Expand All @@ -32,10 +35,19 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web:2.0.5.RELEASE'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.0.0'
implementation 'com.h2database:h2:1.4.197'
implementation 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3'

testImplementation 'org.springframework.boot:spring-boot-starter-test:2.0.5.RELEASE'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc:2.0.2.RELEASE'

}

// Define the main class for the application
mainClassName = 'banking.api.App'

asciidoctor {
sourceDir 'src/main/asciidoc'
attributes 'snippets': file('target/snippets')
outputDir 'target/snippets'
}

Empty file modified gradlew
100644 → 100755
Empty file.
9 changes: 9 additions & 0 deletions src/main/asciidoc/index.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
= API documentation With Spring REST Docs

This is an example output for a service running at http://localhost:8080:

.request
include::{snippets}/customer/http-request.adoc[]

.response
include::{snippets}/customer/http-response.adoc[]
43 changes: 21 additions & 22 deletions src/test/java/banking/api/CustomerOperationsControllerTests.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
package banking.api;

import static org.hamcrest.Matchers.containsString;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.math.BigDecimal;

import org.json.JSONObject;
import banking.api.constants.Constants.EndPoints;
import banking.api.constants.Constants.Messages;
import banking.api.controllers.CustomerOperationsController;
import banking.api.db.models.Customer;
import banking.api.db.repository.CustomerAccountMybatisRepository;
import banking.api.db.repository.CustomerMybatisRepository;
import banking.api.services.CustomerOperationsService;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Verify;
import java.math.BigDecimal;

import banking.api.constants.Constants.EndPoints;
import banking.api.constants.Constants.Messages;
import banking.api.controllers.CustomerOperationsController;
import banking.api.db.models.Customer;
import banking.api.db.models.CustomerAccount;
import banking.api.db.repository.CustomerAccountMybatisRepository;
import banking.api.db.repository.CustomerMybatisRepository;
import banking.api.services.CustomerOperationsService;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;

@RunWith(SpringRunner.class)
@WebMvcTest(CustomerOperationsController.class)
@AutoConfigureRestDocs(outputDir = "target/snippets")
public class CustomerOperationsControllerTests {

@Autowired
Expand Down Expand Up @@ -61,7 +59,8 @@ public void checkBalanceEnpointPointShouldReturnBalanceWithValidInput() throws E
.thenReturn(testBalance);

this.mockMvc.perform(get(EndPoints.CHECK_BALANCE_ENDPOINT + testNationalIdNUm)).andDo(print()).andExpect(status().isOk())
.andExpect(content().string(containsString(testBalance.toString())));
.andExpect(content().string(containsString(testBalance.toString())))
.andDo(document("customer"));

}

Expand Down