Annotate Long.valueOf() to return @NonNull
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ui / swtbot / tests / wizards / TestImportExportPackageWizard.java
CommitLineData
13fd2a91
MK
1/*******************************************************************************
2 * Copyright (c) 2014, 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.tracecompass.tmf.ui.swtbot.tests.wizards;
14
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assert.assertFalse;
17import static org.junit.Assert.assertNotNull;
18import static org.junit.Assert.assertTrue;
19
20import java.io.File;
21import java.io.FileWriter;
22import java.io.IOException;
23
24import org.apache.log4j.ConsoleAppender;
25import org.apache.log4j.Logger;
26import org.apache.log4j.SimpleLayout;
27import org.eclipse.core.runtime.Path;
28import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
29import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
30import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
31import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
32import org.eclipse.swtbot.swt.finder.waits.Conditions;
33import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
34import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
35import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
36import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
37import org.junit.BeforeClass;
38import org.junit.Test;
39import org.junit.runner.RunWith;
40
41/**
42 * Export and Import wizard tests
43 *
44 * @author Matthew Khouzam
45 *
46 */
47@RunWith(SWTBotJunit4ClassRunner.class)
48public class TestImportExportPackageWizard {
49
50 // private static final int PACKAGE_SIZE = 213732;
51 private static final String EXPORT_LOCATION = TmfTraceManager.getTemporaryDirPath() + File.separator + "test.zip";
52 private static final String IMPORT_TRACE_PACKAGE = "Import Trace Package...";
53 private static final String EXPORT_TRACE_PACKAGE = "Export Trace Package...";
54 private static final String PROJECT_EXPLORER = "Project Explorer";
55 private static final String FINISH = "Finish";
56 private static final String COMPRESS_THE_CONTENTS_OF_THE_FILE = "Compress the contents of the file";
57 private static final String SAVE_IN_ZIP_FORMAT = "Save in zip format";
58 private static final String SAVE_IN_TAR_FORMAT = "Save in tar format";
59 private static final String SELECT_ALL = "Select All";
60 private static final String DESELECT_ALL = "Deselect All";
61 private static final String WELCOME_NAME = "welcome";
62 private static final String SWT_BOT_THREAD_NAME = "SWTBot Thread";
63 private static final String PROJECT_NAME = "Test";
64 private static final String XMLSTUB_ID = "org.eclipse.linuxtools.tmf.core.tests.xmlstub";
65
66 /*
67 * FIXME: bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=477508, we
68 * shouldn't need so many events.
69 */
70 private static final String TRACE_CONTENT = "<trace>" +
71 "<event timestamp=\"100\" name=\"event\"><field name=\"field\" value=\"1\" type=\"int\" /></event>" +
72 "<event timestamp=\"200\" name=\"event1\"><field name=\"field\" value=\"2\" type=\"int\" /></event>" +
73 "<event timestamp=\"201\" name=\"event\"><field name=\"field\" value=\"3\" type=\"int\" /></event>" +
74 "<event timestamp=\"202\" name=\"event1\"><field name=\"field\" value=\"3\" type=\"int\" /></event>" +
75 "<event timestamp=\"203\" name=\"event1\"><field name=\"field\" value=\"3\" type=\"int\" /></event>" +
76 "<event timestamp=\"300\" name=\"event1\"><field name=\"field\" value=\"2\" type=\"int\" /></event>" +
77 "<event timestamp=\"301\" name=\"event\"><field name=\"field\" value=\"3\" type=\"int\" /></event>" +
78 "<event timestamp=\"302\" name=\"event1\"><field name=\"field\" value=\"3\" type=\"int\" /></event>" +
79 "<event timestamp=\"333\" name=\"event1\"><field name=\"field\" value=\"3\" type=\"int\" /></event>" +
80 "<event timestamp=\"500\" name=\"event1\"><field name=\"field\" value=\"2\" type=\"int\" /></event>" +
81 "<event timestamp=\"501\" name=\"event\"><field name=\"field\" value=\"3\" type=\"int\" /></event>" +
82 "<event timestamp=\"502\" name=\"event1\"><field name=\"field\" value=\"3\" type=\"int\" /></event>" +
83 "<event timestamp=\"533\" name=\"event1\"><field name=\"field\" value=\"3\" type=\"int\" /></event>" +
84 "</trace>";
85
86 /** The Log4j logger instance. */
87 private static final Logger fLogger = Logger.getRootLogger();
88 private static SWTWorkbenchBot fBot;
89
90 /** Test Class setup */
91 @BeforeClass
92 public static void init() {
93 SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
94 SWTBotUtils.failIfUIThread();
95 Thread.currentThread().setName(SWT_BOT_THREAD_NAME); // for the debugger
96 /* set up for swtbot */
97 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
98 fLogger.addAppender(new ConsoleAppender(new SimpleLayout()));
99 fBot = new SWTWorkbenchBot();
100
101 SWTBotUtils.closeView(WELCOME_NAME, fBot);
102
103 SWTBotUtils.switchToTracingPerspective();
104 /* finish waiting for eclipse to load */
105 SWTBotUtils.waitForJobs();
106
107 }
108
109 /**
110 * test opening a trace, importing
111 *
112 * @throws IOException
113 * won't happen
114 */
115 @Test
116 public void test() throws IOException {
dc9e6c4e 117 File f = File.createTempFile("temp", ".xml").getCanonicalFile();
13fd2a91
MK
118 try (FileWriter fw = new FileWriter(f)) {
119 fw.write(TRACE_CONTENT);
120 }
121 File exportPackage = new File(EXPORT_LOCATION);
122 if (exportPackage.exists()) {
123 exportPackage.delete();
124 }
125 assertFalse("File: " + EXPORT_LOCATION + " already present, aborting test", exportPackage.exists());
126 assertTrue("Trace :" + f.getAbsolutePath() + " does not exist, aborting test", f.exists());
127 SWTBotUtils.createProject(PROJECT_NAME);
128 SWTBotUtils.openTrace(PROJECT_NAME, f.getAbsolutePath(), XMLSTUB_ID);
129 SWTBotUtils.waitForJobs();
130 assertEquals("Incorrect opened trace!", f.getAbsolutePath(), (new File(TmfTraceManager.getInstance().getActiveTrace().getPath())).getAbsolutePath());
131 SWTBotView projectExplorerBot = fBot.viewByTitle(PROJECT_EXPLORER);
132 assertNotNull("Cannot find " + PROJECT_EXPLORER, projectExplorerBot);
133 projectExplorerBot.show();
134 SWTBotTreeItem treeItem = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME);
135
136 treeItem.contextMenu(EXPORT_TRACE_PACKAGE).click();
137 fBot = new SWTWorkbenchBot();
138 fBot.button(DESELECT_ALL).click();
139 SWTBotTreeItem[] items = fBot.tree().getAllItems();
140 for (SWTBotTreeItem item : items) {
141 assertEquals(item.isChecked(), false);
142 }
143 fBot.button(SELECT_ALL).click();
144 for (SWTBotTreeItem item : items) {
145 assertEquals(item.isChecked(), true);
146 }
147 fBot.radio(SAVE_IN_TAR_FORMAT).click();
148 fBot.radio(SAVE_IN_ZIP_FORMAT).click();
149
150 fBot.checkBox(COMPRESS_THE_CONTENTS_OF_THE_FILE).click();
151 fBot.checkBox(COMPRESS_THE_CONTENTS_OF_THE_FILE).click();
152 fBot.comboBox().setText(EXPORT_LOCATION);
153 SWTBotShell shell = fBot.activeShell();
154 fBot.button(FINISH).click();
155 // finished exporting
156 SWTBotUtils.waitForJobs();
157 fBot.waitUntil(Conditions.shellCloses(shell));
158 fBot = new SWTWorkbenchBot();
159 exportPackage = new File(EXPORT_LOCATION);
160 assertTrue("Exported package", exportPackage.exists());
161 // Fixme: determine why exportPackageSize is different on different machines
162 // assertEquals("Exported package size check", PACKAGE_SIZE, exportPackage.length());
163
164 // import
165 treeItem = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME);
166 treeItem.contextMenu(IMPORT_TRACE_PACKAGE).click();
167 fBot = new SWTWorkbenchBot();
168 fBot.comboBox().setText(EXPORT_LOCATION);
169 fBot.comboBox().typeText("\n");
170
171 fBot.button(SELECT_ALL).click();
172 shell = fBot.activeShell();
173 fBot.button(FINISH).click();
174 fBot.button("Yes To All").click();
175 fBot.waitUntil(Conditions.shellCloses(shell));
176 fBot = new SWTWorkbenchBot();
177 SWTBotUtils.openEditor(fBot, PROJECT_NAME, new Path(f.getName()));
178 assertEquals("Test if import matches", f.getName(), TmfTraceManager.getInstance().getActiveTrace().getName());
179 assertFalse("Test if import files don't match", f.getAbsolutePath().equals(TmfTraceManager.getInstance().getActiveTrace().getPath()));
180 SWTBotUtils.deleteProject(PROJECT_NAME, fBot);
181 SWTBotUtils.waitForJobs();
182 }
183
184}
This page took 0.031405 seconds and 5 git commands to generate.