1 package net.sf.openrocket.communication;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertTrue;
6 import static org.junit.Assert.fail;
8 import java.io.IOException;
10 import net.sf.openrocket.util.BuildProperties;
12 import org.junit.Test;
15 public class BugReportTest {
17 private HttpURLConnectionMock setup() {
18 HttpURLConnectionMock connection = new HttpURLConnectionMock();
19 Communicator.setConnectionSource(new ConnectionSourceStub(connection));
21 connection.setUseCaches(true);
25 private void check(HttpURLConnectionMock connection) {
26 assertEquals(Communicator.BUG_REPORT_URL, connection.getTrueUrl());
27 assertTrue(connection.getConnectTimeout() > 0);
28 assertEquals(BuildProperties.getVersion(), connection.getRequestProperty("X-OpenRocket-Version"));
29 assertTrue(connection.getInstanceFollowRedirects());
30 assertEquals("POST", connection.getRequestMethod());
31 assertFalse(connection.getUseCaches());
36 public void testBugReportSuccess() throws IOException {
37 HttpURLConnectionMock connection = setup();
38 connection.setResponseCode(Communicator.BUG_REPORT_RESPONSE_CODE);
45 BugReporter.sendBugReport(message);
49 String msg = connection.getOutputStreamString();
50 assertTrue(msg.indexOf("version=" + BuildProperties.getVersion()) >= 0);
51 assertTrue(msg.indexOf(Communicator.encode(message)) >= 0);
56 public void testBugReportFailure() throws IOException {
57 HttpURLConnectionMock connection = setup();
58 connection.setResponseCode(200);
66 BugReporter.sendBugReport(message);
67 fail("Exception did not occur");
68 } catch (IOException e) {