Commit ca7f1dfe authored by Bonita CI's avatar Bonita CI
Browse files

Merge branch 'CoreProduct' into 'master'

parents 89aae9cb c6c288bf
/**
* Copyright (C) 2012-2014 Bonitasoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* Copyright (C) 2012-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
......@@ -180,6 +180,7 @@ public class ExportRepositoryWizardPage extends WizardPage {
@Override
public void widgetSelected(final SelectionEvent e) {
checkedElementsObservable.clear();
final ITreeContentProvider provider = (ITreeContentProvider) treeViewer.getContentProvider();
checkedElementsObservable.addAll(Arrays.asList(provider.getElements(stores)));
}
......
......@@ -19,7 +19,9 @@ import static com.google.common.collect.Iterables.find;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import org.bonitasoft.engine.bpm.document.DocumentValue;
import org.bonitasoft.studio.common.DataUtil;
import org.bonitasoft.studio.common.ExpressionConstants;
import org.bonitasoft.studio.common.Messages;
......@@ -401,7 +403,7 @@ public class ExpressionHelper {
public static Operation createDefaultConnectorOutputOperation(final Output output) {
final Operation operation = ExpressionFactory.eINSTANCE.createOperation();
final Operator assignment = ExpressionFactory.eINSTANCE.createOperator();
assignment.setType(ExpressionConstants.ASSIGNMENT_OPERATOR);
assignment.setType(isDocumentValue(output) ? ExpressionConstants.SET_DOCUMENT_OPERATOR : ExpressionConstants.ASSIGNMENT_OPERATOR);
operation.setOperator(assignment);
final Expression rightOperand = ExpressionFactory.eINSTANCE.createExpression();
......@@ -417,6 +419,10 @@ public class ExpressionHelper {
return operation;
}
private static boolean isDocumentValue(Output output) {
return Objects.equals(DocumentValue.class.getName(), output.getType());
}
public static Data dataFromIteratorExpression(final MultiInstantiable parentFlowElement, final Expression iteratorExpression, final MainProcess mainProcess) {
final String returnType = iteratorExpression.getReturnType();
Data d = null;
......
......@@ -12,7 +12,7 @@
* 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.designer.ui.property.section.control;
package org.bonitasoft.studio.common.widgets;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.widgets.Composite;
......
......@@ -45,8 +45,8 @@ nullable=Nullable
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 which contract input will be generated.
SelectBusinessDataWizardPageTitle=Select business data or document
selectBusinessDataWizardPageDescription=Select business variable or document from which contract input will be generated.
generate=Add from data...
contractInputGenerationTitle=Add Contract input
rootContractInputName=Input name
......@@ -57,7 +57,7 @@ inputType=Input type
attributetype=Attribute type
atLeastOneAttributeShouldBeSelectedError=At least one attribute should be checked.
attributeName = Attribute name
warningAddFromData_noDataAvailable=Please create first a business variable from Data view.
warningAddFromData_noDataAvailable=Please create first a business variable from Data view or a document from Document view.
warningAddFromData_noDataSelected=Please select a business variable in the list.
reminderForStepMessage=From the contract definition, the Studio can automatically generate operations to store or update business variables.\nYou can then modify these operations if necessary.
reminderForProcessMessage=From the contract definition, the Studio can automatically generate scripts to initialize business variables.
......@@ -85,4 +85,12 @@ deselectAll=Deselect all
preview=Preview >
selectMandatories=Mandatory attributes
mandatoryFieldsNotSelectedWarning=Mandatory attribute(s) {0} is/are not selected. Either select it/them or initialize it/them manually.
mandatoryFieldsNotSelectedStepWarning=Mandatory attribute(s) {0} is/are not selected. Either select it/them or create storage and update operations.
\ No newline at end of file
mandatoryFieldsNotSelectedStepWarning=Mandatory attribute(s) {0} is/are not selected. Either select it/them or create storage and update operations.
businessVariable=Business variable
document=Document
warningAddFromData_noDocumentSelected=Please create first a document from document view.
warningAddFromData_noDocumentAvailable=Please select a Document in the list.
defaultValueAlreadyDefinedWarning=The document {0} is already initialized. Create input from this document will overwrite the current value of {0} by the value of contract input.
fileInputType=of type FILE
openUpdateDocumentOperationWarningTitle=Update document operation generation
openUpdateDocumentOperationWarningMessages=The contract input have been specified. Operations to set the value of document {0} with the contract input value will be generated. It can be viewed in the Operations pane.\nIf operation has already been generated for this input, it will not be replaced.
\ No newline at end of file
......@@ -15,7 +15,10 @@
package org.bonitasoft.studio.contract.ui.property;
import static org.assertj.core.api.Assertions.assertThat;
import static org.bonitasoft.studio.model.process.builders.BusinessObjectDataBuilder.aBusinessData;
import static org.bonitasoft.studio.model.process.builders.ContractBuilder.aContract;
import static org.bonitasoft.studio.model.process.builders.DataBuilder.aData;
import static org.bonitasoft.studio.model.process.builders.DocumentBuilder.aDocument;
import static org.bonitasoft.studio.model.process.builders.PoolBuilder.aPool;
import static org.bonitasoft.studio.model.process.builders.TaskBuilder.aTask;
import static org.mockito.Matchers.anyString;
......@@ -29,6 +32,7 @@ import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.contract.core.mapping.expression.FieldToContractInputMappingExpressionBuilder;
import org.bonitasoft.studio.contract.core.mapping.operation.FieldToContractInputMappingOperationBuilder;
import org.bonitasoft.studio.contract.i18n.Messages;
import org.bonitasoft.studio.data.ui.property.section.PoolAdaptableSelectionProvider;
import org.bonitasoft.studio.designer.ui.contribution.CreateAndEditFormContributionItem;
import org.bonitasoft.studio.model.process.Contract;
import org.bonitasoft.studio.model.process.ContractInput;
......@@ -74,6 +78,9 @@ public class ContractPropertySectionTest {
@Mock
private ContractContainerAdaptableSelectionProvider selectionProvider;
@Mock
private PoolAdaptableSelectionProvider poolSelectionProvider;
@Mock
private CreateAndEditFormContributionItem contributionItem;
......@@ -109,7 +116,8 @@ public class ContractPropertySectionTest {
@Before
public void setUp() throws Exception {
parent = realm.createComposite();
section = spy(new ContractPropertySection(sharedImages, eclipseContext, selectionProvider, repositoryAccessor, operationBuilder, expressionBuilder,
section = spy(new ContractPropertySection(sharedImages, eclipseContext, selectionProvider, poolSelectionProvider, repositoryAccessor, operationBuilder,
expressionBuilder,
progressService));
when(tabbedPropertySheetPage.getWidgetFactory()).thenReturn(new TabbedPropertySheetWidgetFactory());
doReturn(contributionItem).when(section).newContributionItem(CreateAndEditFormContributionItem.class);
......@@ -194,4 +202,34 @@ public class ContractPropertySectionTest {
doReturn(aTask().build()).when(selectionProvider).getAdapter(EObject.class);
assertThat(section.getSectionDescription()).isEqualTo(Messages.stepContractSectionDescription);
}
@Test
public void should_bindGenerateButtonEnablement_convert_boolean_value_to_true_when_pool_contains_business_variable() {
final Pool pool = aPool().havingContract(aContract()).havingData(aBusinessData().build()).build();
section.init(new WritableValue(pool.getContract(), Contract.class));
doReturn(new StructuredSelection(pool)).when(poolSelectionProvider).getSelection();
final Button button = new Button(parent, SWT.PUSH);
section.bindGenerateButtonEnablement(button);
assertThat(button.isEnabled()).isTrue();
}
@Test
public void should_bindGenerateButtonEnablement_convert_return_boolean_value_to_true_when_pool_contains_documents() {
final Pool pool = aPool().havingContract(aContract()).havingDocuments(aDocument().build()).build();
section.init(new WritableValue(pool.getContract(), Contract.class));
doReturn(new StructuredSelection(pool)).when(poolSelectionProvider).getSelection();
final Button button = new Button(parent, SWT.PUSH);
section.bindGenerateButtonEnablement(button);
assertThat(button.isEnabled()).isTrue();
}
@Test
public void should_bindGenerateButtonEnablement_convert_return_boolean_value_to_false_when_pool_contains_no_data() {
final Pool pool = aPool().havingContract(aContract()).havingData(aData().build()).build();
section.init(new WritableValue(pool.getContract(), Contract.class));
doReturn(new StructuredSelection(pool)).when(poolSelectionProvider).getSelection();
final Button button = new Button(parent, SWT.PUSH);
section.bindGenerateButtonEnablement(button);
assertThat(button.isEnabled()).isFalse();
}
}
......@@ -26,13 +26,14 @@ import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelRepositoryStore;
import org.bonitasoft.studio.model.process.BusinessObjectData;
import org.bonitasoft.studio.model.process.Data;
import org.bonitasoft.studio.model.process.Document;
import org.bonitasoft.studio.model.process.ProcessFactory;
import org.bonitasoft.studio.swt.rules.RealmWithDisplay;
import org.eclipse.core.databinding.observable.value.WritableValue;
import org.junit.Rule;
import org.junit.Test;
public class BusinessDataSelectedValidatorTest {
public class AvailableDataValidatorTest {
@Rule
public RealmWithDisplay realmWithDisplay = new RealmWithDisplay();
......@@ -47,7 +48,9 @@ public class BusinessDataSelectedValidatorTest {
final BusinessObjectModelRepositoryStore businessObjectStore = mock(BusinessObjectModelRepositoryStore.class);
when(businessObjectStore.getBusinessObjectByQualifiedName(businessObjectData.getClassName())).thenReturn(new BusinessObject());
assertThat(new BusinessDataSelectedValidator(availableBusinessData, selectedDataObservable, businessObjectStore).validate().isOK()).isTrue();
assertThat(
new AvailableDataValidator(availableBusinessData, selectedDataObservable, new ArrayList<Document>(), businessObjectStore)
.validate().isOK()).isTrue();
}
@Test
......@@ -55,7 +58,8 @@ public class BusinessDataSelectedValidatorTest {
final WritableValue selectedDataObservable = new WritableValue();
final List<Data> availableBusinessData = new ArrayList<Data>();
assertThat(
new BusinessDataSelectedValidator(availableBusinessData, selectedDataObservable, mock(BusinessObjectModelRepositoryStore.class)).validate()
new AvailableDataValidator(availableBusinessData, selectedDataObservable, new ArrayList<Document>(),
mock(BusinessObjectModelRepositoryStore.class)).validate()
.isOK()).isFalse();
}
......@@ -69,16 +73,21 @@ public class BusinessDataSelectedValidatorTest {
final BusinessObjectModelRepositoryStore businessObjectStore = mock(BusinessObjectModelRepositoryStore.class);
when(businessObjectStore.getBusinessObjectByQualifiedName(businessObjectData.getClassName())).thenReturn(null);
assertThat(new BusinessDataSelectedValidator(availableBusinessData, selectedDataObservable, businessObjectStore).validate().isOK()).isFalse();
assertThat(
new AvailableDataValidator(availableBusinessData, selectedDataObservable, new ArrayList<Document>(), businessObjectStore)
.validate().isOK()).isFalse();
}
@Test
public void testValidate_KO_forInvalidBusinessDataSelected() throws Exception {
final WritableValue selectedDataObservable = new WritableValue();
final List<Data> availableBusinessData = new ArrayList<Data>();
availableBusinessData.add(ProcessFactory.eINSTANCE.createData());
final BusinessObjectData data = ProcessFactory.eINSTANCE.createBusinessObjectData();
availableBusinessData.add(data);
selectedDataObservable.setValue(data);
assertThat(
new BusinessDataSelectedValidator(availableBusinessData, selectedDataObservable, mock(BusinessObjectModelRepositoryStore.class)).validate()
new AvailableDataValidator(availableBusinessData, selectedDataObservable, new ArrayList<Document>(),
mock(BusinessObjectModelRepositoryStore.class)).validate()
.isOK()).isFalse();
}
......
......@@ -27,6 +27,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelRepositoryStore;
import org.bonitasoft.studio.common.ExpressionConstants;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.contract.core.mapping.FieldToContractInputMapping;
import org.bonitasoft.studio.contract.core.mapping.expression.FieldToContractInputMappingExpressionBuilder;
......@@ -36,7 +37,11 @@ import org.bonitasoft.studio.groovy.ui.viewer.GroovyViewer;
import org.bonitasoft.studio.model.businessObject.BusinessObjectBuilder;
import org.bonitasoft.studio.model.businessObject.FieldBuilder.SimpleFieldBuilder;
import org.bonitasoft.studio.model.process.BusinessObjectData;
import org.bonitasoft.studio.model.process.ContractInputType;
import org.bonitasoft.studio.model.process.Document;
import org.bonitasoft.studio.model.process.DocumentType;
import org.bonitasoft.studio.model.process.Pool;
import org.bonitasoft.studio.model.process.ProcessFactory;
import org.bonitasoft.studio.model.process.Task;
import org.bonitasoft.studio.model.process.provider.ProcessItemProviderAdapterFactory;
import org.bonitasoft.studio.swt.rules.RealmWithDisplay;
......@@ -101,7 +106,7 @@ public class ContractInputGenerationWizardTest {
expressionBuilder, preferenceStore, sharedImages, dialogFactory, new ContractInputGenerationWizardPagesFactory(), sourceViewerFactory);
wizard.addPages();
assertThat(wizard.getPages()[0]).isInstanceOf(SelectBusinessDataWizardPage.class);
assertThat(wizard.getPages()[0]).isInstanceOf(SelectDataWizardPage.class);
}
@Test
......@@ -114,7 +119,7 @@ public class ContractInputGenerationWizardTest {
expressionBuilder, preferenceStore, sharedImages, dialogFactory, new ContractInputGenerationWizardPagesFactory(), sourceViewerFactory);
wizard.addPages();
assertThat(wizard.getPages()[0]).isInstanceOf(SelectBusinessDataWizardPage.class);
assertThat(wizard.getPages()[0]).isInstanceOf(SelectDataWizardPage.class);
}
@Test
......@@ -131,7 +136,7 @@ public class ContractInputGenerationWizardTest {
when(sourceViewerFactory.createSourceViewer(any(Composite.class), any(Boolean.class))).thenReturn(groovyViewer);
when(groovyViewer.getSourceViewer()).thenReturn(sourceViewer);
when(groovyViewer.getDocument()).thenReturn(document);
final ContractInputGenerationWizard wizard = new ContractInputGenerationWizard(process, editingDomain(), repositoryAccessor, operationBuilder,
expressionBuilder,
preferenceStore, sharedImages, dialogFactory, new ContractInputGenerationWizardPagesFactory(), sourceViewerFactory);
......@@ -141,8 +146,7 @@ public class ContractInputGenerationWizardTest {
wizard.setContainer(wizardContainer);
wizard.createPageControls(realmWithDisplay.createComposite());
wizard.performFinish();
assertThat(process.getContract().getInputs()).extracting("name").contains("employeeInput");
assertThat(process.getContract().getInputs()).extracting("name").contains("employee_input");
assertThat(process.getContract().getInputs().get(0).getInputs()).extracting("name").contains("firstName");
}
......@@ -151,7 +155,7 @@ public class ContractInputGenerationWizardTest {
final BusinessObjectData data = aBusinessData().withName("employee").withClassname("org.company.Employee").build();
final Pool process = aPool().havingContract(aContract()).build();
process.getData().add(data);
final BusinessObjectModelRepositoryStore store = mock(BusinessObjectModelRepositoryStore.class);
when(store.getBusinessObjectByQualifiedName("org.company.Employee")).thenReturn(
BusinessObjectBuilder.aBO("org.company.Employee").withField(SimpleFieldBuilder.aStringField("firstName").build()).build());
......@@ -192,7 +196,7 @@ public class ContractInputGenerationWizardTest {
when(sourceViewerFactory.createSourceViewer(any(Composite.class), any(Boolean.class))).thenReturn(groovyViewer);
when(groovyViewer.getSourceViewer()).thenReturn(sourceViewer);
when(groovyViewer.getDocument()).thenReturn(document);
final ContractInputGenerationWizard wizard = new ContractInputGenerationWizard(process, editingDomain(), repositoryAccessor, operationBuilder,
expressionBuilder,
preferenceStore, sharedImages, dialogFactory, new ContractInputGenerationWizardPagesFactory(), sourceViewerFactory);
......@@ -220,7 +224,7 @@ public class ContractInputGenerationWizardTest {
BusinessObjectBuilder.aBO("org.company.Employee").withField(SimpleFieldBuilder.aStringField("firstName").build()).build());
when(repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class)).thenReturn(store);
when(preferenceStore.getString(ContractInputGenerationInfoDialogFactory.SHOW_GENERATION_SUCCESS_DIALOG)).thenReturn("always");
final ContractInputGenerationWizard wizard = new ContractInputGenerationWizard(task, editingDomain(), repositoryAccessor, operationBuilder,
expressionBuilder,
preferenceStore, sharedImages, dialogFactory, new ContractInputGenerationWizardPagesFactory(), sourceViewerFactory);
......@@ -251,12 +255,12 @@ public class ContractInputGenerationWizardTest {
when(preferenceStore.getString(ContractInputGenerationInfoDialogFactory.SHOW_GENERATION_SUCCESS_DIALOG)).thenReturn("always");
when(operationBuilder.toOperation(any(BusinessObjectData.class), any(FieldToContractInputMapping.class))).thenReturn(
anOperation().build());
final ContractInputGenerationWizard wizard = new ContractInputGenerationWizard(task, editingDomain(), repositoryAccessor, operationBuilder,
expressionBuilder,
preferenceStore, sharedImages, dialogFactory, new ContractInputGenerationWizardPagesFactory(), sourceViewerFactory);
wizard.addPages();
final IWizardContainer wizardContainer = Mockito.mock(IWizardContainer.class);
when(wizardContainer.getShell()).thenReturn(realmWithDisplay.getShell());
wizard.setContainer(wizardContainer);
......@@ -266,22 +270,71 @@ public class ContractInputGenerationWizardTest {
assertThat(task.getOperations().isEmpty()).isFalse();
}
@Test
public void should_add_DocumentUpdateOperation_whenDataIsDocument_onFinish() {
final Task task = aTask().havingContract(aContract()).build();
final Pool process = aPool().havingContract(aContract()).build();
final Document document1 = ProcessFactory.eINSTANCE.createDocument();
document1.setName("myDocument");
process.getDocuments().add(document1);
process.getElements().add(task);
final ContractInputGenerationWizard wizard = new ContractInputGenerationWizard(task, editingDomain(), repositoryAccessor, operationBuilder,
expressionBuilder,
preferenceStore, sharedImages, dialogFactory, new ContractInputGenerationWizardPagesFactory(), sourceViewerFactory);
wizard.addPages();
final IWizardContainer wizardContainer = Mockito.mock(IWizardContainer.class);
when(wizardContainer.getShell()).thenReturn(realmWithDisplay.getShell());
wizard.setContainer(wizardContainer);
wizard.createPageControls(realmWithDisplay.createComposite());
wizard.performFinish();
assertThat(task.getContract().getInputs().get(0).getType()).isEqualTo(ContractInputType.FILE);
assertThat(task.getOperations().get(0).getLeftOperand().getName()).isEqualTo("myDocument");
assertThat(task.getOperations().get(0).getRightOperand().getType()).isEqualTo(ExpressionConstants.CONTRACT_INPUT_TYPE);
assertThat(task.getOperations().get(0).getRightOperand().getName()).isEqualTo("myDocument_doc_input");
}
@Test
public void should_add_FileInput_whenDataIsDocument_onFinish() {
final Pool process = aPool().havingContract(aContract()).build();
process.getDocuments().add(ProcessFactory.eINSTANCE.createDocument());
when(sourceViewerFactory.createSourceViewer(any(Composite.class), any(Boolean.class))).thenReturn(groovyViewer);
when(groovyViewer.getSourceViewer()).thenReturn(sourceViewer);
when(groovyViewer.getDocument()).thenReturn(document);
final ContractInputGenerationWizard wizard = new ContractInputGenerationWizard(process, editingDomain(), repositoryAccessor, operationBuilder,
expressionBuilder,
preferenceStore, sharedImages, dialogFactory, new ContractInputGenerationWizardPagesFactory(), sourceViewerFactory);
wizard.addPages();
final IWizardContainer wizardContainer = Mockito.mock(IWizardContainer.class);
when(wizardContainer.getShell()).thenReturn(realmWithDisplay.getShell());
wizard.setContainer(wizardContainer);
wizard.createPageControls(realmWithDisplay.createComposite());
wizard.performFinish();
assertThat(process.getContract().getInputs().get(0).getType()).isEqualTo(ContractInputType.FILE);
assertThat(process.getDocuments().get(0).getDocumentType()).isEqualTo(DocumentType.CONTRACT);
}
@Test
public void should_canFinish_return_false_when_no_data_is_defined() {
final Pool process = aPool().havingContract(aContract()).build();
when(sourceViewerFactory.createSourceViewer(any(Composite.class), any(Boolean.class))).thenReturn(groovyViewer);
when(groovyViewer.getSourceViewer()).thenReturn(sourceViewer);
when(groovyViewer.getDocument()).thenReturn(document);
final ContractInputGenerationWizard wizard = new ContractInputGenerationWizard(process, editingDomain(), repositoryAccessor, operationBuilder,
expressionBuilder, preferenceStore, sharedImages, dialogFactory, new ContractInputGenerationWizardPagesFactory(), sourceViewerFactory);
wizard.addPages();
final IWizardContainer wizardContainer = Mockito.mock(IWizardContainer.class);
when(wizardContainer.getShell()).thenReturn(realmWithDisplay.getShell());
wizard.setContainer(wizardContainer);
wizard.createPageControls(realmWithDisplay.createComposite());
assertThat(wizard.canFinish()).isFalse();
}
......@@ -290,7 +343,7 @@ public class ContractInputGenerationWizardTest {
final Pool process = aPool().havingContract(aContract()).build();
final BusinessObjectData data = aBusinessData().withClassname("com.company.Employee").build();
process.getData().add(data);
final BusinessObjectModelRepositoryStore store = mock(BusinessObjectModelRepositoryStore.class);
Mockito.doReturn(BusinessObjectBuilder.aBO("com.company.Employee").withField(SimpleFieldBuilder.aTextField("name").build()).build()).when(store)
.getBusinessObjectByQualifiedName("com.company.Employee");
......@@ -298,16 +351,16 @@ public class ContractInputGenerationWizardTest {
when(sourceViewerFactory.createSourceViewer(any(Composite.class), any(Boolean.class))).thenReturn(groovyViewer);
when(groovyViewer.getSourceViewer()).thenReturn(sourceViewer);
when(groovyViewer.getDocument()).thenReturn(document);
final ContractInputGenerationWizard wizard = new ContractInputGenerationWizard(process, editingDomain(), repositoryAccessor, operationBuilder,
expressionBuilder, preferenceStore, sharedImages, dialogFactory, new ContractInputGenerationWizardPagesFactory(), sourceViewerFactory);
wizard.addPages();
final IWizardContainer wizardContainer = Mockito.mock(IWizardContainer.class);
when(wizardContainer.getShell()).thenReturn(realmWithDisplay.getShell());
wizard.setContainer(wizardContainer);
wizard.createPageControls(realmWithDisplay.createComposite());
assertThat(wizard.canFinish()).isTrue();
}
......
......@@ -68,7 +68,7 @@ public class CreateContractInputFromBusinessObjectWizardPageTest {
rootNameObservable.setValue("employeeInput");
final WritableList fieldToContractInputMappingsObservable = new WritableList();
final CreateContractInputFromBusinessObjectWizardPage page = new CreateContractInputFromBusinessObjectWizardPage(contract, options,
selectedDataObservable, rootNameObservable, new FieldToContractInputMappingFactory(), fieldToContractInputMappingsObservable, store);
selectedDataObservable, new FieldToContractInputMappingFactory(), fieldToContractInputMappingsObservable, store);
final FieldToContractInputMapping rootMapping1 = new RelationFieldToContractInputMapping(Mockito.mock(RelationField.class));
final SimpleFieldToContractInputMapping childMapping1 = new SimpleFieldToContractInputMapping(Mockito.mock(SimpleField.class));
final SimpleFieldToContractInputMapping childMapping2 = new SimpleFieldToContractInputMapping(Mockito.mock(SimpleField.class));
......@@ -100,7 +100,7 @@ public class CreateContractInputFromBusinessObjectWizardPageTest {
rootNameObservable.setValue("employeeInput");
final WritableList fieldToContractInputMappingsObservable = new WritableList();
final CreateContractInputFromBusinessObjectWizardPage page = new CreateContractInputFromBusinessObjectWizardPage(contract, options,
selectedDataObservable, rootNameObservable, new FieldToContractInputMappingFactory(), fieldToContractInputMappingsObservable, store);
selectedDataObservable, new FieldToContractInputMappingFactory(), fieldToContractInputMappingsObservable, store);
final FieldToContractInputMapping rootMapping1 = new RelationFieldToContractInputMapping(Mockito.mock(RelationField.class));
final SimpleFieldToContractInputMapping childMapping1 = new SimpleFieldToContractInputMapping(Mockito.mock(SimpleField.class));
final SimpleFieldToContractInputMapping childMapping2 = new SimpleFieldToContractInputMapping(Mockito.mock(SimpleField.class));
......@@ -132,7 +132,7 @@ public class CreateContractInputFromBusinessObjectWizardPageTest {
rootNameObservable.setValue("employeeInput");
final WritableList fieldToContractInputMappingsObservable = new WritableList();
final CreateContractInputFromBusinessObjectWizardPage page = new CreateContractInputFromBusinessObjectWizardPage(contract, options,
selectedDataObservable, rootNameObservable, new FieldToContractInputMappingFactory(), fieldToContractInputMappingsObservable, store);
selectedDataObservable, new FieldToContractInputMappingFactory(), fieldToContractInputMappingsObservable, store);
final FieldToContractInputMapping rootMapping1 = new RelationFieldToContractInputMapping(Mockito.mock(RelationField.class));
final SimpleFieldToContractInputMapping childMapping1 = new SimpleFieldToContractInputMapping(Mockito.mock(SimpleField.class));
final SimpleFieldToContractInputMapping childMapping2 = new SimpleFieldToContractInputMapping(Mockito.mock(SimpleField.class));
......@@ -162,7 +162,7 @@ public class CreateContractInputFromBusinessObjectWizardPageTest {
rootNameObservable.setValue("employeeInput");
final WritableList fieldToContractInputMappingsObservable = new WritableList();
final CreateContractInputFromBusinessObjectWizardPage page = new CreateContractInputFromBusinessObjectWizardPage(contract, options,
selectedDataObservable, rootNameObservable, new FieldToContractInputMappingFactory(), fieldToContractInputMappingsObservable, store);
selectedDataObservable, new FieldToContractInputMappingFactory(), fieldToContractInputMappingsObservable, store);
final RelationField rootField1 = Mockito.mock(RelationField.class);
final RelationField rootField2 = Mockito.mock(RelationField.class);
final SimpleField childField1 = Mockito.mock(SimpleField.class);
......
......@@ -15,6 +15,7 @@
package org.bonitasoft.studio.contract.ui.wizard;
import static org.assertj.core.api.Assertions.assertThat;
import static org.bonitasoft.studio.model.process.builders.BusinessObjectDataBuilder.aBusinessData;
import static org.bonitasoft.studio.model.process.builders.PoolBuilder.aPool;
import static org.mockito.Mockito.mock;
......@@ -25,9 +26,11 @@ 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.model.process.BusinessObjectData;
import org.bonitasoft.studio.swt.rules.RealmWithDisplay;
import org.eclipse.core.databinding.observable.set.IObservableSet;
import org.eclipse.core.databinding.observable.set.WritableSet;
import org.eclipse.core.databinding.observable.value.WritableValue;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -48,7 +51,10 @@ public class EmptySelectionMultivalidatorTest {
@Test
public void shouldReturnErrorWhenNoElementsAreChecked() {
final IObservableSet checkedElements = new WritableSet();
final EmptySelectionMultivalidator multiValidator = new EmptySelectionMultivalidator(checkedElements,
final WritableValue selectedDataObservable = new WritableValue();
final BusinessObjectData businessObjectData = aBusinessData().withClassname("org.test.Employee").build();
selectedDataObservable.setValue(businessObjectData);
final EmptySelectionMultivalidator multiValidator = new EmptySelectionMultivalidator(selectedDataObservable, checkedElements,
new ArrayList<FieldToContractInputMapping>(), aPool().build());
assertThat(multiValidator.validate().isOK()).isFalse();
}
......@@ -57,7 +63,10 @@ public class EmptySelectionMultivalidatorTest {
public void shouldReturnOkStatusWhenAtLeastOneElementIsChecked() {
final IObservableSet checkedElements = new WritableSet();
checkedElements.add(mock(FieldToContractInputMapping.class));
final EmptySelectionMultivalidator multiValidator = new EmptySelectionMultivalidator(checkedElements,
final WritableValue selectedDataObservable = new WritableValue();
final BusinessObjectData businessObjectData = aBusinessData().withClassname("org.test.Employee").build();
selectedDataObservable.setValue(businessObjectData);
final EmptySelectionMultivalidator multiValidator = new EmptySelectionMultivalidator(selectedDataObservable, checkedElements,
new ArrayList<FieldToContractInputMapping>(), aPool().build());
assertThat(multiValidator.validate().isOK()).isTrue();
}
......@@ -79,7 +88,10 @@ public class EmptySelectionMultivalidatorTest {
checkedElements.add(rootMapping1);
checkedElements.add(rootMapping2);
checkedElements.add(childMapping2);
final EmptySelectionMultivalidator multiValidator = new EmptySelectionMultivalidator(checkedElements,
final WritableValue selectedDataObservable = new WritableValue();
final BusinessObjectData businessObjectData = aBusinessData().withClassname("org.test.Employee").build();
selectedDataObservable.setValue(businessObjectData);
final EmptySelectionMultivalidator multiValidator = new EmptySelectionMultivalidator(selectedDataObservable, checkedElements,
Lists.newArrayList(rootMapping1, rootMapping2), aPool().build());
assertThat(multiValidator.validate().isOK()).isFalse();
}
......@@ -102,7 +114,10 @@ public class EmptySelectionMultivalidatorTest {
checkedElements.add(rootMapping2);
checkedElements.add(childMapping2);
checkedElements.add(childMapping1);
final EmptySelectionMultivalidator multiValidator = new EmptySelectionMultivalidator(checkedElements,