`MixService.save(MixSaveDto)` utilise maintenant le méthode MixTypeService.createForNameAndMaterialType(String, MaterialType)
La méthode utilisait directement le constructeur de MixType, qui ne vérifie pas les conflits de nom avec les Materials existants, d'où l'erreur de contrainte unique. Le test de la méthode est ajuster pour vérifier l'utilisation de la méthode adéquate.
This commit is contained in:
parent
aff519537f
commit
04ce615eb4
|
@ -26,7 +26,7 @@ data class Mix(
|
|||
@ManyToOne
|
||||
val recipe: Recipe,
|
||||
|
||||
@ManyToOne(cascade = [CascadeType.PERSIST])
|
||||
@ManyToOne
|
||||
var mixType: MixType,
|
||||
|
||||
@OneToMany(cascade = [CascadeType.ALL])
|
||||
|
|
|
@ -33,7 +33,7 @@ class MixServiceImpl(
|
|||
override fun save(entity: MixSaveDto): Mix {
|
||||
val recipe = recipeService.getById(entity.recipeId)
|
||||
val materialType = materialTypeService.getById(entity.materialTypeId)
|
||||
val mixType = MixType(entity.name, materialType)
|
||||
val mixType = mixTypeService.createForNameAndMaterialType(entity.name, materialType)
|
||||
|
||||
var mix = save(mix(recipe = recipe, mixType = mixType))
|
||||
val mixMaterials =
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#spring.datasource.url=jdbc:h2:mem:cre
|
||||
spring.datasource.url=jdbc:h2:file:./workdir/recipes
|
||||
spring.datasource.url=jdbc:h2:mem:cre
|
||||
#spring.datasource.url=jdbc:h2:file:./workdir/recipes
|
||||
spring.datasource.username=sa
|
||||
spring.datasource.password=LWK4Y7TvEbNyhu1yCoG3
|
||||
spring.h2.console.path=/dbconsole
|
||||
|
|
|
@ -56,6 +56,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(mixType)
|
||||
doReturn(true).whenever(service).existsById(mixWithId.id!!)
|
||||
doReturn(mixWithId).whenever(service).save(mix)
|
||||
doReturn(mixWithMaterials).whenever(service).update(mixWithMaterials)
|
||||
|
@ -66,6 +67,9 @@ class MixServiceTest : AbstractExternalModelServiceTest<Mix, MixSaveDto, MixUpda
|
|||
verify(service).update(mixWithMaterials)
|
||||
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!!))
|
||||
|
||||
assertEquals(mixWithMaterials, found)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue