Commit 363f7008 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '1123-empty-data-overlay' into 'devel_14.0.x'

upload of empty data overlay file resulted in an error

See merge request !1067
parents 86be8a9c 58ba0629
Pipeline #21413 passed with stage
in 11 minutes and 48 seconds
......@@ -10,6 +10,7 @@ minerva (14.0.9) stable; urgency=medium
overlay second time and an error was thrown (#1121)
* Bug fix: when data overlay name in zip uploaded zip file is not present the
name of a file is used as overlay name (#1065)
* Bug fix: uploading empty data overlay resulted in an error (#1123)
-- Piotr Gawron <piotr.gawron@uni.lu> Mon, 3 Feb 2020 15:00:00 +0200
......
......@@ -37,6 +37,7 @@ public final class TextFileUtils {
*/
public static Map<String, String> getHeaderParametersFromFile(InputStream is) throws IOException {
Map<String, String> result = new HashMap<>();
result.put(COLUMN_COUNT_PARAM, "0");
BufferedReader in = new BufferedReader(new InputStreamReader(is));
String line = null;
while ((line = in.readLine()) != null) {
......
......@@ -35,6 +35,15 @@ public class TextFileUtilsTest extends CommonTestFunctions {
assertNull(params.get("header"));
}
@Test
public void testGetHeaderParametersFromEmptyFile() throws Exception {
String fileContent = "";
Map<String, String> params = TextFileUtils
.getHeaderParametersFromFile(new ByteArrayInputStream(fileContent.getBytes(StandardCharsets.UTF_8)));
assertNotNull(params.get(TextFileUtils.COLUMN_COUNT_PARAM));
}
@Test
public void testParseHeader() throws Exception {
InputStream is = new FileInputStream("testFiles/fileHeader.txt");
......
......@@ -471,6 +471,9 @@ public class ColorSchemaReader {
lineIndex++;
line = br.readLine();
}
if (line == null) {
throw new InvalidColorSchemaException("File does not contain any data");
}
String[] columns = line.split("\t");
Map<ColorSchemaColumn, Integer> schemaColumns = new HashMap<>();
......
......@@ -245,6 +245,24 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
reader.readColorSchema(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)), params);
}
@Test(expected = InvalidColorSchemaException.class)
public void testEmptyFile() throws Exception {
Map<String, String> params = new HashMap<>();
params.put(TextFileUtils.COLUMN_COUNT_PARAM, "0");
String input = "";
reader.readColorSchema(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)), params);
}
@Test(expected = InvalidColorSchemaException.class)
public void testFileWithHeaderOnly() throws Exception {
Map<String, String> params = new HashMap<>();
params.put(TextFileUtils.COLUMN_COUNT_PARAM, "0");
String input = "#xyz=aaaa\nabc=ttt";
reader.readColorSchema(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)), params);
}
@Test
public void testColoringWithInvalidValueAndColor2() throws Exception {
Map<String, String> params = new HashMap<>();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment