본문 바로가기

Java/스프링 입문 - 스프링 부트, 웹 MVC, DB 접근 기술19

[회원 관리 예제, 백엔드 개발 - (5)] 회원 서비스 테스트 git repository : https://github.com/Rezalog/spring-boot-entry-inf GitHub - Rezalog/spring-boot-entry-inf Contribute to Rezalog/spring-boot-entry-inf development by creating an account on GitHub. github.com 구현한 회원 서비스, MemberService 를 테스트하기 위한 코드를 작성해보자. 이때 테스트 코드 작성시, given-when-then 으로 나누어 작성하는 습관을 들이자! (**cmd + shift + T 로 테스트 자동 생성이 가능 !) MemberServiceTest beforeEach MemoryMemberRepository 은 .. 2022. 6. 30.
[회원 관리 예제, 백엔드 개발 - (4)] 회원 서비스 개발 git repository : https://github.com/Rezalog/spring-boot-entry-inf GitHub - Rezalog/spring-boot-entry-inf Contribute to Rezalog/spring-boot-entry-inf development by creating an account on GitHub. github.com 회원 서비스 : 회원 리포지토리와 도메인을 활용해서, 실제 비즈니스 로직을 구현한다. 실제로 구현해볼 서비스는 회원가입, 전체 회원 조회이다. MemberService class join(회원가입) - 기본 로직 도메인인 Member 타입으로 받은 회원정보로 중복 회원을 검증하고, repo에 저장한 뒤 Long type 의 id를 반환한다. .. 2022. 6. 30.
[회원 관리 예제, 백엔드 개발 - (3)] 회원 리포지토리 테스트 케이스 작성 git repository : https://github.com/Rezalog/spring-boot-entry-inf GitHub - Rezalog/spring-boot-entry-inf Contribute to Rezalog/spring-boot-entry-inf development by creating an account on GitHub. github.com 메인 메소드나 Controller를 실행해서 테스트를 하기에는 준비 및 실행이 오래걸리고, 반복적으로 실행하거나 여러 테스트케이스를 한번에 실행하기 어려운 단점이 있다. 이를 해결하기 위하여 JUnit 을 이용한 테스트 케이스를 작성하고 테스트 해볼 수 있다. JUnit Test 과정 (1) - findById 구현한 interface 인 M.. 2022. 6. 29.
[회원 관리 예제, 백엔드 개발 - (2)] 회원 도메인과 리포지토리 만들기 git repository : https://github.com/Rezalog/spring-boot-entry-inf GitHub - Rezalog/spring-boot-entry-inf Contribute to Rezalog/spring-boot-entry-inf development by creating an account on GitHub. github.com Package domain : 비즈니스 로직에서 사용되고 DB에 저장되어 관리되기 위한 객체 Member repository : domain 객체를 저장하기 위함 MemberRepository(interface) MemoryMebmerRepository(interface impl) domain 식별자 id, 입력받을 회원 정보인 name 에 .. 2022. 6. 29.
[회원 관리 예제, 백엔드 개발 - (1)] 비즈니스 요구사항 정리 git repository : https://github.com/Rezalog/spring-boot-entry-inf GitHub - Rezalog/spring-boot-entry-inf Contribute to Rezalog/spring-boot-entry-inf development by creating an account on GitHub. github.com 비즈니스 로직을 먼저 설정하고, 회원 도메인과 리포지토리를 만든다. 비즈니스 로직(스프링 생태계를 알아보기 위한 것이므로, 단순하게 작성) 데이터 : 회원ID, 이름 기능 : 회원 등록, 조회 DB 설정 안됨을 가정(memory) 리포지토리가 정상적으로 동작하는지 확인하기 위해 테스트 케이스를 작성한다. 실제 비즈니스 로직을 적용한 회원 서비.. 2022. 6. 29.
[스프링 웹 개발 기초 - (3)] API - API 방식 : 일단 view 에 관여하지 않고 서버간 데이터만 전달하는 방식으로 이해하자. hello-string method @ResponseBody : 해당 요청에 대한 HelloController가 helloString 메소드를 실행하여 처리할 때, 입력받은 query string 의 name 의 value 를 HTTP의 body 부에 직접 "hello + (name key의 value)" 형태로 넘겨준다. 즉, ResponseBody 어노테이션 때문에 view가 없이 데이터만 넘겨줌. html 태그 없이 body 부의 hello spring 만 보이는 상태. helloApi Method Hello static class 를 생성, helloApi 메소드에서 Hello 객체 인스턴스를 생성하여.. 2022. 6. 29.