package com.ociweb.oe.greenlightning.api;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertThat;
import static org.hamcrest.core.StringStartsWith.startsWith;
import static org.hamcrest.core.StringEndsWith.endsWith;

import org.junit.Test;

import com.ociweb.gl.api.GreenRuntime;
import com.ociweb.pronghorn.util.Appendables;


public class AppTest { 
	
	 @Test
	    public void testApp()
	    {
		    StringBuilder result = new StringBuilder();
		    
		    int timeoutMS = 120_000;
			int rate = 200;//if this rate is much faster two different write outs may end up in the wrong order.
			boolean cleanExit = GreenRuntime.testConcurrentUntilShutdownRequested(new StateMachine(result,rate), timeoutMS);
		    
		    /////////////////////////////
		    //System.out.println(result);
		    /////////////////////////////

		    CharSequence[] rows = Appendables.split(result, '\n');
		    
		    System.err.println(result.toString());
		    
		    assertTrue(cleanExit);
		    assertEquals(result.toString(), 17, rows.length);	
		    int i = 0;
		    int iterations = 3;
		    while (--iterations>=0) {
			    assertThat(rows[i++].toString(), startsWith("Green"));
			    assertThat(rows[i++].toString(), endsWith("Go"));
			    assertThat(rows[i++].toString(), startsWith("Yellow"));
			    assertThat(rows[i++].toString(), startsWith("Red"));
			    assertThat(rows[i++].toString(), endsWith("Stop"));
		    }
	    }
	
}

@@ -1081,9 +1081,9 @@
 ), 1
-7
+1
 , ro
@@ -1238,36 +1238,34 @@
 ;%0A%09%09%09   
- assertThat
+%0A%09%09%09    if 
 (rows%5Bi
-++
 %5D.toStri
@@ -1260,34 +1260,33 @@
 ws%5Bi%5D.toString()
-, 
+.
 endsWith(%22Go%22));
@@ -1284,17 +1284,49 @@
 h(%22Go%22))
-;
+ %7B%0A%09%09%09    %09i++;%0A%09%09%09    %7D;%0A%09%09%09    
 %0A%09%09%09    
@@ -1446,37 +1446,34 @@
 );%0A%09%09%09  
-  assertThat
+%0A%09%09%09    if 
 (rows%5Bi
-++
 %5D.toStri
@@ -1476,18 +1476,17 @@
 String()
-, 
+.
 endsWith
@@ -1494,17 +1494,49 @@
 %22Stop%22))
-;
+ %7B%0A%09%09%09    %09i++;%0A%09%09%09    %7D;%0A%09%09%09    
 %0A%09%09    %7D

update test