Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MSITE-945] More modern temporary file handling #203

Merged
merged 3 commits into from
Jul 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on this

@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