Skip to content

Commit

Permalink
deegree#1760 - fixed date formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoltz committed Nov 7, 2024
1 parent e1d99f4 commit 5c32ee4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
5 changes: 5 additions & 0 deletions deegree-tools/deegree-tools-gml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@
<version>${spring-batch.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
import java.io.PrintWriter;
import java.nio.file.Path;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Collection;

Expand All @@ -51,7 +53,7 @@ public class ReportWriter extends JobExecutionListenerSupport {

private static final Logger LOG = getLogger(ReportWriter.class);

private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");

private final Summary summary;

Expand Down Expand Up @@ -134,13 +136,13 @@ private String getTimeNeeded(StepExecution stepExecution) {

private String getStartTime(StepExecution stepExecution) {
if (stepExecution != null && stepExecution.getStartTime() != null)
return DATE_FORMAT.format(stepExecution.getStartTime());
return stepExecution.getStartTime().format(DATE_FORMAT);
return "UNKNOWN";
}

private String getEndTime(StepExecution stepExecution) {
if (stepExecution != null && stepExecution.getEndTime() != null)
return DATE_FORMAT.format(stepExecution.getEndTime());
return stepExecution.getEndTime().format(DATE_FORMAT);
return "UNKNOWN";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.deegree.tools.featurestoresql.loader;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.Collections;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;

/**
* @author <a href="mailto:[email protected]">Lyn Goltz </a>
*/
public class ReportWriterTest {

@Rule
public TemporaryFolder tmpFolder = new TemporaryFolder();

@Test
public void test() throws IOException {
Summary summary = new Summary();
ReportWriter reportWriter = new ReportWriter(summary, tmpFolder.newFile().toPath());

JobExecution jobExecution = mock(JobExecution.class);
StepExecution stepExecution = mock(StepExecution.class);
when(jobExecution.getStepExecutions()).thenReturn(Collections.singletonList(stepExecution));
when(stepExecution.getStartTime()).thenReturn(LocalDateTime.now().minusDays(1));
when(stepExecution.getEndTime()).thenReturn(LocalDateTime.now().minusDays(1));
when(stepExecution.getExitStatus()).thenReturn(ExitStatus.COMPLETED);

reportWriter.afterJob(jobExecution);
}

}

0 comments on commit 5c32ee4

Please sign in to comment.