DateTimeExpandMetExtractor extends AbstractFilemgrMetExtractor { @Override public Metadata doExtract(Product product, Metadata metadata) throws MetExtractionException { String fullDateTime = getFullDateTime(metadata); createDateField(metadata, yearKey, fullDateTime, fullDateTimeFormat, "yyyy"); createDateField(metadata, monthKey, fullDateTime, fullDateTimeFormat, "MM"); createDateField(metadata, dayKey, fullDateTime, fullDateTimeFormat, "dd"); createDateField(metadata, hourKey, fullDateTime, fullDateTimeFormat, "HH"); createDateField(metadata, minuteKey, fullDateTime, fullDateTimeFormat, "mm"); createDateField(metadata, secondKey, fullDateTime, fullDateTimeFormat, "ss"); return metadata; }  @Override void doConfigure(); @Override Metadata doExtract(Product product, Metadata metadata);  }
@Test public void testExpandAll() throws MetExtractionException { when(configuration.containsKey("FullDateTimeKey")).thenReturn(true); when(configuration.containsKey("FullDateTimeFormat")).thenReturn(true); when(configuration.containsKey("YearKey")).thenReturn(true); when(configuration.containsKey("MonthKey")).thenReturn(true); when(configuration.containsKey("DayKey")).thenReturn(true); when(configuration.containsKey("HourKey")).thenReturn(true); when(configuration.containsKey("MinuteKey")).thenReturn(true); when(configuration.containsKey("SecondKey")).thenReturn(true); extractor.configure(configuration); Metadata extractedMetadata = extractor.doExtract(null, metadata); assertThat(extractedMetadata.getMetadata("StartYear"), is("2013")); assertThat(extractedMetadata.getMetadata("StartMonth"), is("05")); assertThat(extractedMetadata.getMetadata("StartDay"), is("23")); assertThat(extractedMetadata.getMetadata("StartHour"), is("03")); assertThat(extractedMetadata.getMetadata("StartMinute"), is("02")); assertThat(extractedMetadata.getMetadata("StartSecond"), is("01")); }
@Test public void testExpandSome() throws MetExtractionException { when(configuration.containsKey("FullDateTimeKey")).thenReturn(true); when(configuration.containsKey("FullDateTimeFormat")).thenReturn(true); when(configuration.containsKey("YearKey")).thenReturn(true); when(configuration.containsKey("MonthKey")).thenReturn(true); when(configuration.containsKey("DayKey")).thenReturn(true); extractor.configure(configuration); Metadata extractedMetadata = extractor.doExtract(null, metadata); assertThat(extractedMetadata.getMetadata("StartYear"), is("2013")); assertThat(extractedMetadata.getMetadata("StartMonth"), is("05")); assertThat(extractedMetadata.getMetadata("StartDay"), is("23")); assertThat(extractedMetadata.containsKey("StartHour"), is(false)); assertThat(extractedMetadata.containsKey("StartMinute"), is(false)); assertThat(extractedMetadata.containsKey("StartSecond"), is(false)); }
@Test public void testFailure() throws MetExtractionException { when(configuration.containsKey("FullDateTimeKey")).thenReturn(false); extractor.configure(configuration); expectedException.expect(MetExtractionException.class); extractor.doExtract(null, metadata); }