From c3f2aa348f4de97b0a94213d5d9e432a3a1a3c82 Mon Sep 17 00:00:00 2001 From: Lim Jonguk Date: Mon, 14 Mar 2022 20:51:56 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20querydsl=20=EC=84=A4=EC=A0=95=20=20=20?= =?UTF-8?q?=20=20=20=20=EC=8B=AC=EC=9D=98=20=EB=AA=A9=EB=A1=9D=20=EB=B0=98?= =?UTF-8?q?=EC=98=81=20=20=20=20=20=20=20=ED=8E=98=EC=9D=B4=EC=A7=95=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC(=EC=8B=9C=EC=9E=91=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=200=20=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 80 ++++-- .../cmm/controller/CmmUserMgtController.java | 4 +- .../controller/MinCivBoard680Controller.java | 3 +- .../controller/MinSimsa680Controller.java | 74 +++++ .../controller/MinUserinfoController.java | 2 +- .../com/xit/biz/ctgy/dto/MinSimsa680Dto.java | 77 +++++ .../xit/biz/ctgy/dto/MinSimsa680GroupDto.java | 30 ++ .../biz/ctgy/dto/MinSimsaReviewGroupDto.java | 20 ++ .../dto/struct/MinSimsa680GroupMapstruct.java | 12 + .../ctgy/dto/struct/MinSimsa680Mapstruct.java | 12 + .../com/xit/biz/ctgy/entity/MinSimsa680.java | 25 +- .../xit/biz/ctgy/entity/MinSimsaUser680.java | 20 +- .../com/xit/biz/ctgy/entity/MinUserinfo.java | 24 +- .../repository/IMinSimsa680Repository.java | 7 + .../IMinSimsa680RepositoryCustom.java | 11 + .../IMinSimsa680RepositoryImpl.java | 104 +++++++ .../biz/ctgy/service/IMinSimsa680Service.java | 17 ++ .../ctgy/service/impl/MinSimsa680Service.java | 43 +++ .../core/config/support/QuerydslConfig.java | 22 ++ .../com/xit/core/support/jpa/JpaUtil.java | 2 +- .../jpa/QuerydslPageAndSortRepository.java | 69 +++++ .../jpa/QuerydslPageAndSortRepositoy1.kt | 81 ++++++ src/main/resources/config/application.yml | 4 +- src/test/java/com/xit/ApplicationTest.java | 17 -- .../biz/cmm/BoardControllerMockMvcTest.java | 109 ------- .../com/xit/biz/cmm/BoardControllerTest.java | 60 ---- .../xit/biz/cmm/BoardRepositoryTest__.java | 159 ----------- .../com/xit/biz/cmm/BoardServiceTest.java | 106 ------- .../CmmUserControllerMockMvcTest.java | 122 -------- .../CmmUserControllerMockitoTest.java | 67 ----- .../controller/CmmUserControllerRestTest.java | 89 ------ .../cmm/controller/CmmUserControllerTest.java | 93 ------ .../repository/ICmmBoardRepositoryTest.java | 65 ----- .../repository/ICmmCodeRepositoryTest.java | 144 ---------- .../repository/ICmmFileRepositoryTest.java | 61 ---- .../repository/ICmmUserRepositoryTest.java | 74 ----- .../java/com/xit/biz/cmm/user/ApiTests.java | 42 --- .../xit/biz/cmm/user/IntegrationTests.java | 46 --- .../com/xit/biz/cmm/user/RepositoryTests.java | 35 --- .../com/xit/biz/cmm/user/ServiceTests.java | 58 ---- .../cmm/user/StandaloneControllerTests.java | 44 --- .../IMinSimsa680RepositoryTest.java | 39 +++ .../core/OAuth2LocalControllerTest.java | 268 ------------------ .../core/CmmUserRepositoryTest.java | 54 ---- .../resolver/TestActiveProfileResolver.java | 19 -- .../service/core/OAuthLocalServiceTest.java | 96 ------- 46 files changed, 726 insertions(+), 1884 deletions(-) create mode 100644 src/main/java/com/xit/biz/ctgy/controller/MinSimsa680Controller.java create mode 100644 src/main/java/com/xit/biz/ctgy/dto/MinSimsa680Dto.java create mode 100644 src/main/java/com/xit/biz/ctgy/dto/MinSimsa680GroupDto.java create mode 100644 src/main/java/com/xit/biz/ctgy/dto/MinSimsaReviewGroupDto.java create mode 100644 src/main/java/com/xit/biz/ctgy/dto/struct/MinSimsa680GroupMapstruct.java create mode 100644 src/main/java/com/xit/biz/ctgy/dto/struct/MinSimsa680Mapstruct.java create mode 100644 src/main/java/com/xit/biz/ctgy/repository/IMinSimsa680Repository.java create mode 100644 src/main/java/com/xit/biz/ctgy/repository/IMinSimsa680RepositoryCustom.java create mode 100644 src/main/java/com/xit/biz/ctgy/repository/IMinSimsa680RepositoryImpl.java create mode 100644 src/main/java/com/xit/biz/ctgy/service/IMinSimsa680Service.java create mode 100644 src/main/java/com/xit/biz/ctgy/service/impl/MinSimsa680Service.java create mode 100644 src/main/java/com/xit/core/config/support/QuerydslConfig.java create mode 100644 src/main/java/com/xit/core/support/jpa/QuerydslPageAndSortRepository.java create mode 100644 src/main/java/com/xit/core/support/jpa/QuerydslPageAndSortRepositoy1.kt delete mode 100644 src/test/java/com/xit/ApplicationTest.java delete mode 100644 src/test/java/com/xit/biz/cmm/BoardControllerMockMvcTest.java delete mode 100644 src/test/java/com/xit/biz/cmm/BoardControllerTest.java delete mode 100644 src/test/java/com/xit/biz/cmm/BoardRepositoryTest__.java delete mode 100644 src/test/java/com/xit/biz/cmm/BoardServiceTest.java delete mode 100644 src/test/java/com/xit/biz/cmm/controller/CmmUserControllerMockMvcTest.java delete mode 100644 src/test/java/com/xit/biz/cmm/controller/CmmUserControllerMockitoTest.java delete mode 100644 src/test/java/com/xit/biz/cmm/controller/CmmUserControllerRestTest.java delete mode 100644 src/test/java/com/xit/biz/cmm/controller/CmmUserControllerTest.java delete mode 100644 src/test/java/com/xit/biz/cmm/repository/ICmmBoardRepositoryTest.java delete mode 100644 src/test/java/com/xit/biz/cmm/repository/ICmmCodeRepositoryTest.java delete mode 100644 src/test/java/com/xit/biz/cmm/repository/ICmmFileRepositoryTest.java delete mode 100644 src/test/java/com/xit/biz/cmm/repository/ICmmUserRepositoryTest.java delete mode 100644 src/test/java/com/xit/biz/cmm/user/ApiTests.java delete mode 100644 src/test/java/com/xit/biz/cmm/user/IntegrationTests.java delete mode 100644 src/test/java/com/xit/biz/cmm/user/RepositoryTests.java delete mode 100644 src/test/java/com/xit/biz/cmm/user/ServiceTests.java delete mode 100644 src/test/java/com/xit/biz/cmm/user/StandaloneControllerTests.java create mode 100644 src/test/java/com/xit/biz/ctgy/repository/IMinSimsa680RepositoryTest.java delete mode 100644 src/test/java/com/xit/core/controller/core/OAuth2LocalControllerTest.java delete mode 100644 src/test/java/com/xit/core/repository/core/CmmUserRepositoryTest.java delete mode 100644 src/test/java/com/xit/core/resolver/TestActiveProfileResolver.java delete mode 100644 src/test/java/com/xit/core/service/core/OAuthLocalServiceTest.java diff --git a/build.gradle b/build.gradle index 190bcae..66882d5 100644 --- a/build.gradle +++ b/build.gradle @@ -8,6 +8,7 @@ buildscript { ext { springBootVersion ='2.6.3' + queryDslVersion = "5.0.0" } dependencies { @@ -26,7 +27,7 @@ plugins { id 'war' //id 'net.ltgt.apt' version '0.21' // querydsl - //id 'com.ewerk.gradle.plugins.querydsl' version '1.0.10' + id 'com.ewerk.gradle.plugins.querydsl' version '1.0.10' //id 'org.openapi.generator' version '5.1.1' // docker : jib @@ -122,30 +123,37 @@ dependencies { //-----------------------------------------------------------------------------------// // JPA logging p6spy implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.8.0' - implementation 'p6spy:p6spy:3.9.1' +// implementation 'p6spy:p6spy:3.9.1' // JPA querydsl - //compileOnly 'com.querydsl:querydsl-jpa' - //compileOnly 'com.querydsl:querydsl-apt' +// compileOnly 'com.querydsl:querydsl-jpa:' + String.valueOf(queryDslVersion) +// compileOnly 'com.querydsl:querydsl-apt:' + String.valueOf(queryDslVersion) + implementation "com.querydsl:querydsl-jpa:${queryDslVersion}" + implementation "com.querydsl:querydsl-core:${queryDslVersion}" + implementation "com.querydsl:querydsl-apt:${queryDslVersion}" + annotationProcessor( + "javax.persistence:javax.persistence-api", + "javax.annotation:javax.annotation-api", + "com.querydsl:querydsl-apt:${queryDslVersion}:jpa") // JPA mapstruct : lombok 과 함께 사용시 반드시 순서 지겨야 함다 - lombok이 먼저 선언된 경우 - implementation 'org.projectlombok:lombok-mapstruct-binding:0.2.0' - implementation 'org.projectlombok:lombok' - implementation 'org.mapstruct:mapstruct:1.4.2.Final' - annotationProcessor "org.projectlombok:lombok-mapstruct-binding:0.2.0" - annotationProcessor 'org.projectlombok:lombok' - annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final' +// implementation 'org.projectlombok:lombok-mapstruct-binding:0.2.0' +// implementation 'org.projectlombok:lombok' +// implementation 'org.mapstruct:mapstruct:1.4.2.Final' +// annotationProcessor "org.projectlombok:lombok-mapstruct-binding:0.2.0" +// annotationProcessor 'org.projectlombok:lombok' +// annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final' // JPA mapstruct : lombok 과 함께 사용시 반드시 순서 지겨야 함다 - ㅡmapstruct이 먼저 선언된 경우 // target class 에 @Builder 가 있어도 무시하고 생성자 + setter 를 사용하므로 정상적으로 Mapper 클래스를 Generation 하기 위해서 // @NoArgsConstructor, @Setter 가 필요 // but, 최근 Setter 사용을 지양하는 추세라 mapstruct를 먼저 오도록 해서 @Builder 방식으로 Generation -// implementation 'org.mapstruct:mapstruct:1.4.2.Final' -// implementation 'org.projectlombok:lombok-mapstruct-binding:0.2.0' -// implementation 'org.projectlombok:lombok' -// annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final' -// annotationProcessor "org.projectlombok:lombok-mapstruct-binding:0.2.0" -// annotationProcessor 'org.projectlombok:lombok' + implementation 'org.mapstruct:mapstruct:1.4.2.Final' + implementation 'org.projectlombok:lombok-mapstruct-binding:0.2.0' + implementation 'org.projectlombok:lombok' + annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final' + annotationProcessor "org.projectlombok:lombok-mapstruct-binding:0.2.0" + annotationProcessor 'org.projectlombok:lombok' //-----------------------------------------------------------------------------------// //-----------------------------------------------------------------------------------// @@ -239,6 +247,10 @@ dependencies { testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' + // querydsl + testImplementation "com.querydsl:querydsl-jpa:${queryDslVersion}" + testAnnotationProcessor "com.querydsl:querydsl-apt:${queryDslVersion}" + testCompileOnly 'org.projectlombok:lombok' testAnnotationProcessor 'org.projectlombok:lombok' //-----------------------------------------------------------------------------------// @@ -290,6 +302,42 @@ tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } +//-----------------------------------------------------------------------------------// +// querydsl +//-----------------------------------------------------------------------------------// +def querydslDir = "$buildDir/generated" +querydsl { + jpa = true + querydslSourcesDir = querydslDir +} +sourceSets { + main { + java { + //srcDirs = ["$projectDir/src/main/java", querydslDir] + srcDir querydslDir + } + } +} +configurations { + compileOnly { + extendsFrom annotationProcessor + } + querydsl.extendsFrom compileClasspath +} +compileQuerydsl { + options.annotationProcessorPath = configurations.querydsl +} + +compileJava { + options.compilerArgs << '-s' + options.compilerArgs << "$buildDir/generated/" + + doFirst { + delete(files("${buildDir}/generated/")) + file(new File(buildDir, '/generated/')).mkdirs(); + } +} +//-----------------------------------------------------------------------------------// test { //exclude '**/*' diff --git a/src/main/java/com/xit/biz/cmm/controller/CmmUserMgtController.java b/src/main/java/com/xit/biz/cmm/controller/CmmUserMgtController.java index cd82e86..6b6527c 100644 --- a/src/main/java/com/xit/biz/cmm/controller/CmmUserMgtController.java +++ b/src/main/java/com/xit/biz/cmm/controller/CmmUserMgtController.java @@ -38,7 +38,7 @@ public class CmmUserMgtController { @Operation(summary = "사용자 전체 목록 조회" , description = "등록된 사용자 전체 목록 조회") @Parameters({ - @Parameter(in = ParameterIn.QUERY, name = "page", description = "페이지", required = true, example = "1"), + @Parameter(in = ParameterIn.QUERY, name = "page", description = "페이지", required = true, example = "0"), @Parameter(in = ParameterIn.QUERY, name = "size", description = "페이지당갯수", required = true, example = "10") }) @GetMapping(value="/page1", produces = MediaType.APPLICATION_JSON_VALUE) @@ -60,7 +60,7 @@ public class CmmUserMgtController { @Parameter(name = "userEmail", hidden = true), @Parameter(name = "userPswd", hidden = true), @Parameter(name = "authority", hidden = true), - @Parameter(in = ParameterIn.QUERY, name = "page", description = "페이지", required = true, example = "1"), + @Parameter(in = ParameterIn.QUERY, name = "page", description = "페이지", required = true, example = "0"), @Parameter(in = ParameterIn.QUERY, name = "size", description = "페이지당갯수", required = true, example = "10") //@Parameter(in = ParameterIn.QUERY, name = "sort", description = "정렬", required = true, example = "codeOrdr"), }) diff --git a/src/main/java/com/xit/biz/ctgy/controller/MinCivBoard680Controller.java b/src/main/java/com/xit/biz/ctgy/controller/MinCivBoard680Controller.java index 29ec1fb..98ca675 100644 --- a/src/main/java/com/xit/biz/ctgy/controller/MinCivBoard680Controller.java +++ b/src/main/java/com/xit/biz/ctgy/controller/MinCivBoard680Controller.java @@ -37,13 +37,12 @@ public class MinCivBoard680Controller { @Parameters({ @Parameter(in = ParameterIn.QUERY, name = "ciTitle", description = "제목", required = false, example = " "), @Parameter(in = ParameterIn.QUERY, name = "ciName", description = "이름", required = false, example = " "), - @Parameter(in = ParameterIn.QUERY, name = "page", description = "페이지", required = true, example = "1"), + @Parameter(in = ParameterIn.QUERY, name = "page", description = "페이지", required = true, example = "0"), @Parameter(in = ParameterIn.QUERY, name = "size", description = "페이지당갯수", required = true, example = "10") }) @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity findMinCivBoard680s( @Parameter(hidden = true) - //@ModelAttribute("minCivBoard680Dto") final MinCivBoard680Dto minCivBoard680Dto, @Parameter(hidden = true) final Pageable pageable) { diff --git a/src/main/java/com/xit/biz/ctgy/controller/MinSimsa680Controller.java b/src/main/java/com/xit/biz/ctgy/controller/MinSimsa680Controller.java new file mode 100644 index 0000000..279c343 --- /dev/null +++ b/src/main/java/com/xit/biz/ctgy/controller/MinSimsa680Controller.java @@ -0,0 +1,74 @@ +package com.xit.biz.ctgy.controller; + +import com.xit.biz.ctgy.dto.MinSimsa680Dto; +import com.xit.biz.ctgy.dto.MinSimsa680GroupDto; +import com.xit.biz.ctgy.dto.struct.MinSimsa680GroupMapstruct; +import com.xit.biz.ctgy.dto.struct.MinSimsa680Mapstruct; +import com.xit.biz.ctgy.service.IMinSimsa680Service; +import com.xit.core.api.IRestResponse; +import com.xit.core.api.RestResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.mapstruct.factory.Mappers; +import org.springframework.data.domain.Pageable; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.validation.Valid; + +@Tag(name = "MinCivBoard680Controller", description = "게시글 관리") +@RestController +@RequestMapping("/api/v1/ctgy/simsa") +@Validated +@RequiredArgsConstructor +public class MinSimsa680Controller { + + private final IMinSimsa680Service service; + + private final MinSimsa680Mapstruct mapstruct = Mappers.getMapper(MinSimsa680Mapstruct.class); + private final MinSimsa680GroupMapstruct groupMapstruct = Mappers.getMapper(MinSimsa680GroupMapstruct.class); + + @Operation(summary = "심사(대상) 목록 조회" , description = "심사(대상) 목록 조회") + @Parameters({ + @Parameter(in = ParameterIn.QUERY, name = "msYear", description = "심사년도", required = true, example = "2021"), + @Parameter(in = ParameterIn.QUERY, name = "msChasu", description = "차수", required = false, example = " "), + @Parameter(in = ParameterIn.QUERY, name = "page", description = "페이지", required = true, example = "0"), + @Parameter(in = ParameterIn.QUERY, name = "size", description = "페이지당갯수", required = true, example = "10") + + }) + @GetMapping(value="review", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity findMinSimsa680Groups( + @Valid + @Parameter(hidden = true) + final MinSimsa680GroupDto minSimsa680GroupDto, + @Parameter(hidden = true) + final Pageable pageable) { + return RestResponse.of(service.findMinSimsa680Groups(minSimsa680GroupDto, pageable)); + } + + // TODO :: 파라메터 정의 필요 + @Operation(summary = "심사(대상)자 조회" , description = "심사(대상)자 조회") + @Parameters({ + @Parameter(in = ParameterIn.QUERY, name = "page", description = "페이지", required = true, example = "0"), + @Parameter(in = ParameterIn.QUERY, name = "size", description = "페이지당갯수", required = true, example = "10") + }) + @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) + @Transactional(readOnly = true) + public ResponseEntity findMinSimsa680s( + @Parameter(hidden = true) + final MinSimsa680Dto minSimsa680Dto, + @Parameter(hidden = true) + final Pageable pageable) { + return RestResponse.of(service.findMinSimsa680s2(mapstruct.toEntity(minSimsa680Dto), pageable)); + } + +} diff --git a/src/main/java/com/xit/biz/ctgy/controller/MinUserinfoController.java b/src/main/java/com/xit/biz/ctgy/controller/MinUserinfoController.java index 06cec4f..7e160fa 100644 --- a/src/main/java/com/xit/biz/ctgy/controller/MinUserinfoController.java +++ b/src/main/java/com/xit/biz/ctgy/controller/MinUserinfoController.java @@ -44,7 +44,7 @@ public class MinUserinfoController { @Parameters({ @Parameter(in = ParameterIn.QUERY, name = "userid", description = "사용자ID", required = false, example = " "), @Parameter(in = ParameterIn.QUERY, name = "name", description = "이름", required = false, example = " "), - @Parameter(in = ParameterIn.QUERY, name = "page", description = "페이지", required = true, example = "1"), + @Parameter(in = ParameterIn.QUERY, name = "page", description = "페이지", required = true, example = "0"), @Parameter(in = ParameterIn.QUERY, name = "size", description = "페이지당갯수", required = true, example = "10") }) @GetMapping(value="users", produces = MediaType.APPLICATION_JSON_VALUE) diff --git a/src/main/java/com/xit/biz/ctgy/dto/MinSimsa680Dto.java b/src/main/java/com/xit/biz/ctgy/dto/MinSimsa680Dto.java new file mode 100644 index 0000000..a503247 --- /dev/null +++ b/src/main/java/com/xit/biz/ctgy/dto/MinSimsa680Dto.java @@ -0,0 +1,77 @@ +package com.xit.biz.ctgy.dto; + +import com.xit.biz.ctgy.entity.MinSimsaUser680; +import com.xit.biz.ctgy.entity.Tf680Recall; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; + +@Schema(name = "MinCivBoard680Dto", description = "게시판") +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +public class MinSimsa680Dto { + // private static final long SerialVersionUID = 1L; + + @Schema(required = true, title = "민원코드", example = " ", description = "Input Description...") + private Long id; + + // private Tf680Recall tf680Recall; + + + + + // private final Set minSimsaUser680s = new HashSet<>(); + + + + + + @Schema(required = true, title = "접수번호", example = " ", description = "Input Description...") + private String msSeq; + + @Schema(required = true, title = "차량번호", example = " ", description = "Input Description...") + private String msCarnum; + + @Schema(required = true, title = "년도", example = " ", description = "Input Description...") + private String msYear; + + @Schema(required = true, title = "차수", example = " ", description = "Input Description...") + private Long msChasu; + + @Schema(required = true, title = "심사시작일시", example = " ", description = "Input Description...") + private java.sql.Date msSdate; + + @Schema(required = true, title = "심사시작시간", example = " ", description = "Input Description...") + private String msStartsi; + + @Schema(required = true, title = "심사종료일시", example = " ", description = "Input Description...") + private java.sql.Date msEdate; + + @Schema(required = true, title = "심사마감일시", example = " ", description = "Input Description...") + private java.sql.Date msCdate; + + @Schema(required = true, title = "심사마감시간", example = " ", description = "Input Description...") + private String msClosesi; + + @Schema(required = false, title = "단속일자", example = " ", description = "Input Description...") + private java.sql.Date msWdate; + + @Schema(required = false, title = "단속장소", example = " ", description = "Input Description...") + private String msPos; + + @Schema(required = false, title = "결과코드", example = " ", description = "Input Description...") + private String msResult; + + @Schema(required = false, title = "단속시간", example = " ", description = "Input Description...") + private String msJbtime; + +} diff --git a/src/main/java/com/xit/biz/ctgy/dto/MinSimsa680GroupDto.java b/src/main/java/com/xit/biz/ctgy/dto/MinSimsa680GroupDto.java new file mode 100644 index 0000000..561fa9b --- /dev/null +++ b/src/main/java/com/xit/biz/ctgy/dto/MinSimsa680GroupDto.java @@ -0,0 +1,30 @@ +package com.xit.biz.ctgy.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +import javax.validation.constraints.Size; +import java.sql.Date; + +@Schema(name = "MinSimsa680GroupDto", description = "심의목록 조회") +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class MinSimsa680GroupDto { + @Schema(required = true, title = "심사년도", example = "2021", description = "심사년도") + @Size(min = 4, max = 4) + private String msYear; + + @Schema(title = "차수", example = " ", description = "차수") + private Long msChasu; + private Date msSdate; + private String msStartsi; + private Date msEdate; + private Date msCdate; + private String msClosesi; + private Long cnt; + + +} diff --git a/src/main/java/com/xit/biz/ctgy/dto/MinSimsaReviewGroupDto.java b/src/main/java/com/xit/biz/ctgy/dto/MinSimsaReviewGroupDto.java new file mode 100644 index 0000000..2ed211e --- /dev/null +++ b/src/main/java/com/xit/biz/ctgy/dto/MinSimsaReviewGroupDto.java @@ -0,0 +1,20 @@ +package com.xit.biz.ctgy.dto; + +import com.querydsl.core.annotations.QueryProjection; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +import java.sql.Date; + +@Schema(name = "MinSimsaReviewGroupDto", description = "심사자 조회") +@Getter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class MinSimsaReviewGroupDto { + private Date msEdate; + private String msuTeam; + private String name; + private Long clcnt; + private Long totcnt; +} diff --git a/src/main/java/com/xit/biz/ctgy/dto/struct/MinSimsa680GroupMapstruct.java b/src/main/java/com/xit/biz/ctgy/dto/struct/MinSimsa680GroupMapstruct.java new file mode 100644 index 0000000..5c61bf0 --- /dev/null +++ b/src/main/java/com/xit/biz/ctgy/dto/struct/MinSimsa680GroupMapstruct.java @@ -0,0 +1,12 @@ +package com.xit.biz.ctgy.dto.struct; + +import com.xit.biz.ctgy.dto.MinSimsa680GroupDto; +import com.xit.biz.ctgy.entity.MinSimsa680; +import com.xit.core.support.jpa.mapstruct.IMapstruct; +import com.xit.core.support.jpa.mapstruct.MapStructMapperConfig; +import org.mapstruct.Mapper; + +@Mapper(config = MapStructMapperConfig.class) +public interface MinSimsa680GroupMapstruct extends IMapstruct { + +} diff --git a/src/main/java/com/xit/biz/ctgy/dto/struct/MinSimsa680Mapstruct.java b/src/main/java/com/xit/biz/ctgy/dto/struct/MinSimsa680Mapstruct.java new file mode 100644 index 0000000..9d5ca15 --- /dev/null +++ b/src/main/java/com/xit/biz/ctgy/dto/struct/MinSimsa680Mapstruct.java @@ -0,0 +1,12 @@ +package com.xit.biz.ctgy.dto.struct; + +import com.xit.biz.ctgy.dto.MinSimsa680Dto; +import com.xit.biz.ctgy.entity.MinSimsa680; +import com.xit.core.support.jpa.mapstruct.IMapstruct; +import com.xit.core.support.jpa.mapstruct.MapStructMapperConfig; +import org.mapstruct.Mapper; + +@Mapper(config = MapStructMapperConfig.class) +public interface MinSimsa680Mapstruct extends IMapstruct { + +} diff --git a/src/main/java/com/xit/biz/ctgy/entity/MinSimsa680.java b/src/main/java/com/xit/biz/ctgy/entity/MinSimsa680.java index 239ea88..796e27f 100644 --- a/src/main/java/com/xit/biz/ctgy/entity/MinSimsa680.java +++ b/src/main/java/com/xit/biz/ctgy/entity/MinSimsa680.java @@ -17,28 +17,29 @@ import java.util.Set; @Data @Entity @Table(name = "min_simsa680", schema = "", catalog = "") -public class MinSimsa680 implements Serializable { - private static final long SerialVersionUID = 1L; +public class MinSimsa680 { //implements Serializable { + //private static final long SerialVersionUID = 1L; @Schema(required = true, title = "민원코드", example = " ", description = "Input Description...") @Id @Column(name = "ms_maincode") - private Long id; + private Long msMaincode; - @Schema(required = true, title = "민원코드", example = " ", description = "Input Description...") -// @Column(name = "MS_MAINCODE", nullable = false) - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "rc_code") - /*private Long msMaincode;*/ - private Tf680Recall tf680Recall; +// @Schema(required = true, title = "민원코드", example = " ", description = "Input Description...") +//// @Column(name = "MS_MAINCODE", nullable = false) +// @OneToOne(fetch = FetchType.LAZY) +// @JoinColumn(name = "rc_code") +// /*private Long msMaincode;*/ +// private Tf680Recall tf680Recall; - @OneToMany(targetEntity = MinSimsaUser680.class, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "msu_maincode") - private final Set minSimsaUser680s = new HashSet<>(); + //@OneToMany(targetEntity = MinSimsaUser680.class, cascade = CascadeType.ALL, orphanRemoval = true) + //@JoinColumn(name = "msu_maincode") + //@OneToMany(targetEntity = MinSimsaUser680.class, mappedBy = "minSimsa680") //, fetch = FetchType.EAGER)//, cascade = CascadeType.ALL, orphanRemoval = true) + //private final Set minSimsaUser680s = new HashSet<>(); diff --git a/src/main/java/com/xit/biz/ctgy/entity/MinSimsaUser680.java b/src/main/java/com/xit/biz/ctgy/entity/MinSimsaUser680.java index a21aaa2..e0022eb 100644 --- a/src/main/java/com/xit/biz/ctgy/entity/MinSimsaUser680.java +++ b/src/main/java/com/xit/biz/ctgy/entity/MinSimsaUser680.java @@ -28,9 +28,9 @@ public class MinSimsaUser680 implements Serializable { @Column(name = "msu_maincode", length = 10) private Long msuMaincode; -// @Schema(required = true, title = "민원심사사용자코드", example = " ", description = "Input Description...") -// @Column(name = "msu_userid", nullable = false, length = 20) -// private String msuUserid; + @Schema(required = true, title = "민원심사사용자코드", example = " ", description = "Input Description...") + @Column(name = "msu_userid", nullable = false, length = 20) + private String msuUserid; @Schema(required = false, title = "결과코드", example = " ", description = "Input Description...") @Column(name = "msu_result", nullable = true) @@ -54,9 +54,13 @@ public class MinSimsaUser680 implements Serializable { //@JsonIgnore - @Setter - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "msu_userid") - private MinUserinfo minUserinfo; - +// @Setter +// @ManyToOne(fetch = FetchType.LAZY) +// @JoinColumn(name = "msu_userid") +// private MinUserinfo minUserinfo; +// +// @Setter +// @ManyToOne(fetch = FetchType.LAZY) +// @JoinColumn(name = "msu_maincode") +// private MinSimsa680 minSimsa680; } diff --git a/src/main/java/com/xit/biz/ctgy/entity/MinUserinfo.java b/src/main/java/com/xit/biz/ctgy/entity/MinUserinfo.java index 4f99056..d21d23b 100644 --- a/src/main/java/com/xit/biz/ctgy/entity/MinUserinfo.java +++ b/src/main/java/com/xit/biz/ctgy/entity/MinUserinfo.java @@ -71,18 +71,18 @@ public class MinUserinfo implements Serializable { //@Transient //@JsonIgnore - @OneToMany(targetEntity = MinSimsaUser680.class, mappedBy = "minUserinfo") //, fetch = FetchType.EAGER)//, cascade = CascadeType.ALL, orphanRemoval = true) - private final Set minSimsaUser680s = new HashSet<>(); - - public void addMinSimsaUser680(final MinSimsaUser680 minSimsaUser680){ - minSimsaUser680s.add(minSimsaUser680); - minSimsaUser680.setMinUserinfo(this); - } - - public void removeSimsaUser680(final MinSimsaUser680 minSimsaUser680){ - minSimsaUser680s.remove(minSimsaUser680); - minSimsaUser680.setMinUserinfo(null); - } + //@OneToMany(targetEntity = MinSimsaUser680.class, mappedBy = "minUserinfo") //, fetch = FetchType.EAGER)//, cascade = CascadeType.ALL, orphanRemoval = true) + //private final Set minSimsaUser680s = new HashSet<>(); + +// public void addMinSimsaUser680(final MinSimsaUser680 minSimsaUser680){ +// minSimsaUser680s.add(minSimsaUser680); +// minSimsaUser680.setMinUserinfo(this); +// } +// +// public void removeSimsaUser680(final MinSimsaUser680 minSimsaUser680){ +// minSimsaUser680s.remove(minSimsaUser680); +// minSimsaUser680.setMinUserinfo(null); +// } @Override public boolean equals(Object o) { diff --git a/src/main/java/com/xit/biz/ctgy/repository/IMinSimsa680Repository.java b/src/main/java/com/xit/biz/ctgy/repository/IMinSimsa680Repository.java new file mode 100644 index 0000000..7f46169 --- /dev/null +++ b/src/main/java/com/xit/biz/ctgy/repository/IMinSimsa680Repository.java @@ -0,0 +1,7 @@ +package com.xit.biz.ctgy.repository; + +import com.xit.biz.ctgy.entity.MinSimsa680; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface IMinSimsa680Repository extends JpaRepository, IMinSimsa680RepositoryCustom { +} diff --git a/src/main/java/com/xit/biz/ctgy/repository/IMinSimsa680RepositoryCustom.java b/src/main/java/com/xit/biz/ctgy/repository/IMinSimsa680RepositoryCustom.java new file mode 100644 index 0000000..fabe796 --- /dev/null +++ b/src/main/java/com/xit/biz/ctgy/repository/IMinSimsa680RepositoryCustom.java @@ -0,0 +1,11 @@ +package com.xit.biz.ctgy.repository; + +import com.xit.biz.ctgy.dto.MinSimsa680GroupDto; +import com.xit.biz.ctgy.dto.MinSimsaReviewGroupDto; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +public interface IMinSimsa680RepositoryCustom { + Page findMinSimsa680Groups(MinSimsa680GroupDto pMinSimsa680GroupDto, Pageable pageable); + Page findMinSimsa680s2(Pageable pageable); +} diff --git a/src/main/java/com/xit/biz/ctgy/repository/IMinSimsa680RepositoryImpl.java b/src/main/java/com/xit/biz/ctgy/repository/IMinSimsa680RepositoryImpl.java new file mode 100644 index 0000000..41aa325 --- /dev/null +++ b/src/main/java/com/xit/biz/ctgy/repository/IMinSimsa680RepositoryImpl.java @@ -0,0 +1,104 @@ +package com.xit.biz.ctgy.repository; + +import com.querydsl.core.BooleanBuilder; +import com.querydsl.core.QueryResults; +import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.CaseBuilder; +import com.querydsl.jpa.impl.JPAQueryFactory; +import com.xit.biz.ctgy.dto.MinSimsa680GroupDto; +import com.xit.biz.ctgy.dto.MinSimsaReviewGroupDto; +import com.xit.core.util.Checks; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; + +import static com.xit.biz.ctgy.entity.QMinSimsa680.minSimsa680; +import static com.xit.biz.ctgy.entity.QMinSimsaUser680.minSimsaUser680; +import static com.xit.biz.ctgy.entity.QMinUserinfo.minUserinfo; + +@RequiredArgsConstructor +public class IMinSimsa680RepositoryImpl implements IMinSimsa680RepositoryCustom { + + private final JPAQueryFactory queryFactory; + + @Override + public Page findMinSimsa680Groups(MinSimsa680GroupDto pMinSimsa680GroupDto, Pageable pageable) { + /* + SELECT MS_CHASU, MS_SDATE, MS_STARTSI, MS_EDATE, MS_CDATE, MS_CLOSESI, COUNT(*) CNT + FROM MIN_SIMSA680 + WHERE MS_YEAR = '"& rYear &"' AND MS_CHASU LIKE '%"& rChasu &"%' + GROUP BY MS_CHASU, MS_SDATE, MS_STARTSI, MS_EDATE, MS_CDATE, MS_CLOSESI + ORDER BY MS_CHASU DESC + */ + + + BooleanBuilder builder = new BooleanBuilder(); + if( !Checks.isEmpty(pMinSimsa680GroupDto.getMsYear())) { + builder.and(minSimsa680.msYear.eq(pMinSimsa680GroupDto.getMsYear())); + } + if( !Checks.isEmpty(pMinSimsa680GroupDto.getMsChasu())) { + builder.and(minSimsa680.msChasu.like(String.valueOf(pMinSimsa680GroupDto.getMsChasu()))); + } + QueryResults rslt = + queryFactory.select(Projections.fields( + MinSimsa680GroupDto.class, + minSimsa680.msYear, + minSimsa680.msChasu, + minSimsa680.msSdate, + minSimsa680.msStartsi, + minSimsa680.msEdate, + minSimsa680.msCdate, + minSimsa680.msClosesi, + minSimsa680.count().as("cnt") + )) + .from(minSimsa680) + .where(builder) + .groupBy(minSimsa680.msYear, minSimsa680.msChasu, minSimsa680.msSdate, minSimsa680.msStartsi, minSimsa680.msEdate, minSimsa680.msCdate, minSimsa680.msClosesi) + .orderBy(minSimsa680.msYear.desc(), minSimsa680.msChasu.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetchResults(); + + + return new PageImpl<>(rslt.getResults(), pageable, rslt.getTotal()); + } + + @Override + public Page findMinSimsa680s2(Pageable pageable) { + /* + SELECT MS_EDATE, MSU_TEAM, NAME, SUM(DECODE(MSU_RESULT, 0, 0, 1)) CLCNT, COUNT(*) TOTCNT + FROM MIN_USERINFO, MIN_SIMSA_USER680, MIN_SIMSA680 + WHERE USERID = MSU_USERID AND MS_MAINCODE = MSU_MAINCODE + GROUP BY MS_EDATE, MSU_TEAM, NAME + ORDER BY MS_EDATE DESC, MSU_TEAM, NAME + */ + +// Expression rsltEa = new CaseBuilder() +// .when(minSimsaUser680.msuResult.eq("0")).then(0L) +// .otherwise(1L).sum().as("clcnt"); + QueryResults rslt = + queryFactory.select(Projections.fields( + MinSimsaReviewGroupDto.class, + minSimsa680.msEdate, + minSimsaUser680.msuTeam, + minUserinfo.name, + new CaseBuilder() + .when(minSimsaUser680.msuResult.eq("0")).then(0L) + .otherwise(1L).sum().as("clcnt"), + minSimsa680.count().as("totcnt") + )) + .from(minSimsaUser680) + .join(minSimsa680) + .on(minSimsa680.msMaincode.eq(minSimsaUser680.msuMaincode)) + .join(minUserinfo) + .on(minSimsaUser680.msuUserid.eq(minUserinfo.userid)) + .groupBy(minSimsa680.msEdate, minSimsaUser680.msuTeam, minUserinfo.name) + .orderBy(minSimsa680.msEdate.desc(), minSimsaUser680.msuTeam.asc(), minUserinfo.name.asc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetchResults(); + + return new PageImpl<>(rslt.getResults(), pageable, rslt.getTotal()); + } +} diff --git a/src/main/java/com/xit/biz/ctgy/service/IMinSimsa680Service.java b/src/main/java/com/xit/biz/ctgy/service/IMinSimsa680Service.java new file mode 100644 index 0000000..4253cec --- /dev/null +++ b/src/main/java/com/xit/biz/ctgy/service/IMinSimsa680Service.java @@ -0,0 +1,17 @@ +package com.xit.biz.ctgy.service; + +import com.xit.biz.ctgy.dto.MinSimsa680GroupDto; +import com.xit.biz.ctgy.dto.MinSimsaReviewGroupDto; +import com.xit.biz.ctgy.entity.MinSimsa680; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +public interface IMinSimsa680Service { + + //Page findMinSimsa680Groups(MinSimsa680 minSimsa680, Pageable pageable); + Page findMinSimsa680Groups(MinSimsa680GroupDto minSimsa680GroupDto, Pageable pageable); + + Page findMinSimsa680s(MinSimsa680 minSimsa680, Pageable pageable); + + Page findMinSimsa680s2(MinSimsa680 minSimsa680, Pageable pageable); +} diff --git a/src/main/java/com/xit/biz/ctgy/service/impl/MinSimsa680Service.java b/src/main/java/com/xit/biz/ctgy/service/impl/MinSimsa680Service.java new file mode 100644 index 0000000..187e8e4 --- /dev/null +++ b/src/main/java/com/xit/biz/ctgy/service/impl/MinSimsa680Service.java @@ -0,0 +1,43 @@ +package com.xit.biz.ctgy.service.impl; + +import com.xit.biz.ctgy.dto.MinSimsa680GroupDto; +import com.xit.biz.ctgy.dto.MinSimsaReviewGroupDto; +import com.xit.biz.ctgy.entity.MinSimsa680; +import com.xit.biz.ctgy.repository.IMinSimsa680Repository; +import com.xit.biz.ctgy.service.IMinSimsa680Service; +import com.xit.core.support.jpa.JpaUtil; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.*; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains; + +@Service +@RequiredArgsConstructor +public class MinSimsa680Service implements IMinSimsa680Service { + + private final IMinSimsa680Repository repository; + + @Transactional(readOnly = true) + public Page findMinSimsa680s(MinSimsa680 minSimsa680, Pageable pageable) { + pageable = JpaUtil.getPagingInfo(pageable); + ExampleMatcher exampleMatcher = ExampleMatcher.matchingAll() + .withMatcher("ciTitle", contains()) + .withMatcher("ciName", contains()); + Example example = Example.of(minSimsa680, exampleMatcher); + Page page = repository.findAll(example, pageable); + // List userList = page.getContent(); + return page; + } + + @Transactional(readOnly = true) + public Page findMinSimsa680Groups(MinSimsa680GroupDto minSimsa680GroupDto, Pageable pageable) { + return repository.findMinSimsa680Groups(minSimsa680GroupDto, pageable); + } + + @Transactional(readOnly = true) + public Page findMinSimsa680s2(MinSimsa680 minSimsa680, Pageable pageable) { + return repository.findMinSimsa680s2(pageable); + } +} diff --git a/src/main/java/com/xit/core/config/support/QuerydslConfig.java b/src/main/java/com/xit/core/config/support/QuerydslConfig.java new file mode 100644 index 0000000..cbfd92c --- /dev/null +++ b/src/main/java/com/xit/core/config/support/QuerydslConfig.java @@ -0,0 +1,22 @@ +package com.xit.core.config.support; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +/** + * JPA Querydsl 사용을 위한 설정 + */ +@Configuration +public class QuerydslConfig { + @PersistenceContext + private EntityManager entityManager; + + @Bean + public JPAQueryFactory jpaQueryFactory() { + return new JPAQueryFactory(entityManager); + } +} diff --git a/src/main/java/com/xit/core/support/jpa/JpaUtil.java b/src/main/java/com/xit/core/support/jpa/JpaUtil.java index 7a45bd6..201f7e4 100644 --- a/src/main/java/com/xit/core/support/jpa/JpaUtil.java +++ b/src/main/java/com/xit/core/support/jpa/JpaUtil.java @@ -16,7 +16,7 @@ public class JpaUtil { if(Checks.isEmpty(pageable)){ return PageRequest.of(pageNumber, pageSize); } - int page = Checks.isEmpty(pageable.getPageNumber())? pageNumber: pageable.getPageNumber() - 1; + int page = Checks.isEmpty(pageable.getPageNumber())? pageNumber: pageable.getPageNumber(); int limit = Checks.isEmpty(pageable.getPageSize())? pageSize: pageable.getPageSize(); Sort sort = Checks.isEmpty(pageable.getSort())? null: pageable.getSort(); if(Checks.isEmpty(sort)) return PageRequest.of(page, limit); diff --git a/src/main/java/com/xit/core/support/jpa/QuerydslPageAndSortRepository.java b/src/main/java/com/xit/core/support/jpa/QuerydslPageAndSortRepository.java new file mode 100644 index 0000000..b7183f3 --- /dev/null +++ b/src/main/java/com/xit/core/support/jpa/QuerydslPageAndSortRepository.java @@ -0,0 +1,69 @@ +package com.xit.core.support.jpa; + +import com.querydsl.core.QueryMetadata; +import com.querydsl.core.types.dsl.PathBuilder; +import com.querydsl.core.types.dsl.PathBuilderFactory; +import com.querydsl.jpa.JPQLQuery; +import java.util.List; +import javax.persistence.EntityManager; +import kotlin.Metadata; +import kotlin.collections.CollectionsKt; +import kotlin.jvm.internal.Intrinsics; +import org.jetbrains.annotations.NotNull; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.support.Querydsl; + +@Metadata( + mv = {1, 6, 0}, + k = 1, + d1 = {"\u00004\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\b\u0016\u0018\u00002\u00020\u0001B\u0019\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\n\u0010\u0004\u001a\u0006\u0012\u0002\b\u00030\u0005¢\u0006\u0002\u0010\u0006J(\u0010\u0007\u001a\b\u0012\u0004\u0012\u0002H\t0\b\"\u0004\b\u0000\u0010\t2\u0006\u0010\n\u001a\u00020\u000b2\f\u0010\f\u001a\b\u0012\u0004\u0012\u0002H\t0\rJ*\u0010\u000e\u001a\b\u0012\u0004\u0012\u0002H\t0\b\"\u0004\b\u0000\u0010\t2\u0006\u0010\n\u001a\u00020\u000b2\f\u0010\f\u001a\b\u0012\u0004\u0012\u0002H\t0\rH\u0002J*\u0010\u000f\u001a\b\u0012\u0004\u0012\u0002H\t0\b\"\u0004\b\u0000\u0010\t2\u0006\u0010\n\u001a\u00020\u000b2\f\u0010\f\u001a\b\u0012\u0004\u0012\u0002H\t0\rH\u0002J\b\u0010\u0010\u001a\u00020\u0011H\u0002R\u0012\u0010\u0004\u001a\u0006\u0012\u0002\b\u00030\u0005X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u0012"}, + d2 = {"Lcom/xit/core/support/jpa/QuerydslPageAndSortRepository;", "", "entityManager", "Ljavax/persistence/EntityManager;", "clazz", "Ljava/lang/Class;", "(Ljavax/persistence/EntityManager;Ljava/lang/Class;)V", "getPageImpl", "Lorg/springframework/data/domain/PageImpl;", "T", "pageable", "Lorg/springframework/data/domain/Pageable;", "query", "Lcom/querydsl/jpa/JPQLQuery;", "getPageImplIfGroupBy", "getPageImplIfNotGroupBy", "getQuerydsl", "Lorg/springframework/data/jpa/repository/support/Querydsl;", "xit-opst-bo.main"} +) +public class QuerydslPageAndSortRepository { + private final EntityManager entityManager; + private final Class clazz; + + public QuerydslPageAndSortRepository(@NotNull EntityManager entityManager, @NotNull Class clazz) { + Intrinsics.checkNotNullParameter(entityManager, "entityManager"); + Intrinsics.checkNotNullParameter(clazz, "clazz"); + this.entityManager = entityManager; + this.clazz = clazz; + } + + private final Querydsl getQuerydsl() { + PathBuilder builder = (new PathBuilderFactory()).create(this.clazz); + return new Querydsl(this.entityManager, builder); + } + + @NotNull + public final PageImpl getPageImpl(@NotNull Pageable pageable, @NotNull JPQLQuery query) { + Intrinsics.checkNotNullParameter(pageable, "pageable"); + Intrinsics.checkNotNullParameter(query, "query"); + QueryMetadata var10000 = query.getMetadata(); + Intrinsics.checkNotNullExpressionValue(var10000, "query.metadata"); + return var10000.getGroupBy().size() > 0 ? this.getPageImplIfGroupBy(pageable, query) : this.getPageImplIfNotGroupBy(pageable, query); + } + + private final PageImpl getPageImplIfGroupBy(Pageable pageable, JPQLQuery query) { + List queryResult = query.fetch(); + int totalCount = queryResult.size(); + long offset = pageable.getOffset(); + if (offset > (long)totalCount) { + return new PageImpl(CollectionsKt.emptyList(), pageable, (long)totalCount); + } else { + int limit = pageable.getPageSize() * (pageable.getPageNumber() + 1); + limit = limit > totalCount ? totalCount : limit; + List results = queryResult.subList((int)offset, limit); + return new PageImpl(results, pageable, (long)totalCount); + } + } + + private final PageImpl getPageImplIfNotGroupBy(Pageable pageable, JPQLQuery query) { + long totalCount = query.fetchCount(); + List results = this.getQuerydsl().applyPagination(pageable, query).fetch(); + return new PageImpl(results, pageable, totalCount); + } + + +} diff --git a/src/main/java/com/xit/core/support/jpa/QuerydslPageAndSortRepositoy1.kt b/src/main/java/com/xit/core/support/jpa/QuerydslPageAndSortRepositoy1.kt new file mode 100644 index 0000000..c2c0ab4 --- /dev/null +++ b/src/main/java/com/xit/core/support/jpa/QuerydslPageAndSortRepositoy1.kt @@ -0,0 +1,81 @@ +package com.xit.core.support.jpa; + +import com.querydsl.core.types.dsl.PathBuilderFactory +import com.querydsl.jpa.JPQLQuery +import org.springframework.data.domain.PageImpl +import org.springframework.data.domain.Pageable +import org.springframework.data.jpa.repository.support.Querydsl +import javax.persistence.EntityManager + + open class QuerydslPageAndSortRepository1 ( + private val entityManager: EntityManager, + private val clazz: Class<*> +) { + + private fun getQuerydsl(): Querydsl { + val builder = PathBuilderFactory().create(clazz) + return Querydsl(entityManager, builder) + } + + /** + * Paging 처리 결과값 조회 + * - Query Paging 결과값 + * - Pageable 객체 + * - Query total Count + * @param pageable Pageable + * @param query JPQLQuery + * @return PageImpl + */ + fun getPageImpl(pageable: Pageable, query: JPQLQuery): PageImpl { + return if (query.metadata.groupBy.size > 0) { + getPageImplIfGroupBy(pageable, query) + } else { + getPageImplIfNotGroupBy(pageable, query) + } + } + + /** + * GroupBy절을 사용하는 Query + * @param pageable Pageable + * @param query JPQLQuery + * @return PageImpl + */ + private fun getPageImplIfGroupBy(pageable: Pageable, query: JPQLQuery): PageImpl { + val queryResult = query.fetch() + val totalCount = queryResult.size + + val offset = pageable.offset + + // totalCount 보다 큰 값이 들어온 경우 + if (offset > totalCount) { + return PageImpl(listOf(), pageable, totalCount.toLong()) + } + + // limit 설정 + var limit = pageable.pageSize * (pageable.pageNumber + 1) + limit = if (limit > totalCount) { + totalCount + } else { + limit + } + + val results = queryResult.subList(offset.toInt(), limit) + return PageImpl(results, pageable, totalCount.toLong()) + } + + /** + * GroupBy절을 사용안하는 Query + * @param pageable Pageable + * @param query JPQLQuery + * @return PageImpl + */ + private fun getPageImplIfNotGroupBy(pageable: Pageable, query: JPQLQuery): PageImpl { + val totalCount = query.fetchCount() + + val results = getQuerydsl() + .applyPagination(pageable, query) + .fetch() + + return PageImpl(results, pageable, totalCount) + } +} diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index e1654a9..0c74aac 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -53,7 +53,7 @@ spring: web: pageable: # 1 페이지 부터 시작 : default 0 - one-indexed-parameters: true + one-indexed-parameters: false # 기본 페이지 size default-page-size: 10 # 페이지당 최대 size @@ -256,7 +256,7 @@ server: # Response 에 Exception Message 를 표시할지 : ALWAYS, NEVER, ON_PARAM include-message: ALWAYS # Response 에 Stack Trace 를 표시할지 (never | always | on_param) on_trace_params 은 deprecated - include-stacktrace: ALWAYS + include-stacktrace: on_param # 브라우저 요청에 대해 서버 오류시 기본으로 노출할 페이지를 사용할지 여부 whitelabel: enabled: true diff --git a/src/test/java/com/xit/ApplicationTest.java b/src/test/java/com/xit/ApplicationTest.java deleted file mode 100644 index 29fd818..0000000 --- a/src/test/java/com/xit/ApplicationTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.xit; - -import org.junit.Test; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; - -//@ExtendWith(SpringExtension.class) -@SpringBootTest -//@TestPropertySource({"classpath:application-test.properties","classpath:config.properties"}) -//@ActiveProfiles({"local"}) -public class ApplicationTest extends SpringBootServletInitializer { - - @Test - public void contextLoads() { - } - -} diff --git a/src/test/java/com/xit/biz/cmm/BoardControllerMockMvcTest.java b/src/test/java/com/xit/biz/cmm/BoardControllerMockMvcTest.java deleted file mode 100644 index ee71dd3..0000000 --- a/src/test/java/com/xit/biz/cmm/BoardControllerMockMvcTest.java +++ /dev/null @@ -1,109 +0,0 @@ -//package com.xit.biz.sample.controller; -// -//import com.fasterxml.jackson.databind.ObjectMapper; -//import com.xit.biz.sample.domain.Board; -//import com.xit.biz.sample.dto.BoardDto; -//import com.xit.biz.sample.service.BoardServiceImpl; -//import org.junit.jupiter.api.AfterEach; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.Test; -// -//import org.mockito.Mockito; -//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.http.MediaType; -//import org.springframework.test.context.ActiveProfiles; -//import org.springframework.test.web.servlet.MockMvc; -//import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -// -//import static org.hamcrest.core.Is.is; -//import static org.mockito.ArgumentMatchers.any; -//import static org.mockito.BDDMockito.given; -//import static org.springframework.http.MediaType.APPLICATION_JSON; -//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -// -// -//@WebMvcTest(BoardController.class) -//@ActiveProfiles({"local", "logging"}) -//class BoardControllerMockMvcTest { -// -// @MockBean -// private BoardServiceImpl boardService; -// -// @Autowired -// private MockMvc mockMvc; -// -// ObjectMapper mapper = new ObjectMapper(); -// -// final BoardDto boardDto = BoardDto.builder() -// .boardId(1L) -// .title("제목1") -// .content("내용1") -// .insUserId("작성자1") -// .updUserId(null) -// .insDtTm(null) -// .updDtTm(null) -// .build(); -// -// final Board board = Board.builder() -// .boardId(1L) -// .title("제목1") -// .content("내용1") -// .insUserId("작성자1") -// .updUserId(null) -// .insDtTm(null) -// .updDtTm(null) -// .build(); -// -// @Test -// void findByBoardId() throws Exception { -// Mockito.when(boardService.findByBoardId(boardDto.getBoardId())).thenReturn(boardDto); -// -// mockMvc.perform(MockMvcRequestBuilders -// .get("/sample/board/{boardId}", 1) -// //.param("id", String.valueOf(boardDto.getId())) -// .contentType(MediaType.APPLICATION_JSON)) -// .andExpect(status().isOk()) -// .andExpect(jsonPath("$.boardId", is(boardDto.getBoardId().longValue()))) -// .andExpect(jsonPath("$.title", is(boardDto.getTitle()))) -// .andExpect(jsonPath("$.content", is(boardDto.getContent()))) -// .andExpect(jsonPath("$.insUserId", is(boardDto.getInsUserId()))) -// .andExpect(jsonPath("$.insDtTm", is(boardDto.getInsDtTm()))) -// .andExpect(jsonPath("$.updDtTm", is(boardDto.getUpdDtTm()))); -// //.andExpect(jsonPath("$.updDtTm").value(IsNull.nullValue())); -// } -// -// @Test -// void addBoard() throws Exception { -// given(boardService.add(any(BoardDto.class))).willReturn(boardDto); -// -// mockMvc.perform(MockMvcRequestBuilders -// .post("/sample/board") -// .content(mapper.writeValueAsString(boardDto)) -// .contentType(MediaType.APPLICATION_JSON) -// .accept(APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(jsonPath("$.boardId", is(boardDto.getBoardId().longValue()))) -// .andExpect(jsonPath("$.title", is(boardDto.getTitle()))) -// .andExpect(jsonPath("$.content", is(boardDto.getContent()))) -// .andExpect(jsonPath("$.insUserId", is(boardDto.getInsUserId()))) -// .andExpect(jsonPath("$.insDtTm", is(boardDto.getInsDtTm()))) -// .andExpect(jsonPath("$.updDtTm", is(boardDto.getUpdDtTm()))); -// //.andExpect(jsonPath("$.updDtTm").value(IsNull.nullValue())); -// } -// -// -// @BeforeEach -// void setUp() { -// } -// -// @AfterEach -// void tearDown() { -// } -// -// -//} \ No newline at end of file diff --git a/src/test/java/com/xit/biz/cmm/BoardControllerTest.java b/src/test/java/com/xit/biz/cmm/BoardControllerTest.java deleted file mode 100644 index ae285a5..0000000 --- a/src/test/java/com/xit/biz/cmm/BoardControllerTest.java +++ /dev/null @@ -1,60 +0,0 @@ -//package com.xit.biz.sample.controller; -// -//import com.xit.biz.sample.dto.BoardDto; -//import com.xit.biz.sample.service.BoardServiceImpl; -//import com.xit.core.exception.NotFoundException; -//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.HttpStatus; -//import org.springframework.http.ResponseEntity; -// -//import java.util.Objects; -// -//import static org.junit.jupiter.api.Assertions.*; -//import static org.mockito.ArgumentMatchers.*; -//import static org.mockito.BDDMockito.given; -//import static org.mockito.Mockito.*; -// -//@ExtendWith(MockitoExtension.class) -//class BoardControllerTest { -// -// @Mock -// private BoardServiceImpl boardService; -// -// @InjectMocks -// private BoardController boardController; -// -// @BeforeEach -// void setUp() { -// } -// -// @AfterEach -// void tearDown() { -// } -// -// @Test -// void findByBoardId() { -// final BoardDto boardDto = new BoardDto(1L, "제목1", "내용1", null,"작성자1", null, null, null); -// -// given(boardService.findByBoardId(boardDto.getBoardId())).willReturn(boardDto); -// ResponseEntity re = boardController.findByBoardId(boardDto.getBoardId()); -// assertNotNull(re); -// assertEquals(HttpStatus.OK, re.getStatusCode()); -// assertEquals(boardDto.getBoardId(), Objects.requireNonNull(re.getBody().getBoardId())); -// verify(boardService).findByBoardId(anyLong()); -// -// // 실패 -// given(boardService.findByBoardId(anyLong())).willThrow(NotFoundException.class); -// assertThrows(NotFoundException.class, ()->boardController.findByBoardId(anyLong())); -//// verify(boardService).findByBoardId(anyLong()); -// } -// -// @Test -// void addBoard() { -// } -//} \ No newline at end of file diff --git a/src/test/java/com/xit/biz/cmm/BoardRepositoryTest__.java b/src/test/java/com/xit/biz/cmm/BoardRepositoryTest__.java deleted file mode 100644 index 178eccd..0000000 --- a/src/test/java/com/xit/biz/cmm/BoardRepositoryTest__.java +++ /dev/null @@ -1,159 +0,0 @@ -//package com.xit.biz.sample; -// -//import com.xit.biz.sample.domain.Board; -//import com.xit.biz.sample.domain.BoardRepository; -//import lombok.extern.slf4j.Slf4j; -//import org.aspectj.lang.annotation.After; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.Test; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -//import org.springframework.boot.test.context.SpringBootTest; -//import org.springframework.boot.test.web.client.TestRestTemplate; -//import org.springframework.http.MediaType; -//import org.springframework.http.HttpStatus; -//import org.springframework.http.ResponseEntity; -// -// -//import org.springframework.test.context.ActiveProfiles; -//import org.springframework.test.web.servlet.MockMvc; -//import org.springframework.test.web.servlet.setup.MockMvcBuilders; -//import org.springframework.transaction.annotation.Transactional; -//import org.springframework.web.context.WebApplicationContext; -//import org.springframework.web.filter.CharacterEncodingFilter; -// -//import java.util.List; -// -//import static org.assertj.core.api.Assertions.assertThat; -//import static org.springframework.test.web.client.match.MockRestRequestMatchers.content; -//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -// -//import static org.assertj.core.api.BDDAssertions.then; -//import static org.hamcrest.core.Is.is; -// -// -////Junit5 사용시에는 해당 어노테이션은 명시할 필요없다. -////@RunWith(SpringRunner.class) -// -//@SpringBootTest( -// //properties = { "propertyTest.value=propertyTest", "testValue=test" } -// //properties = {"spring.config.location=classpath:application-test.properties"} -// webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT -//) -//// Mock 테스트시 필요한 의존성을 제공 -//@AutoConfigureMockMvc -//@Transactional -//@ActiveProfiles(value = {"local","logging"}) -//@Slf4j -//public class BoardRepositoryTest { -// -// @Autowired -// BoardRepository boardRepository; -// -// /* -// @MockBean -// BoardRepository boardRepository; -// */ -// -// @Autowired -// MockMvc mvc; -// -// /* -// webEnvironment설정시(NONE을 설정시 사용 불가) 그에 맞춰서 자동으로 설정되어 빈이 생성되며, RestTemplate의 테스트를 처리가 가능 -// */ -// @Autowired private TestRestTemplate restTemplate; -// -// // Service로 등록하는 빈 -// //@Autowired -// //private MemberService memberService; -// -// @Autowired -// private WebApplicationContext ctx; -// -// -// //Junit4의 @Before -// @BeforeEach() -// public void setup() { -// this.mvc = MockMvcBuilders.webAppContextSetup(ctx) -// .addFilters(new CharacterEncodingFilter("UTF-8", true)) // 필터 추가 -// .alwaysDo(print()) -// .build(); -// } -// -// -// -// // @After -// public void cleanup() { -// boardRepository.deleteAll(); -// } -// -// @Test -// public void 게시글저장_블러오기() { -// //given -// String title = "테스트 게시글"; -// String content = "테스트 본문"; -// -// boardRepository.save(Board.builder() -// .title(title) -// .content(content) -// .insUserId("b088081@gmail.com") -// .build()); -// -// //when -// List boardList = boardRepository.findAll(); -// -// //then -// Board board = boardList.get(0); -// assertThat(board.getTitle()).isEqualTo(title); -// assertThat(board.getContent()).isEqualTo(content); -// } -// -// @Test -// void getMember() throws Exception { -// log.info("##### Properties 테스트 #####"); -// -// /******** START : MOC MVC test **********/ -// log.info("******** START : MOC MVC test **********"); -// mvc.perform(get("/memberTest/1")) -// .andExpect(status().isOk()) -// .andExpect(content().contentType(MediaType.APPLICATION_JSON)) -// .andExpect(jsonPath("$.boardId", is("goddaehee"))) -// .andDo(print()); -// log.info("******** END : MOC MVC test **********"); -// /******** END : MOC MVC test **********/ -// -// /******** START : TestRestTemplate test **********/ -// log.info("******** START : TestRestTemplate test **********"); -// ResponseEntity response = restTemplate.getForEntity("/memberTest/1", MemberVo.class); -// then(response.getStatusCode()).isEqualTo(HttpStatus.OK); -// then(response.getBody()).isNotNull(); log.info("******** END : TestRestTemplate test **********"); -// /******** END : TestRestTemplate test **********/ -// -// /******** START : MockBean test **********/ -// log.info("******** START : MockBean test **********"); -// /* -// MemberVo memberVo = MemberVo.builder() -// .id(testId) .name(testName) -// .build(); -// given(memberRepository.findByBoardId(1L)) -// .willReturn(Optional.of(memberVo)); -// */ -// -// Optional member = memberService.findByBoardId(1L); -// if (member.isPresent()) { -// // ※ Junit4 사용시 -// // assertThat(memberVo.getId()).isEqualTo(member.get().getId()); -// // assertThat(memberVo.getName()).isEqualTo(member.get().getName()); -// // Junit5 BDD 사용시 -// then("goddaehee").isEqualTo(member.get().getId()); -// then("갓대희").isEqualTo(member.get().getName()); -// } log.info("******** END : MockBean test **********"); -// /******** END : MockBean test **********/ -// } -// -// -// -//} diff --git a/src/test/java/com/xit/biz/cmm/BoardServiceTest.java b/src/test/java/com/xit/biz/cmm/BoardServiceTest.java deleted file mode 100644 index 6d2cb3d..0000000 --- a/src/test/java/com/xit/biz/cmm/BoardServiceTest.java +++ /dev/null @@ -1,106 +0,0 @@ -//package com.xit.biz.sample.service; -// -//import com.xit.biz.sample.domain.Board; -//import com.xit.biz.sample.domain.BoardRepository; -//import com.xit.biz.sample.dto.BoardDto; -//import com.xit.biz.sample.mapper.BoardMapper; -//import com.xit.core.exception.NotFoundException; -//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.mapstruct.factory.Mappers; -//import org.mockito.InjectMocks; -//import org.mockito.Mock; -//import org.mockito.junit.jupiter.MockitoExtension; -// -//import java.util.Optional; -// -//import static org.junit.jupiter.api.Assertions.*; -//import static org.mockito.ArgumentMatchers.*; -//import static org.mockito.BDDMockito.given; -//import static org.mockito.Mockito.*; -// -//@ExtendWith(MockitoExtension.class) -//class BoardServiceTest { -// -// @Mock -// private BoardRepository boardRepository; -// -// @InjectMocks -// private BoardService boardService = new BoardServiceImpl(this.boardRepository); -// -// private final BoardMapper mapper = Mappers.getMapper(BoardMapper.class); -// -// @BeforeEach -// void setUp() { -// } -// -// @AfterEach -// void tearDown() { -// } -// -// @Test -// void add() { -// final BoardDto boardDto = new BoardDto(1L, "제목1", "내용1", "작성자1", null, null, null); -// -// // 성공 -// // given()이 호출되면 willReturn() 이 반환 -// given(boardRepository.findByBoardId(boardDto.getId())).willReturn(Optional.empty()); -// given(boardRepository.save(mapper.toEntity(boardDto)).willReturn(Board.class); -// -// Board savedBoard = boardService.add(boardDto); -// assertNotNull(savedBoard); -// // verify() 가 findByBoardId를 호출 했는지 검증 -// verify(boardRepository).findByBoardId(anyLong()); -// verify(boardRepository).save(any(Board.class)); -// -// // 실패 -// given(boardRepository.findByBoardId(board.getId())).willReturn(Optional.of(board)); -// assertThrows(NotFoundException.class, ()->boardService.add(board)); -// verify(boardRepository, never()).save(any(Board.class)); -// } -// -// @Test -// void findByBoardId() { -// final BoardDto boardDto = new BoardDto(1L, "제목1", "내용1", "작성자1", null, null, null); -// -// // 성공 -// given(boardRepository.findByBoardId(boardDto.getId())).willReturn(Optional.of(boardDto)); -// BoardDto getBoard = boardService.findByBoardId(boardDto.getId()); -// assertEquals(boardDto, getBoard); -// verify(boardRepository).findByBoardId(anyLong()); -// -// // 실패 -// final Long id = 1L; -// given(boardRepository.findByBoardId(anyLong())).willReturn(Optional.empty()); -// assertThrows(NotFoundException.class, () -> boardService.findByBoardId(id)); -// verify(boardRepository).findByBoardId(any(Long.class)); -// } -// -// @Test -// void update() { -// final BoardDto boardDto = new BoardDto(1L, "제목1-1", "내용1-1", "작성자1", "변경자1", null, null); -// -// // 성공 -// given(boardRepository.findByBoardId(boardDto.getId())).willReturn(Optional.of(boardDto)); -// given(boardRepository.save(boardDto)).willReturn(board); -// -// Board updateBoard = boardService.update(board); -// assertNotNull(updateBoard); -// verify(boardRepository).save(any(Board.class)); -// -// // 실패 -// given(boardRepository.findByBoardId(anyLong())).willReturn(Optional.empty()); -// assertThrows(NotFoundException.class, () -> boardService.update(board)); -// verify(boardRepository).findByBoardId(anyLong()); -// } -// -// @Test -// void delete() { -// final Long id = 1L; -// boardService.delete(id); -// verify(boardRepository, times(1)).deleteById(anyLong()); -// verify(boardRepository, times(1)).findByBoardId(anyLong()); -// } -//} \ No newline at end of file diff --git a/src/test/java/com/xit/biz/cmm/controller/CmmUserControllerMockMvcTest.java b/src/test/java/com/xit/biz/cmm/controller/CmmUserControllerMockMvcTest.java deleted file mode 100644 index 0ac64d1..0000000 --- a/src/test/java/com/xit/biz/cmm/controller/CmmUserControllerMockMvcTest.java +++ /dev/null @@ -1,122 +0,0 @@ -//package com.xit.biz.cmm.controller; -// -//import com.xit.biz.cmm.domain.CmmUser; -//import com.xit.biz.cmm.domain.CmmUserRepository; -//import org.junit.jupiter.api.*; -//import org.mockito.Mockito; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -//import org.springframework.boot.test.context.SpringBootTest; -//import org.springframework.test.web.servlet.MockMvc; -//import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -// -//import static org.assertj.core.api.Assertions.assertThat; -//import static org.codehaus.groovy.runtime.DefaultGroovyMethods.any; -//import static org.mockito.BDDMockito.given; -//import static org.springframework.http.MediaType.APPLICATION_JSON; -//import static org.springframework.test.web.client.match.MockRestRequestMatchers.jsonPath; -//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -// -//@SpringBootTest -//@AutoConfigureMockMvc -////@TestMethodOrder(value = MethodOrderer.OrderAnnotation.class) // @Order에 의한 순서 -//@TestMethodOrder(MethodOrderer.MethodName.class) -////@TestMethodOrder(value = MethodOrderer.DisplayName.class) -//class CmmUserControllerMockMvcTest { -// -//// @LocalServerPort -//// private int port; -// -// @Autowired -// private MockMvc mockMvc; -// -//// @Autowired -//// private TestRestTemplate restTemplate; -// -// @Autowired(required=true) -// private CmmUserRepository cmmUserRepository; -// -// final CmmUser cmmUser = CmmUser.builder() -// .cmmUserId(1L) -// .userId("minuk926") -// .userName("임종욱") -// .passWord("password") -// .insUserId("minuk926") -// .build(); -// -// @BeforeEach -// void setUp() { -// } -// -// @AfterEach -// void tearDown() { -// cmmUserRepository.deleteAll(); -// } -// -// @Test -// void T01_사용자_생성() throws Exception { -// given(cmmUserRepository.save(cmmUser)).willReturn(cmmUser); -// -// mockMvc.perform(MockMvcRequestBuilders -// .post("/web/cmm/user/save") -// //.content(mapper.writeValueAsString(boardDto)) -// .contentType(APPLICATION_JSON) -// .accept(APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isOk()); -//// .andExpect(jsonPath("$.boardId", is(boardDto.getBoardId().longValue()))) -//// .andExpect(jsonPath("$.title", is(boardDto.getTitle()))) -//// .andExpect(jsonPath("$.content", is(boardDto.getContent()))) -//// .andExpect(jsonPath("$.insUserId", is(boardDto.getInsUserId()))) -//// .andExpect(jsonPath("$.insDtTm", is(boardDto.getInsDtTm()))) -//// .andExpect(jsonPath("$.updDtTm", is(boardDto.getUpdDtTm()))); -// //.andExpect(jsonPath("$.updDtTm").value(IsNull.nullValue())); -// } -// -// @Test -// void T02_사용자_조회() throws Exception { -// Mockito.when(cmmUserRepository.findByCmmUserId(cmmUser.getCmmUserId())).thenReturn(cmmUser); -// -// this.mockMvc.perform(MockMvcRequestBuilders -// .get("/web/cmm/user/{cmmUserId}", 1) -// //.param("id", String.valueOf(boardDto.getId())) -// .contentType(APPLICATION_JSON)) -// .andExpect(status().isOk()); -//// .andExpect(content().json()) -//// .andExpect(jsonPath("$.title", is(boardDto.getTitle()))) -//// .andExpect(jsonPath("$.content", is(boardDto.getContent()))) -//// .andExpect(jsonPath("$.insUserId", is(boardDto.getInsUserId()))) -//// .andExpect(jsonPath("$.insDtTm", is(boardDto.getInsDtTm()))) -//// .andExpect(jsonPath("$.updDtTm", is(boardDto.getUpdDtTm()))); -// //.andExpect(jsonPath("$.updDtTm").value(IsNull.nullValue())); -// } -// -// -// -// -// @Test -// void userAll() { -// } -// -// @Test -// void userAllPage() { -// } -// -// @Test -// void findByCmmUserId() { -// } -// -// @Test -// void findByUserId() { -// } -// -// -// @Test -// void modifyUser() { -// } -// -// @Test -// void removeUserById() { -// } -//} \ No newline at end of file diff --git a/src/test/java/com/xit/biz/cmm/controller/CmmUserControllerMockitoTest.java b/src/test/java/com/xit/biz/cmm/controller/CmmUserControllerMockitoTest.java deleted file mode 100644 index e41cb08..0000000 --- a/src/test/java/com/xit/biz/cmm/controller/CmmUserControllerMockitoTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.xit.biz.cmm.controller; - -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 static org.assertj.core.api.Assertions.assertThat; - -@ExtendWith(MockitoExtension.class) -class CmmUserControllerMockitoTest { - - @Mock - //private Service service; - - @InjectMocks - private CmmUserMgtController cmmUserMgtController; - - @InjectMocks - private CmmUserWebController cmmUserWebController; - - //@InjectMocks - //private CmmUserRepository cmmUserRepository; - - @BeforeEach - void setMockOutput() { - //when(helloService.getWelcomeMessage()).thenReturn("Hello Mockito Test"); - } - - @AfterEach - void tearDown() { - - } - - @Test - void T01_API_사용자등록() { - //CmmUser cmmUser = cmmUserController.findByCmmUserId(1L); - } - - @Test - void userAll() { - } - - @Test - void userAllPage() { - } - - @Test - void findByCmmUserId() { - } - - @Test - void findByUserId() { - } - - - @Test - void modifyUser() { - } - - @Test - void removeUserById() { - } -} \ No newline at end of file diff --git a/src/test/java/com/xit/biz/cmm/controller/CmmUserControllerRestTest.java b/src/test/java/com/xit/biz/cmm/controller/CmmUserControllerRestTest.java deleted file mode 100644 index 82fca1e..0000000 --- a/src/test/java/com/xit/biz/cmm/controller/CmmUserControllerRestTest.java +++ /dev/null @@ -1,89 +0,0 @@ -//package com.xit.biz.cmm.controller; -// -//import com.xit.biz.cmm.domain.CmmUser; -//import com.xit.biz.cmm.domain.CmmUserRepository; -//import org.junit.jupiter.api.AfterEach; -//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.boot.test.web.client.TestRestTemplate; -//import org.springframework.boot.web.server.LocalServerPort; -//import org.springframework.http.HttpStatus; -//import org.springframework.http.ResponseEntity; -// -//import java.util.List; -// -//import static org.assertj.core.api.Assertions.assertThat; -//import static org.junit.jupiter.api.Assertions.*; -// -//@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -//class CmmUserControllerRestTest { -// -// @LocalServerPort -// private int port; -// -// private String url; -// -// @Autowired -// private TestRestTemplate restTemplate; -// -// @BeforeEach -// void setUp() { -// url = String.format("http://localhost:%d", port); -// } -// -// @AfterEach -// void tearDown() { -// -// } -// -// @Test -// void T01_API_사용자등록() { -// String url = "http://localhost:" + port +"/api/cmm/user"; -// -// //given -// //CmmUser cmmUser = CmmUser.builder().cmmUserId().userId() -// CmmUser cmmUser = new CmmUser(null, "minuk926", "임종욱", "password", "minuk926", null, null, null); -// -// //when -// ResponseEntity responseEntity = this.restTemplate.postForEntity(url+"/api/cmm/user", cmmUser, CmmUser.class); -// -// //then -// assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK); -// -//// List list = cmmUserRepository.findAll(); -//// assertThat(list.get(0).getUserId()).isEqualTo("minuk926"); -//// assertThat(list.get(0).getUserName()).isEqualTo("임종욱"); -// } -// -// @Test -// void T01_WEB_사용자_조회() { -// CmmUser cmmUser = this.restTemplate.getForObject(url+"/api/cmm/user/{cmmUserId}", CmmUser.class, 1); -// } -// -// @Test -// void userAll() { -// } -// -// @Test -// void userAllPage() { -// } -// -// @Test -// void findByCmmUserId() { -// } -// -// @Test -// void findByUserId() { -// } -// -// -// @Test -// void modifyUser() { -// } -// -// @Test -// void removeUserById() { -// } -//} \ No newline at end of file diff --git a/src/test/java/com/xit/biz/cmm/controller/CmmUserControllerTest.java b/src/test/java/com/xit/biz/cmm/controller/CmmUserControllerTest.java deleted file mode 100644 index df7dee0..0000000 --- a/src/test/java/com/xit/biz/cmm/controller/CmmUserControllerTest.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.xit.biz.cmm.controller; - -import com.xit.biz.cmm.entity.CmmRole; -import com.xit.biz.cmm.entity.CmmUser; -import com.xit.biz.cmm.service.ICmmUserService; -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.web.servlet.MockMvc; - -import java.util.Arrays; -import java.util.List; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; - -@SpringBootTest -@AutoConfigureMockMvc -@Slf4j -@ActiveProfiles("test") -public class CmmUserControllerTest { - - @Autowired - MockMvc mockMvc; - - @MockBean - private ICmmUserService ICmmUserService; - - private CmmUser user; - private List roles; - - @BeforeEach - void setUp() { - // given - this.user = CmmUser.builder() - .userId("minuk926") - .userName("임종욱") - .password("minuk926") - //.insUserId("minuk926") - .build(); - this.roles = Arrays.asList( - CmmRole.builder() - .roleName("ROLE_1") - .roleRemark("ROLE_1_REMARK") - .build(), - CmmRole.builder() - .roleName("ROLE_2") - .roleRemark("ROLE_2_REMARK") - .build() - - ); - } - - @AfterEach - void tearDown() { - } - - @Test - public void test(){ - log.info("---------"); - } - - @Test - void findAll() { - } - - @Test - void findAllPage() { - } - - @Test - void findByCmmUserId() { - } - - @Test - void save() { -// mockMvc.perform(post("/api/cmm/user")) - - } - - @Test - void modify() { - } - - @Test - void deleteById() { - } -} diff --git a/src/test/java/com/xit/biz/cmm/repository/ICmmBoardRepositoryTest.java b/src/test/java/com/xit/biz/cmm/repository/ICmmBoardRepositoryTest.java deleted file mode 100644 index 4e58c61..0000000 --- a/src/test/java/com/xit/biz/cmm/repository/ICmmBoardRepositoryTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.xit.biz.cmm.repository; - -import com.xit.biz.cmm.entity.CmmBoard; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; - -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -//@ExtendWith(SpringExtension.class) -@DataJpaTest -class ICmmBoardRepositoryTest { - - @Autowired - private ICmmBoardRepository boardRepository; - - private CmmBoard board; - - @BeforeEach - void setUp() { - board = board.builder() - .title("board title") - .content("board content") - .ctgCd("ctg1") - .build(); - - boardRepository.save(board); - } - - @AfterEach - void tearDown() { - } - - @Test - void idStrategyTest() { - CmmBoard board1 = new CmmBoard(null, "ctg_1", "제목1", "내용1"); - CmmBoard board2 = new CmmBoard(null, "ctg_2", "제목2", "내용2"); - CmmBoard savedBoard1 = boardRepository.save(board1); - CmmBoard savedBoard2 = boardRepository.save(board2); - - assertEquals(1, Math.abs(savedBoard2.getBoardId() - savedBoard1.getBoardId())); - - } - - @Test - void 게시글_작성(){ - CmmBoard board = new CmmBoard(null, "ctg_1", "제목1", "내용1"); - CmmBoard saveBoard = boardRepository.save(board); - assertEquals(board.getTitle(), saveBoard.getTitle(), "savedUserTest"); - assertEquals(board.getContent(), saveBoard.getContent()); - } - - @Test - void 게시글_조회(){ - Optional boardInfo = boardRepository.findById(1l); - boardInfo.ifPresent(v -> assertEquals(v.getTitle(), "제목1")); - - //Optional byId = boardRepository.findByBoardId(1l); - } -} \ No newline at end of file diff --git a/src/test/java/com/xit/biz/cmm/repository/ICmmCodeRepositoryTest.java b/src/test/java/com/xit/biz/cmm/repository/ICmmCodeRepositoryTest.java deleted file mode 100644 index d03ccf6..0000000 --- a/src/test/java/com/xit/biz/cmm/repository/ICmmCodeRepositoryTest.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.xit.biz.cmm.repository; - -import com.xit.biz.cmm.dto.ComboCodeDto; -import com.xit.biz.cmm.entity.*; -import com.xit.biz.cmm.entity.spec.CmmCodeSpecification; -import com.xit.biz.cmm.dto.CmmCodeDto; -import com.xit.biz.cmm.dto.IComboCodeDto; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.data.domain.Example; -import org.springframework.data.domain.ExampleMatcher; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; - -import java.util.List; - -@DataJpaTest -class ICmmCodeRepositoryTest { - - @Autowired - private ICmmCodeGrpRepository cmmCodeGrpRepository; - - @Autowired - private ICmmCodeLRepostory cmmCodeLRepository; - - @Autowired - private ICmmCodeMRepository cmmCodeMRepository; - - @Autowired - private ICmmCodeSRepository cmmCodeSRepository; - - @BeforeEach - void setUp() { - } - - @AfterEach - void tearDown() { - } - - @Test - void load(){ - } - - @Test - void crud(){ - CmmCodeGrp cmmCodeGrp = CmmCodeGrp.builder() - .codeGrpId("G_CODE_SAM") - .codeNm("공통코드그룹예제") - .codeRemark("공통코드그룹설명") - .codeOrdr(99) - .build() - ; - CmmCodeGrp savedCmmCodeGrp = cmmCodeGrpRepository.save(cmmCodeGrp); - CmmCodeGrp qCmmCodeGrp = cmmCodeGrpRepository.findByCodeGrpId(savedCmmCodeGrp.getCodeGrpId()); - System.out.println(qCmmCodeGrp); - - - - CmmCodeL cmmCodeL = CmmCodeL.builder() - .codeGrpId("G_CODE_SAM") - .codeCd("L0001") - .codeNm("대분류코드예제") - .codeRemark("대분류코드설명") - .codeOrdr(99) - .build(); - CmmCodeL savedCmmCodeL = cmmCodeLRepository.save(cmmCodeL); - //List cmmCodeLList = cmmCodeLRepository.findByCodeGrpIdAndUseYnOrderByCodeOrdr(savedCmmCodeL.getCodeGrpId(), savedCmmCodeL.getUseYn()); - //System.out.println(cmmCodeLList); - - List comboCodeDtoList = cmmCodeLRepository.queryComboCode(savedCmmCodeL.getCodeGrpId()); - System.out.println(comboCodeDtoList); - - CmmCodeM cmmCodeM = CmmCodeM.builder() - .codeGrpId("G_CODE_SAM") - .codeLcd("L0001") - .codeCd("M001") - .codeNm("중분류코드예제") - .codeRemark("중분류코드설명") - .codeOrdr(1) - .build(); - CmmCodeM savedCmmCodeM = cmmCodeMRepository.save(cmmCodeM); - - CmmCodeS cmmCodeS = CmmCodeS.builder() - .codeGrpId("G_CODE_SAM") - .codeLcd("L0001") - .codeMcd("M001") - .codeCd("01") - .codeNm("소분류코드예제") - .codeRemark("소분류코드설명") - .codeOrdr(11) - .build(); - CmmCodeS savedCmmCodeS = cmmCodeSRepository.save(cmmCodeS); - - //List list = cmmCodeSRepository.findByCodeGrpIdAndCodeLcdAndCodeMcdAndUseYnOrderByCodeOrdr(savedCmmCodeS.getCodeGrpId(), savedCmmCodeS.getCodeLcd(), savedCmmCodeS.getCodeMcd(), savedCmmCodeS.getUseYn()); - //System.out.println(list); - - List comboCodeDtos = cmmCodeSRepository.queryComboCodeClass(savedCmmCodeS.getCodeGrpId(), savedCmmCodeS.getCodeLcd(), savedCmmCodeS.getCodeMcd()); - System.out.println(comboCodeDtos); - -// cmmFileDtlIds.setFileMstId(savedCmmFileMst.getFileMstId()); -// //cmmFileDtlIds.setFileId(CommUtil.getStringFromUUID()); -// CmmFileDtl cmmFileDtl = CmmFileDtl.builder() -// .fileMstId(cmmFileDtlIds.getFileMstId()) -// .fileId(cmmFileDtlIds.getFileId()) -// .orgFileNm("aaa.jpg") -// .contentType("imeg/jpeg") -// .fileSize(200000l) -// .fileExt("jpg") -// .build(); -// -// CmmFileDtl savedCmmFileDtl = cmmFileDtlRepository.save(cmmFileDtl); -// -// cmmFileDtlRepository.findById(cmmFileDtlIds); - } - - @Test - void specs(){ - - Specification spec = Specification.where(CmmCodeSpecification.eqCodeGrpId("G_CODE_GRP")); - spec.and(CmmCodeSpecification.eqCodeLcd("00001")); -// -// if(CmmCodeDto) -// Specification.where(TodoSpecification.equalTodoId(todoId)); - cmmCodeSRepository.findAll(spec, PageRequest.of(0, 10)); - } - - @Test - void exam(){ - - CmmCodeS codeS = CmmCodeS.builder() - .codeGrpId("C_CODE") - .codeLcd("00001") - .build(); - - ExampleMatcher exampleMatcher = ExampleMatcher.matchingAny(); - //.withIgnorePaths("up", "down"); - - Example example = Example.of(codeS, exampleMatcher); - cmmCodeSRepository.findAll(example); - } -} \ No newline at end of file diff --git a/src/test/java/com/xit/biz/cmm/repository/ICmmFileRepositoryTest.java b/src/test/java/com/xit/biz/cmm/repository/ICmmFileRepositoryTest.java deleted file mode 100644 index b02b480..0000000 --- a/src/test/java/com/xit/biz/cmm/repository/ICmmFileRepositoryTest.java +++ /dev/null @@ -1,61 +0,0 @@ -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; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; - -import java.util.UUID; - -@DataJpaTest -class ICmmFileRepositoryTest { - - @Autowired - private ICmmFileMstRepository cmmFileMstRepository; - - @Autowired - private ICmmFileDtlRepository cmmFileDtlRepository; - - @BeforeEach - void setUp() { - } - - @AfterEach - void tearDown() { - } - - @Test - void crud(){ - CmmFileMst cmmFileMst = CmmFileMst.builder() - .fileMstId(CommUtil.getStringFromUUID()) - .fileCtgCd("BOARD") - .fileBizId("BOARD1") - .build() - ; - - - - - CmmFileMst savedCmmFileMst = cmmFileMstRepository.save(cmmFileMst); - CmmFileDtlIds cmmFileDtlIds = new CmmFileDtlIds(); - cmmFileDtlIds.setFileMstId(savedCmmFileMst.getFileMstId()); - //cmmFileDtlIds.setFileId(CommUtil.getStringFromUUID()); - CmmFileDtl cmmFileDtl = CmmFileDtl.builder() - .fileMstId(cmmFileDtlIds.getFileMstId()) - .fileId(cmmFileDtlIds.getFileId()) - .orgFileNm("aaa.jpg") - .contentType("imeg/jpeg") - .fileSize(200000l) - .fileExt("jpg") - .build(); - - CmmFileDtl savedCmmFileDtl = cmmFileDtlRepository.save(cmmFileDtl); - - cmmFileDtlRepository.findById(cmmFileDtlIds); - } -} \ No newline at end of file diff --git a/src/test/java/com/xit/biz/cmm/repository/ICmmUserRepositoryTest.java b/src/test/java/com/xit/biz/cmm/repository/ICmmUserRepositoryTest.java deleted file mode 100644 index b766437..0000000 --- a/src/test/java/com/xit/biz/cmm/repository/ICmmUserRepositoryTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.xit.biz.cmm.repository; - -import com.xit.biz.cmm.entity.CmmRole; -import com.xit.biz.cmm.entity.CmmUser; -import com.xit.core.oauth2.oauth.entity.ProviderType; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; - -import java.util.Arrays; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -//@ExtendWith(SpringExtension.class) -@DataJpaTest -class ICmmUserRepositoryTest { - - @Autowired - ICmmUserRepository userRepository; - @Autowired - ICmmRoleRepository roleRepository; - - private CmmUser user; - private List roles; - - @BeforeEach - void setUp() { - // given - this.user = CmmUser.builder() - .providerType(ProviderType.LOCAL) - .userId("minuk926") - .userName("임종욱") - .password("minuk926") - .build(); - this.roles = Arrays.asList( - CmmRole.builder() - .roleName("ROLE_1") - .roleRemark("ROLE_1_REMARK") - .build(), - CmmRole.builder() - .roleName("ROLE_2") - .roleRemark("ROLE_2_REMARK") - .build() - - ); - - } - - @AfterEach - void tearDown() { - } - - @Test - void createTest(){ - // when - userRepository.save(user); - //List savedRols = roleRepository.saveAll(roles); - - // then - //assertEquals(user.getUserId(), savedRols.get(0).getRoleId()); - - } - - @Test - void findByCmmUserId() { - } - - @Test - void findByUserId() { - } -} \ No newline at end of file diff --git a/src/test/java/com/xit/biz/cmm/user/ApiTests.java b/src/test/java/com/xit/biz/cmm/user/ApiTests.java deleted file mode 100644 index 97bca8e..0000000 --- a/src/test/java/com/xit/biz/cmm/user/ApiTests.java +++ /dev/null @@ -1,42 +0,0 @@ -//package com.xit.biz.cmm.user; -// -//import com.xit.biz.cmm.domain.CmmUser; -//import org.assertj.core.api.Assertions; -//import org.junit.jupiter.api.Test; -//import org.springframework.http.HttpStatus; -//import org.springframework.http.ResponseEntity; -//import org.springframework.web.client.HttpClientErrorException; -//import org.springframework.web.client.RestTemplate; -// -//public class ApiTests { -// -// @Test -// public void testCreateReadDelete() { -// RestTemplate restTemplate = new RestTemplate(); -// -// String url = "http://localhost:8080/api/cmm/user"; -// -// CmmUser cmmUser = new CmmUser(null, "minuk926", "임종욱", "password", "minuk926", null, null, null); -// ResponseEntity entity = restTemplate.postForEntity(url, cmmUser, CmmUser.class); -// -// CmmUser[] employees = restTemplate.getForObject(url, CmmUser[].class); -// Assertions.assertThat(employees).extracting(CmmUser::getUserName).containsOnly("임종욱"); -// -// restTemplate.delete(url + "/" + entity.getBody().getCmmUserId()); -// Assertions.assertThat(restTemplate.getForObject(url, CmmUser[].class)).isEmpty(); -// } -// -// @Test -// public void testErrorHandlingReturnsBadRequest() { -// -// RestTemplate restTemplate = new RestTemplate(); -// -// String url = "http://localhost:8080/wrong"; -// -// try { -// restTemplate.getForEntity(url, String.class); -// } catch (HttpClientErrorException e) { -// Assertions.assertThat(e.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); -// } -// } -//} diff --git a/src/test/java/com/xit/biz/cmm/user/IntegrationTests.java b/src/test/java/com/xit/biz/cmm/user/IntegrationTests.java deleted file mode 100644 index 0f91541..0000000 --- a/src/test/java/com/xit/biz/cmm/user/IntegrationTests.java +++ /dev/null @@ -1,46 +0,0 @@ -//package com.xit.biz.cmm.user; -// -//import com.xit.biz.cmm.controller.CmmUserController; -//import com.xit.biz.cmm.domain.CmmUser; -//import org.assertj.core.api.Assertions; -//import org.junit.jupiter.api.Test; -//import org.junit.jupiter.api.extension.ExtendWith; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.boot.test.context.SpringBootTest; -//import org.springframework.test.context.junit.jupiter.SpringExtension; -// -//import javax.xml.bind.ValidationException; -// -//@ExtendWith(SpringExtension.class) -//@SpringBootTest -//public class IntegrationTests { -// -// @Autowired -// CmmUserController cmmUserController; -// -// final CmmUser cmmUser = CmmUser.builder() -// .cmmUserId(1L) -// .userId("minuk926") -// .userName("임종욱") -// .passWord("password") -// .insUserId("minuk926") -// .build(); -// -// @Test -// public void testCreateReadDelete() { -// CmmUser rsltUser = cmmUserController.save(cmmUser); -// -// Iterable cmmUsers = cmmUserController.findAll(); -// Assertions.assertThat(cmmUsers).first().hasFieldOrPropertyWithValue("userId", "minuk926"); -// -// cmmUserController.deleteById(rsltUser.getCmmUserId()); -// Assertions.assertThat(cmmUserController.findAll()).is.isEmpty(); -// } -// -// @Test -// public void errorHandlingValidationExceptionThrown() { -// -// Assertions.assertThatExceptionOfType(ValidationException.class) -// .isThrownBy(() -> cmmUserController.somethingIsWrong()); -// } -//} \ No newline at end of file diff --git a/src/test/java/com/xit/biz/cmm/user/RepositoryTests.java b/src/test/java/com/xit/biz/cmm/user/RepositoryTests.java deleted file mode 100644 index f82aec0..0000000 --- a/src/test/java/com/xit/biz/cmm/user/RepositoryTests.java +++ /dev/null @@ -1,35 +0,0 @@ -//package com.xit.biz.cmm.user; -// -//import com.xit.biz.cmm.domain.CmmUser; -//import com.xit.biz.cmm.domain.CmmUserRepository; -//import org.assertj.core.api.Assertions; -//import org.junit.jupiter.api.Test; -//import org.junit.jupiter.api.extension.ExtendWith; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; -//import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -//import org.springframework.test.context.junit.jupiter.SpringExtension; -// -//@ExtendWith(SpringExtension.class) -//@DataJpaTest -//@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) -//public class RepositoryTests { -// -// @Autowired -// CmmUserRepository cmmUserRepository; -// -// @Test -// public void testCreateReadDelete() { -// CmmUser cmmUser = new CmmUser(null, "minuk926", "임종욱", "password", "minuk926", null, null, null); -// -// -// cmmUserRepository.save(cmmUser); -// -// Iterable employees = cmmUserRepository.findAll(); -// Assertions.assertThat(employees).extracting(CmmUser::getUserName).containsOnly("임종욱"); -// -// cmmUserRepository.deleteAll(); -// Assertions.assertThat(cmmUserRepository.findAll()).isEmpty(); -// } -//} -// diff --git a/src/test/java/com/xit/biz/cmm/user/ServiceTests.java b/src/test/java/com/xit/biz/cmm/user/ServiceTests.java deleted file mode 100644 index a59ff50..0000000 --- a/src/test/java/com/xit/biz/cmm/user/ServiceTests.java +++ /dev/null @@ -1,58 +0,0 @@ -//package com.xit.biz.cmm.user; -// -//import static org.junit.jupiter.api.Assertions.assertEquals; -//import static org.mockito.Mockito.times; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -//import java.util.ArrayList; -//import java.util.List; -// -//import com.xit.biz.cmm.domain.CmmUser; -//import com.xit.biz.cmm.domain.CmmUserRepository; -//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; -// -//@ExtendWith(MockitoExtension.class) -//public class ServiceTests { -// -// @InjectMocks -// CmmUserService service; -// -// @Mock -// CmmUserRepository dao; -// -// @Test -// public void testFindAllEmployees() -// { -// List list = new ArrayList(); -// CmmUser empOne = new CmmUser(null, "minuk9261", "임종욱1", "password1", "minuk9261", null, null, null); -// CmmUser empTwo = new CmmUser(null, "minuk9262", "임종욱2", "password2", "minuk9262", null, null, null); -// CmmUser empThree = new CmmUser(null, "minuk9263", "임종욱3", "password3", "minuk9263", null, null, null); -// -// list.add(empOne); -// list.add(empTwo); -// list.add(empThree); -// -// when(dao.findAll()).thenReturn(list); -// -// //test -// List empList = service.findAll(); -// -// assertEquals(3, empList.size()); -// verify(dao, times(1)).findAll(); -// } -// -// @Test -// public void testCreateOrSaveEmployee() -// { -// CmmUser cmmUser = new CmmUser(null, "minuk9261", "임종욱1", "password1", "minuk9261", null, null, null); -// -// service.save(cmmUser); -// -// verify(dao, times(1)).save(employee); -// } -//} diff --git a/src/test/java/com/xit/biz/cmm/user/StandaloneControllerTests.java b/src/test/java/com/xit/biz/cmm/user/StandaloneControllerTests.java deleted file mode 100644 index 053b1e7..0000000 --- a/src/test/java/com/xit/biz/cmm/user/StandaloneControllerTests.java +++ /dev/null @@ -1,44 +0,0 @@ -//package com.xit.biz.cmm.user; -// -//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -// -//import java.util.Arrays; -//import java.util.List; -// -//import com.xit.biz.cmm.controller.CmmUserController; -//import com.xit.biz.cmm.domain.CmmUser; -//import org.hamcrest.Matchers; -//import org.junit.jupiter.api.Test; -//import org.junit.jupiter.api.extension.ExtendWith; -//import org.mockito.Mockito; -//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.test.context.junit.jupiter.SpringExtension; -//import org.springframework.test.web.servlet.MockMvc; -// -//@ExtendWith(SpringExtension.class) -//@WebMvcTest(CmmUserController.class) -//public class StandaloneControllerTests { -// -// @MockBean -// CmmUserService cmmUserService; -// -// @Autowired -// MockMvc mockMvc; -// -// @Test -// public void testfindAll() throws Exception { -// CmmUser cmmUser = new CmmUser(null, "minuk9261", "임종욱1", "password1", "minuk9261", null, null, null); -// List cmmUsers = Arrays.asList(cmmUser); -// -// Mockito.when(cmmUserService.findAll()).thenReturn(cmmUsers); -// -// mockMvc.perform(get("/api/cmm/user")) -// .andExpect(status().isOk()) -// .andExpect(jsonPath("$", Matchers.hasSize(1))) -// .andExpect(jsonPath("$[0].userName", Matchers.is("임종욱1"))); -// } -//} diff --git a/src/test/java/com/xit/biz/ctgy/repository/IMinSimsa680RepositoryTest.java b/src/test/java/com/xit/biz/ctgy/repository/IMinSimsa680RepositoryTest.java new file mode 100644 index 0000000..ea2feba --- /dev/null +++ b/src/test/java/com/xit/biz/ctgy/repository/IMinSimsa680RepositoryTest.java @@ -0,0 +1,39 @@ +package com.xit.biz.ctgy.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +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 javax.persistence.EntityManager; +import javax.transaction.Transactional; + +import static com.xit.biz.ctgy.entity.QMinSimsa680.minSimsa680; +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest +@Transactional +class IMinSimsa680RepositoryTest { + + @Autowired + private IMinSimsa680Repository iMinSimsa680Repository; + + @Autowired + private JPAQueryFactory jpaQueryFactory; + + @Test + @DisplayName("wwwww") + void findMinSimsa680s2() { + + +// jpaQueryFactory.selectFrom(minSimsa680) +// .leftJoin(minSimsa680.msMaincode, minSimsaUser680).fetchJoin() +// .groupBy(minSimsa680.msEdate, minSimsaUser680.msuTeam, qMinUserinfo.name) +// .orderBy(minSimsa680.msChasu.desc()) +// //.where(minSimsa680.name.eq(name)) + // .fetch(); + + } + +} \ No newline at end of file diff --git a/src/test/java/com/xit/core/controller/core/OAuth2LocalControllerTest.java b/src/test/java/com/xit/core/controller/core/OAuth2LocalControllerTest.java deleted file mode 100644 index ebe4142..0000000 --- a/src/test/java/com/xit/core/controller/core/OAuth2LocalControllerTest.java +++ /dev/null @@ -1,268 +0,0 @@ -package com.xit.core.controller.core; - -import com.xit.biz.cmm.dto.CmmUserDto; -import com.xit.biz.cmm.dto.struct.CmmUserMapstruct; -import com.xit.biz.cmm.entity.CmmRole; -import com.xit.biz.cmm.entity.CmmUser; -import com.xit.biz.cmm.repository.ICmmRoleRepository; -import com.xit.biz.cmm.repository.ICmmUserRepository; -import com.xit.core.api.IRestResponse; -import com.xit.core.oauth2.api.controller.OAuth2LocalController; -import com.xit.core.oauth2.api.dto.LoginRequestDto; -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; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.runner.RunWith; -import org.mapstruct.factory.Mappers; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -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.access.prepost.PreAuthorize; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.core.userdetails.User; -import org.springframework.security.test.context.support.WithMockUser; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; -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; -import org.springframework.util.MultiValueMap; -import org.springframework.web.context.WebApplicationContext; -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; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -//@RunWith(SpringRunner.class) -//@RunWith(MockitoJUnitRunner.class) -//@ExtendWith(SpringExtension.class) - - -//@ContextConfiguration(classes = { ApplicationConfig.class }) -//@WebAppConfiguration - -// @Controller, @ControllerAdvice 사용 가능 - @Service, @Component, @Repository 사용 불가 -//@WebMvcTest(controllers = OAuth2LocalController.class) - -//@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) -//@AutoConfigureMockMvc - -//@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -//@ActiveProfiles(value = {"test"}) - - -@RunWith( SpringRunner.class ) -@AutoConfigureMockMvc -@ActiveProfiles( "local" ) -@SpringBootTest -@WithMockUser -class OAuth2LocalControllerTest { - - @Autowired - MockMvc mockMvc; - - //@Autowired - //TestRestTemplate testRestTemplate; - - @Autowired - private WebApplicationContext ctx; - - - 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 - //private CmmUserMapstruct mapstruct = CmmUserMapstructImpl.INSTANCE; - @Autowired - ICmmUserRepository userRepository; - //@Autowired - //ICmmRoleRepository roleRepository; - - //private CmmUserMapstruct cmmUserMapstruct = Mappers.getMapper(CmmUserMapstruct.class); - - @BeforeEach - void setUp() { - //this.mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext).build(); - this.mockMvc = MockMvcBuilders.webAppContextSetup( this.ctx ) - .addFilter( new CharacterEncodingFilter( "UTF-8", true ) ) - .build(); - - this.user = CmmUser.builder() - .cmmUserId(CommUtil.getStringFromUUID()) - .providerType(ProviderType.LOCAL) - .userId("minuk926") - .userName("임종욱") - .password("Minuk926!@") - .email("minuk926@gmail.com") - .roleType(RoleType.USER) - .build(); -// user.setCmmUserId(CommUtil.getStringFromUUID()); -// CmmUser cmmUser = userRepository.save(user); - - // userRepository.save(user); - } - - @AfterEach - void tearDown() { - } - - - @Test - @PreAuthorize("isAuthenticated()") - public void print() { - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - User principal = (User)authentication.getPrincipal(); - System.out.println(principal); - } - - @Test - @PreAuthorize("isAuthenticated()") - void login() throws Exception { - -// ServletContext servletContext = webApplicationContext.getServletContext(); -// -// assertNotNull(servletContext); -// assertTrue(servletContext instanceof MockServletContext); -// 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()) -// .andExpect(status().isOk()) -// .andExpect(jsonPath("$.success").value(true)) -// .andExpect(jsonPath("$.data").exists()) -// //.andExpect(jsonPath("$.success").value(true)) -// //.andExpect(jsonPath("$.success").value(true)) -// ; - - - // given - userRepository.saveAndFlush(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()) -// .andReturn(); - //.andExpect(jsonPath("$.success").value(true)) - //.andExpect(jsonPath("$.data").exists()); - -// testRestTemplate.postForEntity("/api/v1/auth/login", loginRequestDto, ResponseEntity.class); - } - - @Test - void reissueFromHeader() { - } - - @Test - void reissueFromCookie() { - } - - @Test - void reissueFromParam() { - } - - @Test - void validate() { - } - - @Test - void findAccessTokenInfo() { - } - - @Test - void testLogin() { - } - - @Test - void testReissueFromHeader() { - } - - @Test - void testReissueFromCookie() { - } - - @Test - void testReissueFromParam() { - } - - @Test - void testValidate() { - } - - @Test - void testFindAccessTokenInfo() { - } -} \ No newline at end of file diff --git a/src/test/java/com/xit/core/repository/core/CmmUserRepositoryTest.java b/src/test/java/com/xit/core/repository/core/CmmUserRepositoryTest.java deleted file mode 100644 index e8c4318..0000000 --- a/src/test/java/com/xit/core/repository/core/CmmUserRepositoryTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.xit.core.repository.core; - -import com.xit.biz.cmm.repository.ICmmUserRepository; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith(SpringExtension.class) -@DataJpaTest -@ActiveProfiles(value = "dev") -public class CmmUserRepositoryTest { - @Autowired - private ICmmUserRepository cmmUserRepository; - - -// @Test -// public void saveUserTest() { -// User user = new User(null,"name", "password"); -// User savedUser = userRepository.save(user); -// Assertions.assertEquals(user.getEmail(), savedUser.getEmail(), -// "saveUserTest"); -// Assertions.assertEquals(user.getPassword(), savedUser.getPassword(), -// "saveUserTest"); -// } -// -// @Test -// public void findByEmailSuccessTest() { -// User user = new User(null, "name1", "password"); -// User savedUser = userRepository.save(user); -// -// Optional userFindByEmail = userRepository.findByEmail(user.getEmail()); -// userFindByEmail.ifPresent(value -> Assertions.assertEquals(savedUser.getEmail(), value.getEmail())); -// } -// -// @Test -// public void findByEmailFailureTest() { -// -// Optional userFindByEmail = userRepository.findByEmail("not exist email"); -// Assertions.assertEquals(Optional.empty(), userFindByEmail); -// } -// -// @Test -// public void idStrategyTest() { -// User user1 = new User(null, "name1", "password"); -// User user2 = new User(null,"name2", "password"); -// User savedUser1 = userRepository.save(user1); -// User savedUser2 = userRepository.save(user2); -// -// Assertions.assertEquals(1, Math.abs(savedUser1.getId() - savedUser2.getId())); -// -// } -} diff --git a/src/test/java/com/xit/core/resolver/TestActiveProfileResolver.java b/src/test/java/com/xit/core/resolver/TestActiveProfileResolver.java deleted file mode 100644 index 8a38321..0000000 --- a/src/test/java/com/xit/core/resolver/TestActiveProfileResolver.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.xit.core.resolver; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.lang.NonNull; -import org.springframework.test.context.ActiveProfilesResolver; - -@Slf4j -public class TestActiveProfileResolver implements ActiveProfilesResolver { - - @Override - public @NonNull String[] resolve(@NonNull Class testClass) { - String profile = System.getProperty("profile"); - if (profile == null) { - profile = "local"; - log.warn("Default spring profiles active is null. use {} profile.", profile); - } - return new String[]{profile}; - } -} \ No newline at end of file diff --git a/src/test/java/com/xit/core/service/core/OAuthLocalServiceTest.java b/src/test/java/com/xit/core/service/core/OAuthLocalServiceTest.java deleted file mode 100644 index 614a0bc..0000000 --- a/src/test/java/com/xit/core/service/core/OAuthLocalServiceTest.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.xit.core.service.core; - -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -@ExtendWith(MockitoExtension.class) -public class OAuthLocalServiceTest { - -// @Mock -// private UserRepository userRepository; -// -// @InjectMocks -// private UserService userService = new UserServiceImpl(this.userRepository); - -// @Test -// void addUserSuccessfully() { -// final User user = new User(null, "name", "password"); -// given(userRepository.findByEmail(user.getEmail())).willReturn(Optional.empty()); -// given(userRepository.save(user)).willReturn(user); -// -// User savedUser = userService.add(user); -// Assertions.assertNotNull(savedUser); -// verify(userRepository).findByEmail(anyString()); -// verify(userRepository).save(any(User.class)); -// } -// -// @Test -// void addUserFailure() { -// final User user = new User(1L, "name", "password"); -// given(userRepository.findByEmail(user.getEmail())).willReturn(Optional.of(user)); -// Assertions.assertThrows(UserNotFoundException.class, () -> userService.add(user)); -// verify(userRepository, never()).save(any(User.class)); -// } -// -// @Test -// void getUserSuccessfully() { -// final User user = new User(1L, "name", "password"); -// given(userRepository.findById(user.getId())).willReturn(Optional.of(user)); -// User userByGet = userService.get(user.getId()); -// Assertions.assertEquals(user, userByGet); -// verify(userRepository).findById(anyLong()); -// } -// -// @Test -// void getUserFailure() { -// given(userRepository.findById(anyLong())).willReturn(Optional.empty()); -// Assertions.assertThrows(UserNotFoundException.class, () -> userService.get(anyLong())); -// verify(userRepository).findById(anyLong()); -// } -// -// @Test -// void updateSuccessfully() { -// final User user = new User(1L, "name", "password"); -// given(userRepository.findById(user.getId())).willReturn(Optional.of(user)); -// given(userRepository.save(user)).willReturn(user); -// User updatedUser = userService.update(user); -// Assertions.assertNotNull(updatedUser); -// verify(userRepository).save(any(User.class)); -// } -// -// @Test -// void updateFailure() { -// final User user = new User(1L, "name", "password"); -// given(userRepository.findById(anyLong())).willReturn(Optional.empty()); -// Assertions.assertThrows(UserNotFoundException.class, () -> userService.update(user)); -// verify(userRepository).findById(anyLong()); -// } -// -// @Test -// void deleteSuccessfully() { -// final Long id = 1L; -// userService.delete(id); -// verify(userRepository, times(1)).deleteById(anyLong()); -// verify(userRepository, times(1)).findById(anyLong()); -// -// } -// -// @Test -// void findByEmailSuccessfully() { -// final User user = new User(1L, "name", "password"); -// given(userRepository.findByEmail(user.getEmail())).willReturn(Optional.of(user)); -// User userByEmail = userService.findByEmail(user.getEmail()); -// Assertions.assertEquals(user, userByEmail); -// verify(userRepository).findByEmail(any(String.class)); -// } -// -// @Test -// void findByEmailFailure() { -// final String email = "email"; -// given(userRepository.findByEmail(email)).willReturn(Optional.empty()); -// Assertions.assertThrows(UserNotFoundException.class, () -> userService.findByEmail(email)); -// verify(userRepository).findByEmail(any(String.class)); -// } -}