source: josm/trunk/test/unit/org/openstreetmap/josm/io/CertificateAmendmentTestIT.java

Last change on this file was 18893, checked in by taylor.smock, 6 months ago

Fix #16567: Upgrade to JUnit 5

JOSMTestRules and JOSMTestFixture can reset the default JOSM profile, which can
be unexpected for new contributors. This updates all tests to use JUnit 5 and
the new JUnit 5 annotations.

This also renames MapCSSStyleSourceFilterTest to MapCSSStyleSourceFilterPerformanceTest
to match the naming convention for performance tests and fixes some lint issues.

This was tested by running all tests individually and together.

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.junit.jupiter.api.Assertions.fail;
5import static org.junit.jupiter.api.Assumptions.assumeFalse;
6
7import java.io.IOException;
8import java.net.URL;
9import java.net.URLConnection;
10import java.util.ArrayList;
11import java.util.List;
12
13import javax.net.ssl.SSLHandshakeException;
14
15import org.junit.jupiter.api.BeforeAll;
16import org.junit.jupiter.api.Test;
17import org.junit.jupiter.api.Timeout;
18import org.openstreetmap.josm.TestUtils;
19import org.openstreetmap.josm.testutils.annotations.HTTPS;
20
21/**
22 * Integration tests of {@link CertificateAmendment} class.
23 */
24@HTTPS
25@Timeout(20)
26class CertificateAmendmentTestIT {
27 private static final List<String> errorsToIgnore = new ArrayList<>();
28
29 /**
30 * Setup test
31 * @throws IOException in case of I/O error
32 */
33 @BeforeAll
34 public static void beforeClass() throws IOException {
35 errorsToIgnore.addAll(TestUtils.getIgnoredErrorMessages(CertificateAmendmentTestIT.class));
36 }
37
38 /**
39 * Test a well-known certificate.
40 * @throws IOException in case of I/O error
41 */
42 @Test
43 void testDefault() throws IOException {
44 // something that is not embedded
45 connect("https://www.bing.com", true);
46 }
47
48 /**
49 * Test <a href="https://letsencrypt.org">Let's Encrypt</a>.
50 * @throws IOException in case of I/O error
51 */
52 @Test
53 void testLetsEncrypt() throws IOException {
54 // signed by letsencrypt's own ISRG root
55 connect("https://valid-isrgrootx1.letsencrypt.org", true);
56 // signed by letsencrypt's cross-sign CA
57 connect("https://letsencrypt.org", true);
58 // signed by letsencrypt's cross-sign CA, requires SNI
59 connect("https://acme-v02.api.letsencrypt.org", true);
60 }
61
62 /**
63 * Test overpass API.
64 * @throws IOException in case of I/O error
65 */
66 @Test
67 void testOverpass() throws IOException {
68 connect("https://overpass-api.de", true);
69 }
70
71 /**
72 * Test Dutch government.
73 * @throws IOException in case of I/O error
74 */
75 @Test
76 void testDutchGovernment() throws IOException {
77 connect("https://geodata.nationaalgeoregister.nl", true);
78 }
79
80 /**
81 * Test Taiwan government.
82 * @throws IOException in case of I/O error
83 */
84 @Test
85 void testTaiwanGovernment() throws IOException {
86 connect("https://grca.nat.gov.tw", true);
87 }
88
89 private static void connect(String url, boolean shouldWork) throws IOException {
90 URLConnection connection = new URL(url).openConnection();
91 try {
92 connection.connect();
93 } catch (SSLHandshakeException e) {
94 String error = "Untrusted: " + url;
95 assumeFalse(errorsToIgnore.contains(error));
96 if (shouldWork) {
97 throw new IOException(error, e);
98 } else {
99 return;
100 }
101 }
102 String error = "Expected error: " + url;
103 assumeFalse(errorsToIgnore.contains(error));
104 if (!shouldWork) {
105 fail(error);
106 }
107 }
108}
Note: See TracBrowser for help on using the repository browser.