/*
 * This file is part of the DITA Open Toolkit project.
 *
 * Copyright 2021 Jarno Elovirta
 *
 * See the accompanying LICENSE file for applicable license.
 */

package org.dita.dost.module;

import com.google.common.collect.ImmutableSet;
import nu.validator.htmlparser.dom.HtmlDocumentBuilder;
import org.apache.tools.ant.*;
import org.dita.dost.TestUtils;
import org.dita.dost.chunk.ChunkModule;
import org.dita.dost.module.AbstractModuleTest;
import org.dita.dost.module.AbstractPipelineModule;
import org.dita.dost.module.MoveMetaModule;
import org.dita.dost.pipeline.AbstractPipelineInput;
import org.dita.dost.pipeline.PipelineHashIO;
import org.dita.dost.store.CacheStore;
import org.dita.dost.store.Store;
import org.dita.dost.store.StreamStore;
import org.dita.dost.util.CatalogUtils;
import org.dita.dost.util.FileUtils;
import org.dita.dost.util.Job;
import org.dita.dost.util.XMLUtils;
import org.junit.*;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.w3c.dom.*;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.*;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static java.util.Collections.emptyList;
import static junit.framework.Assert.assertEquals;
import static org.apache.commons.io.FileUtils.deleteDirectory;
//import static org.dita.dost.MoveMetaModuleTest.Transtype.PREPROCESS;
import static org.dita.dost.TestUtils.assertXMLEqual;
import static org.dita.dost.util.Constants.*;

@RunWith(Parameterized.class)
public class MoveMetaModuleTest extends AbstractModuleTest {
    @Parameterized.Parameters(name = "{0}")
    public static Collection<Object[]> data() {
        return Arrays.asList(new Object[][]{
                {"MatadataInheritance_foreign"},
                {"MatadataInheritance_keywords"},
                {"MatadataInheritance_linktext"},
                {"MatadataInheritance_othermeta"},
                {"MatadataInheritance_pemissions"},
                {"MatadataInheritance_pemissions_replace"},
                {"MatadataInheritance_prodinfo"},
                {"MatadataInheritance_publisher"},
                {"MatadataInheritance_resourceid"},
                {"MatadataInheritance_searchtitle"},
                {"MatadataInheritance_shortdesc"},
                {"MatadataInheritance_source"},
                {"MatadataInheritance_source_replace"},
                {"MatadataInheritance_unknown"},
                {"MetadataInheritance_audience"},
                {"MetadataInheritance_author"},
                {"MetadataInheritance_category"},
                {"MetadataInheritance_copyright"},
                {"MetadataInheritance_critdates"},
                {"MetadataInheritance_critdates_replace"},
                {"MetadataInheritance_data"},
                {"MetadataInheritance_dataabout"}
        });
    }

    public MoveMetaModuleTest(String testCase) {
        super(testCase, Collections.emptyMap());
    }

    @Override
    protected AbstractPipelineInput getAbstractPipelineInput() {
        final AbstractPipelineInput input = new PipelineHashIO();
        input.setAttribute(ANT_INVOKER_EXT_PARAM_TRANSTYPE, "html5");
        input.setAttribute(ANT_INVOKER_EXT_PARAM_STYLE,
                Paths.get("src", "main", "plugins", "org.dita.base", "xsl", "preprocess", "mappull.xsl").toString());
        return input;
    }

    @Override
    protected AbstractPipelineModule getModule(final File tempDir) {
        return new MoveMetaModule();
    }

    @Before
    public void setUp() throws Exception {
        super.setUp();
        final XMLUtils xmlUtils = new XMLUtils();
        final DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
        f.setNamespaceAware(true);
        final DocumentBuilder b = f.newDocumentBuilder();
        for (File file : tempDir.listFiles((dir, name) -> name.endsWith("dita") || name.endsWith("ditamap"))) {
            final Document d = b.parse(file);
            d.appendChild(d.createProcessingInstruction("workdir-uri", tempDir.toURI().toString()));
            xmlUtils.writeDocument(d, file);
        }
    }

    @Test
    @Ignore
    public void parallelFile() {
        chunkModule.setParallel(true);
        test();
    }

