mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-21 15:04:22 +01:00
test model data
This commit is contained in:
committed by
Carsten Otto
parent
d3818877a6
commit
14f70219b4
@@ -11,9 +11,12 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.ui.Model;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static de.cotto.lndmanagej.controller.dto.ChannelDetailsDtoFixture.CHANNEL_DETAILS_DTO;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -31,6 +34,7 @@ class ChannelDetailsControllerTest {
|
||||
void channelDetails() throws NotFoundException {
|
||||
when(pageService.channelDetails(CHANNEL_ID)).thenReturn(new ChannelDetailsPage(CHANNEL_DETAILS_DTO));
|
||||
assertThat(channelDetailsController.channelDetails(CHANNEL_ID, model)).isEqualTo("channel-details");
|
||||
verify(model).addAllAttributes(Map.of("channel", CHANNEL_DETAILS_DTO, "id", CHANNEL_ID));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -38,5 +42,6 @@ class ChannelDetailsControllerTest {
|
||||
when(pageService.channelDetails(CHANNEL_ID)).thenThrow(NotFoundException.class);
|
||||
when(pageService.error("Channel not found.")).thenReturn(new ErrorPage("x"));
|
||||
assertThat(channelDetailsController.channelDetails(CHANNEL_ID, model)).isEqualTo("error");
|
||||
verify(model).addAllAttributes(Map.of("error", "x"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package de.cotto.lndmanagej.ui.controller;
|
||||
|
||||
import de.cotto.lndmanagej.controller.dto.BalanceInformationDto;
|
||||
import de.cotto.lndmanagej.controller.dto.PoliciesDto;
|
||||
import de.cotto.lndmanagej.model.BalanceInformation;
|
||||
import de.cotto.lndmanagej.model.Coins;
|
||||
import de.cotto.lndmanagej.ui.dto.NodeDto;
|
||||
import de.cotto.lndmanagej.ui.dto.OpenChannelDto;
|
||||
import de.cotto.lndmanagej.ui.dto.StatusModel;
|
||||
import de.cotto.lndmanagej.ui.page.PageService;
|
||||
import de.cotto.lndmanagej.ui.page.channel.ChannelsPage;
|
||||
@@ -14,16 +19,24 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.ui.Model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static de.cotto.lndmanagej.controller.dto.NodesAndChannelsWithWarningsDto.NONE;
|
||||
import static de.cotto.lndmanagej.controller.dto.OpenChannelDtoFixture.OPEN_CHANNEL_DTO;
|
||||
import static de.cotto.lndmanagej.model.BalanceInformationFixtures.REMOTE_BALANCE;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID;
|
||||
import static de.cotto.lndmanagej.model.NodeFixtures.NODE_PEER;
|
||||
import static de.cotto.lndmanagej.model.PolicyFixtures.POLICIES_FOR_LOCAL_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class DashboardControllerTest {
|
||||
private static final String CHANNELS_KEY = "channels";
|
||||
private static final String NODES_KEY = "nodes";
|
||||
|
||||
@InjectMocks
|
||||
private DashboardController dashboardController;
|
||||
|
||||
@@ -38,18 +51,45 @@ class DashboardControllerTest {
|
||||
StatusModel statusModel = new StatusModel(true, 213, NONE);
|
||||
when(pageService.dashboard()).thenReturn(new DashboardPage(List.of(), List.of(), statusModel));
|
||||
assertThat(dashboardController.dashboard(model)).isEqualTo("dashboard");
|
||||
verify(model).addAllAttributes(
|
||||
Map.of(NODES_KEY, List.of(), CHANNELS_KEY, List.of(), "status", statusModel)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void channels() {
|
||||
when(pageService.channels()).thenReturn(new ChannelsPage(List.of(OPEN_CHANNEL_DTO)));
|
||||
assertThat(dashboardController.channels(model)).isEqualTo("channels");
|
||||
assertThat(dashboardController.channels(model)).isEqualTo(CHANNELS_KEY);
|
||||
verify(model).addAllAttributes(Map.of(CHANNELS_KEY, List.of(OPEN_CHANNEL_DTO)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void channels_sorted_by_outbound() {
|
||||
OpenChannelDto channelA = withBalance(Coins.ofSatoshis(2));
|
||||
OpenChannelDto channelB = withBalance(Coins.ofSatoshis(3));
|
||||
OpenChannelDto channelC = withBalance(Coins.ofSatoshis(1));
|
||||
when(pageService.channels()).thenReturn(new ChannelsPage(List.of(channelA, channelB, channelC)));
|
||||
assertThat(dashboardController.channels(model)).isEqualTo(CHANNELS_KEY);
|
||||
verify(model).addAllAttributes(Map.of(CHANNELS_KEY, List.of(channelC, channelA, channelB)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void nodes() {
|
||||
NodeDto nodeDto = new NodeDto(PUBKEY.toString(), NODE_PEER.alias(), true);
|
||||
when(pageService.nodes()).thenReturn(new NodesPage(List.of(nodeDto)));
|
||||
assertThat(dashboardController.nodes(model)).isEqualTo("nodes");
|
||||
assertThat(dashboardController.nodes(model)).isEqualTo(NODES_KEY);
|
||||
verify(model).addAllAttributes(Map.of(NODES_KEY, List.of(nodeDto)));
|
||||
}
|
||||
|
||||
private OpenChannelDto withBalance(Coins localBalance) {
|
||||
BalanceInformation balanceInformation =
|
||||
new BalanceInformation(localBalance, Coins.NONE, REMOTE_BALANCE, Coins.NONE);
|
||||
return new OpenChannelDto(
|
||||
CHANNEL_ID,
|
||||
"Albert",
|
||||
PUBKEY,
|
||||
PoliciesDto.createFromModel(POLICIES_FOR_LOCAL_CHANNEL),
|
||||
BalanceInformationDto.createFromModel(balanceInformation)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,13 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.ui.Model;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import static de.cotto.lndmanagej.controller.dto.NodeDetailsDtoFixture.NODE_DETAILS_DTO;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -32,6 +34,7 @@ class NodeDetailsControllerTest {
|
||||
void nodeDetails() {
|
||||
when(pageService.nodeDetails(PUBKEY)).thenReturn(new NodeDetailsPage(NODE_DETAILS_DTO));
|
||||
assertThat(nodeDetailsController.nodeDetails(PUBKEY, model)).isEqualTo("node-details");
|
||||
verify(model).addAllAttributes(Map.of("node", NODE_DETAILS_DTO, "pubkey", PUBKEY));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user