parent
0eb018ac5a
commit
c3f2aa348f
@ -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<? extends IRestResponse> 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<? extends IRestResponse> findMinSimsa680s(
|
||||
@Parameter(hidden = true)
|
||||
final MinSimsa680Dto minSimsa680Dto,
|
||||
@Parameter(hidden = true)
|
||||
final Pageable pageable) {
|
||||
return RestResponse.of(service.findMinSimsa680s2(mapstruct.toEntity(minSimsa680Dto), pageable));
|
||||
}
|
||||
|
||||
}
|
@ -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<MinSimsaUser680> 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;
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
@ -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<MinSimsa680GroupDto, MinSimsa680> {
|
||||
|
||||
}
|
@ -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<MinSimsa680Dto, MinSimsa680> {
|
||||
|
||||
}
|
@ -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<MinSimsa680, Long>, IMinSimsa680RepositoryCustom {
|
||||
}
|
@ -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<MinSimsa680GroupDto> findMinSimsa680Groups(MinSimsa680GroupDto pMinSimsa680GroupDto, Pageable pageable);
|
||||
Page<MinSimsaReviewGroupDto> findMinSimsa680s2(Pageable pageable);
|
||||
}
|
@ -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<MinSimsa680GroupDto> 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<MinSimsa680GroupDto> 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<MinSimsaReviewGroupDto> 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<Long> rsltEa = new CaseBuilder()
|
||||
// .when(minSimsaUser680.msuResult.eq("0")).then(0L)
|
||||
// .otherwise(1L).sum().as("clcnt");
|
||||
QueryResults<MinSimsaReviewGroupDto> 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());
|
||||
}
|
||||
}
|
@ -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<MinSimsa680GroupDto> findMinSimsa680Groups(MinSimsa680 minSimsa680, Pageable pageable);
|
||||
Page<MinSimsa680GroupDto> findMinSimsa680Groups(MinSimsa680GroupDto minSimsa680GroupDto, Pageable pageable);
|
||||
|
||||
Page<MinSimsa680> findMinSimsa680s(MinSimsa680 minSimsa680, Pageable pageable);
|
||||
|
||||
Page<MinSimsaReviewGroupDto> findMinSimsa680s2(MinSimsa680 minSimsa680, Pageable pageable);
|
||||
}
|
@ -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<MinSimsa680> findMinSimsa680s(MinSimsa680 minSimsa680, Pageable pageable) {
|
||||
pageable = JpaUtil.getPagingInfo(pageable);
|
||||
ExampleMatcher exampleMatcher = ExampleMatcher.matchingAll()
|
||||
.withMatcher("ciTitle", contains())
|
||||
.withMatcher("ciName", contains());
|
||||
Example<MinSimsa680> example = Example.of(minSimsa680, exampleMatcher);
|
||||
Page<MinSimsa680> page = repository.findAll(example, pageable);
|
||||
// List<CmmUser> userList = page.getContent();
|
||||
return page;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Page<MinSimsa680GroupDto> findMinSimsa680Groups(MinSimsa680GroupDto minSimsa680GroupDto, Pageable pageable) {
|
||||
return repository.findMinSimsa680Groups(minSimsa680GroupDto, pageable);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Page<MinSimsaReviewGroupDto> findMinSimsa680s2(MinSimsa680 minSimsa680, Pageable pageable) {
|
||||
return repository.findMinSimsa680s2(pageable);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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<T>
|
||||
* @return PageImpl<T>
|
||||
*/
|
||||
fun <T> getPageImpl(pageable: Pageable, query: JPQLQuery<T>): PageImpl<T> {
|
||||
return if (query.metadata.groupBy.size > 0) {
|
||||
getPageImplIfGroupBy(pageable, query)
|
||||
} else {
|
||||
getPageImplIfNotGroupBy(pageable, query)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GroupBy절을 사용하는 Query
|
||||
* @param pageable Pageable
|
||||
* @param query JPQLQuery<T>
|
||||
* @return PageImpl<T>
|
||||
*/
|
||||
private fun <T> getPageImplIfGroupBy(pageable: Pageable, query: JPQLQuery<T>): PageImpl<T> {
|
||||
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<T>
|
||||
* @return PageImpl<T>
|
||||
*/
|
||||
private fun <T> getPageImplIfNotGroupBy(pageable: Pageable, query: JPQLQuery<T>): PageImpl<T> {
|
||||
val totalCount = query.fetchCount()
|
||||
|
||||
val results = getQuerydsl()
|
||||
.applyPagination(pageable, query)
|
||||
.fetch()
|
||||
|
||||
return PageImpl(results, pageable, totalCount)
|
||||
}
|
||||
}
|
@ -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() {
|
||||
}
|
||||
|
||||
}
|
@ -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() {
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
@ -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<BoardDto> 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() {
|
||||
// }
|
||||
//}
|
@ -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<Board> 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<MemberVo> 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<MemberVo> 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 **********/
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//}
|
@ -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());
|
||||
// }
|
||||
//}
|
@ -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() {
|
||||
// }
|
||||
//}
|
@ -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() {
|
||||
}
|
||||
}
|
@ -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<CmmUser> responseEntity = this.restTemplate.postForEntity(url+"/api/cmm/user", cmmUser, CmmUser.class);
|
||||
//
|
||||
// //then
|
||||
// assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
//
|
||||
//// List<CmmUser> 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() {
|
||||
// }
|
||||
//}
|
@ -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<CmmRole> 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() {
|
||||
}
|
||||
}
|
@ -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<CmmBoard> boardInfo = boardRepository.findById(1l);
|
||||
boardInfo.ifPresent(v -> assertEquals(v.getTitle(), "제목1"));
|
||||
|
||||
//Optional<Board> byId = boardRepository.findByBoardId(1l);
|
||||
}
|
||||
}
|
@ -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<CmmCodeL> cmmCodeLList = cmmCodeLRepository.findByCodeGrpIdAndUseYnOrderByCodeOrdr(savedCmmCodeL.getCodeGrpId(), savedCmmCodeL.getUseYn());
|
||||
//System.out.println(cmmCodeLList);
|
||||
|
||||
List<ComboCodeDto> 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<CmmCodeS> list = cmmCodeSRepository.findByCodeGrpIdAndCodeLcdAndCodeMcdAndUseYnOrderByCodeOrdr(savedCmmCodeS.getCodeGrpId(), savedCmmCodeS.getCodeLcd(), savedCmmCodeS.getCodeMcd(), savedCmmCodeS.getUseYn());
|
||||
//System.out.println(list);
|
||||
|
||||
List<ComboCodeDto> 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<CmmCodeDto> 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<CmmCodeS> example = Example.of(codeS, exampleMatcher);
|
||||
cmmCodeSRepository.findAll(example);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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<CmmRole> 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<CmmRoleGrp> savedRols = roleRepository.saveAll(roles);
|
||||
|
||||
// then
|
||||
//assertEquals(user.getUserId(), savedRols.get(0).getRoleId());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void findByCmmUserId() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void findByUserId() {
|
||||
}
|
||||
}
|
@ -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<CmmUser> 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);
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -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<CmmUser> 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());
|
||||
// }
|
||||
//}
|
@ -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<CmmUser> employees = cmmUserRepository.findAll();
|
||||
// Assertions.assertThat(employees).extracting(CmmUser::getUserName).containsOnly("임종욱");
|
||||
//
|
||||
// cmmUserRepository.deleteAll();
|
||||
// Assertions.assertThat(cmmUserRepository.findAll()).isEmpty();
|
||||
// }
|
||||
//}
|
||||
//
|
@ -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<CmmUser> list = new ArrayList<CmmUser>();
|
||||
// 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<CmmUser> 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);
|
||||
// }
|
||||
//}
|
@ -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<CmmUser> 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")));
|
||||
// }
|
||||
//}
|
@ -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();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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<String, String> 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() {
|
||||
}
|
||||
}
|
@ -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<User> userFindByEmail = userRepository.findByEmail(user.getEmail());
|
||||
// userFindByEmail.ifPresent(value -> Assertions.assertEquals(savedUser.getEmail(), value.getEmail()));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void findByEmailFailureTest() {
|
||||
//
|
||||
// Optional<User> 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()));
|
||||
//
|
||||
// }
|
||||
}
|
@ -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};
|
||||
}
|
||||
}
|
@ -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));
|
||||
// }
|
||||
}
|
Loading…
Reference in New Issue