27b74bc782b92c7079be8891b12a30de58b99fc0
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core.tests / src / org / eclipse / tracecompass / tmf / core / tests / filter / TmfFilterNodeTest.java
1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
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 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.core.tests.filter;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertFalse;
17 import static org.junit.Assert.assertTrue;
18
19 import java.util.Arrays;
20 import java.util.HashSet;
21 import java.util.Set;
22
23 import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
24 import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
25 import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
26 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode;
27 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode;
28 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode;
29 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode;
30 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode;
31 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode;
32 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode;
33 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode;
34 import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
35 import org.junit.Before;
36 import org.junit.Test;
37
38 /**
39 * Test suite for the {@link TmfFilterNode} class.
40 *
41 * @author Patrick Tasse
42 */
43 @SuppressWarnings("javadoc")
44 public class TmfFilterNodeTest extends TmfFilterTreeNodeTestBase {
45
46 // ------------------------------------------------------------------------
47 // Variables
48 // ------------------------------------------------------------------------
49
50 private static final String FILTER = "filter";
51 private ITmfEventField fContent = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, null);
52 private TmfEvent fEvent = new TmfEvent(TRACE, 0, new TmfNanoTimestamp(1), EVENT_TYPE, fContent);
53 private TmfFilterNode fFilter;
54
55 // ------------------------------------------------------------------------
56 // Tests
57 // ------------------------------------------------------------------------
58
59 @Before
60 public void createFilter() {
61 fFilter = new TmfFilterNode(null, FILTER);
62 fFilterNode = fFilter;
63 }
64
65 @Test
66 public void testMatches() {
67 fFilter.addChild(TRUE_NODE);
68 assertTrue(fFilter.matches(fEvent));
69
70 fFilter.replaceChild(0, FALSE_NODE);
71 assertFalse(fFilter.matches(fEvent));
72 }
73
74 @Test
75 public void testGetFilterName() {
76 assertEquals("getFilterName()", FILTER, fFilter.getFilterName());
77 }
78
79 @Test
80 public void testGetName() {
81 assertEquals("getName()", "FILTER", fFilter.getNodeName());
82 }
83
84 @Test
85 public void testGetValidChildren() {
86 Set<String> validChildren = new HashSet<>(Arrays.asList(
87 TmfFilterTraceTypeNode.NODE_NAME,
88 TmfFilterAndNode.NODE_NAME,
89 TmfFilterOrNode.NODE_NAME,
90 TmfFilterContainsNode.NODE_NAME,
91 TmfFilterEqualsNode.NODE_NAME,
92 TmfFilterMatchesNode.NODE_NAME,
93 TmfFilterCompareNode.NODE_NAME));
94 assertEquals("getValidChildren()", validChildren, new HashSet<>(fFilter.getValidChildren()));
95 }
96 }
This page took 0.031792 seconds and 4 git commands to generate.