1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.oauth;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertNotNull;
|
---|
6 | import static org.junit.Assert.assertNull;
|
---|
7 |
|
---|
8 | import java.io.IOException;
|
---|
9 | import java.net.MalformedURLException;
|
---|
10 | import java.net.URL;
|
---|
11 |
|
---|
12 | import org.junit.BeforeClass;
|
---|
13 | import org.junit.Test;
|
---|
14 | import org.openstreetmap.josm.JOSMFixture;
|
---|
15 | import org.openstreetmap.josm.data.oauth.SignpostAdapters.HttpRequest;
|
---|
16 | import org.openstreetmap.josm.data.oauth.SignpostAdapters.HttpResponse;
|
---|
17 | import org.openstreetmap.josm.data.oauth.SignpostAdapters.OAuthConsumer;
|
---|
18 | import org.openstreetmap.josm.tools.HttpClient;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Unit tests for class {@link SignpostAdapters}.
|
---|
22 | */
|
---|
23 | public class SignpostAdaptersTest {
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Setup test.
|
---|
27 | */
|
---|
28 | @BeforeClass
|
---|
29 | public static void setUpBeforeClass() {
|
---|
30 | JOSMFixture.createUnitTestFixture().init();
|
---|
31 | }
|
---|
32 |
|
---|
33 | private static HttpClient newClient() throws MalformedURLException {
|
---|
34 | return HttpClient.create(new URL("https://www.openstreetmap.org"));
|
---|
35 | }
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Unit test of method {@link SignpostAdapters.OAuthConsumer#wrap}.
|
---|
39 | * @throws MalformedURLException never
|
---|
40 | */
|
---|
41 | @Test
|
---|
42 | public void testOAuthConsumerWrap() throws MalformedURLException {
|
---|
43 | assertNotNull(new OAuthConsumer("", "").wrap(newClient()));
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Unit test of method {@link SignpostAdapters.HttpRequest#getMessagePayload}.
|
---|
48 | * @throws IOException never
|
---|
49 | */
|
---|
50 | @Test
|
---|
51 | public void testHttpRequestGetMessagePayload() throws IOException {
|
---|
52 | assertNull(new HttpRequest(newClient()).getMessagePayload());
|
---|
53 | }
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * Unit test of method {@link SignpostAdapters.HttpRequest#setRequestUrl}.
|
---|
57 | * @throws IOException never
|
---|
58 | */
|
---|
59 | @Test(expected = IllegalStateException.class)
|
---|
60 | public void testHttpRequestSetRequestUrl() throws IOException {
|
---|
61 | new HttpRequest(newClient()).setRequestUrl(null);
|
---|
62 | }
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Unit test of method {@link SignpostAdapters.HttpRequest#getAllHeaders}.
|
---|
66 | * @throws IOException never
|
---|
67 | */
|
---|
68 | @Test(expected = IllegalStateException.class)
|
---|
69 | public void testHttpRequestGetAllHeaders() throws IOException {
|
---|
70 | new HttpRequest(newClient()).getAllHeaders();
|
---|
71 | }
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * Unit test of method {@link SignpostAdapters.HttpRequest#unwrap}.
|
---|
75 | * @throws IOException never
|
---|
76 | */
|
---|
77 | @Test(expected = IllegalStateException.class)
|
---|
78 | public void testHttpRequestUnwrap() throws IOException {
|
---|
79 | new HttpRequest(newClient()).unwrap();
|
---|
80 | }
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Unit test of method {@link SignpostAdapters.HttpResponse#getReasonPhrase()}.
|
---|
84 | * @throws Exception never
|
---|
85 | */
|
---|
86 | @Test
|
---|
87 | public void testHttpResponseGetReasonPhrase() throws Exception {
|
---|
88 | assertEquals("OK", new HttpResponse(new HttpRequest(newClient()).request.connect()).getReasonPhrase());
|
---|
89 | }
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * Unit test of method {@link SignpostAdapters.HttpResponse#unwrap}.
|
---|
93 | * @throws IOException never
|
---|
94 | */
|
---|
95 | @Test(expected = IllegalStateException.class)
|
---|
96 | public void testHttpResponseUnwrap() throws IOException {
|
---|
97 | new HttpResponse(new HttpRequest(newClient()).request.connect()).unwrap();
|
---|
98 | }
|
---|
99 | }
|
---|