1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 |
|
---|
6 | import java.io.ByteArrayOutputStream;
|
---|
7 | import java.io.IOException;
|
---|
8 | import java.nio.charset.StandardCharsets;
|
---|
9 | import java.time.LocalDate;
|
---|
10 | import java.time.Month;
|
---|
11 | import java.time.ZoneOffset;
|
---|
12 | import java.util.Date;
|
---|
13 |
|
---|
14 | import org.junit.Rule;
|
---|
15 | import org.junit.Test;
|
---|
16 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
17 | import org.openstreetmap.josm.data.gpx.GpxConstants;
|
---|
18 | import org.openstreetmap.josm.data.gpx.GpxData;
|
---|
19 | import org.openstreetmap.josm.data.gpx.WayPoint;
|
---|
20 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
21 |
|
---|
22 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Tests the {@link GpxWriter}.
|
---|
26 | */
|
---|
27 | public class GpxWriterTest {
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Setup rule
|
---|
31 | */
|
---|
32 | @Rule
|
---|
33 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
34 | public JOSMTestRules test = new JOSMTestRules();
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/16550">#16550</a>
|
---|
38 | * @throws IOException never
|
---|
39 | */
|
---|
40 | @Test
|
---|
41 | public void testTicket16550() throws IOException {
|
---|
42 | GpxData gpx = new GpxData();
|
---|
43 | WayPoint waypoint = new WayPoint(LatLon.ZERO);
|
---|
44 | waypoint.put(GpxConstants.PT_TIME, Date.from(LocalDate.of(2018, Month.AUGUST, 2).atStartOfDay(ZoneOffset.UTC).toInstant()));
|
---|
45 | gpx.addWaypoint(waypoint);
|
---|
46 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
---|
47 | try (GpxWriter writer = new GpxWriter(baos)) {
|
---|
48 | writer.write(gpx);
|
---|
49 | }
|
---|
50 | // Checks that time stored as date is correctly written into XML timestamp
|
---|
51 | assertEquals(String.format("<?xml version='1.0' encoding='UTF-8'?>%n" +
|
---|
52 | "<gpx version=\"1.1\" creator=\"JOSM GPX export\" xmlns=\"http://www.topografix.com/GPX/1/1\"%n" +
|
---|
53 | " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"%n" +
|
---|
54 | " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">%n" +
|
---|
55 | " <metadata>%n" +
|
---|
56 | " <bounds minlat=\"0.0\" minlon=\"0.0\" maxlat=\"0.0\" maxlon=\"0.0\"/>%n" +
|
---|
57 | " </metadata>%n" +
|
---|
58 | " <wpt lat=\"0.0\" lon=\"0.0\">%n" +
|
---|
59 | " <time>2018-08-02T00:00:00.000Z</time>%n" +
|
---|
60 | " </wpt>%n" +
|
---|
61 | "</gpx>"), baos.toString(StandardCharsets.UTF_8.name()));
|
---|
62 | }
|
---|
63 | }
|
---|