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

5379 TempDir support for tests #5499

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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 @@ -13,7 +13,7 @@ RUN mvn package -Dmaven.test.skip -Declipselink.weave.skip
# Do the Maven build to create the custom Java Runtime Image
# Incremental docker builds will resume here when you change sources
ADD src src
RUN mvn -Ddocker.build=true package -Pjlink-image -DskipTests
RUN mvn package -Pjlink-image -DskipTests
RUN echo "done!"

# 2nd stage, build the final image with the JRI built in the 1st stage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* the test class have finished.
*
*/
@Deprecated
public class TemporaryFolderExt implements BeforeEachCallback, AfterEachCallback {

private Path root;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
import java.util.List;

import io.helidon.common.testing.junit5.RestoreSystemPropertiesExt;
import io.helidon.common.testing.junit5.TemporaryFolderExt;
import io.helidon.config.spi.ConfigNode.ObjectNode;
import io.helidon.config.spi.ConfigSource;

import com.xebialabs.restito.server.StubServer;
import org.glassfish.grizzly.http.util.HttpStatus;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.io.TempDir;

import static com.xebialabs.restito.builder.stub.StubHttp.whenHttp;
import static com.xebialabs.restito.semantics.Action.status;
Expand All @@ -53,9 +52,6 @@ public class ConfigSourceMetaConfigTest {
private static final String TEST_ENV_VAR_VALUE = "This Is My ENV VARS Value.";
private static final String RELATIVE_PATH_TO_RESOURCE = "/src/test/resources/";

@RegisterExtension
public TemporaryFolderExt folder = TemporaryFolderExt.build();

@Test
@ExtendWith(RestoreSystemPropertiesExt.class)
public void testSystemProperties() {
Expand All @@ -65,9 +61,9 @@ public void testSystemProperties() {
ObjectNode.builder()
.addValue("type", "system-properties")
.build()));

ConfigSource source = singleSource(metaConfig);

assertThat(source, is(instanceOf(AbstractConfigSource.class)));

Config config = justFrom(source);
Expand Down Expand Up @@ -132,8 +128,7 @@ public void testFile() {
}

@Test
public void testDirectory() throws IOException {
File folder = this.folder.newFolder();
public void testDirectory(@TempDir File folder) throws IOException {
Files.write(Files.createFile(new File(folder, "username").toPath()), "libor".getBytes());
Files.write(Files.createFile(new File(folder, "password").toPath()), "^ery$ecretP&ssword".getBytes());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
import java.time.Instant;
import java.util.Optional;

import io.helidon.common.testing.junit5.TemporaryFolderExt;
import io.helidon.config.spi.ConfigContent;
import io.helidon.config.spi.ConfigNode.ObjectNode;
import io.helidon.config.spi.ConfigSource;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.io.TempDir;

import static io.helidon.config.ValueNodeMatcher.valueNode;
import static org.hamcrest.CoreMatchers.not;
Expand All @@ -44,9 +43,9 @@
*/
public class DirectoryConfigSourceTest {

@RegisterExtension
static TemporaryFolderExt folder = TemporaryFolderExt.build();
@TempDir
File tempFolder;

@Test
public void testDescriptionMandatory() {
ConfigSource configSource = ConfigSources.directory("secrets").build();
Expand All @@ -71,7 +70,7 @@ public void testLoadNoDirectory() {

@Test
public void testLoadEmptyDirectory() throws IOException {
DirectoryConfigSource configSource = ConfigSources.directory(folder.newFolder().getAbsolutePath())
DirectoryConfigSource configSource = ConfigSources.directory(tempFolder.getAbsolutePath())
.build();

Optional<ConfigContent.NodeContent> maybeContent = configSource.load();
Expand All @@ -93,11 +92,10 @@ public void testLoadEmptyDirectory() throws IOException {

@Test
public void testLoadDirectory() throws IOException {
File folder = DirectoryConfigSourceTest.folder.newFolder();
Files.write(Files.createFile(new File(folder, "username").toPath()), "libor".getBytes());
Files.write(Files.createFile(new File(folder, "password").toPath()), "^ery$ecretP&ssword".getBytes());
Files.write(Files.createFile(new File(tempFolder, "username").toPath()), "libor".getBytes());
Files.write(Files.createFile(new File(tempFolder, "password").toPath()), "^ery$ecretP&ssword".getBytes());

DirectoryConfigSource configSource = ConfigSources.directory(folder.getAbsolutePath())
DirectoryConfigSource configSource = ConfigSources.directory(tempFolder.getAbsolutePath())
.build();

Optional<ConfigContent.NodeContent> maybeContent = configSource.load();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@

import io.helidon.common.media.type.MediaType;
import io.helidon.common.media.type.MediaTypes;
import io.helidon.common.testing.junit5.TemporaryFolderExt;
import io.helidon.config.spi.ConfigParser;
import io.helidon.config.spi.ConfigSource;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static io.helidon.common.testing.junit5.OptionalMatcher.optionalValue;
import static org.hamcrest.CoreMatchers.not;
Expand All @@ -48,10 +46,6 @@ public class FileConfigSourceTest {
private static final MediaType TEST_MEDIA_TYPE = MediaTypes.create("my/media/type");
private static final String RELATIVE_PATH_TO_RESOURCE = "/src/test/resources/";

@RegisterExtension
static TemporaryFolderExt folder = TemporaryFolderExt.build();


@Test
public void testDescriptionMandatory() {
ConfigSource configSource = ConfigSources.file("application.conf").build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
import java.nio.file.Paths;
import java.util.Optional;

import io.helidon.common.testing.junit5.TemporaryFolderExt;
import io.helidon.config.spi.ConfigContent;
import io.helidon.config.spi.OverrideSource;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -37,9 +35,6 @@ public class FileOverrideSourceTest {

private static final String RELATIVE_PATH_TO_RESOURCE = "/src/test/resources/";

@RegisterExtension
static TemporaryFolderExt folder = TemporaryFolderExt.build();

private static String getDir() {
return Paths.get("").toAbsolutePath() + RELATIVE_PATH_TO_RESOURCE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@

import java.io.File;
import java.nio.file.Files;

import io.helidon.common.testing.junit5.TemporaryFolderExt;
import java.nio.file.Path;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.io.TempDir;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -33,13 +32,13 @@
*/
public class FileSourceHelperTest {

@RegisterExtension
static TemporaryFolderExt folder = TemporaryFolderExt.build();
@TempDir
Path tempFolder;

@Test
public void testDigestSameContent() throws Exception {
File file1 = folder.newFile("test1");
File file2 = folder.newFile("test2");
File file1 = Files.createFile(tempFolder.resolve("test1")).toFile();
File file2 = Files.createFile(tempFolder.resolve("test2")).toFile();
Files.write(file1.toPath(), "test file".getBytes());
Files.write(file2.toPath(), "test file".getBytes());

Expand All @@ -48,8 +47,8 @@ public void testDigestSameContent() throws Exception {

@Test
public void testDigestDifferentContent() throws Exception {
File file1 = folder.newFile("test1");
File file2 = folder.newFile("test2");
File file1 = Files.createFile(tempFolder.resolve("test1")).toFile();
File file2 = Files.createFile(tempFolder.resolve("test2")).toFile();
Files.write(file1.toPath(), "test file1".getBytes());
Files.write(file2.toPath(), "test file2".getBytes());

Expand Down
Loading