// Path: src/test/java/at/makubi/maven/plugin/avrohugger/TestHelper.java
// public static void failTestIfFilesDiffer(Path expectedFile, Path actualFile) throws IOException {
//     String fileDiff = TestHelper.fileDiff(expectedFile.toFile(), actualFile.toFile());
//     if (!fileDiff.isEmpty()) {
//         fail("Expected file " + expectedFile + " and actual file " + actualFile + " differ. See output below." + System.lineSeparator() + fileDiff);
//     }
// }


import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import static at.makubi.maven.plugin.avrohugger.TestHelper.failTestIfFilesDiffer;
/*
 * Copyright 2016 the original author or authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package at.makubi.maven.plugin.avrohugger;




public class GeneratorMojoTest extends AbstractHarnessMojoTestCase {

    final Path testResourcesDir = Paths.get("src/test/resources/unit/avrohugger-maven-plugin/mojo");

    // ${basedir}
    final Path testRunnerBaseDir = Paths.get("target/test-harness/avrohugger-maven-plugin");
    // ${project.build.directory}
    final Path testRunnerProjectBuildDir = testRunnerBaseDir.resolve("target");

    @Before
    public void setUp() throws Exception {
        super.setUp();

        FileUtils.deleteDirectory(testRunnerBaseDir.toFile());
        createDir(testRunnerBaseDir);
    }

    public void testGenerateScalaSourcesWithDefaultSettings() throws Exception {
        final Path defaultTestResourcesDir = testResourcesDir.resolve("default");

        final Path testAvroSourceDir = testRunnerBaseDir.resolve(Defaults.relativeSourceDirectory);
        final Path testAvroSourceSubDir = testAvroSourceDir.resolve("subdir");

        final Path apiAvdl = Paths.get("Api.avdl");
        final Path subApiAvdl = Paths.get("SubApi.avdl");
        final Path recordWith25FieldsAvdl = Paths.get("RecordWith25Fields.avdl");
        final String testPomName = "pom-defaults.xml";

        createDir(testAvroSourceDir);
        createDir(testAvroSourceSubDir);

        // Copy pom
        Path srcPom = defaultTestResourcesDir.resolve(testPomName);
        Path pomPath = testRunnerBaseDir.resolve(testPomName);
        Files.copy(srcPom, pomPath, StandardCopyOption.REPLACE_EXISTING);

        // Copy AVDL files
        Files.copy(testResourcesDir.resolve(apiAvdl), testAvroSourceDir.resolve(apiAvdl), StandardCopyOption.REPLACE_EXISTING);
        Files.copy(testResourcesDir.resolve(subApiAvdl), testAvroSourceSubDir.resolve(subApiAvdl), StandardCopyOption.REPLACE_EXISTING);
        Files.copy(testResourcesDir.resolve(recordWith25FieldsAvdl), testAvroSourceDir.resolve(recordWith25FieldsAvdl), StandardCopyOption.REPLACE_EXISTING);

        GeneratorMojo generatorMojo = (GeneratorMojo) lookupMojo(pomPath, "generate-scala-sources");
        generatorMojo.execute();

        // Test 'sourceDirectory', 'outputDirectory' and 'sourceGenerationFormat'
// Path: src/test/java/at/makubi/maven/plugin/avrohugger/TestHelper.java
// public static void failTestIfFilesDiffer(Path expectedFile, Path actualFile) throws IOException {
//     String fileDiff = TestHelper.fileDiff(expectedFile.toFile(), actualFile.toFile());
//     if (!fileDiff.isEmpty()) {
//         fail("Expected file " + expectedFile + " and actual file " + actualFile + " differ. See output below." + System.lineSeparator() + fileDiff);
//     }
// }


// Path: src/test/java/at/makubi/maven/plugin/avrohugger/GeneratorMojoTest.java
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import static at.makubi.maven.plugin.avrohugger.TestHelper.failTestIfFilesDiffer;

/*
 * Copyright 2016 the original author or authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package at.makubi.maven.plugin.avrohugger;




public class GeneratorMojoTest extends AbstractHarnessMojoTestCase {

    final Path testResourcesDir = Paths.get("src/test/resources/unit/avrohugger-maven-plugin/mojo");

    // ${basedir}
    final Path testRunnerBaseDir = Paths.get("target/test-harness/avrohugger-maven-plugin");
    // ${project.build.directory}
    final Path testRunnerProjectBuildDir = testRunnerBaseDir.resolve("target");

    @Before
    public void setUp() throws Exception {
        super.setUp();

        FileUtils.deleteDirectory(testRunnerBaseDir.toFile());
        createDir(testRunnerBaseDir);
    }

    public void testGenerateScalaSourcesWithDefaultSettings() throws Exception {
        final Path defaultTestResourcesDir = testResourcesDir.resolve("default");

        final Path testAvroSourceDir = testRunnerBaseDir.resolve(Defaults.relativeSourceDirectory);
        final Path testAvroSourceSubDir = testAvroSourceDir.resolve("subdir");

        final Path apiAvdl = Paths.get("Api.avdl");
        final Path subApiAvdl = Paths.get("SubApi.avdl");
        final Path recordWith25FieldsAvdl = Paths.get("RecordWith25Fields.avdl");
        final String testPomName = "pom-defaults.xml";

        createDir(testAvroSourceDir);
        createDir(testAvroSourceSubDir);

        // Copy pom
        Path srcPom = defaultTestResourcesDir.resolve(testPomName);
        Path pomPath = testRunnerBaseDir.resolve(testPomName);
        Files.copy(srcPom, pomPath, StandardCopyOption.REPLACE_EXISTING);

        // Copy AVDL files
        Files.copy(testResourcesDir.resolve(apiAvdl), testAvroSourceDir.resolve(apiAvdl), StandardCopyOption.REPLACE_EXISTING);
        Files.copy(testResourcesDir.resolve(subApiAvdl), testAvroSourceSubDir.resolve(subApiAvdl), StandardCopyOption.REPLACE_EXISTING);
        Files.copy(testResourcesDir.resolve(recordWith25FieldsAvdl), testAvroSourceDir.resolve(recordWith25FieldsAvdl), StandardCopyOption.REPLACE_EXISTING);

        GeneratorMojo generatorMojo = (GeneratorMojo) lookupMojo(pomPath, "generate-scala-sources");
        generatorMojo.execute();

        // Test 'sourceDirectory', 'outputDirectory' and 'sourceGenerationFormat'
        failTestIfFilesDiffer(defaultTestResourcesDir.resolve("Record.scala"), testRunnerProjectBuildDir.resolve(Defaults.relativeOutputDirectory).resolve("at/makubi/maven/plugin/model/Record.scala"));