package org.requirementsascode.extract.freemarker;

import java.io.File;
import java.io.OutputStreamWriter;
import java.util.function.Consumer;

import org.junit.Before;
import org.junit.Test;
import org.requirementsascode.UseCaseModel;
import org.requirementsascode.UseCaseModelBuilder;
import org.requirementsascode.UseCaseModelRunner;
import org.requirementsascode.extract.freemarker.FreeMarkerEngine;
import org.requirementsascode.extract.freemarker.systemreaction.GreetUser;
import org.requirementsascode.extract.freemarker.systemreaction.PromptUserToEnterName;
import org.requirementsascode.extract.freemarker.systemreaction.Quit;
import org.requirementsascode.extract.freemarker.userevent.DecideToQuit;
import org.requirementsascode.extract.freemarker.userevent.EnterName;

public class FreemarkerEngineTest {
  private FreeMarkerEngine engine;

  @Before
  public void setUp() throws Exception {
    engine = new FreeMarkerEngine();
  }

  @Test
  public void printsUseCaseModelToConsole() throws Exception {
		UseCaseModel useCaseModel = UseCaseModelBuilder.newBuilder()
			.useCase("Get greeted")
				.basicFlow()
					.step("S1").system(promptUserToEnterName())
					.step("S2").user(enterName()).system(greetUser())
					.step("S3").user(decideToQuit())
					.step("S4").system(quit())
		.build();

    engine.put("useCaseModel", useCaseModel);
    File templateFile = new File("src/test/resources/example.ftlh");
    engine.process(templateFile, new OutputStreamWriter(System.out));
  }

  private Consumer<UseCaseModelRunner> promptUserToEnterName() {
    return new PromptUserToEnterName();
  }

  private Class<EnterName> enterName() {
    return EnterName.class;
  }

  private Consumer<EnterName> greetUser() {
    return new GreetUser();
  }

  private Class<DecideToQuit> decideToQuit() {
    return DecideToQuit.class;
  }

  private Consumer<UseCaseModelRunner> quit() {
    return new Quit();
  }
}

@@ -81,28 +81,20 @@
 java.io.
-OutputStream
+File
 Writer;%0A
@@ -327,75 +327,8 @@
 er;%0A
-import org.requirementsascode.extract.freemarker.FreeMarkerEngine;%0A
 impo
@@ -935,17 +935,16 @@
 ption %7B%0A
-%09
 %09UseCase
@@ -999,17 +999,16 @@
 der()%0A%09%09
-%09
 .useCase
@@ -1023,17 +1023,16 @@
 eeted%22)%0A
-%09
 %09%09%09.basi
@@ -1039,25 +1039,24 @@
 cFlow()%0A%09%09%09%09
-%09
 .step(%22S1%22).
@@ -1083,25 +1083,24 @@
 nterName())%0A
-%09
 %09%09%09%09.step(%22S
@@ -1137,25 +1137,24 @@
 reetUser())%0A
-%09
 %09%09%09%09.step(%22S
@@ -1182,17 +1182,16 @@
 ())%0A%09%09%09%09
-%09
 .step(%22S
@@ -1209,17 +1209,16 @@
 quit())%0A
-%09
 %09.build(
@@ -1344,71 +1344,211 @@
     
-engine.process(templateFile, new OutputStreamWriter(System.out)
+File outputFile = File.createTempFile( %22requirementsascodeextract_test%22, %22.html%22);%0A    engine.process(templateFile, new FileWriter(outputFile));%0A    %0A    System.out.println(%22Wrote file to: %22 + outputFile
 );%0A 

Write test html file to file system