/**
 * Copyright (C) 2015 digitalfondue (info@digitalfondue.ch)
 *
 * 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 ch.digitalfondue.stampo;

import static java.nio.file.Files.write;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

import org.junit.Assert;
import org.junit.Test;

import ch.digitalfondue.stampo.TestUtils.InputOutputDirs;

public class StampoMultiLocalesTest {


  @Test
  public void testMultipleLocales() throws IOException {
    try (InputOutputDirs iod = TestUtils.get()) {
      
      write(iod.inputDir.resolve("content/index.html.peb"),
          "<h1>Hello World {{locale}}</h1>".getBytes(StandardCharsets.UTF_8));
      
      Files.createDirectories(iod.inputDir.resolve("content/post"));
      
      write(iod.inputDir.resolve("content/post/first.html"),
          "<h1>First {{locale}}</h1>".getBytes(StandardCharsets.UTF_8));
      
      write(iod.inputDir.resolve("content/post/second.html"),
          "<h1>Second {{locale}}</h1>".getBytes(StandardCharsets.UTF_8));
      
      write(iod.inputDir.resolve("configuration.yaml"), "locales: ['en', 'de','fr']".getBytes(StandardCharsets.UTF_8));
      
      Stampo stampo = new Stampo(iod.inputDir, iod.outputDir);
      
      stampo.build();
      
      Assert.assertTrue(Files.exists(iod.outputDir.resolve("en/index.html")));
      Assert.assertTrue(Files.exists(iod.outputDir.resolve("de/index.html")));
      Assert.assertTrue(Files.exists(iod.outputDir.resolve("fr/index.html")));
      
      Assert.assertTrue(Files.exists(iod.outputDir.resolve("en/post/first/index.html")));
      Assert.assertTrue(Files.exists(iod.outputDir.resolve("de/post/first/index.html")));
      Assert.assertTrue(Files.exists(iod.outputDir.resolve("fr/post/first/index.html")));
      
      
      Assert.assertTrue(Files.exists(iod.outputDir.resolve("en/post/second/index.html")));
      Assert.assertTrue(Files.exists(iod.outputDir.resolve("de/post/second/index.html")));
      Assert.assertTrue(Files.exists(iod.outputDir.resolve("fr/post/second/index.html")));
    }
  }
}

@@ -796,16 +796,41 @@
 e.Files;
+%0Aimport java.util.Arrays;
 %0A%0Aimport
@@ -1086,23 +1086,17 @@
 et()) %7B%0A
-      
 %0A
+
       wr
@@ -1222,31 +1222,25 @@
 ts.UTF_8));%0A
-      
 %0A
+
       Files.
@@ -1292,30 +1292,24 @@
 nt/post%22));%0A
-      
 %0A      write
@@ -1350,24 +1350,28 @@
 t/first.html
+.peb
 %22),%0A        
@@ -1427,38 +1427,32 @@
 arsets.UTF_8));%0A
-      
 %0A      write(iod
@@ -1494,16 +1494,20 @@
 ond.html
+.peb
 %22),%0A    
@@ -1572,30 +1572,24 @@
 ts.UTF_8));%0A
-      
 %0A      write
@@ -1632,16 +1632,26 @@
 .yaml%22),
+%0A         
  %22locale
@@ -1703,30 +1703,24 @@
 ts.UTF_8));%0A
-      
 %0A      Stamp
@@ -1771,23 +1771,17 @@
 utDir);%0A
-      
 %0A
+
       st
@@ -1798,94 +1798,73 @@
 ();%0A
+%0A
       
-%0A      Assert.assertTrue(Files.exists(iod.outputDir.resolve(%22en/index.html%22)));%0A
+for (String locale : Arrays.asList(%22en%22, %22de%22, %22fr%22)) %7B%0A  
     
@@ -1918,19 +1918,26 @@
 resolve(
-%22de
+locale + %22
 /index.h
@@ -1943,32 +1943,34 @@
 html%22)));%0A      
+  
 Assert.assertTru
@@ -1970,148 +1970,110 @@
 sert
-True(Files.exists(iod.outputDir.resolve(%22fr/index.html%22)));
+Equals(%22%3Ch1%3EHello World %22 + locale + %22%3C/h1%3E%22,
 %0A      
-%0A
       
-Assert.assertTrue(F
+TestUt
 il
-e
 s.
-exists(iod.outputDir.resolve(%22en/post/first
+fileOutputAsString(iod, locale + %22
 /ind
@@ -2074,35 +2074,37 @@
  %22/index.html%22))
-)
 ;%0A
+%0A  
       Assert.ass
@@ -2142,27 +2142,34 @@
 Dir.resolve(
-%22de
+locale + %22
 /post/first/
@@ -2182,32 +2182,34 @@
 html%22)));%0A      
+  
 Assert.assertTru
@@ -2209,51 +2209,104 @@
 sert
-True(Files.exists(iod.outputDir.resolve(%22fr
+Equals(%22%3Ch1%3EFirst %22 + locale + %22%3C/h1%3E%22,%0A            TestUtils.fileOutputAsString(iod, locale + %22
 /pos
@@ -2330,25 +2330,13 @@
 l%22))
-)
 ;%0A
+%0A
   
-    %0A      %0A
     
@@ -2390,19 +2390,26 @@
 resolve(
-%22en
+locale + %22
 /post/se
@@ -2427,32 +2427,34 @@
 html%22)));%0A      
+  
 Assert.assertTru
@@ -2454,142 +2454,105 @@
 sert
-True(Files.exists(iod.outputDir.resolve(%22de/post/second/index.html%22)));%0A      Assert.assertTrue(F
+Equals(%22%3Ch1%3ESecond %22 + locale + %22%3C/h1%3E%22,%0A            TestUt
 il
-e
 s.
-exists(iod.outputDir.resolve(%22fr
+fileOutputAsString(iod, locale + %22
 /pos
@@ -2569,26 +2569,34 @@
 ndex.html%22))
-)
 ;
+%0A      %7D%0A
 %0A    %7D%0A  %7D%0A%7D

update test