-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test.asaas.api.token=$aact_YTU5YTE0M2M2N2I4MTliNzk0YTI5N2U5MzdjNWZmNDQ6OjAwMDAwMDAwMDAwMDAwNDAyMjQ6OiRhYWNoXzBkNTZkYmI5LTQ1ZDUtNDIyNi04NWVhLTY4NTFhODQ0YzZlOA== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/test/java/io/github/jpdev/asaassdk/AsaasClientMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.github.jpdev.asaassdk; | ||
|
||
import io.github.jpdev.asaassdk.http.Asaas; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.util.Properties; | ||
|
||
public class AsaasClientMock { | ||
|
||
public static void create() { | ||
Asaas.initSandbox(getApiToken()); | ||
} | ||
|
||
private static String getApiToken() { | ||
Properties properties = new Properties(); | ||
try (FileInputStream input = new FileInputStream("config.properties")) { | ||
properties.load(input); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Erro ao carregar o arquivo de configuração.", e); | ||
} | ||
return properties.getProperty("test.asaas.api.token"); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/test/java/io/github/jpdev/asaassdk/http/AsaasTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.github.jpdev.asaassdk.http; | ||
|
||
import static org.junit.jupiter.api.Assumptions.assumeTrue; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import io.github.jpdev.asaassdk.AsaasClientMock; | ||
import io.github.jpdev.asaassdk.exception.ConnectionException; | ||
import io.github.jpdev.asaassdk.rest.payment.Payment; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class AsaasTest { | ||
|
||
@BeforeAll | ||
static void setup() { | ||
AsaasClientMock.create(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Teste de token informado") | ||
void testInformedToken() { | ||
assumeTrue(Asaas.getRestClient() != null, "Token da API não configurado."); | ||
} | ||
|
||
@Test | ||
@DisplayName("Teste de token incorreto") | ||
void testIncorrectToken() { | ||
assumeTrue(Asaas.getRestClient() != null, "Token da API não configurado."); | ||
|
||
Asaas.setToken("incorrectToken"); | ||
assertThrowsExactly(ConnectionException.class, () -> Payment.reader().read()); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/test/java/io/github/jpdev/asaassdk/rest/pix/transaction/PixTransactionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.github.jpdev.asaassdk.rest.pix.transaction; | ||
|
||
import io.github.jpdev.asaassdk.AsaasClientMock; | ||
import io.github.jpdev.asaassdk.http.Asaas; | ||
import io.github.jpdev.asaassdk.rest.action.ResourceSet; | ||
import io.github.jpdev.asaassdk.rest.pix.enums.PixAddressKeyType; | ||
import io.github.jpdev.asaassdk.rest.transfer.Transfer; | ||
import io.github.jpdev.asaassdk.rest.transfer.children.response.TransferOperationType; | ||
import io.github.jpdev.asaassdk.utils.Money; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assumptions.assumeTrue; | ||
|
||
public class PixTransactionTest { | ||
|
||
@BeforeAll | ||
static void setup() { | ||
AsaasClientMock.create(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Integração | Criação de transação Pix com chave") | ||
void testCreatePixKey() { | ||
assumeTrue(Asaas.getRestClient() != null, "Token da API não configurado."); | ||
|
||
BigDecimal value = BigDecimal.valueOf(0.01); | ||
|
||
Transfer transfer = Transfer.pixAddressKeyCreator() | ||
.setPixAddressKey("+5547999999999") | ||
.setPixAddressKeyType(PixAddressKeyType.PHONE) | ||
.setValue(value) | ||
.setDescription("Teste unitário") | ||
.create(); | ||
|
||
assertNotNull(transfer, "Transferência não criada."); | ||
assertEquals(value, Money.create(transfer.getValue()), "Valor da transferência incorreto."); | ||
assertEquals("Teste unitário", transfer.getDescription(), "Descrição da transferência incorreta."); | ||
assertEquals(TransferOperationType.PIX, transfer.getOperationType(), "Tipo de operação incorreto."); | ||
} | ||
|
||
@Test | ||
@DisplayName("Integração | Leitura de transação Pix") | ||
void testListing() { | ||
assumeTrue(Asaas.getRestClient() != null, "Token da API não configurado."); | ||
|
||
List<Transfer> transferList = Transfer.reader().read().getData(); | ||
assumeTrue(transferList != null && !transferList.isEmpty(), "Nenhuma transferência encontrada."); | ||
|
||
Transfer transfer = transferList.stream().findFirst().orElse(null); | ||
|
||
assertNotNull(transfer, "Transferência não encontrada."); | ||
assertNotNull(transfer.getId(), "ID da transferência não encontrado."); | ||
assertNotNull(transfer.getValue(), "Valor da transferência não encontrado."); | ||
assertNotNull(transfer.getDateCreated()); | ||
} | ||
} |