<commit_before>package ch.uzh.ifi.pdeboer.pplib.process

import ch.uzh.ifi.pdeboer.pplib.process.entities.PassableProcessParam
import ch.uzh.ifi.pdeboer.pplib.process.recombination.{RecombinationVariant, RecombinationVariantProcessXMLExporter}
import ch.uzh.ifi.pdeboer.pplib.util.U
import org.junit.{Assert, Test}

import scala.reflect.ClassTag

/**
 * Created by pdeboer on 28/11/14.
 */
class RecombinationVariantProcessXMLExporterTest {
	@Test
	def testStringListExport: Unit = {
		val inputDataProcess: List[String] = List("test1", "test2")
		val outputDataProcess: String = "result1"
		val processType = new PassableProcessWithRuns[List[String], String](Map(inputDataProcess -> outputDataProcess))
		val variant = new RecombinationVariant(Map("testprocess" -> processType))
		val process = variant.createProcess("testprocess")

		val exporter = new RecombinationVariantProcessXMLExporter(variant) //List is default
		val xmlExport = exporter.transformDataWithExporter(process, process.inputType.runtimeClass, inputDataProcess)

		Assert.assertEquals("<List><Item>test1</Item><Item>test2</Item></List>",
			U.removeWhitespaces(xmlExport.toString))

		Assert.assertEquals(outputDataProcess, exporter.transformDataWithExporter(process, process.outputType.runtimeClass, outputDataProcess))
	}

	@Test
	def testStringSetExport: Unit = {
		val inputDataProcess = Set("test1", "test2")
		val outputDataProcess: String = "result1"
		val processType = new PassableProcessWithRuns[Set[String], String](Map(inputDataProcess -> outputDataProcess))
		val variant = new RecombinationVariant(Map("testprocess" -> processType))
		val process = variant.createProcess("testprocess")
		val exporter = new RecombinationVariantProcessXMLExporter(variant) //List is default
		val xmlExport = exporter.transformDataWithExporter(process, process.inputType.runtimeClass, inputDataProcess)

		Assert.assertEquals("<Set><Item>test1</Item><Item>test2</Item></Set>",
			U.removeWhitespaces(xmlExport.toString))

		Assert.assertEquals(outputDataProcess, exporter.transformDataWithExporter(process, process.outputType.runtimeClass, outputDataProcess))
	}

	@Test
	def testIntListExport: Unit = {
		val inputDataProcess = List(1, 2, 3)
		val outputDataProcess = 3
		val processType = new PassableProcessWithRuns[List[Int], Integer](Map(inputDataProcess -> outputDataProcess))
		val variant = new RecombinationVariant(Map("testprocess" -> processType))
		val process = variant.createProcess("testprocess")

		val exporter = new RecombinationVariantProcessXMLExporter(variant) //List is default
		val xmlExport = exporter.transformDataWithExporter(process, process.inputType.runtimeClass, inputDataProcess)

		Assert.assertEquals("<List><Item>1</Item><Item>2</Item><Item>3</Item></List>",
			U.removeWhitespaces(xmlExport.toString))

		Assert.assertEquals(outputDataProcess, exporter.transformDataWithExporter(process, process.outputType.runtimeClass, outputDataProcess))
	}


	@Test
	def testMapExport: Unit = {
		val inputDataProcess = Map("key1" -> "value1", "key2" -> "value2")
		val outputDataProcess = 3
		val processType = new PassableProcessWithRuns[Map[String, String], Integer](Map(inputDataProcess -> outputDataProcess))
		val variant = new RecombinationVariant(Map("testprocess" -> processType))
		val process = variant.createProcess("testprocess")

		val exporter = new RecombinationVariantProcessXMLExporter(variant) //List is default
		val xmlExport = exporter.transformDataWithExporter(process, process.inputType.runtimeClass, inputDataProcess)

		Assert.assertEquals("<Map><Item><Key>key1</Key><Value>value1</Value></Item><Item><Key>key2</Key><Value>value2</Value></Item></Map>",
			U.removeWhitespaces(xmlExport.toString))

		Assert.assertEquals(outputDataProcess, exporter.transformDataWithExporter(process, process.outputType.runtimeClass, outputDataProcess))
	}

