Merge branch 'bug-solving' into 'master'

Règle les bugs #49, #50 et #51

Closes #49, #50, and #51

See merge request color-recipes-explorer/backend!10
This commit is contained in:
William Nolin 2021-03-10 00:57:27 +00:00
commit 1f61ebdc5f
51 changed files with 312 additions and 118 deletions

View File

@ -1,22 +0,0 @@
package dev.fyloz.trial.colorrecipesexplorer.exception.model
import dev.fyloz.trial.colorrecipesexplorer.exception.RestException
import dev.fyloz.trial.colorrecipesexplorer.model.Model
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.ResponseStatus
class EntityNotFoundException(
modelType: Class<out Model>,
val identifierType: IdentifierType,
val requestedId: Any
) : ModelException(modelType)
@ResponseStatus(HttpStatus.NOT_FOUND)
class EntityNotFoundRestException(val value: Any) :
RestException("An entity could not be found with the given identifier", HttpStatus.NOT_FOUND) {
@Suppress("unused")
override fun buildBody(): RestExceptionBody = object : RestExceptionBody() {
val id = value
}
}

View File

@ -1,6 +1,6 @@
package dev.fyloz.trial.colorrecipesexplorer.service;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException;
import dev.fyloz.trial.colorrecipesexplorer.model.NamedModel;
import dev.fyloz.trial.colorrecipesexplorer.repository.NamedJpaRepository;

View File

@ -3,8 +3,8 @@ package dev.fyloz.trial.colorrecipesexplorer.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import dev.fyloz.trial.colorrecipesexplorer.config.Preferences;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.NullIdentifierException;
import dev.fyloz.trial.colorrecipesexplorer.model.Model;

View File

@ -1,6 +1,6 @@
package dev.fyloz.trial.colorrecipesexplorer.service.model;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityLinkedException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException;
import dev.fyloz.trial.colorrecipesexplorer.model.Company;

View File

@ -1,6 +1,6 @@
package dev.fyloz.trial.colorrecipesexplorer.service.model;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException;
import dev.fyloz.trial.colorrecipesexplorer.model.Material;
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialSaveDto;

View File

@ -2,8 +2,8 @@ package dev.fyloz.trial.colorrecipesexplorer.service.model;
import dev.fyloz.trial.colorrecipesexplorer.exception.CannotDeleteDefaultMaterialTypeException;
import dev.fyloz.trial.colorrecipesexplorer.exception.CannotEditDefaultMaterialTypeException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException;
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType;
import dev.fyloz.trial.colorrecipesexplorer.model.dto.MaterialTypeEditorDto;

View File

@ -1,6 +1,6 @@
package dev.fyloz.trial.colorrecipesexplorer.service.model;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException;
import dev.fyloz.trial.colorrecipesexplorer.model.*;
import dev.fyloz.trial.colorrecipesexplorer.model.dto.MixFormDto;

View File

@ -1,7 +1,7 @@
package dev.fyloz.trial.colorrecipesexplorer.service.model;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException;
import dev.fyloz.trial.colorrecipesexplorer.model.Material;
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType;

View File

@ -1,6 +1,6 @@
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;
import dev.fyloz.trial.colorrecipesexplorer.service.files.MarkdownFilesService;

View File

@ -1,6 +1,6 @@
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.model.Recipe;
import dev.fyloz.trial.colorrecipesexplorer.web.response.JSONResponseBuilder;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;

View File

@ -1,6 +1,6 @@
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.creators;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.model.Company;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;

View File

@ -1,7 +1,7 @@
//package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.creators;
//
//import dev.fyloz.trial.colorrecipesexplorer.exception.SimdutException;
//import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
//import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException;
//import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
//import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;
//import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseDataType;

View File

@ -1,7 +1,7 @@
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.creators
import dev.fyloz.trial.colorrecipesexplorer.exception.SimdutException
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode
import dev.fyloz.trial.colorrecipesexplorer.model.Material
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialSaveDto

View File

@ -1,6 +1,6 @@
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.creators;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;

