import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
private static final boolean IS_WIN32 = System.getProperty("os.name").startsWith("Windows"); //$NON-NLS-1$//$NON-NLS-2$
private static final String URI_DEVICE_SEPARATOR = IS_WIN32 ? URI_SEPARATOR : "";
+ /** Test Class setup */
+ @BeforeClass
+ public static void beforeClass() {
+ createProject(TRACE_PROJECT_NAME);
+ }
+
+ /** Test Class tear down */
+ @AfterClass
+ public static void afterClass() {
+ SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
+ }
+
/**
* Test import from directory
*
*/
@Test
public void testExtractArchivesFromDirectory() throws Exception {
- testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false);
+ testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, false);
}
/**
*/
@Test
public void testExtractArchivesFromDirectoryLinks() throws Exception {
- testImportAndExtractArchives(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false);
+ testImportAndExtractArchives(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, false);
}
/**
*/
@Test
public void testExtractArchivesFromDirectoryLinksPreserveStruture() throws Exception {
- testImportAndExtractArchives(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false);
+ testImportAndExtractArchives(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, true, false);
}
/**
*/
@Test
public void testExtractArchivesFromArchive() throws Exception {
- testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, true);
+ testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, true);
}
/**
*/
@Test
public void testExtractArchivesFromArchivePreserveFolder() throws Exception {
- testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, true);
+ testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false, true);
}
/**
*/
@Test
public void testEmptyArchive() throws Exception {
- createProject();
String testArchivePath = createEmptyArchive();
openImportWizard();
assertNoTraces();
- SWTBotUtils.deleteProject(getProjectName(), fBot);
+ SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
+ Files.delete(Paths.get(testArchivePath));
}
/**
*/
@Test
public void testEmptyDirectory() throws Exception {
- createProject();
- String testDirectoryPath = createEmptyDirectory().getLocation().toOSString();
+ IFolder emptyDirectory = createEmptyDirectory();
+ String testDirectoryPath = emptyDirectory.getLocation().toOSString();
openImportWizard();
selectImportFromDirectory(testDirectoryPath);
assertNoTraces();
- SWTBotUtils.deleteProject(getProjectName(), fBot);
+ Files.delete(Paths.get(testDirectoryPath));
+ emptyDirectory.delete(true, null);
+ SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
}
/**
*/
@Test
public void testEmptyFile() throws Exception {
- createProject();
IFolder folder = createEmptyDirectory();
createEmptyFile(folder);
String testDirectoryPath = folder.getLocation().toOSString();
assertNoTraces();
- SWTBotUtils.deleteProject(getProjectName(), fBot);
+ SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
+ folder.delete(true, null);
}
/**
*/
@Test
public void testDirectoryWithEmptyArchive() throws Exception {
- createProject();
- createEmptyArchive();
+ String testArchivePath = createEmptyArchive();
openImportWizard();
selectImportFromDirectory(getProjectResource().getLocation().toOSString());
- selectFile(GENERATED_ARCHIVE_NAME, getProjectName());
+ selectFile(GENERATED_ARCHIVE_NAME, TRACE_PROJECT_NAME);
setOptions(0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
importFinish();
assertNoTraces();
- SWTBotUtils.deleteProject(getProjectName(), fBot);
+ SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
+ Files.delete(Paths.get(testArchivePath));
}
/**
*/
@Test
public void testNestedEmptyArchive() throws Exception {
- createProject();
IProject project = getProjectResource();
// Create the empty archive from an empty folder
IFile renamedArchiveFile = archiveFile.getWorkspace().getRoot().getFile(dest);
createArchive(renamedArchiveFile);
+ renamedArchiveFile.delete(true, null);
openImportWizard();
selectImportFromArchive(testArchivePath);
assertNoTraces();
- SWTBotUtils.deleteProject(getProjectName(), fBot);
+ SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
+ Files.delete(Paths.get(testArchivePath));
}
- private void assertNoTraces() {
+ private static void assertNoTraces() {
TmfProjectElement tmfProject = TmfProjectRegistry.getProject(getProjectResource(), true);
assertNotNull(tmfProject);
TmfTraceFolder tracesFolder = tmfProject.getTracesFolder();
}
private void testImport(int options, boolean testViews, boolean fromArchive) throws Exception {
- createProject();
String expectedSourceLocation = null;
openImportWizard();
if (fromArchive) {
}
checkOptions(options, expectedSourceLocation, expectedElementPath);
- TmfEventsEditor tmfEd = SWTBotUtils.openEditor(fBot, getProjectName(), expectedElementPath);
+ TmfEventsEditor tmfEd = SWTBotUtils.openEditor(fBot, TRACE_PROJECT_NAME, expectedElementPath);
if (testViews) {
testViews(tmfEd);
}
fBot.closeAllEditors();
- SWTBotUtils.deleteProject(getProjectName(), fBot);
+ SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
}
- private void testImportAndExtractArchives(int options, boolean fromArchive) throws Exception {
- createProject();
-
+ private void testImportAndExtractArchives(int options, boolean testViews, boolean fromArchive) throws Exception {
String expectedSourceLocation;
IPath expectedElementPath;
+ String testArchivePath = null;
if (fromArchive) {
- String testArchivePath = createNestedArchive();
+ testArchivePath = createNestedArchive();
openImportWizard();
selectImportFromArchive(testArchivePath);
selectFile(ARCHIVE_FILE_NAME, ARCHIVE_ROOT_ELEMENT_NAME, TRACE_PROJECT_NAME, TRACE_FOLDER_PARENT_NAME);
checkOptions(expectedOptions, expectedSourceLocation, expectedElementPath);
TmfEventsEditor editor = SWTBotUtils.openEditor(fBot, TRACE_PROJECT_NAME, expectedElementPath);
- testViews(editor);
+ if (testViews) {
+ testViews(editor);
+ }
- SWTBotUtils.deleteProject(getProjectName(), fBot);
+ SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
+ if (testArchivePath != null) {
+ Files.delete(Paths.get(testArchivePath));
+ }
}
/**
* Create a temporary archive containing a nested archive. For example,
* testtraces.zip/synctraces.tar.gz can be used to test a nested archive.
*/
- private String createNestedArchive() throws IOException, CoreException, URISyntaxException {
+ private static String createNestedArchive() throws IOException, CoreException, URISyntaxException {
// Link to the test traces folder. We use a link so that we can safely
// delete the entire project when we are done.
IProject project = getProjectResource();
IFolder folder = project.getFolder(TRACE_FOLDER_PARENT_NAME);
folder.createLink(new Path(canonicalPath), IResource.REPLACE, null);
IFile file = folder.getFile(ARCHIVE_FILE_NAME);
- return createArchive(file);
+ String archivePath = createArchive(file);
+ folder.delete(true, null);
+ return archivePath;
}
/**
* Create the empty archive from an empty folder
*/
- private String createEmptyArchive() throws CoreException, URISyntaxException {
- return createArchive(createEmptyDirectory());
+ private static String createEmptyArchive() throws CoreException, URISyntaxException {
+ IFolder tempEmptyDirectory = createEmptyDirectory();
+ String archivePath = createArchive(tempEmptyDirectory);
+ tempEmptyDirectory.delete(true, null);
+ return archivePath;
}
- private IFolder createEmptyDirectory() throws CoreException {
+ private static IFolder createEmptyDirectory() throws CoreException {
IProject project = getProjectResource();
IFolder folder = project.getFolder(EMPTY_ARCHIVE_FOLDER);
folder.create(true, true, null);
}
}
- private void checkOptions(int optionFlags, String expectedSourceLocation, IPath expectedElementPath) throws CoreException {
+ private static void checkOptions(int optionFlags, String expectedSourceLocation, IPath expectedElementPath) throws CoreException {
IProject project = getProjectResource();
assertTrue(project.exists());
TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, true);
assertEquals(expectedSourceLocation, sourceLocation);
}
- @Override
- protected String getProjectName() {
- return TRACE_PROJECT_NAME;
- }
-
- private IProject getProjectResource() {
- return ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectName());
+ private static IProject getProjectResource() {
+ return ResourcesPlugin.getWorkspace().getRoot().getProject(TRACE_PROJECT_NAME);
}
}
import java.util.List;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
import org.eclipse.tracecompass.tmf.ui.project.model.TmfOpenTraceHelper;
+import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement;
import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectRegistry;
+import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement;
import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder;
import org.eclipse.tracecompass.tmf.ui.project.model.TmfTracesFolder;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers.ProjectElementHasChild;
return tracesFolderItem;
}
+ /**
+ * Clear the traces folder
+ *
+ * @param bot
+ * a given workbench bot
+ * @param projectName
+ * the name of the project (needs to exist)
+ */
+ public static void clearTracesFolder(SWTWorkbenchBot bot, String projectName) {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, false);
+ TmfTraceFolder tracesFolder = tmfProject.getTracesFolder();
+ try {
+ for (TmfTraceElement traceElement : tracesFolder.getTraces()) {
+ traceElement.delete(null);
+ }
+
+ final IFolder resource = tracesFolder.getResource();
+ resource.accept(new IResourceVisitor() {
+ @Override
+ public boolean visit(IResource visitedResource) throws CoreException {
+ if (visitedResource != resource) {
+ visitedResource.delete(true, null);
+ }
+ return true;
+ }
+ }, IResource.DEPTH_ONE, 0);
+ } catch (CoreException e) {
+ fail(e.getMessage());
+ }
+
+ bot.waitUntil(new DefaultCondition() {
+ private int fTraceNb = 0;
+
+ @Override
+ public boolean test() throws Exception {
+ List<TmfTraceElement> traces = tracesFolder.getTraces();
+ fTraceNb = traces.size();
+ return fTraceNb == 0;
+ }
+
+ @Override
+ public String getFailureMessage() {
+ return "Traces Folder not empty (" + fTraceNb + ")";
+ }
+ });
+
+ }
+
/**
* Select the project in Project Explorer
*