diff --git a/build.gradle b/build.gradle index 0470473..dd9c724 100644 --- a/build.gradle +++ b/build.gradle @@ -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 { @@ -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' +} + diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/asciidoc/index.adoc b/src/main/asciidoc/index.adoc new file mode 100644 index 0000000..8e83d8b --- /dev/null +++ b/src/main/asciidoc/index.adoc @@ -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[] \ No newline at end of file diff --git a/src/test/java/banking/api/CustomerOperationsControllerTests.java b/src/test/java/banking/api/CustomerOperationsControllerTests.java index 92e298c..2dfeb24 100644 --- a/src/test/java/banking/api/CustomerOperationsControllerTests.java +++ b/src/test/java/banking/api/CustomerOperationsControllerTests.java @@ -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 @@ -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")); }