package test.java;

import static org.junit.Assert.*;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import com.xrtb.bidder.Controller;
import com.xrtb.common.ForensiqLog;
import com.xrtb.pojo.ForensiqClient;
/**
 * A class for testing that the bid has the right parameters
 * @author Ben M. Faul
 *
 */
public class TestForensiq  {
	static Controller c;
	public static String test = "";
	
	@BeforeClass
	  public static void testSetup() {		
		try {
			Config.setup();
			Config.setup();System.out.println("******************  TestForensiq");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	  }

	  @AfterClass
	  public static void testCleanup() {
		  Config.teardown();
	  }
	  
	  /**
	   * Test a valid bid response.
	   * @throws Exception on networking errors.
	   */
	  @Test 
	  public void testBad() throws Exception {
			ForensiqClient forensiq = ForensiqClient.build("6RLzOXoxntkqr0PHJ1Z0");
			
			String rt = "display";                        												
			String ip = "52.35.123.110";					  												// device.ip
			String url = "http%3A%2F%2Fwww.myheretrtrtouse.com%2Fsections%2Fliving%3Fa%3D3%20";			// site.page
			String ua = "erererer%2F4.0%20(compatible%3B%20MSIE%207.0%3B%20Windoreererws%20NT%206.0";	// device.ua
			String seller = "seller1234";																// site.name		
			String crid = "creative1234";																// your creative id
			
			ForensiqLog m = forensiq.bid(rt, ip, url, ua, seller, crid);
			assertNotNull(m);
	  }
	  
	  /**
	   * Test a valid bid response.
	   * @throws Exception on networking errors.
	   */
	  @Test 
	  public void testGood() throws Exception {
		  
		  ForensiqClient forensiq = ForensiqClient.build("6RLzOXoxntkqr0PHJ1Z0");
			
			String rt = "display";
			String ip = "123.254.33.4";
			String url = "http%3A%2F%2Fwww.myheretrtrtouse.com%2Fsections%2Fliving%3Fa%3D3%20";
			String ua = "erererer%2F4.0%20(compatible%3B%20MSIE%207.0%3B%20Windoreererws%20NT%206.0)";
			String seller = "seller1234";
			String crid = "xyz1234";
			
			ForensiqLog m = forensiq.bid(rt, ip, url, ua, seller, crid);
			assertNull(m);
	  }
	  
	  @Test 
	  public void testARealBid() throws Exception {
		  	ForensiqClient forensiq =  ForensiqClient.build("6RLzOXoxntkqr0PHJ1Z0");
		  	
		  	String s = Charset
					.defaultCharset()
					.decode(ByteBuffer.wrap(Files.readAllBytes(Paths
							.get("./SampleBids/nexage.txt")))).toString();
		  	
		  	
		  	
			String rt = "display";
			String ip = "123.254.33.4";
			String url = "http%3A%2F%2Fwww.myheretrtrtouse.com%2Fsections%2Fliving%3Fa%3D3%20";
			String ua = "erererer%2F4.0%20(compatible%3B%20MSIE%207.0%3B%20Windoreererws%20NT%206.0)";
			String seller = "seller1234";
			String crid = "xyz1234";
			
			ForensiqLog m = forensiq.bid(rt, ip, url, ua, seller, crid);
			assertNull(m);
	  }
}
@@ -1814,16 +1814,18 @@
 %7B%0A%09%09  %0A%09
+/*
 %09  Foren
@@ -1867,36 +1867,29 @@
 .build(%22
-6RLzOXoxntkqr0PHJ1Z0
+YOUR KEY HERE
 %22);%0A%09%09%09%0A
@@ -1928,33 +1928,33 @@
 ing ip = %22123.25
-4
+0
 .33.4%22;%0A%09%09%09Strin
@@ -2265,32 +2265,37 @@
 %09assertNull(m);%0A
+%09%09*/%0A
 %09  %7D%0A%09  %0A%09  @Tes
@@ -2347,16 +2347,18 @@
 tion %7B%0A%09
+/*
 %09  %09Fore
@@ -2402,36 +2402,29 @@
 .build(%22
-6RLzOXoxntkqr0PHJ1Z0
+YOUR_KEY_HERE
 %22);%0A%09%09  
@@ -2979,18 +2979,23 @@
 ertNull(m);%0A
+%09%09*/%0A
 %09  %7D%0A%7D

Remove old keys, add your own to test your implementation.