[7937] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.tools;
|
---|
| 3 |
|
---|
| 4 | import static org.junit.Assert.assertEquals;
|
---|
| 5 | import static org.junit.Assert.assertTrue;
|
---|
| 6 |
|
---|
| 7 | import java.io.ByteArrayInputStream;
|
---|
| 8 | import java.io.IOException;
|
---|
| 9 | import java.nio.charset.StandardCharsets;
|
---|
| 10 | import java.util.zip.GZIPInputStream;
|
---|
| 11 |
|
---|
| 12 | import javax.xml.bind.DatatypeConverter;
|
---|
| 13 |
|
---|
| 14 | import org.junit.Before;
|
---|
| 15 | import org.junit.Test;
|
---|
| 16 | import org.openstreetmap.josm.JOSMFixture;
|
---|
| 17 | import org.openstreetmap.josm.Main;
|
---|
| 18 | import org.openstreetmap.josm.actions.ShowStatusReportAction;
|
---|
| 19 |
|
---|
| 20 | /**
|
---|
| 21 | * Bug report unit tests.
|
---|
| 22 | */
|
---|
| 23 | public class BugReportExceptionHandlerTest {
|
---|
| 24 |
|
---|
| 25 | /**
|
---|
| 26 | * Setup tests.
|
---|
| 27 | */
|
---|
| 28 | @Before
|
---|
| 29 | public void setUp() {
|
---|
| 30 | JOSMFixture.createUnitTestFixture().init();
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | /**
|
---|
| 34 | * Test method for {@link org.openstreetmap.josm.tools.BugReportExceptionHandler#getBugReportUrl(java.lang.String)}.
|
---|
[8509] | 35 | * @throws IOException if any I/O error occurs
|
---|
[7937] | 36 | */
|
---|
| 37 | @Test
|
---|
| 38 | public void testGetBugReportUrl() throws IOException {
|
---|
| 39 | String report = ShowStatusReportAction.getReportHeader();
|
---|
| 40 | String url = BugReportExceptionHandler.getBugReportUrl(report).toExternalForm();
|
---|
| 41 | String prefix = Main.getJOSMWebsite()+"/josmticket?gdata=";
|
---|
| 42 | assertTrue(url.startsWith(prefix));
|
---|
| 43 |
|
---|
| 44 | String gdata = url.substring(prefix.length());
|
---|
| 45 | // JAXB only provides support for "base64" decoding while we encode url in "base64url", so switch encoding, only for test purpose
|
---|
| 46 | byte[] data = DatatypeConverter.parseBase64Binary(gdata.replace('-', '+').replace('_', '/'));
|
---|
| 47 | byte[] buff = new byte[8192];
|
---|
| 48 | try (GZIPInputStream is = new GZIPInputStream(new ByteArrayInputStream(data))) {
|
---|
| 49 | StringBuilder sb = new StringBuilder();
|
---|
| 50 | for (int n = is.read(buff); n > 0; n = is.read(buff)) {
|
---|
| 51 | sb.append(new String(buff, 0, n, StandardCharsets.UTF_8));
|
---|
| 52 | }
|
---|
| 53 | assertEquals(report, sb.toString());
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 | }
|
---|