421023a969fb15baa9a08e728b90332dc58be6c9
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ui / swtbot / tests / wizards / TestImportExportPackageWizard.java
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
13 package org.eclipse.tracecompass.tmf.ui.swtbot.tests.wizards;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertFalse;
17 import static org.junit.Assert.assertNotNull;
18 import static org.junit.Assert.assertTrue;
19
20 import java.io.File;
21 import java.io.FileWriter;
22 import java.io.IOException;
23
24 import org.apache.log4j.ConsoleAppender;
25 import org.apache.log4j.Logger;
26 import org.apache.log4j.SimpleLayout;
27 import org.eclipse.core.runtime.Path;
28 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
29 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
30 import org.eclipse.swtbot.swt.finder.SWTBot;
31 import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
32 import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
33 import org.eclipse.swtbot.swt.finder.waits.Conditions;
34 import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
35 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
36 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
37 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
38 import org.junit.BeforeClass;
39 import org.junit.Test;
40 import org.junit.runner.RunWith;
41
42 /**
43 * Export and Import wizard tests
44 *
45 * @author Matthew Khouzam
46 *
47 */
48 @RunWith(SWTBotJunit4ClassRunner.class)
49 public class TestImportExportPackageWizard {
50
51 // private static final int PACKAGE_SIZE = 213732;
52 private static final String EXPORT_LOCATION = TmfTraceManager.getTemporaryDirPath() + File.separator + "test.zip";
53 private static final String IMPORT_TRACE_PACKAGE = "Import Trace Package...";
54 private static final String IMPORT_TRACE_PACKAGE_TITLE = "Import trace package";
55 private static final String EXPORT_TRACE_PACKAGE = "Export Trace Package...";
56 private static final String EXPORT_TRACE_PACKAGE_TITLE = "Export trace package";
57 private static final String PROJECT_EXPLORER = "Project Explorer";
58 private static final String FINISH = "Finish";
59 private static final String COMPRESS_THE_CONTENTS_OF_THE_FILE = "Compress the contents of the file";
60 private static final String SAVE_IN_ZIP_FORMAT = "Save in zip format";
61 private static final String SAVE_IN_TAR_FORMAT = "Save in tar format";
62 private static final String SELECT_ALL = "Select All";
63 private static final String DESELECT_ALL = "Deselect All";
64 private static final String WELCOME_NAME = "welcome";
65 private static final String SWT_BOT_THREAD_NAME = "SWTBot Thread";
66 private static final String PROJECT_NAME = "Test";
67 private static final String XMLSTUB_ID = "org.eclipse.linuxtools.tmf.core.tests.xmlstub";
68
69 private static final String TRACE_CONTENT = "<trace>" +
70 "<event timestamp=\"100\" name=\"event\"><field name=\"field\" value=\"1\" type=\"int\" /></event>" +
71 "<event timestamp=\"200\" name=\"event1\"><field name=\"field\" value=\"2\" type=\"int\" /></event>" +
72 "<event timestamp=\"201\" name=\"event\"><field name=\"field\" value=\"3\" type=\"int\" /></event>" +
73 "<event timestamp=\"202\" name=\"event1\"><field name=\"field\" value=\"3\" type=\"int\" /></event>" +
74 "<event timestamp=\"203\" name=\"event1\"><field name=\"field\" value=\"3\" type=\"int\" /></event>" +
75 "<event timestamp=\"300\" name=\"event1\"><field name=\"field\" value=\"2\" type=\"int\" /></event>" +
76 "<event timestamp=\"301\" name=\"event\"><field name=\"field\" value=\"3\" type=\"int\" /></event>" +
77 "<event timestamp=\"302\" name=\"event1\"><field name=\"field\" value=\"3\" type=\"int\" /></event>" +
78 "<event timestamp=\"333\" name=\"event1\"><field name=\"field\" value=\"3\" type=\"int\" /></event>" +
79 "<event timestamp=\"500\" name=\"event1\"><field name=\"field\" value=\"2\" type=\"int\" /></event>" +
80 "<event timestamp=\"501\" name=\"event\"><field name=\"field\" value=\"3\" type=\"int\" /></event>" +
81 "<event timestamp=\"502\" name=\"event1\"><field name=\"field\" value=\"3\" type=\"int\" /></event>" +
82 "<event timestamp=\"533\" name=\"event1\"><field name=\"field\" value=\"3\" type=\"int\" /></event>" +
83 "</trace>";
84
85 /** The Log4j logger instance. */
86 private static final Logger fLogger = Logger.getRootLogger();
87 private static SWTWorkbenchBot fBot;
88
89 /** Test Class setup */
90 @BeforeClass
91 public static void init() {
92 SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
93 SWTBotUtils.initialize();
94 Thread.currentThread().setName(SWT_BOT_THREAD_NAME); // for the debugger
95 /* set up for swtbot */
96 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
97 fLogger.addAppender(new ConsoleAppender(new SimpleLayout()));
98 fBot = new SWTWorkbenchBot();
99
100 SWTBotUtils.closeView(WELCOME_NAME, fBot);
101
102 SWTBotUtils.switchToTracingPerspective();
103 /* finish waiting for eclipse to load */
104 SWTBotUtils.waitForJobs();
105
106 }
107
108 /**
109 * test opening a trace, importing
110 *
111 * @throws IOException
112 * won't happen
113 */
114 @Test
115 public void test() throws IOException {
116 File f = File.createTempFile("temp", ".xml").getCanonicalFile();
117 try (FileWriter fw = new FileWriter(f)) {
118 fw.write(TRACE_CONTENT);
119 }
120 File exportPackage = new File(EXPORT_LOCATION);
121 if (exportPackage.exists()) {
122 exportPackage.delete();
123 }
124 assertFalse("File: " + EXPORT_LOCATION + " already present, aborting test", exportPackage.exists());
125 assertTrue("Trace :" + f.getAbsolutePath() + " does not exist, aborting test", f.exists());
126 SWTBotUtils.createProject(PROJECT_NAME);
127 SWTBotUtils.openTrace(PROJECT_NAME, f.getAbsolutePath(), XMLSTUB_ID);
128 SWTBotUtils.waitForJobs();
129 assertEquals("Incorrect opened trace!", f.getAbsolutePath(), (new File(TmfTraceManager.getInstance().getActiveTrace().getPath())).getAbsolutePath());
130 SWTBotView projectExplorerBot = fBot.viewByTitle(PROJECT_EXPLORER);
131 assertNotNull("Cannot find " + PROJECT_EXPLORER, projectExplorerBot);
132 projectExplorerBot.show();
133 SWTBotTreeItem treeItem = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME);
134
135 treeItem.contextMenu(EXPORT_TRACE_PACKAGE).click();
136 fBot.waitUntil(Conditions.shellIsActive(EXPORT_TRACE_PACKAGE_TITLE));
137 SWTBot shellBot = fBot.activeShell().bot();
138 shellBot.button(DESELECT_ALL).click();
139 SWTBotTreeItem[] items = fBot.tree().getAllItems();
140 for (SWTBotTreeItem item : items) {
141 assertEquals(item.isChecked(), false);
142 }
143 shellBot.button(SELECT_ALL).click();
144 for (SWTBotTreeItem item : items) {
145 assertEquals(item.isChecked(), true);
146 }
147 shellBot.radio(SAVE_IN_TAR_FORMAT).click();
148 shellBot.radio(SAVE_IN_ZIP_FORMAT).click();
149
150 shellBot.checkBox(COMPRESS_THE_CONTENTS_OF_THE_FILE).click();
151 shellBot.checkBox(COMPRESS_THE_CONTENTS_OF_THE_FILE).click();
152 shellBot.comboBox().setText(EXPORT_LOCATION);
153 SWTBotShell shell = fBot.activeShell();
154 shellBot.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.waitUntil(Conditions.shellIsActive(IMPORT_TRACE_PACKAGE_TITLE));
168 shellBot = fBot.activeShell().bot();
169 shellBot.comboBox().setText(EXPORT_LOCATION);
170 shellBot.comboBox().typeText("\n");
171
172 shellBot.button(SELECT_ALL).click();
173 shell = fBot.activeShell();
174 shellBot.button(FINISH).click();
175 fBot.button("Yes To All").click();
176 fBot.waitUntil(Conditions.shellCloses(shell));
177 fBot = new SWTWorkbenchBot();
178 SWTBotUtils.openEditor(fBot, PROJECT_NAME, new Path(f.getName()));
179 assertEquals("Test if import matches", f.getName(), TmfTraceManager.getInstance().getActiveTrace().getName());
180 assertFalse("Test if import files don't match", f.getAbsolutePath().equals(TmfTraceManager.getInstance().getActiveTrace().getPath()));
181 SWTBotUtils.deleteProject(PROJECT_NAME, fBot);
182 SWTBotUtils.waitForJobs();
183 }
184
185 }
This page took 0.037718 seconds and 4 git commands to generate.