View File

@ -1,7 +1,7 @@
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.creators;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.model.MixKt;
import dev.fyloz.trial.colorrecipesexplorer.model.MixTypeKt;
import dev.fyloz.trial.colorrecipesexplorer.model.Recipe;

View File

@ -1,8 +1,8 @@
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.editors;
import dev.fyloz.trial.colorrecipesexplorer.exception.SimdutException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseDataType;

View File

@ -1,8 +1,8 @@
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.editors;
import dev.fyloz.trial.colorrecipesexplorer.exception.CannotEditDefaultMaterialTypeException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;

View File

@ -1,7 +1,7 @@
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.editors;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.model.Mix;
import dev.fyloz.trial.colorrecipesexplorer.model.MixKt;
import dev.fyloz.trial.colorrecipesexplorer.model.MixTypeKt;

View File

@ -1,6 +1,6 @@
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.editors;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.model.Recipe;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;

View File

@ -1,6 +1,6 @@
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.files;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.model.Recipe;
import dev.fyloz.trial.colorrecipesexplorer.web.response.JSONResponseBuilder;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;

View File

@ -1,6 +1,6 @@
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.files;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.service.files.SimdutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;

View File

@ -1,6 +1,6 @@
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.files;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.service.files.XlsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;

View File

@ -1,7 +1,7 @@
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.removers;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityLinkedException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.model.Company;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;

View File

@ -1,7 +1,7 @@
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.removers;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityLinkedException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseDataType;

View File

@ -2,7 +2,7 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.removers;
import dev.fyloz.trial.colorrecipesexplorer.exception.CannotDeleteDefaultMaterialTypeException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityLinkedException;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseDataType;

View File

@ -1,6 +1,6 @@
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.removers;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.model.Mix;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;

View File

@ -1,6 +1,6 @@
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.removers;
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException;
import dev.fyloz.trial.colorrecipesexplorer.model.Recipe;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;

View File

@ -1,7 +1,7 @@
package dev.fyloz.trial.colorrecipesexplorer.config
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.model.Employee
import dev.fyloz.trial.colorrecipesexplorer.model.EmployeeLoginRequest
import dev.fyloz.trial.colorrecipesexplorer.model.EmployeePermission

View File

@ -1,9 +1,7 @@
package dev.fyloz.trial.colorrecipesexplorer.exception.model
package dev.fyloz.trial.colorrecipesexplorer.exception
import dev.fyloz.trial.colorrecipesexplorer.exception.RestException
import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException
import dev.fyloz.trial.colorrecipesexplorer.model.Model
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.ResponseStatus
class EntityAlreadyExistsException(
modelType: Class<out Model>,
@ -26,12 +24,8 @@ class EntityAlreadyExistsException(
)
}
@ResponseStatus(HttpStatus.CONFLICT)
class EntityAlreadyExistsRestException(val value: Any) :
RestException("An entity with the given identifier already exists", HttpStatus.CONFLICT) {
@Suppress("unused")
override fun buildBody(): RestExceptionBody = object : RestExceptionBody() {
val id = value
}
}
class EntityNotFoundException(
modelType: Class<out Model>,
val identifierType: IdentifierType,
val requestedId: Any
) : ModelException(modelType)

View File

