CSVMetadataLoader extends FileWithMetadataAction implements EOCAware { public FileInfo processLine(String[] nextLine, String[] metadataFields) { localCounters.clear(); if(nextLine.length != metadataFields.length) throw new RuntimeException("Line " + Arrays.asList(nextLine) + " does not have the same number of fields as the header line"); FileInfo fileInfo = new FileInfo(); fileInfo.put(Parameters.PARAM_INPUT_FILE,inputFile); if(nameSpace!=null) fileInfo.put(Parameters.PARAM_NAMESPACE, "{"+nameSpace+"}"); if(contentType!=null) fileInfo.put(Parameters.PARAM_CONTENTTYPE, contentType); HashMap docMetadata = new HashMap(); for(int i=0;i<nextLine.length;i++) { localCounters.put(inputFile.getAbsolutePath(),Integer.valueOf(1)); if(Parameters.PARAM_FILE.equals(metadataFields[i])) { String newPath = processPath(nextLine[i]); File file = new File(newPath); fileInfo.put(Parameters.PARAM_INPUT_PATH,inputPath); fileInfo.put(Parameters.PARAM_FILE,file); fileInfo.put(Parameters.PARAM_NAME, newPath.substring(newPath.lastIndexOf("/")+1)); localCounters.put(file.getAbsolutePath(),Integer.valueOf(1)); setCounter(file.getAbsolutePath(), Integer.valueOf(1)); } else docMetadata.put(metadataFields[i], nextLine[i]); } fileInfo.put(Parameters.PARAM_METADATA,docMetadata); logger.info("fileInfo=" + fileInfo); return fileInfo; }  @Override String getInputPath(); void setInputFile(File inputFile); CSVReader createReader(); FileInfo processLine(String[] nextLine, String[] metadataFields); String[] readMetadataFields(CSVReader reader); String getCategory(); void setNameSpace(String nameSpace); void setContentType(String contentType); @Override void beforeSendEOC();  }
@Test public final void testProcessLine() throws Exception { setUp(); CSVReader reader = metadataLoader.createReader(); String[] metadataFields = metadataLoader.readMetadataFields(reader); HashMap parameterMap = new HashMap(); String[] line = {"/home/rox/m2a-dev-tutorial/input-csv/file1.txt","metadata11","metadata21","metadata31"}; metadataLoader.processLine(line, metadataFields); assertEquals("/home/rox/m2a-dev-tutorial/input-csv/file1.txt",((File)(parameterMap.get(Parameters.PARAM_FILE))).getAbsolutePath()); HashMap<String,String> metadata = (HashMap)parameterMap.get(Parameters.PARAM_METADATA); assertEquals("metadata11",metadata.get(metadataFields[1])); assertEquals("metadata21",metadata.get(metadataFields[2])); assertEquals("metadata31",metadata.get(metadataFields[3])); reader.close(); }