-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
4 changed files
with
129 additions
and
9 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
cakk-api/src/test/java/com/cakk/api/common/base/ControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.cakk.api.common.base; | ||
|
||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
import org.springframework.web.context.WebApplicationContext; | ||
import org.springframework.web.filter.CharacterEncodingFilter; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.navercorp.fixturemonkey.FixtureMonkey; | ||
import com.navercorp.fixturemonkey.api.introspector.BuilderArbitraryIntrospector; | ||
import com.navercorp.fixturemonkey.api.introspector.ConstructorPropertiesArbitraryIntrospector; | ||
import com.navercorp.fixturemonkey.api.introspector.FieldReflectionArbitraryIntrospector; | ||
|
||
@AutoConfigureMockMvc | ||
@ActiveProfiles("test") | ||
@SpringBootTest | ||
public abstract class ControllerTest { | ||
|
||
@Autowired | ||
protected MockMvc mockMvc; | ||
|
||
@Autowired | ||
protected ObjectMapper objectMapper; | ||
|
||
@BeforeEach | ||
void setup(WebApplicationContext webApplicationContext) { | ||
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext) | ||
.addFilters(new CharacterEncodingFilter("UTF-8", true)) | ||
.alwaysDo(print()) | ||
.build(); | ||
} | ||
|
||
protected final FixtureMonkey getConstructorMonkey() { | ||
return FixtureMonkey.builder() | ||
.objectIntrospector(ConstructorPropertiesArbitraryIntrospector.INSTANCE) | ||
.build(); | ||
} | ||
|
||
protected final FixtureMonkey getReflectionMonkey() { | ||
return FixtureMonkey.builder() | ||
.objectIntrospector(FieldReflectionArbitraryIntrospector.INSTANCE) | ||
.build(); | ||
} | ||
|
||
protected final FixtureMonkey getBuilderMonkey() { | ||
return FixtureMonkey.builder() | ||
.objectIntrospector(BuilderArbitraryIntrospector.INSTANCE) | ||
.build(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
cakk-api/src/test/java/com/cakk/api/common/base/ServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.cakk.api.common.base; | ||
|
||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import com.navercorp.fixturemonkey.FixtureMonkey; | ||
import com.navercorp.fixturemonkey.api.introspector.BuilderArbitraryIntrospector; | ||
import com.navercorp.fixturemonkey.api.introspector.ConstructorPropertiesArbitraryIntrospector; | ||
import com.navercorp.fixturemonkey.api.introspector.FieldReflectionArbitraryIntrospector; | ||
|
||
import com.cakk.domain.config.JpaConfig; | ||
|
||
@Import(JpaConfig.class) | ||
@ActiveProfiles("test") | ||
@ExtendWith(MockitoExtension.class) | ||
public abstract class ServiceTest { | ||
|
||
protected final FixtureMonkey getConstructorMonkey() { | ||
return FixtureMonkey.builder() | ||
.objectIntrospector(ConstructorPropertiesArbitraryIntrospector.INSTANCE) | ||
.build(); | ||
} | ||
|
||
protected final FixtureMonkey getReflectionMonkey() { | ||
return FixtureMonkey.builder() | ||
.objectIntrospector(FieldReflectionArbitraryIntrospector.INSTANCE) | ||
.build(); | ||
} | ||
|
||
protected final FixtureMonkey getBuilderMonkey() { | ||
return FixtureMonkey.builder() | ||
.objectIntrospector(BuilderArbitraryIntrospector.INSTANCE) | ||
.build(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
cakk-api/src/test/java/com/cakk/api/common/container/MysqlTestContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.cakk.api.common.container; | ||
|
||
import org.testcontainers.containers.MySQLContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
@Testcontainers | ||
public abstract class MysqlTestContainer { | ||
|
||
private static final String MYSQL_VERSION = "mysql:8"; | ||
private static final String DATABASE_NAME = "cakk"; | ||
|
||
@Container | ||
public static final MySQLContainer MYSQL_CONTAINER = new MySQLContainer(MYSQL_VERSION) | ||
.withDatabaseName(DATABASE_NAME); | ||
|
||
static { | ||
MYSQL_CONTAINER.start(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters