Changeset 35790 in osm for applications/editors/josm/plugins/http2
- Timestamp:
- 2021-07-17T14:14:21+02:00 (3 years ago)
- Location:
- applications/editors/josm/plugins/http2
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/http2
- Property svn:ignore
-
old new 2 2 build 3 3 javadoc 4 bintest
-
- Property svn:ignore
-
applications/editors/josm/plugins/http2/.classpath
r35053 r35790 2 2 <classpath> 3 3 <classpathentry kind="src" path="src"/> 4 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-11.0.3.7-hotspot"> 4 <classpathentry kind="src" output="bintest" path="test/unit"> 5 <attributes> 6 <attribute name="test" value="true"/> 7 </attributes> 8 </classpathentry> 9 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"> 5 10 <attributes> 6 11 <attribute name="module" value="true"/> -
applications/editors/josm/plugins/http2/src/org/openstreetmap/josm/plugins/http2/Http2Client.java
r35427 r35790 46 46 @Override 47 47 protected void setupConnection(ProgressMonitor progressMonitor) throws IOException { 48 request = createRequest(); 49 50 notifyConnect(progressMonitor); 51 52 if (requiresBody()) { 53 logRequestBody(); 54 } 55 } 56 57 protected HttpRequest createRequest() throws IOException { 48 58 HttpRequest.Builder requestBuilder; 49 59 try { … … 77 87 } 78 88 } 79 request = requestBuilder.build(); 80 81 notifyConnect(progressMonitor); 82 83 if (requiresBody()) { 84 logRequestBody(); 85 } 89 return requestBuilder.build(); 86 90 } 87 91 -
applications/editors/josm/plugins/http2/test/unit/org/openstreetmap/josm/plugins/http2/Http2ClientTest.java
r35427 r35790 3 3 4 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertThrows; 6 import static org.junit.jupiter.api.Assertions.assertTrue; 5 7 6 import org.junit.Test; 8 import java.io.IOException; 9 import java.net.URI; 10 import java.net.URL; 11 import java.net.http.HttpRequest; 12 import java.time.Duration; 13 import java.util.List; 14 import java.util.Map; 15 import java.util.Optional; 16 17 import org.junit.jupiter.api.Test; 7 18 import org.openstreetmap.josm.plugins.http2.Http2Client.Http2Response; 19 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 8 20 9 21 /** 10 22 * Unit test of {@link Http2Client} 11 23 */ 12 public class Http2ClientTest { 24 @BasicPreferences 25 class Http2ClientTest { 13 26 14 27 /** … … 16 29 */ 17 30 @Test 18 publicvoid testParseDate() {31 void testParseDate() { 19 32 assertEquals(786297600000L, Http2Response.parseDate("Thu, 01 Dec 1994 16:00:00 GMT")); 20 33 assertEquals(783459811000L, Http2Response.parseDate("Sat, 29 Oct 1994 19:43:31 GMT")); … … 30 43 assertEquals(0L, Http2Response.parseDate("foo-bar")); 31 44 } 45 46 @Test 47 void testCreateRequest() throws Exception { 48 HttpRequest request = new Http2Client(new URL("https://foo.bar"), "GET").createRequest(); 49 assertEquals("GET", request.method()); 50 assertEquals(Duration.ofSeconds(30), request.timeout().get()); 51 assertEquals(new URI("https://foo.bar"), request.uri()); 52 assertEquals(Optional.empty(), request.version()); 53 Map<String, List<String>> headers = request.headers().map(); 54 assertEquals(2, headers.size()); 55 List<String> encodings = headers.get("Accept-Encoding"); 56 assertEquals(1, encodings.size()); 57 assertEquals("gzip, deflate", encodings.get(0)); 58 List<String> userAgents = headers.get("User-Agent"); 59 assertEquals(1, userAgents.size()); 60 assertTrue(userAgents.get(0).startsWith("JOSM/1.5 ("), userAgents.get(0)); 61 assertEquals("https://foo.bar GET", request.toString()); 62 } 63 64 @Test 65 void testCreateRequest_invalidURI() throws Exception { 66 // From https://josm.openstreetmap.de/ticket/21126 67 // URISyntaxException for URL not formatted strictly according to RFC2396 68 // See chapter "2.4.3. Excluded US-ASCII Characters" 69 assertTrue(assertThrows(IOException.class, () -> new Http2Client( 70 new URL("https://commons.wikimedia.org/w/api.php?format=xml&action=query&list=geosearch&gsnamespace=6&gslimit=500&gsprop=type|name&gsbbox=52.2804692|38.1772755|52.269721|38.2045051"), "GET") 71 .createRequest()).getCause().getMessage().startsWith("Illegal character in query at index 116:")); 72 } 32 73 }
Note:
See TracChangeset
for help on using the changeset viewer.