tmf.core.tests: Add method to simplify XML Trace stub setup
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core.tests / stubs / org / eclipse / tracecompass / tmf / tests / stubs / trace / xml / TmfXmlTraceStub.java
index b2bb7a3fbd82e24ef230c51d7b1e2b5464f521a3..b03109400a76d7f3726037c7ba0d821d94d2c68d 100644 (file)
@@ -14,6 +14,7 @@
 package org.eclipse.tracecompass.tmf.tests.stubs.trace.xml;
 
 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+import static org.junit.Assert.fail;
 
 import java.io.File;
 import java.io.IOException;
@@ -31,6 +32,7 @@ import javax.xml.validation.Validator;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.jdt.annotation.Nullable;
@@ -102,6 +104,27 @@ public class TmfXmlTraceStub extends TmfTrace {
     private Collection<ITmfEventAspect<?>> fAspects = TmfTrace.BASE_ASPECTS;
     private final Collection<ITmfEventAspect<?>> fAdditionalAspects = new HashSet<>();
 
+    /**
+     * Validate and initialize a {@link TmfXmlTraceStub} object
+     *
+     * @param absolutePath
+     *            The absolute file path of the trace file
+     * @return The trace
+     */
+    public static TmfXmlTraceStub setupTrace(IPath absolutePath) {
+        TmfXmlTraceStub trace = new TmfXmlTraceStub();
+        IStatus status = trace.validate(null, absolutePath.toOSString());
+        if (!status.isOK()) {
+            fail(status.getException().getMessage());
+        }
+        try {
+            trace.initTrace(null, absolutePath.toOSString(), TmfEvent.class);
+        } catch (TmfTraceException e) {
+            fail(e.getMessage());
+        }
+        return trace;
+    }
+
     /**
      * Constructor. Constructs the custom XML trace with the appropriate
      * definition.
This page took 0.034329 seconds and 5 git commands to generate.