@ -2,6 +2,7 @@ package dev.fyloz.trial.colorrecipesexplorer.exception
import com.fasterxml.jackson.annotation.JsonProperty
import dev.fyloz.trial.colorrecipesexplorer.exception.model.*
import dev.fyloz.trial.colorrecipesexplorer.model.Model
import org.springframework.context.annotation.Profile
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpStatus
@ -10,15 +11,51 @@ import org.springframework.validation.FieldError
import org.springframework.web.bind.MethodArgumentNotValidException
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.context.request.WebRequest
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
abstract class RestException(val exceptionMessage: String, val httpStatus: HttpStatus) : RuntimeException(exceptionMessage) {
abstract class RestException(val exceptionMessage: String, val httpStatus: HttpStatus) :
RuntimeException(exceptionMessage) {
abstract fun buildBody(): RestExceptionBody
open inner class RestExceptionBody(val status: Int = httpStatus.value(), @JsonProperty("message") val message: String = exceptionMessage)
open inner class RestExceptionBody(
val status: Int = httpStatus.value(),
@JsonProperty("message") val message: String = exceptionMessage
)
}
@ResponseStatus(HttpStatus.CONFLICT)
class EntityAlreadyExistsRestException(val value: Any) :
RestException("An entity with the given identifier already exists", HttpStatus.CONFLICT) {
@Suppress("unused")
override fun buildBody(): RestExceptionBody = object : RestExceptionBody() {
val id = value
}
}
@ResponseStatus(HttpStatus.NOT_FOUND)
class EntityNotFoundRestException(val value: Any) :
RestException("An entity could not be found with the given identifier", HttpStatus.NOT_FOUND) {
@Suppress("unused")
override fun buildBody(): RestExceptionBody = object : RestExceptionBody() {
val id = value
}
}
@ResponseStatus(HttpStatus.CONFLICT)
class CannotDeleteEntityRestException(val value: Long) :
RestException(
"The entity with the given identifier could not be deleted because it is required by other entities",
HttpStatus.CONFLICT
) {
@Suppress("unused")
override fun buildBody(): RestExceptionBody = object : RestExceptionBody() {
val id = value
}
}
@ControllerAdvice
@Profile("rest")
class RestResponseEntityExceptionHandler : ResponseEntityExceptionHandler() {
@ -32,7 +69,12 @@ class RestResponseEntityExceptionHandler : ResponseEntityExceptionHandler() {
return handleExceptionInternal(exception, exception.buildBody(), HttpHeaders(), exception.httpStatus, request)
}
override fun handleMethodArgumentNotValid(ex: MethodArgumentNotValidException, headers: HttpHeaders, status: HttpStatus, request: WebRequest): ResponseEntity<Any> {
override fun handleMethodArgumentNotValid(
ex: MethodArgumentNotValidException,
headers: HttpHeaders,
status: HttpStatus,
request: WebRequest
): ResponseEntity<Any> {
val errors = hashMapOf<String, String>()
ex.bindingResult.allErrors.forEach {
val fieldName = (it as FieldError).field

View File

@ -1,7 +1,18 @@
package dev.fyloz.trial.colorrecipesexplorer.repository
import dev.fyloz.trial.colorrecipesexplorer.model.Company
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository
@Repository
interface CompanyRepository : NamedJpaRepository<Company>
interface CompanyRepository : NamedJpaRepository<Company> {
@Query(
"""
select case when(count(r.id) > 0) then false else true end
from Company c
left join Recipe r on c.id = r.company.id
where c.id = :id
"""
)
fun canBeDeleted(id: Long): Boolean
}

View File

@ -2,6 +2,7 @@ package dev.fyloz.trial.colorrecipesexplorer.repository
import dev.fyloz.trial.colorrecipesexplorer.model.Material
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository
@Repository
@ -11,4 +12,15 @@ interface MaterialRepository : NamedJpaRepository<Material> {
/** Gets all the materials with the given [materialType]. */
fun findAllByMaterialType(materialType: MaterialType): Collection<Material>
@Query(
"""
select case when(count(mm.id) + count(mt.id) > 0) then false else true end
from Material m
left join MixMaterial mm on m.id = mm.material.id
left join MixType mt on m.id = mt.material.id
where m.id = :id
"""
)
fun canBeDeleted(id: Long): Boolean
}

View File

@ -1,6 +1,7 @@
package dev.fyloz.trial.colorrecipesexplorer.repository
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository
@Repository
@ -13,4 +14,14 @@ interface MaterialTypeRepository : NamedJpaRepository<MaterialType> {
/** Gets the material type with the given [prefix]. */
fun findByPrefix(prefix: String): MaterialType?
@Query(
"""
select case when(count(m.id) > 0) then false else true end
from MaterialType t
left join Material m on t.id = m.materialType.id
where t.id = :id
"""
)
fun canBeDeleted(id: Long): Boolean
}

View File

@ -3,8 +3,19 @@ package dev.fyloz.trial.colorrecipesexplorer.repository
import dev.fyloz.trial.colorrecipesexplorer.model.Mix
import dev.fyloz.trial.colorrecipesexplorer.model.MixType
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
interface MixRepository : JpaRepository<Mix, Long> {
/** Finds all mixes with the given [mixType]. */
fun findAllByMixType(mixType: MixType): Collection<Mix>
@Query(
"""
select case when(count(mm.id) > 0) then false else true end
from Mix m
left join MixMaterial mm on m.mixType.material.id = mm.material.id
where m.id = :id
"""
)
fun canBeDeleted(id: Long): Boolean
}

View File

@ -1,11 +1,30 @@
package dev.fyloz.trial.colorrecipesexplorer.repository
import dev.fyloz.trial.colorrecipesexplorer.model.Material
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType
import dev.fyloz.trial.colorrecipesexplorer.model.MixType
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository
@Repository
interface MixTypeRepository : NamedJpaRepository<MixType> {
@Query("select case when(count(m) > 0) then true else false end from MixType m where m.name = :name and m.material.materialType = :materialType")
fun existsByNameAndMaterialType(name: String, materialType: MaterialType): Boolean
/** Gets the mix type with the given [material]. */
fun findByMaterial(material: Material): MixType?
/** Gets the [MixType] with the given [name] and [materialType]. */
@Query("select m from MixType m where m.name = :name and m.material.materialType = :materialType")
fun findByNameAndMaterialType(name: String, materialType: MaterialType): MixType?
@Query(
"""
select case when(count(m.id) > 0) then false else true end
from MixType t
left join Mix m on t.id = m.mixType.id
where t.id = :id
"""
)
fun canBeDeleted(id: Long): Boolean
}

View File

@ -2,9 +2,9 @@ package dev.fyloz.trial.colorrecipesexplorer.service
import dev.fyloz.trial.colorrecipesexplorer.config.blacklistedJwtTokens
import dev.fyloz.trial.colorrecipesexplorer.config.defaultGroupCookieName
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.model.*
import dev.fyloz.trial.colorrecipesexplorer.model.validation.or
import dev.fyloz.trial.colorrecipesexplorer.repository.EmployeeGroupRepository

View File

@ -1,5 +1,6 @@
package dev.fyloz.trial.colorrecipesexplorer.service
import dev.fyloz.trial.colorrecipesexplorer.exception.CannotDeleteEntityRestException
import dev.fyloz.trial.colorrecipesexplorer.model.Company
import dev.fyloz.trial.colorrecipesexplorer.model.CompanySaveDto
import dev.fyloz.trial.colorrecipesexplorer.model.CompanyUpdateDto
@ -30,4 +31,9 @@ class CompanyServiceImpl(companyRepository: CompanyRepository, val recipeService
)
})
}
override fun deleteById(id: Long) {
if (!repository.canBeDeleted(id)) throw CannotDeleteEntityRestException(id)
super.deleteById(id)
}
}

View File

@ -1,5 +1,6 @@
package dev.fyloz.trial.colorrecipesexplorer.service
import dev.fyloz.trial.colorrecipesexplorer.exception.CannotDeleteEntityRestException
import dev.fyloz.trial.colorrecipesexplorer.model.*
import dev.fyloz.trial.colorrecipesexplorer.repository.MaterialRepository
import dev.fyloz.trial.colorrecipesexplorer.service.files.SimdutService
@ -90,4 +91,9 @@ class MaterialServiceImpl(
private fun assertPersistedMaterial(material: Material) {
Assert.notNull(material.name, "The persisted material with the id ${material.id} has a null name")
}
override fun deleteById(id: Long) {
if (!repository.canBeDeleted(id)) throw CannotDeleteEntityRestException(id)
super.deleteById(id)
}
}

View File

@ -1,8 +1,9 @@
package dev.fyloz.trial.colorrecipesexplorer.service
import dev.fyloz.trial.colorrecipesexplorer.config.properties.MaterialTypeProperties
import dev.fyloz.trial.colorrecipesexplorer.exception.CannotDeleteEntityRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.RestException
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsRestException
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialTypeSaveDto
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialTypeUpdateDto
@ -73,11 +74,9 @@ class MaterialTypeServiceImpl(repository: MaterialTypeRepository, private val ma
return super<AbstractExternalNamedModelService>.update(entity)
}
override fun delete(entity: MaterialType) {
if (isUsedByMaterial(entity))
throw CannotDeleteUsedMaterialTypeRestException()
super.delete(entity)
override fun deleteById(id: Long) {
if (!repository.canBeDeleted(id)) throw CannotDeleteEntityRestException(id)
super.deleteById(id)
}
override fun saveSystemTypes(systemTypeProperties: Collection<MaterialTypeProperties.MaterialTypeProperty>) {

View File

@ -1,5 +1,6 @@
package dev.fyloz.trial.colorrecipesexplorer.service
import dev.fyloz.trial.colorrecipesexplorer.exception.CannotDeleteEntityRestException
import dev.fyloz.trial.colorrecipesexplorer.model.*
import dev.fyloz.trial.colorrecipesexplorer.repository.MixRepository
import org.springframework.context.annotation.Lazy
@ -33,7 +34,7 @@ class MixServiceImpl(
override fun save(entity: MixSaveDto): Mix {
val recipe = recipeService.getById(entity.recipeId)
val materialType = materialTypeService.getById(entity.materialTypeId)
val mixType = mixTypeService.createForNameAndMaterialType(entity.name, materialType)
val mixType = mixTypeService.getOrCreateForNameAndMaterialType(entity.name, materialType)
var mix = save(mix(recipe = recipe, mixType = mixType))
val mixMaterials =
@ -83,7 +84,7 @@ class MixServiceImpl(
val mix = getById(entity.id)
if (entity.name != null || entity.materialTypeId != null) {
mix.mixType = if (mixTypeIsShared(mix.mixType)) {
mixTypeService.createForNameAndMaterialType(
mixTypeService.saveForNameAndMaterialType(
entity.name ?: mix.mixType.name,
if (entity.materialTypeId != null) materialTypeService.getById(entity.materialTypeId) else mix.mixType.material.materialType!!
)
@ -110,4 +111,9 @@ class MixServiceImpl(
recipeService.removeMix(entity)
super.delete(entity)
}
override fun deleteById(id: Long) {
if (!repository.canBeDeleted(id)) throw CannotDeleteEntityRestException(id)
super.deleteById(id)
}
}

View File

@ -1,18 +1,28 @@
package dev.fyloz.trial.colorrecipesexplorer.service
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.CannotDeleteEntityRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.model.*
import dev.fyloz.trial.colorrecipesexplorer.repository.MixTypeRepository
import org.springframework.context.annotation.Lazy
import org.springframework.stereotype.Service
interface MixTypeService : NamedModelService<MixType, MixTypeRepository> {
/** Checks if a [MixType] with the given [name] and [materialType] exists. */
fun existsByNameAndMaterialType(name: String, materialType: MaterialType): Boolean
/** Gets the mix type with the given [material]. */
fun getByMaterial(material: Material): MixType
/** Gets the [MixType] with the given [name] and [materialType]. */
fun getByNameAndMaterialType(name: String, materialType: MaterialType): MixType
/** Returns a [MixType] for the given [name] and [materialType]. If a mix type with these does not already exists, it will be created. */
fun getOrCreateForNameAndMaterialType(name: String, materialType: MaterialType): MixType
/** Returns a new and persisted [MixType] with the given [name] and [materialType]. */
fun createForNameAndMaterialType(name: String, materialType: MaterialType): MixType
fun saveForNameAndMaterialType(name: String, materialType: MaterialType): MixType
/** Returns the given [mixType] updated with the given [name] and [materialType]. */
fun updateForNameAndMaterialType(mixType: MixType, name: String, materialType: MaterialType): MixType
@ -25,16 +35,29 @@ class MixTypeServiceImpl(
@Lazy val mixService: MixService
) :
AbstractNamedModelService<MixType, MixTypeRepository>(mixTypeRepository), MixTypeService {
override fun existsByNameAndMaterialType(name: String, materialType: MaterialType): Boolean =
repository.existsByNameAndMaterialType(name, materialType)
override fun getByMaterial(material: Material): MixType =
repository.findByMaterial(material) ?: throw EntityNotFoundRestException(material.name)
override fun getByNameAndMaterialType(name: String, materialType: MaterialType): MixType =
repository.findByNameAndMaterialType(name, materialType)
?: throw EntityNotFoundRestException("$name/${materialType.name}")
override fun getOrCreateForNameAndMaterialType(name: String, materialType: MaterialType): MixType =
if (existsByNameAndMaterialType(name, materialType))
getByNameAndMaterialType(name, materialType)
else
saveForNameAndMaterialType(name, materialType)
override fun save(entity: MixType): MixType {
if (materialService.existsByName(entity.name))
throw EntityAlreadyExistsRestException(entity.name)
return super.save(entity)
}
override fun createForNameAndMaterialType(name: String, materialType: MaterialType): MixType =
override fun saveForNameAndMaterialType(name: String, materialType: MaterialType): MixType =
save(
mixType(
name = name,
@ -53,4 +76,9 @@ class MixTypeServiceImpl(
material.name = name
material.materialType = materialType
})
override fun deleteById(id: Long) {
if (!repository.canBeDeleted(id)) throw CannotDeleteEntityRestException(id)
super.deleteById(id)
}
}

View File

@ -1,6 +1,6 @@
package dev.fyloz.trial.colorrecipesexplorer.service
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.model.*
import dev.fyloz.trial.colorrecipesexplorer.model.validation.isNotNullAndNotBlank
import dev.fyloz.trial.colorrecipesexplorer.model.validation.or

View File

@ -1,8 +1,8 @@
package dev.fyloz.trial.colorrecipesexplorer.service
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.model.EntityDto
import dev.fyloz.trial.colorrecipesexplorer.model.Model
import dev.fyloz.trial.colorrecipesexplorer.model.NamedModel

View File

@ -1,8 +1,8 @@
package dev.fyloz.trial.colorrecipesexplorer.service
import com.nhaarman.mockitokotlin2.*
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.model.EntityDto
import dev.fyloz.trial.colorrecipesexplorer.model.Model
import dev.fyloz.trial.colorrecipesexplorer.model.NamedModel

View File

@ -2,8 +2,8 @@ package dev.fyloz.trial.colorrecipesexplorer.service
import com.nhaarman.mockitokotlin2.*
import dev.fyloz.trial.colorrecipesexplorer.config.defaultGroupCookieName
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.model.*
import dev.fyloz.trial.colorrecipesexplorer.repository.EmployeeGroupRepository
import dev.fyloz.trial.colorrecipesexplorer.repository.EmployeeRepository

View File

@ -52,4 +52,10 @@ class CompanyServiceTest :
override fun `update(dto) calls and returns update() with the created entity`() =
withBaseUpdateDtoTest(entity, entityUpdateDto, service, any())
// delete()
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`()
}
}

View File

@ -1,12 +1,11 @@
package dev.fyloz.trial.colorrecipesexplorer.service
import com.nhaarman.mockitokotlin2.*
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsRestException
import dev.fyloz.trial.colorrecipesexplorer.model.*
import dev.fyloz.trial.colorrecipesexplorer.repository.MaterialRepository
import dev.fyloz.trial.colorrecipesexplorer.service.files.SimdutService
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.springframework.mock.web.MockMultipartFile
@ -191,6 +190,12 @@ class MaterialServiceTest :
verify(simdutService).update(eq(mockSimdutFile), any())
}
// delete()
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`()
}
/** Helper function to replace collections.in because the id is not considered in the equals function of Material while Thymeleaf is supported. */
private infix fun Collection<Material>.contains(material: Material): Boolean =
any { it.id == material.id }

View File

@ -1,12 +1,11 @@
package dev.fyloz.trial.colorrecipesexplorer.service
import com.nhaarman.mockitokotlin2.*
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.model.*
import dev.fyloz.trial.colorrecipesexplorer.repository.MaterialTypeRepository
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import kotlin.test.assertEquals
@ -167,10 +166,7 @@ class MaterialTypeServiceTest :
verify(repository).delete(entity)
}
@Test
fun `delete() throws CannotDeleteUsedMaterialTypeRestException when the material type is in use`() {
doReturn(true).whenever(service).isUsedByMaterial(entity)
assertThrows<CannotDeleteUsedMaterialTypeRestException> { service.delete(entity) }
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`()
}
}

View File

@ -36,6 +36,7 @@ class MixServiceTest : AbstractExternalModelServiceTest<Mix, MixSaveDto, MixUpda
// save()
@Test
override fun `save(dto) calls and returns save() with the created entity`() {
val recipe = recipe(id = entitySaveDto.recipeId)
val materialType = materialType(id = entitySaveDto.materialTypeId)
@ -54,7 +55,7 @@ class MixServiceTest : AbstractExternalModelServiceTest<Mix, MixSaveDto, MixUpda
whenever(recipeService.getById(recipe.id!!)).doReturn(recipe)
whenever(materialTypeService.getById(materialType.id!!)).doReturn(materialType)
whenever(mixMaterialService.createFromMap(mixWithId, entitySaveDto.mixMaterials!!)).doReturn(mixMaterials)
whenever(mixTypeService.createForNameAndMaterialType(mixType.name, mixType.material.materialType!!)).doReturn(
whenever(mixTypeService.getOrCreateForNameAndMaterialType(mixType.name, mixType.material.materialType!!)).doReturn(
mixType
)
doReturn(true).whenever(service).existsById(mixWithId.id!!)
@ -68,7 +69,7 @@ class MixServiceTest : AbstractExternalModelServiceTest<Mix, MixSaveDto, MixUpda
verify(recipeService).addMix(recipe, mix)
// Verify if this method is called instead of the MixType's constructor, which does not check if the name is already taken by a material.
verify(mixTypeService).createForNameAndMaterialType(mixType.name, mixType.material.materialType!!)
verify(mixTypeService).getOrCreateForNameAndMaterialType(mixType.name, mixType.material.materialType!!)
assertEquals(mixWithMaterials, found)
}
@ -115,14 +116,14 @@ class MixServiceTest : AbstractExternalModelServiceTest<Mix, MixSaveDto, MixUpda
}
@Test
fun `update(dto) calls MixTypeService createForNameAndMaterialType() when mix type is shared`() {
fun `update(dto) calls MixTypeService saveForNameAndMaterialType() when mix type is shared`() {
mixUpdateDtoMixTypeTest(sharedMixType = true) {
whenever(mixTypeService.createForNameAndMaterialType(mixUpdateDto.name!!, materialType))
whenever(mixTypeService.saveForNameAndMaterialType(mixUpdateDto.name!!, materialType))
.doReturn(newMixType)
val found = service.update(mixUpdateDto)
verify(mixTypeService).createForNameAndMaterialType(mixUpdateDto.name!!, materialType)
verify(mixTypeService).saveForNameAndMaterialType(mixUpdateDto.name!!, materialType)
assertEquals(newMixType, found.mixType)
}
@ -191,6 +192,12 @@ class MixServiceTest : AbstractExternalModelServiceTest<Mix, MixSaveDto, MixUpda
verify(service).update(expected)
}
// delete()
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`()
}
}
data class MixUpdateDtoTestScope(

View File

@ -1,15 +1,15 @@
package dev.fyloz.trial.colorrecipesexplorer.service
import com.nhaarman.mockitokotlin2.*
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.model.*
import dev.fyloz.trial.colorrecipesexplorer.repository.MixTypeRepository
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class MixTypeServiceTest : AbstractNamedModelServiceTest<MixType, MixTypeService, MixTypeRepository>() {
@ -18,7 +18,8 @@ class MixTypeServiceTest : AbstractNamedModelServiceTest<MixType, MixTypeService
private val mixService: MixService = mock()
override val service: MixTypeService = spy(MixTypeServiceImpl(repository, materialService, mixService))
private val material: Material = material(id = 0L)
private val materialType: MaterialType = materialType()
private val material: Material = material(id = 0L, materialType = materialType)
override val entity: MixType = mixType(id = 0L, name = "mix type", material = material)
override val anotherEntity: MixType = mixType(id = 1L, name = "another mix type")
override val entityWithEntityName: MixType = mixType(id = 2L, name = entity.name)
@ -29,6 +30,19 @@ class MixTypeServiceTest : AbstractNamedModelServiceTest<MixType, MixTypeService
super.afterEach()
}
// existsByNameAndMaterialType
@Test
fun `existsByNameAndMaterialType() returns repository's answer`() {
setOf(true, false).forEach {
whenever(repository.existsByNameAndMaterialType(entity.name, materialType)).doReturn(it)
val found = service.existsByNameAndMaterialType(entity.name, materialType)
assertTrue { found == it }
}
}
// getByMaterial()
@Test
@ -48,6 +62,42 @@ class MixTypeServiceTest : AbstractNamedModelServiceTest<MixType, MixTypeService
assertEquals(material.name, exception.value)
}
// getByNameAndMaterialType()
@Test
fun `getByNameAndMaterialType() returns the mix type with the given name and material type`() {
whenever(repository.findByNameAndMaterialType(entity.name, materialType)).doReturn(entity)
val found = service.getByNameAndMaterialType(entity.name, materialType)
assertEquals(entity, found)
}
// getOrCreateForNameAndMaterialType()
@Test
fun `getOrCreateForNameAndMaterialType() calls getForNameAndMaterialType() when a mix type with the given name and material type exists`() {
doReturn(true).whenever(service).existsByNameAndMaterialType(entity.name, materialType)
doReturn(entity).whenever(service).getByNameAndMaterialType(entity.name, materialType)
val found = service.getOrCreateForNameAndMaterialType(entity.name, materialType)
verify(service).getByNameAndMaterialType(entity.name, materialType)
assertEquals(entity, found)
}
@Test
fun `getOrCreateForNameAndMaterialType() calls saveForNameAndMaterialType() when no mix type with the given name and material type exists`() {
doReturn(false).whenever(service).existsByNameAndMaterialType(entity.name, materialType)
doReturn(entity).whenever(service).saveForNameAndMaterialType(entity.name, materialType)
val found = service.getOrCreateForNameAndMaterialType(entity.name, materialType)
verify(service).saveForNameAndMaterialType(entity.name, materialType)
assertEquals(entity, found)
}
// save()
@Test
@ -58,16 +108,16 @@ class MixTypeServiceTest : AbstractNamedModelServiceTest<MixType, MixTypeService
assertEquals(entity.name, exception.value)
}
// createForNameAndMaterialType()
// saveForNameAndMaterialType()
@Test
fun `createForNameAndMaterialType() creates a save a valid mix type with the given name and material type`() {
fun `saveForNameAndMaterialType() creates a save a valid mix type with the given name and material type`() {
val name = entity.name
val materialType = materialType()
doAnswer { it.arguments[0] }.whenever(service).save(any())
val found = service.createForNameAndMaterialType(name, materialType)
val found = service.saveForNameAndMaterialType(name, materialType)
verify(service).save(any())
@ -97,4 +147,11 @@ class MixTypeServiceTest : AbstractNamedModelServiceTest<MixType, MixTypeService
assertEquals(materialType, found.material.materialType)
assertTrue(found.material.isMixType)
}
// delete()
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`()
}
}

View File

@ -1,7 +1,7 @@
package dev.fyloz.trial.colorrecipesexplorer.service
import com.nhaarman.mockitokotlin2.*
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.model.*
import dev.fyloz.trial.colorrecipesexplorer.repository.RecipeRepository
import dev.fyloz.trial.colorrecipesexplorer.service.files.FilesService