Skip to content

Commit

Permalink
Merge pull request #9 from sdeleuze/various-improvements
Browse files Browse the repository at this point in the history
Various improvements
  • Loading branch information
arey committed Feb 15, 2018
2 parents 392fe59 + 9f3ce77 commit 4702c81
Show file tree
Hide file tree
Showing 19 changed files with 111 additions and 149 deletions.
27 changes: 13 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

buildscript {

extra["kotlinVersion"] = "1.1.60"
extra["springBootVersion"] = "2.0.0.M7"
extra["jUnitVersion"] = "5.0.0"
extra["springBootVersion"] = "2.0.0.RC1"
extra["boostrapVersion"] = "3.3.6"
extra["jQueryVersion"] = "2.2.4"
extra["jQueryUIVersion"] = "1.11.4"
extra["elVersion"] = "3.0.1-b08"

val springBootVersion: String by extra

Expand All @@ -26,15 +23,16 @@ buildscript {


plugins {
val kotlinVersion = "1.1.60"
val kotlinVersion = "1.2.21"

id("org.jetbrains.kotlin.jvm") version kotlinVersion
id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion
id("io.spring.dependency-management") version "1.0.3.RELEASE"
id("io.spring.dependency-management") version "1.0.4.RELEASE"
}

apply {
plugin("org.springframework.boot")
plugin("org.junit.platform.gradle.plugin")
}


Expand All @@ -44,7 +42,6 @@ val jUnitVersion: String by extra
val boostrapVersion: String by extra
val jQueryVersion: String by extra
val jQueryUIVersion: String by extra
val elVersion: String by extra

version = springBootVersion

Expand All @@ -66,20 +63,22 @@ dependencies {
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.springframework.boot:spring-boot-starter-cache")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-webflux")
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("javax.cache:cache-api")
compile("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion")
compile("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
compile("org.jetbrains.kotlin:kotlin-stdlib")
compile("org.jetbrains.kotlin:kotlin-reflect")
compile("org.webjars:webjars-locator")
compile("org.webjars:jquery:$jQueryVersion")
compile("org.webjars:jquery-ui:$jQueryUIVersion")
compile("org.webjars:bootstrap:$boostrapVersion")

testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("org.glassfish:javax.el:$elVersion")
testCompile("org.junit.jupiter:junit-jupiter-api:$jUnitVersion")
testRuntime("org.junit.jupiter:junit-jupiter-engine:$jUnitVersion")
testCompile("org.springframework.boot:spring-boot-starter-test") {
exclude(module = "junit")
}
testCompile("org.springframework.boot:spring-boot-starter-webflux")
testCompile("org.junit.jupiter:junit-jupiter-api")
testRuntime("org.junit.jupiter:junit-jupiter-engine")

runtime("org.hsqldb:hsqldb")
runtime("mysql:mysql-connector-java")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Owner : Person() {
@Digits(fraction = 0, integer = 10)
var telephone = ""

@OneToMany(cascade = arrayOf(CascadeType.ALL), mappedBy = "owner")
@OneToMany(cascade = [CascadeType.ALL], mappedBy = "owner")
var pets: MutableSet<Pet> = HashSet()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Pet : NamedEntity() {
@JoinColumn(name = "owner_id")
var owner: Owner? = null

@OneToMany(cascade = arrayOf(CascadeType.ALL), mappedBy = "petId", fetch = FetchType.EAGER)
@OneToMany(cascade = [CascadeType.ALL], mappedBy = "petId", fetch = FetchType.EAGER)
var visits: MutableSet<Visit> = LinkedHashSet()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import javax.xml.bind.annotation.XmlElement
class Vet : Person() {

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "vet_specialties", joinColumns = arrayOf(JoinColumn(name = "vet_id")), inverseJoinColumns = arrayOf(JoinColumn(name = "specialty_id")))
@JoinTable(name = "vet_specialties", joinColumns = [JoinColumn(name = "vet_id")], inverseJoinColumns = [JoinColumn(name = "specialty_id")])
var specialties: MutableSet<Specialty> = HashSet()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ class VetController(val vetRepository: VetRepository) {
return "vets/vetList"
}

@GetMapping(path = arrayOf("vets.json"), produces = arrayOf("application/json"))
@GetMapping("vets.json", produces = ["application/json"])
@ResponseBody
fun showJsonVetList(): Vets =
// Here we are returning an object of type 'Vets' rather than a collection of Vet
// objects so it is simpler for Json/Object mapping
Vets(vetRepository.findAll())


@GetMapping(path = arrayOf("vets.xml"))
@GetMapping("vets.xml")
@ResponseBody
fun showXmlVetList(): Vets =
Vets(vetRepository.findAll())
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h3>Built with:</h3>
<li><a href="https://projects.spring.io/spring-boot/">Spring Boot</a></li>
<li><a href="https://kotlinlang.org/">The Kotlin programming language</a></li>
<li><a href="http://www.thymeleaf.org/">The Thymeleaf template engine</a></li>
<li><a href="https://docs.spring.io/spring-framework/docs/5.0.1.RELEASE/spring-framework-reference/web-reactive.html#spring-webflux">Spring WebFlux</a></li>
<li><a href="https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/web.html#mvc">Spring MVC</a></li>
</ul>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.springframework.samples.petclinic.model


import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.jupiter.api.Test
import org.springframework.context.i18n.LocaleContextHolder
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean
import java.util.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ package org.springframework.samples.petclinic.owner
import org.assertj.core.api.Assertions
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.util.Lists
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.BDDMockito.given
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.context.annotation.Import
import org.springframework.test.context.junit4.SpringRunner
import org.springframework.test.context.junit.jupiter.SpringExtension
import org.springframework.test.web.reactive.server.WebTestClient
import org.springframework.util.LinkedMultiValueMap
import org.springframework.web.reactive.function.BodyInserters
Expand All @@ -26,20 +26,17 @@ import java.util.*
*
* @author Colin But
*/
@RunWith(SpringRunner::class)
@ExtendWith(SpringExtension::class)
@WebFluxTest(OwnerController::class)
@Import(ThymeleafAutoConfiguration::class)
class OwnerControllerTest {

@Autowired
lateinit private var client: WebTestClient;
class OwnerControllerTest(@Autowired private val client: WebTestClient) {

@MockBean
lateinit private var owners: OwnerRepository
private lateinit var owners: OwnerRepository

lateinit private var george: Owner
private lateinit var george: Owner

@Before
@BeforeEach
fun setup() {
Locale.setDefault(Locale.US)
george = Owner()
Expand Down Expand Up @@ -107,7 +104,7 @@ class OwnerControllerTest {
}

@Test
@Ignore
@Disabled
fun testProcessFindFormByLastName() {
given(owners.findByLastName(george.lastName)).willReturn(Lists.newArrayList<Owner>(george))

Expand All @@ -120,7 +117,7 @@ class OwnerControllerTest {
}

@Test
@Ignore
@Disabled
fun testProcessFindFormNoOwnersFound() {

// How to submit data into a GET with the Webflux client?
Expand Down Expand Up @@ -195,7 +192,7 @@ class OwnerControllerTest {

companion object {

private val TEST_OWNER_ID = 1
private const val TEST_OWNER_ID = 1
}

}
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package org.springframework.samples.petclinic.owner

import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
import org.springframework.test.context.junit4.SpringRunner
import org.springframework.test.context.junit.jupiter.SpringExtension
import org.springframework.transaction.annotation.Transactional


@RunWith(SpringRunner::class)
@ExtendWith(SpringExtension::class)
@DataJpaTest
class OwnerRepositoryTest {

@Autowired
lateinit private var owners: OwnerRepository
class OwnerRepositoryTest(@Autowired private val owners: OwnerRepository) {

@Test
fun shouldFindOwnersByLastName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package org.springframework.samples.petclinic.owner

import org.assertj.core.api.Assertions
import org.assertj.core.util.Lists
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.BDDMockito.given
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration
Expand All @@ -14,7 +14,7 @@ import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.FilterType
import org.springframework.context.annotation.Import
import org.springframework.test.context.junit4.SpringRunner
import org.springframework.test.context.junit.jupiter.SpringExtension
import org.springframework.test.web.reactive.server.WebTestClient
import org.springframework.util.LinkedMultiValueMap
import org.springframework.web.reactive.function.BodyInserters
Expand All @@ -25,24 +25,21 @@ import java.util.*
*
* @author Colin But
*/
const val TEST_OWNER_ID = 1
const val TEST_PET_ID = 1

@RunWith(SpringRunner::class)
@WebFluxTest(PetController::class, includeFilters = arrayOf(ComponentScan.Filter(value = PetTypeFormatter::class, type = FilterType.ASSIGNABLE_TYPE)))
@ExtendWith(SpringExtension::class)
@WebFluxTest(PetController::class, includeFilters = [ComponentScan.Filter(value = PetTypeFormatter::class, type = FilterType.ASSIGNABLE_TYPE)])
@Import(ThymeleafAutoConfiguration::class)
class PetControllerTest {
class PetControllerTest(@Autowired private val client: WebTestClient) {

@Autowired
lateinit private var client: WebTestClient;
private val TEST_OWNER_ID = 1
private val TEST_PET_ID = 1

@MockBean
lateinit private var pets: PetRepository
private lateinit var pets: PetRepository

@MockBean
lateinit private var owners: OwnerRepository
private lateinit var owners: OwnerRepository

@Before
@BeforeEach
fun setup() {
val cat = PetType()
cat.id = 3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
package org.springframework.samples.petclinic.owner

import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
import org.springframework.test.context.junit4.SpringRunner
import org.springframework.test.context.junit.jupiter.SpringExtension
import org.springframework.transaction.annotation.Transactional
import java.util.*

@RunWith(SpringRunner::class)
@ExtendWith(SpringExtension::class)
@DataJpaTest
class PetRepositoryTest {

@Autowired
lateinit private var pets: PetRepository

@Autowired
lateinit private var owners: OwnerRepository

class PetRepositoryTest(@Autowired private val pets: PetRepository, @Autowired private val owners: OwnerRepository) {

@Test
fun shouldFindPetWithCorrectId() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.springframework.samples.petclinic.owner


import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.junit.MockitoJUnitRunner
import org.springframework.test.context.junit.jupiter.SpringExtension
import java.text.ParseException
import java.util.*

Expand All @@ -16,17 +17,17 @@ import java.util.*
*
* @author Colin But
*/
@RunWith(MockitoJUnitRunner::class)
@ExtendWith(SpringExtension::class)
class PetTypeFormatterTest {

@Mock
lateinit private var pets: PetRepository
private lateinit var pets: PetRepository

lateinit private var petTypeFormatter: PetTypeFormatter
private lateinit var petTypeFormatter: PetTypeFormatter

@Before
@BeforeEach
fun setup() {
this.petTypeFormatter = PetTypeFormatter(pets)
petTypeFormatter = PetTypeFormatter(pets)
}

@Test
Expand All @@ -45,11 +46,10 @@ class PetTypeFormatterTest {
assertEquals("Bird", petType.name)
}

@Test(expected = ParseException::class)
@Throws(ParseException::class)
fun shouldThrowParseException() {
Mockito.`when`(this.pets.findPetTypes()).thenReturn(makePetTypes())
petTypeFormatter.parse("Fish", Locale.ENGLISH)
assertThrows(ParseException::class.java, { petTypeFormatter.parse("Fish", Locale.ENGLISH) })
}

/**
Expand Down
Loading

0 comments on commit 4702c81

Please sign in to comment.