/** Tests that the variables are degribed to csv and that the csv contains the actual values */ @Test public void testDegribVariables() { variable.setName(VARIABLE_NAME); variable.setMessages(messages); variable.setOutputName(OUTPUT_VARIABLE_NAME); variables = new ArrayList<DegribVariable>(); variables.add(variable); degrib.setVariables(variables); try { degrib.degribVariables(); } catch (IOException e1) { System.out.println("Error running degrib executable"); e1.printStackTrace(); } String[] extensions = {"csv"}; Collection<File> result = FileUtils.listFiles(outputDirectory, extensions, false); int actualCount = result.size(); assertEquals(messages.size(), actualCount); for (Integer m : messages) { System.out.println(m); String currentFile = outputDirectory.getPath() + "/" + OUTPUT_VARIABLE_NAME + m + ".csv"; System.out.println(currentFile); try { assertTrue( FileUtils.directoryContains( outputDirectory, new File(outputDirectory, OUTPUT_VARIABLE_NAME + m + ".csv"))); } catch (IOException e) { System.out.println("Error accessing directory"); } } }
/** Tests that the files for a given variable are returned */ @Test public void testFilesForVariableFound() { variable.setName(VARIABLE_NAME); variable.setMessages(messages); variable.setOutputName(OUTPUT_VARIABLE_NAME); variables = new ArrayList<DegribVariable>(); variables.add(variable); degrib.setVariables(variables); Collection<File> results = degrib.getGribFiles(variable); assertEquals(COUNT_OF_WIND_FILES, results.size()); }
@Before public void setUp() throws Exception { degrib = new Degribber(); variable = new DegribVariable(); // Location of bin files to degrib degribDirectory = new File("src/test/java/com/greendev/pragma/degrib/resources/"); // Output the degrib results in the same folder outputDirectory = degribDirectory; messages = new ArrayList<Integer>(); degrib.setDegribDirectory(degribDirectory); degrib.setOutputDirectory(outputDirectory); degrib.setExecutable(executable); // Create sample messages to degrib (1-4) for (int i = 1; i < 5; i++) messages.add(i); }
/** * Tests that for a variable that does not exist, the degriber does not stop and nothing is * created in the output directory Useful in the case of downloads that fail (will be estimated * with older data) that should not be degribed. */ @Test public void testDegribVariableNotExists() { variable.setName(NON_EXISTING_VARIABLE_NAME); variable.setMessages(messages); variable.setOutputName(NON_EXISTING_OUTPUT_VARIABLE_NAME); variables = new ArrayList<DegribVariable>(); variables.add(variable); degrib.setVariables(variables); try { degrib.degribVariables(); } catch (IOException e1) { System.out.println("Error running degrib executable"); e1.printStackTrace(); } String[] extensions = {"csv"}; Collection<File> result = FileUtils.listFiles(outputDirectory, extensions, false); assertEquals(result.size(), COUNT_OF_SUN_FILES); }