1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import org.junit.jupiter.api.Test;
|
---|
5 | import org.openstreetmap.josm.data.osm.UserInfo;
|
---|
6 | import org.openstreetmap.josm.tools.XmlUtils;
|
---|
7 | import org.w3c.dom.Document;
|
---|
8 |
|
---|
9 | import java.io.ByteArrayInputStream;
|
---|
10 | import java.nio.charset.StandardCharsets;
|
---|
11 | import java.time.Instant;
|
---|
12 |
|
---|
13 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Unit test of {@link OsmServerUserInfoReader}
|
---|
17 | */
|
---|
18 | class OsmServerUserInfoReaderTest {
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Unit test of {@link OsmServerUserInfoReader#buildFromXML}
|
---|
22 | */
|
---|
23 | @Test
|
---|
24 | void testBuildFromXML() throws Exception {
|
---|
25 | // from https://wiki.openstreetmap.org/wiki/API_v0.6#Details_of_the_logged-in_user
|
---|
26 | String xml = "<osm version=\"0.6\" generator=\"OpenStreetMap server\">\n" +
|
---|
27 | "\t<user display_name=\"Max Muster\" account_created=\"2006-07-21T19:28:26Z\" id=\"1234\">\n" +
|
---|
28 | "\t\t<contributor-terms agreed=\"true\" pd=\"true\"/>\n" +
|
---|
29 | "\t\t<img href=\"https://www.openstreetmap.org/attachments/users/images/000/000/1234/original/someLongURLOrOther.JPG\"/>\n" +
|
---|
30 | "\t\t<roles></roles>\n" +
|
---|
31 | "\t\t<changesets count=\"4182\"/>\n" +
|
---|
32 | "\t\t<traces count=\"513\"/>\n" +
|
---|
33 | "\t\t<blocks>\n" +
|
---|
34 | "\t\t\t<received count=\"0\" active=\"0\"/>\n" +
|
---|
35 | "\t\t</blocks>\n" +
|
---|
36 | "\t\t<home lat=\"49.4733718952806\" lon=\"8.89285988577866\" zoom=\"3\"/>\n" +
|
---|
37 | "\t\t<description>The description of your profile</description>\n" +
|
---|
38 | "\t\t<languages>\n" +
|
---|
39 | "\t\t\t<lang>de-DE</lang>\n" +
|
---|
40 | "\t\t\t<lang>de</lang>\n" +
|
---|
41 | "\t\t\t<lang>en-US</lang>\n" +
|
---|
42 | "\t\t\t<lang>en</lang>\n" +
|
---|
43 | "\t\t</languages>\n" +
|
---|
44 | "\t\t<messages>\n" +
|
---|
45 | "\t\t\t<received count=\"1\" unread=\"0\"/>\n" +
|
---|
46 | "\t\t\t<sent count=\"0\"/>\n" +
|
---|
47 | "\t\t</messages>\n" +
|
---|
48 | "\t</user>\n" +
|
---|
49 | "</osm>";
|
---|
50 | Document document = XmlUtils.parseSafeDOM(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
|
---|
51 | UserInfo userInfo = OsmServerUserInfoReader.buildFromXML(document);
|
---|
52 | assertEquals("Max Muster", userInfo.getDisplayName());
|
---|
53 | assertEquals(1234, userInfo.getId());
|
---|
54 | assertEquals(Instant.parse("2006-07-21T19:28:26Z"), userInfo.getAccountCreated());
|
---|
55 | }
|
---|
56 | }
|
---|