1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.swtbot
.tests
;
16 import java
.io
.FileNotFoundException
;
17 import java
.io
.IOException
;
18 import java
.io
.RandomAccessFile
;
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
;
25 import org
.junit
.BeforeClass
;
28 * Abstract custom parser
29 * @author Matthew Khouzam
32 public class AbstractCustomParserWizard
{
34 /** The Log4j logger instance. */
35 static final Logger fLogger
= Logger
.getRootLogger();
38 * The SWTBot running the test
40 protected static SWTWorkbenchBot fBot
;
42 /** Test Class setup */
44 public static void init() {
45 SWTBotUtil
.failIfUIThread();
46 Thread
.currentThread().setName("SWTBot Thread"); // for the debugger
47 /* set up for swtbot */
48 SWTBotPreferences
.TIMEOUT
= 20000; /* 20 second timeout */
49 fLogger
.addAppender(new ConsoleAppender(new SimpleLayout()));
50 fBot
= new SWTWorkbenchBot();
52 SWTBotUtil
.closeView("welcome", fBot
);
54 SWTBotUtil
.switchToTracingPerspective();
55 /* finish waiting for eclipse to load */
56 SWTBotUtil
.waitForJobs();
61 * Extract test XML file
64 * the XML file to open
66 * the category of the parser
67 * @param definitionName
68 * the name of the definition
69 * @return an XML string of the definition
71 * Error reading the file
72 * @throws FileNotFoundException
75 protected static String
extractTestXml(File xmlFile
, String category
, String definitionName
) throws IOException
, FileNotFoundException
{
76 StringBuilder xmlPart
= new StringBuilder();
77 boolean started
= false;
78 try (RandomAccessFile raf
= new RandomAccessFile(xmlFile
, "r");) {
79 String s
= raf
.readLine();
81 if (s
.equals("<Definition category=\"" + category
+ "\" name=\"" + definitionName
+ "\">")) {
85 if (s
.equals("</Definition>")) {
94 return xmlPart
.toString();