source: josm/trunk/test/unit/org/openstreetmap/josm/tools/BugReportExceptionHandlerTest.java@ 7134

Last change on this file since 7134 was 7082, checked in by Don-vip, 10 years ago

see #8465 - replace Utils.UTF_8 by StandardCharsets.UTF_8, new in Java 7

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