샘플코드 완성
This commit is contained in:
@@ -8,11 +8,11 @@ import io.github.sejoung.product.persistence.mapper.RoundProductMapper;
|
||||
import io.github.sejoung.product.persistence.repository.ProductRepository;
|
||||
import io.github.sejoung.product.usecases.port.out.SaveRoundProductOutUseCase;
|
||||
|
||||
public class SaveRoundProductService implements SaveRoundProductOutUseCase {
|
||||
public class JPASaveRoundProductService implements SaveRoundProductOutUseCase {
|
||||
|
||||
private final ProductRepository repository;
|
||||
|
||||
public SaveRoundProductService(ProductRepository repository) {
|
||||
public JPASaveRoundProductService(ProductRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ spring:
|
||||
show-sql: true
|
||||
open-in-view: false
|
||||
hibernate:
|
||||
ddl-auto: validate
|
||||
ddl-auto: create-drop
|
||||
properties:
|
||||
hibernate:
|
||||
discriminator:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.github.sejoung.product.persistence.service;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -13,22 +14,21 @@ import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@DataJpaTest
|
||||
class SaveRoundProductServiceTest {
|
||||
|
||||
class JPASaveRoundProductServiceTest {
|
||||
@Autowired
|
||||
private ProductRepository repository;
|
||||
|
||||
private SaveRoundProductService service;
|
||||
private JPASaveRoundProductService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new SaveRoundProductService(repository);
|
||||
service = new JPASaveRoundProductService(repository);
|
||||
}
|
||||
|
||||
@Test
|
||||
void saveRoundProduct() {
|
||||
var actual = service.saveRoundProduct(JpaTestUtil.defaultRoundProduct());
|
||||
log.debug("{}",actual);
|
||||
log.debug("{}", actual);
|
||||
assertThat(actual.getProductId()).isNotNull();
|
||||
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
server:
|
||||
port: 8080
|
||||
@@ -1,8 +1,5 @@
|
||||
package io.github.sejoung.product.rest.controller;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
@@ -11,15 +8,12 @@ import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import io.github.sejoung.product.rest.util.RestTestUtil;
|
||||
import io.github.sejoung.product.rest.util.SaveRoundProductInUseCaseStub;
|
||||
import io.github.sejoung.product.usecases.port.in.SaveRoundProductInUseCase;
|
||||
|
||||
@WebMvcTest(controllers = SaveRoundProductController.class)
|
||||
class SaveRoundProductControllerTest {
|
||||
|
||||
30
configuration/build.gradle
Normal file
30
configuration/build.gradle
Normal file
@@ -0,0 +1,30 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'org.springframework.boot' version '2.5.1'
|
||||
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(':domain')
|
||||
implementation project(':adapters:jpa-persistence')
|
||||
implementation project(':adapters:rest')
|
||||
implementation 'org.springframework.boot:spring-boot-starter'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
runtimeOnly 'com.h2database:h2'
|
||||
|
||||
testImplementation('org.springframework.boot:spring-boot-starter-test') {
|
||||
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
|
||||
}
|
||||
|
||||
testImplementation 'com.h2database:h2'
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package io.github.sejoung.product;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package io.github.sejoung.product.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import io.github.sejoung.product.persistence.repository.ProductRepository;
|
||||
import io.github.sejoung.product.persistence.service.JPASaveRoundProductService;
|
||||
import io.github.sejoung.product.usecases.port.in.SaveRoundProductInUseCase;
|
||||
import io.github.sejoung.product.usecases.service.DomainSaveRoundProductService;
|
||||
|
||||
@Configuration
|
||||
public class DIConfiguration {
|
||||
|
||||
@Bean
|
||||
public SaveRoundProductInUseCase saveRoundProductInUseCase(ProductRepository repository) {
|
||||
return new DomainSaveRoundProductService(new JPASaveRoundProductService(repository));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package io.github.sejoung.product.rest.controller;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import io.github.sejoung.product.rest.util.RestTestUtil;
|
||||
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
class SaveRoundProductControllerTest {
|
||||
|
||||
private static final String URL = "/product/round";
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@DisplayName("회차권 API 테스트")
|
||||
@Test
|
||||
void saveRoundProduct() throws Exception {
|
||||
|
||||
var objectMapper = new ObjectMapper();
|
||||
var json = objectMapper.writeValueAsString(RestTestUtil.defaultSaveRoundProductCommand(null));
|
||||
mockMvc.perform(post(URL)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.content(json))
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package io.github.sejoung.product.rest.util;
|
||||
|
||||
import io.github.sejoung.product.entities.Product;
|
||||
import io.github.sejoung.product.usecases.port.in.SaveRoundProductInUseCase;
|
||||
|
||||
public interface RestTestUtil {
|
||||
|
||||
static SaveRoundProductInUseCase.SaveRoundProductCommand defaultSaveRoundProductCommand(Long productId) {
|
||||
return SaveRoundProductInUseCase.SaveRoundProductCommand.builder()
|
||||
.count(1)
|
||||
.status(Product.ProductStatus.CREATE)
|
||||
.productId(productId)
|
||||
.productName("회차권")
|
||||
.categoryId(1L)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,11 +4,11 @@ import io.github.sejoung.product.mapper.SaveRoundProductCommandMapper;
|
||||
import io.github.sejoung.product.usecases.port.in.SaveRoundProductInUseCase;
|
||||
import io.github.sejoung.product.usecases.port.out.SaveRoundProductOutUseCase;
|
||||
|
||||
public class SaveRoundProductService implements SaveRoundProductInUseCase {
|
||||
public class DomainSaveRoundProductService implements SaveRoundProductInUseCase {
|
||||
|
||||
private final SaveRoundProductOutUseCase saveRoundProductOutUseCase;
|
||||
|
||||
public SaveRoundProductService(SaveRoundProductOutUseCase saveRoundProductOutUseCase) {
|
||||
public DomainSaveRoundProductService(SaveRoundProductOutUseCase saveRoundProductOutUseCase) {
|
||||
this.saveRoundProductOutUseCase = saveRoundProductOutUseCase;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
package io.github.sejoung.product.usecases.service;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.github.sejoung.product.entities.Category;
|
||||
import io.github.sejoung.product.entities.Product;
|
||||
import io.github.sejoung.product.usecases.port.in.SaveRoundProductInUseCase;
|
||||
import io.github.sejoung.product.usecases.port.out.SaveRoundProductOutUseCaseStub;
|
||||
|
||||
class SaveRoundProductServiceTest {
|
||||
|
||||
private SaveRoundProductService service;
|
||||
class DomainSaveRoundProductServiceTest {
|
||||
private DomainSaveRoundProductService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
this.service = new SaveRoundProductService(new SaveRoundProductOutUseCaseStub());
|
||||
this.service = new DomainSaveRoundProductService(new SaveRoundProductOutUseCaseStub());
|
||||
}
|
||||
|
||||
@DisplayName("회차권 저장")
|
||||
@@ -3,4 +3,5 @@ rootProject.name = 'hexagonal-architecture'
|
||||
include 'domain'
|
||||
include 'adapters:jpa-persistence'
|
||||
include 'adapters:rest'
|
||||
include 'configuration'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user