Make tests independent of tests order execution
When changing JUnit and Spring version the test failed because of the different order execution.
This commit is contained in:
parent
cbd195791d
commit
80f6f6e0cf
4 changed files with 206 additions and 171 deletions
|
|
@ -33,6 +33,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.Query;
|
||||
|
|
@ -597,10 +598,10 @@ public class OrderElementDAO extends IntegrationEntityDAO<OrderElement>
|
|||
OrderElement orderElement2) {
|
||||
Order order1 = orderElement1.getOrder();
|
||||
Order order2 = orderElement2.getOrder();
|
||||
if (order1.getId() == null || order2.getId() == null) {
|
||||
if (order1 == null || order2 == null) {
|
||||
return false;
|
||||
}
|
||||
return order1.getId().equals(order2.getId());
|
||||
return ObjectUtils.equals(order1.getId(), order2.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -52,7 +52,8 @@ import org.libreplan.business.workreports.valueobjects.DescriptionValue;
|
|||
* @author Diego Pino García <dpino@igalia.com>
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
public class WorkReportLine extends IntegrationEntity implements Comparable,
|
||||
public class WorkReportLine extends IntegrationEntity implements
|
||||
Comparable<WorkReportLine>,
|
||||
IWorkReportsElements {
|
||||
|
||||
public static WorkReportLine create(WorkReport workReport) {
|
||||
|
|
@ -240,9 +241,8 @@ public class WorkReportLine extends IntegrationEntity implements Comparable,
|
|||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object arg0) {
|
||||
public int compareTo(WorkReportLine workReportLine) {
|
||||
if (date != null) {
|
||||
final WorkReportLine workReportLine = (WorkReportLine) arg0;
|
||||
return date.compareTo(workReportLine.getDate());
|
||||
}
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ import java.util.List;
|
|||
import javax.annotation.Resource;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.libreplan.business.IDataBootstrap;
|
||||
|
|
@ -55,9 +54,9 @@ import org.libreplan.ws.materials.api.MaterialCategoryDTO;
|
|||
import org.libreplan.ws.materials.api.MaterialCategoryListDTO;
|
||||
import org.libreplan.ws.materials.api.MaterialDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
/**
|
||||
* Tests for <code>IMaterialService</code>.
|
||||
|
|
@ -95,11 +94,7 @@ public class MaterialServiceTest {
|
|||
@Resource
|
||||
private IDataBootstrap unitTypeBootstrap;
|
||||
|
||||
private String unitTypeCodeA = "unitTypeCodeA";
|
||||
|
||||
private String unitTypeCodeB = "unitTypeCodeB";
|
||||
|
||||
@Before
|
||||
@BeforeTransaction
|
||||
public void loadRequiredaData() {
|
||||
IOnTransaction<Void> load = new IOnTransaction<Void>() {
|
||||
|
||||
|
|
@ -108,19 +103,26 @@ public class MaterialServiceTest {
|
|||
configurationBootstrap.loadRequiredData();
|
||||
materialCategoryBootstrap.loadRequiredData();
|
||||
unitTypeBootstrap.loadRequiredData();
|
||||
createUnitTypes();
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
transactionService.runOnAnotherTransaction(load);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Rollback(false)
|
||||
public void CreateUnitType() {
|
||||
UnitType entityA = UnitType.create(unitTypeCodeA, getUniqueName());
|
||||
UnitType entityB = UnitType.create(unitTypeCodeB, getUniqueName());
|
||||
private UnitType entityA;
|
||||
|
||||
private String getUnitTypeCodeA() {
|
||||
return entityA.getCode();
|
||||
}
|
||||
|
||||
private UnitType entityB;
|
||||
|
||||
private void createUnitTypes() {
|
||||
entityA = UnitType.create(getUniqueName(), getUniqueName());
|
||||
entityB = UnitType.create(getUniqueName(), getUniqueName());
|
||||
unitTypeDAO.save(entityA);
|
||||
unitTypeDAO.save(entityB);
|
||||
unitTypeDAO.flush();
|
||||
|
|
@ -133,16 +135,16 @@ public class MaterialServiceTest {
|
|||
/* Build materialCategory (0 constraint violations). */
|
||||
// Missing material name and the unit type.
|
||||
MaterialDTO m1 = new MaterialDTO(null, new BigDecimal(13),
|
||||
unitTypeCodeA, true);
|
||||
getUnitTypeCodeA(), true);
|
||||
// Missing default unit price
|
||||
MaterialDTO m2 = new MaterialDTO("material 2", null, unitTypeCodeA,
|
||||
MaterialDTO m2 = new MaterialDTO("material 2", null, getUnitTypeCodeA(),
|
||||
true);
|
||||
// Missing unit type
|
||||
MaterialDTO m3 = new MaterialDTO("material 3", new BigDecimal(13),
|
||||
null, true);
|
||||
// Missing unit type, same name
|
||||
MaterialDTO m4 = new MaterialDTO("material 3", new BigDecimal(13),
|
||||
unitTypeCodeA, null);
|
||||
getUnitTypeCodeA(), null);
|
||||
|
||||
List<MaterialDTO> materialDTOs = new ArrayList<MaterialDTO>();
|
||||
materialDTOs.add(m1);
|
||||
|
|
@ -166,9 +168,9 @@ public class MaterialServiceTest {
|
|||
public void testAddMaterialRepeatedCodes() {
|
||||
/* Build material with same code (1 constraint violations). */
|
||||
MaterialDTO m1 = new MaterialDTO("CodeA", "material1", new BigDecimal(
|
||||
13), unitTypeCodeA, true);
|
||||
13), getUnitTypeCodeA(), true);
|
||||
MaterialDTO m2 = new MaterialDTO("CodeA", "material2", new BigDecimal(
|
||||
13), unitTypeCodeA, true);
|
||||
13), getUnitTypeCodeA(), true);
|
||||
|
||||
List<MaterialDTO> materialDTOs = new ArrayList<MaterialDTO>();
|
||||
materialDTOs.add(m1);
|
||||
|
|
@ -190,9 +192,9 @@ public class MaterialServiceTest {
|
|||
public void testAddValidMaterialCategory() {
|
||||
/* Build material (0 constraint violations). */
|
||||
MaterialDTO m1 = new MaterialDTO("CodeM1", "material1", new BigDecimal(
|
||||
13), unitTypeCodeA, true);
|
||||
13), getUnitTypeCodeA(), true);
|
||||
MaterialDTO m2 = new MaterialDTO("CodeM2", "material2", new BigDecimal(
|
||||
13), unitTypeCodeA, true);
|
||||
13), getUnitTypeCodeA(), true);
|
||||
|
||||
List<MaterialDTO> materialDTOs1 = new ArrayList<MaterialDTO>();
|
||||
List<MaterialDTO> materialDTOs2 = new ArrayList<MaterialDTO>();
|
||||
|
|
@ -275,16 +277,6 @@ public class MaterialServiceTest {
|
|||
@Test
|
||||
public void testAddAndUpdateMaterialCategory() {
|
||||
|
||||
String unitTypeCodeA = getUniqueName();
|
||||
String unitTypeCodeB = getUniqueName();
|
||||
UnitType entityA = UnitType.create(unitTypeCodeA, "UnitTypeA");
|
||||
UnitType entityB = UnitType.create(unitTypeCodeB, "UnitTypeB");
|
||||
unitTypeDAO.save(entityA);
|
||||
unitTypeDAO.save(entityB);
|
||||
unitTypeDAO.flush();
|
||||
sessionFactory.getCurrentSession().evict(entityA);
|
||||
sessionFactory.getCurrentSession().evict(entityB);
|
||||
|
||||
/* Build material (0 constraint violations). */
|
||||
MaterialDTO m1 = new MaterialDTO("M-1", "tornillos",
|
||||
new BigDecimal(13), UnitTypeBootstrap.getDefaultUnitType()
|
||||
|
|
|
|||
|
|
@ -30,14 +30,19 @@ import static org.libreplan.web.WebappGlobalNames.WEBAPP_SPRING_SECURITY_CONFIG_
|
|||
import static org.libreplan.web.test.WebappGlobalNames.WEBAPP_SPRING_CONFIG_TEST_FILE;
|
||||
import static org.libreplan.web.test.WebappGlobalNames.WEBAPP_SPRING_SECURITY_CONFIG_TEST_FILE;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.xml.datatype.XMLGregorianCalendar;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.joda.time.LocalDate;
|
||||
|
|
@ -47,7 +52,8 @@ import org.junit.runner.RunWith;
|
|||
import org.libreplan.business.IDataBootstrap;
|
||||
import org.libreplan.business.common.IAdHocTransactionService;
|
||||
import org.libreplan.business.common.IOnTransaction;
|
||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.libreplan.business.common.IntegrationEntity;
|
||||
import org.libreplan.business.common.daos.IIntegrationEntityDAO;
|
||||
import org.libreplan.business.costcategories.daos.ITypeOfWorkHoursDAO;
|
||||
import org.libreplan.business.costcategories.entities.TypeOfWorkHours;
|
||||
import org.libreplan.business.labels.daos.ILabelDAO;
|
||||
|
|
@ -78,9 +84,9 @@ import org.libreplan.ws.workreports.api.WorkReportLineDTO;
|
|||
import org.libreplan.ws.workreports.api.WorkReportListDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.annotation.NotTransactional;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
|
|
@ -100,7 +106,7 @@ public class WorkReportServiceTest {
|
|||
private IWorkReportService workReportService;
|
||||
|
||||
@Autowired
|
||||
private IWorkerDAO workerDAO;
|
||||
private IWorkerDAO dao;
|
||||
|
||||
@Autowired
|
||||
private SessionFactory sessionFactory;
|
||||
|
|
@ -159,146 +165,184 @@ public class WorkReportServiceTest {
|
|||
@Resource
|
||||
private IDataBootstrap configurationBootstrap;
|
||||
|
||||
@Test
|
||||
@Rollback(false)
|
||||
public void loadRequiredaData() {
|
||||
@BeforeTransaction
|
||||
public void setup() {
|
||||
transactionService.runOnTransaction(new IOnTransaction<Void>() {
|
||||
|
||||
@Override
|
||||
public Void execute() {
|
||||
loadRequiredaData();
|
||||
givenWorkerStored();
|
||||
givenOrderLineStored();
|
||||
createAPairOfLabelTypes();
|
||||
|
||||
givenTypeOfWorkHoursStored();
|
||||
givenWorkReportTypeStored();
|
||||
givenWorkReportTypeStored2();
|
||||
givenWorkReportTypeStored3();
|
||||
givenWorkReportTypeStored4();
|
||||
givenWorkReportTypeStored5();
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void loadRequiredaData() {
|
||||
configurationBootstrap.loadRequiredData();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Rollback(false)
|
||||
public void givenWorkerStored() {
|
||||
Worker worker = Worker.create("Firstname", "Surname", resourceCode);
|
||||
worker.setCode(resourceCode);
|
||||
workerDAO.save(worker);
|
||||
workerDAO.flush();
|
||||
sessionFactory.getCurrentSession().evict(worker);
|
||||
|
||||
worker.dontPoseAsTransientObjectAnymore();
|
||||
private static <T extends IntegrationEntity> T findOrCreate(
|
||||
IIntegrationEntityDAO<? super T> dao, Class<T> klass,
|
||||
String code, Object... constructorArguments) {
|
||||
if (dao.existsByCode(code)) {
|
||||
return klass.cast(dao.findExistingEntityByCode(code));
|
||||
} else {
|
||||
try {
|
||||
Method create = klass.getMethod("create",
|
||||
asClasses(constructorArguments));
|
||||
T result = klass
|
||||
.cast(create.invoke(null, constructorArguments));
|
||||
result.setCode(code);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Rollback(false)
|
||||
public void givenOrderLineStored() {
|
||||
OrderLine orderLine = OrderLine.create();
|
||||
orderLine.setCode(orderElementCode);
|
||||
orderLine.setName("order-line-name" + UUID.randomUUID());
|
||||
|
||||
orderElementDAO.save(orderLine);
|
||||
orderElementDAO.flush();
|
||||
sessionFactory.getCurrentSession().evict(orderLine);
|
||||
|
||||
orderLine.dontPoseAsTransientObjectAnymore();
|
||||
private static Class<?>[] asClasses(Object[] constructorArguments) {
|
||||
Class<?>[] result = new Class<?>[constructorArguments.length];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = constructorArguments[i].getClass();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test
|
||||
@Rollback(false)
|
||||
public void createAPairOfLabelTypes() {
|
||||
LabelType labelType_A = LabelType.create(labelTypeA, labelTypeA);
|
||||
LabelType labelType_B = LabelType.create(labelTypeB, labelTypeB);
|
||||
|
||||
Label label_A1 = Label.create(labelA1, labelA1);
|
||||
Label label_A2 = Label.create(labelA2, labelA2);
|
||||
Label label_B1 = Label.create(labelB1, labelB1);
|
||||
|
||||
labelType_A.addLabel(label_A1);
|
||||
labelType_A.addLabel(label_A2);
|
||||
labelType_B.addLabel(label_B1);
|
||||
|
||||
labelTypeDAO.save(labelType_A);
|
||||
labelTypeDAO.save(labelType_B);
|
||||
labelTypeDAO.flush();
|
||||
sessionFactory.getCurrentSession().evict(labelType_A);
|
||||
sessionFactory.getCurrentSession().evict(labelType_B);
|
||||
labelType_A.dontPoseAsTransientObjectAnymore();
|
||||
labelType_B.dontPoseAsTransientObjectAnymore();
|
||||
private void givenWorkerStored() {
|
||||
Worker worker = findOrCreate(dao, Worker.class, resourceCode,
|
||||
"Firstname", "Surname", resourceCode);
|
||||
if (worker.isNewObject()) {
|
||||
dao.save(worker);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Rollback(false)
|
||||
public void givenTypeOfWorkHoursStored() {
|
||||
TypeOfWorkHours typeOfWorkHours = TypeOfWorkHours.create();
|
||||
typeOfWorkHours.setCode(typeOfWorkHoursCode);
|
||||
typeOfWorkHours.setName("type-of-work-hours-name-" + UUID.randomUUID());
|
||||
typeOfWorkHours.setDefaultPrice(BigDecimal.TEN);
|
||||
|
||||
typeOfWorkHoursDAO.save(typeOfWorkHours);
|
||||
typeOfWorkHoursDAO.flush();
|
||||
sessionFactory.getCurrentSession().evict(typeOfWorkHours);
|
||||
|
||||
typeOfWorkHours.dontPoseAsTransientObjectAnymore();
|
||||
private void givenOrderLineStored() {
|
||||
OrderLine orderLine = findOrCreate(orderElementDAO, OrderLine.class,
|
||||
orderElementCode);
|
||||
if (orderLine.isNewObject()) {
|
||||
orderLine.setName("order-line-name" + UUID.randomUUID());
|
||||
orderElementDAO.save(orderLine);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Rollback(false)
|
||||
public void givenWorkReportTypeStored() {
|
||||
givenWorkReportTypeStored(false, false, false, null, workReportTypeCode);
|
||||
private void createAPairOfLabelTypes() {
|
||||
LabelType labelType_A = findOrCreate(labelTypeDAO, LabelType.class,
|
||||
labelTypeA, labelTypeA, labelTypeA);
|
||||
LabelType labelType_B = findOrCreate(labelTypeDAO, LabelType.class,
|
||||
labelTypeB, labelTypeB, labelTypeB);
|
||||
|
||||
if (labelType_A.isNewObject()) {
|
||||
Label label_A1 = Label.create(labelA1, labelA1);
|
||||
Label label_A2 = Label.create(labelA2, labelA2);
|
||||
Label label_B1 = Label.create(labelB1, labelB1);
|
||||
|
||||
labelType_A.addLabel(label_A1);
|
||||
labelType_A.addLabel(label_A2);
|
||||
labelType_B.addLabel(label_B1);
|
||||
|
||||
labelTypeDAO.save(labelType_A);
|
||||
labelTypeDAO.save(labelType_B);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Rollback(false)
|
||||
public void givenWorkReportTypeStored2() {
|
||||
givenWorkReportTypeStored(true, false, false, null, workReportTypeCode2);
|
||||
private void givenTypeOfWorkHoursStored() {
|
||||
TypeOfWorkHours typeOfWorkHours = findOrCreate(typeOfWorkHoursDAO,
|
||||
TypeOfWorkHours.class, typeOfWorkHoursCode);
|
||||
|
||||
if (typeOfWorkHours.isNewObject()) {
|
||||
typeOfWorkHours.setCode(typeOfWorkHoursCode);
|
||||
typeOfWorkHours.setName("type-of-work-hours-name-"
|
||||
+ UUID.randomUUID());
|
||||
typeOfWorkHours.setDefaultPrice(BigDecimal.TEN);
|
||||
|
||||
typeOfWorkHoursDAO.save(typeOfWorkHours);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Rollback(false)
|
||||
public void givenWorkReportTypeStored3() {
|
||||
givenWorkReportTypeStored(false, false, false,
|
||||
private void givenWorkReportTypeStored() {
|
||||
WorkReportType t = givenWorkReportTypeStored(false, false, false, null,
|
||||
workReportTypeCode);
|
||||
workReportTypeDAO.save(t);
|
||||
}
|
||||
|
||||
private void givenWorkReportTypeStored2() {
|
||||
WorkReportType t = givenWorkReportTypeStored(true, false, false, null,
|
||||
workReportTypeCode2);
|
||||
workReportTypeDAO.save(t);
|
||||
}
|
||||
|
||||
private void givenWorkReportTypeStored3() {
|
||||
WorkReportType t = givenWorkReportTypeStored(false, false, false,
|
||||
HoursManagementEnum.HOURS_CALCULATED_BY_CLOCK,
|
||||
workReportTypeCode3);
|
||||
workReportTypeDAO.save(t);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Rollback(false)
|
||||
public void givenWorkReportTypeStored4() {
|
||||
private void givenWorkReportTypeStored4() {
|
||||
WorkReportType type = givenWorkReportTypeStored(false, false, false,
|
||||
null,workReportTypeCode4);
|
||||
type.addDescriptionFieldToEndHead(DescriptionField.create(field1, 10));
|
||||
type.addDescriptionFieldToEndLine(DescriptionField.create(field2, 10));
|
||||
null, workReportTypeCode4);
|
||||
|
||||
workReportTypeDAO.save(type);
|
||||
workReportTypeDAO.flush();
|
||||
sessionFactory.getCurrentSession().evict(type);
|
||||
type.dontPoseAsTransientObjectAnymore();
|
||||
if (type.isNewObject()) {
|
||||
type.addDescriptionFieldToEndHead(DescriptionField.create(field1,
|
||||
10));
|
||||
type.addDescriptionFieldToEndLine(DescriptionField.create(field2,
|
||||
10));
|
||||
|
||||
workReportTypeDAO.save(type);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Rollback(false)
|
||||
public void givenWorkReportTypeStored5() {
|
||||
private void givenWorkReportTypeStored5() {
|
||||
WorkReportType type = givenWorkReportTypeStored(false, false, false,
|
||||
null, workReportTypeCode5);
|
||||
if (!type.isNewObject()) {
|
||||
return;
|
||||
}
|
||||
|
||||
WorkReportLabelTypeAssigment labelAssigment1 = WorkReportLabelTypeAssigment
|
||||
.create(true);
|
||||
WorkReportLabelTypeAssigment labelAssigment2 = WorkReportLabelTypeAssigment
|
||||
.create(false);
|
||||
|
||||
try {
|
||||
labelAssigment1.setLabelType(labelTypeDAO.findByCode(labelTypeA));
|
||||
labelAssigment1.setDefaultLabel(labelDAO.findByCode(labelA1));
|
||||
labelAssigment1.setPositionNumber(0);
|
||||
labelAssigment1.setLabelType(labelTypeDAO
|
||||
.findExistingEntityByCode(labelTypeA));
|
||||
labelAssigment1.setDefaultLabel(labelDAO
|
||||
.findExistingEntityByCode(labelA1));
|
||||
labelAssigment1.setPositionNumber(0);
|
||||
|
||||
labelAssigment2.setLabelType(labelTypeDAO.findByCode(labelTypeB));
|
||||
labelAssigment2.setDefaultLabel(labelDAO.findByCode(labelB1));
|
||||
labelAssigment2.setPositionNumber(0);
|
||||
labelAssigment2.setLabelType(labelTypeDAO
|
||||
.findExistingEntityByCode(labelTypeB));
|
||||
labelAssigment2.setDefaultLabel(labelDAO
|
||||
.findExistingEntityByCode(labelB1));
|
||||
labelAssigment2.setPositionNumber(0);
|
||||
|
||||
type.addLabelAssigmentToEndHead(labelAssigment1);
|
||||
type.addLabelAssigmentToEndLine(labelAssigment2);
|
||||
type.addLabelAssigmentToEndHead(labelAssigment1);
|
||||
type.addLabelAssigmentToEndLine(labelAssigment2);
|
||||
|
||||
workReportTypeDAO.save(type);
|
||||
workReportTypeDAO.flush();
|
||||
sessionFactory.getCurrentSession().evict(type);
|
||||
type.dontPoseAsTransientObjectAnymore();
|
||||
|
||||
} catch (InstanceNotFoundException e) {
|
||||
assertTrue(false);
|
||||
}
|
||||
workReportTypeDAO.save(type);
|
||||
}
|
||||
|
||||
private WorkReportType givenWorkReportTypeStored(boolean dateShared,
|
||||
boolean orderElementShared, boolean resourceShared,
|
||||
HoursManagementEnum hoursManagement, String workReportTypeCode) {
|
||||
WorkReportType workReportType = WorkReportType.create();
|
||||
|
||||
WorkReportType workReportType = findOrCreate(workReportTypeDAO,
|
||||
WorkReportType.class, workReportTypeCode);
|
||||
if (!workReportType.isNewObject()) {
|
||||
return workReportType;
|
||||
}
|
||||
|
||||
workReportType.setCode(workReportTypeCode);
|
||||
workReportType.setName(workReportTypeCode);
|
||||
|
||||
|
|
@ -310,11 +354,6 @@ public class WorkReportServiceTest {
|
|||
workReportType.setHoursManagement(hoursManagement);
|
||||
}
|
||||
|
||||
workReportTypeDAO.save(workReportType);
|
||||
workReportTypeDAO.flush();
|
||||
sessionFactory.getCurrentSession().evict(workReportType);
|
||||
workReportType.dontPoseAsTransientObjectAnymore();
|
||||
|
||||
return workReportType;
|
||||
}
|
||||
|
||||
|
|
@ -522,15 +561,8 @@ public class WorkReportServiceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@NotTransactional
|
||||
public void importValidWorkReportWithDateAtWorkReportLevel() {
|
||||
int previous = transactionService
|
||||
.runOnTransaction(new IOnTransaction<Integer>() {
|
||||
@Override
|
||||
public Integer execute() {
|
||||
return workReportDAO.getAll().size();
|
||||
}
|
||||
});
|
||||
int previous = workReportDAO.getAll().size();
|
||||
|
||||
WorkReportDTO workReportDTO = createWorkReportDTO(workReportTypeCode2);
|
||||
Date date = new LocalDate().toDateTimeAtStartOfDay().toDate();
|
||||
|
|
@ -544,26 +576,36 @@ public class WorkReportServiceTest {
|
|||
assertThat(
|
||||
instanceConstraintViolationsListDTO.instanceConstraintViolationsList
|
||||
.size(), equalTo(0));
|
||||
List<WorkReport> workReports = transactionService
|
||||
.runOnTransaction(new IOnTransaction<List<WorkReport>>() {
|
||||
@Override
|
||||
public List<WorkReport> execute() {
|
||||
List<WorkReport> list = workReportDAO.getAll();
|
||||
for (WorkReport workReport : list) {
|
||||
Set<WorkReportLine> workReportLines = workReport
|
||||
.getWorkReportLines();
|
||||
for (WorkReportLine line : workReportLines) {
|
||||
line.getDate();
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
});
|
||||
|
||||
List<WorkReport> workReports = workReportDAO.getAll();
|
||||
assertThat(workReports.size(), equalTo(previous + 1));
|
||||
|
||||
assertThat(workReports.get(previous).getDate(), equalTo(date));
|
||||
assertThat(workReports.get(previous).getWorkReportLines().iterator()
|
||||
.next().getDate(), equalTo(date));
|
||||
WorkReport imported = workReportDAO
|
||||
.findExistingEntityByCode(workReportDTO.code);
|
||||
assertThat(imported.getDate(), equalTo(date));
|
||||
|
||||
List<WorkReportLine> importedLines = new ArrayList<WorkReportLine>(
|
||||
imported.getWorkReportLines());
|
||||
Collections.sort(importedLines);
|
||||
|
||||
List<WorkReportLineDTO> exportedLines = new ArrayList<WorkReportLineDTO>(
|
||||
workReportDTO.workReportLines);
|
||||
Collections.sort(exportedLines, new Comparator<WorkReportLineDTO>() {
|
||||
@Override
|
||||
public int compare(WorkReportLineDTO o1, WorkReportLineDTO o2) {
|
||||
return o1.date.compare(o2.date);
|
||||
}
|
||||
});
|
||||
|
||||
for (WorkReportLineDTO each : exportedLines) {
|
||||
WorkReportLine line = importedLines.remove(0);
|
||||
assertThat(line.getDate().getTime(), equalTo(asTime(each.getDate())));
|
||||
}
|
||||
}
|
||||
|
||||
private long asTime(XMLGregorianCalendar date2) {
|
||||
return date2
|
||||
.toGregorianCalendar().getTime().getTime();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue