1 /*******************************************************************************
2 * Copyright (c) 2016 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
8 ******************************************************************************/
9 package org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.tests
.stateprovider
;
11 import static org
.junit
.Assert
.assertEquals
;
12 import static org
.junit
.Assert
.assertNotNull
;
13 import static org
.junit
.Assert
.fail
;
17 import org
.eclipse
.core
.runtime
.IStatus
;
18 import org
.eclipse
.jdt
.annotation
.NonNull
;
19 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.model
.ITmfXmlModelFactory
;
20 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.model
.TmfXmlPatternSegmentBuilder
;
21 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.model
.readwrite
.TmfXmlReadWriteModelFactory
;
22 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.module
.XmlUtils
;
23 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.segment
.TmfXmlPatternSegment
;
24 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.stateprovider
.TmfXmlStrings
;
25 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.tests
.common
.TmfXmlTestFiles
;
26 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.tests
.module
.XmlUtilsTest
;
27 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.tests
.stubs
.PatternSegmentFactoryStub
;
28 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.tests
.stubs
.StateSystemContainerStub
;
29 import org
.junit
.Before
;
30 import org
.junit
.Test
;
31 import org
.w3c
.dom
.Element
;
32 import org
.w3c
.dom
.Node
;
33 import org
.w3c
.dom
.NodeList
;
36 * Test suite for the XML pattern segment builder. The builder should create the
37 * corresponding pattern segment :
46 * -field1 : 5
49 * -field2 : "test"
52 * -field3 : 1
55 * @author Jean-Christian Kouame
57 public class TmfXmlPatternSegmentBuilderTest
{
59 private static final @NonNull String ANALYSIS_ID
= "xml test pattern segment";
60 private final @NonNull StateSystemContainerStub fContainer
= new StateSystemContainerStub();
61 private final @NonNull ITmfXmlModelFactory fModelFactory
= TmfXmlReadWriteModelFactory
.getInstance();
62 private File fTestXmlFile
;
65 * test the {@link XmlUtils#xmlValidate(File)} method
68 public void testXmlValidate() {
69 fTestXmlFile
= TmfXmlTestFiles
.VALID_PATTERN_SEGMENT
.getFile();
70 if ((fTestXmlFile
== null) || !fTestXmlFile
.exists()) {
71 fail("XML pattern test file does not exist");
73 IStatus status
= XmlUtils
.xmlValidate(fTestXmlFile
);
75 fail(status
.getMessage());
80 * Create a pattern segment builder that will generate a pattern segment.
81 * This method test the data of the pattern segment created.
84 public void testBuilder() {
85 Element doc
= XmlUtils
.getElementInFile(fTestXmlFile
.getPath(), TmfXmlStrings
.PATTERN
, ANALYSIS_ID
);
86 NodeList patternSegments
= doc
.getElementsByTagName(TmfXmlStrings
.SEGMENT
);
87 assertEquals("Number of pattern segments", 2, patternSegments
.getLength());
89 final Node item2
= patternSegments
.item(1);
90 assertNotNull("pattern segment 2", item2
);
91 // create a pattern segment builder using the second pattern segment description in the XML pattern file
92 TmfXmlPatternSegmentBuilder builder
= new TmfXmlPatternSegmentBuilder(fModelFactory
, (Element
) item2
, fContainer
);
93 assertNotNull("builder", builder
);
95 //Create a pattern segment and test its content
96 TmfXmlPatternSegment segment
= builder
.generatePatternSegment(PatternSegmentFactoryStub
.TEST_2_END_EVENT
,
97 PatternSegmentFactoryStub
.TEST_2_START_EVENT
.getTimestamp(),
98 PatternSegmentFactoryStub
.TEST_2_END_EVENT
.getTimestamp());
99 XmlUtilsTest
.testPatternSegmentData(PatternSegmentFactoryStub
.TEST_2
, segment
);