/*
 * JBoss, Home of Professional Open Source
 * Copyright 2009, Red Hat Middleware LLC, and individual contributors
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * 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 org.jboss.shrinkwrap.impl.base.importer;

import java.util.logging.Logger;

import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.importer.ExplodedImporter;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
import org.junit.Assert;
import org.junit.Test;

/**
 * TestCase to ensure the correctness of the ExplodedImporter
 *
 * @author <a href="mailto:aslak@conduct.no">Aslak Knutsen</a>
 * @version $Revision: $
 */
public class ExplodedImporterTestCase
{

   private static final String EXISTING_DIRECTORY_RESOURCE = "exploded_import_test";
   
   private static final String EXISTING_FILE_RESOURCE = "exploded_import_test/Test.properties";
   
   @Test
   public void shouldBeAbleToImportADriectory() throws Exception {
      
      Archive<?> archive = ShrinkWrap.create(ExplodedImporter.class, "test.jar")
                              .importDirectory(
                                    SecurityActions.getThreadContextClassLoader()
                                       .getResource(EXISTING_DIRECTORY_RESOURCE).toURI().getPath()
                              )
                              .as(JavaArchive.class);
      Logger.getLogger(ExplodedImporterTestCase.class.getName()).info(archive.toString(true));
      Assert.assertTrue(
            "Root files should be imported",
            archive.contains(new BasicPath("/Test.properties")));      
      
      Assert.assertTrue(
            "Nested files should be imported",
            archive.contains(new BasicPath("/META-INF/MANIFEST.FM")));      

      Assert.assertTrue(
            "Nested files should be imported",
            archive.contains(new BasicPath("/org/jboss/Test.properties")));
      
      Assert.assertTrue(
            "Empty directories should be imported",
            archive.contains(new BasicPath("/empty_dir")));
      
      Assert.assertTrue(
            "Nested empty directories should be imported",
            archive.contains(new BasicPath("/parent/empty_dir"))); 
   }
   
   @Test(expected = IllegalArgumentException.class)
   public void shouldThrowExceptionIfImportingAFile() throws Exception {
    
      ShrinkWrap.create(ExplodedImporter.class, "test.jar")
                  .importDirectory(
                        SecurityActions.getThreadContextClassLoader()
                           .getResource(EXISTING_FILE_RESOURCE).toURI().getPath()
                  );
   }
}

@@ -824,24 +824,109 @@
 .importer;%0A%0A
+import java.io.File;%0Aimport java.io.IOException;%0Aimport java.net.URISyntaxException;%0A
 import java.
@@ -942,24 +942,24 @@
 ing.Logger;%0A
-
 %0Aimport org.
@@ -1220,16 +1220,46 @@
 Assert;%0A
+import org.junit.BeforeClass;%0A
 import o
@@ -1565,16 +1565,16 @@
 t%22;%0A   %0A
-
    priva
@@ -1661,24 +1661,1317 @@
 rties%22;%0A   %0A
+   /**%0A    * Name of the empty directory%0A    */%0A   private static final String EMPTY_DIR_NAME = %22empty_dir%22;%0A   %0A   /**%0A    * Name of a parent directory%0A    */%0A   private static final String PARENT_DIR_NAME = %22parent%22;%0A   %0A   /**%0A    * Creates the empty directories for this test, as Git cannot store empty dirs in SCM%0A    * @throws IOException%0A    * @throws URISyntaxException%0A    */%0A   @BeforeClass%0A   public static void makeEmptyDirectories() throws IOException, URISyntaxException%0A   %7B%0A      final File root = new File(ExplodedImporterTestCase.class.getProtectionDomain().getCodeSource().getLocation()%0A            .toURI());%0A      final File exlodedImportTest = new File(root, EXISTING_DIRECTORY_RESOURCE);%0A      Assert.assertTrue(%22Import test folder does not exist: %22 + exlodedImportTest.getAbsolutePath(), exlodedImportTest.exists());%0A      final File empty = new File(exlodedImportTest, EMPTY_DIR_NAME);%0A      Assert.assertTrue(%22Could not create the empty directory%22, empty.mkdir());%0A      final File parent = new File(exlodedImportTest, PARENT_DIR_NAME);%0A      final File parentEmpty = new File(parent, EMPTY_DIR_NAME);%0A      Assert.assertTrue(%22Could not create the parent empty directory%22, parentEmpty.mkdirs());%0A      parentEmpty.deleteOnExit();%0A      empty.deleteOnExit();%0A   %7D%0A   %0A
    @Test%0A   

Update test to reflect that Git will not store empty directories