1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 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 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Adapted for TMF Trace Model 1.0
12 * Alexandre Montplaisir - Port to JUnit4
13 * Marc-Andre Laperle - Adapted to CustomXmlTrace
14 *******************************************************************************/
16 package org
.eclipse
.linuxtools
.tmf
.ui
.tests
.trace
;
18 import java
.io
.BufferedWriter
;
20 import java
.io
.FileWriter
;
21 import java
.text
.SimpleDateFormat
;
22 import java
.util
.Date
;
24 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlTrace
;
25 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.indexer
.ITmfTraceIndexer
;
30 * Test suite for indexing using a CustomXmlTrace.
32 * @author Marc-Andre Laperle
34 public class CustomXmlIndexTest
extends AbstractCustomTraceIndexTest
{
36 private static final String TRACE_DIRECTORY
= System
.getProperty("java.io.tmpdir") + File
.separator
+ "dummyXmlTrace";
37 private static final String TRACE_PATH
= TRACE_DIRECTORY
+ File
.separator
+ "test.xml";
38 private static final String DEFINITION_PATH
= "tracesets" + File
.separator
+ "xml" + File
.separator
+ "testDefinition.xml";
40 private static CustomXmlTraceDefinition
createDefinition() {
41 CustomXmlTraceDefinition
[] definitions
= CustomXmlTraceDefinition
.loadAll(new File(DEFINITION_PATH
).toString());
42 return definitions
[0];
46 protected String
getTraceDirectory() {
47 return TRACE_DIRECTORY
;
51 protected TestTrace
createTrace() throws Exception
{
52 CustomXmlTraceDefinition definition
= createDefinition();
53 final File file
= new File(TRACE_PATH
);
54 BufferedWriter writer
= new BufferedWriter(new FileWriter(file
));
55 writer
.write("<trace>");
56 for (int i
= 0; i
< NB_EVENTS
; ++i
) {
57 SimpleDateFormat f
= new SimpleDateFormat(TIMESTAMP_FORMAT
);
58 String eventStr
= "<element time=\"" + f
.format(new Date(i
)) + "\">message</element>\n";
59 writer
.write(eventStr
);
61 writer
.write("</trace>");
64 return new TestXmlTrace(file
.toString(), definition
, BLOCK_SIZE
);
67 private class TestXmlTrace
extends CustomXmlTrace
implements TestTrace
{
68 public TestXmlTrace(String path
, CustomXmlTraceDefinition createDefinition
, int blockSize
) throws TmfTraceException
{
69 super(null, createDefinition
, path
, blockSize
);
73 protected ITmfTraceIndexer
createIndexer(int interval
) {
74 return new TestIndexer(this, interval
);
78 public TestIndexer
getIndexer() {
79 return (TestIndexer
) super.getIndexer();