mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-21 15:04:22 +01:00
cleanup
This commit is contained in:
committed by
Carsten Otto
parent
7242bd3d96
commit
857bfeb5ae
@@ -1,6 +1,6 @@
|
||||
package de.cotto.lndmanagej.ui;
|
||||
|
||||
import de.cotto.lndmanagej.controller.ChannelIdConverter;
|
||||
import de.cotto.lndmanagej.model.ChannelIdResolver;
|
||||
import de.cotto.lndmanagej.ui.controller.SearchController;
|
||||
import de.cotto.lndmanagej.ui.dto.ChannelDetailsDto;
|
||||
import de.cotto.lndmanagej.ui.dto.NodeDto;
|
||||
@@ -17,15 +17,17 @@ import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID;
|
||||
import static de.cotto.lndmanagej.ui.model.ChannelDetailsDtoFixture.CHANNEL_DETAILS_DTO;
|
||||
import static de.cotto.lndmanagej.ui.model.NodeDetailsDtoFixture.NODE_DETAILS_DTO;
|
||||
import static de.cotto.lndmanagej.ui.model.OpenChannelDtoFixture.OPEN_CHANNEL_DTO;
|
||||
import static de.cotto.lndmanagej.ui.model.OpenChannelDtoFixture.WOS;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.when;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||
@@ -42,15 +44,15 @@ class SearchControllerIT {
|
||||
@MockBean
|
||||
private PageService pageService;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@MockBean
|
||||
private ChannelIdConverter channelIdConverter;
|
||||
@SuppressWarnings("unused")
|
||||
private ChannelIdResolver channelIdResolver;
|
||||
|
||||
@Test
|
||||
void search_noOpenChannels_errorPage() throws Exception {
|
||||
given(this.dataService.getOpenChannels()).willReturn(List.of());
|
||||
given(this.pageService.error(any())).willReturn(new ErrorPage("myErrorMessage"));
|
||||
mockMvc.perform(MockMvcRequestBuilders.get("/search?q=783231610496155649"))
|
||||
when(dataService.getOpenChannels()).thenReturn(List.of());
|
||||
when(pageService.error(any())).thenReturn(new ErrorPage("myErrorMessage"));
|
||||
mockMvc.perform(MockMvcRequestBuilders.get("/search?q=" + CHANNEL_ID))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(model().attribute("error", "myErrorMessage"))
|
||||
.andExpect(view().name("error"));
|
||||
@@ -58,19 +60,19 @@ class SearchControllerIT {
|
||||
|
||||
@Test
|
||||
void searchForChannelId_viaShortChannelId_found() throws Exception {
|
||||
searchForChannelId("783231610496155649");
|
||||
searchForChannelId(CHANNEL_ID.getShortChannelId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void searchForChannelId_viaCompactChannelId_found() throws Exception {
|
||||
searchForChannelId("712345x123x1");
|
||||
searchForChannelId(CHANNEL_ID);
|
||||
}
|
||||
|
||||
private void searchForChannelId(String query) throws Exception {
|
||||
given(this.dataService.getOpenChannels()).willReturn(
|
||||
List.of(create(CHANNEL_DETAILS_DTO))
|
||||
private void searchForChannelId(Object query) throws Exception {
|
||||
when(dataService.getOpenChannels()).thenReturn(
|
||||
List.of(openChannelDto(CHANNEL_DETAILS_DTO))
|
||||
);
|
||||
given(this.pageService.channelDetails(any())).willReturn(new ChannelDetailsPage(CHANNEL_DETAILS_DTO));
|
||||
when(pageService.channelDetails(any())).thenReturn(new ChannelDetailsPage(CHANNEL_DETAILS_DTO));
|
||||
mockMvc.perform(MockMvcRequestBuilders.get("/search?q=" + query))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(model().attribute("id", is(CHANNEL_DETAILS_DTO.channelId())))
|
||||
@@ -88,8 +90,8 @@ class SearchControllerIT {
|
||||
}
|
||||
|
||||
private void searchAndExpectSingleNode(String query) throws Exception {
|
||||
given(this.dataService.getOpenChannels()).willReturn(List.of(OPEN_CHANNEL_DTO));
|
||||
given(this.pageService.nodeDetails(any())).willReturn(new NodeDetailsPage(NODE_DETAILS_DTO));
|
||||
when(dataService.getOpenChannels()).thenReturn(List.of(OPEN_CHANNEL_DTO));
|
||||
when(pageService.nodeDetails(any())).thenReturn(new NodeDetailsPage(NODE_DETAILS_DTO));
|
||||
mockMvc.perform(MockMvcRequestBuilders.get("/search?q=" + query))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(model().attribute("pubkey", is(OPEN_CHANNEL_DTO.remotePubkey())))
|
||||
@@ -98,20 +100,19 @@ class SearchControllerIT {
|
||||
|
||||
@Test
|
||||
void searchForAlias_TwoNodesFound() throws Exception {
|
||||
given(this.dataService.getOpenChannels()).willReturn(List.of(OPEN_CHANNEL_DTO, WOS));
|
||||
given(this.pageService.nodes(any())).willReturn(nodesPage(OPEN_CHANNEL_DTO, WOS)
|
||||
);
|
||||
when(dataService.getOpenChannels()).thenReturn(List.of(OPEN_CHANNEL_DTO, WOS));
|
||||
when(pageService.nodes(any())).thenReturn(nodesPage(OPEN_CHANNEL_DTO, WOS));
|
||||
mockMvc.perform(MockMvcRequestBuilders.get("/search?q=al"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(model().attributeExists("nodes"))
|
||||
.andExpect(view().name("nodes"));
|
||||
}
|
||||
|
||||
private NodesPage nodesPage(OpenChannelDto channel1, OpenChannelDto channel2) {
|
||||
return new NodesPage(List.of(create(channel1), create(channel2)));
|
||||
private NodesPage nodesPage(OpenChannelDto... channels) {
|
||||
return new NodesPage(Arrays.stream(channels).map(this::nodeDto).toList());
|
||||
}
|
||||
|
||||
public static OpenChannelDto create(ChannelDetailsDto channelDetails) {
|
||||
public OpenChannelDto openChannelDto(ChannelDetailsDto channelDetails) {
|
||||
return new OpenChannelDto(
|
||||
channelDetails.channelId(),
|
||||
channelDetails.remoteAlias(),
|
||||
@@ -120,7 +121,7 @@ class SearchControllerIT {
|
||||
channelDetails.balanceInformation());
|
||||
}
|
||||
|
||||
public static NodeDto create(OpenChannelDto channel) {
|
||||
public NodeDto nodeDto(OpenChannelDto channel) {
|
||||
return new NodeDto(channel.remotePubkey().toString(), channel.remoteAlias(), true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user