Spring Initializr에서 프로젝트 생성
application.properties 파일 수정
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.datasource.generate-unique-name=false
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
kafka topic 생성
checkout에서 생성한 데이터를 발행하고 consume
bin/kafka-topics.sh --create --topic checkout.complete.v1 --partitions 5 --bootstrap-server localhost:9092
product id별 합산 금액 발행
bin/kafka-topics.sh --create --topic checkout.aggregated.v1 --partitions 5 --bootstrap-server localhost:9092
코드 작성
테스트 - CheckOutSubmitControllerTest.java
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@AutoConfigureMockMvc
public class CheckOutSubmitControllerTest {
@Autowired
private MockMvc mockMvc;
@Test
public void testPostSubmitCheckOut() throws Exception {
mockMvc.perform(post("/submitCheckOut")
.param("memberId","10001")
.param("productId","200001")
.param("amount", "33000")
.param("shippingAddress","546"))
.andExpect(status().isOk())
.andDo(print());
}
}
서버 실행 후 확인
http://localhost:8080/checkOutForm 에서 데이터 전송
결과
데이터베이스 확인 - http://localhost:8080/h2-console