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
18 changes: 10 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
plugins {
id 'checkstyle'
id 'org.springframework.boot' version '3.3.13'
id 'org.springframework.boot' version '4.0.5'
id 'io.spring.dependency-management' version '1.1.7'
id 'java'
}

group = 'com.bitpay'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
java {
sourceCompatibility = '17'
}

repositories {
mavenCentral()
Expand All @@ -29,12 +31,12 @@ dependencies {
compileOnly 'org.projectlombok:lombok:1.18.44'
implementation 'com.google.code.gson:gson:2.13.2'
implementation 'com.bitpay:bitpay_sdk:10.3.0'
implementation 'org.liquibase:liquibase-core:4.31.1'
implementation 'com.h2database:h2:2.1.214'
implementation 'org.liquibase:liquibase-core:5.0.2'
implementation 'com.h2database:h2:2.3.232'
implementation 'org.springframework:spring-webflux:7.0.6'
implementation 'org.springframework:spring-websocket:7.0.6'
implementation 'org.springframework:spring-messaging:7.0.6'
implementation "org.springframework.boot:spring-boot-starter-data-jpa:3.5.12"
implementation "org.springframework.boot:spring-boot-starter-data-jpa:4.0.5"
implementation 'org.springframework.boot:spring-boot-starter-log4j2'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
Expand Down Expand Up @@ -74,13 +76,13 @@ task integrationTest(type: Test) {
}

checkstyle {
toolVersion = "8.39"
project.ext.checkstyleVersion = '8.39'
toolVersion = "10.20.2"
project.ext.checkstyleVersion = '10.20.2'
configFile = rootProject.file("${rootProject.projectDir}/config/checkstyle/checkstyle.xml")
}

tasks.withType(Checkstyle) {
reports {
xml.destination rootProject.file("build/reports/checkstyle-result.xml")
xml.outputLocation = rootProject.file("build/reports/checkstyle-result.xml")
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.4-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions src/intTest/java/com/bitpay/demo/AbstractIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.TestPropertySource;

@TestPropertySource(properties = {"spring.config.location=classpath:application-integrationtest.yaml"})
Expand All @@ -30,7 +30,7 @@ public abstract class AbstractIntegrationTest implements UnitTest {
@Autowired
protected InvoiceRepository invoiceRepository;

@MockBean
@MockitoBean
private Logger logger;

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Objects;
import javax.annotation.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
Expand All @@ -19,7 +18,6 @@
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

@AutoConfigureMockMvc
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public abstract class AbstractUiIntegrationTest extends AbstractIntegrationTest {
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
Expand All @@ -28,7 +28,7 @@ public class CreateDonationIntegrationTest extends AbstractUiIntegrationTest {

private static final String URL = "/invoice";

@MockBean
@MockitoBean
private Client bitpayClient;

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

public class CreateInvoiceIntegrationTest extends AbstractUiIntegrationTest {

private static final String URL = "/invoice";

@MockBean
@MockitoBean
private Client bitpayClient;

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void shouldNotUpdateInvoiceWhenUpdateDataAreInvalid() throws Exception {

// then
result.andExpect(MockMvcResultMatchers.status().isBadRequest())
.andExpect(MockMvcResultMatchers.content().json(getDataFromFile("invalidUpdateDataResponse.json"), false));
.andExpect(MockMvcResultMatchers.content().json(getDataFromFile("invalidUpdateDataResponse.json")));
Assertions.assertEquals(
"new",
this.invoiceRepository.findById(invoice.getInvoiceId()).getStatus().value()
Expand Down
18 changes: 15 additions & 3 deletions src/intTest/resources/application-integrationtest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,34 @@ bitpay:

server:
port: 8000
error:
path: /error

spring:
datasource:
url: "jdbc:h2:mem:test;MODE=MYSQL"
url: "jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
username: test
password: test
hikari:
maxLifetime: 150000
maximumPoolSize: 2
jpa:
hibernate:
ddl-auto: none
ddl-auto: create-drop
properties:
hibernate:
dialect: org.hibernate.dialect.H2Dialect
format: true
enable_lazy_load_no_trans: false
jdbc.batch_size: 20
order.inserts: true
order.updates: true
liquibase:
enabled: false
main:
banner-mode: off
web:
resources:
add-mappings: true

app-url: "https://localhost:8080"
app-url: "https://localhost:8080"
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Map;
import java.util.UUID;
import lombok.NonNull;
import org.springframework.transaction.annotation.Transactional;

@DependencyInjection
public class CreateInvoice {
Expand All @@ -42,6 +43,7 @@ public class CreateInvoice {
}

@NonNull
@Transactional
public String execute(@NonNull final Map<String, Object> requestParameters)
throws MissingRequiredField, BitPayException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public HttpCreateInvoice(@NonNull final CreateInvoice createInvoice) {
}

@PostMapping("/invoice")
public ResponseEntity execute(@NonNull @RequestParam final Map<String, Object> params) throws BitPayException {
public ResponseEntity<Void> execute(
@NonNull @RequestParam final Map<String, Object> params
) throws BitPayException {
final String url = this.createInvoice.execute(params);

final HttpHeaders headers = new HttpHeaders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,22 @@
package com.bitpay.demo.shared.infrastructure;

import com.bitpay.demo.shared.bitpayproperties.BitPayProperties;
import jakarta.servlet.http.HttpServletRequest;
import java.util.Map;
import lombok.NonNull;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ModelAttribute;


@Configuration
class CustomErrorViewResolver implements ErrorViewResolver {
@ControllerAdvice
class CustomErrorViewResolver {

private final BitPayProperties bitPayProperties;

CustomErrorViewResolver(@NonNull final BitPayProperties bitPayProperties) {
this.bitPayProperties = bitPayProperties;
}

@Override
public ModelAndView resolveErrorView(
@NonNull final HttpServletRequest request,
@NonNull final HttpStatus status,
@NonNull final Map<String, Object> model
) {
if (!HttpStatus.NOT_FOUND.equals(status)) {
return null;
}

return new ModelAndView("error/404", "design", this.bitPayProperties.getDesign());
@ModelAttribute
public void addDesignAttribute(Model model) {
model.addAttribute("design", this.bitPayProperties.getDesign());
}
}
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@
</one-to-many>
<embedded name="addressesJson">
<attribute-override name="value">
<column name="addresses_json"/>
<column name="addresses_json" column-definition="text"/>
</attribute-override>
</embedded>
<embedded name="addressRequestPending">
Expand Down Expand Up @@ -628,4 +628,4 @@
</embedded>
</attributes>
</entity>
</entity-mappings>
</entity-mappings>
7 changes: 6 additions & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ bitpay:

server:
port: 8000
error:
path: /error

spring:
datasource:
Expand All @@ -75,5 +77,8 @@ spring:
format: true
main:
banner-mode: off
web:
resources:
add-mappings: true

app-url: "https://localhost:8080"
app-url: "https://localhost:8080"
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package com.bitpay.demo.invoice.application.features.tasks.createinvoice;

import com.bitpay.demo.UnitTest;
import com.bitpay.demo.invoice.domain.buyer.BuyerEmailAddress;
import com.bitpay.demo.invoice.domain.buyer.BuyerName;
import com.bitpay.demo.invoice.domain.buyer.BuyerPhoneNumber;
Expand All @@ -22,7 +21,7 @@
import org.mockito.Mockito;
import org.skyscreamer.jsonassert.JSONAssert;

class InvoiceBuyerFactoryTest implements UnitTest, GetBitPayInvoice {
class InvoiceBuyerFactoryTest implements GetBitPayInvoice {

@Test
void shouldMapToInvoiceBuyer() throws JSONException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

package com.bitpay.demo.invoice.application.features.tasks.createinvoice;

import com.bitpay.demo.UnitTest;
import org.json.JSONException;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;

class InvoiceBuyerProvidedInfoFactoryTest implements UnitTest, GetBitPayInvoice {
class InvoiceBuyerProvidedInfoFactoryTest implements GetBitPayInvoice {

@Test
void shouldMapToInvoiceBuyerProvidedInfo() throws JSONException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package com.bitpay.demo.invoice.application.features.tasks.createinvoice;

import com.bitpay.demo.UnitTest;
import com.bitpay.demo.invoice.domain.Amount;
import com.bitpay.demo.invoice.domain.Invoice;
import com.bitpay.demo.invoice.domain.InvoiceUuid;
Expand Down Expand Up @@ -35,7 +34,7 @@
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.skyscreamer.jsonassert.comparator.CustomComparator;

class InvoiceFactoryTest implements UnitTest, GetBitPayInvoice {
class InvoiceFactoryTest implements GetBitPayInvoice {

@Test
void shouldMapToInvoice() throws JSONException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@

package com.bitpay.demo.invoice.application.features.tasks.createinvoice;

import com.bitpay.demo.UnitTest;
import com.bitpay.demo.invoice.domain.Invoice;
import org.json.JSONException;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;

class InvoiceItemizedDetailFactoryTest implements UnitTest, GetBitPayInvoice {
class InvoiceItemizedDetailFactoryTest implements GetBitPayInvoice {

@Test
void shouldMapToInvoiceItemizedDetail() throws JSONException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@

package com.bitpay.demo.invoice.application.features.tasks.createinvoice;

import com.bitpay.demo.UnitTest;
import com.bitpay.demo.invoice.domain.payment.InvoicePayment;
import java.util.AbstractMap;
import org.json.JSONException;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;

class InvoicePaymentCurrencyFactoryTest implements UnitTest, GetBitPayInvoice {
class InvoicePaymentCurrencyFactoryTest implements GetBitPayInvoice {

@Test
void shouldMapToInvoicePaymentCurrency() throws JSONException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package com.bitpay.demo.invoice.application.features.tasks.createinvoice;

import com.bitpay.demo.UnitTest;
import com.bitpay.demo.invoice.domain.CurrencyCode;
import com.bitpay.demo.invoice.domain.payment.DisplaySubtotal;
import com.bitpay.demo.invoice.domain.payment.DisplayTotal;
Expand All @@ -25,7 +24,7 @@
import org.mockito.Mockito;
import org.skyscreamer.jsonassert.JSONAssert;

class InvoicePaymentFactoryTest implements UnitTest, GetBitPayInvoice {
class InvoicePaymentFactoryTest implements GetBitPayInvoice {

@Test
void shouldMapToInvoicePayment() throws JSONException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package com.bitpay.demo.invoice.application.features.tasks.createinvoice;

import com.bitpay.demo.UnitTest;
import com.bitpay.demo.invoice.domain.CurrencyCode;
import com.bitpay.demo.invoice.domain.refund.InvoiceRefund;
import com.bitpay.demo.invoice.domain.refund.InvoiceRefundInfo;
Expand All @@ -16,7 +15,7 @@
import org.mockito.Mockito;
import org.skyscreamer.jsonassert.JSONAssert;

class InvoiceRefundFactoryTest implements UnitTest, GetBitPayInvoice {
class InvoiceRefundFactoryTest implements GetBitPayInvoice {

@Test
void shouldMapToInvoiceRefund() throws JSONException {
Expand Down
Loading