	@Test
	def testCompleteExport: Unit = {
		val inputDataProcess: List[String] = List("test1", "test2")
		val outputDataProcess: String = "result1"
		val processType = new PassableProcessWithRuns[List[String], String](Map(inputDataProcess -> outputDataProcess))
		val variant = new RecombinationVariant(Map("testprocess" -> processType))
		val process = variant.createProcess("testprocess")

		val exporter = new RecombinationVariantProcessXMLExporter(variant) //List is default
		Assert.assertEquals("<Variant><ProcessExecutions><ProcessExecution><Name>testprocess</Name><Process><Class>ch.uzh.ifi.pdeboer.pplib.process.RecombinationVariantXMLExporterTest$TestProcess</Class><InputClass>scala.collection.immutable.List</InputClass><OutputClass>java.lang.String</OutputClass><Categories><Category></Category></Categories><Parameters><Parameter><Name>other_memoizerName</Name><Category>other</Category><Value>None</Value><IsSpecified>false</IsSpecified></Parameter><Parameter><Name>other_storeExecutionResults</Name><Category>other</Category><Value>true</Value><IsSpecified>false</IsSpecified></Parameter></Parameters></Process><Results><Result><Input><List><Item>test1</Item><Item>test2</Item></List></Input><Output>result1</Output></Result></Results></ProcessExecution></ProcessExecutions></Variant>", U.removeWhitespaces(exporter.xml + ""))
	}

