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.PortJSO;

/**
 * Tests for {@link PortJSO}.
 * 
 * @author Mark Piper (mark.piper@colorado.edu)
 */
public class PortJSOTest extends GWTTestCase {

  private PortJSO portJSO;
  private String id;
  private Boolean required;
  
  @Override
  public String getModuleName() {
     return "edu.colorado.csdms.wmt.WMT";
  }
  
  // A JSNI method that defines a fixture for the tests.
  private native PortJSO testPortJSO(String id, boolean required) /*-{ 
    return {"required":required, "id":id} 
  }-*/;  
  
  @Before
  @Override
  protected void gwtSetUp() throws Exception {
    id = "test";
    required = true;
    portJSO = testPortJSO(id, required);
  }

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

  @Test
  public void testGetId() {
    assertEquals(id, portJSO.getId());
  }
  
  @Test
  public void testSetId() {
    String newId = "foo";
    portJSO.setId(newId);
    assertEquals(newId, portJSO.getId());
  }
  
  @Test
  public void testIsRequired() {
    assertTrue(portJSO.isRequired());
  }

  @Test
  public void testSetIsRequired() {
    Boolean isRequired = false;
    portJSO.isRequired(isRequired);
//    assertFalse(portJSO.isRequired());
  }
}

@@ -1,8 +1,29 @@
+/**%0A * %3CLicense%3E%0A */%0A
 package 
@@ -123,24 +123,73 @@
 unit.Test;%0A%0A
+import com.google.gwt.core.client.JsArrayString;%0A
 import com.g
@@ -310,20 +310,331 @@
 ortJSO%7D.
-%0A * 
+ JUnit integration is provided by extending%0A * %7B@link GWTTestCase%7D.%0A * %0A * @see http://www.gwtproject.org/doc/latest/DevGuideTesting.html%0A * @see http://www.gwtproject.org/doc/latest/tutorial/JUnit.html%0A * @see http://blog.danielwellman.com/2008/08/testing-json-parsing-using-javascript-overlay-types-in-gwt-15.html
 %0A * @aut
@@ -784,17 +784,17 @@
 private 
-B
+b
 oolean r
@@ -804,16 +804,126 @@
 ired;%0A  
+private JsArrayString exchange_items;%0A  %0A  /**%0A   * The module that sources this class. Must be present.%0A   */
 %0A  @Over
@@ -1013,17 +1013,23 @@
 %7D%0A  %0A  /
-/
+**%0A   *
  A JSNI 
@@ -1072,16 +1072,134 @@
 e tests.
+ Returns a PortJSO%0A   * object for testing.%0A   * %0A   * @param id%0A   * @param required%0A   * @param exchange_items%0A   */
 %0A  priva
@@ -1259,28 +1259,61 @@
 ired
-) /*-%7B %0A    
+,%0A      JsArrayString exchange_items) /*-%7B%0A%09%09
 return %7B
 %22req
@@ -1308,16 +1308,20 @@
 return %7B
+%0A%09%09%09
 %22require
@@ -1322,17 +1322,19 @@
 equired%22
-:
+ : 
 required
@@ -1338,18 +1338,63 @@
 red,
- %22id%22:id%7D 
+%0A%09%09%09%22id%22 : id,%0A%09%09%09%22exchange_items%22 : exchange_items%0A%09%09%7D
 %0A  %7D
@@ -1510,16 +1510,178 @@
 = true;%0A
+    exchange_items = (JsArrayString) JsArrayString.createArray();%0A    exchange_items.push(%22foo%22);%0A    exchange_items.push(%22bar%22);%0A    exchange_items.push(%22baz%22);%0A
     port
@@ -1710,16 +1710,32 @@
 required
+, exchange_items
 );%0A  %7D%0A%0A
@@ -2161,17 +2161,17 @@
 ) %7B%0A    
-B
+b
 oolean i
@@ -2225,18 +2225,16 @@
 uired);%0A
-//
     asse
@@ -2267,11 +2267,125 @@
 ());%0A  %7D
+%0A%0A  @Test%0A  public void testGetExchangeItems() %7B%0A    assertEquals(exchange_items, portJSO.getExchangeItems());%0A  %7D
 %0A%7D%0A

Add test for new methods in PortJSO