137N/A/*
137N/A * CDDL HEADER START
137N/A *
137N/A * The contents of this file are subject to the terms of the
137N/A * Common Development and Distribution License (the "License").
137N/A * You may not use this file except in compliance with the License.
137N/A *
137N/A * See LICENSE.txt included in this distribution for the specific
137N/A * language governing permissions and limitations under the License.
137N/A *
137N/A * When distributing Covered Code, include this CDDL HEADER in each
137N/A * file and include the License file at LICENSE.txt.
137N/A * If applicable, add the following below this CDDL HEADER, with the
137N/A * fields enclosed by brackets "[]" replaced with your own identifying
137N/A * information: Portions Copyright [yyyy] [name of copyright owner]
137N/A *
137N/A * CDDL HEADER END
137N/A */
137N/A
137N/A/*
137N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
137N/A * Use is subject to license terms.
137N/A */
137N/Apackage org.opensolaris.opengrok.util;
137N/A
137N/Aimport java.io.BufferedReader;
137N/Aimport java.io.File;
137N/Aimport java.io.IOException;
137N/Aimport java.util.ArrayList;
137N/Aimport java.util.List;
137N/Aimport org.junit.After;
137N/Aimport org.junit.AfterClass;
137N/Aimport org.junit.Before;
137N/Aimport org.junit.BeforeClass;
137N/Aimport org.junit.Test;
137N/Aimport static org.junit.Assert.*;
137N/A
137N/A/**
137N/A *
137N/A * @author Trond Norbye
137N/A */
137N/Apublic class ExecutorTest {
137N/A
137N/A public ExecutorTest() {
137N/A }
137N/A
137N/A @BeforeClass
137N/A public static void setUpClass() throws Exception {
137N/A }
137N/A
137N/A @AfterClass
137N/A public static void tearDownClass() throws Exception {
137N/A }
137N/A
137N/A @Before
137N/A public void setUp() {
137N/A }
137N/A
137N/A @After
137N/A public void tearDown() {
137N/A }
137N/A
137N/A @Test
137N/A public void testString() throws IOException {
137N/A List<String> cmdList = new ArrayList<String>();
137N/A cmdList.add("echo");
137N/A cmdList.add("testing org.opensolaris.opengrok.util.Executor");
137N/A Executor instance = new Executor(cmdList);
137N/A assertEquals(0, instance.exec());
137N/A assertTrue(instance.getOutputString().startsWith("testing org.opensolaris.opengrok.util.Executor"));
137N/A String err = instance.getErrorString();
137N/A assertEquals(0, err.length());
137N/A }
137N/A
137N/A @Test
137N/A public void testReader() throws IOException {
137N/A List<String> cmdList = new ArrayList<String>();
137N/A cmdList.add("echo");
137N/A cmdList.add("testing org.opensolaris.opengrok.util.Executor");
137N/A Executor instance = new Executor(cmdList);
137N/A assertEquals(0, instance.exec());
137N/A BufferedReader in = new BufferedReader(instance.getOutputReader());
137N/A assertEquals("testing org.opensolaris.opengrok.util.Executor", in.readLine());
137N/A in.close();
137N/A in = new BufferedReader(instance.getErrorReader());
137N/A assertNull(in.readLine());
137N/A in.close();
137N/A }
137N/A
137N/A @Test
137N/A public void testStream() throws IOException {
137N/A List<String> cmdList = new ArrayList<String>();
137N/A cmdList.add("echo");
137N/A cmdList.add("testing org.opensolaris.opengrok.util.Executor");
137N/A Executor instance = new Executor(cmdList, new File("."));
137N/A assertEquals(0, instance.exec());
137N/A assertNotNull(instance.getOutputStream());
137N/A assertNotNull(instance.getErrorStream());
137N/A BufferedReader in = new BufferedReader(instance.getOutputReader());
137N/A assertEquals("testing org.opensolaris.opengrok.util.Executor", in.readLine());
137N/A in.close();
137N/A in = new BufferedReader(instance.getErrorReader());
137N/A assertNull(in.readLine());
137N/A in.close();
137N/A }
137N/A}
137N/A