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

fix tests

parent 9c451c3a
......@@ -33,20 +33,7 @@ public final class AutomaticSwitchPerspectivePartListener implements IPartListen
@Override
public void partActivated(final MPart part) {
// if(!isSwitching){
// isSwitching = true;
// try{
// if (part.getElementId().equals("org.eclipse.e4.ui.compatibility.editor")) {
// String activePerspective = getActivePerspectiveId(part);
// final String id = BonitaPerspectivesUtils.getPerspectiveId(((CompatibilityEditor) part.getObject()).getEditor());
// if (id != null && !id.equals(activePerspective)) {
// BonitaPerspectivesUtils.switchToPerspective(id);
// }
// }
// }finally{
// isSwitching = false;
// }
// }
}
@Override
......
......@@ -37,6 +37,7 @@ import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.command.AddCommand;
import org.eclipse.emf.edit.command.RemoveCommand;
......@@ -68,8 +69,9 @@ public class ComparisonExpressionValidator implements IExpressionValidator {
}
final Injector injector = ConditionModelActivator.getInstance().getInjector(ConditionModelActivator.ORG_BONITASOFT_STUDIO_CONDITION_CONDITIONMODEL);
Resource resource = null;
final XtextComparisonExpressionLoader xtextComparisonExpressionLoader = new XtextComparisonExpressionLoader(injector);
try {
resource = new XtextComparisonExpressionLoader(injector).loadResource(value.toString(), context);
resource = xtextComparisonExpressionLoader.loadResource(value.toString(), context);
} catch (final ComparisonExpressionLoadException e) {
BonitaStudioLog.error(e);
return ValidationStatus.error(e.getMessage());
......@@ -78,7 +80,8 @@ public class ComparisonExpressionValidator implements IExpressionValidator {
final IResourceValidator xtextResourceChecker = injector.getInstance(IResourceValidator.class);
final MultiStatus status = new MultiStatus(ExpressionEditorPlugin.PLUGIN_ID, 0, "", null);
final ConditionModelJavaValidator validator = injector.getInstance(ConditionModelJavaValidator.class);
validator.setCurrentResourceSet(context.eResource().getResourceSet());
final ResourceSet resourceSet = context.eResource().getResourceSet();
validator.setCurrentResourceSet(resourceSet);
final List<Issue> issues = xtextResourceChecker.validate(resource, CheckMode.FAST_ONLY, null);
if(issues.isEmpty()){
......
......@@ -18,7 +18,9 @@ package org.bonitasoft.studio.condition.ui.expression;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bonitasoft.studio.common.emf.tools.ModelHelper;
......@@ -30,9 +32,8 @@ import org.bonitasoft.studio.condition.scoping.ConditionModelGlobalScopeProvider
import org.bonitasoft.studio.model.parameter.Parameter;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.bonitasoft.studio.model.process.Data;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
......@@ -70,26 +71,6 @@ public class XtextComparisonExpressionLoader {
return (Operation_Compare) contents.get(0);
}
protected IFile createTmpFile(final String content, final IProject project) throws IOException {
final IFile file = project.getFile("somefile.cmodel");
if (file.exists()) {
try {
file.delete(true, null);
} catch (final CoreException e) {
throw new IOException(e);
}
}
if (content != null && !content.isEmpty()) {
final InputStream is = new StringInputStream(content, "UTF-8");
try {
file.create(is, true, null);
} catch (final CoreException e) {
throw new IOException(e);
}
}
return file;
}
protected List<String> getAccessibleReferences(final EObject context) {
final List<String> accessibleObjects = new ArrayList<String>();
for (final Data d : ModelHelper.getAccessibleData(context)) {
......@@ -105,22 +86,22 @@ public class XtextComparisonExpressionLoader {
}
public Resource loadResource(final String comparisonExpression, final EObject context) throws ComparisonExpressionLoadException {
Assert.isLegal(comparisonExpression != null);
final XtextResourceSetProvider xtextResourceSetProvider = injector.getInstance(XtextResourceSetProvider.class);
final IProject project = RepositoryManager.getInstance().getCurrentRepository().getProject();
final ResourceSet resourceSet = xtextResourceSetProvider.get(project);
IFile file;
final Resource resource = resourceSet.createResource(URI.createFileURI("somefile.cmodel"));
InputStream inputStream;
try {
file = createTmpFile(comparisonExpression, project);
} catch (final IOException e) {
throw new ComparisonExpressionLoadException("Failed to create a temporary file for comparison expression " + comparisonExpression, e);
inputStream = new StringInputStream(comparisonExpression, "UTF-8");
} catch (final UnsupportedEncodingException e) {
throw new ComparisonExpressionLoadException("Failed to create StringInputString from expression.", e);
}
Resource resource = null;
if (file.exists()) {
resource = resourceSet.getResource(URI.createPlatformResourceURI(file.getFullPath().toOSString(), true), true);
} else {
resource = resourceSet.createResource(URI.createPlatformResourceURI(file.getFullPath().toOSString(), true));
try {
resource.load(inputStream, Collections.emptyMap());
} catch (final IOException e) {
throw new ComparisonExpressionLoadException("Failed to load Xtext resource.", e);
}
final ConditionModelGlobalScopeProvider globalScopeProvider = injector.getInstance(ConditionModelGlobalScopeProvider.class);
globalScopeProvider.setAccessibleEObjects(getAccessibleReferences(context));
return resource;
......
......@@ -20,7 +20,9 @@ import org.bonitasoft.studio.model.process.JavaObjectData;
import org.bonitasoft.studio.model.process.LongType;
import org.bonitasoft.studio.model.process.StringType;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.xtext.nodemodel.INode;
......@@ -107,7 +109,13 @@ public class ConditionModelJavaValidator extends AbstractConditionModelJavaValid
private String getDataType(final Expression_ProcessRef e) {
EObject reference = e.getValue();
if (reference.eIsProxy()) {
reference = EcoreUtil.resolve(reference, resourceSet);
final URI uri = EcoreUtil.getURI(reference);
if (uri.toString().contains(".proc")) {
final Resource resource = resourceSet.getResource(uri.trimFragment(), false);
if (resource != null) {
reference = resource.getEObject(uri.fragment());
}
}
}
if (reference instanceof JavaObjectData) {
final JavaObjectData javaData = (JavaObjectData) reference;
......
......@@ -118,13 +118,13 @@ public class DecisionTableWizardPage extends WizardPage {
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createControl(final Composite arg0) {
public void createControl(final Composite parent) {
if (decisionTable.getDefaultAction() == null && wizard.getPossibleDefaultTableActions() != null
&& wizard.getPossibleDefaultTableActions().length > 0) {
decisionTable.setDefaultAction(wizard.getPossibleDefaultTableActions()[0]);
}
final Composite res = new Composite(arg0, SWT.NONE);
final Composite res = new Composite(parent, SWT.NONE);
res.setLayout(new GridLayout(1, false));
final Group gridGroup = new Group(res, SWT.NONE);
......@@ -300,6 +300,7 @@ public class DecisionTableWizardPage extends WizardPage {
});
op1widget.setContext(container);
op1widget.addFilter(new AvailableExpressionTypeFilter(new String[]{ExpressionConstants.CONDITION_TYPE}));
op1widget.setContext(container);
op1widget.setInput(lineWorkingCopy);
op1widget.setSelection(new StructuredSelection(cond));
op1widget.getEraseControl().addListener(SWT.Selection, new Listener() {
......
......@@ -19,8 +19,6 @@ package org.bonitasoft.studio.engine.export.expression.converter.comparison;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
import java.io.File;
import org.bonitasoft.engine.expression.ExpressionType;
import org.bonitasoft.engine.expression.InvalidExpressionException;
import org.bonitasoft.studio.common.ExpressionConstants;
......@@ -40,10 +38,7 @@ import org.bonitasoft.studio.model.process.Data;
import org.bonitasoft.studio.model.process.builders.BooleanDataTypeBuilder;
import org.bonitasoft.studio.model.process.builders.DataBuilder;
import org.bonitasoft.studio.model.process.builders.DoubleDataTypeBuilder;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.xtext.resource.XtextResource;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
......@@ -210,22 +205,4 @@ public class ComparisonExpressionConverterTest {
assertThat(engineExpression.getDependencies()).isEmpty();
}
@Test
public void should_convert_a_studio_expression_into_an_engine_expression_clean_compare_resource() throws Exception {
final File newFile = folder.newFile("somcemodel.cmodel");
final URI fileURI = URI.createFileURI(newFile.getAbsolutePath());
final Resource resource = new XtextResource(fileURI);
assertThat(newFile).exists();
final Operation_Compare operation_Compare = ConditionModelFactory.eINSTANCE.createOperation_Compare();
final Operation_Unary unaryOperation = ConditionModelFactory.eINSTANCE.createOperation_Unary();
final Expression_ProcessRef processRef = ConditionModelFactory.eINSTANCE.createExpression_ProcessRef();
processRef.setValue(EcoreUtil.copy(validVariable));
unaryOperation.setValue(processRef);
operation_Compare.setOp(unaryOperation);
resource.getContents().add(operation_Compare);
when(loader.loadConditionExpression(unaryExpression.getContent(), null)).thenReturn(operation_Compare);
comparisonExpressionConverter.convert(unaryExpression);
assertThat(newFile).doesNotExist();
}
}
......@@ -16,13 +16,9 @@
*/
package org.bonitasoft.studio.engine.export.expression.converter.comparison;
import java.io.IOException;
import java.util.Collections;
import org.bonitasoft.engine.expression.ExpressionBuilder;
import org.bonitasoft.engine.expression.InvalidExpressionException;
import org.bonitasoft.studio.common.ExpressionConstants;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.condition.conditionModel.Operation_Compare;
import org.bonitasoft.studio.condition.conditionModel.Operation_NotUnary;
import org.bonitasoft.studio.condition.conditionModel.Unary_Operation;
......@@ -68,14 +64,6 @@ public class ComparisonExpressionConverter implements IExpressionConverter {
return null;
} catch (final ComparisonExpressionLoadException e) {
throw new InvalidExpressionException("Failed to load comparison expression");
} finally {
if (compare != null && compare.eResource() != null) {
try {
compare.eResource().delete(Collections.emptyMap());
} catch (final IOException e) {
BonitaStudioLog.error(e);
}
}
}
}
......
/**
* 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.model.connectorconfiguration.builders;
import org.bonitasoft.studio.model.connectorconfiguration.ConnectorConfiguration;
import org.bonitasoft.studio.model.connectorconfiguration.ConnectorConfigurationFactory;
/**
* @author Romain Bioteau
*
*/
public class ConnectorConfigurationBuilder {
public static ConnectorConfigurationBuilder create() {
return new ConnectorConfigurationBuilder();
}
private final ConnectorConfiguration instance;
public ConnectorConfigurationBuilder() {
instance = ConnectorConfigurationFactory.eINSTANCE.createConnectorConfiguration();
}
public ConnectorConfigurationBuilder havingParameter(final ConnectorParameterBuilder parameter) {
instance.getParameters().add(parameter.build());
return this;
}
public ConnectorConfiguration build() {
return instance;
}
}
/**
* 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.model.connectorconfiguration.builders;
import org.bonitasoft.studio.model.connectorconfiguration.ConnectorConfigurationFactory;
import org.bonitasoft.studio.model.connectorconfiguration.ConnectorParameter;
import org.bonitasoft.studio.model.expression.builders.ExpressionBuilder;
/**
* @author Romain Bioteau
*
*/
public class ConnectorParameterBuilder {
public static ConnectorParameterBuilder create() {
return new ConnectorParameterBuilder();
}
private final ConnectorParameter instance;
public ConnectorParameterBuilder() {
instance = ConnectorConfigurationFactory.eINSTANCE.createConnectorParameter();
}
public ConnectorParameterBuilder withKey(final String key) {
instance.setKey(key);
return this;
}
public ConnectorParameterBuilder havingExpression(final ExpressionBuilder expression) {
instance.setExpression(expression.build());
return this;
}
public ConnectorParameter build() {
return instance;
}
}
/**
* 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.model.process.builders;
import org.bonitasoft.studio.model.connectorconfiguration.builders.ConnectorConfigurationBuilder;
import org.bonitasoft.studio.model.process.Connector;
import org.bonitasoft.studio.model.process.ProcessFactory;
/**
* @author Romain Bioteau
*
*/
public class ConnectorBuilder extends ElementBuilder<Connector, ConnectorBuilder> {
public static ConnectorBuilder createConnectorBuilder() {
return new ConnectorBuilder();
}
public ConnectorBuilder withDefinitionId(final String definitionId) {
getBuiltInstance().setDefinitionId(definitionId);
return getThis();
}
public ConnectorBuilder withDefinitionVersion(final String definitionVersion) {
getBuiltInstance().setDefinitionVersion(definitionVersion);
return getThis();
}
public ConnectorBuilder onEvent(final String event) {
getBuiltInstance().setEvent(event);
return getThis();
}
public ConnectorBuilder havingConfiguration(final ConnectorConfigurationBuilder connectorConfiguration) {
getBuiltInstance().setConfiguration(connectorConfiguration.build());
return getThis();
}
@Override
protected Connector newInstance() {
return ProcessFactory.eINSTANCE.createConnector();
}
}
......@@ -17,11 +17,7 @@
*/
package org.bonitasoft.studio.validation.constraints.process;
import java.io.IOException;
import java.util.Collections;
import org.bonitasoft.studio.common.ExpressionConstants;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.condition.conditionModel.Operation_Compare;
import org.bonitasoft.studio.condition.ui.expression.ComparisonExpressionLoadException;
import org.bonitasoft.studio.condition.ui.expression.XtextComparisonExpressionLoader;
......@@ -73,13 +69,6 @@ public class ConditionExpressionConstraint extends AbstractLiveValidationMarkerC
if(opCompare == null || opCompare.getOp() == null){
return ctx.createFailureStatus(Messages.bind(Messages.invalidConditionExpression,conditionExpression.getName()));
}
if (opCompare != null && opCompare.eResource() != null) {
try {
opCompare.eResource().delete(Collections.emptyMap());
} catch (final IOException e) {
BonitaStudioLog.error(e);
}
}
}
}
return ctx.createSuccessStatus();
......
......@@ -26,8 +26,8 @@ import java.util.List;
import org.bonitasoft.studio.model.process.MainProcess;
import org.bonitasoft.studio.model.process.Pool;
import org.bonitasoft.studio.validation.constraints.connector.ConnectorExistenceConstraint;
import org.bonitasoft.studio.validation.constraints.process.AssignableConstraint;
import org.bonitasoft.studio.validation.constraints.process.ConnectorExistenceConstraint;
import org.bonitasoft.studio.validation.constraints.process.InclusiveMergeGatewayConstraint;
import org.bonitasoft.studio.validation.constraints.process.XORGatewayConstraint;
import org.eclipse.core.resources.IMarker;
......
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