package nxm.database.test.junit.prim;

import nxm.database.prim.nmjdbc;
import nxm.sys.lib.Args;
import nxm.sys.lib.Midas;
import nxm.sys.lib.Table;
import nxm.sys.test.junit.NMTestCase;

/** Minimal nmjdbc testing
 *  @author Jeanette McCall
 */
public class nmjdbcTest extends NMTestCase {

  /** public constructor to allow running this test case directly with JUnit.
   *  @param midas      The midas context to use when running the tests.
  */
  public nmjdbcTest (String methodName) {
    this(methodName, null);
  }

  /** This constructor is required by NeXtMidas Unit Testing framework.
      @param methodName The name of the method being called.
      @param midas      The midas context to use when running the tests.
  */
  public nmjdbcTest (String methodName, Midas midas) {
    super(methodName, midas);
  }

  /** The goal is to validate that the new Table.getKeys() along with the foreach
   *  behaves the same as the deprecated enumeration(), more(), next(), combination
   */
  public void testDoDelete () {
    nmjdbc nmJDBC = new nmjdbc();
    Args args = new Args(getMidas());
    nmJDBC.setArgs(args);
    nmJDBC.checkin(getMidas());
    Table tbl4doDelete =
        new Table("{PERMGEOS={GEOSKEY1=GEOSVAL1,GEOSKEY2=GEOSVAL2},PERMCMBS={CMBSK1=CMBSV1,CMBSK2=CMBSV2,CMBSK3=CMBSV3}}");
    Table tblCombsdoDelete =
        new Table("{PERMCMBS={CMBSK1=CMBSV1,CMBSK2=CMBSV2,CMBSK3=CMBSV3}}");
    nmJDBC.setCheckAPIUpdate(true);
    try {
      nmJDBC.doDelete(tbl4doDelete);
    }
    catch (NullPointerException npe){
      Table actual = nmJDBC.getAPIUpdateInfo();
      Table expected = new Table("{DODELETE_GEOS=\"('GEOSVAL1','GEOSVAL2')\"}");
      assertEquals("doDelete geos pkays same",expected,actual);
    }
    nmJDBC.setCheckAPIUpdate(true); // clear previous
    try {
      nmJDBC.doDelete(tblCombsdoDelete);
    }
    catch (NullPointerException npe){
      Table actual = nmJDBC.getAPIUpdateInfo();
      Table expected = new Table("{DODELETE_COMBS=\"('CMBSV1','CMBSV2','CMBSV3')\"}");
      assertEquals("doDelete combs pkays same",expected,actual);
    }
    nmJDBC.setCheckAPIUpdate(false);
  }

}