package nxm.sys.test.junit.libg;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import nxm.sys.lib.Midas;
import nxm.sys.lib.Table;
import nxm.sys.libg.LayerWMS;
import nxm.sys.test.junit.NMTestCase;

/** Test class for LayerWMS
 *
 *  @author Zachary Matthews
 *  @since  NeXtMidas 4.0.1
 */
public class LayerWMSTest extends NMTestCase {

  private LayerWMS lwms;

  public LayerWMSTest (String methodName) {
    this(methodName, null);
  }

  public LayerWMSTest (String methodName, Midas midas) {
    super(methodName, midas);
  }

  @Before
  public void setUp() {
    lwms = new LayerWMS();
  }

  @Test
  public void testSetByNameCRSs() {
    String crs84Name = "CRS:84", epsg4269Name = "EPSG:4269", epsg4326Name = "EPSG:4326";
    Table crs84Table = new Table("{NAME=\"CRS:84\",X=\"longitude\",Y=\"latitude\",Z=\"none\",ALLOW=\"true\"}"),
        crs83Table = new Table("{NAME=\"CRS:83\",X=\"longitude\",Y=\"latitude\",Z=\"none\",ALLOW=\"true\"}"),
        crs27Table = new Table("{NAME=\"CRS:27\",X=\"longitude\",Y=\"latitude\",Z=\"none\",ALLOW=\"true\"}"),
        crs88Table = new Table("{NAME=\"CRS:88\",X=\"none\",Y=\"none\",Z=\"altitude\",ALLOW=\"true\"}"),
        epsg4269Table = new Table("{NAME=\"EPSG:4269\",X=\"latitude\",Y=\"longitude\",Z=\"none\",ALLOW=\"true\"}"),
        epsg4326Table = new Table("{NAME=\"EPSG:4326\",X=\"latitude\",Y=\"longitude\",Z=\"none\",ALLOW=\"true\"}");
    String expTblStr = "";

    lwms.setByNameCRSs(crs84Name);
    expTblStr = "{CRS_0="+crs84Table.toString()+"}";
    assertEquals(lwms.getCoordRefSystems().toString(),expTblStr.toString());

    lwms.setByNameCRSs(crs84Name+","+epsg4269Name+","+epsg4326Name);
    expTblStr = "{CRS_0="+crs84Table.toString()+",CRS_1="+epsg4269Table.toString()+",CRS_2="+epsg4326Table.toString()+"}";
    assertEquals(lwms.getCoordRefSystems().toString(),expTblStr.toString());

    lwms.setByNameCRSs("");
    expTblStr = "{CRS_0="+epsg4326Table.toString()+",CRS_1="+crs84Table.toString()+",CRS_2="+crs83Table.toString()+
        ",CRS_3="+crs27Table.toString()+",CRS_4="+crs88Table.toString()+",CRS_5="+epsg4269Table.toString()+"}";
    assertEquals(lwms.getCoordRefSystems().toString(),expTblStr.toString());
  }

  /** Close the LayerWMS since it does not automatically close
   *  @since NeXtMidas 4.1.4 */
  @After
  public void tearDown() {
    lwms.close();
  }
}
