Skip to content

Commit

Permalink
Merge branch 'master' into tc/make-room
Browse files Browse the repository at this point in the history
  • Loading branch information
ahyoon99 authored Aug 29, 2020
2 parents a8cf024 + 4f65af2 commit 6b4b360
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
Empty file added apps/h2db/crm
Empty file.
1 change: 1 addition & 0 deletions src/main/java/web/chat/backend/entity/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder
@Getter
@Setter
@Entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ void shouldRespond400StatusCode_ifNotFoundRoom() throws Exception {
void getRooms() throws Exception {

// when
ResultActions resultActions = mockMvc.perform(get("/api/rooms"));

// then
resultActions.andExpect(status().isOk())
.andDo(print());
}

@Test
Expand Down
42 changes: 42 additions & 0 deletions src/test/java/web/chat/backend/controller/RoomControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.BDDMockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;


import java.util.Arrays;
import java.util.List;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
Expand All @@ -22,6 +28,7 @@
import lombok.RequiredArgsConstructor;
import web.chat.backend.controller.request.RoomRequest;
import web.chat.backend.controller.response.RoomResponse;

import web.chat.backend.entity.Room;
import web.chat.backend.service.MessageService;
import web.chat.backend.service.RoomService;
Expand All @@ -44,10 +51,33 @@ class RoomControllerTest {
void getRooms() throws Exception {

// given
Room r1 = Room.builder()
.id(1L)
.title("test1")
.build();
Room r2 = Room.builder()
.id(2L)
.title("test2")
.build();
Room r3 = Room.builder()
.id(3L)
.title("test3")
.build();
List<Room> roomList = Arrays.asList(r1, r2, r3);

given(roomService.getRooms()).willReturn(roomList);

// when
ResultActions resultActions = mockMvc.perform(get("/api/rooms"));

// then
resultActions.andExpect(status().isOk())
.andExpect(jsonPath("$.rooms", not(empty())))
.andExpect(jsonPath("$.rooms", hasSize(3)))
.andExpect(jsonPath("$.rooms[0].id", is(1)))
.andExpect(jsonPath("$.rooms[1].id", is(2)))
.andExpect(jsonPath("$.rooms[2].id", is(3)))
.andDo(print());
}

@Test
Expand Down Expand Up @@ -105,9 +135,21 @@ void createRoom_titleLengthLessThan_2() throws Exception {
void createRoom_titleLengthExceed_20() throws Exception {

// given
RoomRequest req = new RoomRequest();
req.setTitle("title length exceeds 20");

final String body = objectMapper.writeValueAsString(req);

// when
ResultActions resultActions = mockMvc.perform(
post("/api/rooms")
.contentType(MediaType.APPLICATION_JSON)
.content(body));

// then
resultActions.andExpect(status().is4xxClientError())
.andExpect(result -> assertTrue(result.getResolvedException() instanceof MethodArgumentNotValidException))
.andDo(print());

}
}

0 comments on commit 6b4b360

Please sign in to comment.