chore: 不要な依存を削除

This commit is contained in:
usbharu 2023-11-09 18:03:45 +09:00
parent 8992ff1928
commit f2fea24fce
2 changed files with 18 additions and 27 deletions

View File

@ -163,9 +163,7 @@ dependencies {
compileOnly("io.swagger.core.v3:swagger-annotations:2.2.6") compileOnly("io.swagger.core.v3:swagger-annotations:2.2.6")
implementation("io.swagger.core.v3:swagger-models:2.2.6") implementation("io.swagger.core.v3:swagger-models:2.2.6")
implementation("org.jetbrains.exposed:exposed-java-time:$exposed_version") implementation("org.jetbrains.exposed:exposed-java-time:$exposed_version")
testImplementation("org.springframework.boot:spring-boot-test-autoconfigure")
testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin") implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.springframework.security:spring-security-oauth2-jose") implementation("org.springframework.security:spring-security-oauth2-jose")
@ -193,7 +191,6 @@ dependencies {
implementation("io.ktor:ktor-client-content-negotiation:$ktor_version") implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
testImplementation("io.ktor:ktor-client-mock:$ktor_version") testImplementation("io.ktor:ktor-client-mock:$ktor_version")
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0") testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0")
testImplementation("org.mockito:mockito-inline:5.2.0") testImplementation("org.mockito:mockito-inline:5.2.0")
testImplementation("nl.jqno.equalsverifier:equalsverifier:3.15.3") testImplementation("nl.jqno.equalsverifier:equalsverifier:3.15.3")

View File

@ -16,17 +16,10 @@ import org.mockito.Mock
import org.mockito.junit.jupiter.MockitoExtension import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.kotlin.* import org.mockito.kotlin.*
import org.springframework.security.core.context.SecurityContextHolder import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.anonymous
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication
import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity
import org.springframework.security.web.DefaultSecurityFilterChain
import org.springframework.security.web.FilterChainProxy
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken
import org.springframework.security.web.util.matcher.AnyRequestMatcher
import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.get import org.springframework.test.web.servlet.get
import org.springframework.test.web.servlet.setup.MockMvcBuilders import org.springframework.test.web.servlet.setup.MockMvcBuilders
import org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder
import java.net.URL import java.net.URL
@ExtendWith(MockitoExtension::class) @ExtendWith(MockitoExtension::class)
@ -44,21 +37,21 @@ class NoteApControllerImplTest {
fun setUp() { fun setUp() {
mockMvc = MockMvcBuilders.standaloneSetup(noteApControllerImpl) mockMvc = MockMvcBuilders.standaloneSetup(noteApControllerImpl)
.apply<StandaloneMockMvcBuilder>( // .apply<StandaloneMockMvcBuilder>(
springSecurity( // springSecurity(
FilterChainProxy( // FilterChainProxy(
DefaultSecurityFilterChain( // DefaultSecurityFilterChain(
AnyRequestMatcher.INSTANCE // AnyRequestMatcher.INSTANCE
) // )
) // )
) // )
) // )
.build() .build()
} }
@Test @Test
fun `postAP 匿名で取得できる`() = runTest { fun `postAP 匿名で取得できる`() = runTest {
SecurityContextHolder.clearContext()
val note = Note( val note = Note(
name = "Note", name = "Note",
id = "https://example.com/users/hoge/posts/1234", id = "https://example.com/users/hoge/posts/1234",
@ -74,7 +67,7 @@ class NoteApControllerImplTest {
mockMvc mockMvc
.get("/users/hoge/posts/1234") { .get("/users/hoge/posts/1234") {
with(anonymous()) // with(anonymous())
} }
.asyncDispatch() .asyncDispatch()
.andExpect { status { isOk() } } .andExpect { status { isOk() } }
@ -83,11 +76,12 @@ class NoteApControllerImplTest {
@Test @Test
fun `postAP 存在しない場合は404`() = runTest { fun `postAP 存在しない場合は404`() = runTest {
SecurityContextHolder.clearContext()
whenever(noteApApiService.getNote(eq(123), isNull())).doReturn(null) whenever(noteApApiService.getNote(eq(123), isNull())).doReturn(null)
mockMvc mockMvc
.get("/users/hoge/posts/123") { .get("/users/hoge/posts/123") {
with(anonymous()) // with(anonymous())
} }
.asyncDispatch() .asyncDispatch()
.andExpect { status { isNotFound() } } .andExpect { status { isNotFound() } }
@ -117,11 +111,11 @@ class NoteApControllerImplTest {
SecurityContextHolder.getContext().authentication = preAuthenticatedAuthenticationToken SecurityContextHolder.getContext().authentication = preAuthenticatedAuthenticationToken
mockMvc.get("/users/hoge/posts/1234") { mockMvc.get("/users/hoge/posts/1234") {
with( // with(
authentication( // authentication(
preAuthenticatedAuthenticationToken // preAuthenticatedAuthenticationToken
) // )
) // )
}.asyncDispatch() }.asyncDispatch()
.andExpect { status { isOk() } } .andExpect { status { isOk() } }
.andExpect { content { json(objectMapper.writeValueAsString(note)) } } .andExpect { content { json(objectMapper.writeValueAsString(note)) } }