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