Correction des tests
This commit is contained in:
parent
891e32990d
commit
689bd2a602
|
@ -7,6 +7,7 @@ import dev.fyloz.colorrecipesexplorer.model.EmployeeLoginRequest
|
|||
import dev.fyloz.colorrecipesexplorer.model.EmployeePermission
|
||||
import dev.fyloz.colorrecipesexplorer.service.EmployeeService
|
||||
import dev.fyloz.colorrecipesexplorer.service.EmployeeServiceImpl
|
||||
import dev.fyloz.colorrecipesexplorer.service.EmployeeUserDetailsService
|
||||
import dev.fyloz.colorrecipesexplorer.service.EmployeeUserDetailsServiceImpl
|
||||
import io.jsonwebtoken.ExpiredJwtException
|
||||
import io.jsonwebtoken.Jwts
|
||||
|
@ -219,7 +220,7 @@ class JwtAuthenticationFilter(
|
|||
}
|
||||
|
||||
class JwtAuthorizationFilter(
|
||||
private val userDetailsService: EmployeeUserDetailsServiceImpl,
|
||||
private val userDetailsService: EmployeeUserDetailsService,
|
||||
private val securityConfigurationProperties: SecurityConfigurationProperties,
|
||||
authenticationManager: AuthenticationManager
|
||||
) : BasicAuthenticationFilter(authenticationManager) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package dev.fyloz.colorrecipesexplorer.model
|
|||
|
||||
import org.springframework.security.core.GrantedAuthority
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority
|
||||
import java.util.*
|
||||
|
||||
enum class EmployeePermission(
|
||||
val impliedPermissions: List<EmployeePermission> = listOf(),
|
||||
|
|
|
@ -51,9 +51,6 @@ interface NamedModelService<E : NamedModel, R : JpaRepository<E, *>> : ModelServ
|
|||
|
||||
/** Gets the entity with the given [name]. */
|
||||
fun getByName(name: String): E
|
||||
|
||||
/** Deletes the entity with the given [name]. */
|
||||
fun deleteByName(name: String)
|
||||
}
|
||||
|
||||
|
||||
|
@ -100,7 +97,6 @@ abstract class AbstractNamedModelService<E : NamedModel, R : NamedJpaRepository<
|
|||
|
||||
override fun existsByName(name: String): Boolean = repository.existsByName(name)
|
||||
override fun getByName(name: String): E = repository.findByName(name) ?: throw nameNotFoundException(name)
|
||||
override fun deleteByName(name: String) = repository.deleteByName(name)
|
||||
|
||||
override fun save(entity: E): E {
|
||||
if (existsByName(entity.name))
|
||||
|
|
|
@ -250,7 +250,6 @@ abstract class AbstractNamedModelServiceTest<E : NamedModel, S : NamedModelServi
|
|||
doReturn(false).whenever(service).existsById(entity.id!!)
|
||||
|
||||
assertThrows<NotFoundException> { service.update(entity) }
|
||||
.assertErrorCode("name")
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -261,15 +260,6 @@ abstract class AbstractNamedModelServiceTest<E : NamedModel, S : NamedModelServi
|
|||
assertThrows<AlreadyExistsException> { service.update(entity) }
|
||||
.assertErrorCode("name")
|
||||
}
|
||||
|
||||
// deleteByName()
|
||||
|
||||
@Test
|
||||
open fun `deleteByName() deletes the entity with the given name in the repository`() {
|
||||
service.deleteByName(entity.name)
|
||||
|
||||
verify(repository).deleteByName(entity.name)
|
||||
}
|
||||
}
|
||||
|
||||
interface ExternalModelServiceTest {
|
||||
|
|
|
@ -61,7 +61,23 @@ class CompanyServiceTest :
|
|||
|
||||
// delete()
|
||||
|
||||
override fun `delete() deletes in the repository`() {
|
||||
whenCanBeDeleted {
|
||||
super.`delete() deletes in the repository`()
|
||||
}
|
||||
}
|
||||
|
||||
// deleteById()
|
||||
|
||||
override fun `deleteById() deletes the entity with the given id in the repository`() {
|
||||
super.`deleteById() deletes the entity with the given id in the repository`()
|
||||
whenCanBeDeleted {
|
||||
super.`deleteById() deletes the entity with the given id in the repository`()
|
||||
}
|
||||
}
|
||||
|
||||
private fun whenCanBeDeleted(id: Long = any(), test: () -> Unit) {
|
||||
whenever(repository.canBeDeleted(id)).doReturn(true)
|
||||
|
||||
test()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -239,11 +239,27 @@ class MaterialServiceTest :
|
|||
|
||||
// delete()
|
||||
|
||||
override fun `delete() deletes in the repository`() {
|
||||
whenCanBeDeleted {
|
||||
super.`delete() deletes in the repository`()
|
||||
}
|
||||
}
|
||||
|
||||
// deleteById()
|
||||
|
||||
override fun `deleteById() deletes the entity with the given id in the repository`() {
|
||||
super.`deleteById() deletes the entity with the given id in the repository`()
|
||||
whenCanBeDeleted {
|
||||
super.`deleteById() deletes the entity with the given id in the repository`()
|
||||
}
|
||||
}
|
||||
|
||||
/** Utility property to check if the identifier of the given [Material] is even. */
|
||||
private val Material.evenId: Boolean
|
||||
get() = this.id!! % 2 == 0L
|
||||
|
||||
private fun whenCanBeDeleted(id: Long = any(), test: () -> Unit) {
|
||||
whenever(repository.canBeDeleted(id)).doReturn(true)
|
||||
|
||||
test()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,12 +164,21 @@ class MaterialTypeServiceTest :
|
|||
|
||||
// delete()
|
||||
|
||||
@Test
|
||||
fun `delete() calls delete() in the repository`() {
|
||||
doReturn(false).whenever(service).isUsedByMaterial(entity)
|
||||
override fun `delete() deletes in the repository`() {
|
||||
whenCanBeDeleted {
|
||||
super.`delete() deletes in the repository`()
|
||||
}
|
||||
}
|
||||
|
||||
service.delete(entity)
|
||||
override fun `deleteById() deletes the entity with the given id in the repository`() {
|
||||
whenCanBeDeleted {
|
||||
super.`deleteById() deletes the entity with the given id in the repository`()
|
||||
}
|
||||
}
|
||||
|
||||
verify(repository).delete(entity)
|
||||
private fun whenCanBeDeleted(id: Long = any(), test: () -> Unit) {
|
||||
whenever(repository.canBeDeleted(id)).doReturn(true)
|
||||
|
||||
test()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -215,10 +215,25 @@ class MixServiceTest : AbstractExternalModelServiceTest<Mix, MixSaveDto, MixUpda
|
|||
|
||||
// delete()
|
||||
|
||||
override fun `delete() deletes in the repository`() {
|
||||
whenCanBeDeleted {
|
||||
super.`delete() deletes in the repository`()
|
||||
}
|
||||
}
|
||||
|
||||
// deleteById()
|
||||
|
||||
@Test
|
||||
override fun `deleteById() deletes the entity with the given id in the repository`() {
|
||||
whenever(repository.canBeDeleted(entity.id!!)).doReturn(true)
|
||||
super.`deleteById() deletes the entity with the given id in the repository`()
|
||||
whenCanBeDeleted {
|
||||
super.`deleteById() deletes the entity with the given id in the repository`()
|
||||
}
|
||||
}
|
||||
|
||||
private fun whenCanBeDeleted(id: Long = any(), test: () -> Unit) {
|
||||
whenever(repository.canBeDeleted(id)).doReturn(true)
|
||||
|
||||
test()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -149,8 +149,23 @@ class MixTypeServiceTest : AbstractNamedModelServiceTest<MixType, MixTypeService
|
|||
|
||||
// delete()
|
||||
|
||||
override fun `delete() deletes in the repository`() {
|
||||
whenCanBeDeleted {
|
||||
super.`delete() deletes in the repository`()
|
||||
}
|
||||
}
|
||||
|
||||
// deleteById()
|
||||
|
||||
override fun `deleteById() deletes the entity with the given id in the repository`() {
|
||||
whenever(repository.canBeDeleted(any())).doReturn(true)
|
||||
super.`deleteById() deletes the entity with the given id in the repository`()
|
||||
whenCanBeDeleted {
|
||||
super.`deleteById() deletes the entity with the given id in the repository`()
|
||||
}
|
||||
}
|
||||
|
||||
private fun whenCanBeDeleted(id: Long = any(), test: () -> Unit) {
|
||||
whenever(repository.canBeDeleted(id)).doReturn(true)
|
||||
|
||||
test()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -196,12 +196,12 @@ class RecipeImageServiceTest {
|
|||
@Test
|
||||
fun `getByIdForRecipe() throws RecipeImageNotFoundException when no image with the given recipe and image id exists`() {
|
||||
doReturn(imagePath).whenever(service).getPath(imageId, recipeId)
|
||||
whenever(recipeService.getById(recipeId)).doReturn(recipe)
|
||||
whenever(fileService.readAsBytes(imagePath)).doAnswer { throw NoSuchFileException(imagePath) }
|
||||
|
||||
assertThrows<RecipeImageNotFoundException> { service.getByIdForRecipe(imageId, recipeId) }
|
||||
}
|
||||
|
||||
|
||||
// getAllIdsForRecipe()
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue