Commit 70e11ad0 authored by Romain Bioteau's avatar Romain Bioteau
Browse files

Merge pull request #263 from bonitasoft/defect/BS-14131-handleDepthHigherThan5

BS-14131: Add persistenceID also on last attribute; of aggregagtion when
parents 4a01bc1d 5634f59c
......@@ -60,6 +60,17 @@ public class FieldToContractInputMappingFactoryTest {
assertThat(mappings).extracting("field.name").containsOnly("manager");
}
@Test
public void should_create_fieldMappingToContractInputMapping_from_complex_business_object_recursive_with_aggregation_field() {
final BusinessObject businessObject = aBO("Employee")
.withField(RelationFieldBuilder.anAggregationField("manager", aBO("Employee").build())).build();
final FieldToContractInputMappingFactory factory = new FieldToContractInputMappingFactory();
final List<FieldToContractInputMapping> mappings = factory.createMappingForBusinessObjectType(businessObject);
assertThat(mappings).extracting("field.name").containsOnly("manager");
}
@Test
public void should_create_fieldMappingToContractInputMapping_from_complex_business_object_with_composition_field() {
final BusinessObject businessObject = aBO("Employee")
......@@ -91,6 +102,18 @@ public class FieldToContractInputMappingFactoryTest {
.isEmpty()).isTrue();
}
@Test
public void should_create_fieldMappingToContractInputMappingTree_withADepth_of_five_when_business_model_is_recursive_with_agregation() {
final BusinessObject businessObject = aBO("Employee").build();
businessObject.addField(RelationFieldBuilder.anAggregationField("employee", businessObject));
final FieldToContractInputMappingFactory factory = new FieldToContractInputMappingFactory();
final List<FieldToContractInputMapping> mappings = factory.createMappingForBusinessObjectType(businessObject);
final FieldToContractInputMapping lastMappingChild = mappings.get(0).getChildren().get(1).getChildren().get(1).getChildren().get(1).getChildren().get(1).getChildren().get(1);
assertThat(lastMappingChild.getChildren().size()).isEqualTo(1);
}
@Test
public void should_create_a_persistenceId_mapping_for_aggregated_field() {
final BusinessObject businessObject = aBO("Employee").build();
......@@ -104,4 +127,5 @@ public class FieldToContractInputMappingFactoryTest {
assertThat(((RelationFieldToContractInputMapping) mappings.get(0)).getChildren()).extracting("field.name").contains("persistenceId");
}
}
......@@ -49,15 +49,14 @@ public class FieldToContractInputMappingFactory {
private FieldToContractInputMapping createRelationFieldToContractInputMapping(final RelationField field, int depth) {
final RelationFieldToContractInputMapping relationFieldMapping = new RelationFieldToContractInputMapping(field);
if (RelationField.Type.AGGREGATION.equals(((RelationField) relationFieldMapping.getField()).getType())) {
addPersistenceIdMapping(relationFieldMapping);
}
if (depth > 0) {
depth--;
if (RelationField.Type.AGGREGATION.equals(((RelationField) relationFieldMapping.getField()).getType())) {
addPersistenceIdMapping(relationFieldMapping);
}
for (final Field child : field.getReference().getFields()) {
relationFieldMapping.addChild(createFieldToContractInputMapping(child, depth));
}
}
return relationFieldMapping;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment