package org.dita.dost.module;

import static org.junit.Assert.assertEquals;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import org.dita.dost.TestUtils;
import org.dita.dost.exception.DITAOTException;
import org.dita.dost.module.TopicMergeModule;
import org.dita.dost.pipeline.AbstractFacade;
import org.dita.dost.pipeline.PipelineFacade;
import org.dita.dost.pipeline.PipelineHashIO;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;


public class TestTopicMergeModule {
	
	private final File resourceDir = new File("test-stub", "TestTopicMergeModule");
	private File tempDir;
	
	public TopicMergeModule module;
	
	private AbstractFacade facade;
	
	private PipelineHashIO pipelineInput;
	final File ditalistfile = new File (resourceDir, "compare.xml");
	File tobecomparefile;
	
	@Before
	public void setUp() throws IOException {
		tempDir = TestUtils.createTempDir(getClass());
		
		facade = new PipelineFacade();
		pipelineInput = new PipelineHashIO();
		
		final File tempDir = new File(resourceDir, "temp");
		final File inputDir = new File(resourceDir, "input");
		
		final File inputMap = new File(inputDir, "test.ditamap");
		
		final File outDir = new File(resourceDir, "out");
		tobecomparefile = new File(tempDir, "tobecompared.xml");
		
		pipelineInput.setAttribute("inputmap", inputMap.getPath());
		pipelineInput.setAttribute("basedir", resourceDir.getPath());
		pipelineInput.setAttribute("inputdir", inputDir.getPath());
		pipelineInput.setAttribute("output", tobecomparefile.getPath());
		pipelineInput.setAttribute("outputdir", outDir.getPath());
		pipelineInput.setAttribute("tempDir", tempDir.getPath());
		pipelineInput.setAttribute("ditadir", "");
		pipelineInput.setAttribute("ditaext", ".xml");
		pipelineInput.setAttribute("indextype", "xhtml");
		pipelineInput.setAttribute("encoding", "en-US");
		pipelineInput.setAttribute("targetext", ".html");
		pipelineInput.setAttribute("validate", "false");
		pipelineInput.setAttribute("generatecopyouter", "1");
		pipelineInput.setAttribute("outercontrol", "warn");
		pipelineInput.setAttribute("onlytopicinmap", "false");
		pipelineInput.setAttribute("ditalist", new File(tempDir, "dita.list").getPath());
		pipelineInput.setAttribute("maplinks", new File(tempDir, "maplinks.unordered").getPath());
		
	}
	
	@Test
	public void testtopicmergemodule() throws DITAOTException, IOException
	{
		TopicMergeModule topicmergemodule = new TopicMergeModule();
        topicmergemodule.execute(pipelineInput);

		assertEquals(TestUtils.readFileToString(ditalistfile, true),
					 TestUtils.readFileToString(tobecomparefile, true));
    }

	@After
	public void tearDown() throws IOException {
		TestUtils.forceDelete(tempDir);
	}

}

@@ -610,17 +610,16 @@
 -stub%22, 
-%22
 TestTopi
@@ -630,17 +630,38 @@
 geModule
-%22
+.class.getSimpleName()
 );%0A%09priv
@@ -711,24 +711,26 @@
 e module;%0A%09%0A
+//
 %09private Abs
@@ -984,16 +984,18 @@
 ());%0A%09%09%0A
+//
 %09%09facade
@@ -1066,62 +1066,8 @@
 %0A%09%09%0A
-%09%09final File tempDir = new File(resourceDir, %22temp%22);%0A
 %09%09fi
@@ -1114,27 +1114,24 @@
 , %22input%22);%0A
-%09%09%0A
 %09%09final File
@@ -1178,18 +1178,16 @@
 amap%22);%0A
-%09%09
 %0A%09%09final
@@ -1192,19 +1192,25 @@
 al File 
-out
+temporary
 Dir = ne
@@ -1212,32 +1212,143 @@
  = new File(
-resource
+tempDir, %22temp%22);%0A%09%09TestUtils.copy(new File(resourceDir, %22temp%22), temporaryDir);%0A%09%09%0A%09%09final File outDir = new File(temp
 Dir, %22out%22);
@@ -1373,28 +1373,27 @@
  = new File(
-temp
+out
 Dir, %22tobeco
@@ -1769,16 +1769,21 @@
 r%22, temp
+orary
 Dir.getP
@@ -2307,24 +2307,29 @@
 ew File(temp
+orary
 Dir, %22dita.l
@@ -2396,24 +2396,29 @@
 ew File(temp
+orary
 Dir, %22maplin

Fix TestTopicMergeModule unit test - ID: 3159001