Commit | Line | Data |
---|---|---|
c750ceef GB |
1 | /******************************************************************************* |
2 | * Copyright (c) 2016 École Polytechnique de Montréal | |
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 | ||
10 | package org.eclipse.tracecompass.tmf.core.tests.analysis.requirements; | |
11 | ||
12 | import static org.junit.Assert.assertFalse; | |
13 | import static org.junit.Assert.assertNotNull; | |
14 | import static org.junit.Assert.assertTrue; | |
15 | ||
16 | import java.util.Collections; | |
17 | ||
18 | import org.eclipse.jdt.annotation.NonNull; | |
58080002 GB |
19 | import org.eclipse.tracecompass.tmf.core.analysis.requirements.TmfAbstractAnalysisRequirement; |
20 | import org.eclipse.tracecompass.tmf.core.analysis.requirements.TmfAbstractAnalysisRequirement.PriorityLevel; | |
c750ceef GB |
21 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
22 | import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub; | |
23 | import org.junit.Before; | |
24 | import org.junit.Test; | |
25 | ||
26 | import com.google.common.collect.ImmutableSet; | |
27 | ||
28 | import org.eclipse.tracecompass.tmf.core.analysis.requirements.TmfCompositeAnalysisRequirement; | |
29 | ||
30 | /** | |
31 | * Test the {@link TmfCompositeAnalysisRequirement} class | |
32 | * | |
33 | * @author Geneviève Bastien | |
34 | */ | |
35 | public class CompositeRequirementTest { | |
36 | ||
58080002 | 37 | private static final @NonNull TmfAbstractAnalysisRequirement FALSE_REQ1 = new TmfAbstractAnalysisRequirement(Collections.EMPTY_SET, PriorityLevel.MANDATORY) { |
c750ceef GB |
38 | @Override |
39 | public boolean test(ITmfTrace trace) { | |
40 | return false; | |
41 | } | |
42 | }; | |
43 | ||
58080002 | 44 | private static final @NonNull TmfAbstractAnalysisRequirement FALSE_REQ2 = new TmfAbstractAnalysisRequirement(Collections.EMPTY_SET, PriorityLevel.MANDATORY) { |
c750ceef GB |
45 | @Override |
46 | public boolean test(ITmfTrace trace) { | |
47 | return false; | |
48 | } | |
49 | }; | |
50 | ||
58080002 | 51 | private static final @NonNull TmfAbstractAnalysisRequirement TRUE_REQ1 = new TmfAbstractAnalysisRequirement(Collections.EMPTY_SET, PriorityLevel.MANDATORY) { |
c750ceef GB |
52 | @Override |
53 | public boolean test(ITmfTrace trace) { | |
54 | return true; | |
55 | } | |
56 | }; | |
57 | ||
58080002 | 58 | private static final @NonNull TmfAbstractAnalysisRequirement TRUE_REQ2 = new TmfAbstractAnalysisRequirement(Collections.EMPTY_SET, PriorityLevel.MANDATORY) { |
c750ceef GB |
59 | @Override |
60 | public boolean test(ITmfTrace trace) { | |
61 | return true; | |
62 | } | |
63 | }; | |
64 | ||
65 | private ITmfTrace fTrace; | |
66 | ||
67 | /** | |
68 | * Setup a trace to be used in tests | |
69 | */ | |
70 | @Before | |
71 | public void setupTrace() { | |
72 | fTrace = new TmfTraceStub(); | |
73 | } | |
74 | ||
75 | /** | |
76 | * Test composite requirement with {@link PriorityLevel#MANDATORY} level | |
77 | */ | |
78 | @Test | |
79 | public void testMandatory() { | |
80 | ITmfTrace trace = fTrace; | |
81 | assertNotNull(trace); | |
82 | ||
58080002 | 83 | TmfAbstractAnalysisRequirement req = new TmfCompositeAnalysisRequirement(ImmutableSet.of(TRUE_REQ1), PriorityLevel.MANDATORY); |
c750ceef GB |
84 | assertTrue(req.test(trace)); |
85 | ||
86 | req = new TmfCompositeAnalysisRequirement(ImmutableSet.of(TRUE_REQ1, TRUE_REQ2), PriorityLevel.MANDATORY); | |
87 | assertTrue(req.test(trace)); | |
88 | ||
89 | req = new TmfCompositeAnalysisRequirement(ImmutableSet.of(FALSE_REQ1), PriorityLevel.MANDATORY); | |
90 | assertFalse(req.test(trace)); | |
91 | ||
92 | req = new TmfCompositeAnalysisRequirement(ImmutableSet.of(FALSE_REQ1, TRUE_REQ1), PriorityLevel.MANDATORY); | |
93 | assertFalse(req.test(trace)); | |
94 | ||
95 | req = new TmfCompositeAnalysisRequirement(ImmutableSet.of(FALSE_REQ1, FALSE_REQ2), PriorityLevel.MANDATORY); | |
96 | assertFalse(req.test(trace)); | |
97 | } | |
98 | ||
99 | /** | |
100 | * Test composite requirement with {@link PriorityLevel#AT_LEAST_ONE} level | |
101 | */ | |
102 | @Test | |
103 | public void testAtLeastOne() { | |
104 | ITmfTrace trace = fTrace; | |
105 | assertNotNull(trace); | |
106 | ||
58080002 | 107 | TmfAbstractAnalysisRequirement req = new TmfCompositeAnalysisRequirement(ImmutableSet.of(TRUE_REQ1), PriorityLevel.AT_LEAST_ONE); |
c750ceef GB |
108 | assertTrue(req.test(trace)); |
109 | ||
110 | req = new TmfCompositeAnalysisRequirement(ImmutableSet.of(TRUE_REQ1, TRUE_REQ2), PriorityLevel.AT_LEAST_ONE); | |
111 | assertTrue(req.test(trace)); | |
112 | ||
113 | req = new TmfCompositeAnalysisRequirement(ImmutableSet.of(FALSE_REQ1), PriorityLevel.AT_LEAST_ONE); | |
114 | assertFalse(req.test(trace)); | |
115 | ||
116 | req = new TmfCompositeAnalysisRequirement(ImmutableSet.of(FALSE_REQ1, TRUE_REQ1), PriorityLevel.AT_LEAST_ONE); | |
117 | assertTrue(req.test(trace)); | |
118 | ||
119 | req = new TmfCompositeAnalysisRequirement(ImmutableSet.of(FALSE_REQ1, FALSE_REQ2), PriorityLevel.AT_LEAST_ONE); | |
120 | assertFalse(req.test(trace)); | |
121 | } | |
122 | ||
123 | /** | |
124 | * Test composite requirement with {@link PriorityLevel#ALL_OR_NOTHING} level | |
125 | */ | |
126 | @Test | |
127 | public void testAllOrNothing() { | |
128 | ITmfTrace trace = fTrace; | |
129 | assertNotNull(trace); | |
130 | ||
58080002 | 131 | TmfAbstractAnalysisRequirement req = new TmfCompositeAnalysisRequirement(ImmutableSet.of(TRUE_REQ1), PriorityLevel.ALL_OR_NOTHING); |
c750ceef GB |
132 | assertTrue(req.test(trace)); |
133 | ||
134 | req = new TmfCompositeAnalysisRequirement(ImmutableSet.of(TRUE_REQ1, TRUE_REQ2), PriorityLevel.ALL_OR_NOTHING); | |
135 | assertTrue(req.test(trace)); | |
136 | ||
137 | req = new TmfCompositeAnalysisRequirement(ImmutableSet.of(FALSE_REQ1), PriorityLevel.ALL_OR_NOTHING); | |
138 | assertTrue(req.test(trace)); | |
139 | ||
140 | req = new TmfCompositeAnalysisRequirement(ImmutableSet.of(FALSE_REQ1, TRUE_REQ1), PriorityLevel.ALL_OR_NOTHING); | |
141 | assertFalse(req.test(trace)); | |
142 | ||
143 | req = new TmfCompositeAnalysisRequirement(ImmutableSet.of(FALSE_REQ1, FALSE_REQ2), PriorityLevel.ALL_OR_NOTHING); | |
144 | assertTrue(req.test(trace)); | |
145 | } | |
146 | ||
147 | /** | |
148 | * Test composite requirement with {@link PriorityLevel#OPTIONAL} level | |
149 | */ | |
150 | @Test | |
151 | public void testOptional() { | |
152 | ITmfTrace trace = fTrace; | |
153 | assertNotNull(trace); | |
154 | ||
58080002 | 155 | TmfAbstractAnalysisRequirement req = new TmfCompositeAnalysisRequirement(ImmutableSet.of(TRUE_REQ1), PriorityLevel.OPTIONAL); |
c750ceef GB |
156 | assertTrue(req.test(trace)); |
157 | ||
158 | req = new TmfCompositeAnalysisRequirement(ImmutableSet.of(TRUE_REQ1, TRUE_REQ2), PriorityLevel.OPTIONAL); | |
159 | assertTrue(req.test(trace)); | |
160 | ||
161 | req = new TmfCompositeAnalysisRequirement(ImmutableSet.of(FALSE_REQ1), PriorityLevel.OPTIONAL); | |
162 | assertTrue(req.test(trace)); | |
163 | ||
164 | req = new TmfCompositeAnalysisRequirement(ImmutableSet.of(FALSE_REQ1, TRUE_REQ1), PriorityLevel.OPTIONAL); | |
165 | assertTrue(req.test(trace)); | |
166 | ||
167 | req = new TmfCompositeAnalysisRequirement(ImmutableSet.of(FALSE_REQ1, FALSE_REQ2), PriorityLevel.OPTIONAL); | |
168 | assertTrue(req.test(trace)); | |
169 | } | |
170 | ||
171 | } |