본문 바로가기

Java

Spring boot Test with Mockito Mocking Framworks mockito easymock jmockit Mockito in spring boot mockito framwork is builtin spring boot dependency -> spring-boot-starter-test Mockito Test Process setup set expectations with mock reponses execute call the method want to test assert check the result and verify that it is expected result verify optionally.. verify calls (how many times called etc..) Mokcito Test in Spring boot .. 더보기
Unit Test - ParameterizedTest Source annotation @ValueSource -> Array of values: Strings, ints, doubles, floats etc @CsvSource -> Array of CSV String values @CsvFileSource -> CSV values read from a file @EnumSource -> Enum constant values @MethodSoruce -> Custom method for providing values //sample @DispleName("Testing with Small data file") @PrameterizedTest(name="value={0}, expected={1}") //0번째 인덱스의 값이 1 @CsvFileSource(res.. 더보기
Java Conditional Unit Test @Test @Disabled("Don't run until JIRA #123 is resolved") void testDisabled(){ // } @Test @EnabledOnOs(OS.WINDOWS) void testForWindowsOnly(){ } @Test @EnabledOnOs(OS.MAC) void testForMacOnly(){ } @Test @EnabledOnOs({OS.MAC,OS.WINDOWS}) void testForMacAndWindowsOnly(){ } @Test @EnabledOnOs(OS.LINUX) void testForLinuxOnly(){ } @Test @EnabledOnJre(JRE.JAVA_17) void testForJava17(){ } @Test @EnabledO.. 더보기
spring aop AOP DI 추가 implementation 'org.springframework.boot:spring-boot-starter-aop' controller @Slf4j @RestController @RequestMapping("/api") public class RestApiController { @GetMapping("/get/{id}") public String get(@PathVariable Long id, @RequestParam String name){ return String.format("%s-%s",id, name); } @PostMapping("/post") public UserDto post(@RequestBody UserDto userDto){ return userDto; } @Dec.. 더보기
Spring mvc async rest api /* 결제 내역 조회시 해당 결제 내역에 사용자 정보를 포함해야 한다. 사용자 정보 조회를 위해 결제아이디로 사용자 정보를 조회 후 결제 정보에 조인 시켜야 한다. 해당 프로세스를 비동기적으로 처리 하도록 한다. */ Enable Async and config thread pool @EnableAsync @Configuration public class BeanConfig { /** * @see https://kapentaz.github.io/spring/Spring-ThreadPoolTaskExecutor-%EC%84%A4%EC%A0%95/# */ @Bean("accounting-async-thread") public Executor asyncThread(){ ThreadPoolTaskExecutor .. 더보기
Spring mvc async rest api /* 결제 내역 조회시 해당 결제 내역에 사용자 정보를 포함해야 한다. 사용자 정보 조회를 위해 결제아이디로 사용자 정보를 조회 후 결제 정보에 조인 시켜야 한다. 해당 프로세스를 비동기적으로 처리 하도록 한다. */ Enable Async and config thread pool @EnableAsync @Configuration public class BeanConfig { /** * @see https://kapentaz.github.io/spring/Spring-ThreadPoolTaskExecutor-%EC%84%A4%EC%A0%95/# */ @Bean("accounting-async-thread") public Executor asyncThread(){ ThreadPoolTaskExecutor .. 더보기
java excell downloader in spring boot 1. dependency // xls 엑셀 파일 읽기 쓰기 implementation 'org.apache.poi:poi:4.1.2' // xlsx 엑셀 파일 읽기 쓰기 implementation 'org.apache.poi:poi-ooxml:4.1.2' 2. excell writer //column enum @Getter @AllArgsConstructor public enum ReconcileColumnType { PAYMENT_DATE("결제 일자", 0), CANCEL_DATE("취소 일자", 1), PG_REQUEST_KEY("결제 요청 번호", 2), USER_ID("사용자 아이디", 3), PAYMENT_STATUS("결제 상태", 4), PAYMENT_AMOUNT("결제(취소) 금액", 5.. 더보기
Java conver t JsonArray to List public static List jsonArrayToObjectList(String json, Class target) throws IOException { ObjectMapper mapper = new ObjectMapper(); CollectionType listType = mapper.getTypeFactory() .constructCollectionType(ArrayList.class, target); List ts = mapper.readValue(json, listType); log.debug("TargetClass: {}", ts.get(0).getClass().getName()); return ts; } //TargetClass class Target {} //sample json arr.. 더보기