diff --git a/Procfile b/Procfile
index e3ca92a..20e000e 100644
--- a/Procfile
+++ b/Procfile
@@ -1 +1 @@
-web: java -jar -Dspring.profiles.active=prod -Dserver.port=$PORT target/financial-java-api-3.1.2-SNAPSHOT.jar
\ No newline at end of file
+web: java -jar -Dspring.profiles.active=prod -Dserver.port=$PORT target/financial-java-api-3.1.3-SNAPSHOT.jar
\ No newline at end of file
diff --git a/README.md b/README.md
index 0262513..3959c63 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ This API provides HTTP endpoint's and tools for the following:
* Create a Transaction: `POST/financial/v1/transactions`
* Update a Transaction: `PUT/financial/v1/transactions`
* Delete a Transaction (by id): `DELETE/financial/v1/transactions/1`
-* Get report of transactions in a period of time (sorted and paginated): `GET/financial/v1/transactions?startDate=2020-01-01&endDate=2020-09-18&order=DESC&page=2`
+* Get report of transactions in a period of time (sorted and paginated): `GET/financial/v1/transactions?startDate=2020-01-01&endDate=2020-09-20&page=2&size=5&sort=DESC`
* Find a unique transaction by id: `GET/financial/v1/transactions/1`
* Find a unique transaction by id, but filtering JSON fields: `GET/financial/v1/transactions/1?fields=id,nsu,transactionDate,amount`
* Find transactions by NSU (Unique sequential number): `GET/financial/v1/transactions/byNsu/{nsuNumber}`
@@ -94,7 +94,7 @@ the one that was updated.
"type": "CARD",
"links": [
{
- "rel": "self",
+ "rel": "self",
"href": "http://localhost:8080/financial/v1/transactions/1"
}
]
@@ -102,10 +102,10 @@ the one that was updated.
}
```
-`GET/financial/v1/transactions?startDate=2020-01-01&endDate=2020-01-18&order=DESC&page=2`
+`GET/financial/v1/transactions?startDate=2020-01-01&endDate=2020-01-18&page=2&size=5&sort=DESC`
-This end-point returns transactions created within the period specified in the request. E.g: in the above query, we are looking for
-all transactions carried out between 01-18 January 2020. Also, the result should return in descending order and only the page 2.
+The end-point returns transactions were created within the period specified in the request. E.g., in the above query, we are looking for all transactions carried out between 01-18 January 2020. Also, the result should return in descending order and only page 2
+with five transactions.
`DELETE/financial/v1/transaction/{id}`
@@ -131,7 +131,7 @@ This end-point returns the statistics based on the transactions created.
"count": 2,
"links": [
{
- "rel": "self",
+ "rel": "self",
"href": "http://localhost:8080/financial/v1/statistics/1"
}
]
@@ -182,7 +182,7 @@ The API also was developed to run with an `jar`. In order to generate this `jar`
mvn package
```
-It will clean, compile and generate a `jar` at target directory, e.g. `financial-java-api-3.1.2-SNAPSHOT.jar`
+It will clean, compile and generate a `jar` at target directory, e.g. `financial-java-api-3.1.3-SNAPSHOT.jar`
### Execution
@@ -220,7 +220,7 @@ mvn integration-test
In order to run the API, run the jar simply as following:
```bash
-java -jar financial-java-api-3.1.2-SNAPSHOT.jar --spring.profiles.active=dev
+java -jar financial-java-api-3.1.3-SNAPSHOT.jar --spring.profiles.active=dev
```
or
diff --git a/pom.xml b/pom.xml
index bc6602e..a431a6c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,11 +6,11 @@
io.github.mariazevedo88
financial-java-api
- 3.1.2-SNAPSHOT
+ 3.1.3-SNAPSHOT
jar
financial-java-api
- A financial API for managing transactions
+ A financial API for managing transactions. It is built with Java, Spring Boot, and Spring Framework.
diff --git a/src/it/java/io/github/mariazevedo88/financialjavaapi/it/FinancialJavaApiIntegrationTest.java b/src/it/java/io/github/mariazevedo88/financialjavaapi/it/FinancialJavaApiIntegrationTest.java
index 338bcc1..e678e48 100644
--- a/src/it/java/io/github/mariazevedo88/financialjavaapi/it/FinancialJavaApiIntegrationTest.java
+++ b/src/it/java/io/github/mariazevedo88/financialjavaapi/it/FinancialJavaApiIntegrationTest.java
@@ -4,7 +4,7 @@
import java.math.BigDecimal;
import java.text.ParseException;
-import java.time.LocalDateTime;
+import java.time.LocalDate;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
@@ -59,8 +59,7 @@ public void testCreateTransactionNSU123456() throws ParseException {
//Create a new HttpEntity
final HttpEntity entity = new HttpEntity<>(dtoNsu123456, headers);
- ResponseEntity responseEntity = this.restTemplate
- .exchange("http://localhost:" + port + "/financial/v1/transactions",
+ ResponseEntity responseEntity = this.restTemplate.exchange("http://localhost:" + port + "/financial/v1/transactions",
HttpMethod.POST, entity, String.class);
assertEquals(201, responseEntity.getStatusCodeValue());
@@ -80,8 +79,7 @@ public void testCreateTransactionNSU258963() throws ParseException {
//Create a new HttpEntity
final HttpEntity entity = new HttpEntity<>(dtoNsu258963, headers);
- ResponseEntity responseEntity = this.restTemplate
- .exchange("http://localhost:" + port + "/financial/v1/transactions",
+ ResponseEntity responseEntity = this.restTemplate.exchange("http://localhost:" + port + "/financial/v1/transactions",
HttpMethod.POST, entity, String.class);
assertEquals(201, responseEntity.getStatusCodeValue());
@@ -97,16 +95,12 @@ public void testFindAllTransactions() throws ParseException {
//Create a new HttpEntity
final HttpEntity entity = new HttpEntity<>(headers);
- LocalDateTime startDateTime = FinancialApiUtil.
- getLocalDateTimeFromString("2020-08-21T18:32:04.150Z");
- LocalDateTime endDateTime = startDateTime.plusDays(5);
-
- String startDate = startDateTime.format(FinancialApiUtil.getDateFormater());
- String endDate = endDateTime.format(FinancialApiUtil.getDateFormater());
+ String startDate = LocalDate.of(2020, 8, 20).toString();
+ String endDate = LocalDate.of(2020, 8, 30).toString();
ResponseEntity responseEntity = this.restTemplate
- .exchange("http://localhost:" + port + "/financial/v1/transactions?startDate=" + startDate + "&endDate=" + endDate,
- HttpMethod.GET, entity, String.class);
+ .exchange("http://localhost:" + port + "/financial/v1/transactions?startDate=" + startDate + "&endDate=" + endDate
+ + "&page=" + 1 + "&size=" + 2 + "&order=ASC", HttpMethod.GET, entity, String.class);
assertEquals(200, responseEntity.getStatusCodeValue());
}
diff --git a/src/main/java/io/github/mariazevedo88/financialjavaapi/controller/v1/transaction/TransactionController.java b/src/main/java/io/github/mariazevedo88/financialjavaapi/controller/v1/transaction/TransactionController.java
index f925d79..352949e 100644
--- a/src/main/java/io/github/mariazevedo88/financialjavaapi/controller/v1/transaction/TransactionController.java
+++ b/src/main/java/io/github/mariazevedo88/financialjavaapi/controller/v1/transaction/TransactionController.java
@@ -13,6 +13,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.web.PageableDefault;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.server.mvc.WebMvcLinkBuilder;
@@ -37,7 +39,6 @@
import io.github.mariazevedo88.financialjavaapi.exception.NotParsableContentException;
import io.github.mariazevedo88.financialjavaapi.exception.TransactionInvalidUpdateException;
import io.github.mariazevedo88.financialjavaapi.exception.TransactionNotFoundException;
-import io.github.mariazevedo88.financialjavaapi.model.enumeration.PageOrderEnum;
import io.github.mariazevedo88.financialjavaapi.model.transaction.Transaction;
import io.github.mariazevedo88.financialjavaapi.service.transaction.TransactionService;
import io.github.mariazevedo88.financialjavaapi.util.FinancialApiUtil;
@@ -55,7 +56,7 @@
@RequestMapping("/financial/v1/transactions")
public class TransactionController {
- private TransactionService transactionService;
+ TransactionService transactionService;
@Autowired
public TransactionController(TransactionService transactionService) {
@@ -93,9 +94,9 @@ public TransactionController(TransactionService transactionService) {
*/
@PostMapping
@ApiOperation(value = "Route to create a transaction")
- public ResponseEntity> create(@RequestHeader(value=FinancialApiUtil.HEADER_FINANCIAL_API_VERSION, defaultValue="${api.version}")
- String apiVersion, @RequestHeader(value=FinancialApiUtil.HEADER_API_KEY, defaultValue="${api.key}") String apiKey,
- @Valid @RequestBody TransactionDTO dto, BindingResult result) throws NotParsableContentException {
+ public ResponseEntity> create(@RequestHeader(value=FinancialApiUtil.HEADER_FINANCIAL_API_VERSION, defaultValue="${api.version}") String apiVersion,
+ @RequestHeader(value=FinancialApiUtil.HEADER_API_KEY, defaultValue="${api.key}") String apiKey, @Valid @RequestBody TransactionDTO dto, BindingResult result)
+ throws NotParsableContentException {
Response response = new Response<>();
@@ -155,9 +156,9 @@ public ResponseEntity> create(@RequestHeader(value=Fina
*/
@PutMapping(path = "/{id}")
@ApiOperation(value = "Route to update a transaction")
- public ResponseEntity> update(@RequestHeader(value=FinancialApiUtil.HEADER_FINANCIAL_API_VERSION, defaultValue="${api.version}")
- String apiVersion, @RequestHeader(value=FinancialApiUtil.HEADER_API_KEY, defaultValue="${api.key}") String apiKey, @Valid @RequestBody TransactionDTO dto,
- BindingResult result) throws TransactionNotFoundException, TransactionInvalidUpdateException, NotParsableContentException {
+ public ResponseEntity> update(@RequestHeader(value=FinancialApiUtil.HEADER_FINANCIAL_API_VERSION, defaultValue="${api.version}") String apiVersion,
+ @RequestHeader(value=FinancialApiUtil.HEADER_API_KEY, defaultValue="${api.key}") String apiKey, @Valid @RequestBody TransactionDTO dto, BindingResult result)
+ throws TransactionNotFoundException, TransactionInvalidUpdateException, NotParsableContentException {
Response response = new Response<>();
@@ -199,8 +200,9 @@ public ResponseEntity> update(@RequestHeader(value=Fina
* @param apiKey - API Key to access the routes
* @param startDate - the start date of the search
* @param endDate - the end date of the search
- * @param page - the page that will be return in the search
- * @param order - the sort order that the results should be shown: ASC - ascending order; DESC - descending order
+ * @param pageable Object for pagination information: the page that will be return in the search,
+ * the size of page, and sort direction that the results should be shown: ASC - ascending order;
+ * DESC - descending order.
*
* @return ResponseEntity with a Response>
object and the HTTP status
*
@@ -217,16 +219,15 @@ public ResponseEntity> update(@RequestHeader(value=Fina
@ApiOperation(value = "Route to find all transactions of the API in a period of time")
public ResponseEntity>> findAllBetweenDates(@RequestHeader(value=FinancialApiUtil.HEADER_FINANCIAL_API_VERSION, defaultValue="${api.version}")
String apiVersion, @RequestHeader(value=FinancialApiUtil.HEADER_API_KEY, defaultValue="${api.key}") String apiKey, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd")
- LocalDate startDate, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate, @RequestParam(name="page", defaultValue = "0") int page,
- @RequestParam(name="order", defaultValue = "ASC") String order) throws TransactionNotFoundException {
+ LocalDate startDate, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate, @PageableDefault(page = 1, size = 10, sort = {"id"}) Pageable pageable)
+ throws TransactionNotFoundException {
Response> response = new Response<>();
LocalDateTime startDateTime = FinancialApiUtil.convertLocalDateToLocalDateTime(startDate);
LocalDateTime endDateTime = FinancialApiUtil.convertLocalDateToLocalDateTime(endDate);
- Page transactions = transactionService.findBetweenDates(startDateTime, endDateTime,
- page, PageOrderEnum.getSortDirection(order));
+ Page transactions = transactionService.findBetweenDates(startDateTime, endDateTime, pageable);
if (transactions.isEmpty()) {
throw new TransactionNotFoundException("There are no transactions registered between startDate=" + startDate
@@ -236,7 +237,7 @@ public ResponseEntity>> findAllBetweenDates(@Reque
Page itemsDTO = transactions.map(t -> t.convertEntityToDTO());
itemsDTO.stream().forEach(dto -> {
try {
- createSelfLinkInCollections(apiVersion, apiKey, dto, null);
+ createSelfLinkInCollections(apiVersion, apiKey, dto);
} catch (TransactionNotFoundException e) {
log.error("There are no transactions registered between startDate= {} and endDate= {}", startDate, endDate);
}
@@ -292,7 +293,7 @@ public ResponseEntity>> findByNsu(@RequestHeader(v
transactionsDTO.stream().forEach(dto -> {
try {
- createSelfLinkInCollections(apiVersion, apiKey, dto, null);
+ createSelfLinkInCollections(apiVersion, apiKey, dto);
} catch (TransactionNotFoundException e) {
log.error("There are no transactions registered with the nsu= {}", transactionNSU);
}
@@ -420,10 +421,10 @@ private void createSelfLink(Transaction transaction, TransactionDTO transactionD
* @param transactionDTO
* @throws TransactionNotFoundException
*/
- private void createSelfLinkInCollections(String apiVersion, String apiKey, final TransactionDTO transactionDTO, String fields)
+ private void createSelfLinkInCollections(String apiVersion, String apiKey, final TransactionDTO transactionDTO)
throws TransactionNotFoundException {
- Link selfLink = linkTo(methodOn(TransactionController.class).findById(apiVersion, apiKey,
- transactionDTO.getId(), fields)).withSelfRel();
+ Link selfLink = linkTo(methodOn(TransactionController.class).findById(apiVersion, apiKey, transactionDTO.getId(), null))
+ .withSelfRel().expand();
transactionDTO.add(selfLink);
}
diff --git a/src/main/java/io/github/mariazevedo88/financialjavaapi/model/enumeration/PageOrderEnum.java b/src/main/java/io/github/mariazevedo88/financialjavaapi/model/enumeration/PageOrderEnum.java
deleted file mode 100644
index 755a3d1..0000000
--- a/src/main/java/io/github/mariazevedo88/financialjavaapi/model/enumeration/PageOrderEnum.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package io.github.mariazevedo88.financialjavaapi.model.enumeration;
-
-/**
- * Enum that classifies the ascending order or descending order
- * in the sort operations in API routes.
- *
- * @author Mariana Azevedo
- * @since 23/08/2020
- */
-public enum PageOrderEnum {
-
- ASC("ASC"), DESC("DESC");
-
- private String value;
-
- private PageOrderEnum(String value) {
- this.value = value;
- }
-
- public String getValue() {
- return value;
- }
-
- /**
- * Method to get the sort order of a search result.
- *
- * @author Mariana Azevedo
- * @since 23/08/2020
- *
- * @return PageOrderEnum
object
- */
- public static PageOrderEnum getSortDirection(String value){
- if(ASC.getValue().equals(value)) {
- return ASC;
- }
- return DESC;
- }
-}
diff --git a/src/main/java/io/github/mariazevedo88/financialjavaapi/service/transaction/TransactionService.java b/src/main/java/io/github/mariazevedo88/financialjavaapi/service/transaction/TransactionService.java
index 33cc074..439e298 100644
--- a/src/main/java/io/github/mariazevedo88/financialjavaapi/service/transaction/TransactionService.java
+++ b/src/main/java/io/github/mariazevedo88/financialjavaapi/service/transaction/TransactionService.java
@@ -4,10 +4,10 @@
import java.util.List;
import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import io.github.mariazevedo88.financialjavaapi.dto.model.transaction.TransactionDTO;
import io.github.mariazevedo88.financialjavaapi.exception.TransactionNotFoundException;
-import io.github.mariazevedo88.financialjavaapi.model.enumeration.PageOrderEnum;
import io.github.mariazevedo88.financialjavaapi.model.transaction.Transaction;
/**
@@ -79,14 +79,13 @@ public interface TransactionService {
*
* @param startDate - the start date of the search
* @param endDate - the end date of the search
- * @param page - the page that will be return in the search
- * @param order - the sort order that the results should be shown:
- * ASC - ascending order; DESC - descending order
+ * @param pageable - object for pagination information: the page that will be return in the search,
+ * the size of page, and sort direction that the results should be shown: ASC - ascending order;
+ * DESC - descending order.
*
* @return Page
object
*/
- Page findBetweenDates(LocalDateTime startDate, LocalDateTime endDate, int page,
- PageOrderEnum order);
+ Page findBetweenDates(LocalDateTime startDate, LocalDateTime endDate, Pageable pageable);
/**
* Method to build a partial response in requests regarding Transaction.
diff --git a/src/main/java/io/github/mariazevedo88/financialjavaapi/service/transaction/impl/TransactionServiceImpl.java b/src/main/java/io/github/mariazevedo88/financialjavaapi/service/transaction/impl/TransactionServiceImpl.java
index 09d720d..de4a16c 100644
--- a/src/main/java/io/github/mariazevedo88/financialjavaapi/service/transaction/impl/TransactionServiceImpl.java
+++ b/src/main/java/io/github/mariazevedo88/financialjavaapi/service/transaction/impl/TransactionServiceImpl.java
@@ -4,12 +4,9 @@
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Sort;
-import org.springframework.data.domain.Sort.Direction;
+import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -18,7 +15,6 @@
import io.github.mariazevedo88.financialjavaapi.dto.model.transaction.TransactionDTO;
import io.github.mariazevedo88.financialjavaapi.exception.TransactionNotFoundException;
-import io.github.mariazevedo88.financialjavaapi.model.enumeration.PageOrderEnum;
import io.github.mariazevedo88.financialjavaapi.model.transaction.Transaction;
import io.github.mariazevedo88.financialjavaapi.repository.transaction.TransactionRepository;
import io.github.mariazevedo88.financialjavaapi.service.transaction.TransactionService;
@@ -34,9 +30,6 @@ public class TransactionServiceImpl implements TransactionService {
TransactionRepository transactionRepository;
- @Value("${pagination.items_per_page}")
- private int itemsPerPage;
-
@Autowired
public TransactionServiceImpl(TransactionRepository transactionRepository) {
this.transactionRepository = transactionRepository;
@@ -79,17 +72,13 @@ public Transaction findById(Long id) throws TransactionNotFoundException {
}
/**
- * @see TransactionService#findBetweenDates()
+ * @see TransactionService#findBetweenDates(LocalDateTime, LocalDateTime, Pageable)
*/
@Override
- public Page findBetweenDates(LocalDateTime startDate, LocalDateTime endDate, int page,
- PageOrderEnum order) {
- Sort sort = Direction.ASC.name().equals(order.getValue()) ?
- Sort.by("id").ascending() : Sort.by("id").descending();
- PageRequest pg = PageRequest.of(page, itemsPerPage, sort);
+ public Page findBetweenDates(LocalDateTime startDate, LocalDateTime endDate, Pageable pageable) {
return transactionRepository.
findAllByTransactionDateGreaterThanEqualAndTransactionDateLessThanEqual(startDate,
- endDate, pg);
+ endDate, pageable);
}
/**
diff --git a/src/main/java/io/github/mariazevedo88/financialjavaapi/util/config/PageableConfiguration.java b/src/main/java/io/github/mariazevedo88/financialjavaapi/util/config/PageableConfiguration.java
new file mode 100644
index 0000000..5f46e47
--- /dev/null
+++ b/src/main/java/io/github/mariazevedo88/financialjavaapi/util/config/PageableConfiguration.java
@@ -0,0 +1,42 @@
+package io.github.mariazevedo88.financialjavaapi.util.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.web.config.PageableHandlerMethodArgumentResolverCustomizer;
+import org.springframework.data.web.config.SortHandlerMethodArgumentResolverCustomizer;
+
+/**
+ * Class that implements the necessary settings to the pagination feature works correctly.
+ *
+ * @author Mariana Azevedo
+ * @since 20/09/2020
+ */
+@Configuration
+public class PageableConfiguration {
+
+ /**
+ * Method that allow customize Pageable configurations.
+ *
+ * @author Mariana Azevedo
+ * @since 20/09/2020
+ *
+ * @return PageableHandlerMethodArgumentResolverCustomizer
object
+ */
+ @Bean
+ PageableHandlerMethodArgumentResolverCustomizer pageableResolverCustomizer() {
+ return pageableResolver -> pageableResolver.setOneIndexedParameters(true);
+ }
+
+ /**
+ * Method that allow customize Sort configurations.
+ *
+ * @author Mariana Azevedo
+ * @since 20/09/2020
+ *
+ * @return SortHandlerMethodArgumentResolverCustomizer
object
+ */
+ @Bean
+ SortHandlerMethodArgumentResolverCustomizer sortResolverCustomizer() {
+ return sortResolver -> sortResolver.setSortParameter("sort");
+ }
+}
\ No newline at end of file
diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties
index 9514fa2..b60612b 100644
--- a/src/main/resources/application-prod.properties
+++ b/src/main/resources/application-prod.properties
@@ -22,16 +22,21 @@ spring.mvc.throw-exception-if-no-handler-found=true
spring.mvc.resources.add-mappings=false
spring.mvc.date-format=yyyy-MM-dd
-#configuring API pagination
-pagination.items_per_page=10
+#Configuring API pagination
+#Maximum page size to be accepted
+spring.data.web.pageable.max-page-size=100
+#Page index parameter name
+spring.data.web.pageable.page-parameter=page
+#Page size parameter name
+spring.data.web.pageable.size-parameter=size
#configuring jwt secret
jwt.secret=oioqowepjsjdasd!$%mknfskdnf090192019
jwt.expiration=6000
#configuring API version
-release.version=3.1.2
-api.version=2020-09-18
+release.version=3.1.3
+api.version=2020-09-20
api.key="FX001-FREE"
#enable response compression
diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties
index f37f719..88c2166 100644
--- a/src/main/resources/application-test.properties
+++ b/src/main/resources/application-test.properties
@@ -22,9 +22,17 @@ spring.cache.jcache.config=classpath:cache/ehcache.xml
spring.mvc.throw-exception-if-no-handler-found=true
spring.mvc.resources.add-mappings=false
+#Configuring API pagination
+#Maximum page size to be accepted
+spring.data.web.pageable.max-page-size=100
+#Page index parameter name
+spring.data.web.pageable.page-parameter=page
+#Page size parameter name
+spring.data.web.pageable.size-parameter=size
+
#configuring API version
-release.version=3.1.2
-api.version=2020-09-18
+release.version=3.1.3
+api.version=2020-09-20
api.key="FX001-FREE"
#enable response compression
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index c474317..1c344b0 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -23,16 +23,21 @@ spring.thymeleaf.check-template-location=false
spring.mvc.throw-exception-if-no-handler-found=true
spring.mvc.resources.add-mappings=false
-#configuring API pagination
-pagination.items_per_page=10
+#Configuring API pagination
+#Maximum page size to be accepted
+spring.data.web.pageable.max-page-size=100
+#Page index parameter name
+spring.data.web.pageable.page-parameter=page
+#Page size parameter name
+spring.data.web.pageable.size-parameter=size
#configuring jwt secret
jwt.secret=qweernadnamdn19820918209!#ajhad
jwt.expiration=3600
#configuring API version
-release.version=3.1.2
-api.version=2020-09-18
+release.version=3.1.3
+api.version=2020-09-20
api.key="FX001-FREE"
#enable response compression
diff --git a/src/test/java/io/github/mariazevedo88/financialjavaapi/test/controller/transaction/TransactionControllerTest.java b/src/test/java/io/github/mariazevedo88/financialjavaapi/test/controller/transaction/TransactionControllerTest.java
index 0080115..6e8492f 100644
--- a/src/test/java/io/github/mariazevedo88/financialjavaapi/test/controller/transaction/TransactionControllerTest.java
+++ b/src/test/java/io/github/mariazevedo88/financialjavaapi/test/controller/transaction/TransactionControllerTest.java
@@ -10,6 +10,9 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.TestMethodOrder;
+import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
+import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.mockito.BDDMockito;
import org.mockito.Mockito;
@@ -47,6 +50,7 @@
@AutoConfigureMockMvc
@ActiveProfiles("test")
@TestInstance(Lifecycle.PER_CLASS)
+@TestMethodOrder(OrderAnnotation.class)
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, MockitoTestExecutionListener.class })
public class TransactionControllerTest {
@@ -80,6 +84,7 @@ private void setUp() {
* @throws Exception
*/
@Test
+ @Order(1)
public void testSave() throws Exception {
BDDMockito.given(transactionService.save(Mockito.any(Transaction.class))).willReturn(getMockTransaction());
@@ -107,6 +112,7 @@ public void testSave() throws Exception {
* @throws Exception
*/
@Test
+ @Order(2)
public void testSaveInvalidTransaction() throws Exception {
BDDMockito.given(transactionService.save(Mockito.any(Transaction.class))).willReturn(getMockTransaction());
diff --git a/src/test/java/io/github/mariazevedo88/financialjavaapi/test/repository/statistic/StatisticRepositoryTest.java b/src/test/java/io/github/mariazevedo88/financialjavaapi/test/repository/statistic/StatisticRepositoryTest.java
index 2b8f0ba..9ed134b 100644
--- a/src/test/java/io/github/mariazevedo88/financialjavaapi/test/repository/statistic/StatisticRepositoryTest.java
+++ b/src/test/java/io/github/mariazevedo88/financialjavaapi/test/repository/statistic/StatisticRepositoryTest.java
@@ -25,9 +25,9 @@
* @since 24/03/2020
*/
@SpringBootTest
-@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class })
@ActiveProfiles("test")
@TestInstance(Lifecycle.PER_CLASS)
+@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class })
public class StatisticRepositoryTest {
@Autowired
diff --git a/src/test/java/io/github/mariazevedo88/financialjavaapi/test/repository/transaction/TransactionRepositoryTest.java b/src/test/java/io/github/mariazevedo88/financialjavaapi/test/repository/transaction/TransactionRepositoryTest.java
index ebdd234..8389e06 100644
--- a/src/test/java/io/github/mariazevedo88/financialjavaapi/test/repository/transaction/TransactionRepositoryTest.java
+++ b/src/test/java/io/github/mariazevedo88/financialjavaapi/test/repository/transaction/TransactionRepositoryTest.java
@@ -11,6 +11,9 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.TestMethodOrder;
+import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
+import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@@ -29,9 +32,10 @@
* @since 24/03/2020
*/
@SpringBootTest
-@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class })
@ActiveProfiles("test")
@TestInstance(Lifecycle.PER_CLASS)
+@TestMethodOrder(OrderAnnotation.class)
+@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class })
public class TransactionRepositoryTest {
@Autowired
@@ -59,6 +63,7 @@ private void setUp() {
* @since 24/03/2020
*/
@Test
+ @Order(1)
public void testSave() {
Transaction transaction = new Transaction(null, "270257", "000123", LocalDateTime.now(),
@@ -76,6 +81,7 @@ public void testSave() {
* @since 24/03/2020
*/
@Test
+ @Order(2)
public void testFindByNsu(){
List response = repository.findByNsu("220788");
diff --git a/src/test/java/io/github/mariazevedo88/financialjavaapi/test/service/statistic/StatisticServiceTest.java b/src/test/java/io/github/mariazevedo88/financialjavaapi/test/service/statistic/StatisticServiceTest.java
index 93bf4e7..5a12e74 100644
--- a/src/test/java/io/github/mariazevedo88/financialjavaapi/test/service/statistic/StatisticServiceTest.java
+++ b/src/test/java/io/github/mariazevedo88/financialjavaapi/test/service/statistic/StatisticServiceTest.java
@@ -28,9 +28,9 @@
* @since 05/04/2020
*/
@SpringBootTest
-@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, MockitoTestExecutionListener.class })
@ActiveProfiles("test")
@TestInstance(Lifecycle.PER_CLASS)
+@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, MockitoTestExecutionListener.class })
public class StatisticServiceTest {
private static final BigDecimal SUM = BigDecimal.valueOf(500);
diff --git a/src/test/java/io/github/mariazevedo88/financialjavaapi/test/service/transaction/TransactionServiceTest.java b/src/test/java/io/github/mariazevedo88/financialjavaapi/test/service/transaction/TransactionServiceTest.java
index 79a047c..c62b053 100644
--- a/src/test/java/io/github/mariazevedo88/financialjavaapi/test/service/transaction/TransactionServiceTest.java
+++ b/src/test/java/io/github/mariazevedo88/financialjavaapi/test/service/transaction/TransactionServiceTest.java
@@ -10,9 +10,12 @@
import java.util.Collections;
import java.util.List;
+import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
+import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
+import org.junit.jupiter.api.TestMethodOrder;
import org.mockito.BDDMockito;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
@@ -22,11 +25,12 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
-import io.github.mariazevedo88.financialjavaapi.model.enumeration.PageOrderEnum;
import io.github.mariazevedo88.financialjavaapi.model.enumeration.TransactionTypeEnum;
import io.github.mariazevedo88.financialjavaapi.model.transaction.Transaction;
import io.github.mariazevedo88.financialjavaapi.repository.transaction.TransactionRepository;
@@ -39,9 +43,10 @@
* @since 05/04/2020
*/
@SpringBootTest
-@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, MockitoTestExecutionListener.class })
@ActiveProfiles("test")
@TestInstance(Lifecycle.PER_CLASS)
+@TestMethodOrder(OrderAnnotation.class)
+@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, MockitoTestExecutionListener.class })
public class TransactionServiceTest {
@Autowired
@@ -59,6 +64,7 @@ public class TransactionServiceTest {
* @since 05/04/2020
*/
@Test
+ @Order(1)
public void testSave() {
BDDMockito.given(repository.save(Mockito.any(Transaction.class)))
@@ -76,6 +82,7 @@ public void testSave() {
* @since 05/04/2020
*/
@Test
+ @Order(2)
public void testFindByNsu() {
BDDMockito.given(repository.findByNsu(Mockito.anyString()))
@@ -92,6 +99,7 @@ public void testFindByNsu() {
* @since 21/08/2020
*/
@Test
+ @Order(3)
public void testFindBetweenDates() {
List transactions = new ArrayList<>();
@@ -99,9 +107,9 @@ public void testFindBetweenDates() {
Page page = new PageImpl<>(transactions);
BDDMockito.given(repository.findAllByTransactionDateGreaterThanEqualAndTransactionDateLessThanEqual(Mockito.any(LocalDateTime.class),
- Mockito.any(LocalDateTime.class), Mockito.any(PageRequest.class))).willReturn(page);
+ Mockito.any(LocalDateTime.class), Mockito.any(Pageable.class))).willReturn(page);
- Page response = service.findBetweenDates(DATE, DATE, 0, PageOrderEnum.ASC);
+ Page response = service.findBetweenDates(DATE, DATE, PageRequest.of(1, 10, Sort.by("id").ascending()));
assertNotNull(response);
}