mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-13 22:15:26 +00:00
bug4371 Added utility class to truncate expedition filename extensions
incl. JUnit tests
This commit is contained in:
1 parent
318bfeaa13
commit
c4f94c4bbb
3 files changed
+103
-2
No files matched your search
+75
@@ -0,0 +1,75 @@
|
||||
package com.sap.sailing.server.gateway.trackfiles.impl;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExpeditionImportFilenameUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testTruncateFilenameExtentions_CSV() {
|
||||
testCase("2017Nov08_2.csv", "2017Nov08_2");
|
||||
testCase("2017Nov04VeryShort.CSV", "2017Nov04VeryShort");
|
||||
testCase("2017Nov04.1s_clean.csv", "2017Nov04.1s_clean");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTruncateFilenameExtentions_TXT() {
|
||||
testCase("Expedition_28Oct17_0820.txt", "Expedition_28Oct17_0820");
|
||||
testCase("VarLog1Hz_20171104_100149_843.Txt", "VarLog1Hz_20171104_100149_843");
|
||||
testCase("VarLog1Hz_20171105_091128_062.TXT", "VarLog1Hz_20171105_091128_062");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTruncateFilenameExtentions_LOG() {
|
||||
testCase("file1.log", "file1");
|
||||
testCase("file2.LOG", "file2");
|
||||
testCase("file3.Log", "file3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTruncateFilenameExtentions_GZ() {
|
||||
testCase("archive1.gz", "archive1");
|
||||
testCase("archive2.GZ", "archive2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTruncateFilenameExtentions_ZIP() {
|
||||
testCase("archive1.zip", "archive1");
|
||||
testCase("archive2.ZIP", "archive2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTruncateFilenameExtentions_CSV_GZ() {
|
||||
testCase("2017Nov08.csv.gz", "2017Nov08");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTruncateFilenameExtentions_CSV_ZIP() {
|
||||
testCase("2017Nov08.csv.zip", "2017Nov08");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTruncateFilenameExtentions_TXT_GZ() {
|
||||
testCase("VarLog1Hz_20171105_091128_062.Txt.gz", "VarLog1Hz_20171105_091128_062");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTruncateFilenameExtentions_TXT_ZIP() {
|
||||
testCase("VarLog1Hz_20171105_091128_062.Txt.zip", "VarLog1Hz_20171105_091128_062");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTruncateFilenameExtentions_LOG_GZ() {
|
||||
testCase("log-archive.log.gz", "log-archive");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTruncateFilenameExtentions_LOG_ZIP() {
|
||||
testCase("log-archive.log.zip", "log-archive");
|
||||
}
|
||||
|
||||
private void testCase(String actualFilename, String expectedResult) {
|
||||
Assert.assertEquals(expectedResult, ExpeditionImportFilenameUtils.truncateFilenameExtentions(actualFilename));
|
||||
}
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.sap.sailing.server.gateway.trackfiles.impl;
|
||||
|
||||
import static com.sap.sailing.server.trackfiles.impl.ExpeditionImportFileHandler.supportedExpeditionArchiveFileExtensions;
|
||||
import static com.sap.sailing.server.trackfiles.impl.ExpeditionImportFileHandler.supportedExpeditionLogFileExtensions;
|
||||
|
||||
class ExpeditionImportFilenameUtils {
|
||||
|
||||
static String truncateFilenameExtentions(String filenameWithExtensions) {
|
||||
return removeTailIfExists(removeTailIfExists(filenameWithExtensions, supportedExpeditionArchiveFileExtensions),
|
||||
supportedExpeditionLogFileExtensions);
|
||||
}
|
||||
|
||||
private static String removeTailIfExists(String source, Iterable<String> extensionsToRemove) {
|
||||
for (String toRemove : extensionsToRemove) {
|
||||
final String tailToRemove = "." + toRemove;
|
||||
if (source.toLowerCase().endsWith(tailToRemove)) {
|
||||
return source.substring(0, source.length() - tailToRemove.length());
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
}
|
||||
+5
-2
@@ -10,11 +10,14 @@ import java.util.List;
|
||||
import com.sap.sailing.domain.trackimport.FormatNotSupportedException;
|
||||
|
||||
public abstract class ExpeditionImportFileHandler implements CompressedStreamsUtil.FileHandler {
|
||||
public static final List<String> supportedExpeditionLogFileExtensions = Arrays.asList(new String[] { "csv", "log", "txt" });
|
||||
|
||||
public static final List<String> supportedExpeditionLogFileExtensions = Arrays.asList("csv", "log", "txt");
|
||||
public static final List<String> supportedExpeditionArchiveFileExtensions = Arrays.asList("gz", "zip");
|
||||
public static final List<String> supportedExpeditionFileExtensions;
|
||||
|
||||
static {
|
||||
final List<String> allExtensions = new ArrayList<>(supportedExpeditionLogFileExtensions);
|
||||
allExtensions.addAll(Arrays.asList(new String[] { "gz", "zip" }));
|
||||
allExtensions.addAll(supportedExpeditionArchiveFileExtensions);
|
||||
supportedExpeditionFileExtensions = Collections.unmodifiableList(allExtensions);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user