diff --git a/.github/workflows/pr-ci.yaml b/.github/workflows/pr-ci.yaml new file mode 100644 index 0000000..89c64b5 --- /dev/null +++ b/.github/workflows/pr-ci.yaml @@ -0,0 +1,59 @@ +name: PR 시 CI 테스트 자동화 + +on: + pull_request: + branches: + - main + +jobs: + test: + name: Test + runs-on: ubuntu-latest + + permissions: + checks: write + pull-requests: write + + steps: + - name: 레포지토리 체크아웃 + uses: actions/checkout@v4 + with: + token: ${{ secrets.GIT_TOKEN }} + - run: touch ./src/main/resources/security.properties + - run: echo "${{ secrets.SECURITY_PROP }}" > ./src/main/resources/security.properties + + - name: JDK 17 설치 + uses: actions/setup-java@v4 + with: + distribution: 'oracle' + java-version: '17' + cache: 'gradle' + + - name: Gradle 종속성 캐시 + uses: actions/cache@v4 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Gradle 명령 실행 권한 부여 + run: chmod +x ./gradlew + shell: bash + + - name: Gradle로 프로젝트 Build + run: ./gradlew build + + - name: 테스트 결과를 PR 코멘트로 출력 + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + files: '**/build/test-results/test/TEST-*.xml' + + - name: 테스트 실패 시, 오류가 발생한 코드 라인에 코멘트 추가 + uses: mikepenz/action-junit-report@v4 + if: always() + with: + report_paths: '**/build/test-results/test/TEST-*.xml' \ No newline at end of file diff --git a/build.gradle b/build.gradle index 869139f..656f936 100644 --- a/build.gradle +++ b/build.gradle @@ -36,35 +36,41 @@ dependencies { // Mail implementation 'org.springframework.boot:spring-boot-starter-mail' + testImplementation 'com.icegreen:greenmail-junit5:2.1.1' + testImplementation 'commons-codec:commons-codec:1.17.1' // Security implementation 'org.springframework.boot:spring-boot-starter-security' // DB implementation 'org.mariadb.jdbc:mariadb-java-client:3.1.2' + runtimeOnly 'com.h2database:h2' - // Redis 추가 + // Redis implementation 'org.springframework.boot:spring-boot-starter-data-redis' // Swagger implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0' - //jwt + // JWT implementation 'io.jsonwebtoken:jjwt-api:0.11.5' implementation 'io.jsonwebtoken:jjwt-impl:0.11.5' implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5' - // mybatis + // MyBatis implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.4' - // lombok + // Lombok annotationProcessor 'org.projectlombok:lombok' compileOnly 'org.projectlombok:lombok' - // test + // Test testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + testImplementation 'org.springframework.boot:spring-boot-testcontainers' + testImplementation 'org.testcontainers:testcontainers' + testImplementation 'org.testcontainers:junit-jupiter' //Querydsl 추가 implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' diff --git a/src/main/java/com/example/shop/ShopApplication.java b/src/main/java/com/example/shop/ShopApplication.java index 5cfd1e2..99cefdc 100644 --- a/src/main/java/com/example/shop/ShopApplication.java +++ b/src/main/java/com/example/shop/ShopApplication.java @@ -7,7 +7,6 @@ import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @SpringBootApplication -@EnableJpaAuditing @PropertySource("classpath:security.properties") public class ShopApplication { diff --git a/src/main/java/com/example/shop/auth/controller/AuthController.java b/src/main/java/com/example/shop/auth/controller/AuthController.java index bc5ace0..fe08a4d 100644 --- a/src/main/java/com/example/shop/auth/controller/AuthController.java +++ b/src/main/java/com/example/shop/auth/controller/AuthController.java @@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.*; @Tag(name="Auth") -@RestController() +@RestController @RequiredArgsConstructor @RequestMapping(value = "/api/auth") public class AuthController { diff --git a/src/main/java/com/example/shop/global/config/db/JpaConfig.java b/src/main/java/com/example/shop/global/config/db/JpaConfig.java new file mode 100644 index 0000000..5490473 --- /dev/null +++ b/src/main/java/com/example/shop/global/config/db/JpaConfig.java @@ -0,0 +1,9 @@ +package com.example.shop.global.config.db; + +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +@Configuration +@EnableJpaAuditing +public class JpaConfig { +} diff --git a/src/main/java/com/example/shop/global/config/db/RedisConfig.java b/src/main/java/com/example/shop/global/config/db/RedisConfig.java index eb67d36..54cbc06 100644 --- a/src/main/java/com/example/shop/global/config/db/RedisConfig.java +++ b/src/main/java/com/example/shop/global/config/db/RedisConfig.java @@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisStandaloneConfiguration; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; @@ -12,6 +13,7 @@ import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; +@Profile("!test") @Configuration @EnableRedisRepositories public class RedisConfig { diff --git a/src/test/java/com/example/shop/ShopApplicationTests.java b/src/test/java/com/example/shop/ShopApplicationTests.java index 47684f7..695059c 100644 --- a/src/test/java/com/example/shop/ShopApplicationTests.java +++ b/src/test/java/com/example/shop/ShopApplicationTests.java @@ -1,9 +1,11 @@ package com.example.shop; import org.junit.jupiter.api.Test; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest +@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.ANY) class ShopApplicationTests { @Test diff --git a/src/test/java/com/example/shop/admin/dao/OrderDeliveryRepositoryTest.java b/src/test/java/com/example/shop/admin/dao/OrderDeliveryRepositoryTest.java index 6446489..e4e36d2 100644 --- a/src/test/java/com/example/shop/admin/dao/OrderDeliveryRepositoryTest.java +++ b/src/test/java/com/example/shop/admin/dao/OrderDeliveryRepositoryTest.java @@ -1,12 +1,14 @@ package com.example.shop.admin.dao; import com.example.shop.admin.dto.OrderDeliveryRequest; +import com.example.shop.global.setting.RedisTest; import org.assertj.core.api.SoftAssertions; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; 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.jdbc.AutoConfigureTestDatabase; import org.springframework.boot.test.context.SpringBootTest; import java.util.Set; @@ -14,8 +16,10 @@ import static com.example.shop.batch.util.OrderDeliveryBatchUtil.getOrderKeyYesterday; import static org.assertj.core.api.Assertions.assertThat; + @SpringBootTest -class OrderDeliveryRepositoryTest { +@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.ANY) +class OrderDeliveryRepositoryTest extends RedisTest { @Autowired private OrderDeliveryRepository orderDeliveryRepository; diff --git a/src/test/java/com/example/shop/batch/OrderUpdateSenderWriterTest.java b/src/test/java/com/example/shop/batch/OrderUpdateSenderWriterTest.java index 1273375..9ef52bf 100644 --- a/src/test/java/com/example/shop/batch/OrderUpdateSenderWriterTest.java +++ b/src/test/java/com/example/shop/batch/OrderUpdateSenderWriterTest.java @@ -7,9 +7,7 @@ import com.example.shop.domain.order.Order; import com.example.shop.domain.order.OrderRepository; import com.example.shop.domain.order.OrderStatus; -import com.example.shop.domain.user.Role; -import com.example.shop.domain.user.User; -import com.example.shop.domain.user.UserRepository; +import com.example.shop.global.setting.ServiceTest; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; @@ -17,20 +15,24 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.jdbc.Sql; -import java.util.ArrayList; import java.util.List; import static com.example.shop.batch.util.OrderDeliveryBatchUtil.getOrderKeyYesterday; +import static org.mockito.Mockito.doNothing; -@Transactional -@SpringBootTest -class OrderUpdateSenderWriterTest { - @Autowired +@ExtendWith(MockitoExtension.class) +@Sql(scripts = "classpath:/sql/order-data.sql", + executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) +class OrderUpdateSenderWriterTest extends ServiceTest { + + @MockBean private AdminOrderService adminOrderService; @Autowired private OrderDeliveryRepository orderDeliveryRepository; @@ -38,24 +40,12 @@ class OrderUpdateSenderWriterTest { private SqlSessionFactory sqlSessionFactory; @Autowired private OrderRepository orderRepository; - @Autowired - private UserRepository userRepository; @BeforeEach void setup() { - User user = User.builder() - .email("test@test.com") - .password("test") - .userRole(Role.ROLE_USER) - .orders(new ArrayList<>()) - .userName("tester") - .build(); - - user = userRepository.save(user); - - for (long i = 1; i <= 532; i++) { + for (long i = 1; i <= 5; i++) { orderDeliveryRepository.addOrderEmail(getOrderKeyYesterday(), - new OrderDeliveryRequest(user.getEmail(), i+"test")); + new OrderDeliveryRequest("test@test.com", i+"test")); } } @@ -70,7 +60,7 @@ void write() { sqlSession.flushStatements(); } finally { - orderDeliveryRequestList.forEach(adminOrderService::sendDeliveryAlertEmail); + orderDeliveryRequestList.forEach(doNothing().when(adminOrderService)::sendDeliveryAlertEmail); orderDeliveryRepository.removeOrderEmail(getOrderKeyYesterday(), orderDeliveryRequestList.toArray()); } diff --git a/src/test/java/com/example/shop/global/config/RedisTestConfig.java b/src/test/java/com/example/shop/global/config/RedisTestConfig.java new file mode 100644 index 0000000..e4e8411 --- /dev/null +++ b/src/test/java/com/example/shop/global/config/RedisTestConfig.java @@ -0,0 +1,30 @@ +package com.example.shop.global.config; + +import com.example.shop.admin.dto.OrderDeliveryRequest; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +@TestConfiguration +@EnableRedisRepositories +public class RedisTestConfig { + + @Bean + public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate redisTemplate = new RedisTemplate<>(); + redisTemplate.setConnectionFactory(connectionFactory); + + // JSON 형식으로 직렬화 + Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer<>(OrderDeliveryRequest.class); + redisTemplate.setKeySerializer(new StringRedisSerializer()); + redisTemplate.setValueSerializer(serializer); + redisTemplate.setHashKeySerializer(new StringRedisSerializer()); + redisTemplate.setHashValueSerializer(serializer); + + return redisTemplate; + } +} diff --git a/src/test/java/com/example/shop/global/config/RedisTestContainer.java b/src/test/java/com/example/shop/global/config/RedisTestContainer.java new file mode 100644 index 0000000..bbd2640 --- /dev/null +++ b/src/test/java/com/example/shop/global/config/RedisTestContainer.java @@ -0,0 +1,28 @@ +package com.example.shop.global.config; + +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testcontainers.utility.DockerImageName; + +@Testcontainers +public class RedisTestContainer { + + private static final String REDIS_IMAGE = "redis:7.4.1-alpine"; + private static final int REDIS_PORT = 6379; + private static final GenericContainer REDIS_CONTAINER; + + static { + REDIS_CONTAINER = new GenericContainer<>(DockerImageName.parse(REDIS_IMAGE)) + .withExposedPorts(REDIS_PORT) + .withReuse(true); + REDIS_CONTAINER.start(); + } + + @DynamicPropertySource + private static void registerRedisProperties(DynamicPropertyRegistry registry) { + registry.add("spring.data.redis.host", REDIS_CONTAINER::getHost); + registry.add("spring.data.redis.port", () -> REDIS_CONTAINER.getMappedPort(REDIS_PORT)); + } +} diff --git a/src/test/java/com/example/shop/global/setting/ControllerTest.java b/src/test/java/com/example/shop/global/setting/ControllerTest.java new file mode 100644 index 0000000..8f81ee3 --- /dev/null +++ b/src/test/java/com/example/shop/global/setting/ControllerTest.java @@ -0,0 +1,63 @@ +package com.example.shop.global.setting; + +import com.example.shop.admin.controller.AdminOrderController; +import com.example.shop.admin.controller.AdminProductController; +import com.example.shop.admin.service.AdminOrderService; +import com.example.shop.admin.service.AdminProductService; +import com.example.shop.auth.controller.AuthController; +import com.example.shop.auth.service.AuthService; +import com.example.shop.global.config.auth.JwtAuthenticationFilter; +import com.example.shop.user.controller.CartController; +import com.example.shop.user.controller.OrderController; +import com.example.shop.user.controller.ProductController; +import com.example.shop.user.service.CartService; +import com.example.shop.user.service.OrderService; +import com.example.shop.user.service.ProductService; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +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.test.context.ActiveProfiles; +import org.springframework.test.web.servlet.MockMvc; + +@ActiveProfiles("test") +@ExtendWith(MockitoExtension.class) +@WebMvcTest({ + AdminOrderController.class, + AdminProductController.class, + AuthController.class, + CartController.class, + OrderController.class, + ProductController.class +}) +public abstract class ControllerTest { + + @Autowired + protected MockMvc mockMvc; + + @Autowired + protected ObjectMapper objectMapper; + + @MockBean + protected JwtAuthenticationFilter jwtAuthenticationFilter; + + @MockBean + protected AdminOrderService adminOrderService; + + @MockBean + protected AdminProductService adminProductService; + + @MockBean + protected AuthService authService; + + @MockBean + protected CartService cartService; + + @MockBean + protected OrderService orderService; + + @MockBean + protected ProductService productService; +} diff --git a/src/test/java/com/example/shop/global/setting/RedisTest.java b/src/test/java/com/example/shop/global/setting/RedisTest.java new file mode 100644 index 0000000..a240d2d --- /dev/null +++ b/src/test/java/com/example/shop/global/setting/RedisTest.java @@ -0,0 +1,13 @@ +package com.example.shop.global.setting; + +import com.example.shop.global.config.RedisTestConfig; +import com.example.shop.global.config.RedisTestContainer; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.ActiveProfiles; + +@SpringBootTest +@ActiveProfiles("test") +@Import(RedisTestConfig.class) +public abstract class RedisTest extends RedisTestContainer { +} diff --git a/src/test/java/com/example/shop/global/setting/RepositoryTest.java b/src/test/java/com/example/shop/global/setting/RepositoryTest.java new file mode 100644 index 0000000..47011f6 --- /dev/null +++ b/src/test/java/com/example/shop/global/setting/RepositoryTest.java @@ -0,0 +1,11 @@ +package com.example.shop.global.setting; + +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.ActiveProfiles; + +@DataJpaTest +@ActiveProfiles("test") +@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.ANY) +public abstract class RepositoryTest { +} diff --git a/src/test/java/com/example/shop/global/setting/ServiceTest.java b/src/test/java/com/example/shop/global/setting/ServiceTest.java new file mode 100644 index 0000000..a1416a5 --- /dev/null +++ b/src/test/java/com/example/shop/global/setting/ServiceTest.java @@ -0,0 +1,15 @@ +package com.example.shop.global.setting; + +import com.example.shop.global.config.RedisTestConfig; +import com.example.shop.global.config.RedisTestContainer; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.ActiveProfiles; + +@SpringBootTest +@ActiveProfiles("test") +@Import(RedisTestConfig.class) +@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.ANY) +public abstract class ServiceTest extends RedisTestContainer { +} diff --git a/src/test/java/com/example/shop/global/util/EmailSenderTest.java b/src/test/java/com/example/shop/global/util/EmailSenderTest.java new file mode 100644 index 0000000..bae23d5 --- /dev/null +++ b/src/test/java/com/example/shop/global/util/EmailSenderTest.java @@ -0,0 +1,116 @@ +package com.example.shop.global.util; + +import com.example.shop.admin.dto.OrderDeliveryRequest; +import com.example.shop.global.config.RedisTestConfig; +import com.icegreen.greenmail.configuration.GreenMailConfiguration; +import com.icegreen.greenmail.junit5.GreenMailExtension; +import com.icegreen.greenmail.util.GreenMailUtil; +import com.icegreen.greenmail.util.ServerSetupTest; +import jakarta.mail.MessagingException; +import jakarta.mail.internet.MimeMessage; +import org.apache.commons.codec.DecoderException; +import org.apache.commons.codec.net.QuotedPrintableCodec; +import org.assertj.core.api.SoftAssertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.ActiveProfiles; +import org.thymeleaf.context.Context; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +import static com.example.shop.global.util.TemplateEnginUtil.templateEngine; + +@SpringBootTest +@ActiveProfiles("test") +@Import(RedisTestConfig.class) +@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.ANY) +class EmailSenderTest { + + @RegisterExtension + static GreenMailExtension greenMail = new GreenMailExtension(ServerSetupTest.SMTP) + .withConfiguration(GreenMailConfiguration.aConfig().withUser("testMail", "testMail")) + .withPerMethodLifecycle(true); // 테스트 메서드마다 새로운 GreenMail 인스턴스 사용 + + @Autowired + private EmailSender emailSender; + + @DisplayName("이메일 인증 코드 송수신 테스트") + @Test + void sendAuthCode() { + // given + String receivedEmail = "receivedmail@test.com"; + String subject = "test subject"; + String content = authCodeTemplate("test authCode"); + + // when + emailSender.sendMail(receivedEmail, subject, content); + greenMail.waitForIncomingEmail(1); // 비동기로 동작하기 때문에 대기함 + + //then + verifyReceivedEmail(receivedEmail, subject, content); + } + + @DisplayName("주문 배송 알림 이메일 송수신 테스트") + @Test + void sendDeliveryAlertEmail() { + // given + OrderDeliveryRequest order = new OrderDeliveryRequest("tester@test.com", "Test Order Number"); + String today = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy년 MM월 dd일")); + String receivedEmail = "tester@test.com"; + String subject = "test subject"; + String content = orderDeliveryTemplate(order); + + // when + emailSender.sendMail(receivedEmail, subject, content); + greenMail.waitForIncomingEmail(1); // 비동기로 동작하기 때문에 대기함 + + //then + verifyReceivedEmail(receivedEmail, subject, content); + } + + private void verifyReceivedEmail(String receivedEmail, String subject, String content) { + QuotedPrintableCodec codec = new QuotedPrintableCodec("UTF-8"); // 한글을 디코딩하기 위함 + MimeMessage[] receivedMessages = greenMail.getReceivedMessages(); + + SoftAssertions.assertSoftly(softAssertions -> { + try { + softAssertions.assertThat(receivedMessages[0].getAllRecipients()[0].toString()) + .isEqualTo(receivedEmail); + + softAssertions.assertThat(receivedMessages[0].getSubject()) + .isEqualTo(subject); + + softAssertions.assertThat(codec.decode(GreenMailUtil.getBody(receivedMessages[0]))) + .isEqualToIgnoringNewLines(content); + + softAssertions.assertThatThrownBy(() -> GreenMailUtil.getBody(receivedMessages[1])) + .isExactlyInstanceOf(ArrayIndexOutOfBoundsException.class); + + } catch (MessagingException | DecoderException e) { + e.printStackTrace(); + } + }); + } + + private String authCodeTemplate(String authCode) { + Context context = new Context(); + context.setVariable("authCode", authCode); + return templateEngine.process("auth-code-email", context); + } + + private String orderDeliveryTemplate(OrderDeliveryRequest order) { + String orderNumber = order.getOrderNumber(); + String deliveryDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy년 MM월 dd일")); + + Context context = new Context(); + context.setVariable("orderNumber", orderNumber); + context.setVariable("deliveryDate", deliveryDate); + return templateEngine.process("delivery-email", context); + } +} \ No newline at end of file diff --git a/src/test/resources/application-test.yaml b/src/test/resources/application-test.yaml new file mode 100644 index 0000000..c6c0337 --- /dev/null +++ b/src/test/resources/application-test.yaml @@ -0,0 +1,68 @@ +spring: + datasource: + driver-class-name: org.h2.Driver + url: jdbc:h2:mem/shop;MODE=MYSQL;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=TRUE + username: sa + password: + + jpa: + show-sql: true + hibernate: + ddl-auto: create-drop + properties: + hibernate: + format_sql: true + dialect: org.hibernate.dialect.H2Dialect + defer-datasource-initialization: true + database: h2 + + mail: + host: 127.0.0.1 + port: 3025 + username: testMail + password: testMail + properties: + mail: + smtp: + auth: true + starttls: + enable: true + transport: + protocol: smtp + debug: true + default-encoding: UTF-8 + + data: + redis: + port: 6379 + host: localhost + + batch: + jdbc: + initialize-schema: always + + web: + resources: + static-locations: file:///C:/ProductImage/ # 이미지 저장 경로 설정 + +server: + shutdown: graceful + +jwt: + secret: dgedgbdafmjgbaasfgadbsgmadfhgbfamfdsbvmssdgsdfgdf + + +mybatis: + mapper-locations: classpath:mappers/*.xml + type-aliases-package: com.example.shop.user.dto, com.example.shop.admin.dto + configuration: + map-underscore-to-camel-case: true + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + +logging: + level: + root: INFO + org.mybatis: DEBUG + org.apache.ibatis: DEBUG + org.mybatis.spring.SqlSessionFactoryBean: DEBUG + org.springframework.jdbc.datasource.DataSourceTransactionManager: DEBUG diff --git a/src/test/resources/sql/order-data.sql b/src/test/resources/sql/order-data.sql new file mode 100644 index 0000000..a4f6c2f --- /dev/null +++ b/src/test/resources/sql/order-data.sql @@ -0,0 +1,22 @@ +-- User 테이블에 데이터 삽입 +INSERT INTO users (email, password, user_role, user_name, user_status, created_at, updated_at) +VALUES + ('test@test.com', 'test', 'ROLE_USER', 'tester', 'ACTIVE', now(), now()); + +-- Order 테이블에 데이터 삽입 +INSERT INTO orders ( + created_at, updated_at, receiver_address, receiver_name, receiver_phone, + receiver_postal_code, shipping_message, order_number, order_status, + total_price, user_id +) +VALUES + (CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'Address 1', 'User 1', '0100000001', + '10001', 'Test message', '1test', 'PAID', 10500.00, 1), + (CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'Address 2', 'User 2', '0100000002', + '10002', 'Test message', '2test', 'PAID', 11000.00, 1), + (CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'Address 3', 'User 3', '0100000003', + '10003', 'Test message', '3test', 'PAID', 11500.00, 1), + (CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'Address 4', 'User 4', '0100000004', + '10004', 'Test message', '4test', 'PAID', 12000.00, 1), + (CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'Address 5', 'User 5', '0100000005', + '10005', 'Test message', '5test', 'PAID', 12500.00, 1);