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.ByteArrayInputStream;
|
---|
7 | import java.nio.charset.StandardCharsets;
|
---|
8 |
|
---|
9 | import org.junit.BeforeClass;
|
---|
10 | import org.junit.Test;
|
---|
11 | import org.openstreetmap.josm.JOSMFixture;
|
---|
12 | import org.openstreetmap.josm.data.osm.Changeset;
|
---|
13 | import org.openstreetmap.josm.data.osm.User;
|
---|
14 | import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Unit tests of {@link OsmApi} class.
|
---|
18 | */
|
---|
19 | public class OsmApiTest {
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Setup test.
|
---|
23 | */
|
---|
24 | @BeforeClass
|
---|
25 | public static void setUp() {
|
---|
26 | JOSMFixture.createUnitTestFixture().init();
|
---|
27 | }
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/12675">Bug #12675</a>.
|
---|
31 | * @throws IllegalDataException if an error occurs
|
---|
32 | */
|
---|
33 | @Test
|
---|
34 | public void testTicket12675() throws IllegalDataException {
|
---|
35 | OsmApi api = OsmApi.getOsmApi();
|
---|
36 | Changeset cs = new Changeset();
|
---|
37 | cs.setUser(User.getAnonymous());
|
---|
38 | cs.setId(38038262);
|
---|
39 | String xml = api.toXml(cs);
|
---|
40 | assertEquals("<?xml version='1.0' encoding='UTF-8'?>\n"+
|
---|
41 | "<osm version='0.6' generator='JOSM'>\n"+
|
---|
42 | " <changeset id='38038262' user='<anonymous>' uid='-1' open='false'>\n"+
|
---|
43 | " </changeset>\n"+
|
---|
44 | "</osm>\n", xml.replace("\r", ""));
|
---|
45 | Changeset cs2 = OsmChangesetParser.parse(
|
---|
46 | new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)),
|
---|
47 | NullProgressMonitor.INSTANCE).iterator().next();
|
---|
48 | assertEquals(User.getAnonymous(), cs2.getUser());
|
---|
49 | }
|
---|
50 | }
|
---|