tmf.core.tests: Allow TmfXmlTraceStub to have additional aspects
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Mon, 21 Mar 2016 17:14:52 +0000 (13:14 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Fri, 1 Apr 2016 13:59:16 +0000 (09:59 -0400)
These aspects can be added individually for each unit test as required.

Change-Id: Ib8a6894239958593f88d91c4d8bcd91d3b7b845a
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/68947
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Hudson CI
tmf/org.eclipse.tracecompass.tmf.core.tests/stubs/org/eclipse/tracecompass/tmf/tests/stubs/trace/xml/TmfXmlTraceStub.java

index f6c3ac83a1940941555ac1eaab3a643aae526512..1477160a08dd9043ae6c7015262390950fca0ddf 100644 (file)
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.util.Collection;
+import java.util.HashSet;
 
 import javax.xml.XMLConstants;
 import javax.xml.transform.Source;
@@ -99,6 +100,7 @@ public class TmfXmlTraceStub extends TmfTrace {
     private CustomXmlTrace fTrace;
 
     private Collection<ITmfEventAspect> fAspects = TmfTrace.BASE_ASPECTS;
+    private final Collection<ITmfEventAspect> fAdditionalAspects = new HashSet<>();
 
     /**
      * Constructor. Constructs the custom XML trace with the appropriate
@@ -293,7 +295,10 @@ public class TmfXmlTraceStub extends TmfTrace {
             fieldsArray[i] = new TmfEventField(checkNotNull(fields[i]), val, null);
         }
 
-        /* Generate the aspects for this trace if it is the 'set_aspects' definition */
+        /*
+         * Generate the aspects for this trace if it is the 'set_aspects'
+         * definition
+         */
         if (fTrace.getDefinition() != fDefinition) {
             generateAspects(fieldsArray);
             return null;
@@ -345,6 +350,8 @@ public class TmfXmlTraceStub extends TmfTrace {
 
         /* Add the big content aspect */
         builder.add(ITmfEventAspect.BaseAspects.CONTENTS);
+        /* Add the additional aspects */
+        builder.addAll(fAdditionalAspects);
         fAspects = builder.build();
     }
 
@@ -353,4 +360,19 @@ public class TmfXmlTraceStub extends TmfTrace {
         return fAspects;
     }
 
+    /**
+     * Adds a new event aspect to this type of trace. Since this trace type is
+     * used to build custom traces that mimic the behavior of real traces, the
+     * required aspects may be missing and this method allows to add them. This
+     * method should be called before calling
+     * {@link #initTrace(IResource, String, Class)} otherwise the additional
+     * aspects will not be picked up when generating the aspects.
+     *
+     * @param aspect
+     *            The aspect to have
+     */
+    public void addEventAspect(ITmfEventAspect aspect) {
+        fAdditionalAspects.add(aspect);
+    }
+
 }
This page took 0.050194 seconds and 5 git commands to generate.