L2FormattingMapper extends Mapper<NullWritable, NullWritable, NullWritable, NullWritable> { static Map<String, Object> createBandSubsetParameter(Product targetProduct, Configuration jobConfig) { String outputBandList = jobConfig.get(JobConfigNames.CALVALUS_OUTPUT_BANDLIST); boolean hasBandList = StringUtils.isNotNullAndNotEmpty(outputBandList); Map<String, Object> subsetParams = new HashMap<String, Object>(); if (hasBandList) { String[] bandNames = outputBandList.split(","); StringBuilder sb = new StringBuilder(); for (String bandName : bandNames) { if (targetProduct.containsBand(bandName)) { if (sb.length() > 0) { sb.append(","); } sb.append(bandName); } else { String msgPattern = "Band '%s' shall be included in the output product but is not contained in " + "the processed product. Check if processing options are set appropriate?"; throw new IllegalStateException(String.format(msgPattern, bandName)); } } subsetParams.put("bandNames", sb.toString()); } return subsetParams; }  @Override void run(Mapper.Context context); static String getProductName(Configuration jobConfig, String fileName);  }
@Test(expected = IllegalStateException.class) public void testCreateBandSubsetParameterWhenBandIsMissing() throws Exception { JobConf jobConfig = new JobConf(); jobConfig.set(JobConfigNames.CALVALUS_OUTPUT_BANDLIST, "Band_1,Band_2,Band_3"); Product targetProduct = new Product("name", "type", 10, 10); targetProduct.addBand("Band_1", ProductData.TYPE_INT16); targetProduct.addBand("Band_3", ProductData.TYPE_INT16); L2FormattingMapper.createBandSubsetParameter(targetProduct, jobConfig); }
@Test public void testCreateBandSubsetParameter() throws Exception { JobConf jobConfig = new JobConf(); jobConfig.set(JobConfigNames.CALVALUS_OUTPUT_BANDLIST, "Band_1,Band_2,Band_3"); Product targetProduct = new Product("name", "type", 10, 10); targetProduct.addBand("Band_1", ProductData.TYPE_INT16); targetProduct.addBand("Band_2", ProductData.TYPE_INT16); targetProduct.addBand("Band_3", ProductData.TYPE_INT16); Map<String, Object> bandSubsetParameter = L2FormattingMapper.createBandSubsetParameter(targetProduct, jobConfig); String names = (String) bandSubsetParameter.get("bandNames"); assertNotNull(names); String[] bandNames = names.split(","); assertEquals(3, bandNames.length); assertEquals("Band_1", bandNames[0]); assertEquals("Band_2", bandNames[1]); assertEquals("Band_3", bandNames[2]); }