package edu.colorado.csdms.wmt.client;

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

import com.google.gwt.junit.client.GWTTestCase;

import edu.colorado.csdms.wmt.client.data.ConfigurationJSO;

/**
 * Tests for {@link ConfigurationJSO}. JUnit integration is provided by 
 * extending {@link GWTTestCase}.
 * 
 * @see http://www.gwtproject.org/doc/latest/DevGuideTesting.html
 * @see http://www.gwtproject.org/doc/latest/tutorial/JUnit.html
 * @see http://blog.danielwellman.com/2008/08/testing-json-parsing-using-javascript-overlay-types-in-gwt-15.html
 * @author Mark Piper (mark.piper@colorado.edu)
 */
public class ConfigurationJSOTest extends GWTTestCase {

  private ConfigurationJSO configurationJSO;
  private String version;
  private String releaseDate;
  private String apiUrl;  
  
  /**
   * The module that sources this class. Must be present.
   */
  @Override
  public String getModuleName() {
     return "edu.colorado.csdms.wmt.WMT";
  }
  
  /**
   * A JSNI method that defines a fixture for the tests. Returns a
   * {@link ConfigurationJSO} object for testing.
   * 
   * @param version
   * @param releaseDate
   * @param apiUrl
   */
  private native ConfigurationJSO testConfigurationJSO(String version, 
      String releaseDate, String apiUrl) /*-{
		return {
			"version" : version,
			"release_date" : releaseDate,
			"api_url" : apiUrl
		}
  }-*/;  
  
  @Before
  @Override
  protected void gwtSetUp() throws Exception {
    version = "0.9.3";
    releaseDate = "2014-07-27";
    apiUrl = "https://csdms.colorado.edu/wmt/api-dev/";
    configurationJSO = testConfigurationJSO(version, releaseDate, apiUrl);
  }

  @After
  @Override
  protected void gwtTearDown() throws Exception {
  }

  @Test
  public void testGetId() {
    assertEquals(version, configurationJSO.getVersion());
  }

  @Test
  public void testGetReleaseDate() {
    assertEquals(releaseDate, configurationJSO.getReleaseDate());
  }
  
  @Test
  public void testGetApiUrl() {
    assertEquals(apiUrl, configurationJSO.getApiUrl());
  }
}

@@ -102,24 +102,73 @@
 unit.Test;%0A%0A
+import com.google.gwt.core.client.JsArrayString;%0A
 import com.g
@@ -340,17 +340,16 @@
 vided by
- 
 %0A * exte
@@ -759,32 +759,19 @@
 tionJSO 
-configurationJSO
+jso
 ;%0A  priv
@@ -844,21 +844,210 @@
  apiUrl;
-  
 %0A  
+private static final String%5B%5D HOSTS = %7B%0A      %22beach.colorado.edu%22, %22localhost%22, %22janus.colorado.edu%22%7D;%0A  private static final int ARRAY_LENGTH = HOSTS.length;%0A  private JsArrayString hosts;%0A
 %0A  /**%0A 
@@ -1159,17 +1159,16 @@
 ) %7B%0A    
- 
 return %22
@@ -1200,18 +1200,16 @@
 T%22;%0A  %7D%0A
-  
 %0A  /**%0A 
@@ -1469,17 +1469,16 @@
 version,
- 
 %0A      S
@@ -1509,16 +1509,37 @@
 g apiUrl
+, JsArrayString hosts
 ) /*-%7B%0A%09
@@ -1626,16 +1626,48 @@
 : apiUrl
+,%0A%09%09%09%22execution_servers%22 : hosts
 %0A%09%09%7D%0A  %7D
@@ -1670,21 +1670,17 @@
 %0A  %7D-*/;
-  %0A  
+%0A
 %0A  @Befo
@@ -1856,32 +1856,165 @@
 /%22;%0A    
-configurationJSO
+hosts = JsArrayString.createObject().cast();%0A    hosts.setLength(ARRAY_LENGTH);%0A    for (String host : HOSTS) %7B%0A      hosts.push(host);%0A    %7D%0A    jso
  = testC
@@ -2057,16 +2057,23 @@
 , apiUrl
+, hosts
 );%0A  %7D%0A%0A
@@ -2210,32 +2210,19 @@
 ersion, 
-configurationJSO
+jso
 .getVers
@@ -2309,32 +2309,19 @@
 seDate, 
-configurationJSO
+jso
 .getRele
@@ -2336,18 +2336,16 @@
 ));%0A  %7D%0A
-  
 %0A  @Test
@@ -2406,35 +2406,501 @@
 rl, 
-configurationJSO.getApiUrl(
+jso.getApiUrl());%0A  %7D%0A%0A  /*%0A   * Test the length of the array.%0A   */%0A  @Test%0A  public void testLength() %7B%0A    assertEquals(ARRAY_LENGTH, jso.getHosts().length());%0A  %7D%0A%0A  /*%0A   * Test whether all hosts can be retrieved.%0A   */%0A  @Test%0A  public void testGetHosts() %7B%0A    assertEquals(hosts, jso.getHosts());%0A  %7D%0A%0A  /*%0A   * Test whether a single host can be retrieved.%0A   */%0A  @Test%0A  public void testGetSingleHost() %7B%0A    int index = 0;%0A    assertEquals(hosts.get(index), jso.getHosts().get(index
 ));%0A

Add unit tests for execution server list in config file