Fix pending issues in previous commit
FEA: ItEr75S29DefaultData
This commit is contained in:
parent
c48fd3ddd3
commit
c364192df6
6 changed files with 115 additions and 20 deletions
|
|
@ -45,8 +45,8 @@ public class LabelBootstrap implements ILabelBootstrap {
|
|||
@Override
|
||||
@Transactional
|
||||
public void loadRequiredData() {
|
||||
LabelType priorityType = LabelType.create("Priority");
|
||||
if (labelTypeDAO.getAll().size() == 0) {
|
||||
LabelType priorityType = LabelType.create("Priority");
|
||||
priorityType.setCodeAutogenerated(true);
|
||||
priorityType.setCode(entitySequenceDAO
|
||||
.getNextEntityCodeWithoutTransaction(EntityNameEnum.LABEL));
|
||||
|
|
|
|||
|
|
@ -64,21 +64,18 @@ public class CriterionsBootstrap implements ICriterionsBootstrap {
|
|||
@Autowired
|
||||
private List<ICriterionTypeProvider> providers;
|
||||
|
||||
private boolean isTest = false;
|
||||
|
||||
public CriterionsBootstrap() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void loadRequiredData() {
|
||||
Map<CriterionType, List<String>> typesWithCriterions = getTypesWithCriterions();
|
||||
// Insert predefined criterions
|
||||
for (Entry<CriterionType, List<String>> entry : typesWithCriterions
|
||||
.entrySet()) {
|
||||
CriterionType criterionType = retrieveOrCreate(entry.getKey());
|
||||
// FIXME when tests are fixed isTest has no sense
|
||||
if (isTest || criterionDAO.getAll().size() == 0) {
|
||||
if (criterionTypeDAO.findAll().isEmpty()) {
|
||||
Map<CriterionType, List<String>> typesWithCriterions = getTypesWithCriterions();
|
||||
// Insert predefined criterions
|
||||
for (Entry<CriterionType, List<String>> entry : typesWithCriterions
|
||||
.entrySet()) {
|
||||
CriterionType criterionType = retrieveOrCreate(entry.getKey());
|
||||
// Create predefined criterions for criterionType
|
||||
for (String criterionName : entry.getValue()) {
|
||||
ensureCriterionExists(criterionName, criterionType);
|
||||
|
|
@ -87,12 +84,6 @@ public class CriterionsBootstrap implements ICriterionsBootstrap {
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME this method is not needed when tests are fixed
|
||||
public void loadRequiredData(boolean test) {
|
||||
isTest = test;
|
||||
loadRequiredData();
|
||||
}
|
||||
|
||||
private void ensureCriterionExists(String criterionName,
|
||||
CriterionType criterionType) {
|
||||
Criterion criterion = Criterion.createPredefined(criterionName,
|
||||
|
|
|
|||
|
|
@ -31,6 +31,4 @@ public interface ICriterionsBootstrap extends IDataBootstrap {
|
|||
|
||||
public abstract void loadRequiredData();
|
||||
|
||||
public void loadRequiredData(boolean test);
|
||||
|
||||
}
|
||||
|
|
@ -28,12 +28,20 @@ import static org.libreplan.business.test.BusinessGlobalNames.BUSINESS_SPRING_CO
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.libreplan.business.IDataBootstrap;
|
||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.libreplan.business.resources.bootstrap.ICriterionsBootstrap;
|
||||
import org.libreplan.business.resources.daos.ICriterionDAO;
|
||||
import org.libreplan.business.resources.daos.ICriterionTypeDAO;
|
||||
import org.libreplan.business.resources.daos.IResourceDAO;
|
||||
import org.libreplan.business.resources.entities.CategoryCriteria;
|
||||
import org.libreplan.business.resources.entities.Criterion;
|
||||
import org.libreplan.business.resources.entities.CriterionType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
|
@ -45,14 +53,49 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
@Transactional
|
||||
public class CriterionsBootstrapTest {
|
||||
|
||||
@Resource
|
||||
private IDataBootstrap configurationBootstrap;
|
||||
|
||||
@Autowired
|
||||
private ICriterionsBootstrap criterionsBootstrap;
|
||||
|
||||
@Autowired
|
||||
private ICriterionDAO criterionDAO;
|
||||
|
||||
@Autowired
|
||||
private IResourceDAO resourceDAO;
|
||||
|
||||
@Autowired
|
||||
private ICriterionTypeDAO criterionTypeDAO;
|
||||
|
||||
private List<Criterion> somePredefinedCriterions;
|
||||
|
||||
@Before
|
||||
public void loadRequiredaData() {
|
||||
// Load data
|
||||
configurationBootstrap.loadRequiredData();
|
||||
cleanCriteria();
|
||||
}
|
||||
|
||||
private void cleanCriteria() {
|
||||
try {
|
||||
|
||||
List<org.libreplan.business.resources.entities.Resource> resources = resourceDAO
|
||||
.findAll();
|
||||
for (org.libreplan.business.resources.entities.Resource resource : resources) {
|
||||
resourceDAO.remove(resource.getId());
|
||||
}
|
||||
|
||||
List<CriterionType> types = criterionTypeDAO.findAll();
|
||||
for (CriterionType type : types) {
|
||||
criterionTypeDAO.remove(type.getId());
|
||||
}
|
||||
|
||||
} catch (InstanceNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public CriterionsBootstrapTest() {
|
||||
somePredefinedCriterions = getSomePredefinedCriterions();
|
||||
}
|
||||
|
|
@ -68,7 +111,7 @@ public class CriterionsBootstrapTest {
|
|||
@Test
|
||||
public void testBootstrap() {
|
||||
givenNoSomePredefinedCriterionExists();
|
||||
criterionsBootstrap.loadRequiredData(true);
|
||||
criterionsBootstrap.loadRequiredData();
|
||||
thenAllSomePredefinedCriterionsExist();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import static org.libreplan.web.test.WebappGlobalNames.WEBAPP_SPRING_SECURITY_CO
|
|||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
|
|
@ -51,6 +52,7 @@ import org.libreplan.business.advance.entities.AdvanceType;
|
|||
import org.libreplan.business.advance.entities.DirectAdvanceAssignment;
|
||||
import org.libreplan.business.advance.exceptions.DuplicateAdvanceAssignmentForOrderElementException;
|
||||
import org.libreplan.business.advance.exceptions.DuplicateValueTrueReportGlobalAdvanceException;
|
||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.libreplan.business.labels.entities.Label;
|
||||
import org.libreplan.business.labels.entities.LabelType;
|
||||
import org.libreplan.business.materials.entities.Material;
|
||||
|
|
@ -65,11 +67,16 @@ import org.libreplan.business.requirements.entities.DirectCriterionRequirement;
|
|||
import org.libreplan.business.requirements.entities.IndirectCriterionRequirement;
|
||||
import org.libreplan.business.resources.bootstrap.ICriterionsBootstrap;
|
||||
import org.libreplan.business.resources.daos.ICriterionDAO;
|
||||
import org.libreplan.business.resources.daos.ICriterionTypeDAO;
|
||||
import org.libreplan.business.resources.daos.IResourceDAO;
|
||||
import org.libreplan.business.resources.entities.Criterion;
|
||||
import org.libreplan.business.resources.entities.CriterionType;
|
||||
import org.libreplan.business.scenarios.bootstrap.PredefinedScenarios;
|
||||
import org.libreplan.business.scenarios.entities.OrderVersion;
|
||||
import org.libreplan.business.scenarios.entities.Scenario;
|
||||
import org.libreplan.business.templates.entities.OrderElementTemplate;
|
||||
import org.libreplan.business.workreports.daos.IWorkReportDAO;
|
||||
import org.libreplan.business.workreports.entities.WorkReport;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
|
@ -105,6 +112,15 @@ public class OrderElementTreeModelTest {
|
|||
@Autowired
|
||||
private ICriterionDAO criterionDAO;
|
||||
|
||||
@Autowired
|
||||
private IWorkReportDAO workReportDAO;
|
||||
|
||||
@Autowired
|
||||
private IResourceDAO resourceDAO;
|
||||
|
||||
@Autowired
|
||||
private ICriterionTypeDAO criterionTypeDAO;
|
||||
|
||||
private Order order;
|
||||
|
||||
private OrderElementTreeModel model;
|
||||
|
|
@ -127,16 +143,42 @@ public class OrderElementTreeModelTest {
|
|||
|
||||
@Before
|
||||
public void loadRequiredaData() {
|
||||
cleanCriteria(workReportDAO, resourceDAO, criterionTypeDAO);
|
||||
|
||||
// Load data
|
||||
configurationBootstrap.loadRequiredData();
|
||||
defaultAdvanceTypesBootstrapListener.loadRequiredData();
|
||||
scenariosBootstrap.loadRequiredData();
|
||||
criterionsBootstrap.loadRequiredData(true);
|
||||
criterionsBootstrap.loadRequiredData();
|
||||
|
||||
givenOrder();
|
||||
givenModel();
|
||||
}
|
||||
|
||||
public static void cleanCriteria(IWorkReportDAO workReportDAO,
|
||||
IResourceDAO resourceDAO, ICriterionTypeDAO criterionTypeDAO) {
|
||||
try {
|
||||
List<WorkReport> reports = workReportDAO.findAll();
|
||||
for (WorkReport each : reports) {
|
||||
workReportDAO.remove(each.getId());
|
||||
}
|
||||
|
||||
List<org.libreplan.business.resources.entities.Resource> resources = resourceDAO
|
||||
.findAll();
|
||||
for (org.libreplan.business.resources.entities.Resource each : resources) {
|
||||
resourceDAO.remove(each.getId());
|
||||
}
|
||||
|
||||
List<CriterionType> types = criterionTypeDAO.findAll();
|
||||
for (CriterionType each : types) {
|
||||
criterionTypeDAO.remove(each.getId());
|
||||
}
|
||||
|
||||
} catch (InstanceNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void givenOrder() {
|
||||
order = Order.create();
|
||||
order.setName("order");
|
||||
|
|
|
|||
|
|
@ -69,9 +69,13 @@ import org.libreplan.business.orders.entities.OrderLine;
|
|||
import org.libreplan.business.requirements.entities.CriterionRequirement;
|
||||
import org.libreplan.business.requirements.entities.DirectCriterionRequirement;
|
||||
import org.libreplan.business.requirements.entities.IndirectCriterionRequirement;
|
||||
import org.libreplan.business.resources.daos.ICriterionTypeDAO;
|
||||
import org.libreplan.business.resources.daos.IResourceDAO;
|
||||
import org.libreplan.business.resources.entities.PredefinedCriterionTypes;
|
||||
import org.libreplan.business.resources.entities.ResourceEnum;
|
||||
import org.libreplan.business.scenarios.bootstrap.IScenariosBootstrap;
|
||||
import org.libreplan.business.workreports.daos.IWorkReportDAO;
|
||||
import org.libreplan.web.orders.OrderElementTreeModelTest;
|
||||
import org.libreplan.ws.common.api.AdvanceMeasurementDTO;
|
||||
import org.libreplan.ws.common.api.ConstraintViolationDTO;
|
||||
import org.libreplan.ws.common.api.CriterionRequirementDTO;
|
||||
|
|
@ -129,8 +133,25 @@ public class OrderElementServiceTest {
|
|||
@Autowired
|
||||
private IAdHocTransactionService transactionService;
|
||||
|
||||
@Autowired
|
||||
private IWorkReportDAO workReportDAO;
|
||||
|
||||
@Autowired
|
||||
private IResourceDAO resourceDAO;
|
||||
|
||||
@Autowired
|
||||
private ICriterionTypeDAO criterionTypeDAO;
|
||||
|
||||
@Before
|
||||
public void loadRequiredaData() {
|
||||
transactionService.runOnTransaction(new IOnTransaction<Void>() {
|
||||
@Override
|
||||
public Void execute() {
|
||||
OrderElementTreeModelTest.cleanCriteria(workReportDAO,
|
||||
resourceDAO, criterionTypeDAO);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
transactionService.runOnAnotherTransaction(new IOnTransaction<Void>() {
|
||||
@Override
|
||||
public Void execute() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue