aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilliano Molaire2014-04-21 11:07:29 (EDT)
committerGenevieve Bastien2014-04-25 15:00:17 (EDT)
commit13df50ce83e1c57b7d3750a9da8e055b6be3f1d2 (patch)
treeb2e399cfe4dd4a62e5330c414a0f0179188bd648
parent11c45b5c69e73721b190798c3443d9996e80e2db (diff)
downloadorg.eclipse.linuxtools-13df50ce83e1c57b7d3750a9da8e055b6be3f1d2.zip
org.eclipse.linuxtools-13df50ce83e1c57b7d3750a9da8e055b6be3f1d2.tar.gz
org.eclipse.linuxtools-13df50ce83e1c57b7d3750a9da8e055b6be3f1d2.tar.bz2
TMF: Add an analysis requirement helperrefs/changes/85/24285/8
The helper can get lists of requirement values from one or several analysis requirement providers. Change-Id: I16287dd1bbaf99a7f15767ef7d044a81e48457dc 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/24285 Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com> Tested-by: Hudson CI 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.java10
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AnalysisRequirementHelperTest.java171
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisRequirementHelper.java141
3 files changed, 317 insertions, 5 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..5b7efb3 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,11 @@ import org.junit.runners.Suite;
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
- AnalysisModuleTest.class,
- AnalysisModuleHelperTest.class,
- AnalysisManagerTest.class,
- AnalysisParameterProviderTest.class,
- AnalysisRequirementTest.class
+ AnalysisModuleTest.class,
+ AnalysisManagerTest.class,
+ AnalysisParameterProviderTest.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..83243b3
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AnalysisRequirementHelperTest.java
@@ -0,0 +1,171 @@
+/*******************************************************************************
+ * 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.HashSet;
+import java.util.Map;
+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.Test;
+
+/**
+ * Test suite for the {@link TmfAnalysisRequirementHelper} class
+ */
+public class AnalysisRequirementHelperTest {
+
+ private AnalysisRequirementFactory fRequirementFactory = new AnalysisRequirementFactory();
+ private AnalysisModuleTestHelper fTestModuleHelper = new AnalysisModuleTestHelper(moduleStubEnum.TEST);
+ private AnalysisModuleTestHelper 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 = fRequirementFactory.getRequirementType1();
+ Set<String> values = TmfAnalysisRequirementHelper.getRequirementValues(fTestModuleHelper, type);
+ assertEquals(fRequirementFactory.getRequirementValues1().size(), values.size());
+
+ /* Test with a type not supported */
+ type = fRequirementFactory.getRequirementType2();
+ 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 = fRequirementFactory.getRequirementType2();
+ 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 = fRequirementFactory.getRequirementType1();
+ 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);
+
+ Map<String, Set<String>> valuesByType = TmfAnalysisRequirementHelper.getRequirementValuesMap(providers);
+ assertFalse(valuesByType.isEmpty());
+
+ /* There should be 3 types */
+ assertEquals(3, valuesByType.size());
+
+ Set<String> values = valuesByType.get(fRequirementFactory.getRequirementType1());
+ assertEquals(4, values.size());
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue1()));
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue2()));
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue3()));
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue5()));
+
+ values = valuesByType.get(fRequirementFactory.getRequirementType2());
+ assertEquals(5, values.size());
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue1()));
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue2()));
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue3()));
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue4()));
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue5()));
+
+ values = valuesByType.get(fRequirementFactory.getRequirementType3());
+ assertEquals(3, values.size());
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue3()));
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue4()));
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue5()));
+ }
+
+ /**
+ * 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 */
+ Map<String, Set<String>> valuesByType = TmfAnalysisRequirementHelper.getRequirementValuesMap(providers, ValuePriorityLevel.OPTIONAL);
+ assertTrue(!valuesByType.isEmpty());
+ assertEquals(3, valuesByType.size());
+
+ Set<String> values = valuesByType.get(fRequirementFactory.getRequirementType1());
+ assertTrue(values.isEmpty());
+
+ values = valuesByType.get(fRequirementFactory.getRequirementType2());
+ assertEquals(2, values.size());
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue2()));
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue4()));
+
+ values = valuesByType.get(fRequirementFactory.getRequirementType3());
+ assertTrue(values.isEmpty());
+
+ /* And 3 types with mandatory requirements */
+ valuesByType = TmfAnalysisRequirementHelper.getRequirementValuesMap(providers, ValuePriorityLevel.MANDATORY);
+ assertTrue(!valuesByType.isEmpty());
+ assertEquals(3, valuesByType.size());
+
+ values = valuesByType.get(fRequirementFactory.getRequirementType1());
+ assertEquals(4, values.size());
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue1()));
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue2()));
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue3()));
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue5()));
+
+ values = valuesByType.get(fRequirementFactory.getRequirementType2());
+ assertEquals(3, values.size());
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue1()));
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue3()));
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue5()));
+
+ values = valuesByType.get(fRequirementFactory.getRequirementType3());
+ assertEquals(3, values.size());
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue3()));
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue4()));
+ assertTrue(values.contains(fRequirementFactory.getRequirementValue5()));
+ }
+
+}
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..c4c6616
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisRequirementHelper.java
@@ -0,0 +1,141 @@
+/*******************************************************************************
+ * 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.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisRequirement.ValuePriorityLevel;
+
+/**
+ * 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 Map<String, Set<String>> getRequirementValuesMap(Iterable<IAnalysisRequirementProvider> providers) {
+ Map<String, Set<String>> valuesByType = new HashMap<>();
+ for (IAnalysisRequirementProvider provider : providers) {
+ for (TmfAnalysisRequirement requirement : provider.getAnalysisRequirements()) {
+ Set<String> values = valuesByType.get(requirement.getType());
+ if (values == null) {
+ values = new HashSet<>();
+ }
+ /* Since it's a set, there will be no duplicate */
+ values.addAll(requirement.getValues());
+ valuesByType.put(requirement.getType(), values);
+ }
+ }
+ 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.
+ *
+ * All types of requirement needed by the providers will be returned, but
+ * the values may be empty if none has the requested priority level.
+ *
+ * @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 Map<String, Set<String>> getRequirementValuesMap(Iterable<IAnalysisRequirementProvider> providers, ValuePriorityLevel level) {
+ Map<String, Set<String>> valuesByType = new HashMap<>();
+ for (IAnalysisRequirementProvider provider : providers) {
+ for (TmfAnalysisRequirement requirement : provider.getAnalysisRequirements()) {
+ Set<String> values = valuesByType.get(requirement.getType());
+ if (values == null) {
+ values = new HashSet<>();
+ }
+ /* Since it's a set, there will be no duplicate */
+ for (String value : requirement.getValues()) {
+ if (requirement.getValueLevel(value) == level) {
+ values.add(value);
+ }
+ }
+ valuesByType.put(requirement.getType(), values);
+ }
+ }
+ return valuesByType;
+ }
+}