Commit ebce75d6 authored by Romain Bioteau's avatar Romain Bioteau
Browse files

BS-13312

Renaming
parent a7d02af4
......@@ -31,7 +31,7 @@ expression=Expression
errorMessage=Error message
noInputReferencedInConstraintExpression=No input is referenced in the expression of constraint: {0}
unknownInputReferencedInConstraintExpression=Unknown input \"{0}\" is referenced in the expression of {1}
constraintEditorDescription=Type the constraint using MVEL scripting.
constraintEditorDescription=Type the constraint using Groovy scripting.
contentAssistHint=Use \"Ctrl + Space\" to trigger content assist.
addContentToConstraint=Add content to constraint {0}
editContentToConstraint=Edit content to constraint {0}
......
/**
* Copyright (C) 2014 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.core;
import static org.assertj.core.api.Assertions.assertThat;
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.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* @author Romain Bioteau
*
*/
public class ContractConstraintUtilTest {
private final ProcessFactory factory = ProcessFactory.eINSTANCE;
private Contract contract;
private ContractInput ageInput;
private ContractInput nameInput;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
contract = factory.createContract();
ageInput = factory.createContractInput();
ageInput.setName("age");
ageInput.setType(ContractInputType.INTEGER);
nameInput = factory.createContractInput();
nameInput.setName("name");
nameInput.setType(ContractInputType.TEXT);
contract.getInputs().add(ageInput);
contract.getInputs().add(nameInput);
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
@Test
public void should_retrieve_constraints_for_the_given_input() throws Exception {
final ContractConstraint c1 = ContractConstraintUtil.createConstraint("c1", "age > 18", "Must be an adult", ageInput);
final ContractConstraint c2 = ContractConstraintUtil.createConstraint("c2", "name.lenght < 300", "Name is too long", nameInput);
final ContractConstraint c3 = ContractConstraintUtil.createConstraint("c3", "!name.isEmpty() && age != 0", "Consistent input", nameInput, ageInput);
contract.getConstraints().add(c1);
contract.getConstraints().add(c2);
contract.getConstraints().add(c3);
assertThat(ContractConstraintUtil.getConstraintsForInput(contract, ageInput)).containsOnly(c1, c3);
assertThat(ContractConstraintUtil.getConstraintsForInput(contract, nameInput)).containsOnly(c2, c3);
}
}
......@@ -16,6 +16,7 @@ package org.bonitasoft.studio.contract.core;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
import static org.bonitasoft.studio.model.process.builders.ContractConstraintBuilder.aContractConstraint;
import static org.mockito.Matchers.anyList;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
......@@ -176,7 +177,9 @@ public class ContractEngineDefinitionBuilderTest {
@Test
public void should_build_create_a_contract_with_constraint() throws Exception {
final ContractInput nameInput = addInput(aContract, "name", ContractInputType.TEXT, "name of an employee");
aContract.getConstraints().add(ContractConstraintUtil.createConstraint("myConstraint", "name.length < 50", "name is too long", nameInput));
aContract.getConstraints().add(
aContractConstraint().withName("myConstraint").withExpression("name.length < 50").withErrorMessage("name is too long")
.havingInput(nameInput.getName()).build());
userTaskengineContractBuilder.build(aContract);
verify(taskBuilder).addContract();
verify(contractDefBuilder).addInput("name", Type.TEXT, "name of an employee", nameInput.isMultiple());
......
......@@ -15,12 +15,12 @@
package org.bonitasoft.studio.contract.core.validation;
import static org.assertj.core.api.Assertions.assertThat;
import static org.bonitasoft.studio.model.process.builders.ContractBuilder.aContract;
import static org.bonitasoft.studio.model.process.builders.ContractConstraintBuilder.aContractConstraint;
import static org.bonitasoft.studio.model.process.builders.ContractInputBuilder.aContractInput;
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.junit.Before;
import org.junit.Test;
......@@ -42,9 +42,8 @@ public class ContractConstraintInputValidatorTest {
@Test
public void should_validate_returns_a_valid_status() throws Exception {
final Contract contract = ProcessFactory.eINSTANCE.createContract();
final ContractInput input = addInput(contract, "name", ContractInputType.TEXT, null);
final ContractConstraint constraint = ContractConstraintUtil.createConstraint("name length", "", "", input);
final Contract contract = aContract().havingInput(aContractInput().withName("name")).build();
final ContractConstraint constraint = aContractConstraint().withName("name length").havingInput("name").build();
contract.getConstraints().add(constraint);
assertThat(validator.validate(constraint).isOK()).isTrue();
}
......@@ -52,7 +51,7 @@ public class ContractConstraintInputValidatorTest {
@Test
public void should_validate_returns_an_error_status_for_empty_inputs() throws Exception {
final Contract contract = ProcessFactory.eINSTANCE.createContract();
final ContractConstraint constraint = ContractConstraintUtil.createConstraint("name length", "", "");
final ContractConstraint constraint = aContractConstraint().withName("name length").build();
contract.getConstraints().add(constraint);
assertThat(validator.validate(constraint).isOK()).isFalse();
}
......@@ -60,19 +59,10 @@ public class ContractConstraintInputValidatorTest {
@Test
public void should_validate_returns_an_error_status_for_unknown_inputs() throws Exception {
final Contract contract = ProcessFactory.eINSTANCE.createContract();
final ContractConstraint constraint = ContractConstraintUtil.createConstraint("name length", "", "");
final ContractConstraint constraint = aContractConstraint().withName("name length").build();
constraint.getInputNames().add("unknownInput");
contract.getConstraints().add(constraint);
assertThat(validator.validate(constraint).isOK()).isFalse();
}
private ContractInput addInput(final Contract contract, final String inputName, final ContractInputType type, final String description) {
final ContractInput contractInput = ProcessFactory.eINSTANCE.createContractInput();
contractInput.setName(inputName);
contractInput.setType(type);
contractInput.setDescription(description);
contract.getInputs().add(contractInput);
return contractInput;
}
}
......@@ -22,18 +22,18 @@ import org.bonitasoft.studio.contract.i18n.Messages;
import org.eclipse.jdt.core.compiler.IProblem;
import org.junit.Test;
public class MVELProblemRequestorTest {
public class CompilationProblemRequestorTest {
@Test
public void should_be_active() throws Exception {
final MVELProblemRequestor mvelProblemRequestor = new MVELProblemRequestor();
final CompilationProblemRequestor mvelProblemRequestor = new CompilationProblemRequestor();
assertThat(mvelProblemRequestor.isActive()).isTrue();
}
@Test
public void should_insert_problem_when_accepting() throws Exception {
final MVELProblemRequestor mvelProblemRequestor = new MVELProblemRequestor();
final CompilationProblemRequestor mvelProblemRequestor = new CompilationProblemRequestor();
mvelProblemRequestor.acceptProblem(aProblem("An error message"));
......@@ -42,7 +42,7 @@ public class MVELProblemRequestorTest {
@Test
public void should_reset_problems_when_beginning_report() throws Exception {
final MVELProblemRequestor mvelProblemRequestor = new MVELProblemRequestor();
final CompilationProblemRequestor mvelProblemRequestor = new CompilationProblemRequestor();
mvelProblemRequestor.acceptProblem(aProblem("An error message"));
mvelProblemRequestor.beginReporting();
......@@ -52,7 +52,7 @@ public class MVELProblemRequestorTest {
@Test
public void should_print_a_human_readable_with_message_when_a_single_problem_has_been_found() throws Exception {
final MVELProblemRequestor mvelProblemRequestor = new MVELProblemRequestor();
final CompilationProblemRequestor mvelProblemRequestor = new CompilationProblemRequestor();
mvelProblemRequestor.acceptProblem(aProblem("An error message"));
......@@ -61,7 +61,7 @@ public class MVELProblemRequestorTest {
@Test
public void should_print_a_human_readable_message_when_several_problem_has_been_found() throws Exception {
final MVELProblemRequestor mvelProblemRequestor = new MVELProblemRequestor();
final CompilationProblemRequestor mvelProblemRequestor = new CompilationProblemRequestor();
mvelProblemRequestor.acceptProblem(aProblem("An error message"));
mvelProblemRequestor.acceptProblem(aProblem("Another error message"));
......
......@@ -47,7 +47,7 @@ public class ConstraintExpressionEditorValidatorTest {
@Test
public void should_fails_with_compilation_error() throws Exception {
final MVELProblemRequestor requestor = mock(MVELProblemRequestor.class);
final CompilationProblemRequestor requestor = mock(CompilationProblemRequestor.class);
final ConstraintExpressionEditorValidator validator = new ConstraintExpressionEditorValidator(anExpressionContentObservable("return true &&"), null,
mock(GroovyCompilationUnit.class), requestor);
when(requestor.isEmpty()).thenReturn(false);
......@@ -60,7 +60,7 @@ public class ConstraintExpressionEditorValidatorTest {
@Test
public void should_warn_with_no_input_referenced() throws Exception {
final MVELProblemRequestor requestor = mock(MVELProblemRequestor.class);
final CompilationProblemRequestor requestor = mock(CompilationProblemRequestor.class);
when(requestor.isEmpty()).thenReturn(true);
final ConstraintExpressionEditorValidator validator = new ConstraintExpressionEditorValidator(anExpressionContentObservable("return true;"),
anInputNamesListObservable(),
......@@ -73,7 +73,7 @@ public class ConstraintExpressionEditorValidatorTest {
@Test
public void should_pass_without_errors() throws Exception {
final MVELProblemRequestor requestor = mock(MVELProblemRequestor.class);
final CompilationProblemRequestor requestor = mock(CompilationProblemRequestor.class);
when(requestor.isEmpty()).thenReturn(true);
final ConstraintExpressionEditorValidator validator = new ConstraintExpressionEditorValidator(anExpressionContentObservable("return true;"),
anInputNamesListObservable("input1"),
......
......@@ -34,10 +34,10 @@ import org.mockito.runners.MockitoJUnitRunner;
*
*/
@RunWith(MockitoJUnitRunner.class)
public class MVELEditorTest {
public class ContractConstraintEditorTest {
@Mock
private MVELEditor editor;
private ContractConstraintEditor editor;
@Mock
private IMenuManager menuManager;
......
......@@ -5,12 +5,10 @@
* 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/>.
*/
......@@ -44,10 +42,8 @@ import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.osgi.framework.BundleContext;
/**
* @author Romain Bioteau
*
*/
@RunWith(MockitoJUnitRunner.class)
public class ContractConstraintExpressionWizardPageTest extends AbstractSWTTestCase {
......@@ -62,9 +58,9 @@ public class ContractConstraintExpressionWizardPageTest extends AbstractSWTTestC
@Mock
private GroovySourceViewerFactory groovySourceViewerFactory;
@Mock
private MVELEditorFactory editorFactory;
private ContractConstraintEditorFactory editorFactory;
@Mock
private MVELEditor editor;
private ContractConstraintEditor editor;
@Mock
private WebBrowserFactory browserFactory;
......@@ -136,9 +132,9 @@ public class ContractConstraintExpressionWizardPageTest extends AbstractSWTTestC
}
@Test
public void should_performHelp_open_browser_with_mvel_url() throws Exception {
public void should_performHelp_open_browser_with_groovy_getting_start_url() throws Exception {
wizardPage.createControl(composite);
wizardPage.performHelp();
verify(browserFactory).openExteranlBrowser(ContractConstraintExpressionWizardPage.MVEL_BASICS_URL);
verify(browserFactory).openExteranlBrowser(ContractConstraintExpressionWizardPage.GROOVY_BASICS_URL);
}
}
/**
* Copyright (C) 2014 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.core;
import java.util.ArrayList;
import java.util.List;
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.ProcessFactory;
/**
* @author Romain Bioteau
*
*/
public class ContractConstraintUtil {
private ContractConstraintUtil() {
}
public static List<ContractConstraint> getConstraintsForInput(final Contract contract, final ContractInput input) {
final List<ContractConstraint> result = new ArrayList<ContractConstraint>();
for (final ContractConstraint constraint : contract.getConstraints()) {
if (constraint.getInputNames().contains(input.getName())) {
result.add(constraint);
}
}
return result;
}
public static ContractConstraint createConstraint(final String name, final String expression, final String errorMessage, final ContractInput... inputs) {
final ContractConstraint c = ProcessFactory.eINSTANCE.createContractConstraint();
c.setName(name);
c.setExpression(expression);
c.setErrorMessage(errorMessage);
for (final ContractInput input : inputs) {
c.getInputNames().add(input.getName());
}
return c;
}
}
......@@ -21,7 +21,7 @@ import org.bonitasoft.studio.contract.i18n.Messages;
import org.eclipse.jdt.core.IProblemRequestor;
import org.eclipse.jdt.core.compiler.IProblem;
public class MVELProblemRequestor implements IProblemRequestor {
public class CompilationProblemRequestor implements IProblemRequestor {
/*
* (non-Javadoc)
......
......@@ -36,12 +36,12 @@ public class ConstraintExpressionEditorValidator extends MultiValidator {
private final IObservableValue expressionObservable;
private final IObservableList dependenciesObservable;
private final GroovyCompilationUnit groovyCompilationUnit;
private final MVELProblemRequestor compilationErrorRequestor;
private final CompilationProblemRequestor compilationErrorRequestor;
public ConstraintExpressionEditorValidator(final IObservableValue expressionObservable,
final IObservableList dependenciesObservable,
final GroovyCompilationUnit groovyCompilationUnit,
final MVELProblemRequestor compilationErrorRequestor) {
final CompilationProblemRequestor compilationErrorRequestor) {
this.expressionObservable = expressionObservable;
this.dependenciesObservable = dependenciesObservable;
this.groovyCompilationUnit = groovyCompilationUnit;
......
......@@ -30,7 +30,6 @@ import org.eclipse.jface.text.contentassist.IContentAssistant;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.ui.texteditor.ITextEditor;
public class ConstraintExpressionSourceViewerConfiguration extends GroovyConfiguration {
public ConstraintExpressionSourceViewerConfiguration(final GroovyColorManager colorManager, final IPreferenceStore preferenceSource,
......@@ -38,8 +37,6 @@ public class ConstraintExpressionSourceViewerConfiguration extends GroovyConfigu
super(colorManager, preferenceSource, editor);
}
@SuppressWarnings({ "restriction", "unchecked" })
@Override
public IContentAssistant getContentAssistant(final ISourceViewer sourceViewer) {
final ContentAssistant contentAssistant = (ContentAssistant) super.getContentAssistant(sourceViewer);
......
......@@ -27,9 +27,9 @@ import org.eclipse.jface.action.IMenuManager;
* @author Romain Bioteau
*
*/
public class MVELEditor extends GroovyEditor {
public class ContractConstraintEditor extends GroovyEditor {
public MVELEditor() {
public ContractConstraintEditor() {
super();
setPreferenceStore(GroovyPlugin.getDefault().getPreferenceStore());
}
......
......@@ -22,10 +22,10 @@ package org.bonitasoft.studio.contract.ui.property.constraint.edit.editor;
* @author Romain Bioteau
*
*/
public class MVELEditorFactory {
public class ContractConstraintEditorFactory {
public MVELEditor newInstance() {
return new MVELEditor();
public ContractConstraintEditor newInstance() {
return new ContractConstraintEditor();
}
}
......@@ -53,7 +53,7 @@ public class ContractConstraintExpressionWizard extends Wizard {
public void addPages() {
page = new ContractConstraintExpressionWizardPage(constraintWorkingCopy,
inputs, new GroovySourceViewerFactory(),
new MVELEditorFactory(),
new ContractConstraintEditorFactory(),
new WebBrowserFactory());
if (constraintWorkingCopy.getExpression() == null
|| constraintWorkingCopy.getExpression().isEmpty()) {
......
......@@ -54,7 +54,7 @@ import org.eclipse.ui.views.properties.IPropertySourceProvider;
*/
public class ContractConstraintExpressionWizardPage extends WizardPage implements IDocumentListener {
protected static final String MVEL_BASICS_URL = "http://mvel.codehaus.org/Language+Guide+for+2.0";
protected static final String GROOVY_BASICS_URL = "http://groovy-lang.org/single-page-documentation.html";
private final ContractConstraint constraint;
private final List<ContractInput> inputs;
......@@ -63,14 +63,14 @@ public class ContractConstraintExpressionWizardPage extends WizardPage implement
private GroovyViewer groovyViewer;
private final GroovySourceViewerFactory groovyViewerFactory;
private final MVELEditorFactory editorFactory;
private final ContractConstraintEditorFactory editorFactory;
private final WebBrowserFactory browserFactory;
public ContractConstraintExpressionWizardPage(final ContractConstraint constraint,
final List<ContractInput> inputs,
final GroovySourceViewerFactory sourceViewerFactory,
final MVELEditorFactory editorFactory,
final ContractConstraintEditorFactory editorFactory,
final WebBrowserFactory browserFactory) {
super(ContractConstraintExpressionWizardPage.class.getName());
setDescription(Messages.constraintEditorDescription);
......@@ -113,7 +113,7 @@ public class ContractConstraintExpressionWizardPage extends WizardPage implement
inputIndexer = new ConstraintInputIndexer(constraint, inputs, viewer.getGroovyCompilationUnit());
getSourceViewer().getDocument().set(expressionContentObservable.getValue().toString());
context.addValidationStatusProvider(new ConstraintExpressionEditorValidator(expressionContentObservable, inputsObservable, viewer
.getGroovyCompilationUnit(), new MVELProblemRequestor()));
.getGroovyCompilationUnit(), new CompilationProblemRequestor()));
final CLabel contentAssistHint = new CLabel(container, SWT.NONE);
contentAssistHint.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).create());
......@@ -152,9 +152,9 @@ public class ContractConstraintExpressionWizardPage extends WizardPage implement
@Override
public void performHelp() {
try {
browserFactory.openExteranlBrowser(MVEL_BASICS_URL);
browserFactory.openExteranlBrowser(GROOVY_BASICS_URL);
} catch (final MalformedURLException e) {
BonitaStudioLog.error("Invalid URL format for :" + MVEL_BASICS_URL, e, ContractPlugin.PLUGIN_ID);
BonitaStudioLog.error("Invalid URL format for :" + GROOVY_BASICS_URL, e, ContractPlugin.PLUGIN_ID);
}
}
......
......@@ -5,14 +5,12 @@
* 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
* 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/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.groovy.ui.dialog;
......@@ -58,178 +56,175 @@ import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.dialogs.FilteredTree;
import org.eclipse.ui.dialogs.PatternFilter;
/**
* @author Romain Bioteau
*
*/
public class GroovyEditorDocumentationDialogTray extends DialogTray {
private static final String GROOVY_DOC_LINK = "<a href=\"http://groovy.codehaus.org/Getting+Started+Guide\">"+Messages.groovyDocumentationLink+"</a>"; //$NON-NLS-1$ //$NON-NLS-2$
private static final String GROOVY_DOC_LINK = "<a href=\"http://groovy-lang.org/single-page-documentation.html\">" + Messages.groovyDocumentationLink + "</a>"; //$NON-NLS-1$ //$NON-NLS-2$
protected static final String GROOVY_BROWSER_ID = "org.bonitasoft.studio.groovy.browser"; //$NON-NLS-1$
private static final int SASH_LIMIT = 40;
private ListViewer categoriesList;
private FilteredTree functionsList;
private StyledText documenationText;
private final GroovyViewer viewer;
private HTMLTextPresenter fPresenter;
private HTMLTextPresenter fPresenter;
private String javadocHtml;
private final TextPresentation fPresentation= new TextPresentation();