Update Kotlin Samples

Closes gh-19
This commit is contained in:
Josh Cummings 2021-05-27 10:04:32 -06:00
parent 2396aa4630
commit 10b517f7b6
No known key found for this signature in database
GPG Key ID: 49EF60DD7FF83443
5 changed files with 22 additions and 26 deletions

View File

@ -1,16 +1,16 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
id("org.springframework.boot") version "2.2.6.RELEASE" id("org.springframework.boot") version "2.5.0"
id("io.spring.dependency-management") version "1.0.9.RELEASE" id("io.spring.dependency-management") version "1.0.9.RELEASE"
kotlin("jvm") version "1.3.71" kotlin("jvm") version "1.5.0"
kotlin("plugin.spring") version "1.3.71" kotlin("plugin.spring") version "1.5.0"
} }
repositories { repositories {
mavenCentral() mavenCentral()
maven { maven {
url = uri("https://repo.spring.io/libs-snapshot") url = uri("https://repo.spring.io/snapshot")
} }
} }

View File

@ -1 +1 @@
spring-security.version=5.4.0.BUILD-SNAPSHOT spring-security.version=5.6.0-SNAPSHOT

View File

@ -1,16 +1,16 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
id("org.springframework.boot") version "2.3.1.RELEASE" id("org.springframework.boot") version "2.5.0"
id("io.spring.dependency-management") version "1.0.9.RELEASE" id("io.spring.dependency-management") version "1.0.9.RELEASE"
kotlin("jvm") version "1.3.71" kotlin("jvm") version "1.5.0"
kotlin("plugin.spring") version "1.3.71" kotlin("plugin.spring") version "1.5.0"
} }
repositories { repositories {
mavenCentral() mavenCentral()
maven { maven {
url = uri("https://repo.spring.io/libs-snapshot") url = uri("https://repo.spring.io/snapshot")
} }
} }

View File

@ -1 +1 @@
spring-security.version=5.4.0.BUILD-SNAPSHOT spring-security.version=5.6.0-SNAPSHOT

View File

@ -17,8 +17,8 @@
package org.springframework.security.samples package org.springframework.security.samples
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.junit.Test import org.junit.jupiter.api.Test
import org.junit.runner.RunWith import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.context.SpringBootTest import org.springframework.boot.test.context.SpringBootTest
@ -26,12 +26,12 @@ import org.springframework.mock.web.MockHttpSession
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.formLogin import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.formLogin
import org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.authenticated import org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.authenticated
import org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.unauthenticated import org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.unauthenticated
import org.springframework.test.context.junit4.SpringRunner import org.springframework.test.context.junit.jupiter.SpringExtension
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.request.MockMvcRequestBuilders.get
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
@RunWith(SpringRunner::class) @ExtendWith(SpringExtension::class)
@SpringBootTest @SpringBootTest
@AutoConfigureMockMvc @AutoConfigureMockMvc
class KotlinApplicationTests { class KotlinApplicationTests {
@ -41,16 +41,14 @@ class KotlinApplicationTests {
@Test @Test
fun `index page is not protected`() { fun `index page is not protected`() {
this.mockMvc.get("/") this.mockMvc.perform(get("/"))
.andExpect { .andExpect(status().isOk())
status { isOk }
}
} }
@Test @Test
fun `protected page redirects to login`() { fun `protected page redirects to login`() {
val mvcResult = this.mockMvc.get("/user/index") val mvcResult = this.mockMvc.perform(get("/user/index"))
.andExpect { status { is3xxRedirection } } .andExpect(status().is3xxRedirection())
.andReturn() .andReturn()
assertThat(mvcResult.response.redirectedUrl).endsWith("/log-in") assertThat(mvcResult.response.redirectedUrl).endsWith("/log-in")
@ -76,10 +74,8 @@ class KotlinApplicationTests {
val httpSession = mvcResult.request.getSession(false) as MockHttpSession val httpSession = mvcResult.request.getSession(false) as MockHttpSession
this.mockMvc.get("/user/index") { this.mockMvc.perform(get("/user/index")
session = httpSession .session(httpSession))
}.andExpect { .andExpect(status().isOk());
status { isOk }
}
} }
} }