Commit 9c7a755b authored by Bonita CI's avatar Bonita CI Committed by Adrien
Browse files

chore(uid) update UI Designer version to 1.7.47 (#1182)

parent 9c0feaa7
/**
* Copyright (C) 2018 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.application.actions;
import java.io.File;
import java.util.Optional;
import org.bonitasoft.studio.application.i18n.Messages;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.designer.core.UIDesignerServerManager;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
public class OpenUIDLogCommand extends AbstractHandler implements IHandler {
private static final long MAX_FILE_SIZE = 1000000 * 40; //40Mo
@Override
public Boolean execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final Optional<File> logFile = UIDesignerServerManager.getInstance().getLogFile();
if (logFile.isPresent() && logFile.get().exists()) {
try {
IFileStore fileStore = EFS.getLocalFileSystem().getStore(logFile.get().toURI());
final File localFile = fileStore.toLocalFile(EFS.NONE, Repository.NULL_PROGRESS_MONITOR);
final long fileSize = localFile.length();
if (fileSize < MAX_FILE_SIZE) {
IDE.openEditorOnFileStore(page, fileStore);
} else {
Program textEditor = Program.findProgram("log");
if (textEditor == null) {
textEditor = Program.findProgram("txt");
}
if (textEditor == null || !textEditor.execute(localFile.getAbsolutePath())) {
showWarningMessage(localFile);
}
}
return true;
} catch (final Exception e) {
BonitaStudioLog.error(e);
return false;
}
}
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
Messages.unableTofindLogTitle, Messages.unableTofindLogMessage);
return false;
}
protected void showWarningMessage(File localFile) {
MessageDialog.openWarning(Display.getDefault().getActiveShell(), Messages.failedToOpenLogTitle,
Messages.bind(Messages.failedToOpenLogMessage, localFile.getAbsolutePath(),
org.bonitasoft.studio.common.Messages.bonitaStudioModuleName));
}
}
/**
* Copyright (C) 2018 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.application.actions;
import java.io.File;
import java.util.Optional;
import org.bonitasoft.studio.application.i18n.Messages;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.designer.core.UIDesignerServerManager;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
public class OpenUIDLogCommand extends AbstractHandler implements IHandler {
private static final long MAX_FILE_SIZE = 1000000 * 40; //40Mo
@Override
public Boolean execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final Optional<File> logFile = UIDesignerServerManager.getInstance().getLogFile();
if (logFile.isPresent() && logFile.get().exists()) {
try {
IFileStore fileStore = EFS.getLocalFileSystem().getStore(logFile.get().toURI());
final File localFile = fileStore.toLocalFile(EFS.NONE, Repository.NULL_PROGRESS_MONITOR);
final long fileSize = localFile.length();
if (fileSize < MAX_FILE_SIZE) {
IDE.openEditorOnFileStore(page, fileStore);
} else {
Program textEditor = Program.findProgram("log");
if (textEditor == null) {
textEditor = Program.findProgram("txt");
}
if (textEditor == null || !textEditor.execute(localFile.getAbsolutePath())) {
showWarningMessage(localFile);
}
}
return true;
} catch (final Exception e) {
BonitaStudioLog.error(e);
return false;
}
}
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
Messages.unableTofindLogTitle, Messages.unableTofindLogMessage);
return false;
}
protected void showWarningMessage(File localFile) {
MessageDialog.openWarning(Display.getDefault().getActiveShell(), Messages.failedToOpenLogTitle,
Messages.bind(Messages.failedToOpenLogMessage, localFile.getAbsolutePath(),
org.bonitasoft.studio.common.Messages.bonitaStudioModuleName));
}
}
<?xml version="1.0" encoding="ASCII"?>
<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmi:id="_jKdtYNKdEeaEE_Umqe0dXA">
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_tWbyINKdEeaEE_Umqe0dXA" featurename="commands" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Command" xmi:id="_0n838NKdEeaEE_Umqe0dXA" elementId="org.bonitasoft.studio.la.new.command" commandName="%newApplication"/>
<elements xsi:type="commands:Command" xmi:id="_dHtcoP3SEeanhv23kWy-6w" elementId="org.bonitasoft.studio.la.open.command" commandName="%openApplication"/>
<elements xsi:type="commands:Command" xmi:id="_2helYP6PEeaqYIbFhsSGFw" elementId="org.bonitasoft.studio.la.delete.command" commandName="%deleteApplication"/>
<elements xsi:type="commands:Command" xmi:id="_YHf6AAomEeekfeZYiUbzLg" elementId="org.bonitasoft.studio.la.export.command" commandName="%exportApplication"/>
<elements xsi:type="commands:Command" xmi:id="_g4OJ8ApAEeekfeZYiUbzLg" elementId="org.bonitasoft.studio.la.import.command" commandName="%importApplication"/>
<elements xsi:type="commands:Command" xmi:id="_pL3WsPnPEea-3Os5NcIV0g" elementId="org.bonitasoft.studio.la.deploy.command" commandName="%deployApplication"/>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_--2aUNKdEeaEE_Umqe0dXA" featurename="handlers" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Handler" xmi:id="_BKi10NKeEeaEE_Umqe0dXA" elementId="org.bonitasoft.studio.la.newHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.NewApplicationHandler" command="_0n838NKdEeaEE_Umqe0dXA"/>
<elements xsi:type="commands:Handler" xmi:id="_jUDDEP3SEeanhv23kWy-6w" elementId="org.bonitasoft.studio.la.openHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.OpenApplicationHandler" command="_dHtcoP3SEeanhv23kWy-6w"/>
<elements xsi:type="commands:Handler" xmi:id="_57EXYP6PEeaqYIbFhsSGFw" elementId="org.bonitasoft.studio.la.deleteHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.DeleteApplicationHandler" command="_2helYP6PEeaqYIbFhsSGFw"/>
<elements xsi:type="commands:Handler" xmi:id="_cIN9cAomEeekfeZYiUbzLg" elementId="org.bonitasoft.studio.la.exportHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.ExportApplicationHandler" command="_YHf6AAomEeekfeZYiUbzLg"/>
<elements xsi:type="commands:Handler" xmi:id="_kWFX8ApAEeekfeZYiUbzLg" elementId="org.bonitasoft.studio.la.importHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.ImportApplicationhandler" command="_g4OJ8ApAEeekfeZYiUbzLg"/>
<elements xsi:type="commands:Handler" xmi:id="_JVGowM6fEee2rb_HhIZr1w" elementId="org.bonitasoft.studio.la.handler.deployapplication" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.DeployApplicationHandler" command="_pL3WsPnPEea-3Os5NcIV0g"/>
</fragments>
</fragment:ModelFragments>
<?xml version="1.0" encoding="ASCII"?>
<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmi:id="_jKdtYNKdEeaEE_Umqe0dXA">
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_tWbyINKdEeaEE_Umqe0dXA" featurename="commands" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Command" xmi:id="_0n838NKdEeaEE_Umqe0dXA" elementId="org.bonitasoft.studio.la.new.command" commandName="%newApplication"/>
<elements xsi:type="commands:Command" xmi:id="_dHtcoP3SEeanhv23kWy-6w" elementId="org.bonitasoft.studio.la.open.command" commandName="%openApplication"/>
<elements xsi:type="commands:Command" xmi:id="_2helYP6PEeaqYIbFhsSGFw" elementId="org.bonitasoft.studio.la.delete.command" commandName="%deleteApplication"/>
<elements xsi:type="commands:Command" xmi:id="_YHf6AAomEeekfeZYiUbzLg" elementId="org.bonitasoft.studio.la.export.command" commandName="%exportApplication"/>
<elements xsi:type="commands:Command" xmi:id="_g4OJ8ApAEeekfeZYiUbzLg" elementId="org.bonitasoft.studio.la.import.command" commandName="%importApplication"/>
<elements xsi:type="commands:Command" xmi:id="_pL3WsPnPEea-3Os5NcIV0g" elementId="org.bonitasoft.studio.la.deploy.command" commandName="%deployApplication"/>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_--2aUNKdEeaEE_Umqe0dXA" featurename="handlers" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Handler" xmi:id="_BKi10NKeEeaEE_Umqe0dXA" elementId="org.bonitasoft.studio.la.newHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.NewApplicationHandler" command="_0n838NKdEeaEE_Umqe0dXA"/>
<elements xsi:type="commands:Handler" xmi:id="_jUDDEP3SEeanhv23kWy-6w" elementId="org.bonitasoft.studio.la.openHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.OpenApplicationHandler" command="_dHtcoP3SEeanhv23kWy-6w"/>
<elements xsi:type="commands:Handler" xmi:id="_57EXYP6PEeaqYIbFhsSGFw" elementId="org.bonitasoft.studio.la.deleteHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.DeleteApplicationHandler" command="_2helYP6PEeaqYIbFhsSGFw"/>
<elements xsi:type="commands:Handler" xmi:id="_cIN9cAomEeekfeZYiUbzLg" elementId="org.bonitasoft.studio.la.exportHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.ExportApplicationHandler" command="_YHf6AAomEeekfeZYiUbzLg"/>
<elements xsi:type="commands:Handler" xmi:id="_kWFX8ApAEeekfeZYiUbzLg" elementId="org.bonitasoft.studio.la.importHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.ImportApplicationhandler" command="_g4OJ8ApAEeekfeZYiUbzLg"/>
<elements xsi:type="commands:Handler" xmi:id="_JVGowM6fEee2rb_HhIZr1w" elementId="org.bonitasoft.studio.la.handler.deployapplication" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.DeployApplicationHandler" command="_pL3WsPnPEea-3Os5NcIV0g"/>
</fragments>
</fragment:ModelFragments>
/**
* Copyright (C) 2017 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.la.application.core;
import static org.bonitasoft.engine.business.application.xml.ApplicationNodeBuilder.newApplication;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.notNull;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.bonitasoft.engine.api.ApplicationAPI;
import org.bonitasoft.engine.business.application.Application;
import org.bonitasoft.engine.business.application.ApplicationSearchDescriptor;
import org.bonitasoft.engine.exception.DeletionException;
import org.bonitasoft.engine.search.SearchOptions;
import org.bonitasoft.engine.search.SearchOptionsBuilder;
import org.bonitasoft.engine.search.SearchResult;
import org.bonitasoft.engine.search.impl.SearchResultImpl;
import org.bonitasoft.studio.assertions.StatusAssert;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
public class DeleteApplicationRunnableTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void should_delete_application_by_token() throws Exception {
final ApplicationAPI applicationAPI = mock(ApplicationAPI.class);
final Application application1 = applicationWithId(1);
final Application application2 = applicationWithId(2);
when(applicationAPI.searchApplications(notNull(SearchOptions.class)))
.thenReturn(searchResult(Collections.emptyList()));
when(applicationAPI.searchApplications(eq(withToken("myApp1"))))
.thenReturn(searchResult(Arrays.asList(application1)));
when(applicationAPI.searchApplications(eq(withToken("myApp2"))))
.thenReturn(searchResult(Arrays.asList(application2)));
final DeleteApplicationRunnable operation = new DeleteApplicationRunnable(applicationAPI,
newApplication("myApp1", "My App", "1.0").create());
operation.run(new NullProgressMonitor());
verify(applicationAPI).deleteApplication(1);
StatusAssert.assertThat(operation.getStatus()).isOK();
}
@Test
public void should_fail_if_application_not_found() throws Exception {
final ApplicationAPI applicationAPI = mock(ApplicationAPI.class);
when(applicationAPI.searchApplications(notNull(SearchOptions.class)))
.thenReturn(searchResult(Collections.emptyList()));
final DeleteApplicationRunnable operation = new DeleteApplicationRunnable(applicationAPI,
newApplication("unknownToken", "My App 2", "1.0").create());
operation.run(new NullProgressMonitor());
verify(applicationAPI, never()).deleteApplication(anyInt());
StatusAssert.assertThat(operation.getStatus()).isNotOK();
}
@Test
public void should_not_fail_if_application_not_found_with_ignore_option() throws Exception {
final ApplicationAPI applicationAPI = mock(ApplicationAPI.class);
when(applicationAPI.searchApplications(notNull(SearchOptions.class)))
.thenReturn(searchResult(Collections.emptyList()));
final DeleteApplicationRunnable operation = new DeleteApplicationRunnable(applicationAPI,
newApplication("unknownToken", "My App 2", "1.0").create())
.ignoreErrors();
operation.run(new NullProgressMonitor());
verify(applicationAPI, never()).deleteApplication(anyInt());
StatusAssert.assertThat(operation.getStatus()).isOK();
}
@Test
public void should_fail_if_application_deletion_failed() throws Exception {
final ApplicationAPI applicationAPI = mock(ApplicationAPI.class);
doThrow(DeletionException.class).when(applicationAPI).deleteApplication(1);
final Application application1 = applicationWithId(1);
when(applicationAPI.searchApplications(notNull(SearchOptions.class)))
.thenReturn(searchResult(Collections.emptyList()));
when(applicationAPI.searchApplications(eq(withToken("myApp1"))))
.thenReturn(searchResult(Arrays.asList(application1)));
final DeleteApplicationRunnable operation = new DeleteApplicationRunnable(applicationAPI,
newApplication("myApp1", "My App", "1.0").create());
operation.run(new NullProgressMonitor());
verify(applicationAPI).deleteApplication(1);
StatusAssert.assertThat(operation.getStatus()).isNotOK();
}
private SearchResult<Application> searchResult(List<Application> resultAsList) {
return new SearchResultImpl<>(resultAsList.size(), resultAsList);
}
protected SearchOptions withToken(String token) {
return new SearchOptionsBuilder(0, 1).filter(ApplicationSearchDescriptor.TOKEN, token).done();
}
protected Application applicationWithId(long id) {
final Application app = mock(Application.class);
when(app.getId()).thenReturn(Long.valueOf(id));
return app;
}
}
/**
* Copyright (C) 2017 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.la.application.core;
import static org.bonitasoft.engine.business.application.xml.ApplicationNodeBuilder.newApplication;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.notNull;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.bonitasoft.engine.api.ApplicationAPI;
import org.bonitasoft.engine.business.application.Application;
import org.bonitasoft.engine.business.application.ApplicationSearchDescriptor;
import org.bonitasoft.engine.exception.DeletionException;
import org.bonitasoft.engine.search.SearchOptions;
import org.bonitasoft.engine.search.SearchOptionsBuilder;
import org.bonitasoft.engine.search.SearchResult;
import org.bonitasoft.engine.search.impl.SearchResultImpl;
import org.bonitasoft.studio.assertions.StatusAssert;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
public class DeleteApplicationRunnableTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void should_delete_application_by_token() throws Exception {
final ApplicationAPI applicationAPI = mock(ApplicationAPI.class);
final Application application1 = applicationWithId(1);
final Application application2 = applicationWithId(2);
when(applicationAPI.searchApplications(notNull(SearchOptions.class)))
.thenReturn(searchResult(Collections.emptyList()));
when(applicationAPI.searchApplications(eq(withToken("myApp1"))))
.thenReturn(searchResult(Arrays.asList(application1)));
when(applicationAPI.searchApplications(eq(withToken("myApp2"))))
.thenReturn(searchResult(Arrays.asList(application2)));
final DeleteApplicationRunnable operation = new DeleteApplicationRunnable(applicationAPI,
newApplication("myApp1", "My App", "1.0").create());
operation.run(new NullProgressMonitor());
verify(applicationAPI).deleteApplication(1);
StatusAssert.assertThat(operation.getStatus()).isOK();
}
@Test
public void should_fail_if_application_not_found() throws Exception {
final ApplicationAPI applicationAPI = mock(ApplicationAPI.class);
when(applicationAPI.searchApplications(notNull(SearchOptions.class)))
.thenReturn(searchResult(Collections.emptyList()));
final DeleteApplicationRunnable operation = new DeleteApplicationRunnable(applicationAPI,
newApplication("unknownToken", "My App 2", "1.0").create());
operation.run(new NullProgressMonitor());
verify(applicationAPI, never()).deleteApplication(anyInt());
StatusAssert.assertThat(operation.getStatus()).isNotOK();
}
@Test
public void should_not_fail_if_application_not_found_with_ignore_option() throws Exception {
final ApplicationAPI applicationAPI = mock(ApplicationAPI.class);
when(applicationAPI.searchApplications(notNull(SearchOptions.class)))
.thenReturn(searchResult(Collections.emptyList()));
final DeleteApplicationRunnable operation = new DeleteApplicationRunnable(applicationAPI,
newApplication("unknownToken", "My App 2", "1.0").create())
.ignoreErrors();
operation.run(new NullProgressMonitor());
verify(applicationAPI, never()).deleteApplication(anyInt());
StatusAssert.assertThat(operation.getStatus()).isOK();
}
@Test
public void should_fail_if_application_deletion_failed() throws Exception {
final ApplicationAPI applicationAPI = mock(ApplicationAPI.class);
doThrow(DeletionException.class).when(applicationAPI).deleteApplication(1);
final Application application1 = applicationWithId(1);
when(applicationAPI.searchApplications(notNull(SearchOptions.class)))
.thenReturn(searchResult(Collections.emptyList()));
when(applicationAPI.searchApplications(eq(withToken("myApp1"))))
.thenReturn(searchResult(Arrays.asList(application1)));
final DeleteApplicationRunnable operation = new DeleteApplicationRunnable(applicationAPI,
newApplication("myApp1", "My App", "1.0").create());
operation.run(new NullProgressMonitor());
verify(applicationAPI).deleteApplication(1);
StatusAssert.assertThat(operation.getStatus()).isNotOK();
}
private SearchResult<Application> searchResult(List<Application> resultAsList) {
return new SearchResultImpl<>(resultAsList.size(), resultAsList);
}
protected SearchOptions withToken(String token) {
return new SearchOptionsBuilder(0, 1).filter(ApplicationSearchDescriptor.TOKEN, token).done();
}
protected Application applicationWithId(long id) {
final Application app = mock(Application.class);
when(app.getId()).thenReturn(Long.valueOf(id));
return app;
}
}
/**
* Copyright (C) 2017 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.la.application.core;
import static java.util.Objects.requireNonNull;
import java.lang.reflect.InvocationTargetException;
import org.bonitasoft.engine.api.ApplicationAPI;
import org.bonitasoft.engine.business.application.Application;
import org.bonitasoft.engine.business.application.ApplicationSearchDescriptor;
import org.bonitasoft.engine.business.application.xml.ApplicationNode;
import org.bonitasoft.engine.exception.DeletionException;
import org.bonitasoft.engine.exception.SearchException;
import org.bonitasoft.engine.search.SearchOptions;
import org.bonitasoft.engine.search.SearchOptionsBuilder;
import org.bonitasoft.studio.la.LivingApplicationPlugin;
import org.bonitasoft.studio.la.i18n.Messages;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.operation.IRunnableWithProgress;
public class DeleteApplicationRunnable implements IRunnableWithProgress {
private final ApplicationAPI applicationAPI;
private final ApplicationNode applicationNode;
private IStatus status;
private boolean ignoreErrors = false;
public DeleteApplicationRunnable(ApplicationAPI applicationAPI, ApplicationNode applicationNode) {
this.applicationAPI = requireNonNull(applicationAPI);
this.applicationNode = requireNonNull(applicationNode);
}
public DeleteApplicationRunnable ignoreErrors() {
this.ignoreErrors = true;
return this;
}
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.setTaskName(String.format(Messages.deletingApplication, applicationNode.getDisplayName()));
status = delete(applicationNode);
monitor.worked(1);
}