/*
 * Copyright (C) by Courtanet, All Rights Reserved.
 */
package org.modelmap.example;

import static org.assertj.core.api.Assertions.assertThat;
import static org.modelmap.sample.field.SampleFieldIdInfo.ACCOUNT_ID;
import static org.modelmap.sample.field.SampleFieldIdInfo.BIRTHDATE;
import static org.modelmap.sample.field.SampleFieldIdInfo.TIMEZONE;

import java.time.LocalDate;
import java.util.Optional;

import org.junit.Test;
import org.modelmap.core.FieldModel;
import org.modelmap.core.dsl.DSL;
import org.modelmap.sample.model.SampleModels;
import org.modelmap.sample.model.Timezone;

public class DSLSandboxTest {

    @Test
    public void sample1() {
        FieldModel model = SampleModels.wrapper();
        Optional<String> result = DSL.when(ACCOUNT_ID.eq(1l)) //
                        .withMessage("incorrect account id") //
                        .executeOn(model);
        assertThat(result).isEmpty();
    }

    @Test
    public void sample2() {
        FieldModel model = SampleModels.wrapper();
        Optional<String> result = DSL.when(ACCOUNT_ID.eq(1l).not()) //
                        .withMessage("incorrect account id") //
                        .executeOn(model);
        assertThat(result).isNotEmpty();
    }

    @Test
    public void sample3() {
        FieldModel model = SampleModels.wrapper();
        Optional<String> result = DSL.when(BIRTHDATE.eq(LocalDate.of(1980, 8, 1))) //
                        .withMessage("you can't be born the August 1, 1980")
                        .executeOn(model);
        assertThat(result).isNotEmpty();
    }

    @Test
    public void sample4() {
        FieldModel model = SampleModels.wrapper();
        Optional<String> result = DSL.when(BIRTHDATE.between(LocalDate.of(1980, 1, 1), LocalDate.of(1980, 12, 31))) //
                        .withMessage("you can't be born in 1980")
                        .executeOn(model);
        assertThat(result).isNotEmpty();
    }

    @Test
    public void sample5() {
        FieldModel model = SampleModels.wrapper();
        Optional<String> result = DSL.when(BIRTHDATE.between(LocalDate.of(1980, 1, 1), LocalDate.of(1980, 12, 31)) //
                        .and(ACCOUNT_ID.eq(9l).not())
                        .or(TIMEZONE.eq(Timezone.ETC_GMT))) //
                        .withMessage("you can't be born in 1980 and have an ID different of 9 or having timezone " +
                                        "equals to ETC_GMT")
                        .executeOn(model);
        assertThat(result).isNotEmpty();
    }

}

@@ -380,35 +380,8 @@
 ate;
-%0Aimport java.util.Optional;
 %0A%0Aim
@@ -472,16 +472,60 @@
 sl.DSL;%0A
+import org.modelmap.core.dsl.lang.StepWhen;%0A
 import o
@@ -646,49 +646,15 @@
     
-@Test%0A    public void sample1() %7B%0A       
+private
  Fie
@@ -697,39 +697,68 @@
 ();%0A
+%0A
     
-    Optional%3CString%3E result
+@Test%0A    public void sample1() %7B%0A        StepWhen step
  = D
@@ -784,14 +784,11 @@
 eq(1
-l
+L
 ))
- //
 %0A   
@@ -836,35 +836,33 @@
 ect account id%22)
- //
+;
 %0A               
@@ -858,40 +858,42 @@
     
-                .executeOn(model
+System.out.println(step.readable()
 );%0A 
@@ -906,30 +906,45 @@
  assertThat(
-result
+step.executeOn(model)
 ).isEmpty();
@@ -1001,82 +1001,21 @@
     
-FieldModel model = SampleModels.wrapper();%0A        Optional%3CString%3E result
+StepWhen step
  = D
@@ -1037,25 +1037,25 @@
 _ID.eq(1
-l
+L
 ).not())
  //%0A    
@@ -1046,19 +1046,16 @@
 ).not())
- //
 %0A       
@@ -1107,19 +1107,17 @@
 unt id%22)
- //
+;
 %0A       
@@ -1121,40 +1121,42 @@
     
-                .executeOn(model
+System.out.println(step.readable()
 );%0A 
@@ -1165,38 +1165,53 @@
      assertThat(
-result
+step.executeOn(model)
 ).isNotEmpty();%0A
@@ -1267,82 +1267,21 @@
     
-FieldModel model = SampleModels.wrapper();%0A        Optional%3CString%3E result
+StepWhen step
  = D
@@ -1323,27 +1323,24 @@
 980, 8, 1)))
- //
 %0A           
@@ -1400,24 +1400,25 @@
 st 1, 1980%22)
+;
 %0A           
@@ -1418,40 +1418,42 @@
     
-                .executeOn(model
+System.out.println(step.readable()
 );%0A 
@@ -1462,38 +1462,53 @@
      assertThat(
-result
+step.executeOn(model)
 ).isNotEmpty();%0A
@@ -1564,82 +1564,21 @@
     
-FieldModel model = SampleModels.wrapper();%0A        Optional%3CString%3E result
+StepWhen step
  = D
@@ -1657,19 +1657,16 @@
 2, 31)))
- //
 %0A       
@@ -1723,16 +1723,17 @@
 n 1980%22)
+;
 %0A       
@@ -1737,40 +1737,42 @@
     
-                .executeOn(model
+System.out.println(step.readable()
 );%0A 
@@ -1781,38 +1781,53 @@
      assertThat(
-result
+step.executeOn(model)
 ).isNotEmpty();%0A
@@ -1883,82 +1883,21 @@
     
-FieldModel model = SampleModels.wrapper();%0A        Optional%3CString%3E result
+StepWhen step
  = D
@@ -1975,19 +1975,16 @@
 12, 31))
- //
 %0A       
@@ -2020,17 +2020,17 @@
 _ID.eq(9
-l
+L
 ).not())
@@ -2093,11 +2093,8 @@
 T)))
- //
 %0A   
@@ -2267,26 +2267,26 @@
 TC_GMT%22)
+;
 %0A
- 
         
         
@@ -2281,39 +2281,42 @@
     
-               .executeOn(model
+System.out.println(step.readable()
 );%0A 
@@ -2337,14 +2337,29 @@
 hat(
-result
+step.executeOn(model)
 ).is

Add readable sout to sandbox tests