package nxm.sys.test.junit.lib;

import nxm.sys.lib.*;
import nxm.sys.test.junit.NMTestCase;

/** This will test the Foreign class.
    @author Neon Ngo
    @since NeXtMidas 2.5.0
    @version $Id: ForeignTest.java,v 1.4 2013/05/21 20:50:44 ntn Exp $
 */
public final class ForeignTest extends NMTestCase {
  private Midas M;
  private static final String NON_EXISTENT_CMD = "NON_EXISTENT_CMD_NXMXXX arg1 arg2 arg3";

  /** public constructor to allow running this test case directly with JUnit. */
  public ForeignTest (String methodName) { this(methodName, null); }

  /** Creates a new instance of the class.
      @param methodName The name of the method being called.
      @param midas      The midas context testTo use when running the tests.
   */
  public ForeignTest(String methodName, Midas midas) {
    super(methodName, midas);
    M = midas;
  }

  public void testRunInternal() {
    String cmdline = NON_EXISTENT_CMD;
    try {
      Foreign.runInternal(M, cmdline);
      fail("should not be able to execute command: " + cmdline);
    } catch (MidasException e) { // test BUG 1089
      String errMsg = e.getMessage();
      assertTrue("Exception should contain the command to execute: "+e, (errMsg!=null && errMsg.contains(cmdline)));
    }
  }

  // IGNORE these methods
  public void testRun() {}
  public void testToString() {}
  // NTN: cannot run this test without causing it to hang when running "nm conf" from outside NeXtMidas
  public void testRunExternal() {}
}
