tmf: Add utility method to delete supplementary files of a trace
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.core.tests / src / org / eclipse / tracecompass / tmf / ctf / core / tests / temp / tracemanager / TmfTraceManagerUtilityTest.java
1 /*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir
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.ctf.core.tests.temp.tracemanager;
11
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertTrue;
16 import static org.junit.Assert.fail;
17
18 import java.io.File;
19 import java.io.IOException;
20 import java.nio.file.DirectoryStream;
21 import java.nio.file.Files;
22 import java.nio.file.Path;
23 import java.nio.file.Paths;
24
25 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
26 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
27 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
28 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
29 import org.junit.AfterClass;
30 import org.junit.Before;
31 import org.junit.Test;
32
33 /**
34 * Tests for the utility methods in {@link TmfTraceManager}.
35 *
36 * @author Alexandre Montplaisir
37 */
38 public class TmfTraceManagerUtilityTest {
39
40 private ITmfTrace fTrace;
41
42 /**
43 * Test initialization
44 */
45 @Before
46 public void setup() {
47 fTrace = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.TRACE2);
48 fTrace.indexTrace(true);
49 }
50
51 /**
52 * Test clean-up
53 */
54 @AfterClass
55 public static void teardown() {
56 CtfTmfTestTraceUtils.dispose(CtfTestTrace.TRACE2);
57 }
58
59 /**
60 * Test the {@link TmfTraceManager#getSupplementaryFileDir} method.
61 */
62 @Test
63 public void testSupplementaryFileDir() {
64 final ITmfTrace trace = fTrace;
65 assertNotNull(trace);
66 String name1 = trace.getName();
67 String basePath = TmfTraceManager.getTemporaryDirPath() + File.separator;
68
69 String expected = basePath + name1 + File.separator;
70 assertEquals(expected, TmfTraceManager.getSupplementaryFileDir(trace));
71 }
72
73 /**
74 * Test the {@link TmfTraceManager#deleteSupplementaryFiles} method.
75 */
76 @Test
77 public void testDeleteSupplementaryFiles() {
78 ITmfTrace trace = fTrace;
79 assertNotNull(trace);
80
81 String suppFilesPath = TmfTraceManager.getSupplementaryFileDir(trace);
82 try {
83 /*
84 * Initializing/indexing the trace should have produced some
85 * supplementary files already.
86 */
87 assertFalse(isDirectoryEmpty(suppFilesPath));
88
89 TmfTraceManager.deleteSupplementaryFiles(trace);
90 assertTrue(isDirectoryEmpty(suppFilesPath));
91
92 } catch (IOException e) {
93 fail(e.getMessage());
94 }
95 }
96
97 private static boolean isDirectoryEmpty(String dirPath) throws IOException {
98 Path path = Paths.get(dirPath);
99 try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
100 return !stream.iterator().hasNext();
101 }
102 }
103 }
This page took 0.032616 seconds and 5 git commands to generate.