Commit 9b18367b authored by Romain Bioteau's avatar Romain Bioteau
Browse files

Update test coverage

parent 754317ca
......@@ -52,22 +52,26 @@ public abstract class AbstractBonitaDescriptionSection extends AbstractModelerPr
public void createControls(final Composite parent, final TabbedPropertySheetPage aTabbedPropertySheetPage) {
super.createControls(parent, aTabbedPropertySheetPage);
parent.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).create());
tabbedPropertySheetPage=aTabbedPropertySheetPage;
final TabbedPropertySheetWidgetFactory widgetFactory = tabbedPropertySheetPage.getWidgetFactory();
form = widgetFactory.createForm(parent);
form.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).create());
form.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
form.getBody().setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).create());
form.getBody().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
final Composite formBodyComposite = form.getBody();
formBodyComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).create());
formBodyComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
form.setToolBarVerticalAlignment(SWT.CENTER);
final TogglePropertyHelpContributionItem togglePropertyHelpContributionItem = new TogglePropertyHelpContributionItem(widgetFactory, form,
getSectionDescription());
form.getToolBarManager().add(togglePropertyHelpContributionItem);
form.getToolBarManager().update(true);
form.setText(getSectionTitle());
form.getMenuManager().add(togglePropertyHelpContributionItem);
createContent(form.getBody());
createContent(formBodyComposite);
form.update();
form.setFocus();
}
......
......@@ -37,7 +37,6 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.9.0",
Bundle-Activator: org.bonitasoft.studio.contract.ContractPlugin
Bundle-ActivationPolicy: lazy
Export-Package: org.bonitasoft.studio.contract.core,
org.bonitasoft.studio.contract.core.exception,
org.bonitasoft.studio.contract.core.validation,
org.bonitasoft.studio.contract.i18n;x-friends:="org.bonitasoft.studio.swtbot.framework"
Import-Package: org.bonitasoft.engine.bpm,
......
......@@ -22,7 +22,7 @@ constraintsTabLabel=Constraints
contractInputTypeLabel=Contract Input
removeInputConfirmationMessage=Are you sure you want to remove following input ?\nIf this input is COMPLEX it will remove all children.
removeInputConfirmationTitle=Remove contract input ?
removeInputConfirmationTitle=Remove contract constraint(s) ?
removeConstraintConfirmationTitle=Remove contract constraint(s) ?
removeConstraintConfirmationMessage=Are you sure you want to remove following constraint(s) ?
returnType=Return type
up=Up
......
......@@ -18,12 +18,16 @@ package org.bonitasoft.studio.contract.core.validation;
import static org.assertj.core.api.Assertions.assertThat;
import org.bonitasoft.studio.contract.ContractPlugin;
import org.bonitasoft.studio.contract.core.ContractConstraintUtil;
import org.bonitasoft.studio.model.process.Contract;
import org.bonitasoft.studio.model.process.ContractConstraint;
import org.bonitasoft.studio.model.process.ContractInput;
import org.bonitasoft.studio.model.process.ContractInputType;
import org.bonitasoft.studio.model.process.ProcessFactory;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -92,6 +96,31 @@ public class ContractConstraintInputsValidationRuleTest {
assertThat(validationRule.getRuleId()).isEqualTo(ContractConstraintInputsValidationRule.CONSTRAINT_INPUTS_ID);
}
@Test
public void should_getMessage_return_status_message_for_single_status() throws Exception {
final IStatus status = ValidationStatus.error("a single status error message");
assertThat(validationRule.getMessage(status)).isEqualTo(status.getMessage());
}
@Test
public void should_getMessage_return_status_message_for_empty_multi_status() throws Exception {
final MultiStatus status = new MultiStatus(ContractPlugin.PLUGIN_ID, 0, "", null);
assertThat(validationRule.getMessage(status)).isEmpty();
}
@Test
public void should_getMessage_return_aggregated_status_message_for_mulit_status() throws Exception {
final MultiStatus status = new MultiStatus(ContractPlugin.PLUGIN_ID, 0, "", null);
status.add(ValidationStatus.error("a status error message 1"));
status.add(ValidationStatus.error("a status error message 2"));
assertThat(validationRule.getMessage(status)).contains("message 1", "message 2");
}
@Test(expected = IllegalArgumentException.class)
public void should_getMessage_throw_IllegalArgumentException_for_null_status() throws Exception {
validationRule.getMessage(null);
}
private ContractInput addInput(final Contract contract, final String inputName, final ContractInputType type, final String description) {
final ContractInput contractInput = ProcessFactory.eINSTANCE.createContractInput();
contractInput.setName(inputName);
......
package org.bonitasoft.studio.contract.core.validation;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class DefaultMessageManagerTest {
private DefaultMessageManager defaultMessageManager;
@Before
public void setUp() throws Exception {
defaultMessageManager = new DefaultMessageManager();
}
@After
public void tearDown() throws Exception {
}
@Test
public void testAddMessageObjectStringObjectInt() throws Exception {
defaultMessageManager.addMessage(null, null, null, 0);
}
@Test
public void testAddMessageObjectStringObjectIntControl() throws Exception {
defaultMessageManager.addMessage(null, null, null, 0, null);
}
@Test
public void testCreateSummary() throws Exception {
defaultMessageManager.createSummary(null);
}
@Test
public void testGetDecorationPosition() throws Exception {
defaultMessageManager.getDecorationPosition();
}
@Test
public void testGetMessagePrefixProvider() throws Exception {
defaultMessageManager.getMessagePrefixProvider();
}
@Test
public void testIsAutoUpdate() throws Exception {
defaultMessageManager.isAutoUpdate();
}
@Test
public void testRemoveAllMessages() throws Exception {
defaultMessageManager.removeAllMessages();
}
@Test
public void testRemoveMessageObject() throws Exception {
defaultMessageManager.removeMessage(null);
}
@Test
public void testRemoveMessageObjectControl() throws Exception {
defaultMessageManager.removeMessage(null, null);
}
@Test
public void testRemoveMessages() throws Exception {
defaultMessageManager.removeMessages();
}
@Test
public void testRemoveMessagesControl() throws Exception {
defaultMessageManager.removeMessages(null);
}
@Test
public void testSetAutoUpdate() throws Exception {
defaultMessageManager.setAutoUpdate(false);
}
@Test
public void testSetDecorationPosition() throws Exception {
defaultMessageManager.setDecorationPosition(0);
}
@Test
public void testSetMessagePrefixProvider() throws Exception {
defaultMessageManager.setMessagePrefixProvider(null);
}
@Test
public void testUpdate() throws Exception {
defaultMessageManager.update();
}
}
......@@ -17,24 +17,19 @@
package org.bonitasoft.studio.contract.ui.property;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
import org.bonitasoft.studio.contract.ui.property.input.CellEditorControlAdapter;
import org.bonitasoft.studio.swt.AbstractSWTTestCase;
import org.eclipse.jface.fieldassist.ControlDecoration;
import org.eclipse.jface.fieldassist.FieldDecoration;
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
......@@ -43,16 +38,13 @@ import org.mockito.runners.MockitoJUnitRunner;
*
*/
@RunWith(MockitoJUnitRunner.class)
public class FieldDecoratorProviderTest {
public class FieldDecoratorProviderTest extends AbstractSWTTestCase {
@Spy
private FieldDecoratorProvider fieldDecoratorProvider;
@Mock
private Control control;
@Mock
private FieldDecoration fieldDecoration;
@Mock
private ControlDecoration controlDecoration;
......@@ -62,8 +54,9 @@ public class FieldDecoratorProviderTest {
*/
@Before
public void setUp() throws Exception {
doReturn(fieldDecoration).when(fieldDecoratorProvider).getDecorator(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
doReturn(controlDecoration).when(fieldDecoratorProvider).newControlDecoration(any(Control.class), anyInt());
final Composite composite = createDisplayAndRealm();
control = new Text(composite, SWT.NONE);
fieldDecoratorProvider = new FieldDecoratorProvider();
}
/**
......@@ -71,15 +64,20 @@ public class FieldDecoratorProviderTest {
*/
@After
public void tearDown() throws Exception {
dispose();
}
@Test
public void should_createControlDecorator_attach_a_ControlDecorator_to_a_Control() throws Exception {
final ControlDecoration decorator = fieldDecoratorProvider.createControlDecorator(control, "a description",
FieldDecorationRegistry.DEC_CONTENT_PROPOSAL, SWT.RIGHT);
assertThat(decorator).isEqualTo(controlDecoration);
verify(decorator).setDescriptionText("a description");
verify(decorator).setImage(any(Image.class));
verify(control).addControlListener(any(CellEditorControlAdapter.class));
assertThat(decorator.getControl()).isEqualTo(control);
assertThat(decorator.getDescriptionText()).isEqualTo("a description");
assertThat(decorator.getImage()).isNotNull();
}
@Test(expected = IllegalArgumentException.class)
public void should_getFieldDecorator_thorw_IllegalArgumentException() throws Exception {
fieldDecoratorProvider.getDecorator("fake type");
}
}
......@@ -17,16 +17,21 @@
package org.bonitasoft.studio.contract.ui.property.constraint.edit;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
import org.bonitasoft.studio.common.jface.SWTBotConstants;
import org.bonitasoft.studio.contract.ui.property.FieldDecoratorProvider;
import org.bonitasoft.studio.model.process.Contract;
import org.bonitasoft.studio.model.process.ContractConstraint;
import org.bonitasoft.studio.model.process.ProcessFactory;
import org.bonitasoft.studio.model.process.provider.ProcessItemProviderAdapterFactory;
import org.bonitasoft.studio.swt.AbstractSWTTestCase;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.IMessageManager;
import org.junit.After;
import org.junit.Before;
......@@ -41,9 +46,9 @@ import org.mockito.runners.MockitoJUnitRunner;
*
*/
@RunWith(MockitoJUnitRunner.class)
public class ConstraintErrorMessagePropertyEditingSupportTest {
public class ConstraintErrorMessagePropertyEditingSupportTest extends AbstractSWTTestCase {
@Mock
private ColumnViewer viewer;
private ConstraintErrorMessagePropertyEditingSupport propertyEditingSupport;
......@@ -59,12 +64,16 @@ public class ConstraintErrorMessagePropertyEditingSupportTest {
@Mock
private FieldDecoratorProvider decoratorProvider;
private Composite composite;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
composite = createDisplayAndRealm();
propertySourceProvider = new AdapterFactoryContentProvider(new ProcessItemProviderAdapterFactory());
viewer = new TableViewer(composite);
propertyEditingSupport = new ConstraintErrorMessagePropertyEditingSupport(viewer, propertySourceProvider);
}
......@@ -73,6 +82,16 @@ public class ConstraintErrorMessagePropertyEditingSupportTest {
*/
@After
public void tearDown() throws Exception {
dispose();
}
@Test
public void should_getCellEditor_create_a_cell_editor_with_swtbot_id_set() throws Exception {
final CellEditor cellEditor = propertyEditingSupport.getCellEditor(ProcessFactory.eINSTANCE.createContractConstraint());
assertThat(cellEditor).isNotNull();
assertThat(cellEditor.getControl()).isInstanceOf(Text.class);
assertThat(cellEditor.getControl().getData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY)).isEqualTo(
SWTBotConstants.SWTBOT_ID_CONSTRAINT_ERROR_MESSAGE_TEXTEDITOR);
}
@Test
......@@ -82,7 +101,6 @@ public class ConstraintErrorMessagePropertyEditingSupportTest {
contract.getConstraints().add(constraint);
propertyEditingSupport.setValue(constraint, "age is under 18");
assertThat(constraint.getErrorMessage()).isEqualTo("age is under 18");
verify(viewer).update(constraint, null);
}
}
......@@ -21,6 +21,7 @@ import static org.mockito.Mockito.verify;
import org.bonitasoft.studio.contract.core.validation.ContractDefinitionValidator;
import org.bonitasoft.studio.contract.ui.property.FieldDecoratorProvider;
import org.bonitasoft.studio.contract.ui.property.constraint.edit.editor.ContractConstraintExpressionDialogCellEditor;
import org.bonitasoft.studio.model.process.Contract;
import org.bonitasoft.studio.model.process.ContractConstraint;
import org.bonitasoft.studio.model.process.ProcessFactory;
......@@ -28,7 +29,9 @@ import org.bonitasoft.studio.model.process.provider.ProcessItemProviderAdapterFa
import org.bonitasoft.studio.swt.AbstractSWTTestCase;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.IMessageManager;
import org.junit.After;
......@@ -102,4 +105,10 @@ public class ConstraintExpressionPropertyEditingSupportTest extends AbstractSWTT
assertThat(propertyEditingSupport.canEdit(ProcessFactory.eINSTANCE.createContractInput())).isFalse();
}
@Test
public void should_getCellEditor_return() throws Exception {
propertyEditingSupport = new ConstraintExpressionPropertyEditingSupport(new TableViewer(container), propertySourceProvider, validator);
final CellEditor cellEditor = propertyEditingSupport.getCellEditor(ProcessFactory.eINSTANCE.createContractConstraint());
assertThat(cellEditor).isNotNull().isInstanceOf(ContractConstraintExpressionDialogCellEditor.class);
}
}
......@@ -16,6 +16,7 @@
*/
package org.bonitasoft.studio.contract.ui.property.constraint.edit.editor;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
......@@ -28,6 +29,7 @@ import org.bonitasoft.studio.model.process.provider.ProcessItemProviderAdapterFa
import org.bonitasoft.studio.swt.AbstractSWTTestCase;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.junit.After;
......@@ -51,6 +53,8 @@ public class ContractConstraintExpressionDialogCellEditorTest extends AbstractSW
@Mock
private ConstraintEditorFactory constraintEditorFactory;
private AdapterFactoryContentProvider adapterFactoryContentProvider;
@Mock
private WizardDialog wizardDialog;
/**
* @throws java.lang.Exception
......@@ -89,4 +93,16 @@ public class ContractConstraintExpressionDialogCellEditorTest extends AbstractSW
eq(adapterFactoryContentProvider));
}
@Test
public void should_openDialog_open_wizardDialog() throws Exception {
cellEditor.openDialog(wizardDialog);
verify(wizardDialog).open();
}
@Test
public void should_createWizard_return_a_new_ContractConstraintExpressionWizard() throws Exception {
final ContractConstraintExpressionWizard wizard = cellEditor.createWizard();
assertThat(wizard).isNotNull();
}
}
......@@ -109,14 +109,14 @@ public class ContractInputCompletionProposalComputerTest extends AbstractSWTTest
}
@Test
public void should_computeCompletionProposals_return_if_context_is_not_a_JavaContentAssistInvocationContext() throws Exception {
assertThat(proposalComputer.computeCompletionProposals(null, null)).isNull();
public void should_computeCompletionProposals_return_emptyList_if_context_is_not_a_JavaContentAssistInvocationContext() throws Exception {
assertThat(proposalComputer.computeCompletionProposals(null, null)).isEmpty();
}
@Test
public void should_computeCompletionProposals_log_BadLocationException_and_return_null() throws Exception {
public void should_computeCompletionProposals_log_BadLocationException_and_return_emptyList() throws Exception {
when(context.computeIdentifierPrefix()).thenThrow(new BadLocationException());
assertThat(proposalComputer.computeCompletionProposals(context, null)).isNull();
assertThat(proposalComputer.computeCompletionProposals(context, null)).isEmpty();
}
@Test
......
......@@ -227,6 +227,15 @@ public class ContractInputControllerTest extends AbstractSWTTestCase {
assertThat(((Contract) observableValue.getValue()).getInputs()).containsOnly(input1, input2, input3);
}
@Test
public void should_moveUp_do_nothing() throws Exception {
contractInputController.moveUp(viewer);
}
@Test
public void should_moveDown_do_nothing() throws Exception {
contractInputController.moveDown(viewer);
}
}
......@@ -17,9 +17,6 @@
package org.bonitasoft.studio.contract.ui.property.input.edit;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
......@@ -37,7 +34,9 @@ import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.widgets.Composite;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -55,18 +54,22 @@ public class ContractInputTypeEditingSupportTest extends AbstractSWTTestCase {
@Mock
private ColumnViewer viewer;
private ContractInputTypeEditingSupport contractInputTypeEditingSupport;
@Mock
private CellEditor cellEditor;
@Mock
private ViewerCell cell;
private Composite parent;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
createDisplayAndRealm();
parent = createDisplayAndRealm();
contractInputTypeEditingSupport = new ContractInputTypeEditingSupport(viewer,
new AdapterFactoryContentProvider(new ProcessItemProviderAdapterFactory()), new ContractInputController(
new ContractDefinitionValidator()));
......@@ -80,12 +83,19 @@ public class ContractInputTypeEditingSupportTest extends AbstractSWTTestCase {
dispose();
}
@Test
public void should_cancelEditor_and_editorValueChanged_doNothing() throws Exception {
contractInputTypeEditingSupport.cancelEditor();
contractInputTypeEditingSupport.editorValueChanged(true, true);
}
@Test
public void should_initializeCellEditorValue_add_ICellEditorListener() throws Exception {
contractInputTypeEditingSupport = spy(new ContractInputTypeEditingSupport(viewer,
viewer = new TableViewer(parent);
contractInputTypeEditingSupport = new ContractInputTypeEditingSupport(viewer,
new AdapterFactoryContentProvider(new ProcessItemProviderAdapterFactory()), new ContractInputController(
new ContractDefinitionValidator())));
doReturn(null).when(contractInputTypeEditingSupport).getValue(any(Object.class));
new ContractDefinitionValidator()));
when(cell.getElement()).thenReturn(ProcessFactory.eINSTANCE.createContractInput());
contractInputTypeEditingSupport.initializeCellEditorValue(cellEditor, cell);
verify(cellEditor).addListener(contractInputTypeEditingSupport);
<