package datafu.test.pig.util;

import static org.testng.Assert.*;

import org.adrianwalker.multilinestring.Multiline;
import org.apache.pig.pigunit.PigTest;
import org.testng.annotations.Test;

import datafu.test.pig.PigTests;

public class AssertTests extends PigTests
{
  /**
  register $JAR_PATH
  
  define ASSERT datafu.pig.util.Assert();
  
  data = LOAD 'input' AS (val:INT);
  
  data2 = FILTER data BY ASSERT(val,'assertion appears to have failed, doh!');
  
  STORE data2 INTO 'output';
  */
  @Multiline private static String assertWithMessage;
  
  @Test
  public void shouldAssertWithMessageOnZero() throws Exception
  {
    try
    {
      PigTest test = createPigTestFromString(assertWithMessage);
      
      this.writeLinesToFile("input", "0");
      
      test.runScript();
      
      this.getLinesForAlias(test, "data2");
      
      fail("test should have failed, but it didn't");
    }
    catch (Exception e)
    {
    }
  }
  
  @Test
  public void shouldNotAssertWithMessageOnOne() throws Exception
  {
    PigTest test = createPigTestFromString(assertWithMessage);
    
    this.writeLinesToFile("input", "1");
    
    test.runScript();
    
    this.getLinesForAlias(test, "data2");
  }
  
  /**
  register $JAR_PATH
  
  define ASSERT datafu.pig.util.Assert();
  
  data = LOAD 'input' AS (val:INT);
  
  data2 = FILTER data BY ASSERT(val);
  
  STORE data2 INTO 'output';
  */
  @Multiline private static String assertWithoutMessage;
  
  @Test
  public void shouldAssertWithoutMessageOnZero() throws Exception
  {
    try
    {
      PigTest test = createPigTestFromString(assertWithoutMessage);
      
      this.writeLinesToFile("input", "0");
      
      test.runScript();
      
      this.getLinesForAlias(test, "data2");
      
      fail("test should have failed, but it didn't");
    }
    catch (Exception e)
    {
    }
  }
  
  @Test
  public void shouldNotAssertWithoutMessageOnOne() throws Exception
  {
    PigTest test = createPigTestFromString(assertWithoutMessage);
    
    this.writeLinesToFile("input", "1");
    
    test.runScript();
    
    this.getLinesForAlias(test, "data2");
  }
}

@@ -60,16 +60,40 @@
 ert.*;%0A%0A
+import java.util.List;%0A%0A
 import o
@@ -135,16 +135,50 @@
 tiline;%0A
+import org.apache.pig.data.Tuple;%0A
 import o
@@ -208,16 +208,42 @@
 igTest;%0A
+import org.testng.Assert;%0A
 import o
@@ -1245,32 +1245,53 @@
 ript();%0A    %0A   
+ List%3CTuple%3E result =
  this.getLinesFo
@@ -1309,24 +1309,167 @@
 , %22data2%22);%0A
+    Assert.assertEquals(result.size(), 1);%0A    Assert.assertEquals(result.get(0).size(), 1);%0A    Assert.assertEquals(result.get(0).get(0), 1);%0A
   %7D%0A  %0A  /**
@@ -2337,24 +2337,45 @@
 ();%0A    %0A   
+ List%3CTuple%3E result =
  this.getLin
@@ -2401,14 +2401,157 @@
 ata2%22);%0A
+    Assert.assertEquals(result.size(), 1);%0A    Assert.assertEquals(result.get(0).size(), 1);%0A    Assert.assertEquals(result.get(0).get(0), 1);%0A
   %7D%0A%7D%0A

Add additional verification to assert