Skip to content

Commit

Permalink
Merge pull request #66 from COW-dev/main
Browse files Browse the repository at this point in the history
Co-authored-by: doji <[email protected]>
Co-authored-by: Bokyeom <[email protected]>
  • Loading branch information
3 people authored Nov 26, 2023
2 parents 51ea2b8 + e70bc76 commit f1c7be2
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 32 deletions.
3 changes: 1 addition & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import com.epages.restdocs.apispec.gradle.OpenApi3Task
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jooq.meta.jaxb.Logging
Expand Down Expand Up @@ -130,7 +129,7 @@ tasks.withType<Test> {

tasks.test {
extensions.configure(JacocoTaskExtension::class) {
destinationFile = file("$buildDir/jacoco/jacoco.exec")
setDestinationFile(file("$buildDir/jacoco/jacoco.exec"))
}

finalizedBy(tasks.jacocoTestReport)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### Application version ###
applicationVersion=0.1.3-RELEASE
applicationVersion=0.1.5-RELEASE

### Project configs ###
projectGroup="com.mjucow"
Expand Down
30 changes: 30 additions & 0 deletions src/main/kotlin/com/mjucow/eatda/common/config/WebConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.mjucow.eatda.common.config

import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpMethod
import org.springframework.web.servlet.config.annotation.CorsRegistry
import org.springframework.web.servlet.config.annotation.EnableWebMvc
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
import java.time.Duration
import java.time.temporal.ChronoUnit

@Configuration
@EnableWebMvc
class WebConfig : WebMvcConfigurer {

override fun addCorsMappings(registry: CorsRegistry) {
registry.addMapping("/api/**")
.allowedOriginPatterns("*")
.allowedMethods(
HttpMethod.GET.name(),
HttpMethod.POST.name(),
HttpMethod.DELETE.name(),
HttpMethod.PATCH.name(),
HttpMethod.HEAD.name(),
HttpMethod.OPTIONS.name()
)
.allowedHeaders("*")
.allowCredentials(true)
.maxAge(Duration.of(60, ChronoUnit.MINUTES).toSeconds())
}
}
14 changes: 1 addition & 13 deletions src/test/kotlin/com/mjucow/eatda/AbstractApplicationTest.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
package com.mjucow.eatda

import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.testcontainers.service.connection.ServiceConnection
import org.springframework.test.context.ActiveProfiles
import org.testcontainers.containers.PostgreSQLContainer
import org.testcontainers.junit.jupiter.Container
import org.testcontainers.junit.jupiter.Testcontainers

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@Testcontainers
@ActiveProfiles("test")
abstract class AbstractApplicationTest {
companion object {
@Container
@ServiceConnection
val POSTGRESQL_CONTAINER = PostgreSQLContainer("postgres:15.4-alpine")
.withUsername("test-user")
.withPassword("test-password")
.withDatabaseName("test_db")!!
}
}
abstract class AbstractApplicationTest : AbstractSpringContextTest()
6 changes: 6 additions & 0 deletions src/test/kotlin/com/mjucow/eatda/AbstractSpringContextTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.mjucow.eatda

import org.springframework.test.annotation.DirtiesContext

@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
abstract class AbstractSpringContextTest
5 changes: 3 additions & 2 deletions src/test/kotlin/com/mjucow/eatda/domain/AbstractCacheTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mjucow.eatda.domain

import com.mjucow.eatda.AbstractSpringContextTest
import com.mjucow.eatda.common.config.RedisConfiguration
import com.mjucow.eatda.common.properties.RedisProperties
import org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest
Expand All @@ -17,9 +18,9 @@ import org.testcontainers.utility.DockerImageName
@Testcontainers
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@ActiveProfiles("test")
abstract class AbstractCacheTest {
abstract class AbstractCacheTest : AbstractSpringContextTest() {
companion object {
const val REDIS_PORT = 6379
private const val REDIS_PORT = 6379

@Container
@ServiceConnection(name = "redis")
Expand Down
15 changes: 2 additions & 13 deletions src/test/kotlin/com/mjucow/eatda/domain/AbstractDataTest.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
package com.mjucow.eatda.domain

import com.mjucow.eatda.AbstractSpringContextTest
import com.mjucow.eatda.common.config.JacksonConfiguration
import com.mjucow.eatda.common.config.JooqContextConfiguration
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
import org.springframework.boot.testcontainers.service.connection.ServiceConnection
import org.springframework.context.annotation.Import
import org.springframework.test.context.ActiveProfiles
import org.testcontainers.containers.PostgreSQLContainer
import org.testcontainers.junit.jupiter.Container
import org.testcontainers.junit.jupiter.Testcontainers

@Import(value = [JooqContextConfiguration::class, JacksonConfiguration::class])
@DataJpaTest
@Testcontainers
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@ActiveProfiles("test")
abstract class AbstractDataTest {
companion object {
@Container
@ServiceConnection
val POSTGRESQL_CONTAINER = PostgreSQLContainer("postgres:15.4-alpine")
.withUsername("test-user")
.withPassword("test-password")
.withDatabaseName("test_db")!!
}
}
abstract class AbstractDataTest : AbstractSpringContextTest()
3 changes: 2 additions & 1 deletion src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ spring:
enabled: true

datasource:
url: jdbc:tc:postgresql:///test-database
driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver
url: jdbc:tc:postgresql:15.4-alpine://test-database

data:
redis:
Expand Down

0 comments on commit f1c7be2

Please sign in to comment.