@Transactional
public void checkRemoveElementOnOnlyOrderLineWithCriteriaAndAdvances()
throws DuplicateValueTrueReportGlobalAdvanceException,
DuplicateAdvanceAssignmentForOrderElementException {
model.addElement("element", 100);
OrderLine element = (OrderLine) order.getChildren().get(0);
model.addElementAt(element, "element2", 50);
OrderLineGroup container = (OrderLineGroup) order.getChildren().get(0);
model.removeNode(container.getChildren().iterator().next());
element = (OrderLine) container.getChildren().get(0);
addCriterionRequirement(element);
addDirectAdvanceAssignment(element);
// * infoComponent (code, name, description)
String name = "container";
container.setName(name);
String code = "code";
container.setCode(code);
String description = "description";
container.setDescription(description);
// * initDate
Date date = new Date();
container.setInitDate(date);
// * deadline
container.setDeadline(date);
// * directAdvanceAssignments
addAnotherDirectAdvanceAssignment(container);
// * materialAssignments
addMaterialAssignment(container);
// * labels
addLabel(container);
// * taskQualityForms
addQualityForm(container);
// * criterionRequirements
addAnotherCriterionRequirement(container);
// * template
addTemplate(container);
// * externalCode
String externalCode = "external-code";
container.setExternalCode(externalCode);
model.removeNode(element);
assertTrue(order.getDirectAdvanceAssignments().isEmpty());
assertNull(order.getIndirectAdvanceAssignment(advanceType));
assertNotNull(order.getIndirectAdvanceAssignment(advanceType2));
assertTrue(order.getCriterionRequirements().isEmpty());
assertThat(order.getWorkHours(), equalTo(0));
element = (OrderLine) order.getChildren().get(0);
assertThat(element.getWorkHours(), equalTo(0));
// * infoComponent (code, name, description)
assertThat(element.getName(), equalTo(name));
assertThat(element.getCode(), equalTo(code));
assertThat(element.getDescription(), equalTo(description));
// * initDate
assertThat(element.getInitDate(), equalTo(date));
// * deadline
assertThat(element.getDeadline(), equalTo(date));
// * directAdvanceAssignments
assertThat(element.getDirectAdvanceAssignments().size(), equalTo(1));
assertNotNull(element.getDirectAdvanceAssignmentByType(advanceType2));
assertThat(element.getDirectAdvanceAssignmentByType(advanceType2)
.getOrderElement(), equalTo((OrderElement) element));
// * materialAssignments
assertThat(element.getMaterialAssignments().size(), equalTo(1));
assertThat(element.getMaterialAssignments().iterator().next()
.getMaterial(), equalTo(materialAssignment.getMaterial()));
assertThat(element.getMaterialAssignments().iterator().next()
.getOrderElement(), equalTo((OrderElement) element));
// * labels
assertThat(element.getLabels().size(), equalTo(1));
assertThat(element.getLabels().iterator().next(), equalTo(label));
assertThat(element.getLabels().iterator().next().getType(),
equalTo(label.getType()));
// * taskQualityForms
assertThat(element.getQualityForms().size(), equalTo(1));
assertThat(element.getQualityForms().iterator().next(),
equalTo(qualityForm));
assertThat(element.getTaskQualityForms().iterator().next()
.getOrderElement(), equalTo((OrderElement) element));
// * criterionRequirements
assertThat(element.getCriterionRequirements().size(), equalTo(1));
assertDirectCriterion(element.getCriterionRequirements().iterator()
.next(), criterion2);
assertThat(element.getCriterionRequirements().iterator().next()
.getOrderElement(), equalTo((OrderElement) element));
assertThat(element.getHoursGroups().get(0).getCriterionRequirements()
.size(), equalTo(1));
assertIndirectCriterion(element.getHoursGroups().get(0)
.getCriterionRequirements().iterator().next(), criterion2);
// * template
assertNotNull(element.getTemplate());
assertThat(element.getTemplate().getName(), equalTo(template.getName()));
// * externalCode
assertThat(element.getExternalCode(), equalTo(externalCode));
}