	private class PassableProcessWithRuns[IN: ClassTag, OUT: ClassTag](val runs: Map[IN, OUT]) extends PassableProcessParam[IN, OUT](classOf[TestProcess[IN, OUT]]) {
		override def create(lowerPrioParams: Map[String, Any], higherPrioParams: Map[String, Any]): ProcessStub[IN, OUT] = {
			new TestProcess[IN, OUT](runs)<commit_msg>recombination variant test<commit_after>package ch.uzh.ifi.pdeboer.pplib.process

import ch.uzh.ifi.pdeboer.pplib.process.entities.PassableProcessParam
import ch.uzh.ifi.pdeboer.pplib.process.recombination.{RecombinationVariant, RecombinationVariantProcessXMLExporter}
import ch.uzh.ifi.pdeboer.pplib.util.U
import org.junit.{Assert, Test}

import scala.reflect.ClassTag

/**
 * Created by pdeboer on 28/11/14.
 */
class RecombinationVariantProcessXMLExporterTest {
	@Test
	def testStringListExport: Unit = {
		val inputDataProcess: List[String] = List("test1", "test2")
		val outputDataProcess: String = "result1"
		val processType = new PassableProcessWithRuns[List[String], String](Map(inputDataProcess -> outputDataProcess))
		val variant = new RecombinationVariant(Map("testprocess" -> processType))
		val process = variant.createProcess("testprocess")

		val exporter = new RecombinationVariantProcessXMLExporter(variant) //List is default
		val xmlExport = exporter.transformDataWithExporter(process, process.inputType.runtimeClass, inputDataProcess)

		Assert.assertEquals("<List><Item>test1</Item><Item>test2</Item></List>",
			U.removeWhitespaces(xmlExport.toString))

		Assert.assertEquals(outputDataProcess, exporter.transformDataWithExporter(process, process.outputType.runtimeClass, outputDataProcess))
	}

	@Test
	def testStringSetExport: Unit = {
		val inputDataProcess = Set("test1", "test2")
		val outputDataProcess: String = "result1"
		val processType = new PassableProcessWithRuns[Set[String], String](Map(inputDataProcess -> outputDataProcess))
		val variant = new RecombinationVariant(Map("testprocess" -> processType))
		val process = variant.createProcess("testprocess")
		val exporter = new RecombinationVariantProcessXMLExporter(variant) //List is default
		val xmlExport = exporter.transformDataWithExporter(process, process.inputType.runtimeClass, inputDataProcess)

		Assert.assertEquals("<Set><Item>test1</Item><Item>test2</Item></Set>",
			U.removeWhitespaces(xmlExport.toString))

		Assert.assertEquals(outputDataProcess, exporter.transformDataWithExporter(process, process.outputType.runtimeClass, outputDataProcess))
	}

	@Test
	def testIntListExport: Unit = {
		val inputDataProcess = List(1, 2, 3)
		val outputDataProcess = 3
		val processType = new PassableProcessWithRuns[List[Int], Integer](Map(inputDataProcess -> outputDataProcess))
		val variant = new RecombinationVariant(Map("testprocess" -> processType))
		val process = variant.createProcess("testprocess")

		val exporter = new RecombinationVariantProcessXMLExporter(variant) //List is default
		val xmlExport = exporter.transformDataWithExporter(process, process.inputType.runtimeClass, inputDataProcess)

		Assert.assertEquals("<List><Item>1</Item><Item>2</Item><Item>3</Item></List>",
			U.removeWhitespaces(xmlExport.toString))

		Assert.assertEquals(outputDataProcess, exporter.transformDataWithExporter(process, process.outputType.runtimeClass, outputDataProcess))
	}


	@Test
	def testMapExport: Unit = {
		val inputDataProcess = Map("key1" -> "value1", "key2" -> "value2")
		val outputDataProcess = 3
		val processType = new PassableProcessWithRuns[Map[String, String], Integer](Map(inputDataProcess -> outputDataProcess))
		val variant = new RecombinationVariant(Map("testprocess" -> processType))
		val process = variant.createProcess("testprocess")

		val exporter = new RecombinationVariantProcessXMLExporter(variant) //List is default
		val xmlExport = exporter.transformDataWithExporter(process, process.inputType.runtimeClass, inputDataProcess)

		Assert.assertEquals("<Map><Item><Key>key1</Key><Value>value1</Value></Item><Item><Key>key2</Key><Value>value2</Value></Item></Map>",
			U.removeWhitespaces(xmlExport.toString))

		Assert.assertEquals(outputDataProcess, exporter.transformDataWithExporter(process, process.outputType.runtimeClass, outputDataProcess))
	}

	@Test
	def testCompleteExport: Unit = {
		val inputDataProcess: List[String] = List("test1", "test2")
		val outputDataProcess: String = "result1"
		val processType = new PassableProcessWithRuns[List[String], String](Map(inputDataProcess -> outputDataProcess))
		val variant = new RecombinationVariant(Map("testprocess" -> processType))
		val process = variant.createProcess("testprocess")

		val exporter = new RecombinationVariantProcessXMLExporter(variant) //List is default
		Assert.assertEquals("<Variant><ProcessExecutions><ProcessExecution><Name>testprocess</Name><Process><Class>ch.uzh.ifi.pdeboer.pplib.process.RecombinationVariantProcessXMLExporterTest$TestProcess</Class><InputClass>scala.collection.immutable.List</InputClass><OutputClass>java.lang.String</OutputClass><Categories><Category></Category></Categories><Parameters><Parameter><Name>other_memoizerName</Name><Category>other</Category><Value>None</Value><IsSpecified>false</IsSpecified></Parameter><Parameter><Name>other_storeExecutionResults</Name><Category>other</Category><Value>true</Value><IsSpecified>false</IsSpecified></Parameter></Parameters></Process><Results><Result><Input><List><Item>test1</Item><Item>test2</Item></List></Input><Output>result1</Output></Result></Results></ProcessExecution></ProcessExecutions></Variant>", U.removeWhitespaces(exporter.xml + ""))
	}

	private class PassableProcessWithRuns[IN: ClassTag, OUT: ClassTag](val runs: Map[IN, OUT]) extends PassableProcessParam[IN, OUT](classOf[TestProcess[IN, OUT]]) {
		override def create(lowerPrioParams: Map[String, Any], higherPrioParams: Map[String, Any]): ProcessStub[IN, OUT] = {
			new TestProcess[IN, OUT](runs)
{'fraction_non_alphanumeric': 0.128001444304026, 'fraction_numerical': 0.006860444123487994, 'mean_word_length': 7.7304964539007095, 'pattern_counts': {'":': 0, '<': 183, '<?xml version=': 0, '>': 207, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 18}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '381839', 'n_tokens_mistral': 3362, 'n_tokens_neox': 3190, 'n_words': 525}