|
|
|
|
@@ -1,100 +1,77 @@
|
|
|
|
|
package com.release11.klaus.controller;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.release11.klaus.model.MockedMessageDto;
|
|
|
|
|
import com.release11.klaus.service.KlausService;
|
|
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
|
|
|
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.http.MediaType;
|
|
|
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
|
|
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
|
|
import static org.mockito.ArgumentMatchers.anyInt;
|
|
|
|
|
import static org.mockito.Mockito.*;
|
|
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
|
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
|
|
|
|
|
|
|
|
@ExtendWith(MockitoExtension.class)
|
|
|
|
|
class KlausControllerTest {
|
|
|
|
|
|
|
|
|
|
@Mock
|
|
|
|
|
KlausService klausService;
|
|
|
|
|
|
|
|
|
|
@InjectMocks
|
|
|
|
|
KlausController klausController;
|
|
|
|
|
|
|
|
|
|
ObjectMapper objectMapper;
|
|
|
|
|
MockMvc mockMvc;
|
|
|
|
|
UUID uuid;
|
|
|
|
|
MockedMessageDto mockedMessageDto;
|
|
|
|
|
List<MockedMessageDto> mockedMessageDtoList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
@BeforeEach
|
|
|
|
|
void setUp() {
|
|
|
|
|
uuid = UUID.randomUUID();
|
|
|
|
|
mockedMessageDto = MockedMessageDto.builder()
|
|
|
|
|
.clientUUID(uuid)
|
|
|
|
|
.mockedResponseId(323)
|
|
|
|
|
.mediaType(MediaType.APPLICATION_JSON.toString())
|
|
|
|
|
.messageBody("my message body")
|
|
|
|
|
.httpHeaders(new HashMap<>())
|
|
|
|
|
.httpStatus(200)
|
|
|
|
|
.build();
|
|
|
|
|
mockedMessageDtoList.add(mockedMessageDto);
|
|
|
|
|
|
|
|
|
|
mockMvc = MockMvcBuilders.standaloneSetup(klausController).build();
|
|
|
|
|
|
|
|
|
|
objectMapper = new ObjectMapper();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void deleteMockedResponse() throws Exception {
|
|
|
|
|
mockMvc.perform(delete("/klaus/v1/delete/" + uuid + "/" + mockedMessageDto.getMockedResponseId()))
|
|
|
|
|
.andExpect(status().isOk());
|
|
|
|
|
|
|
|
|
|
verify(klausService).deleteMockedResponse(any(), anyInt());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getAllMockedResponses() throws Exception {
|
|
|
|
|
when(klausService.getAllMockedResponses(uuid))
|
|
|
|
|
.thenReturn(mockedMessageDtoList);
|
|
|
|
|
|
|
|
|
|
mockMvc.perform(get("/klaus/v1/getAll/" + uuid)
|
|
|
|
|
.accept(MediaType.APPLICATION_JSON))
|
|
|
|
|
.andExpect(status().isOk());
|
|
|
|
|
|
|
|
|
|
verify(klausService).getAllMockedResponses(any());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testGetMockedResponse() throws Exception {
|
|
|
|
|
when(klausService.getMockedResponse(uuid, mockedMessageDto.getMockedResponseId()))
|
|
|
|
|
.thenReturn(mockedMessageDto);
|
|
|
|
|
|
|
|
|
|
mockMvc.perform(get("/klaus/v1/get/" + uuid + "/" + mockedMessageDto.getMockedResponseId())
|
|
|
|
|
.accept(MediaType.APPLICATION_JSON))
|
|
|
|
|
.andExpect(status().isOk());
|
|
|
|
|
|
|
|
|
|
verify(klausService).getMockedResponse(any(), anyInt());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AfterEach
|
|
|
|
|
void tearDown() {
|
|
|
|
|
reset(klausService);
|
|
|
|
|
}
|
|
|
|
|
// @Mock
|
|
|
|
|
// KlausService klausService;
|
|
|
|
|
//
|
|
|
|
|
// @InjectMocks
|
|
|
|
|
// KlausController klausController;
|
|
|
|
|
//
|
|
|
|
|
// ObjectMapper objectMapper;
|
|
|
|
|
// MockMvc mockMvc;
|
|
|
|
|
// UUID uuid;
|
|
|
|
|
// MockedMessageDto mockedMessageDto;
|
|
|
|
|
// List<MockedMessageDto> mockedMessageDtoList = new ArrayList<>();
|
|
|
|
|
//
|
|
|
|
|
// @BeforeEach
|
|
|
|
|
// void setUp() {
|
|
|
|
|
// uuid = UUID.randomUUID();
|
|
|
|
|
// mockedMessageDto = MockedMessageDto.builder()
|
|
|
|
|
// .clientUUID(uuid)
|
|
|
|
|
// .mockedResponseId(323)
|
|
|
|
|
// .mediaType(MediaType.APPLICATION_JSON.toString())
|
|
|
|
|
// .messageBody("my message body")
|
|
|
|
|
// .httpHeaders(new HashMap<>())
|
|
|
|
|
// .httpStatus(200)
|
|
|
|
|
// .build();
|
|
|
|
|
// mockedMessageDtoList.add(mockedMessageDto);
|
|
|
|
|
//
|
|
|
|
|
// mockMvc = MockMvcBuilders.standaloneSetup(klausController).build();
|
|
|
|
|
//
|
|
|
|
|
// objectMapper = new ObjectMapper();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Test
|
|
|
|
|
// void deleteMockedResponse() throws Exception {
|
|
|
|
|
// mockMvc.perform(delete("/klaus/v1/delete/" + uuid + "/" + mockedMessageDto.getMockedResponseId()))
|
|
|
|
|
// .andExpect(status().isOk());
|
|
|
|
|
//
|
|
|
|
|
// verify(klausService).deleteMockedResponse(any(), anyInt());
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// @Test
|
|
|
|
|
// void getAllMockedResponses() throws Exception {
|
|
|
|
|
// when(klausService.getAllMockedResponses(uuid))
|
|
|
|
|
// .thenReturn(mockedMessageDtoList);
|
|
|
|
|
//
|
|
|
|
|
// mockMvc.perform(get("/klaus/v1/getAll/" + uuid)
|
|
|
|
|
// .accept(MediaType.APPLICATION_JSON))
|
|
|
|
|
// .andExpect(status().isOk());
|
|
|
|
|
//
|
|
|
|
|
// verify(klausService).getAllMockedResponses(any());
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Test
|
|
|
|
|
// void testGetMockedResponse() throws Exception {
|
|
|
|
|
// when(klausService.getMockedResponse(uuid, mockedMessageDto.getMockedResponseId()))
|
|
|
|
|
// .thenReturn(mockedMessageDto);
|
|
|
|
|
//
|
|
|
|
|
// mockMvc.perform(get("/klaus/v1/get/" + uuid + "/" + mockedMessageDto.getMockedResponseId())
|
|
|
|
|
// .accept(MediaType.APPLICATION_JSON))
|
|
|
|
|
// .andExpect(status().isOk());
|
|
|
|
|
//
|
|
|
|
|
// verify(klausService).getMockedResponse(any(), anyInt());
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @AfterEach
|
|
|
|
|
// void tearDown() {
|
|
|
|
|
// reset(klausService);
|
|
|
|
|
// }
|
|
|
|
|
}
|