반응형 Spring10 Java - Spring Boot의Security를 알아보자 해결 방법 Spring Security를 사용하면 아무 것도 설정하지 않은 상태에서 모든 화면에 액세스하려면 인증이 필요합니다. 로그인 없이 액세스할 수 있도록 하려면 다음과 같이 하십시오. 보안 설정 클래스로 WebSecurityConfigurerAdapter 클래스를 상속하고 EnableWebSecurity 어노테이션이 추가된 클래스를 만듭니다. void configure(HttpSecurity http)메소드를 오버라이드(override) 해, 이하와 같이 인증 불필요한 화면 (URL)을 지정합니다. @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter{ @Bean publ.. 2022. 11. 1. ⑩Junit Controller Test bookList, Search, delete, update Test 2. BookList Test @Sql("classpath:db/tableInit.sql") @Test public void getBookList_test() { //given //when HttpEntity request = new HttpEntity(null, headers); ResponseEntity response = rt.exchange("/api/v1/book", HttpMethod.GET, request, String.class); //then DocumentContext dc = JsonPath.parse(response.getBody()); Integer code = dc.read("$.code"); String title = dc.read("$.body.items[0].title");.. 2022. 10. 23. ⑨Junit Controller Test 초기설정 및 BookSave Test 이제부턴 Controller의 테스트를 진행해보겠습니다. BookApiController 초기설정 //総合テスト @ActiveProfiles("dev") @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class BookApiControllerTest { @Autowired private TestRestTemplate rt; @Autowired private BookRepository bookRepository; private static ObjectMapper om; private static HttpHeaders headers; @BeforeAll public static void init() { om = new ObjectMa.. 2022. 10. 22. ⑦Junit Controller 초기설정 및 책 등록, 책 리스트 보기 먼저 Controller 초기 설정 @RequiredArgsConstructor @RestController public class BookApiController { private final BookService bookService; //1. book save //{ "key" : value, "key" : value } //Jsonは@RequestBodyが必要 @PostMapping("/api/v1/book") public ResponseEntity saveBook(@RequestBody @Valid BookSaveReqDto bookSaveReqDto, BindingResult bindingResult) { if(bindingResult.hasErrors()) { Map errorMap = new.. 2022. 10. 22. ⑥Service Junit 테스트 - 4 검색 수정 junit테스트 1. book 검색 테스트 @Test public void bookSearchTest() { //given Long id = 1L; //stub Book book = new Book(1L, "junit-1", "coding-1"); Optional bookOP = Optional.of(book); when(bookRepository.findById(id)).thenReturn(bookOP); //when BookRespDto bookRespDto = bookService.booksSearch(id); //then assertThat(bookRespDto.getTitle()).isEqualTo(book.getTitle()); assertThat(bookRespDto.getAuthor()).isEqualTo.. 2022. 10. 20. ⑤Service Junit 테스트 - 3 등록과 리스트 junit테스트 Junit 초기 설정 //@DataJpaTest //Tranjectional あるため、テスト後ロールバックします。 @ExtendWith(MockitoExtension.class) public class BookServiceTest { @InjectMocks private BookService bookService; @Mock private BookRepository bookRepository; @Mock private MailSender mailSender; //@Autowired //private BookRepository bookRepository; // 気になる… サービスだけテストしたいけど、レポジトリもテストになる Mockito使用 @ExtendWith(MockitoExtension.class) : M.. 2022. 10. 19. 이전 1 2 다음 반응형