/***********************************************************
 Copyright (C) 2004 VeriSign, Inc.

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

 http://www.verisign.com/nds/naming/change/techdocs.html
 ***********************************************************/

package com.verisign.epp.codec.changeext;

import com.verisign.epp.codec.change.EPPChangeCheckCmd;
import com.verisign.epp.codec.gen.EPPCodecException;
import com.verisign.epp.codec.gen.EPPCodecTst;
import com.verisign.epp.codec.gen.EPPCommand;
import com.verisign.epp.codec.gen.EPPEncodeDecodeStats;
import com.verisign.epp.codec.gen.EPPFactory;
import com.verisign.epp.codec.gen.EPPResponse;
import com.verisign.epp.codec.gen.EPPTransId;
import com.verisign.epp.util.TestThread;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * Is a unit test of the com.verisign.epp.codec.changeext package. The unit test
 * will execute, gather statistics, and output the results of a test of each
 * com.verisign.epp.codec.changeext package concrete extension
 * <code>EPPCodecComponent</code>'s. <br>
 * The unit test is dependent on the use of <a
 * href=http://www.mcwestcorp.com/Junit.html>JUNIT 3.5</a><br>
 * <br>
 * @author $Author: jim $
 * @version $Revision: 1.4 $
 */
public class EPPChangeExtTst {

  static public final String CLTRID = "CLI-12345";
  static public final String SVTRID = "ABCDE-SRV";
  /**
   * Number of unit test iterations to run. This is set in
   * <code>EPPCodecTst.main</code>
   */
  static private long numIterations = 1;

  /**
   * Unit test on extending an EPPComponent with an EPPChangeExt. The
   * particular EPPComponent doesn't matter. In order to avoid external
   * dependencies I'm using an EPPChangeCheckCmd. In practice, EPP Domain and
   * EPP Host commands are more likely. This test will be invoked by JUNIT,
   * since it is prefixed with "test" and is a public method.
   */
  @Test
  public void testChangeExt() {
    EPPCodecTst.printStart("testChangeExt");

    EPPTransId aTransId = new EPPTransId(CLTRID, SVTRID);
    EPPEncodeDecodeStats stats;
    EPPCommand cmd;
    EPPResponse rsp;

    cmd = new EPPChangeCheckCmd(CLTRID, "tk421");
    cmd.addExtension(new EPPChangeExt("thx1138"));
    stats = EPPCodecTst.testEncodeDecode(cmd);

    rsp = new EPPResponse(aTransId);
    stats = EPPCodecTst.testEncodeDecode(rsp);

    EPPCodecTst.printEnd("testChangeExt");
  }

  /**
   * JUNIT <code>suite</code> static method, which returns the tests
   * associated with <code>EPPChangeExtTst</code>.
   */
  @BeforeClass
  public static void beforeClass() {
    EPPCodecTst.initEnvironment();

    // iterations Property
    String numIterProp = System.getProperty("iterations");

    if (numIterProp != null) {
      numIterations = Integer.parseInt(numIterProp);
    }

    // Add the EPPNSProductExtFactory to the EPPCodec.
    try {
      EPPFactory.getInstance().addMapFactory(
          "com.verisign.epp.codec.change.EPPChangeMapFactory");
      EPPFactory.getInstance().addExtFactory(
          "com.verisign.epp.codec.changeext.EPPChangeExtFactory");
    } catch (EPPCodecException e) {
      Assert.fail("EPPCodecException adding factories to EPPCodec: " + e);
    }
  }

  // End EPPChangeExtTst.suite()

  /**
   * Sets the number of iterations to run per test.
   * @param aNumIterations number of iterations to run per test
   */
  public static void setNumIterations(long aNumIterations) {
    numIterations = aNumIterations;
  }

}
