Commit | Line | Data |
---|---|---|
41a0d150 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2014, 2015 Ericsson |
41a0d150 MK |
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 | ||
fa24d78b | 13 | package org.eclipse.tracecompass.tmf.ui.swtbot.tests.parsers.custom; |
41a0d150 MK |
14 | |
15 | import java.io.File; | |
16 | import java.io.FileNotFoundException; | |
17 | import java.io.IOException; | |
18 | import java.io.RandomAccessFile; | |
19 | ||
20 | import org.apache.log4j.ConsoleAppender; | |
21 | import org.apache.log4j.Logger; | |
22 | import org.apache.log4j.SimpleLayout; | |
23 | import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; | |
24 | import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; | |
fa24d78b | 25 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; |
41a0d150 MK |
26 | import org.junit.BeforeClass; |
27 | ||
28 | /** | |
29 | * Abstract custom parser | |
41a0d150 | 30 | * |
fa24d78b | 31 | * @author Matthew Khouzam |
41a0d150 MK |
32 | */ |
33 | public class AbstractCustomParserWizard { | |
34 | ||
35 | /** The Log4j logger instance. */ | |
fa24d78b | 36 | private static final Logger fLogger = Logger.getRootLogger(); |
41a0d150 MK |
37 | |
38 | /** | |
39 | * The SWTBot running the test | |
40 | */ | |
41 | protected static SWTWorkbenchBot fBot; | |
42 | ||
43 | /** Test Class setup */ | |
44 | @BeforeClass | |
45 | public static void init() { | |
fa24d78b | 46 | SWTBotUtils.failIfUIThread(); |
41a0d150 MK |
47 | Thread.currentThread().setName("SWTBot Thread"); // for the debugger |
48 | /* set up for swtbot */ | |
49 | SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */ | |
50 | fLogger.addAppender(new ConsoleAppender(new SimpleLayout())); | |
51 | fBot = new SWTWorkbenchBot(); | |
52 | ||
fa24d78b | 53 | SWTBotUtils.closeView("welcome", fBot); |
41a0d150 | 54 | |
fa24d78b | 55 | SWTBotUtils.switchToTracingPerspective(); |
41a0d150 | 56 | /* finish waiting for eclipse to load */ |
fa24d78b | 57 | SWTBotUtils.waitForJobs(); |
41a0d150 MK |
58 | |
59 | } | |
60 | ||
61 | /** | |
62 | * Extract test XML file | |
63 | * | |
64 | * @param xmlFile | |
65 | * the XML file to open | |
66 | * @param category | |
67 | * the category of the parser | |
68 | * @param definitionName | |
69 | * the name of the definition | |
70 | * @return an XML string of the definition | |
71 | * @throws IOException | |
72 | * Error reading the file | |
73 | * @throws FileNotFoundException | |
74 | * File is not found | |
75 | */ | |
76 | protected static String extractTestXml(File xmlFile, String category, String definitionName) throws IOException, FileNotFoundException { | |
77 | StringBuilder xmlPart = new StringBuilder(); | |
78 | boolean started = false; | |
79 | try (RandomAccessFile raf = new RandomAccessFile(xmlFile, "r");) { | |
80 | String s = raf.readLine(); | |
81 | while (s != null) { | |
82 | if (s.equals("<Definition category=\"" + category + "\" name=\"" + definitionName + "\">")) { | |
83 | started = true; | |
84 | } | |
85 | if (started) { | |
86 | if (s.equals("</Definition>")) { | |
87 | break; | |
88 | } | |
89 | xmlPart.append(s); | |
90 | xmlPart.append('\n'); | |
91 | } | |
92 | s = raf.readLine(); | |
93 | } | |
94 | } | |
95 | return xmlPart.toString(); | |
96 | } | |
97 | } |