package com.nicholaskiraly.research.taskplanner;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.io.IOUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 * Test that PlanSolver implementations yield the same result as the
 * PlanSolverStatic baseline implementation
 */
public class SolverComparisonTest {

  public SolverComparisonTest() {
  }

  @BeforeClass
  public static void setUpClass() {
  }

  @AfterClass
  public static void tearDownClass() {
  }

  @Before
  public void setUp() {
  }

  @After
  public void tearDown() {
  }

  /**
   * Test PlanSolverBruteForce against known static solution
   *
   * @throws IOException
   * @throws FileNotFoundException
   * @throws TaskPlannerException
   */
  @Test
  public void testPlanSolverBruteForce() throws IOException, FileNotFoundException, TaskPlannerException, ClassNotFoundException, InstantiationException, IllegalAccessException {

    String taskFileName = "/tasks001.yml";
    File taskFile = new File(getClass().getResource(taskFileName).getFile());

    String resourceFileName = "/resources001.yml";
    File resourceFile = new File(getClass().getResource(resourceFileName).getFile());

    TaskPlanner planner = new TaskPlanner();

    planner.loadTasksFromFile(taskFile);

    planner.loadResourcesFromFile(resourceFile);

    planner.setSolverClass("PlanSolverBruteForce");

    planner.solve();

    String planYamlString = planner.getSolutionYaml();

    String planFileName = "/plan001.yml";
    File planFile = new File(getClass().getResource(planFileName).getFile());
    String expectedPlanYamlString = IOUtils.toString(planFile.toURI());

    assertEquals(expectedPlanYamlString, planYamlString);
  }

}

@@ -43,16 +43,133 @@
 anner;%0A%0A
+import com.tngtech.java.junit.dataprovider.DataProvider;%0Aimport com.tngtech.java.junit.dataprovider.UseDataProvider;%0A
 import j
@@ -1093,45 +1093,190 @@
 t%0A  
-public void testPlanSolverBruteForce(
+@UseDataProvider(%22providePlanSolverVariants%22)%0A  public void testPlanSolverBruteForce(String taskFileName, String resourceFileName, String planSolverClass, String expectedPlanFileName
 ) th
@@ -1416,51 +1416,8 @@
  %7B%0A%0A
-    String taskFileName = %22/tasks001.yml%22;%0A
     
@@ -1493,60 +1493,8 @@
 ());
-%0A%0A    String resourceFileName = %22/resources001.yml%22;
 %0A   
@@ -1746,10 +1746,9 @@
 ass(
-%22P
+p
 lanS
@@ -1756,19 +1756,13 @@
 lver
-BruteForce%22
+Class
 );%0A%0A
@@ -1847,56 +1847,22 @@
     
-String planFileName = %22/plan001.yml%22;%0A    File p
+File expectedP
 lanF
@@ -1899,17 +1899,25 @@
 esource(
-p
+expectedP
 lanFileN
@@ -1986,17 +1986,25 @@
 oString(
-p
+expectedP
 lanFile.
@@ -2075,12 +2075,384 @@
 ng);%0A  %7D
+%0A  %0A  /**%0A   * Tasks YAML file resource name Provider%0A   *%0A   * for more info, see https://github.com/TNG/junit-dataprovider/wiki/Getting-started#usage%0A   *%0A   * @return%0A   */%0A  @DataProvider%0A  public static String%5B%5D%5B%5D providePlanSolverVariants() %7B%0A    return new String%5B%5D%5B%5D%7B%0A      %7B%22/tasks001.yml%22, %22/resources001.yml%22, %22PlanSolverBruteForce%22, %22/plan001.yml%22%7D,%0A    %7D;%0A  %7D
 %0A%0A%7D%0A

refactor SolverComparisonTest to use junit data providers