Skip to content

Commit 22ac2d6

Browse files
committed
add Java tests
1 parent 079141b commit 22ac2d6

8 files changed

Lines changed: 116 additions & 12 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Support Portal Backend — Java Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
jobs:
13+
build-and-test:
14+
name: Maven Test (Java 17)
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v6
20+
21+
- name: Set up JDK 17
22+
uses: actions/setup-java@v5
23+
with:
24+
java-version: '17'
25+
distribution: 'temurin'
26+
cache: maven
27+
28+
- name: Build and Run Tests
29+
run: |
30+
cd support-portal-backend
31+
mvn clean test
32+
33+
- name: Upload Test Results
34+
if: always()
35+
uses: actions/upload-artifact@v7
36+
with:
37+
name: java-test-results
38+
path: support-portal-backend/target/surefire-reports/

.github/workflows/ops-toolkit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
steps:
1515
- name: Checkout repository
16-
uses: actions/checkout@v4
16+
uses: actions/checkout@v6
1717

1818
- name: Make health_check.sh executable
1919
run: chmod +x it_ops_automation_toolkit/scripts/health_check.sh
@@ -30,7 +30,7 @@ jobs:
3030
| tee log_analysis_output.txt
3131
3232
- name: Upload results as artifacts
33-
uses: actions/upload-artifact@v4
33+
uses: actions/upload-artifact@v7
3434
with:
3535
name: ops-toolkit-results
3636
path: |

.github/workflows/python-etl-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ jobs:
1717

1818
steps:
1919
- name: Checkout repository
20-
uses: actions/checkout@v4
20+
uses: actions/checkout@v6
2121

2222
- name: Set up Python
23-
uses: actions/setup-python@v5
23+
uses: actions/setup-python@v6
2424
with:
2525
python-version: ${{ matrix.python-version }}
2626

@@ -36,7 +36,7 @@ jobs:
3636
pytest --maxfail=1 --disable-warnings -q | tee pytest_output.txt
3737
3838
- name: Upload pytest results
39-
uses: actions/upload-artifact@v4
39+
uses: actions/upload-artifact@v7
4040
with:
4141
name: etl-pytest-results-${{ matrix.python-version }}
4242
path: banking_data_pipeline_python/pytest_output.txt
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.support.controller;
2+
3+
import com.support.model.Transaction;
4+
import com.support.repository.TransactionRepository;
5+
import org.junit.jupiter.api.Test;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
8+
import org.springframework.boot.test.mock.mockito.MockBean;
9+
import org.springframework.http.MediaType;
10+
import org.springframework.test.web.servlet.MockMvc;
11+
12+
import java.util.Arrays;
13+
import java.util.Collections;
14+
15+
import static org.mockito.Mockito.when;
16+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
17+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
18+
19+
@WebMvcTest(TransactionController.class)
20+
public class TransactionControllerTest {
21+
22+
@Autowired
23+
private MockMvc mockMvc;
24+
25+
@MockBean
26+
private TransactionRepository repository;
27+
28+
@Test
29+
public void shouldReturnAllTransactions() throws Exception {
30+
// Arrange: Create a mock transaction
31+
Transaction t1 = new Transaction();
32+
t1.setId(1L);
33+
t1.setTransactionRef("REF-123");
34+
t1.setStatus("FAILED");
35+
t1.setExposureAmount(500.0);
36+
37+
when(repository.findAll()).thenReturn(Arrays.asList(t1));
38+
39+
// Act & Assert: Perform the GET request and check the JSON
40+
mockMvc.perform(get("/api/support/transactions"))
41+
.andExpect(status().isOk())
42+
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
43+
.andExpect(jsonPath("$[0].transactionRef").value("REF-123"))
44+
.andExpect(jsonPath("$[0].status").value("FAILED"))
45+
.andExpect(jsonPath("$[0].exposureAmount").value(500.0));
46+
}
47+
48+
@Test
49+
public void shouldReturnTransactionsByStatus() throws Exception {
50+
// Arrange
51+
Transaction t1 = new Transaction();
52+
t1.setStatus("PROCESSED");
53+
54+
when(repository.findByStatus("PROCESSED")).thenReturn(Arrays.asList(t1));
55+
56+
// Act & Assert
57+
mockMvc.perform(get("/api/support/transactions/status/PROCESSED"))
58+
.andExpect(status().isOk())
59+
.andExpect(jsonPath("$[0].status").value("PROCESSED"));
60+
}
61+
62+
@Test
63+
public void shouldReturnEmptyListWhenNoTransactionsFound() throws Exception {
64+
// Arrange
65+
when(repository.findByStatus("PENDING")).thenReturn(Collections.emptyList());
66+
67+
// Act & Assert
68+
mockMvc.perform(get("/api/support/transactions/status/PENDING"))
69+
.andExpect(status().isOk())
70+
.andExpect(content().json("[]"));
71+
}
72+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/* You can add global styles to this file, and also import other style files */
1+
/* To be filled */

support_portal_frontend/tsconfig.app.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
2-
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
31
{
42
"extends": "./tsconfig.json",
53
"compilerOptions": {

support_portal_frontend/tsconfig.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
2-
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
31
{
42
"compileOnSave": false,
53
"compilerOptions": {

support_portal_frontend/tsconfig.spec.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
2-
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
31
{
42
"extends": "./tsconfig.json",
53
"compilerOptions": {

0 commit comments

Comments
 (0)