Commit 12c3451e authored by Piotr Gawron's avatar Piotr Gawron
Browse files

when processing file throw proper exception if type in is invalid

parent a1e42577
......@@ -104,7 +104,14 @@ public class ColorSchemaReader {
return readGenericColorSchema(colorInputStream);
}
} else {
ColorSchemaType type = ColorSchemaType.valueOf(params.get(ZipEntryFileFactory.LAYOUT_HEADER_PARAM_TYPE));
ColorSchemaType type = null;
try {
type = ColorSchemaType.valueOf(params.get(ZipEntryFileFactory.LAYOUT_HEADER_PARAM_TYPE));
} catch (IllegalArgumentException e) {
String options = StringUtils.join(ColorSchemaType.values(), ", ");
throw new InvalidColorSchemaException("Invalid overlay type: "
+ params.get(ZipEntryFileFactory.LAYOUT_HEADER_PARAM_TYPE) + ". Allowed options: " + options);
}
if (type == null) {
logger.warn("Unknown type of layout file: " + params.get(ZipEntryFileFactory.LAYOUT_HEADER_PARAM_TYPE));
return readGenericColorSchema(colorInputStream);
......
......@@ -480,5 +480,14 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
}
}
@Test(expected = InvalidColorSchemaException.class)
public void testReadColorSchemaWithInvalidType() throws Exception {
FileInputStream fis = new FileInputStream("testFiles/coloring/invalidType.txt");
FileInputStream fis2 = new FileInputStream("testFiles/coloring/invalidType.txt");
ColorSchemaReader reader = new ColorSchemaReader();
reader.readColorSchema(fis, TextFileUtils.getHeaderParametersFromFile(fis2));
}
}
#TYPE=gen
value identifier Chebi
-0,943978048 HGNC:11138
-0,941309505 CHEBI:15377
1 CHEBI:15376
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