aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilliano Molaire2014-04-21 11:07:29 (EDT)
committerGenevieve Bastien2014-05-01 15:14:26 (EDT)
commitb2080ff46b7fb7d282b337862b1d62bc02f83d90 (patch)
tree70c80846cbe0463096181d1d06fde21ded34d5d0
parent4dd4cd835d76289f0cae5ceba3549091db326a74 (diff)
downloadorg.eclipse.linuxtools-b2080ff46b7fb7d282b337862b1d62bc02f83d90.zip
org.eclipse.linuxtools-b2080ff46b7fb7d282b337862b1d62bc02f83d90.tar.gz
org.eclipse.linuxtools-b2080ff46b7fb7d282b337862b1d62bc02f83d90.tar.bz2
TMF: Add an analysis requirement helperrefs/changes/89/25589/3
The helper can get lists of requirement values from one or several analysis requirement providers. Change-Id: I30ab18a04aa17eda1cc49e8e6332690ae4bf6528 Signed-off-by: Guilliano Molaire <guilliamo-jaime.molaire@polymtl.ca> Signed-off-by: Mathieu Rail <contact@mathieurail.com> Reviewed-on: https://git.eclipse.org/r/25589 Tested-by: Hudson CI Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net> Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AllTests.java5
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AnalysisRequirementHelperTest.java182
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisRequirementHelper.java128
3 files changed, 313 insertions, 2 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AllTests.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AllTests.java
index 8dbb609..a97a023 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AllTests.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AllTests.java
@@ -20,11 +20,12 @@ import org.junit.runners.Suite;
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
+ AnalysisManagerTest.class,
AnalysisModuleTest.class,
AnalysisModuleHelperTest.class,
- AnalysisManagerTest.class,
AnalysisParameterProviderTest.class,
- AnalysisRequirementTest.class
+ AnalysisRequirementTest.class,
+ AnalysisRequirementHelperTest.class
})
public class AllTests {
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AnalysisRequirementHelperTest.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AnalysisRequirementHelperTest.java
new file mode 100644
index 0000000..65f1366
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AnalysisRequirementHelperTest.java
@@ -0,0 +1,182 @@
+/*******************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal
+ *
+ * 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
+ *
+ * Contributors:
+ * Guilliano Molaire - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.analysis;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisRequirementProvider;
+import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisRequirement.ValuePriorityLevel;
+import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisRequirementHelper;
+import org.eclipse.linuxtools.tmf.tests.stubs.analysis.AnalysisModuleTestHelper;
+import org.eclipse.linuxtools.tmf.tests.stubs.analysis.AnalysisModuleTestHelper.moduleStubEnum;
+import org.eclipse.linuxtools.tmf.tests.stubs.analysis.AnalysisRequirementFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.Multimap;
+
+/**
+ * Test suite for the {@link TmfAnalysisRequirementHelper} class
+ */
+public class AnalysisRequirementHelperTest {
+
+ private AnalysisModuleTestHelper fTestModuleHelper;
+ private AnalysisModuleTestHelper fTestModuleHelper2;
+
+ /**
+ * Set up analysis modules
+ */
+ @Before
+ public void setUpTest() {
+ fTestModuleHelper = new AnalysisModuleTestHelper(moduleStubEnum.TEST);
+ fTestModuleHelper2 = new AnalysisModuleTestHelper(moduleStubEnum.TEST2);
+ }
+
+ /**
+ * Test suite for the
+ * {@link TmfAnalysisRequirementHelper#getRequirementValues(IAnalysisRequirementProvider, String)}
+ * method
+ */
+ @Test
+ public void testGetRequirementValues() {
+ /* Test with a supported type */
+ String type = AnalysisRequirementFactory.REQUIREMENT_TYPE_1;
+ Set<String> values = TmfAnalysisRequirementHelper.getRequirementValues(fTestModuleHelper, type);
+ assertEquals(AnalysisRequirementFactory.REQUIREMENT_VALUES_1.size(), values.size());
+
+ /* Test with a type not supported */
+ type = AnalysisRequirementFactory.REQUIREMENT_TYPE_2;
+ values = TmfAnalysisRequirementHelper.getRequirementValues(fTestModuleHelper, type);
+ assertTrue(values.isEmpty());
+ }
+
+ /**
+ * Test suite for the
+ * {@link TmfAnalysisRequirementHelper#getRequirementValues(IAnalysisRequirementProvider, String, ValuePriorityLevel)}
+ * method
+ */
+ @Test
+ public void testGetRequirementValuesWithLevel() {
+ /* Test with a supported type */
+ String type = AnalysisRequirementFactory.REQUIREMENT_TYPE_2;
+ Set<String> values = TmfAnalysisRequirementHelper.getRequirementValues(fTestModuleHelper2, type, ValuePriorityLevel.MANDATORY);
+ assertEquals(3, values.size());
+
+ /* Test with another value level */
+ values = TmfAnalysisRequirementHelper.getRequirementValues(fTestModuleHelper2, type, ValuePriorityLevel.OPTIONAL);
+ assertEquals(2, values.size());
+
+ /* Test with a type not supported */
+ type = AnalysisRequirementFactory.REQUIREMENT_TYPE_1;
+ values = TmfAnalysisRequirementHelper.getRequirementValues(fTestModuleHelper2, type, ValuePriorityLevel.MANDATORY);
+ assertTrue(values.isEmpty());
+ }
+
+ /**
+ * Test suite for the
+ * {@link TmfAnalysisRequirementHelper#getRequirementValuesMap(Iterable)}
+ * method
+ */
+ @Test
+ public void testGetRequirementValuesMap() {
+ Set<IAnalysisRequirementProvider> providers = new HashSet<>();
+ providers.add(fTestModuleHelper2);
+ providers.add(fTestModuleHelper);
+
+ Multimap<String, String> valuesByType = TmfAnalysisRequirementHelper.getRequirementValuesMap(providers);
+ assertFalse(valuesByType.isEmpty());
+
+ /* There should be 3 types */
+ assertEquals(3, valuesByType.keySet().size());
+
+ Collection<String> values = valuesByType.get(AnalysisRequirementFactory.REQUIREMENT_TYPE_1);
+ assertEquals(4, values.size());
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_1));
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_2));
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_3));
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_5));
+
+ values = valuesByType.get(AnalysisRequirementFactory.REQUIREMENT_TYPE_2);
+ assertEquals(5, values.size());
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_1));
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_2));
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_3));
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_4));
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_5));
+
+ values = valuesByType.get(AnalysisRequirementFactory.REQUIREMENT_TYPE_3);
+ assertEquals(3, values.size());
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_3));
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_4));
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_5));
+ }
+
+ /**
+ * Test suite for the
+ * {@link TmfAnalysisRequirementHelper#getRequirementValuesMap(Iterable, ValuePriorityLevel)}
+ * method
+ */
+ @Test
+ public void testGetRequirementValuesMapWithLevel() {
+ Set<IAnalysisRequirementProvider> providers = new HashSet<>();
+ providers.add(fTestModuleHelper2);
+ providers.add(fTestModuleHelper);
+
+ /* There should be 3 optional requirements types */
+ Multimap<String, String> valuesByType = TmfAnalysisRequirementHelper.getRequirementValuesMap(providers, ValuePriorityLevel.OPTIONAL);
+ assertTrue(!valuesByType.isEmpty());
+ assertEquals(1, valuesByType.keySet().size());
+
+ Collection<String> values = valuesByType.get(AnalysisRequirementFactory.REQUIREMENT_TYPE_1);
+ assertTrue(values.isEmpty());
+
+ values = valuesByType.get(AnalysisRequirementFactory.REQUIREMENT_TYPE_2);
+ assertEquals(2, values.size());
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_2));
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_4));
+
+ values = valuesByType.get(AnalysisRequirementFactory.REQUIREMENT_TYPE_3);
+ assertTrue(values.isEmpty());
+
+ /* And 3 types with mandatory requirements */
+ valuesByType = TmfAnalysisRequirementHelper.getRequirementValuesMap(providers, ValuePriorityLevel.MANDATORY);
+ assertTrue(!valuesByType.isEmpty());
+ assertEquals(3, valuesByType.keySet().size());
+
+ values = valuesByType.get(AnalysisRequirementFactory.REQUIREMENT_TYPE_1);
+ assertEquals(4, values.size());
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_1));
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_2));
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_3));
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_5));
+
+ values = valuesByType.get(AnalysisRequirementFactory.REQUIREMENT_TYPE_2);
+ assertEquals(3, values.size());
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_1));
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_3));
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_5));
+
+ values = valuesByType.get(AnalysisRequirementFactory.REQUIREMENT_TYPE_3);
+ assertEquals(3, values.size());
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_3));
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_4));
+ assertTrue(values.contains(AnalysisRequirementFactory.REQUIREMENT_VALUE_5));
+ }
+
+}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisRequirementHelper.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisRequirementHelper.java
new file mode 100644
index 0000000..4377ced
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisRequirementHelper.java
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal
+ *
+ * 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
+ *
+ * Contributors:
+ * Guilliano Molaire - Initial API and implementation
+ * Mathieu Rail - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.analysis;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisRequirement.ValuePriorityLevel;
+
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.SetMultimap;
+
+/**
+ * Helper class to simplify analysis requirement management.
+ *
+ * @author Guilliano Molaire
+ * @since 3.0
+ */
+public final class TmfAnalysisRequirementHelper {
+
+ /**
+ * Private constructor. The class should not be instantiated.
+ */
+ private TmfAnalysisRequirementHelper() {
+ }
+
+ /**
+ * Gets the requirement values of a given type from an analysis requirement
+ * provider. Only values linked to the type will be returned.
+ *
+ * @param provider
+ * The analysis requirement provider
+ * @param type
+ * The type of the requirement values we need
+ * @return The list of values for the specified type
+ */
+ public static Set<String> getRequirementValues(IAnalysisRequirementProvider provider, String type) {
+ Set<String> values = new HashSet<>();
+ for (TmfAnalysisRequirement requirement : provider.getAnalysisRequirements()) {
+ if (requirement.getType().equalsIgnoreCase(type)) {
+ values.addAll(requirement.getValues());
+ }
+ }
+ return values;
+ }
+
+ /**
+ * Gets the requirement values of a given type from an analysis requirement
+ * provider, with the specified level. Only values associated with that type
+ * and level will be returned.
+ *
+ * @param provider
+ * The analysis requirement provider
+ * @param type
+ * The type of the requirement values we need
+ * @param level
+ * The priority level of the values to be returned
+ * @return The list of values for the specified type
+ */
+ public static Set<String> getRequirementValues(IAnalysisRequirementProvider provider, String type, ValuePriorityLevel level) {
+ Set<String> values = new HashSet<>();
+ for (TmfAnalysisRequirement requirement : provider.getAnalysisRequirements()) {
+ if (requirement.getType().equalsIgnoreCase(type)) {
+ for (String value : requirement.getValues()) {
+ if (requirement.getValueLevel(value) == level) {
+ values.add(value);
+ }
+ }
+ }
+ }
+ return values;
+ }
+
+ /**
+ * Gets a map in which the keys are the types of different requirements and
+ * the values represent a set of requirement values linked to that type.
+ *
+ * @param providers
+ * The set of analysis requirement provider
+ * @return A map with the values keyed by type
+ */
+ public static SetMultimap<String, String> getRequirementValuesMap(Iterable<IAnalysisRequirementProvider> providers) {
+ SetMultimap<String, String> valuesByType = HashMultimap.create();
+ for (IAnalysisRequirementProvider provider : providers) {
+ for (TmfAnalysisRequirement requirement : provider.getAnalysisRequirements()) {
+ valuesByType.putAll(requirement.getType(), requirement.getValues());
+ }
+ }
+ return valuesByType;
+ }
+
+ /**
+ * Gets a map in which the keys are the types of different requirements and
+ * the values represents a list of requirement values linked to that type.
+ * We only take values with the same priority level as the argument.
+ *
+ * @param providers
+ * The set of analysis requirement provider
+ * @param level
+ * The priority level of the values to be returned
+ * @return A map with the values keyed by type
+ */
+ public static SetMultimap<String, String> getRequirementValuesMap(Iterable<IAnalysisRequirementProvider> providers, ValuePriorityLevel level) {
+ SetMultimap<String, String> valuesByType = HashMultimap.create();
+ for (IAnalysisRequirementProvider provider : providers) {
+ for (TmfAnalysisRequirement requirement : provider.getAnalysisRequirements()) {
+ /* Since it's a set, there will be no duplicate */
+ for (String value : requirement.getValues()) {
+ if (requirement.getValueLevel(value) == level) {
+ valuesByType.put(requirement.getType(), value);
+ }
+ }
+ }
+ }
+ return valuesByType;
+ }
+}