diff --git a/gradlew.bat b/gradlew.bat
index 64a2f73..b51bfba 100644
--- a/gradlew.bat
+++ b/gradlew.bat
@@ -21,7 +21,7 @@
@rem
@rem ##########################################################################
-set JAVA_HOME=D:\tools\java\jdk8144
+set JAVA_HOME=C:\tools\java\azul-11.0.13
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
diff --git a/src/main/java/com/xit/biz/cmm/entity/CmmFileDtl.java b/src/main/java/com/xit/biz/cmm/entity/CmmFileDtl.java
index 15e188a..c389f08 100644
--- a/src/main/java/com/xit/biz/cmm/entity/CmmFileDtl.java
+++ b/src/main/java/com/xit/biz/cmm/entity/CmmFileDtl.java
@@ -34,7 +34,7 @@ public class CmmFileDtl extends AuditEntity implements Serializable {
@Id
@Schema(required = true, title = "파일ID", example = " ", description = "UUID로 자동 생성")
@Column(name = "file_id", nullable = false, length = 50)
- private String fileId;// = UUID.randomUUID().toString().replaceAll("-", "");
+ private String fileId;// = CommUtil.getStringFromUUID();
// @EmbeddedId
// private CmmFileDtlIds cmmFileDtlIds;
diff --git a/src/main/java/com/xit/biz/cmm/service/impl/CmmFileService.java b/src/main/java/com/xit/biz/cmm/service/impl/CmmFileService.java
index ec8d79b..52d16bb 100644
--- a/src/main/java/com/xit/biz/cmm/service/impl/CmmFileService.java
+++ b/src/main/java/com/xit/biz/cmm/service/impl/CmmFileService.java
@@ -8,6 +8,7 @@ import com.xit.biz.cmm.repository.ICmmFileMstRepository;
import com.xit.biz.cmm.service.ICmmFileService;
import com.xit.core.util.AssertUtils;
+import com.xit.core.util.CommUtil;
import com.xit.core.util.DateUtil;
import io.jsonwebtoken.lang.Assert;
import lombok.RequiredArgsConstructor;
@@ -75,7 +76,7 @@ public class CmmFileService implements ICmmFileService {
// file Master key set
// file Master 생성
if(isCheckExists) fileMstId = cmmFileMst.getFileMstId();
- else fileMstId = UUID.randomUUID().toString().replaceAll("-", "");
+ else fileMstId = CommUtil.getStringFromUUID();
cmmFileMst.setFileMstId(fileMstId);
CmmFileMst savedCmmFileMst = cmmFileMstRepository.save(cmmFileMst);
@@ -92,7 +93,7 @@ public class CmmFileService implements ICmmFileService {
orgFileName = StringUtils.cleanPath(Objects.requireNonNull(mf.getOriginalFilename()));
CmmFileDtl cmmFileDtl = CmmFileDtl.builder()
.fileMstId(savedCmmFileMst.getFileMstId())
- .fileId(UUID.randomUUID().toString().replaceAll("-", ""))
+ .fileId(CommUtil.getStringFromUUID())
.fileUpldPath(makePath)
.contentType(mf.getContentType())
.orgFileNm(orgFileName)
diff --git a/src/main/java/com/xit/core/config/aop/LoggerAspect.java b/src/main/java/com/xit/core/config/aop/LoggerAspect.java
index cf670e8..b709843 100644
--- a/src/main/java/com/xit/core/config/aop/LoggerAspect.java
+++ b/src/main/java/com/xit/core/config/aop/LoggerAspect.java
@@ -20,10 +20,17 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
+/**
+ * RequestBody 요청 파라메터 출력은
+ * ReadableRequestWrapperFilter WebFillter를 활성화 하여야 한
+ *
+ * @see com.xit.core.config.filter.log.ReadableRequestWrapperFilter
+ */
@Component
@Aspect
@Slf4j
public class LoggerAspect {
+ // respons 출력 여부
@Value("${api.reponse.logging}")
private boolean isResLogging;
@@ -71,8 +78,8 @@ public class LoggerAspect {
/**
* request 에 담긴 정보를 JSONObject 형태로 반환한다.
- * @param request
- * @return
+ * @param request HttpServletRequest
+ * @return JSONObject
*/
private static JSONObject getParams(HttpServletRequest request) {
JSONObject jsonObject = new JSONObject();
diff --git a/src/main/java/com/xit/core/config/database/DataSourceConfig.java b/src/main/java/com/xit/core/config/database/DataSourceConfig.java
index 523f5f2..319b596 100644
--- a/src/main/java/com/xit/core/config/database/DataSourceConfig.java
+++ b/src/main/java/com/xit/core/config/database/DataSourceConfig.java
@@ -14,27 +14,22 @@ import org.apache.ibatis.type.JdbcType;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
-import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateSettings;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
-import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
-import org.springframework.context.annotation.Profile;
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
-import org.springframework.data.transaction.ChainedTransactionManager;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
-import org.springframework.orm.jpa.vendor.Database;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@@ -92,19 +87,12 @@ public class DataSourceConfig {
return new JpaProperties();
}
- //@Profile("!test")
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(@Value("${spring.jpa.properties.hibernate.hbm2ddl.auto}") String hbm2ddlAuto) {
-// return builder
-// .dataSource(dataSource)
-// .properties(jpaProperties.getProperties())
-// .packages(ENTITY_PACKAGES)
-// .persistenceUnit("default")
-// .build();
-
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setDatabasePlatform(jpaProperties().getDatabasePlatform());
vendorAdapter.setDatabase(jpaProperties().getDatabase());
+ vendorAdapter.setShowSql(jpaProperties().isShowSql());
HibernateProperties hibernateProperties = new HibernateProperties();
hibernateProperties.setDdlAuto(hbm2ddlAuto);
@@ -118,6 +106,7 @@ public class DataSourceConfig {
emf.setPersistenceUnitName("default");
emf.setJpaVendorAdapter(vendorAdapter);
emf.setJpaPropertyMap(propMap); //jpaProperties().getProperties());
+ //emf.getJpaPropertyMap().put(AvailableSettings.BEAN_CONTAINER, new SpringBeanContainer(entityManagerFactory))
return emf;
}
diff --git a/src/main/java/com/xit/core/config/filter/log/CustomCommonsRequestLoggingFilter.java b/src/main/java/com/xit/core/config/filter/log/CustomCommonsRequestLoggingFilter.java
index 466d906..5f72db6 100644
--- a/src/main/java/com/xit/core/config/filter/log/CustomCommonsRequestLoggingFilter.java
+++ b/src/main/java/com/xit/core/config/filter/log/CustomCommonsRequestLoggingFilter.java
@@ -13,6 +13,7 @@ import java.io.IOException;
import java.util.regex.Pattern;
/**
+ *
* WebFilter로 등록
* Application main에 @ServletComponentScan annotation 필요
* logging.level.org.springframework.web.filter=debug 로 설정(로그 출력)
@@ -20,9 +21,12 @@ import java.util.regex.Pattern;
* logback에 CustomCommonsRequestLoggingFilter 에 대한 logger level=debug or info로 설정 해야만 로그 출력
* CommonsRequestLoggingFilter 확장
* logging에서 제외할 url 패턴 지정
+ *
+ * LoggerAspect 에서 로그 출력 하여 미사용
+ *
*/
-@WebFilter(urlPatterns = "/api/*")
-@Order(Ordered.HIGHEST_PRECEDENCE)
+//@WebFilter(urlPatterns = "/api/*")
+//@Order(Ordered.HIGHEST_PRECEDENCE)
public class CustomCommonsRequestLoggingFilter extends CommonsRequestLoggingFilter {
private static final Pattern ONLY_LOGGING_PATTERN = Pattern.compile(XitConstants.EXCLUDE_LOGGING_URL_PATTERN);
CatchLocation catchLocation = CatchLocation.AFTER;
diff --git a/src/main/java/com/xit/core/config/filter/log/ReadableRequestWrapperFilter.java b/src/main/java/com/xit/core/config/filter/log/ReadableRequestWrapperFilter.java
index 1c4e8fb..54449b3 100644
--- a/src/main/java/com/xit/core/config/filter/log/ReadableRequestWrapperFilter.java
+++ b/src/main/java/com/xit/core/config/filter/log/ReadableRequestWrapperFilter.java
@@ -7,9 +7,12 @@ import org.apache.http.entity.ContentType;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
import org.springframework.util.StringUtils;
import javax.servlet.*;
+import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.io.*;
@@ -18,9 +21,12 @@ import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
+/**
+ * Post parameter log를 보려면 활설화 해야 함
+ */
@Slf4j
-//@WebFilter(urlPatterns = "/api/*")
-//@Order(Ordered.HIGHEST_PRECEDENCE)
+@WebFilter(urlPatterns = "/api/*")
+@Order(Ordered.HIGHEST_PRECEDENCE)
public class ReadableRequestWrapperFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) {
@@ -30,7 +36,7 @@ public class ReadableRequestWrapperFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
- ReadableRequestWrapper wrapper = new ReadableRequestWrapper((HttpServletRequest)request);
+ ReadableRequestWrapper wrapper = new ReadableRequestWrapper((HttpServletRequest) request);
chain.doFilter(wrapper, response);
}
@@ -39,7 +45,7 @@ public class ReadableRequestWrapperFilter implements Filter {
// Do nothing
}
- public class ReadableRequestWrapper extends HttpServletRequestWrapper {
+ public static class ReadableRequestWrapper extends HttpServletRequestWrapper {
private final Charset encoding;
private byte[] rawData;
private Map params = new HashMap<>();
diff --git a/src/main/java/com/xit/core/oauth2/api/service/impl/UserService.java b/src/main/java/com/xit/core/oauth2/api/service/impl/UserService.java
index 0d51f71..2f6cd9c 100644
--- a/src/main/java/com/xit/core/oauth2/api/service/impl/UserService.java
+++ b/src/main/java/com/xit/core/oauth2/api/service/impl/UserService.java
@@ -10,6 +10,7 @@ import com.xit.core.oauth2.api.service.IUserService;
import com.xit.core.oauth2.oauth.entity.ProviderType;
import com.xit.core.oauth2.oauth.entity.RoleType;
import com.xit.core.oauth2.utils.SecurityUtil;
+import com.xit.core.util.CommUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.crypto.password.PasswordEncoder;
@@ -40,7 +41,7 @@ public class UserService implements IUserService {
if (cmmUserRepository.existsByUserId(cmmUser.getUserId())) {
throw new UserExistedException(ErrorCode.MEMBER_EXISTS);
}
- cmmUser.setCmmUserId(UUID.randomUUID().toString().replaceAll("-", ""));
+ cmmUser.setCmmUserId(CommUtil.getStringFromUUID());
cmmUser.setCreatedBy(cmmUser.getUserId());
//cmmUser.setCreatedDate(LocalDateTime.now());
cmmUser.setRoleType(RoleType.USER);
diff --git a/src/main/java/com/xit/core/oauth2/oauth/service/CustomOAuth2UserService.java b/src/main/java/com/xit/core/oauth2/oauth/service/CustomOAuth2UserService.java
index b2b0801..d4bfd64 100644
--- a/src/main/java/com/xit/core/oauth2/oauth/service/CustomOAuth2UserService.java
+++ b/src/main/java/com/xit/core/oauth2/oauth/service/CustomOAuth2UserService.java
@@ -8,6 +8,7 @@ import com.xit.core.oauth2.oauth.entity.UserPrincipal;
import com.xit.core.oauth2.oauth.exception.OAuthProviderMissMatchException;
import com.xit.core.oauth2.oauth.info.AbstractOAuth2UserInfo;
import com.xit.core.oauth2.oauth.info.OAuth2UserInfoFactory;
+import com.xit.core.util.CommUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.security.authentication.InternalAuthenticationServiceException;
import org.springframework.security.core.AuthenticationException;
@@ -90,7 +91,7 @@ public class CustomOAuth2UserService extends DefaultOAuth2UserService {
RoleType.USER
);
LocalDateTime localDateTime = LocalDateTime.now();
- user.setCmmUserId(UUID.randomUUID().toString().replaceAll("-", ""));
+ user.setCmmUserId(CommUtil.getStringFromUUID());
user.setCreatedBy(userInfo.getId());
user.setModifiedBy(userInfo.getId());
user.setCreatedDate(localDateTime);
diff --git a/src/main/java/com/xit/core/util/AwsFileUtil.java b/src/main/java/com/xit/core/util/AwsFileUtil.java
index 84b22d9..5f421b4 100644
--- a/src/main/java/com/xit/core/util/AwsFileUtil.java
+++ b/src/main/java/com/xit/core/util/AwsFileUtil.java
@@ -232,7 +232,7 @@ public class AwsFileUtil {
return folder
+ ((folder.substring(folder.length() - 1)).equals("/") ? DateUtil.getToday("")
: ("/" + DateUtil.getToday("")) + "/")
- + UUID.randomUUID().toString().replaceAll("-", "") + System.currentTimeMillis() + ext;
+ + CommUtil.getStringFromUUID() + System.currentTimeMillis() + ext;
}
// /**
diff --git a/src/main/java/com/xit/core/util/CommUtil.java b/src/main/java/com/xit/core/util/CommUtil.java
index d2df5e0..9494df7 100644
--- a/src/main/java/com/xit/core/util/CommUtil.java
+++ b/src/main/java/com/xit/core/util/CommUtil.java
@@ -20,14 +20,15 @@ import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
+import java.util.*;
@Slf4j
public class CommUtil {
+ public static String getStringFromUUID(){
+ return UUID.randomUUID().toString().replaceAll("-", "");
+ }
+
/**
* 클래스의 인스턴스 정보 생성 함수
*
diff --git a/src/main/resources/config/application-dev.yml b/src/main/resources/config/application-dev.yml
index f6fa06e..377adb6 100644
--- a/src/main/resources/config/application-dev.yml
+++ b/src/main/resources/config/application-dev.yml
@@ -32,15 +32,12 @@ spring:
# ==================================================================================================================
jpa:
database-platform: org.hibernate.dialect.PostgreSQLDialect
+ #show-sql: false
properties:
hibernate:
- format_sql: true
- use_sql_comments: false
hbm2ddl:
# create / create-drop / update / validate / none
auto: update
- # hibernate sql log
- #show-sql: false
# h2:
# console:
diff --git a/src/main/resources/config/application-local.yml b/src/main/resources/config/application-local.yml
index 1dffdc6..787583d 100644
--- a/src/main/resources/config/application-local.yml
+++ b/src/main/resources/config/application-local.yml
@@ -32,15 +32,13 @@ spring:
# ==================================================================================================================
jpa:
database-platform: org.hibernate.dialect.H2Dialect
- # hibernate sql log
- show-sql: false
+ #show-sql: false
properties:
hibernate:
- format_sql: true
- use_sql_comments: false
hbm2ddl:
# create / create-drop / update / validate / none
auto: create-drop
+
h2:
console:
enabled: true
@@ -61,13 +59,9 @@ logging:
level:
root: info
org:
- hibernate:
- # hibernate sql log 출력시 변수 바인딩
+ # hibernate sql log 출력시 변수 바인딩
+ #hibernate:
#type: trace
- springframework:
- web:
- #CommonsRequestLoggingFilter(RequestLoggingConfig) 를 이용한 로그출력을 위해 필수 debug
- filter: error
# ==================================================================================================================
# Spring-doc 활성
diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml
index f70dd67..1c79c2e 100644
--- a/src/main/resources/config/application.yml
+++ b/src/main/resources/config/application.yml
@@ -2,15 +2,16 @@ spring:
application:
name: xit-framework
#description: XIT api for development
-
config:
import: classpath:config/conf.yml
profiles:
active: local
include: oauth
- # bean name 중복 허용 - junit 사용시 true??
main:
+ # bean name 중복 허용 - junit 사용시 true??
allow-bean-definition-overriding: true
+ # 순환참조 제거
+ #allow-circular-references: true
# ==================================================================================================================
# spring message
@@ -100,8 +101,6 @@ spring:
# JPA setting
# ==================================================================================================================
jpa:
- hibernate:
- ddl-auto: none
# 템플릿 view 화면의 렌더링이 끝날 때 까지 Lazy fetch 가 가능하도록 해주는 속성
open-in-view: false
generate-ddl: false
@@ -117,6 +116,8 @@ spring:
hbm2ddl:
auto: none
import_files_sql_extractor: org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor
+ format_sql: true
+ use_sql_comments: false
jdbc:
batch_size: 20
lob:
diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml
index 5d76ef7..5e63306 100644
--- a/src/main/resources/logback-spring.xml
+++ b/src/main/resources/logback-spring.xml
@@ -4,11 +4,11 @@
-
+
-
+
@@ -105,14 +105,6 @@
-
-
diff --git a/src/test/java/com/xit/biz/cmm/repository/ICmmCodeRepositoryTest.java b/src/test/java/com/xit/biz/cmm/repository/ICmmCodeRepositoryTest.java
index 51717d8..0df44fb 100644
--- a/src/test/java/com/xit/biz/cmm/repository/ICmmCodeRepositoryTest.java
+++ b/src/test/java/com/xit/biz/cmm/repository/ICmmCodeRepositoryTest.java
@@ -100,7 +100,7 @@ class ICmmCodeRepositoryTest {
System.out.println(comboCodeDtos);
// cmmFileDtlIds.setFileMstId(savedCmmFileMst.getFileMstId());
-// //cmmFileDtlIds.setFileId(UUID.randomUUID().toString().replaceAll("-", ""));
+// //cmmFileDtlIds.setFileId(CommUtil.getStringFromUUID());
// CmmFileDtl cmmFileDtl = CmmFileDtl.builder()
// .fileMstId(cmmFileDtlIds.getFileMstId())
// .fileId(cmmFileDtlIds.getFileId())
diff --git a/src/test/java/com/xit/biz/cmm/repository/ICmmFileRepositoryTest.java b/src/test/java/com/xit/biz/cmm/repository/ICmmFileRepositoryTest.java
index 8ee4f2a..b02b480 100644
--- a/src/test/java/com/xit/biz/cmm/repository/ICmmFileRepositoryTest.java
+++ b/src/test/java/com/xit/biz/cmm/repository/ICmmFileRepositoryTest.java
@@ -3,6 +3,7 @@ package com.xit.biz.cmm.repository;
import com.xit.biz.cmm.entity.CmmFileDtl;
import com.xit.biz.cmm.entity.CmmFileMst;
import com.xit.biz.cmm.entity.ids.CmmFileDtlIds;
+import com.xit.core.util.CommUtil;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -31,7 +32,7 @@ class ICmmFileRepositoryTest {
@Test
void crud(){
CmmFileMst cmmFileMst = CmmFileMst.builder()
- .fileMstId(UUID.randomUUID().toString().replaceAll("-", ""))
+ .fileMstId(CommUtil.getStringFromUUID())
.fileCtgCd("BOARD")
.fileBizId("BOARD1")
.build()
@@ -43,7 +44,7 @@ class ICmmFileRepositoryTest {
CmmFileMst savedCmmFileMst = cmmFileMstRepository.save(cmmFileMst);
CmmFileDtlIds cmmFileDtlIds = new CmmFileDtlIds();
cmmFileDtlIds.setFileMstId(savedCmmFileMst.getFileMstId());
- //cmmFileDtlIds.setFileId(UUID.randomUUID().toString().replaceAll("-", ""));
+ //cmmFileDtlIds.setFileId(CommUtil.getStringFromUUID());
CmmFileDtl cmmFileDtl = CmmFileDtl.builder()
.fileMstId(cmmFileDtlIds.getFileMstId())
.fileId(cmmFileDtlIds.getFileId())
diff --git a/src/test/java/com/xit/core/controller/core/OAuth2LocalControllerTest.java b/src/test/java/com/xit/core/controller/core/OAuth2LocalControllerTest.java
index 201a48e..fcca578 100644
--- a/src/test/java/com/xit/core/controller/core/OAuth2LocalControllerTest.java
+++ b/src/test/java/com/xit/core/controller/core/OAuth2LocalControllerTest.java
@@ -13,6 +13,8 @@ import com.xit.core.oauth2.api.dto.TokenDto;
import com.xit.core.oauth2.api.service.IAuthService;
import com.xit.core.oauth2.oauth.entity.ProviderType;
import com.xit.core.oauth2.oauth.entity.RoleType;
+import com.xit.core.util.CommUtil;
+import com.xit.core.util.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.jupiter.api.AfterEach;
@@ -34,6 +36,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.context.annotation.ComponentScan;
+import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockServletContext;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
@@ -44,6 +47,8 @@ import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MockMvcBuilder;
+import org.springframework.test.web.servlet.MvcResult;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
@@ -53,9 +58,13 @@ import org.springframework.web.filter.CharacterEncodingFilter;
import javax.servlet.ServletContext;
import java.util.Arrays;
+import java.util.Objects;
+import java.util.Optional;
import java.util.UUID;
import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
@@ -79,15 +88,16 @@ class OAuth2LocalControllerTest {
private WebApplicationContext webApplicationContext;
- CmmUser user = CmmUser.builder()
- .providerType(ProviderType.LOCAL)
- .userId("minuk926")
- .userName("임종욱")
- .password("Minuk926!@")
- .email("minuk926@gmail.com")
- .build();
-
-
+ private CmmUser user;
+// = CmmUser.builder()
+// .cmmUserId(CommUtil.getStringFromUUID())
+// .providerType(ProviderType.LOCAL)
+// .userId("minuk926")
+// .userName("임종욱")
+// .password("Minuk926!@")
+// .email("minuk926@gmail.com")
+// .roleType(RoleType.USER)
+// .build();
//@InjectMocks
@@ -103,7 +113,9 @@ class OAuth2LocalControllerTest {
void setUp() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext).build();
- CmmUser user = CmmUser.builder()
+
+ this.user = CmmUser.builder()
+ .cmmUserId(CommUtil.getStringFromUUID())
.providerType(ProviderType.LOCAL)
.userId("minuk926")
.userName("임종욱")
@@ -111,10 +123,10 @@ class OAuth2LocalControllerTest {
.email("minuk926@gmail.com")
.roleType(RoleType.USER)
.build();
- user.setCmmUserId(UUID.randomUUID().toString().replaceAll("-", ""));
- CmmUser cmmUser = userRepository.save(user);
+// user.setCmmUserId(CommUtil.getStringFromUUID());
+// CmmUser cmmUser = userRepository.save(user);
- // userRepository.save(user);
+ // userRepository.save(user);
}
@AfterEach
@@ -132,18 +144,47 @@ class OAuth2LocalControllerTest {
assertNotNull(webApplicationContext.getBean("OAuth2LocalController"));
- MultiValueMap params = new LinkedMultiValueMap<>();
- params.add("providerType", ProviderType.LOCAL.name());
- params.add("userId", "minuk926");
- params.add("password", "Minuk926!@");
- mockMvc.perform(post("/api/vi/auth/login").params(params))
- .andDo(print())
+// MultiValueMap params = new LinkedMultiValueMap<>();
+// params.add("providerType", ProviderType.LOCAL.name());
+// params.add("userId", "minuk926");
+// params.add("password", "Minuk926!@");
+// mockMvc.perform(post("/api/vi/auth/login").params(params))
+// .andDo(print())
+// .andExpect(status().isOk())
+// .andExpect(jsonPath("$.success").value(true))
+// .andExpect(jsonPath("$.data").exists())
+// //.andExpect(jsonPath("$.success").value(true))
+// //.andExpect(jsonPath("$.success").value(true))
+// ;
+
+
+ // given
+ userRepository.save(user);
+ //given(userRepository.save(user)).willReturn(user);
+ //when(userRepository.findByUserId(user.getUserId())).thenReturn(user);
+
+ // when
+
+ // then
+
+ //given(userRepository.save(user)).willReturn(user);
+ //when(userRepository.findByUserId(user.getUserId())).thenReturn()
+
+ LoginRequestDto loginRequestDto = new LoginRequestDto();
+ loginRequestDto.setProviderType(ProviderType.LOCAL);
+ loginRequestDto.setUserId(user.getUserId());
+ loginRequestDto.setPassword("Minuk926!@");
+ MvcResult result = mockMvc.perform(
+ MockMvcRequestBuilders.post("/api/v1/auth/login")
+ .content(Objects.requireNonNull(JsonUtil.toJson(loginRequestDto)))
+ .contentType(MediaType.APPLICATION_JSON)
+ //.accept(MediaType.APPLICATION_JSON)
+ .characterEncoding("UTF-8")
+ ).andDo(print())
.andExpect(status().isOk())
- .andExpect(jsonPath("$.success").value(true))
- .andExpect(jsonPath("$.data").exists())
- //.andExpect(jsonPath("$.success").value(true))
+ .andReturn();
//.andExpect(jsonPath("$.success").value(true))
- ;
+ //.andExpect(jsonPath("$.data").exists());
}
@Test
diff --git a/src/test/java/com/xit/core/oauth2/api/dto/LoginRequestDtoTest.java b/src/test/java/com/xit/core/oauth2/api/dto/LoginRequestDtoTest.java
deleted file mode 100644
index d4e53a2..0000000
--- a/src/test/java/com/xit/core/oauth2/api/dto/LoginRequestDtoTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package com.xit.core.oauth2.api.dto;
-
-import com.xit.core.oauth2.oauth.entity.ProviderType;
-import org.junit.Test;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.mockito.junit.jupiter.MockitoExtension;
-import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.junit4.SpringRunner;
-
-import javax.validation.ConstraintViolation;
-
-import java.util.Set;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-// test runner를 통해 Junit Framework 호출
-// SpringRunner는 SpringJunit4ClassRunner의 단축어
-// @Autowired @MockBean에 해당 하는 것들에만 application context loading
-// 1. component가 주입 되어야 할 때
-// 2. 설정 데이타가 주입되어야 할 때
-// 3. Spring과 관련 없는 기능 테스트시 금지(SpringRunner는 overhead가 크다)
-// @RunWith(SpringRunner.class)
-// @RunWith(SpringRunner.class) : Junit4, @RunWith(MockitoJUnitRunner.class) : Junit 5
-// @Mock : Mock 객체 생성 - mapper에 사용
-// @InjectMocks : Mock 객체 주입 - service 에 사용
-//@RunWith(SpringRunner.class)
-//@RunWith(MockitoJUnitRunner.class)
-@ExtendWith(MockitoExtension.class)
-
-// 1. 메모리 데이타 베이스 설정
-// 2. @Entity class scan
-// 3. Spring Data JAP Repository 설정
-// 4. 테스트 종료시 Rollback
-//@DataJpaTest
-
-// Junit5
-// Spring Test & Spring Boot Test
-// AssertJ
-// Hamcrest
-// Mockito
-// JSONassert
-// JsonPath
-// @ExtendWith(SpringExtention.class)도 적용 되어있어 생략 가능
-// Junit4 사용시 @SpringBootTest는 SpringJUnit4ClassRunner를 상속받는 @RunWhith(SpringRynver.class)와 함께 사용
-//@SpringBootTest
-public class LoginRequestDtoTest {
-
- @BeforeEach
- void setUp() {
- }
-
- @AfterEach
- void tearDown() {
- }
-
- @Test
- public void whenAllInvalid_thenViolationsShouldBeReported() {
- LoginRequestDto dto = new LoginRequestDto();
- //dto.setProviderType(ProviderType.GOOGLE.name());
- //customer.setCustomerTypeOfSubset(CustomerType.DEFAULT);
- //customer.setCustomerTypeMatchesPattern(CustomerType.OLD);
-
-// Set violations = validator.validate(customer);
-
- // assertThat(violations.size()).isEqualTo(3);
-
-// assertThat(violations)
-// .anyMatch(havingPropertyPath("customerTypeString")
-// .and(havingMessage("must be any of enum class com.baeldung.javaxval.enums.demo.CustomerType")));
-// assertThat(violations)
-// .anyMatch(havingPropertyPath("customerTypeOfSubset")
-// .and(havingMessage("must be any of [NEW, OLD]")));
-// assertThat(violations)
-// .anyMatch(havingPropertyPath("customerTypeMatchesPattern")
-// .and(havingMessage("must match \"NEW|DEFAULT\"")));
- }
-
-}
\ No newline at end of file