private void initVelocityContext() throws Exception { VelocityContext velocityContext = metadataResourceEngine.getVelocityContext(); velocityContext.put("system", System.getProperties()); velocityContext.put("softwareName", "BEAM gpt"); velocityContext.put("softwareVersion", System.getProperty("beam.version", "")); velocityContext.put("commandLineArgs", commandLineArgs); // Derived properties (shortcuts). // Check if we really want them, if so, we have to maintain them in the future (nf) File targetFile = new File(commandLineArgs.getTargetFilePath()); File parentFile = targetFile.getParentFile(); velocityContext.put("targetFile", targetFile); velocityContext.put("targetDir", parentFile != null ? parentFile : new File(".")); velocityContext.put("targetBaseName", FileUtils.getFilenameWithoutExtension(targetFile)); velocityContext.put("targetName", targetFile.getName()); velocityContext.put("targetFormat", commandLineArgs.getTargetFormatName()); // Check if we also put the following into the context? // Actually no, because this puts the ontext in an unknown state, because we don't know which are the key's names (nf) //velocityContext.putAll(commandLineArgs.getParameterMap()); //velocityContext.putAll(commandLineArgs.getTargetFilePathMap()); //velocityContext.putAll(commandLineArgs.getSourceFilePathMap()); }
@Test public void testFormatOption() throws Exception { CommandLineArgs lineArgs; lineArgs = parseArgs("Reproject", "-t", "target.h5", "-f", "HDF-5", "source.dim"); assertEquals("HDF-5", lineArgs.getTargetFormatName()); lineArgs = parseArgs("Reproject", "-f", "GeoTIFF", "-t", "target.tif", "source.dim"); assertEquals("GeoTIFF", lineArgs.getTargetFormatName()); lineArgs = parseArgs("Reproject", "-f", "BEAM-DIMAP", "-t", "target.dim", "source.dim"); assertEquals("BEAM-DIMAP", lineArgs.getTargetFormatName()); }
String formatName = commandLineArgs.getTargetFormatName(); writeProduct(targetProduct, filePath, formatName, commandLineArgs.isClearCacheAfterRowWrite());
@Test public void testFormatDetection() throws Exception { CommandLineArgs lineArgs = parseArgs("Reproject", "-t", "target.dim", "source.dim"); assertEquals(CommandLineArgs.DEFAULT_FORMAT_NAME, lineArgs.getTargetFormatName()); String[] args = {"Reproject", "source.dim"}; lineArgs = parseArgs(args); assertEquals(CommandLineArgs.DEFAULT_FORMAT_NAME, lineArgs.getTargetFormatName()); }
@Test public void testOpWithSource() throws Exception { CommandLineArgs lineArgs = parseArgs("Reproject", "source.dim"); assertEquals("Reproject", lineArgs.getOperatorName()); assertEquals(null, lineArgs.getGraphFilePath()); assertEquals(CommandLineArgs.DEFAULT_TARGET_FILEPATH, lineArgs.getTargetFilePath()); assertEquals(CommandLineArgs.DEFAULT_FORMAT_NAME, lineArgs.getTargetFormatName()); SortedMap<String, String> sourceMap = lineArgs.getSourceFilePathMap(); assertNotNull(sourceMap); assertEquals(3, sourceMap.size()); assertEquals("source.dim", sourceMap.get("sourceProduct")); assertEquals("source.dim", sourceMap.get("sourceProduct.1")); assertEquals("source.dim", sourceMap.get("sourceProduct1")); // test for backward compatibility }
configuration.createChild("formatName").setValue(commandLineArgs.getTargetFormatName()); configuration.createChild("clearCacheAfterRowWrite").setValue( Boolean.toString(commandLineArgs.isClearCacheAfterRowWrite()));
@Test public void testOpWithTargetAndSource() throws Exception { CommandLineArgs lineArgs = parseArgs("Reproject", "-t", "output.dim", "source.dim"); assertEquals("Reproject", lineArgs.getOperatorName()); assertEquals(null, lineArgs.getGraphFilePath()); assertEquals("output.dim", lineArgs.getTargetFilePath()); assertEquals(CommandLineArgs.DEFAULT_FORMAT_NAME, lineArgs.getTargetFormatName()); SortedMap<String, String> sourceMap = lineArgs.getSourceFilePathMap(); assertNotNull(sourceMap); assertEquals(3, sourceMap.size()); assertEquals("source.dim", sourceMap.get("sourceProduct")); assertEquals("source.dim", sourceMap.get("sourceProduct.1")); assertEquals("source.dim", sourceMap.get("sourceProduct1")); // test for backward compatibility }
@Test public void testMinimumGraph() throws Exception { CommandLineArgs lineArgs = parseArgs("./map-proj.xml", "source.dim"); assertEquals(null, lineArgs.getOperatorName()); assertEquals("./map-proj.xml", lineArgs.getGraphFilePath()); assertEquals(CommandLineArgs.DEFAULT_TARGET_FILEPATH, lineArgs.getTargetFilePath()); assertEquals(CommandLineArgs.DEFAULT_FORMAT_NAME, lineArgs.getTargetFormatName()); SortedMap<String, String> map = lineArgs.getSourceFilePathMap(); assertNotNull(map); assertEquals("source.dim", map.get("sourceProduct")); assertEquals("source.dim", map.get("sourceProduct.1")); assertEquals("source.dim", map.get("sourceProduct1")); // test for backward compatibility }
@Test public void testHelpOption() throws Exception { CommandLineArgs lineArgs = parseArgs("Reproject", "-h"); assertEquals(true, lineArgs.isHelpRequested()); assertEquals("Reproject", lineArgs.getOperatorName()); assertEquals(null, lineArgs.getGraphFilePath()); assertEquals(CommandLineArgs.DEFAULT_TARGET_FILEPATH, lineArgs.getTargetFilePath()); assertEquals(CommandLineArgs.DEFAULT_FORMAT_NAME, lineArgs.getTargetFormatName()); SortedMap<String, String> map = lineArgs.getSourceFilePathMap(); assertNotNull(map); assertEquals(0, map.size()); }
@Test public void testOpOnly() throws Exception { CommandLineArgs lineArgs = parseArgs("Reproject"); assertEquals(false, lineArgs.isHelpRequested()); assertEquals("Reproject", lineArgs.getOperatorName()); assertEquals(null, lineArgs.getGraphFilePath()); assertEquals(CommandLineArgs.DEFAULT_TARGET_FILEPATH, lineArgs.getTargetFilePath()); assertEquals(CommandLineArgs.DEFAULT_FORMAT_NAME, lineArgs.getTargetFormatName()); SortedMap<String, String> map = lineArgs.getSourceFilePathMap(); assertNotNull(map); assertEquals(0, map.size()); }
@Test public void testGraphOnly() throws Exception { CommandLineArgs lineArgs = parseArgs("./map-proj.xml"); assertEquals(null, lineArgs.getOperatorName()); assertEquals("./map-proj.xml", lineArgs.getGraphFilePath()); assertEquals(CommandLineArgs.DEFAULT_TARGET_FILEPATH, lineArgs.getTargetFilePath()); assertEquals(CommandLineArgs.DEFAULT_FORMAT_NAME, lineArgs.getTargetFormatName()); SortedMap<String, String> map = lineArgs.getSourceFilePathMap(); assertNotNull(map); }