diff --git a/src/main/java/org/olat/modules/video/VideoFormat.java b/src/main/java/org/olat/modules/video/VideoFormat.java index fabdc68b75779802943508a0099cecd8b677fb6b..36285bd3a9a857cd483ccbe811605913fb963dfd 100644 --- a/src/main/java/org/olat/modules/video/VideoFormat.java +++ b/src/main/java/org/olat/modules/video/VideoFormat.java @@ -25,6 +25,7 @@ import java.net.URL; import org.apache.commons.io.FilenameUtils; import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; +import org.olat.core.util.StringHelper; /** * @@ -55,15 +56,15 @@ public enum VideoFormat { } public static VideoFormat secureValueOf(String val) { - if("zip".equals(val)) { - return VideoFormat.mp4;// why was zip a format??? - } - for(VideoFormat format:values()) { if(format.name().equals(val)) { return format; } } + // catch zip, mov and other exotic format + if(StringHelper.containsNonWhitespace(val)) { + return VideoFormat.mp4;// convert at the end all unkown format + } return null; } diff --git a/src/test/java/org/olat/modules/video/VideoFormatTest.java b/src/test/java/org/olat/modules/video/VideoFormatTest.java new file mode 100644 index 0000000000000000000000000000000000000000..9739ad8901b9eeecc144591a2531cd0f8345e9e0 --- /dev/null +++ b/src/test/java/org/olat/modules/video/VideoFormatTest.java @@ -0,0 +1,69 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.modules.video; + +import java.util.Arrays; +import java.util.Collection; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + + +/** + * + * Initial date: 5 avr. 2019<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +@RunWith(Parameterized.class) +public class VideoFormatTest { + + @Parameters + public static Collection<Object[]> data() { + return Arrays.asList(new Object[][] { + { "mov", VideoFormat.mp4 }, + { "zip", VideoFormat.mp4 }, + { "somethingelse", VideoFormat.mp4 }, + { "youtube", VideoFormat.youtube }, + { "vimeo", VideoFormat.vimeo }, + { "panopto", VideoFormat.panopto }, + { "mp4", VideoFormat.mp4 }, + { null, null } + }); + } + + private String format; + private VideoFormat expectedFormat; + + public VideoFormatTest(String format, VideoFormat expectedFormat) { + this.format = format; + this.expectedFormat = expectedFormat; + } + + @Test + public void conve() { + VideoFormat formatEnum = VideoFormat.secureValueOf(format); + Assert.assertEquals(expectedFormat, formatEnum); + } + +} diff --git a/src/test/java/org/olat/test/AllTestsJunit4.java b/src/test/java/org/olat/test/AllTestsJunit4.java index 090a9d137cec0fc6b041e4e557225e68888c260f..c84e88cc6af77250ce6a5ca9c04b247e2c3cdf9d 100644 --- a/src/test/java/org/olat/test/AllTestsJunit4.java +++ b/src/test/java/org/olat/test/AllTestsJunit4.java @@ -269,6 +269,7 @@ import org.junit.runners.Suite; org.olat.modules.taxonomy.manager.TaxonomyLevelTypeDAOTest.class, org.olat.modules.taxonomy.manager.TaxonomyCompetenceDAOTest.class, org.olat.modules.taxonomy.manager.TaxonomyCompetenceAuditLogDAOTest.class, + org.olat.modules.video.VideoFormatTest.class, org.olat.modules.video.manager.VideoTranscodingDAOTest.class, org.olat.modules.video.manager.VideoMetadataDAOTest.class, org.olat.modules.video.manager.VideoXStreamTest.class,