Transition des beans depuis les constructeurs des services vers des setters pour faciliter les tests
This commit is contained in:
parent
43ae9f1222
commit
2ba8d7ccb8
32
pom.xml
32
pom.xml
|
@ -36,11 +36,6 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
|
@ -56,10 +51,6 @@
|
|||
<artifactId>pdfbox</artifactId>
|
||||
<version>2.0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
|
@ -85,7 +76,28 @@
|
|||
<artifactId>commons-io</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<version>2.1.6.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-test-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -10,8 +10,9 @@ import java.io.Serializable;
|
|||
@Entity
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@RequiredArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Company implements IModel {
|
||||
|
||||
@Id
|
||||
|
|
|
@ -2,7 +2,6 @@ package dev.fyloz.trial.colorrecipesexplorer.core.services;
|
|||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.ColorRecipesExplorerApplication;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.Preferences;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityNotFoundException;
|
||||
|
@ -20,14 +19,13 @@ import java.util.List;
|
|||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GenericService<T extends IModel, R extends JpaRepository<T, Long>> implements IGenericService<T> {
|
||||
public abstract class AbstractService<T extends IModel, R extends JpaRepository<T, Long>> implements IGenericService<T> {
|
||||
|
||||
protected Logger logger = Preferences.logger;
|
||||
protected R dao;
|
||||
protected Class<T> type;
|
||||
|
||||
public GenericService(R dao, Class<T> type) {
|
||||
this.dao = dao;
|
||||
public AbstractService(Class<T> type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import dev.fyloz.trial.colorrecipesexplorer.core.exception.TooLowQuantityExcepti
|
|||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.InventoryDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MaterialService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -15,7 +16,8 @@ public class InventoryService {
|
|||
|
||||
private MaterialService materialService;
|
||||
|
||||
public InventoryService(MaterialService materialService) {
|
||||
@Autowired
|
||||
public void setMaterialService(MaterialService materialService) {
|
||||
this.materialService = materialService;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityAlreadyEx
|
|||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityLinkedException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Company;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.GenericService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.AbstractService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.dao.CompanyDao;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
|
@ -13,13 +13,17 @@ import org.springframework.stereotype.Service;
|
|||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Service
|
||||
public class CompanyService extends GenericService<Company, CompanyDao> {
|
||||
public class CompanyService extends AbstractService<Company, CompanyDao> {
|
||||
|
||||
private RecipeService recipeService;
|
||||
|
||||
public CompanyService() {
|
||||
super(Company.class);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public CompanyService(CompanyDao companyDao) {
|
||||
super(companyDao, Company.class);
|
||||
public void setCompanyDao(CompanyDao companyDao) {
|
||||
this.dao = companyDao;
|
||||
}
|
||||
|
||||
// Pour éviter les dépendances circulaires
|
||||
|
|
|
@ -5,7 +5,7 @@ import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityNotFoundE
|
|||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MaterialType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.GenericService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.AbstractService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.files.SimdutService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.dao.MaterialDao;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -19,15 +19,27 @@ import java.util.Optional;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class MaterialService extends GenericService<Material, MaterialDao> {
|
||||
public class MaterialService extends AbstractService<Material, MaterialDao> {
|
||||
|
||||
private MixQuantityService mixQuantityService;
|
||||
private SimdutService simdutService;
|
||||
|
||||
public MaterialService() {
|
||||
super(Material.class);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public MaterialService(MaterialDao materialDao, MixQuantityService mixQuantityService, SimdutService simdutService) {
|
||||
super(materialDao, Material.class);
|
||||
public void setMaterialDao(MaterialDao materialDao) {
|
||||
this.dao = materialDao;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setMixQuantityService(MixQuantityService mixQuantityService) {
|
||||
this.mixQuantityService = mixQuantityService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setSimdutService(SimdutService simdutService) {
|
||||
this.simdutService = simdutService;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,27 +7,33 @@ import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityNotFoundE
|
|||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MaterialType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.MaterialTypeEditorDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.GenericService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.AbstractService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.dao.MaterialTypeDao;
|
||||
import org.commonmark.node.Link;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class MaterialTypeService extends GenericService<MaterialType, MaterialTypeDao> {
|
||||
public class MaterialTypeService extends AbstractService<MaterialType, MaterialTypeDao> {
|
||||
|
||||
private MaterialService materialService;
|
||||
|
||||
private List<MaterialType> defaultMaterialTypes = new LinkedList<>();
|
||||
|
||||
public MaterialTypeService() {
|
||||
super(MaterialType.class);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public MaterialTypeService(MaterialTypeDao materialTypeDao, MaterialService materialService) {
|
||||
super(materialTypeDao, MaterialType.class);
|
||||
public void setMaterialTypeDao(MaterialTypeDao materialTypeDao) {
|
||||
this.dao = materialTypeDao;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setMaterialService(MaterialService materialService) {
|
||||
this.materialService = materialService;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,17 +2,21 @@ package dev.fyloz.trial.colorrecipesexplorer.core.services.model;
|
|||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MixQuantity;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.GenericService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.AbstractService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.dao.MixQuantityDao;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class MixQuantityService extends GenericService<MixQuantity, MixQuantityDao> {
|
||||
public class MixQuantityService extends AbstractService<MixQuantity, MixQuantityDao> {
|
||||
|
||||
public MixQuantityService() {
|
||||
super(MixQuantity.class);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public MixQuantityService(MixQuantityDao mixQuantityDao) {
|
||||
super(mixQuantityDao, MixQuantity.class);
|
||||
public void setMixQuantityDao(MixQuantityDao mixQuantityDao) {
|
||||
this.dao = mixQuantityDao;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,7 +7,7 @@ import dev.fyloz.trial.colorrecipesexplorer.core.model.Mix;
|
|||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MixType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.MixFormDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.GenericService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.AbstractService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.utils.MixBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.dao.MixDao;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -19,17 +19,33 @@ import java.util.Comparator;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class MixService extends GenericService<Mix, MixDao> {
|
||||
public class MixService extends AbstractService<Mix, MixDao> {
|
||||
|
||||
private MaterialService materialService;
|
||||
private MixQuantityService mixQuantityService;
|
||||
private MixTypeService mixTypeService;
|
||||
|
||||
public MixService() {
|
||||
super(Mix.class);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public MixService(MixDao mixDao, MaterialService materialService, MixQuantityService mixQuantityService, MixTypeService mixTypeService) {
|
||||
super(mixDao, Mix.class);
|
||||
public void setMixDao(MixDao mixDao) {
|
||||
this.dao = mixDao;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setMaterialService(MaterialService materialService) {
|
||||
this.materialService = materialService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setMixQuantityService(MixQuantityService mixQuantityService) {
|
||||
this.mixQuantityService = mixQuantityService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setMixTypeService(MixTypeService mixTypeService) {
|
||||
this.mixTypeService = mixTypeService;
|
||||
}
|
||||
|
||||
|
@ -47,7 +63,8 @@ public class MixService extends GenericService<Mix, MixDao> {
|
|||
|
||||
/**
|
||||
* Récupère les produits disponibles pour un mélange existant.
|
||||
*`
|
||||
* `
|
||||
*
|
||||
* @param mix Le mélange
|
||||
* @return Les produits disponibles pour ce mélange
|
||||
*/
|
||||
|
|
|
@ -6,24 +6,30 @@ import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.ModelException;
|
|||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MaterialType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MixType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.GenericService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.AbstractService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.dao.MixTypeDao;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Service
|
||||
public class MixTypeService extends GenericService<MixType, MixTypeDao> {
|
||||
public class MixTypeService extends AbstractService<MixType, MixTypeDao> {
|
||||
|
||||
private MaterialService materialService;
|
||||
|
||||
public MixTypeService() {
|
||||
super(MixType.class);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public MixTypeService(MixTypeDao mixTypeDao, MaterialService materialService) {
|
||||
super(mixTypeDao, MixType.class);
|
||||
public void setMixTypeDao(MixTypeDao mixTypeDao) {
|
||||
this.dao = mixTypeDao;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setMaterialService(MaterialService materialService) {
|
||||
this.materialService = materialService;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import dev.fyloz.trial.colorrecipesexplorer.core.model.Mix;
|
|||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.RecipeEditorFormDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.RecipeExplorerFormDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.GenericService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.AbstractService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.files.ImagesService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.dao.RecipeDao;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -17,19 +17,39 @@ import java.util.*;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class RecipeService extends GenericService<Recipe, RecipeDao> {
|
||||
public class RecipeService extends AbstractService<Recipe, RecipeDao> {
|
||||
|
||||
private CompanyService companyService;
|
||||
private MixService mixService;
|
||||
private StepService stepService;
|
||||
private ImagesService imagesService;
|
||||
|
||||
public RecipeService() {
|
||||
super(Recipe.class);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public RecipeService(RecipeDao recipeDao, CompanyService companyService, MixService mixService, StepService stepService, ImagesService imagesService) {
|
||||
super(recipeDao, Recipe.class);
|
||||
public void setRecipeDao(RecipeDao recipeDao) {
|
||||
this.dao = recipeDao;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setCompanyService(CompanyService companyService) {
|
||||
this.companyService = companyService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setMixService(MixService mixService) {
|
||||
this.mixService = mixService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setStepService(StepService stepService) {
|
||||
this.stepService = stepService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setImagesService(ImagesService imagesService) {
|
||||
this.imagesService = imagesService;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,22 +2,25 @@ package dev.fyloz.trial.colorrecipesexplorer.core.services.model;
|
|||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.RecipeStep;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.GenericService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.AbstractService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.dao.StepDao;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class StepService extends GenericService<RecipeStep, StepDao> {
|
||||
public class StepService extends AbstractService<RecipeStep, StepDao> {
|
||||
|
||||
public StepService() {
|
||||
super(RecipeStep.class);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public StepService(StepDao stepDao) {
|
||||
super(stepDao, RecipeStep.class);
|
||||
public void setStepDao(StepDao stepDao) {
|
||||
this.dao = stepDao;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,12 +10,13 @@ import java.util.Optional;
|
|||
|
||||
@Repository
|
||||
public interface MaterialDao extends JpaRepository<Material, Long> {
|
||||
Optional<Material> findByName(String name);
|
||||
|
||||
List<Material> findAllByMaterialType(MaterialType materialType);
|
||||
|
||||
boolean existsByName(String name);
|
||||
|
||||
boolean existsByMaterialType(MaterialType materialType);
|
||||
|
||||
Optional<Material> findByName(String name);
|
||||
|
||||
List<Material> findAllByMaterialType(MaterialType materialType);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,26 +1,16 @@
|
|||
# DATABASE
|
||||
spring.datasource.url=jdbc:h2:file:./workdir/recipes
|
||||
spring.datasource.username=sa
|
||||
spring.datasource.password=LWK4Y7TvEbNyhu1yCoG3
|
||||
spring.datasource.driver-class-name=org.h2.Driver
|
||||
|
||||
spring.thymeleaf.template-loader-path=classpath:/src/main/java/resources/templates
|
||||
spring.thymeleaf.suffix=.html
|
||||
|
||||
spring.messages.fallback-to-system-locale=true
|
||||
|
||||
spring.servlet.multipart.max-file-size=10MB
|
||||
spring.servlet.multipart.max-request-size=15MB
|
||||
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
||||
|
||||
# DATABASE CONSOLE
|
||||
spring.h2.console.path=/dbconsole
|
||||
spring.h2.console.settings.trace=true
|
||||
spring.h2.console.settings.web-allow-others=true
|
||||
# DATABASE CONSOLE REMOTE
|
||||
spring.h2.console.settings.trace=false
|
||||
spring.h2.console.settings.web-allow-others=false
|
||||
|
||||
# PORT
|
||||
server.port=9090
|
||||
server.http2.enabled=true
|
||||
server.error.whitelabel.enabled=false
|
||||
|
||||
# CRE CONFIG
|
||||
cre.server.upload-directory=./workdir
|
||||
|
@ -41,3 +31,20 @@ entities.material-types.base-name=Base
|
|||
# DEBUG
|
||||
spring.jpa.show-sql=true
|
||||
spring.h2.console.enabled=true
|
||||
|
||||
# DO NOT MODIFY
|
||||
spring.datasource.driver-class-name=org.h2.Driver
|
||||
|
||||
spring.thymeleaf.template-loader-path=classpath:/src/main/java/resources/templates
|
||||
spring.thymeleaf.suffix=.html
|
||||
|
||||
spring.messages.fallback-to-system-locale=true
|
||||
|
||||
spring.servlet.multipart.max-file-size=10MB
|
||||
spring.servlet.multipart.max-request-size=15MB
|
||||
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
||||
|
||||
server.http2.enabled=true
|
||||
server.error.whitelabel.enabled=false
|
||||
|
|
Loading…
Reference in New Issue