package pl.domzal.junit.docker.rule.examples;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import pl.domzal.junit.docker.rule.DockerRule;

public class ExampleVolumeMountTest {

    private static Logger log = LoggerFactory.getLogger(ExampleVolumeMountTest.class);

    @ClassRule
    public static TemporaryFolder tempFolder = new TemporaryFolder();

    private static File testFile;
    private static String testFilename;
    private static File testDir;

    @BeforeClass
    public static void setup() throws IOException {

        testFile = tempFolder.newFile();
        testFilename = testFile.getName();
        FileUtils.write(testFile, "1234567890");
        testDir = tempFolder.getRoot();
        log.debug("testDir: {}", testDir.getAbsolutePath());
    }

    @Rule
    public DockerRule testee = DockerRule.builder()//
            .imageName("busybox")//
            .mountFrom(testDir).to("/somedir", "ro")//
            .cmd("sh", "-c", "cat /somedir/"+testFilename)//
            .build();

    @Test(timeout = 10000)
    public void shouldReadMountFromJavaFile() throws Throwable {
        testee.waitFor("1234567890", 10);
    }

}

@@ -277,65 +277,8 @@
 der;
-%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aim
@@ -370,283 +370,87 @@
     
-private static Logger log = LoggerFactory.getLogger(ExampleVolumeMountTest.class);%0A%0A    @ClassRule%0A    public static TemporaryFolder tempFolder = new TemporaryFolder();%0A%0A    private static File testFile;%0A    private static String testFilename;%0A    private static File testDir
+@ClassRule%0A    public static TemporaryFolder tempFolder = new TemporaryFolder()
 ;%0A%0A 
@@ -517,24 +517,28 @@
 ption %7B%0A
-%0A
+ 
        
+File
  testFil
@@ -564,51 +564,18 @@
 ile(
-);%0A        testFilename = testFile.getName(
+%22somefile%22
 );%0A 
@@ -626,109 +626,8 @@
 %22);%0A
-        testDir = tempFolder.getRoot();%0A        log.debug(%22testDir: %7B%7D%22, testDir.getAbsolutePath());%0A
     
@@ -758,13 +758,26 @@
 m(te
-stDir
+mpFolder.getRoot()
 ).to
@@ -844,22 +844,17 @@
 dir/
-%22+testFilename
+somefile%22
 )//%0A

make mount example simpler