From: Jean-Christian Kouame Date: Wed, 16 Dec 2015 21:19:20 +0000 (-0500) Subject: tmf : Add test suite for the pattern segment builder X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=2fd6b0873002b43ed26b79c6778c89c8085759ab;p=deliverable%2Ftracecompass.git tmf : Add test suite for the pattern segment builder Change-Id: I2ff10d945ce398c943d25a795925a4fc37b0f7b5 Signed-off-by: Jean-Christian Kouame Reviewed-on: https://git.eclipse.org/r/62874 Reviewed-by: Hudson CI Reviewed-by: Genevieve Bastien Tested-by: Genevieve Bastien Reviewed-by: Matthew Khouzam --- diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/.classpath b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/.classpath index 44d08d17ee..1861ed9c81 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/.classpath +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/.classpath @@ -12,5 +12,6 @@ + diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/META-INF/MANIFEST.MF b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/META-INF/MANIFEST.MF index 758960e7e3..33fa99c197 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/META-INF/MANIFEST.MF +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/META-INF/MANIFEST.MF @@ -13,7 +13,8 @@ Require-Bundle: org.junit, org.eclipse.tracecompass.tmf.core.tests, org.eclipse.tracecompass.tmf.ctf.core, org.eclipse.tracecompass.tmf.ctf.core.tests, - org.eclipse.tracecompass.statesystem.core + org.eclipse.tracecompass.statesystem.core, + org.eclipse.tracecompass.segmentstore.core Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy Import-Package: com.google.common.collect;version="10.0.1", diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/build.properties b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/build.properties index 02557ecde0..84e7c9cde0 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/build.properties +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/build.properties @@ -10,7 +10,8 @@ # Ericsson - Initial API and implementation ############################################################################### source.. = src/,\ - common/ + common/,\ + stubs/ output.. = bin/ bin.includes = META-INF/,\ .,\ diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/common/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/common/TmfXmlTestFiles.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/common/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/common/TmfXmlTestFiles.java index 810f6def56..5aa363d10f 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/common/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/common/TmfXmlTestFiles.java +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/common/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/common/TmfXmlTestFiles.java @@ -42,7 +42,9 @@ public enum TmfXmlTestFiles { /** A valid file for conditions tests */ CONDITION_FILE("test_xml_files/test_valid/test_conditions.xml"), /** A valid file for pattern tests */ - VALID_PATTERN_FILE("test_xml_files/test_valid/test_valid_pattern.xml"); + VALID_PATTERN_FILE("test_xml_files/test_valid/test_valid_pattern.xml"), + /** A valid pattern file to test the pattern segment **/ + VALID_PATTERN_SEGMENT("test_xml_files/test_valid/test_pattern_segment.xml"); private final String fPath; diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/module/XmlUtilsTest.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/module/XmlUtilsTest.java index 851674af91..ffbbe7cd19 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/module/XmlUtilsTest.java +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/module/XmlUtilsTest.java @@ -19,7 +19,9 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.File; +import java.util.Iterator; import java.util.List; +import java.util.Map; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; @@ -34,6 +36,7 @@ import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedE import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval; import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue; import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils; +import org.eclipse.tracecompass.tmf.analysis.xml.core.segment.TmfXmlPatternSegment; import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings; import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule; import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.Activator; @@ -290,4 +293,30 @@ public class XmlUtilsTest { } } + /** + * Test a pattern segment against what is expected + * + * @param expected + * The expected pattern segment + * @param actual + * The actual pattern segment + */ + public static void testPatternSegmentData(TmfXmlPatternSegment expected, TmfXmlPatternSegment actual) { + assertEquals("getStart", expected.getStart(), actual.getStart()); + assertEquals("getEnd", expected.getEnd(), actual.getEnd()); + assertEquals("getScale", expected.getScale(), actual.getScale()); + assertEquals("getName", expected.getName(), actual.getName()); + assertNotNull("getContent", actual.getContent()); + + // Test the content of the pattern segment + assertEquals("content size", expected.getContent().size(), actual.getContent().size()); + Iterator> it2 = expected.getContent().entrySet().iterator(); + for (int i = 0; i < expected.getContent().size(); i++) { + Map.Entry expectedContent = it2.next(); + ITmfStateValue actualValue = actual.getContent().get(expectedContent.getKey()); + assertNotNull("Content " + expectedContent.getKey() + " exists", actualValue); + assertEquals("Content value comparison " + i, 0, expectedContent.getValue().compareTo(actualValue)); + } + } + } diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stateprovider/TmfXmlPatternSegmentBuilderTest.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stateprovider/TmfXmlPatternSegmentBuilderTest.java new file mode 100644 index 0000000000..c67794a33c --- /dev/null +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stateprovider/TmfXmlPatternSegmentBuilderTest.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2016 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + ******************************************************************************/ +package org.eclipse.tracecompass.tmf.analysis.xml.core.tests.stateprovider; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import java.io.File; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlModelFactory; +import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlPatternSegmentBuilder; +import org.eclipse.tracecompass.tmf.analysis.xml.core.model.readwrite.TmfXmlReadWriteModelFactory; +import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils; +import org.eclipse.tracecompass.tmf.analysis.xml.core.segment.TmfXmlPatternSegment; +import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings; +import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles; +import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest; +import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.stubs.PatternSegmentFactoryStub; +import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.stubs.StateSystemContainerStub; +import org.junit.Before; +import org.junit.Test; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * Test suite for the XML pattern segment builder. The builder should create the + * corresponding pattern segment : + * + *

