YamlProductionRequestConverter { public ProductionRequest loadProductionRequest(String userName) { String productionType = (String) map.get("productionType"); Map<String, String> parameterMap = new HashMap<>(); Set<Map.Entry<String, Object>> entries = map.entrySet(); for (Map.Entry<String, Object> entry : entries) { String key = entry.getKey(); if (!key.equals("productionType")) { Object value = entry.getValue(); if (value instanceof String) { parameterMap.put(key, ((String) value).trim()); } else if (value instanceof Boolean || value instanceof Number) { parameterMap.put(key, value.toString()); } else if (value instanceof Date) { parameterMap.put(key, DateRange.DATE_FORMAT.format(value)); } else if (value instanceof String[]) { parameterMap.put(key, arrayToString((String[]) value)); } else if (value instanceof List) { List<String> sa = (List) value; parameterMap.put(key, arrayToString(sa.toArray(new String[sa.size()]))); } else if (value == null) { parameterMap.put(key, ""); } else { String msg = String.format("unsupported value type %s for key '%s' with value '%s'", value.getClass().getName(), key, value); throw new IllegalArgumentException(msg); } } } return new ProductionRequest(productionType, userName, parameterMap); } YamlProductionRequestConverter(Reader reader); ProductionRequest loadProductionRequest(String userName);  }
@Test public void testConversionToMap() throws Exception { InputStream resourceAsStream = getClass().getResourceAsStream("ma-request.yaml"); InputStreamReader inputStreamReader = new InputStreamReader(resourceAsStream); ProductionRequest productionRequest = new YamlProductionRequestConverter(inputStreamReader).loadProductionRequest("testuser"); assertNotNull(productionRequest); assertEquals("MA", productionRequest.getProductionType()); assertNotNull(productionRequest.getUserName()); assertEquals("testuser", productionRequest.getUserName()); Map<String, String> parameters = productionRequest.getParameters(); assertNotNull(parameters); assertTrue(parameters.containsKey("calvalus.processor.package")); assertEquals("beam-meris-radiometry", parameters.get("calvalus.processor.package")); assertTrue(parameters.containsKey("calvalus.processor.version")); assertEquals("1.0", parameters.get("calvalus.processor.version")); assertTrue(parameters.containsKey("calvalus.input")); String inputValue = parameters.get("calvalus.input"); assertTrue(inputValue.contains(",")); String[] splits = inputValue.split(","); assertEquals(2, splits.length); assertEquals("hdfs: assertEquals("hdfs: assertTrue(parameters.containsKey("calvalus.l2.parameters")); String l2Parameters = parameters.get("calvalus.l2.parameters"); assertTrue(l2Parameters.startsWith("<parameters>")); assertTrue(l2Parameters.endsWith("</parameters>")); assertTrue(l2Parameters.contains("<doSmile>true</doSmile>")); assertTrue(l2Parameters.contains("<reproVersion>AUTO_DETECT</reproVersion>")); assertTrue(parameters.containsKey("calvalus.output.compression")); assertNotNull(parameters.get("calvalus.output.compression")); assertEquals("", parameters.get("calvalus.output.compression")); assertEquals("BEAM-DIMAP", parameters.get("calvalus.input.format")); assertNull(productionRequest.getRegionGeometry(null)); assertNotNull(parameters.get("calvalus.plainText.parameter")); String expectedPlainText = "<parameters>\nThis is a multiline\nTextfield\n</parameters>"; assertEquals(expectedPlainText, parameters.get("calvalus.plainText.parameter")); assertEquals("true", parameters.get("copyInput")); assertEquals("2017-10-01", parameters.get("minDate")); assertEquals("2017-12-31", parameters.get("maxDate")); }