package ua.ansymo.hintco.test

import org.apache.commons.lang3.SystemUtils
import org.junit.Assume
import org.junit.Ignore
import org.junit.Test
import ua.ansymo.hintco.AdaptiveCosimRunner
import ua.ansymo.hintco.CandidatesGenerator
import ua.ansymo.hintco.ConstraintChecker
import ua.ansymo.hintco.FmuLoader
import ua.ansymo.hintco.ModelStorage
import ua.ansymo.hintco.OutputProcessor
import ua.ansymo.hintco.SingleCosimRunner
import ua.ansymo.hintco.StrongCouplingRunner
import ua.ansymo.hintco.VariantProcessor
import ua.ansymo.hintco.VariantValidator

class WvFormCosimRunnerTest {
	@Test
	def void executeWVCosimMSD(){
		val src = new ModelStorage().loadCandidates("instances/waveform_msd.hintco")
		val runner = new AdaptiveCosimRunner(new OutputProcessor("results-gen/strongCoupMSDTest/Strong"), new FmuLoader, false)
		var generator = new CandidatesGenerator(new ConstraintChecker,new VariantValidator, new VariantProcessor(runner))
		generator.createVariantTree(src)
		generator.generateVariants(src, 1)
		runner.close()
		
		val normal_src = new ModelStorage().loadCandidates("instances/waveform_msd_normal.hintco")
		val normal_runner = new AdaptiveCosimRunner(new OutputProcessor("results-gen/strongCoupMSDTest/Normal"), new FmuLoader, false)
		var normal_generator = new CandidatesGenerator(new ConstraintChecker,new VariantValidator, new VariantProcessor(normal_runner))
		normal_generator.createVariantTree(normal_src)
		normal_generator.generateVariants(normal_src, 1)
		normal_runner.close()
	}
	
	@Test
	@Ignore // Only works if you have amesim license.
	def void executeCosimulationElevatorLoad(){
		Assume.assumeTrue(SystemUtils.IS_OS_WINDOWS) // Because it only works on windows.
		
		val src = new ModelStorage().loadCandidates("instances/elevator_load_scenario.hintco")
		val runner = new SingleCosimRunner(new OutputProcessor("results-gen/elevator"), new FmuLoader)
		var generator = new CandidatesGenerator(new ConstraintChecker,new VariantValidator, new VariantProcessor(runner))
		generator.createVariantTree(src)
		generator.generateVariants(src, 1)
		runner.close()
		
//		System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "debug")
//		System.setProperty("org.slf4j.simpleLogger.logFile", "elevator.log")
		
		val strong_src = new ModelStorage().loadCandidates("instances/elevator_load_scenario.hintco")
		val strong_runner = new StrongCouplingRunner(new OutputProcessor("results-gen/elevatorStrong"), new FmuLoader, true)
		var strong_generator = new CandidatesGenerator(new ConstraintChecker, new VariantValidator, new VariantProcessor(strong_runner))
		strong_generator.createVariantTree(strong_src)
		strong_generator.generateVariants(strong_src, 1)
		strong_runner.close()
		
	}
}