    @Test
    @Ignore
    public void serialMemory() throws IOException {
        job = new Job(tempDir, new CacheStore(tempDir, xmlUtils));
        chunkModule.setJob(job);
        test();
    }

    @Test
    @Ignore
    public void parallelMemory() throws IOException {
        job = new Job(tempDir, new CacheStore(tempDir, xmlUtils));
        chunkModule.setJob(job);
        chunkModule.setParallel(true);
        test();
    }
}

@@ -198,705 +198,184 @@
 ort 
-com.google.common.collect.ImmutableSet;%0Aimport nu.validator.htmlparser.dom.HtmlDocumentBuilder;%0Aimport org.apache.tools.ant.*;%0Aimport org.dita.dost.TestUtils;%0Aimport org.dita.dost.chunk.ChunkModule;%0Aimport org.dita.dost.module.AbstractModuleTest;%0Aimport org.dita.dost.module.AbstractPipelineModule;%0Aimport org.dita.dost.module.MoveMetaModule;%0Aimport org.dita.dost.pipeline.AbstractPipelineInput;%0Aimport org.dita.dost.pipeline.PipelineHashIO;%0Aimport org.dita.dost.store.CacheStore;%0Aimport org.dita.dost.store.Store;%0Aimport org.dita.dost.store.StreamStore;%0Aimport org.dita.dost.util.CatalogUtils;%0Aimport org.dita.dost.util.FileUtils;%0Aimport org.dita.dost.util.Job;%0Aimport org.dita.dost.util.XMLUtils
+org.dita.dost.pipeline.AbstractPipelineInput;%0Aimport org.dita.dost.pipeline.PipelineHashIO;%0Aimport org.dita.dost.util.XMLUtils;%0Aimport org.junit.Before;%0Aimport org.junit.Ignore
 ;%0Aim
@@ -389,17 +389,20 @@
 g.junit.
-*
+Test
 ;%0Aimport
@@ -491,42 +491,16 @@
 dom.
-*;%0Aimport org.xml.sax.SAXException
+Document
 ;%0A%0Ai
@@ -604,17 +604,20 @@
 java.io.
-*
+File
 ;%0Aimport
@@ -659,123 +659,14 @@
 til.
-*;%0Aimport java.util.concurrent.atomic.AtomicInteger;%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern
+Arrays
 ;%0Aim
@@ -684,35 +684,27 @@
 til.
-stream.
 Collect
-ors;%0A
+ion;
 %0Aimport 
 stat
@@ -699,23 +699,16 @@
 %0Aimport 
-static 
 java.uti
@@ -724,257 +724,81 @@
 ions
-.emptyList;%0Aimport static junit.framework.Assert.assertEquals;%0Aimport static org.apache.commons.io.FileUtils.deleteDirectory;%0A//import static org.dita.dost.MoveMetaModuleTest.Transtype.PREPROCESS;%0Aimport static org.dita.dost.TestUtils.assertXMLEqual
+;%0A%0Aimport static org.dita.dost.util.Constants.ANT_INVOKER_EXT_PARAM_STYLE
 ;%0Aim
@@ -838,17 +838,47 @@
 nstants.
-*
+ANT_INVOKER_EXT_PARAM_TRANSTYPE
 ;%0A%0A@RunW
@@ -3584,489 +3584,205 @@
     
-chunkModule.setParallel(true);%0A        test();%0A    %7D%0A%0A    @Test%0A    @Ignore%0A    public void serialMemory() throws IOException %7B%0A        job = new Job(tempDir, new CacheStore(tempDir, xmlUtils));%0A        chunkModule.setJob(job);%0A        test();%0A    %7D%0A%0A    @Test%0A    @Ignore%0A    public void parallelMemory() throws IOException %7B%0A        job = new Job(tempDir, new CacheStore(tempDir, xmlUtils));%0A        chunkModule.setJob(job);%0A        chunkModule.setParallel(true);%0A        test();
+// Ignore because MoveMetaModule doesn't use parallel features%0A    %7D%0A%0A    @Test%0A    @Ignore%0A    public void parallelMemory() %7B%0A        // Ignore because MoveMetaModule doesn't use parallel features
 %0A   

Disable parallel tests