+ * -name : "test" + *

+ *

+ * -content : + *

+ *

+ *     -field1 : 5 + *

+ *

+ *     -field2 : "test" + *

+ *

+ *     -field3 : 1 + *

+ * + * @author Jean-Christian Kouame + */ +public class TmfXmlPatternSegmentBuilderTest { + + private static final @NonNull String ANALYSIS_ID = "xml test pattern segment"; + private final @NonNull StateSystemContainerStub fContainer = new StateSystemContainerStub(); + private final @NonNull ITmfXmlModelFactory fModelFactory = TmfXmlReadWriteModelFactory.getInstance(); + private File fTestXmlFile; + + /** + * test the {@link XmlUtils#xmlValidate(File)} method + */ + @Before + public void testXmlValidate() { + fTestXmlFile = TmfXmlTestFiles.VALID_PATTERN_SEGMENT.getFile(); + if ((fTestXmlFile == null) || !fTestXmlFile.exists()) { + fail("XML pattern test file does not exist"); + } + IStatus status = XmlUtils.xmlValidate(fTestXmlFile); + if (!status.isOK()) { + fail(status.getMessage()); + } + } + + /** + * Create a pattern segment builder that will generate a pattern segment. + * This method test the data of the pattern segment created. + */ + @Test + public void testBuilder() { + Element doc = XmlUtils.getElementInFile(fTestXmlFile.getPath(), TmfXmlStrings.PATTERN, ANALYSIS_ID); + NodeList patternSegments = doc.getElementsByTagName(TmfXmlStrings.SEGMENT); + assertEquals("Number of pattern segments", 2, patternSegments.getLength()); + + final Node item2 = patternSegments.item(1); + assertNotNull("pattern segment 2", item2); + // create a pattern segment builder using the second pattern segment description in the XML pattern file + TmfXmlPatternSegmentBuilder builder = new TmfXmlPatternSegmentBuilder(fModelFactory, (Element) item2, fContainer); + assertNotNull("builder", builder); + + //Create a pattern segment and test its content + TmfXmlPatternSegment segment = builder.generatePatternSegment(PatternSegmentFactoryStub.TEST_2_END_EVENT, + PatternSegmentFactoryStub.TEST_2_START_EVENT.getTimestamp(), + PatternSegmentFactoryStub.TEST_2_END_EVENT.getTimestamp()); + XmlUtilsTest.testPatternSegmentData(PatternSegmentFactoryStub.TEST_2, segment); + } +} diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/stubs/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stubs/PatternSegmentFactoryStub.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/stubs/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stubs/PatternSegmentFactoryStub.java new file mode 100644 index 0000000000..ee5922cc27 --- /dev/null +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/stubs/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stubs/PatternSegmentFactoryStub.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2016 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + ******************************************************************************/ +package org.eclipse.tracecompass.tmf.analysis.xml.core.tests.stubs; + +import java.util.Map; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue; +import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue; +import org.eclipse.tracecompass.tmf.analysis.xml.core.segment.TmfXmlPatternSegment; +import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; +import org.eclipse.tracecompass.tmf.core.event.TmfEvent; +import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; +import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp; +import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; + +import com.google.common.collect.ImmutableMap; + +/** + * Factory generating various pattern segments and data used for tests + * + * @author Jean-Christian Kouame + * + */ +public class PatternSegmentFactoryStub { + + private static final @NonNull String NAME_FIELD_1 = "field1"; + private static final @NonNull String NAME_FIELD_2 = "field2"; + private static final @NonNull String NAME_FIELD_3 = "field3"; + /** + * The content for the segment TEST_2 + */ + private static final @NonNull Map<@NonNull String, @NonNull ITmfStateValue> TEST_2_CONTENT = ImmutableMap + .of(NAME_FIELD_1, TmfStateValue.newValueLong(5l), + NAME_FIELD_2, TmfStateValue.newValueString("test"), + NAME_FIELD_3, TmfStateValue.newValueInt(1)); + + /** + * Start event for pattern segment TEST_2 + */ + public static final @NonNull ITmfEvent TEST_2_START_EVENT = new TmfEvent(null, ITmfContext.UNKNOWN_RANK, new TmfTimestamp(1, ITmfTimestamp.NANOSECOND_SCALE), null, null); + /** + * end event for pattern segment TEST_2 + */ + public static final @NonNull ITmfEvent TEST_2_END_EVENT = new TmfEvent(null, ITmfContext.UNKNOWN_RANK, new TmfTimestamp(10, ITmfTimestamp.NANOSECOND_SCALE), null, null); + + /** + * The pattern segment TEST_2 + */ + public static final @NonNull TmfXmlPatternSegment TEST_2 = new TmfXmlPatternSegment(TEST_2_START_EVENT.getTimestamp().getValue(), TEST_2_END_EVENT.getTimestamp().getValue(), ITmfTimestamp.NANOSECOND_SCALE, "seg_test2", TEST_2_CONTENT); +} diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/stubs/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stubs/StateSystemContainerStub.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/stubs/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stubs/StateSystemContainerStub.java new file mode 100644 index 0000000000..b9f0555e77 --- /dev/null +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/stubs/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stubs/StateSystemContainerStub.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2016 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + ******************************************************************************/ +package org.eclipse.tracecompass.tmf.analysis.xml.core.tests.stubs; + +import java.util.HashSet; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; +import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlLocation; +import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer; + +/** + * This class is a stub for State system Container. + * + * @author Jean-Christian Kouame + * + */ +public class StateSystemContainerStub implements IXmlStateSystemContainer { + + @Override + public String getAttributeValue(String name) { + return null; + } + + @Override + public ITmfStateSystem getStateSystem() { + return null; + } + + @Override + public @NonNull Iterable<@NonNull TmfXmlLocation> getLocations() { + return new HashSet<>(); + } +} diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/test_xml_files/test_valid/test_pattern_segment.xml b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/test_xml_files/test_valid/test_pattern_segment.xml new file mode 100644 index 0000000000..83b7c91ee2 --- /dev/null +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/test_xml_files/test_valid/test_pattern_segment.xml @@ -0,0 +1,59 @@ + + + + + + + + \ No newline at end of file