Skip to content

Commit

Permalink
[MSITE-945] More modern temporary file handling (#203)
Browse files Browse the repository at this point in the history
* More modern temporary file handling
  • Loading branch information
elharo authored and michael-o committed Jul 28, 2024
1 parent eb0b0f6 commit 6fc5d17
Showing 1 changed file with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.util.ReflectionUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

Expand All @@ -51,15 +53,19 @@
@RunWith(JUnit4.class)
public abstract class AbstractSiteDeployWebDavTest extends AbstractMojoTestCase {

File siteTargetPath = new File(getBasedir() + File.separator + "target" + File.separator + "siteTargetDeploy");
// Can use @TempDir with JUnit 5
@Rule
public TemporaryFolder directory = new TemporaryFolder();

private File siteTargetPath;

@Override
@Before
public void setUp() throws Exception {
super.setUp();
siteTargetPath = new File(directory.newFolder(), "target");
if (!siteTargetPath.exists()) {
siteTargetPath.mkdirs();
FileUtils.cleanDirectory(siteTargetPath);
}
}

Expand All @@ -69,7 +75,6 @@ public void setUp() throws Exception {

@Test
public void noAuthzDavDeploy() throws Exception {
FileUtils.cleanDirectory(siteTargetPath);
SimpleDavServerHandler simpleDavServerHandler = new SimpleDavServerHandler(siteTargetPath);

try {
Expand Down Expand Up @@ -104,8 +109,6 @@ public void noAuthzDavDeploy() throws Exception {

@Test
public void davDeployThruProxyWithoutAuthzInProxy() throws Exception {

FileUtils.cleanDirectory(siteTargetPath);
SimpleDavServerHandler simpleDavServerHandler = new SimpleDavServerHandler(siteTargetPath);
try {
File pluginXmlFile = getTestFile("src/test/resources/unit/deploy-dav/pom.xml");
Expand Down Expand Up @@ -151,10 +154,6 @@ public void davDeployThruProxyWithoutAuthzInProxy() throws Exception {

@Test
public void davDeployThruProxyWitAuthzInProxy() throws Exception {

FileUtils.cleanDirectory(siteTargetPath);
// SimpleDavServerHandler simpleDavServerHandler = new SimpleDavServerHandler( siteTargetPath );

Map<String, String> authentications = new HashMap<>();
authentications.put("foo", "titi");

Expand Down Expand Up @@ -226,8 +225,8 @@ private void assertContentInFiles() throws Exception {

File cssFile = new File(siteTargetPath, "site" + File.separator + "css" + File.separator + "maven-base.css");
assertTrue(cssFile.exists());
fileContent = FileUtils.readFileToString(cssFile, StandardCharsets.UTF_8);
assertTrue(fileContent.contains("background-image: url(../images/collapsed.gif);"));
String cssContent = FileUtils.readFileToString(cssFile, StandardCharsets.UTF_8);
assertTrue(cssContent.contains("background-image: url(../images/collapsed.gif);"));
}

/**
Expand Down

0 comments on commit 6fc5d17

Please sign in to comment.