Skip to content

Commit

Permalink
Correct code format + Make video format non nullable (testcontainers#512
Browse files Browse the repository at this point in the history
)
  • Loading branch information
oussamabadr committed Feb 10, 2021
1 parent e093058 commit 01554f0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public VncRecordingContainer withVncPort(int vncPort) {
return this;
}

public VncRecordingContainer withVideoExtension(VncRecordingFormat recordingFormat) {
public VncRecordingContainer withVideoFormat(VncRecordingFormat recordingFormat) {
if (recordingFormat != null) {
this.recordingFormat = recordingFormat;
}
Expand All @@ -99,7 +99,7 @@ protected void configure() {

@SneakyThrows
public void saveRecordingToFile(@NonNull File file) {
try(InputStream inputStream = streamRecording()) {
try (InputStream inputStream = streamRecording()) {
Files.copy(inputStream, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
}
Expand All @@ -121,15 +121,15 @@ public enum VncRecordingFormat {
@Override
String reencodeRecording(@NonNull VncRecordingContainer container, @NonNull String source) throws IOException, InterruptedException {
String newFileOutput = "/newScreen.flv";
container.execInContainer("ffmpeg" , "-i", source, "-vcodec", "libx264", newFileOutput);
container.execInContainer("ffmpeg", "-i", source, "-vcodec", "libx264", newFileOutput);
return newFileOutput;
}
},
MP4("mp4") {
@Override
String reencodeRecording(@NonNull VncRecordingContainer container, @NonNull String source) throws IOException, InterruptedException {
String newFileOutput = "/newScreen.mp4";
container.execInContainer("ffmpeg" , "-i", source, "-vcodec", "libx264", "-movflags", "faststart", newFileOutput);
container.execInContainer("ffmpeg", "-i", source, "-vcodec", "libx264", "-movflags", "faststart", newFileOutput);
return newFileOutput;
}
};
Expand All @@ -147,14 +147,8 @@ public String getExtension() {
return filenameExtension;
}

/**
* @return {@code vncRecordingFormat} value if not null, otherwise, {@link VncRecordingFormat#FLV} will be returned as a default format.
*/
public static VncRecordingFormat of(VncRecordingFormat vncRecordingFormat) {
if (vncRecordingFormat == null) {
return DEFAULT_FORMAT;
}
return vncRecordingFormat;
public static VncRecordingFormat getDefaultFormat() {
return DEFAULT_FORMAT;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ protected void configure() {
vncRecordingContainer = new VncRecordingContainer(this)
.withVncPassword(DEFAULT_PASSWORD)
.withVncPort(VNC_PORT)
.withVideoExtension(recordingFormat);
.withVideoFormat(recordingFormat);
}

if (customImageName != null) {
Expand Down Expand Up @@ -364,7 +364,7 @@ public SELF withRecordingMode(VncRecordingMode recordingMode, File vncRecordingD
return withRecordingMode(recordingMode, vncRecordingDirectory, null);
}

public SELF withRecordingMode(VncRecordingMode recordingMode, File vncRecordingDirectory, @Nullable VncRecordingFormat recordingFormat) {
public SELF withRecordingMode(VncRecordingMode recordingMode, File vncRecordingDirectory, VncRecordingFormat recordingFormat) {
this.recordingMode = recordingMode;
this.vncRecordingDirectory = vncRecordingDirectory;
this.recordingFormat = recordingFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class DefaultRecordingFileFactory implements RecordingFileFactory {

@Override
public File recordingFileForTest(File vncRecordingDirectory, String prefix, boolean succeeded) {
return recordingFileForTest(vncRecordingDirectory, prefix, succeeded, null);
return recordingFileForTest(vncRecordingDirectory, prefix, succeeded, VncRecordingFormat.getDefaultFormat());
}

@Override
Expand All @@ -26,7 +26,7 @@ public File recordingFileForTest(File vncRecordingDirectory, String prefix, bool
resultMarker,
prefix,
filenameDateFormat.format(new Date()),
VncRecordingFormat.of(recordingFormat).getExtension()
recordingFormat.getExtension()
);
return new File(vncRecordingDirectory, fileName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ default File recordingFileForTest(File vncRecordingDirectory, Description descri
return recordingFileForTest(vncRecordingDirectory, description.getTestClass().getSimpleName() + "-" + description.getMethodName(), succeeded);
}

File recordingFileForTest(File vncRecordingDirectory, String prefix, boolean succeeded);

default File recordingFileForTest(File vncRecordingDirectory, String prefix, boolean succeeded, VncRecordingFormat recordingFormat) {
return recordingFileForTest(vncRecordingDirectory, prefix, succeeded);
}

File recordingFileForTest(File vncRecordingDirectory, String prefix, boolean succeeded);

}
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ public void recordingTestThatShouldHaveCorrectDuration() throws IOException, Int
mountableFile = MountableFile.forHostPath(recordedFiles[0].getCanonicalPath());
}

try( GenericContainer<?> container = new GenericContainer<>(DockerImageName.parse("testcontainers/vnc-recorder:1.2.0")) ) {
try (GenericContainer<?> container = new GenericContainer<>(DockerImageName.parse("testcontainers/vnc-recorder:1.2.0"))) {
String recordFileContainerPath = "/tmp/chromeTestRecord.flv";
container.withCopyFileToContainer(mountableFile, recordFileContainerPath)
.withCreateContainerCmdModifier( createContainerCmd -> createContainerCmd.withEntrypoint("ffmpeg") )
.withCommand("-i" , recordFileContainerPath, "-f" ,"null" ,"-" )
.waitingFor( new LogMessageWaitStrategy()
.withCreateContainerCmdModifier(createContainerCmd -> createContainerCmd.withEntrypoint("ffmpeg"))
.withCommand("-i", recordFileContainerPath, "-f", "null", "-")
.waitingFor(new LogMessageWaitStrategy()
.withRegEx(".*Duration.*")
.withStartupTimeout(Duration.of(60, SECONDS)) )
.withStartupTimeout(Duration.of(60, SECONDS)))
.start();
String ffmpegOutput = container.getLogs();

Expand Down

0 comments on commit 01554f0

Please sign in to comment.