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

fix builder generic type

parent af9294d2
package org.bonitasoft.studio.model.process.assertions;
import static java.lang.String.format;
import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.Assertions;
import org.bonitasoft.studio.model.process.Element;
import org.bonitasoft.studio.model.process.TextAnnotationAttachment;
/**
* {@link Element} specific assertions - Generated by CustomAssertionGenerator.
*/
public class ElementAssert extends AbstractAssert<ElementAssert, Element> {
/**
* Creates a new </code>{@link ElementAssert}</code> to make assertions on actual Element.
* @param actual the Element we want to make assertions on.
*/
public ElementAssert(final Element actual) {
super(actual, ElementAssert.class);
}
/**
* An entry point for ElementAssert to follow AssertJ standard <code>assertThat()</code> statements.<br>
* With a static import, one's can write directly : <code>assertThat(myElement)</code> and get specific assertion with code completion.
* @param actual the Element we want to make assertions on.
* @return a new </code>{@link ElementAssert}</code>
*/
public static ElementAssert assertThat(final Element actual) {
return new ElementAssert(actual);
}
/**
* Verifies that the actual Element's documentation is equal to the given one.
* @param documentation the given documentation to compare the actual Element's documentation to.
* @return this assertion object.
* @throws AssertionError - if the actual Element's documentation is not equal to the given one.
*/
public ElementAssert hasDocumentation(final String documentation) {
// check that actual Element we want to make assertions on is not null.
isNotNull();
// we overrides the default error message with a more explicit one
final String errorMessage = format("\nExpected <%s> documentation to be:\n <%s>\n but was:\n <%s>", actual, documentation, actual.getDocumentation());
// check
if (!actual.getDocumentation().equals(documentation)) {
throw new AssertionError(errorMessage);
}
// return the current assertion for method chaining
return this;
}
/**
* Verifies that the actual Element's name is equal to the given one.
* @param name the given name to compare the actual Element's name to.
* @return this assertion object.
* @throws AssertionError - if the actual Element's name is not equal to the given one.
*/
public ElementAssert hasName(final String name) {
// check that actual Element we want to make assertions on is not null.
isNotNull();
// we overrides the default error message with a more explicit one
final String errorMessage = format("\nExpected <%s> name to be:\n <%s>\n but was:\n <%s>", actual, name, actual.getName());
// check
if (!actual.getName().equals(name)) {
throw new AssertionError(errorMessage);
}
// return the current assertion for method chaining
return this;
}
/**
* Verifies that the actual Element's textAnnotationAttachment contains the given TextAnnotationAttachment elements.
* @param textAnnotationAttachment the given elements that should be contained in actual Element's textAnnotationAttachment.
* @return this assertion object.
* @throws AssertionError if the actual Element's textAnnotationAttachment does not contain all given TextAnnotationAttachment elements.
*/
public ElementAssert hasTextAnnotationAttachment(final TextAnnotationAttachment... textAnnotationAttachment) {
// check that actual Element we want to make assertions on is not null.
isNotNull();
// check that given TextAnnotationAttachment varargs is not null.
if (textAnnotationAttachment == null) {
throw new AssertionError("Expecting textAnnotationAttachment parameter not to be null.");
}
// check with standard error message (see commented below to set your own message).
Assertions.assertThat(actual.getTextAnnotationAttachment()).contains(textAnnotationAttachment);
// uncomment the 4 lines below if you want to build your own error message :
// WritableAssertionInfo assertionInfo = new WritableAssertionInfo();
// String errorMessage = "my error message";
// assertionInfo.overridingErrorMessage(errorMessage);
// Iterables.instance().assertContains(assertionInfo, actual.getTeamMates(), teamMates);
// return the current assertion for method chaining
return this;
}
/**
* Verifies that the actual Element has no textAnnotationAttachment.
* @return this assertion object.
* @throws AssertionError if the actual Element's textAnnotationAttachment is not empty.
*/
public ElementAssert hasNoTextAnnotationAttachment() {
// check that actual Element we want to make assertions on is not null.
isNotNull();
// we overrides the default error message with a more explicit one
final String errorMessage = format("\nExpected :\n <%s>\nnot to have textAnnotationAttachment but had :\n <%s>", actual,
actual.getTextAnnotationAttachment());
// check
if (!actual.getTextAnnotationAttachment().isEmpty()) {
throw new AssertionError(errorMessage);
}
// return the current assertion for method chaining
return this;
}
}
......@@ -28,8 +28,8 @@ import org.bonitasoft.studio.model.process.ProcessFactory;
*/
public class ActivityBuilder<T extends Activity, B extends ActivityBuilder<T, B>> extends FlowElementBuilder<T, B> {
public static <T extends Activity, B extends ActivityBuilder<T, B>> ActivityBuilder<T, B> create() {
return new ActivityBuilder<T,B>();
public static ActivityBuilder<?, ?> create() {
return new ActivityBuilder();
}
public B withDuration(final String duration) {
......
......@@ -26,8 +26,8 @@ import org.bonitasoft.studio.model.process.ProcessFactory;
*/
public class DataBuilder<T extends Data, B extends DataBuilder<T, B>> extends ElementBuilder<T, B> {
public static <T extends Data, B extends DataBuilder<T, B>> DataBuilder<T, B> create() {
return new DataBuilder<T, B>();
public static DataBuilder<?, ?> create() {
return new DataBuilder();
}
public B withDatasourceId(final String datasourceId) {
......
......@@ -25,8 +25,8 @@ import org.bonitasoft.studio.model.process.ProcessFactory;
*/
public class JavaObjectDataBuilder<T extends JavaObjectData, B extends JavaObjectDataBuilder<T, B>> extends DataBuilder<T, B> {
public static <T extends JavaObjectData, B extends JavaObjectDataBuilder<T, B>> JavaObjectDataBuilder<T, B> create() {
return new JavaObjectDataBuilder<T, B>();
public static JavaObjectDataBuilder<?, ?> create() {
return new JavaObjectDataBuilder();
}
public B withClassname(final String classname) {
......
......@@ -25,7 +25,9 @@ Require-Bundle: org.eclipse.core.runtime,
org.bonitasoft.studio.diagram.custom;bundle-version="1.0.0",
org.bonitasoft.studio.migration;bundle-version="1.0.0",
org.bonitasoft.studio.swtbot.framework;bundle-version="6.4.0",
org.bonitasoft.studio.exporter
org.bonitasoft.studio.exporter,
org.bonitasoft.studio.preferences,
org.bonitasoft.studio.tests-utils;bundle-version="6.4.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: org.bonitasoft.studio.migration.tests
......@@ -22,18 +22,25 @@ import java.io.File;
import java.util.HashSet;
import java.util.Set;
import org.bonitasoft.studio.common.jface.FileActionDialog;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.operation.ExportBosArchiveOperation;
import org.bonitasoft.studio.common.repository.operation.ImportBosArchiveOperation;
import org.bonitasoft.studio.diagram.custom.repository.DiagramFileStore;
import org.bonitasoft.studio.diagram.custom.repository.DiagramRepositoryStore;
import org.bonitasoft.studio.exporter.handler.ExportBosArchiveHandler;
import org.bonitasoft.studio.model.process.MainProcess;
import org.bonitasoft.studio.model.process.assertions.ElementAssert;
import org.bonitasoft.studio.preferences.BonitaPreferenceConstants;
import org.bonitasoft.studio.preferences.BonitaStudioPreferencesPlugin;
import org.bonitasoft.studio.swtbot.framework.application.BotApplicationWorkbenchWindow;
import org.bonitasoft.studio.swtbot.framework.diagram.BotProcessDiagramPerspective;
import org.bonitasoft.studio.swtbot.framework.draw.BotGefProcessDiagramEditor;
import org.eclipse.core.resources.IResource;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.swtbot.eclipse.gef.finder.SWTBotGefTestCase;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.junit.After;
......@@ -58,6 +65,10 @@ public class ExportImportWithoutMigrationIT extends SWTBotGefTestCase {
public void setUp() throws Exception{
bot.saveAllEditors();
bot.closeAllEditors();
FileActionDialog.setDisablePopup(true);
BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore()
.setValue(BonitaPreferenceConstants.CONSOLE_BROWSER_CHOICE, BonitaPreferenceConstants.INTERNAL_BROWSER);
BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore().setValue(BonitaPreferenceConstants.ASK_RENAME_ON_FIRST_SAVE, false);
}
@Override
......@@ -70,19 +81,27 @@ public class ExportImportWithoutMigrationIT extends SWTBotGefTestCase {
@Test
public void should_export_and_import_of_a_diagram_do_not_trigger_migration() throws Exception {
final BotApplicationWorkbenchWindow workbenchWindow = new BotApplicationWorkbenchWindow(bot);
final BotProcessDiagramPerspective newDiagram = workbenchWindow.createNewDiagram();
final BotGefProcessDiagramEditor diagramEditor = newDiagram.activeProcessDiagramEditor();
final BotProcessDiagramPerspective diagramPerspective = workbenchWindow.createNewDiagram();
BotGefProcessDiagramEditor diagramEditor = diagramPerspective.activeProcessDiagramEditor();
diagramEditor.selectDiagram();
diagramPerspective.getDiagramPropertiesPart().selectGeneralTab().selectDiagramTab().setName("ExportImportWithoutMigrationIT");
diagramEditor = diagramPerspective.activeProcessDiagramEditor().selectDiagram();
final EObject originalSemanticElement = diagramEditor.getSelectedSemanticElement();
assertThat(originalSemanticElement).isInstanceOf(MainProcess.class);
ElementAssert.assertThat((MainProcess) originalSemanticElement).hasName("ExportImportWithoutMigrationIT");
final ExportBosArchiveOperation exportBosArchiveOperation = new ExportBosArchiveOperation();
final File destFolder = folder.newFolder();
destFolder.mkdirs();
final File bosFile = new File(destFolder,"test.bos");
final File bosFile = new File(destFolder, "ExportImportWithoutMigrationIT-1.0.bos");
exportBosArchiveOperation.setDestinationPath(bosFile.getAbsolutePath());
final Set<Object> allDiagramRelatedFiles = ExportBosArchiveHandler.getAllDiagramRelatedFiles((MainProcess) originalSemanticElement);
final DiagramRepositoryStore diagramRepositoryStore = RepositoryManager.getInstance().getRepositoryStore(DiagramRepositoryStore.class);
final DiagramFileStore diagramFileStore = diagramRepositoryStore.getDiagram("ExportImportWithoutMigrationIT",
"1.0");
assertThat(diagramFileStore).isNotNull();
final MainProcess mainProcess = diagramFileStore.getContent();
assertThat(mainProcess.eResource()).isNotNull();
final Set<Object> allDiagramRelatedFiles = ExportBosArchiveHandler.getAllDiagramRelatedFiles(mainProcess);
final Set<IResource> resources = new HashSet<IResource>();
for (final Object filestore : allDiagramRelatedFiles) {
if (filestore instanceof IRepositoryFileStore) {
......@@ -96,8 +115,18 @@ public class ExportImportWithoutMigrationIT extends SWTBotGefTestCase {
assertThat(bosFile.exists()).isTrue();
//delete diagram
final DiagramRepositoryStore diagramRepositoryStore = RepositoryManager.getInstance().getRepositoryStore(DiagramRepositoryStore.class);
diagramRepositoryStore.getDiagram(((MainProcess) originalSemanticElement).getName(), ((MainProcess) originalSemanticElement).getVersion());
diagramFileStore.delete();
final ImportBosArchiveOperation importBosArchiveOperation = new ImportBosArchiveOperation();
importBosArchiveOperation.setArchiveFile(bosFile.getAbsolutePath());
importBosArchiveOperation.setCurrentRepository(RepositoryManager.getInstance().getCurrentRepository());
importBosArchiveOperation.run(Repository.NULL_PROGRESS_MONITOR);
assertThat(importBosArchiveOperation.getStatus().isOK()).isTrue();
workbenchWindow.open().selectDiagram("ExportImportWithoutMigrationIT", "1.0").open();
diagramPerspective.activeProcessDiagramEditor().selectDiagram();
final EObject newSemanticElement = diagramPerspective.activeProcessDiagramEditor().getSelectedSemanticElement();
assertThat(EcoreUtil.equals(originalSemanticElement, newSemanticElement)).isTrue();
}
......
Markdown is supported
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