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
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import static org.junit.jupiter.api.Assertions.assertTrue;

@SpringBootTest
@ActiveProfiles("test")
class ApiGatewayApplicationTests {

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.training.api.gateway;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.test.context.ActiveProfiles;

import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest
@AutoConfigureWebTestClient
@ActiveProfiles("test")
class ApiGatewayRouteTests {

@Autowired
private RouteLocator routeLocator;

@Test
void contextLoads() {
assertNotNull(routeLocator);
}

@Test
void routeConfiguration_hasExpectedRoutes() {
var routes = routeLocator.getRoutes().collectList().block();

assertNotNull(routes);
assertTrue(routes.size() >= 5, "Should have at least 5 routes configured");

assertTrue(routes.stream().anyMatch(r -> r.getId().contains("user-service")));
assertTrue(routes.stream().anyMatch(r -> r.getId().contains("fund-transfer-service")));
assertTrue(routes.stream().anyMatch(r -> r.getId().contains("account-service")));
assertTrue(routes.stream().anyMatch(r -> r.getId().contains("sequence-generator")));
assertTrue(routes.stream().anyMatch(r -> r.getId().contains("transaction-service")));
}
}
43 changes: 43 additions & 0 deletions API-Gateway/src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
server:
port: 8080

eureka:
client:
enabled: false

spring:
application:
name: api-gateway-test
cloud:
gateway:
routes:
- id: user-service
uri: lb://user-service
predicates:
- Path=/api/users/**
- id: fund-transfer-service
uri: lb://fund-transfer-service
predicates:
- Path=/api/fund-transfers/**
- id: account-service
uri: lb://account-service
predicates:
- Path=/accounts/**
- id: sequence-generator
uri: lb://sequence-generator
predicates:
- Path=/sequence/**
- id: transaction-service
uri: lb://transaction-service
predicates:
- Path=/transactions/**
security:
oauth2:
client:
registration:
banking-service-client:
client-id: test-client
client-secret: test-secret
resourceserver:
jwt:
issuer-uri: http://localhost:8571/realms/banking-service
5 changes: 5 additions & 0 deletions Account-Service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import static org.junit.jupiter.api.Assertions.assertTrue;

@SpringBootTest
@ActiveProfiles("test")
class AccountServiceApplicationTests {

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package org.training.account.service.repository;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.TestPropertySource;
import org.training.account.service.model.AccountStatus;
import org.training.account.service.model.AccountType;
import org.training.account.service.model.entity.Account;

import java.math.BigDecimal;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.*;

@DataJpaTest
@TestPropertySource(locations = "classpath:application-test.yml")
class AccountRepositoryTest {

@Autowired
private AccountRepository accountRepository;

@Test
void findAccountByAccountNumber_existingAccount_returnsAccount() {
String accountNumber = "ACC0001234";
Account account = Account.builder()
.accountNumber(accountNumber)
.accountType(AccountType.SAVINGS_ACCOUNT)
.accountStatus(AccountStatus.ACTIVE)
.availableBalance(BigDecimal.valueOf(1000))
.userId(1L)
.build();

accountRepository.save(account);

Optional<Account> result = accountRepository.findAccountByAccountNumber(accountNumber);

assertTrue(result.isPresent());
assertEquals(accountNumber, result.get().getAccountNumber());
assertEquals(AccountType.SAVINGS_ACCOUNT, result.get().getAccountType());
}

@Test
void findAccountByAccountNumber_nonExistingAccount_returnsEmpty() {
Optional<Account> result = accountRepository.findAccountByAccountNumber("NONEXISTENT");

assertFalse(result.isPresent());
}

@Test
void findAccountByUserIdAndAccountType_existingAccount_returnsAccount() {
Long userId = 1L;
AccountType accountType = AccountType.SAVINGS_ACCOUNT;
Account account = Account.builder()
.accountNumber("ACC0001234")
.accountType(accountType)
.accountStatus(AccountStatus.ACTIVE)
.availableBalance(BigDecimal.valueOf(1000))
.userId(userId)
.build();

accountRepository.save(account);

Optional<Account> result = accountRepository.findAccountByUserIdAndAccountType(userId, accountType);

assertTrue(result.isPresent());
assertEquals(userId, result.get().getUserId());
assertEquals(accountType, result.get().getAccountType());
}

@Test
void findAccountByUserIdAndAccountType_nonExistingAccount_returnsEmpty() {
Optional<Account> result = accountRepository
.findAccountByUserIdAndAccountType(999L, AccountType.SAVINGS_ACCOUNT);

assertFalse(result.isPresent());
}

@Test
void findAccountByUserId_existingAccount_returnsAccount() {
Long userId = 1L;
Account account = Account.builder()
.accountNumber("ACC0001234")
.accountType(AccountType.SAVINGS_ACCOUNT)
.accountStatus(AccountStatus.ACTIVE)
.availableBalance(BigDecimal.valueOf(1000))
.userId(userId)
.build();

accountRepository.save(account);

Optional<Account> result = accountRepository.findAccountByUserId(userId);

assertTrue(result.isPresent());
assertEquals(userId, result.get().getUserId());
}

@Test
void findAccountByUserId_nonExistingAccount_returnsEmpty() {
Optional<Account> result = accountRepository.findAccountByUserId(999L);

assertFalse(result.isPresent());
}
}
Loading