Skip to content
Merged
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
2,481 changes: 2,372 additions & 109 deletions logs/pms-application.log

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions reactpotfolio/src/pages/AssetDetails/AssetDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ const AssetDetails = () => {
>
<Tab label="Fundamentals" />
<Tab label="News" />
<Tab label="Expert Opinions" />
{type?.toLowerCase() !== 'mutualfund' && <Tab label="Expert Opinions" />}
{type?.toLowerCase() !== 'mutualfund' && <Tab label="AI Analysis" />}
</Tabs>

Expand Down Expand Up @@ -672,7 +672,7 @@ const AssetDetails = () => {
)}

{/* Recommendations Tab */}
{tabValue === 2 && (
{tabValue === 2 && type?.toLowerCase() !== 'mutualfund' && (
<Box sx={{ p: 4 }}>
<Typography variant="h5" fontWeight="700" mb={1} sx={{ color: '#fff' }}>
What Experts Think
Expand Down Expand Up @@ -833,7 +833,7 @@ const AssetDetails = () => {
)}

{/* AI Analysis Tab */}
{tabValue === 3 && (
{tabValue === 3 && type?.toLowerCase() !== 'mutualfund' && (
<Box sx={{ p: 4 }}>
<Stack direction="row" justifyContent="space-between" alignItems="center" mb={3}>
<Typography variant="h5" fontWeight="700" sx={{ color: '#fff' }}>
Expand Down
2 changes: 1 addition & 1 deletion reactpotfolio/src/pages/Home/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const Home = () => {
Portfolio Dashboard
</Typography>
<Typography variant="body2" sx={{ color: 'rgba(255,255,255,0.5)' }}>
Welcome back, {summary?.userName || 'User'}
Welcome back, User
</Typography>
</Box>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.hsbc;

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

@SpringBootTest
class PortfolioManagementSystemApplicationTests {

@Test
void contextLoads() {
}

}
56 changes: 56 additions & 0 deletions src/testbk/java/org/hsbc/controller/DashboardControllerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.hsbc.controller;

import org.hsbc.service.DashboardService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@ExtendWith(MockitoExtension.class)
class DashboardControllerTest {

private MockMvc mockMvc;

@Mock
private DashboardService service;

@InjectMocks
private DashboardController controller;

@BeforeEach
void setUp() {
mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
}

@Test
void testGetWalletSummary() throws Exception {
// Arrange
// Scenario:
// Available Balance (Wallet cash): 2000.0
// Used Balance (Stock value): 8000.0
// Total Balance (Net worth): 10000.0

when(service.getAvailableBalance()).thenReturn(2000.0);
when(service.getTotalUsedBalance()).thenReturn(8000.0);

// Act & Assert
mockMvc.perform(get("/dashboard/wallet-summary"))
.andExpect(status().isOk())

// Verify Math: available (2000) + used (8000) = total (10000)
.andExpect(jsonPath("$.totalBalance").value(10000.0))

// Verify individual fields
.andExpect(jsonPath("$.totalUsed").value(8000.0))
.andExpect(jsonPath("$.availableBalance").value(2000.0));
}
}
144 changes: 144 additions & 0 deletions src/testbk/java/org/hsbc/controller/PmsControllerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package org.hsbc.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.hsbc.entity.PmsEntity;
import org.hsbc.service.PmsService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;

import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@WebMvcTest(PmsController.class)
class PmsControllerTest {

@Autowired
private MockMvc mockMvc;

@MockBean
private PmsService service;

@Autowired
private ObjectMapper objectMapper;

// 1️⃣ POST /pms/add
@Test
void testAddAsset() throws Exception {
PmsEntity asset = new PmsEntity();
asset.setId(1L);
asset.setCompanyName("Apple");
asset.setQuantity(10);
asset.setBuyPrice(100);
asset.setCurrentPrice(120);

when(service.addAsset(any(PmsEntity.class))).thenReturn(asset);

mockMvc.perform(post("/api/pms/add")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(asset)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.companyName").value("Apple"))
.andExpect(jsonPath("$.quantity").value(10));
}

// 2️⃣ DELETE /pms/remove/{id}
@Test
void testRemoveAsset() throws Exception {
doNothing().when(service).removeAsset(1L);

mockMvc.perform(delete("/api/pms/remove/1"))
.andExpect(status().isOk())
.andExpect(content().string("Asset removed successfully"));
}

// 3️⃣ PUT /pms/update-quantity/{id}
@Test
void testUpdateQuantity() throws Exception {
PmsEntity updated = new PmsEntity();
updated.setId(1L);
updated.setQuantity(20);

when(service.updateQuantity(1L, 20)).thenReturn(updated);

mockMvc.perform(put("/api/pms/update-quantity/1")
.param("quantity", "20"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.quantity").value(20));
}

// 4️⃣ GET /pms/pl/{id}
@Test
void testGetPL() throws Exception {
when(service.calculatePL(1L)).thenReturn(200.0);

mockMvc.perform(get("/api/pms/pl/1"))
.andExpect(status().isOk())
.andExpect(content().string("200.0"));
}

@Test
void testGetPL_NotFound() throws Exception {
when(service.calculatePL(99L)).thenThrow(new org.hsbc.exception.InvalidPmsIdException("Not Found"));

mockMvc.perform(get("/api/pms/pl/99"))
.andExpect(status().isNotFound());
}

// 5️⃣ GET /pms/pl-percentage/{id}
@Test
void testGetPLPercentage() throws Exception {
when(service.calculatePLPercentage(1L)).thenReturn(20.0);

mockMvc.perform(get("/api/pms/pl-percentage/1"))
.andExpect(status().isOk())
.andExpect(content().string("20.0"));
}

// 6️⃣ GET /pms/total-value
@Test
void testGetTotalValue() throws Exception {
when(service.getTotalPortfolioValue()).thenReturn(1200.0);

mockMvc.perform(get("/api/pms/total-value"))
.andExpect(status().isOk())
.andExpect(content().string("1200.0"));
}

@Test
void testGetAssetById() throws Exception {
PmsEntity asset = new PmsEntity();
asset.setId(1L);
when(service.getAssetById(1L)).thenReturn(asset);

mockMvc.perform(get("/api/pms/1"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").value(1));
}

@Test
void testGetAssetById_NotFound() throws Exception {
when(service.getAssetById(99L)).thenThrow(new org.hsbc.exception.InvalidPmsIdException("Not Found"));

mockMvc.perform(get("/api/pms/99"))
.andExpect(status().isNotFound());
}

@Test
void testUpdatePrice() throws Exception {
PmsEntity asset = new PmsEntity();
asset.setSymbol("AAPL");
asset.setCurrentPrice(150.0);

when(service.updateCurrentPrice("AAPL", 150.0)).thenReturn(asset);

mockMvc.perform(put("/api/pms/update-price/AAPL")
.param("price", "150.0"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.currentPrice").value(150.0));
}
}
Loading
Loading