Update Tests to validate more fields

This commit is contained in:
Reinhard Prechtl 2017-06-09 18:15:14 +02:00
parent 75abdba122
commit 925e76f497

View file

@ -22,13 +22,12 @@ import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Scope import org.springframework.context.annotation.Scope
import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.junit4.SpringRunner import org.springframework.test.context.junit4.SpringRunner
import javax.transaction.Transactional import java.time.LocalDateTime
@RunWith(SpringRunner::class) @RunWith(SpringRunner::class)
@ContextConfiguration(classes = arrayOf( @ContextConfiguration(classes = arrayOf(
JpaCityServiceTest.Config::class, JpaCityServiceTest.Config::class,
CityConfig::class)) CityConfig::class))
@Transactional
@DataJpaTest @DataJpaTest
internal class JpaCityServiceTest { internal class JpaCityServiceTest {
@ -93,23 +92,37 @@ internal class JpaCityServiceTest {
@Test @Test
fun `'updateCity' should update existing values`() { fun `'updateCity' should update existing values`() {
val existingCity = repository.save(CityEntity("city", "cityname", "description", Coordinate(1.0, -1.0))) val existingCity = repository.save(CityEntity("city", "cityname", "description", Coordinate(1.0, -1.0))).toDto()
val result = service.updateCity(existingCity.id!!, UpdateCityDto("new name", "new description", CoordinateDto(-1.0, -1.0)))
val result = service.updateCity(existingCity.id, UpdateCityDto("new name", "new description", CoordinateDto(-1.0, -1.0)))
softly.assertThat(result).isNotNull softly.assertThat(result).isNotNull
softly.assertThat(result?.id).isEqualTo(existingCity.id) softly.assertThat(result?.id).isEqualTo(existingCity.id)
softly.assertThat(result?.name).isEqualTo("new name") softly.assertThat(result?.name).isEqualTo("new name")
softly.assertThat(result?.description).isEqualTo("new description") softly.assertThat(result?.description).isEqualTo("new description")
softly.assertThat(result?.location).isEqualTo(CoordinateDto(-1.0, -1.0)) softly.assertThat(result?.location).isEqualTo(CoordinateDto(-1.0, -1.0))
softly.assertThat(result?.updatedAt).isAfter(existingCity.updatedAt)
softly.assertThat(result?.updatedAt).isAfter(existingCity.updatedAt)
softly.assertThat(result?.createdAt).isEqualTo(existingCity.createdAt)
} }
@Test @Test
fun `'updateCity' shouldn't update null values`() { fun `'updateCity' shouldn't update null values`() {
val existingCity = repository.save(CityEntity("city", "cityname", "description", Coordinate(1.0, -1.0))) val existingCity = repository.save(CityEntity(
val result = service.updateCity(existingCity.id!!, UpdateCityDto(null, null, null)) id = "city",
name = "cityname",
description = "description",
location = Coordinate(1.0, -1.0),
updatedAt = LocalDateTime.now().minusYears(1))).toDto()
val result = service.updateCity(existingCity.id, UpdateCityDto(null, null, null))
softly.assertThat(result).isNotNull softly.assertThat(result).isNotNull
softly.assertThat(result?.id).isEqualTo(existingCity.id) softly.assertThat(result?.id).isEqualTo(existingCity.id)
softly.assertThat(result?.name).isEqualTo("cityname") softly.assertThat(result?.name).isEqualTo("cityname")
softly.assertThat(result?.description).isEqualTo("description") softly.assertThat(result?.description).isEqualTo("description")
softly.assertThat(result?.location).isEqualTo(CoordinateDto(1.0, -1.0)) softly.assertThat(result?.location).isEqualTo(CoordinateDto(1.0, -1.0))
softly.assertThat(result?.updatedAt).isAfter(existingCity.updatedAt)
softly.assertThat(result?.createdAt).isEqualTo(existingCity.createdAt)
} }
} }