Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

테스트 환경 최적화 및 테스트 픽스처 생성 #442

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ dependencies {
implementation 'com.github.maricn:logback-slack-appender:1.6.1'

compileOnly 'org.projectlombok:lombok'
// runtimeOnly 'com.mysql:mysql-connector-j'
runtimeOnly 'org.postgresql:postgresql' // DB 변경
runtimeOnly 'org.postgresql:postgresql'
runtimeOnly 'com.h2database:h2'

annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import java.util.List;
import java.util.Optional;

Expand All @@ -16,6 +18,8 @@
@Repository
@RequiredArgsConstructor
public class GroupQueryRepository {
@Autowired
EntityManager em;
private final JPAQueryFactory query;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@

import com.map.gaja.TestEntityCreator;
import com.map.gaja.client.domain.model.Client;
import com.map.gaja.common.NativeRepositoryTest;
import com.map.gaja.group.domain.model.Group;
import com.map.gaja.user.domain.model.User;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import java.util.ArrayList;
import java.util.List;

@SpringBootTest
@Transactional
class ClientBulkNativeRepositoryTest {
class ClientBulkNativeRepositoryTest extends NativeRepositoryTest {

@Autowired
ClientBulkRepository repository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@
//import org.junit.jupiter.api.DisplayName;
//import org.junit.jupiter.api.Test;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.transaction.annotation.Transactional;
//
//import javax.persistence.EntityManager;
//
//import java.time.LocalDateTime;
//
//import static org.junit.jupiter.api.Assertions.*;
//
//@SpringBootTest
//@Transactional
//class ClientImageRepositoryTest {
//class ClientImageRepositoryTest extends NativeRepositoryTest{
// @Autowired
// ClientImageRepository clientImageRepository;
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.map.gaja.client.infrastructure.repository;

import com.map.gaja.client.domain.model.Client;
import com.map.gaja.common.NativeRepositoryTest;
import com.map.gaja.global.event.Events;
import com.map.gaja.group.domain.model.Group;
import com.map.gaja.user.domain.model.Authority;
Expand All @@ -10,19 +11,15 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;

import java.time.LocalDateTime;

import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest
@Transactional
class ClientNativeRepositoryTest {
class ClientNativeRepositoryTest extends NativeRepositoryTest {
@Autowired
ClientRepository clientRepository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.map.gaja.client.infrastructure.repository;

import com.map.gaja.TestEntityCreator;
import com.map.gaja.common.NativeRepositoryTest;
import com.map.gaja.group.domain.model.Group;
import com.map.gaja.client.domain.model.Client;
import com.map.gaja.client.presentation.dto.request.NearbyClientSearchRequest;
Expand All @@ -11,18 +12,14 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import java.util.ArrayList;
import java.util.List;

import static org.assertj.core.api.Assertions.*;

@SpringBootTest
@Transactional
class ClientQueryNativeRepositoryTest {
class ClientQueryNativeRepositoryTest extends NativeRepositoryTest {

@Autowired
ClientQueryRepository clientQueryRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.map.gaja.TestEntityCreator;
import com.map.gaja.client.domain.model.Client;
import com.map.gaja.common.RepositoryTest;
import com.map.gaja.global.event.Events;
import com.map.gaja.group.domain.model.Group;
import com.map.gaja.user.domain.model.User;
Expand All @@ -18,9 +19,7 @@

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest
@Transactional
class ClientRepositoryTest {
class ClientRepositoryTest extends RepositoryTest {
@Autowired
ClientRepository clientRepository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
package com.map.gaja.client.presentation.api;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.map.gaja.client.application.*;
import com.map.gaja.client.presentation.dto.request.ClientIdsRequest;
import com.map.gaja.global.authentication.AuthenticationRepository;
import com.map.gaja.common.ControllerTest;
import com.map.gaja.global.authentication.PrincipalDetails;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
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.data.jpa.mapping.JpaMetamodelMappingContext;
import org.springframework.http.MediaType;
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
Expand All @@ -25,30 +17,9 @@
import static org.mockito.Mockito.*;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;

@WebMvcTest(ClientDeleteController.class)
@MockBean(JpaMetamodelMappingContext.class)
class ClientDeleteControllerTest {

@Autowired
MockMvc mvc;

@MockBean
ClientBulkService clientBulkService;
@MockBean
ClientDeleteService clientDeleteService;
@MockBean
ClientAccessVerifyService clientAccessVerifyService;
@MockBean
AuthenticationRepository authenticationRepository;

class ClientDeleteControllerTest extends ControllerTest {
Long groupId = 1L;
Long clientId = 1L;
private ObjectMapper om;

@BeforeEach
void beforeEach() {
om = new ObjectMapper();
}

@Test
@DisplayName("고객 삭제 성공")
Expand All @@ -69,7 +40,7 @@ void deleteBulkClientTest() throws Exception {
String testUrl = "/api/group/{groupId}/clients/bulk-delete";
List<Long> clientIds = List.of(1L, 2L, 3L);
ClientIdsRequest clientIdsRequest = new ClientIdsRequest(clientIds);
String jsonBody = om.writeValueAsString(clientIdsRequest);
String jsonBody = mapper.writeValueAsString(clientIdsRequest);

MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post(testUrl, groupId)
.with(csrf())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
package com.map.gaja.client.presentation.api;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.map.gaja.client.application.*;
import com.map.gaja.client.domain.exception.InvalidFileException;
import com.map.gaja.client.infrastructure.s3.S3FileService;
import com.map.gaja.client.application.validator.ClientRequestValidator;
import com.map.gaja.client.presentation.dto.request.NewClientRequest;
import com.map.gaja.client.presentation.dto.request.simple.SimpleClientBulkRequest;
import com.map.gaja.client.presentation.dto.request.simple.SimpleNewClientRequest;
import com.map.gaja.client.presentation.dto.response.ClientOverviewResponse;
import com.map.gaja.client.presentation.dto.subdto.StoredFileDto;
import com.map.gaja.global.authentication.AuthenticationRepository;
import com.map.gaja.common.ControllerTest;
import com.map.gaja.global.authentication.PrincipalDetails;
import com.map.gaja.group.application.GroupAccessVerifyService;
import com.map.gaja.group.domain.exception.GroupNotFoundException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
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.data.jpa.mapping.JpaMetamodelMappingContext;
import org.springframework.http.MediaType;
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
Expand All @@ -35,33 +23,9 @@
import static org.mockito.Mockito.times;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;

@WebMvcTest(ClientSavingController.class)
@MockBean(JpaMetamodelMappingContext.class)
public class ClientSavingControllerTest {
@Autowired
MockMvc mvc;

@MockBean
ClientBulkService clientBulkService;
@MockBean
GroupAccessVerifyService groupAccessVerifyService;
@MockBean
ClientRequestValidator clientRequestValidator;
@MockBean
AuthenticationRepository authenticationRepository;
@MockBean
ClientSavingService clientSavingService;

private ObjectMapper om;

public class ClientSavingControllerTest extends ControllerTest {
static Long groupId = 1L;
static Long clientId = 1L;


@BeforeEach
void beforeEach() {
om = new ObjectMapper();
}

@Test
@DisplayName("이미지 없이 고객 등록")
Expand Down Expand Up @@ -117,7 +81,7 @@ void addSimpleBulkClient() throws Exception {
);

SimpleClientBulkRequest request = new SimpleClientBulkRequest(groupId, clientsRequest);
String jsonBody = om.writeValueAsString(request);
String jsonBody = mapper.writeValueAsString(request);

MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post(testUrl, groupId)
.with(csrf())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,21 @@
package com.map.gaja.client.presentation.api;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.map.gaja.client.application.*;
import com.map.gaja.client.domain.exception.ClientNotFoundException;
import com.map.gaja.client.domain.exception.InvalidFileException;
import com.map.gaja.client.infrastructure.s3.S3FileService;
import com.map.gaja.client.application.validator.ClientRequestValidator;
import com.map.gaja.client.presentation.dto.request.NewClientRequest;
import com.map.gaja.client.presentation.dto.response.ClientOverviewResponse;
import com.map.gaja.client.presentation.dto.subdto.StoredFileDto;
import com.map.gaja.global.authentication.AuthenticationRepository;
import com.map.gaja.group.application.GroupAccessVerifyService;
import com.map.gaja.common.ControllerTest;
import org.junit.jupiter.api.DisplayName;
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.data.jpa.mapping.JpaMetamodelMappingContext;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.when;

@WebMvcTest(ClientUpdatingController.class)
@MockBean(JpaMetamodelMappingContext.class)
public class ClientUpdatingControllerTest {
@Autowired
MockMvc mvc;

@MockBean
ClientUpdatingService clientUpdatingService;
@MockBean
ClientAccessVerifyService clientAccessVerifyService;
@MockBean
GroupAccessVerifyService groupAccessVerifyService;
@MockBean
ClientRequestValidator clientRequestValidator;
@MockBean
AuthenticationRepository authenticationRepository;



public class ClientUpdatingControllerTest extends ControllerTest {
final String testUri = "/api/group/{groupId}/clients/{clientId}";


Expand Down
Loading