spring
-
Spring boot Test with MockitoTech/SpringBoot 2022. 5. 22. 11:18
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 - ParameterizedTestTech/SpringBoot 2022. 5. 21. 13:32
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 TestTech/SpringBoot 2022. 5. 21. 13:17
@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 aopTech/SpringBoot 2021. 11. 7. 17:04
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 apiTech/SpringBoot 2021. 11. 7. 16:54
/* 결제 내역 조회시 해당 결제 내역에 사용자 정보를 포함해야 한다. 사용자 정보 조회를 위해 결제아이디로 사용자 정보를 조회 후 결제 정보에 조인 시켜야 한다. 해당 프로세스를 비동기적으로 처리 하도록 한다. */ 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 apiTech/SpringBoot 2021. 11. 7. 15:01
/* 결제 내역 조회시 해당 결제 내역에 사용자 정보를 포함해야 한다. 사용자 정보 조회를 위해 결제아이디로 사용자 정보를 조회 후 결제 정보에 조인 시켜야 한다. 해당 프로세스를 비동기적으로 처리 하도록 한다. */ 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 ..
-
ModelMapper 를 사용하여 객체 컨버팅 하기Tech/SpringBoot 2021. 5. 23. 12:14
서로 다른 클래스의 값을 복사 해주는 라이브러리이며, 필드명 일치 혹은 유사 필드 , 값일 없는 필드 복사 스킵 등 을 쉽게 도와 주는 라이브러리이다. 사용을 위한 dependency org.modelmapper modelmapper 2.3.8 사용 방법 //A 클래스를 B 클래스로 컨버팅 예제 ModelMapper modelMapper = new ModelMapper(); //MatchingStrategies 는 여러가지가 존재하며 상황에 맞게 사용 하도록 한다. //여기서는 필드명 완전일치 할 경우에만 진행 하도록 한다. modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); B b = modelMapper.ma..
-
spring factory patternTech/SpringBoot 2020. 10. 19. 23:46
Factory 패턴: 하위 클래스가 어떤 객체를 생성할지를 결정 하도록 하는 패턴. 스프링에서 빈을 컬렉션으로 주입할 수 있다. //타입 public enum AuthenticationType { PASSWORD, DEVICE, FIDO } //인터페이스 public interface AuthenticationService { AuthenticationType getAuthentiicationType(); void validateAuthentication(); } //비밀번호 인증구현체 @Slf4j @Service public class AuthenticationPasswordService implements AuthenticationService{ @Override public Authenticatio..
-
React Stream create and testTech/SpringBoot 2020. 8. 24. 19:14
//배열로 부터 리액트 타입 생성 public Flux creatFluxFromArray(){ String[] countryArray = new String[] { "Korea","America","China","Canada" }; Flux countryFlux = Flux.fromArray(countryArray); return countryFlux; } // 컬렉션 타입으로부터 리액트 타입 생성 public Flux creatFluxFromIterable(){ List countryList = Arrays.asList("Korea","America","China","Canada"); Flux countryFlux = Flux.fromIterable(countryList); return countryF..
-
Spring boot kafka demo with docker-composeTech/SpringBoot 2020. 7. 20. 21:15
spring boot kafka demo with docker ref kafka with springboot description kafka ref kafka 는 pub-sub 모델을 기반으로 동작한다. 구성요소: zookeeper: producer 와 consumer 를 관리한다. producer: topic 의 메시지 생성후 해당 메시지를 broker 에 전달 consumer: topic 을 subscribe 한다. 메시지를 pull 방식으로 broker 로부터 가져오기 때문에 batch consumer 구현 가능. broker: topic 을 기준으로 메시지 관리 전달받은 메시지를 topic 별로 분류하여 적재 topic: partition 단위로 구성 된다. 클러스터 서버에 분산 저장할 경우 pa..