Commit 32fcc193 authored by Romain Bioteau's avatar Romain Bioteau
Browse files

BS-14253

Fail selection validation if bo of a business data is missing
parent 1d54d7ff
......@@ -72,4 +72,5 @@ autoGeneratedOperationStepButton=Auto-generate storage operations
manuallyDefinedOperationStepButton=No, thanks. I'll manually define how to use the contract.
autoGeneratedOperationProcessButton=Auto-generate the initialization script
manuallyDefinedOperationProcessButton=No, thanks. I'll manually define how to use the contract.
contractStrictGenerationMsg=The contract inputs have been specified.\nA script that sets the default values of the business variable attributes with the contract input values will be generated. It can be viewed and edited in the Data tab. If the default value of a business variable already exists, this script will override it.\n\nContract inputs and the script can be edited manually.\nHowever, there is no refactoring (for example, updating the attribute name or a multiple property in a business object or contract element will break the script).
\ No newline at end of file
contractStrictGenerationMsg=The contract inputs have been specified.\nA script that sets the default values of the business variable attributes with the contract input values will be generated. It can be viewed and edited in the Data tab. If the default value of a business variable already exists, this script will override it.\n\nContract inputs and the script can be edited manually.\nHowever, there is no refactoring (for example, updating the attribute name or a multiple property in a business object or contract element will break the script).
invalidBusinessDataSelected=Invalid business data selected.
\ No newline at end of file
......@@ -15,10 +15,16 @@
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.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
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.ProcessFactory;
import org.bonitasoft.studio.swt.rules.RealmWithDisplay;
......@@ -26,7 +32,6 @@ import org.eclipse.core.databinding.observable.value.WritableValue;
import org.junit.Rule;
import org.junit.Test;
public class BusinessDataSelectedValidatorTest {
@Rule
......@@ -35,25 +40,46 @@ public class BusinessDataSelectedValidatorTest {
@Test
public void testValidate_OK() throws Exception {
final WritableValue selectedDataObservable = new WritableValue();
selectedDataObservable.setValue(new Object());
final BusinessObjectData businessObjectData = aBusinessData().withClassname("org.test.Employee").build();
selectedDataObservable.setValue(businessObjectData);
final List<Data> availableBusinessData = new ArrayList<Data>();
availableBusinessData.add(ProcessFactory.eINSTANCE.createData());
assertThat(new BusinessDataSelectedValidator(availableBusinessData, selectedDataObservable).validate().isOK()).isTrue();
final BusinessObjectModelRepositoryStore businessObjectStore = mock(BusinessObjectModelRepositoryStore.class);
when(businessObjectStore.getBusinessObjectByQualifiedName(businessObjectData.getClassName())).thenReturn(new BusinessObject());
assertThat(new BusinessDataSelectedValidator(availableBusinessData, selectedDataObservable, businessObjectStore).validate().isOK()).isTrue();
}
@Test
public void testValidate_KO_forEmptyBusinessData() throws Exception {
final WritableValue selectedDataObservable = new WritableValue();
final List<Data> availableBusinessData = new ArrayList<Data>();
assertThat(new BusinessDataSelectedValidator(availableBusinessData, selectedDataObservable).validate().isOK()).isFalse();
assertThat(
new BusinessDataSelectedValidator(availableBusinessData, selectedDataObservable, mock(BusinessObjectModelRepositoryStore.class)).validate()
.isOK()).isFalse();
}
@Test
public void testValidate_KO_forNoBusinessDataSelected() throws Exception {
final WritableValue selectedDataObservable = new WritableValue();
final BusinessObjectData businessObjectData = aBusinessData().withClassname("org.test.Employee").build();
selectedDataObservable.setValue(businessObjectData);
final List<Data> availableBusinessData = new ArrayList<Data>();
availableBusinessData.add(ProcessFactory.eINSTANCE.createData());
final BusinessObjectModelRepositoryStore businessObjectStore = mock(BusinessObjectModelRepositoryStore.class);
when(businessObjectStore.getBusinessObjectByQualifiedName(businessObjectData.getClassName())).thenReturn(null);
assertThat(new BusinessDataSelectedValidator(availableBusinessData, selectedDataObservable, 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());
assertThat(new BusinessDataSelectedValidator(availableBusinessData, selectedDataObservable).validate().isOK()).isFalse();
assertThat(
new BusinessDataSelectedValidator(availableBusinessData, selectedDataObservable, mock(BusinessObjectModelRepositoryStore.class)).validate()
.isOK()).isFalse();
}
}
......@@ -101,4 +101,5 @@ public class Messages extends NLS {
public static String autoGeneratedOperationProcessButton;
public static String manuallyDefinedOperationProcessButton;
public static String contractStrictGenerationMsg;
public static String invalidBusinessDataSelected;
}
......@@ -16,7 +16,10 @@ package org.bonitasoft.studio.contract.ui.wizard;
import java.util.List;
import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelRepositoryStore;
import org.bonitasoft.studio.contract.i18n.Messages;
import org.bonitasoft.studio.model.process.BusinessObjectData;
import org.bonitasoft.studio.model.process.Data;
import org.eclipse.core.databinding.observable.value.WritableValue;
import org.eclipse.core.databinding.validation.MultiValidator;
......@@ -28,16 +31,20 @@ public final class BusinessDataSelectedValidator extends MultiValidator {
private final List<Data> availableBusinessData;
private final WritableValue selectedDataObservable;
private final BusinessObjectModelRepositoryStore businessObjectStore;
public BusinessDataSelectedValidator(final List<Data> availableBusinessData, final WritableValue selectedDataObservable) {
public BusinessDataSelectedValidator(final List<Data> availableBusinessData, final WritableValue selectedDataObservable,
final BusinessObjectModelRepositoryStore businessObjectStore) {
this.availableBusinessData = availableBusinessData;
this.selectedDataObservable = selectedDataObservable;
this.businessObjectStore = businessObjectStore;
}
@Override
protected IStatus validate() {
if (selectedDataObservable.getValue() != null) {
return Status.OK_STATUS;
final BusinessObjectData value = (BusinessObjectData) selectedDataObservable.getValue();
return toBusinessObject(value) != null ? Status.OK_STATUS : ValidationStatus.error(Messages.invalidBusinessDataSelected);
} else {
if (availableBusinessData.isEmpty()) {
return ValidationStatus.warning(Messages.warningAddFromData_noDataAvailable);
......@@ -46,4 +53,8 @@ public final class BusinessDataSelectedValidator extends MultiValidator {
}
}
}
}
\ No newline at end of file
private BusinessObject toBusinessObject(final BusinessObjectData selectedData) {
return businessObjectStore.getBusinessObjectByQualifiedName(selectedData.getClassName());
}
}
......@@ -88,7 +88,7 @@ public class SelectBusinessDataWizardPage extends WizardPage {
final IViewerObservableValue observeSingleSelection = ViewersObservables.observeSingleSelection(businessDataTableViewer);
dbc.bindValue(observeSingleSelection, selectedDataObservable);
final MultiValidator multiValidator = new BusinessDataSelectedValidator(availableBusinessData, selectedDataObservable);
final MultiValidator multiValidator = new BusinessDataSelectedValidator(availableBusinessData, selectedDataObservable, businessObjectStore);
dbc.addValidationStatusProvider(multiValidator);
WizardPageSupport.create(this, dbc);
}
......
Supports Markdown
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