InputPathResolver { public static List<String> getInputPathPatterns(String inputPathPattern, Date minDate, Date maxDate, String regionName) { InputPathResolver inputPathResolver = new InputPathResolver(); inputPathResolver.setMinDate(minDate); inputPathResolver.setMaxDate(maxDate); inputPathResolver.setRegionName(regionName); return inputPathResolver.resolve(inputPathPattern); } InputPathResolver(); String getRegionName(); void setRegionName(String regionName); Date getMinDate(); void setMinDate(Date minDate); Date getMaxDate(); void setMaxDate(Date maxDate); List<String> resolve(String inputPathPatterns); List<String> resolveMultiYear(String inputPathPatterns); static List<String> getInputPathPatterns(String inputPathPattern, Date minDate, Date maxDate,
                                                    String regionName); static boolean containsDateVariables(String pattern);  }
@Test public void testThatInputIsOutputWithSimpleNameAndNoVars() throws ParseException { List<String> pathGlobs = InputPathResolver.getInputPathPatterns("foo", null, null, null); assertNotNull(pathGlobs); assertEquals(1, pathGlobs.size()); assertEquals("foo", pathGlobs.get(0)); }
@Test public void testThatInputPatternsCanHaveMultipleEntries() throws ParseException { List<String> pathGlobs = InputPathResolver.getInputPathPatterns("foo,bar,baz", null, null, null); assertNotNull(pathGlobs); assertEquals(3, pathGlobs.size()); assertEquals("foo", pathGlobs.get(0)); assertEquals("bar", pathGlobs.get(1)); assertEquals("baz", pathGlobs.get(2)); }
@Test public void testThatInputIsOutputWithSlashesNameAndNoVars() throws ParseException { List<String> pathGlobs = InputPathResolver.getInputPathPatterns("/foo/", null, null, null); assertNotNull(pathGlobs); assertEquals(1, pathGlobs.size()); assertEquals("/foo/", pathGlobs.get(0)); }
@Test public void testThatRegionStringIsReplaced() throws ParseException { List<String> pathGlobs = InputPathResolver.getInputPathPatterns("/foo/${region}/.*.N1", null, null, "northsea"); assertNotNull(pathGlobs); assertEquals(1, pathGlobs.size()); assertEquals("/foo/northsea/.*.N1", pathGlobs.get(0)); }
@Test public void testThatRegionStringIsReplacedWithStarWhenNotGiven() throws ParseException { List<String> pathGlobs = InputPathResolver.getInputPathPatterns("/foo/${region}/.*.N1", null, null, null); assertNotNull(pathGlobs); assertEquals(1, pathGlobs.size()); assertEquals("/foo/.*/.*.N1", pathGlobs.get(0)); }
@Test public void testThatRegionStringIsReplacedMultipleTimes() throws ParseException { List<String> pathGlobs = InputPathResolver.getInputPathPatterns("/foo/${region}/bar/${region}/.*.N1", null, null, "northsea"); assertNotNull(pathGlobs); assertEquals(1, pathGlobs.size()); assertEquals("/foo/northsea/bar/northsea/.*.N1", pathGlobs.get(0)); }
@Test public void testThatDatePartsAreReplaced() throws ParseException { List<String> pathGlobs = InputPathResolver.getInputPathPatterns("/foo/${yyyy}/${MM}/${dd}/.*.N1", date("2005-12-30"), date("2006-01-02"), null); assertNotNull(pathGlobs); assertEquals(4, pathGlobs.size()); assertEquals("/foo/2005/12/30/.*.N1", pathGlobs.get(0)); assertEquals("/foo/2005/12/31/.*.N1", pathGlobs.get(1)); assertEquals("/foo/2006/01/01/.*.N1", pathGlobs.get(2)); assertEquals("/foo/2006/01/02/.*.N1", pathGlobs.get(3)); }
@Test public void testThatDatePartsAreReplacedWhenNotGiven() throws ParseException { List<String> pathGlobs = InputPathResolver.getInputPathPatterns("/foo/${yyyy}/${MM}/${dd}/.*.N1", null, null, null); assertNotNull(pathGlobs); assertEquals(1, pathGlobs.size()); assertEquals("/foo/.*/.*/.*/.*.N1", pathGlobs.get(0)); }
@Test public void testThatGlobsAreUnique() throws ParseException { List<String> pathGlobs = InputPathResolver.getInputPathPatterns("/foo/${yyyy}/${MM}/.*.N1", date("2005-01-01"), date("2005-01-03"), null); assertNotNull(pathGlobs); assertEquals(1, pathGlobs.size()); assertEquals("/foo/2005/01/.*.N1", pathGlobs.get(0)); }
@Test public void testThatDatePartsAreConcatenated() throws ParseException { List<String> pathGlobs = InputPathResolver.getInputPathPatterns( "/foo/MER_RR__1P\\p{Upper}+${yyyy}${MM}${dd}*.N1", date("2005-01-01"), date("2005-01-03"), null); assertNotNull(pathGlobs); assertEquals(3, pathGlobs.size()); assertEquals("/foo/MER_RR__1P\\p{Upper}+20050101*.N1", pathGlobs.get(0)); assertEquals("/foo/MER_RR__1P\\p{Upper}+20050102*.N1", pathGlobs.get(1)); assertEquals("/foo/MER_RR__1P\\p{Upper}+20050103*.N1", pathGlobs.get(2)); }
@Test public void testGlobForDayOfYear() throws Exception { List<String> pathGlobs = InputPathResolver.getInputPathPatterns("/foo/MER_RR__1P\\p{Upper}+${yyyy}${DDD}*.N1", date("2005-01-01"), date("2005-01-03"), null); assertNotNull(pathGlobs); assertEquals(3, pathGlobs.size()); assertEquals("/foo/MER_RR__1P\\p{Upper}+2005001*.N1", pathGlobs.get(0)); assertEquals("/foo/MER_RR__1P\\p{Upper}+2005002*.N1", pathGlobs.get(1)); assertEquals("/foo/MER_RR__1P\\p{Upper}+2005003*.N1", pathGlobs.get(2)); }