Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2ced11d12a2e8e8565310560869bb6b0193719d6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*******************************************************************************
 * Copyright (c) 2009 IBM Corporation.
 * 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:
 *    IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.linuxtools.systemtap.structures.tests;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.io.File;

import org.eclipse.linuxtools.systemtap.structures.LoggingStreamDaemon;
import org.eclipse.linuxtools.systemtap.structures.runnable.StreamGobbler;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class LoggingStreamDaemonTest {

	@Before
	public void setUp(){
		StreamGobbler gobbler = new StreamGobbler(System.in);
		gobbler.start();
		daemon = new LoggingStreamDaemon();
	}

	@Test
	public void testHandleDataEvent() {
		daemon.handleDataEvent("test");
	}

	@Test
	public void testGetOutput() {
		assertTrue("".equals(daemon.getOutput()));

		daemon.handleDataEvent("test");
		assertTrue("test".equals(daemon.getOutput()));
	}

	@Test
	public void testSaveLog() {
		File f = new File("/tmp/loggingstreamdaemon.test");
		assertTrue(daemon.saveLog(f));
		f.delete();

		daemon.handleDataEvent("test");
		assertTrue(daemon.saveLog(f));
		f.delete();

		f = new File("/root/");
		assertFalse(daemon.saveLog(f));
		f.delete();
	}

	@After
	public void tearDown() {
		daemon.dispose();
		assertNull(daemon.getOutput());
	}

	private LoggingStreamDaemon daemon;
}

Back to the top