/*
 * #%L
 * wcm.io
 * %%
 * Copyright (C) 2015 wcm.io
 * %%
 * 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.
 * #L%
 */
package io.wcm.devops.conga.generator;

import java.io.File;

import org.junit.Before;
import org.junit.Test;

public class GeneratorTest {

  private Generator underTest;

  @Before
  public void setUp() {
    File baseDir = new File("src/test/definitions");
    File destDir = new File("target/generation-test");
    underTest = new Generator(
        new File(baseDir, "roles"),
        new File(baseDir, "environments"),
        new File(baseDir, "templates"),
        destDir);
  }

  @Test
  public void testAllEnvironments() {
    underTest.generate();
  }

  @Test
  public void testOneEnvironments() {
    underTest.generate("env1");
  }

  @Test(expected = GeneratorException.class)
  public void testInvalidEnvironments() {
    underTest.generate("unknown");
  }

}

@@ -672,22 +672,225 @@
 ort 
-java.io.File;%0A
+static org.junit.Assert.assertTrue;%0A%0Aimport java.io.File;%0Aimport java.io.IOException;%0A%0Aimport org.apache.commons.io.FileUtils;%0Aimport org.apache.commons.lang3.CharEncoding;%0Aimport org.apache.commons.lang3.StringUtils;
 %0Aimp
@@ -995,16 +995,64 @@
 derTest;
+%0A  private File baseDir;%0A  private File destDir;
 %0A%0A  @Bef
@@ -1083,21 +1083,16 @@
 ) %7B%0A    
-File 
 baseDir 
@@ -1131,21 +1131,16 @@
 %22);%0A    
-File 
 destDir 
@@ -1421,16 +1421,1643 @@
 erate();
+%0A%0A    File node1Dir = assertDirectory(destDir, %22env1/node1%22);%0A%0A    File text1 = assertFile(node1Dir, %22text/test.txt%22);%0A    assertContains(text1, %22defaultString: value1 %C3%A4%C3%B6%C3%BC%C3%9F%22, CharEncoding.ISO_8859_1);%0A%0A    File json1 = assertFile(node1Dir, %22json/test.json%22);%0A%0A    File xml1tenant1 = assertFile(node1Dir, %22xml/test.tenant1.xml%22);%0A    File xml1tenant2 = assertFile(node1Dir, %22xml/test.tenant2.xml%22);%0A%0A    File node2Dir = assertDirectory(destDir, %22env1/node2%22);%0A%0A    File xml2tenant1 = assertFile(node2Dir, %22xml/test.tenant1.xml%22);%0A    File xml2tenant2 = assertFile(node2Dir, %22xml/test.tenant2.xml%22);%0A  %7D%0A%0A  private File assertDirectory(File assertBaseDir, String path) %7B%0A    File dir = new File(assertBaseDir, path);%0A    assertTrue(%22Directory exists: %22 + FileUtil.getCanonicalPath(dir), dir.exists() && dir.isDirectory());%0A    return dir;%0A  %7D%0A%0A  private File assertFile(File assertBaseDir, String path) %7B%0A    File file = new File(assertBaseDir, path);%0A    assertTrue(%22File exists: %22 + FileUtil.getCanonicalPath(file), file.exists() && file.isFile());%0A    return file;%0A  %7D%0A%0A  private void assertContains(File file, String contains) %7B%0A    assertContains(file, contains, CharEncoding.UTF_8);%0A  %7D%0A%0A  private void assertContains(File file, String contains, String charset) %7B%0A    try %7B%0A      String fileContent = FileUtils.readFileToString(file, charset);%0A      assertTrue(%22File %22 + FileUtil.getCanonicalPath(file) + %22 contains: %22 + contains, StringUtils.contains(fileContent, contains));%0A    %7D%0A    catch (IOException ex) %7B%0A      throw new RuntimeException(%22Unable to read contents from: %22 + FileUtil.getCanonicalPath(file), ex);%0A    %7D
 %0A  %7D%0A%0A  

add unit tests