Commit c6a366d4 authored by azara's avatar azara
Browse files

BS-13234 generate input contract from selected business data field

tests added, corrections after comments on pr
parent 505fd4da
......@@ -42,9 +42,9 @@ removeInputErrorTitle=Remove failed
removeInputErrorMsg=An error occurred when removing contract input.
severalCompilationErrors={0} compilation errors found.
SelectBusinessDataWizardPageTitle=Select business data
selectBusinessDataWizardPageDescription=Select business variable from wich contract input will be generated.
selectBusinessDataWizardPageDescription=Select business variable from which contract input will be generated.
generate=Add from data...
contractInputGenerationTitle=Contract input
contractInputGenerationTitle=Add Contract input
rootContractInputName=Input name
selectFieldToGenerateTitle=Select {0} attributes to add to contract
selectFieldToGenerateDescription=Choose the fields you want to reuse in your contract.
......
......@@ -20,6 +20,7 @@ import static org.mockito.Mockito.doReturn;
import java.util.List;
import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelRepositoryStore;
import org.bonitasoft.studio.model.businessObject.FieldBuilder.RelationFieldBuilder;
import org.bonitasoft.studio.model.businessObject.FieldBuilder.SimpleFieldBuilder;
......@@ -82,4 +83,17 @@ public class FieldToContractInputMappingFactoryTest {
}
@Test
public void should_create_fieldMappingToContractInputMappingTree_withADepth_of_five_when_business_model_is_recursive() {
final BusinessObject bo = aBO("Employee").build();
bo.addField(RelationFieldBuilder.aCompositionField("employee", bo));
doReturn(bo).when(businessObjectStore)
.getBusinessObjectByQualifiedName("Employee");
final FieldToContractInputMappingFactory factory = new FieldToContractInputMappingFactory(businessObjectStore);
final List<FieldToContractInputMapping> mappings = factory.createMappingForBusinessObjectType("Employee");
assertThat(
mappings.get(0).getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren()
.isEmpty()).isTrue();
}
}
/**
* Copyright (C) 2014-2015 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* Copyright (C) 2014-2015 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
......
/**
* Copyright (C) 2014 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* Copyright (C) 2015 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
......
/**
* Copyright (C) 2015 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.contract.ui.wizard;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -89,9 +103,12 @@ public class ContractInputGenerationWizardTest {
}
@Test
public void should_canFinish_return_true_when_data_is_defined() {
public void should_canFinish_return_true_when_data_is_selected() {
final Pool process = aPool().havingContract(aContract()).build();
process.getData().add(aBusinessData().build());
final BusinessObjectData data = aBusinessData().withClassname("com.company.Employee").build();
process.getData().add(data);
Mockito.doReturn(BusinessObjectBuilder.aBO("com.company.Employee").withField(SimpleFieldBuilder.aTextField("name").build()).build()).when(store)
.getBusinessObjectByQualifiedName("com.company.Employee");
final ContractInputGenerationWizard wizard = new ContractInputGenerationWizard(process, editingDomain(), store);
wizard.addPages();
final IWizardContainer wizardContainer = Mockito.mock(IWizardContainer.class);
......
/**
* Copyright (C) 2015 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.contract.ui.wizard;
import static org.assertj.core.api.Assertions.assertThat;
......
/**
* Copyright (C) 2015 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.contract.ui.wizard;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import org.bonitasoft.engine.bdm.model.field.RelationField;
import org.bonitasoft.engine.bdm.model.field.SimpleField;
import org.bonitasoft.studio.contract.core.mapping.FieldToContractInputMapping;
import org.bonitasoft.studio.contract.core.mapping.RelationFieldToContractInputMapping;
import org.bonitasoft.studio.contract.core.mapping.SimpleFieldToContractInputMapping;
import org.bonitasoft.studio.swt.rules.RealmWithDisplay;
import org.eclipse.jface.databinding.viewers.ObservableListTreeContentProvider;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mockito;
import com.google.common.collect.Lists;
/**
* @author aurelie
*/
public class FieldToContractInputMappingViewerCheckStateManagerTest {
@Rule
public RealmWithDisplay realmWithDisplay = new RealmWithDisplay();
@Test
public void should_selectParentIfChildIsSelected() {
final FieldToContractInputMappingViewerCheckStateManager checkedStateManager = new FieldToContractInputMappingViewerCheckStateManager();
final FieldToContractInputMapping rootMapping = new RelationFieldToContractInputMapping(Mockito.mock(RelationField.class));
final SimpleFieldToContractInputMapping childMapping = new SimpleFieldToContractInputMapping(Mockito.mock(SimpleField.class));
rootMapping.addChild(childMapping);
final CheckboxTreeViewer viewer = aCheckBoxTreeViewer(Lists.newArrayList(rootMapping));
checkedStateManager.checkStateChanged(new CheckStateChangedEvent(viewer, childMapping, true));
assertThat(viewer.getChecked(rootMapping)).isTrue();
}
@Test
public void should_deselectParent_IfNoChildIsSelected() {
final FieldToContractInputMappingViewerCheckStateManager checkedStateManager = new FieldToContractInputMappingViewerCheckStateManager();
final FieldToContractInputMapping rootMapping = new RelationFieldToContractInputMapping(Mockito.mock(RelationField.class));
final SimpleFieldToContractInputMapping childMapping = new SimpleFieldToContractInputMapping(Mockito.mock(SimpleField.class));
rootMapping.addChild(childMapping);
final CheckboxTreeViewer viewer = aCheckBoxTreeViewer(Lists.newArrayList(rootMapping));
checkedStateManager.checkStateChanged(new CheckStateChangedEvent(viewer, childMapping, false));
assertThat(viewer.getChecked(rootMapping)).isFalse();
}
private CheckboxTreeViewer aCheckBoxTreeViewer(final List<FieldToContractInputMapping> input) {
final CheckboxTreeViewer viewer = new CheckboxTreeViewer(realmWithDisplay.createComposite());
viewer.setContentProvider(new ObservableListTreeContentProvider(new FieldToContractInputMappingObservableFactory(),
new FieldToContractInputMappingTreeStructureAdvisor()));
viewer.setInput(input);
return viewer;
}
}
/**
* Copyright (C) 2015 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.contract.ui.wizard.labelProvider;
import static org.assertj.core.api.Assertions.assertThat;
......
/**
* Copyright (C) 2015 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.contract.ui.wizard.labelProvider;
import static org.assertj.core.api.Assertions.assertThat;
......
......@@ -15,6 +15,7 @@
package org.bonitasoft.studio.contract.core.mapping;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bonitasoft.engine.bdm.model.field.Field;
......@@ -54,7 +55,7 @@ public abstract class FieldToContractInputMapping {
}
public List<FieldToContractInputMapping> getChildren() {
return children;
return Collections.<FieldToContractInputMapping> unmodifiableList(children);
}
public FieldToContractInputMapping getParent() {
......
......@@ -217,11 +217,6 @@ public class ContractPropertySection extends AbstractBonitaDescriptionSection {
public void widgetSelected(final SelectionEvent e) {
openAddInputWizardDialog();
}
/**
*
*/
});
}
......
......@@ -45,7 +45,6 @@ public class AddInputContractFromDataWizardDialog extends FinishAndAddCustomWiza
final Button finishButton = getButton(IDialogConstants.FINISH_ID);
getFinishAndNewButton().moveAbove(finishButton);
finishButton.setText(IDialogConstants.FINISH_LABEL);
// finishButton.moveAbove(getFinishAndNewButton());
}
/*
......
......@@ -61,8 +61,6 @@ public class FieldToContractInputMappingViewerCheckStateManager implements IChec
checkboxTreeViewer.setSubtreeChecked(mapping, event.getChecked());
selectParentIfChildIsSelected(event, mapping, checkboxTreeViewer);
deselectParentIfNoChildSelected(event, mapping, checkboxTreeViewer);
// checkboxTreeViewer.setGrayChecked(mapping, isGrayed(mapping));
}
/**
......@@ -72,16 +70,16 @@ public class FieldToContractInputMappingViewerCheckStateManager implements IChec
*/
private void deselectParentIfNoChildSelected(final CheckStateChangedEvent event, final FieldToContractInputMapping mapping,
final CheckboxTreeViewer checkboxTreeViewer) {
if (!event.getChecked() && mapping.getParent() != null) {
final FieldToContractInputMapping parentMapping = mapping.getParent();
if (!event.getChecked() && parentMapping != null) {
boolean deselect = true;
for (final FieldToContractInputMapping m : mapping.getParent().getChildren()) {
for (final FieldToContractInputMapping m : parentMapping.getChildren()) {
if (checkboxTreeViewer.getChecked(m)) {
deselect = false;
}
}
// ALL CHILD ARE UNCHECKED
if (deselect) {
checkboxTreeViewer.setChecked(mapping.getParent(), false);
checkboxTreeViewer.setChecked(parentMapping, false);
}
}
}
......
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