configure jackson in ObjectMapperConfiguration

This commit is contained in:
Carsten Otto
2022-01-31 10:38:51 +01:00
parent 7ef9a7f37d
commit 924f94f93c
3 changed files with 50 additions and 3 deletions

View File

@@ -0,0 +1,46 @@
package de.cotto.lndmanagej.controller;
import de.cotto.lndmanagej.controller.dto.ObjectMapperConfiguration;
import de.cotto.lndmanagej.model.ChannelIdResolver;
import de.cotto.lndmanagej.service.ChannelService;
import de.cotto.lndmanagej.service.OwnNodeService;
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.context.annotation.Import;
import org.springframework.test.web.servlet.MockMvc;
import java.util.Set;
import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL;
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.content;
@WebMvcTest(controllers = StatusController.class)
@Import(ObjectMapperConfiguration.class)
class ObjectMapperConfigurationIT {
private static final String PREFIX = "/api/status/";
@Autowired
private MockMvc mockMvc;
@MockBean
@SuppressWarnings("unused")
private ChannelIdResolver channelIdResolver;
@MockBean
private ChannelService channelService;
@MockBean
@SuppressWarnings("unused")
private OwnNodeService ownNodeService;
@Test
void output_is_pretty_printed() throws Exception {
when(channelService.getOpenChannels()).thenReturn(Set.of(LOCAL_OPEN_CHANNEL));
mockMvc.perform(get(PREFIX + "/open-channels/"))
.andExpect(content().string("{\n \"channels\" : [ \"712345x123x1\" ]\n}"));
}
}