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

Last change on this file since 8937 was 8509, checked in by Don-vip, 9 years ago

fix many checkstyle violations

  • Property svn:eol-style set to native
File size: 1.9 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 JOSMFixture.createUnitTestFixture().init();
31 }
32
33 /**
34 * Test method for {@link org.openstreetmap.josm.tools.BugReportExceptionHandler#getBugReportUrl(java.lang.String)}.
35 * @throws IOException if any I/O error occurs
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}
Note: See TracBrowser for help on using the repository browser.