source: josm/trunk/test/unit/org/openstreetmap/josm/tools/PlatformHookWindowsTest.java@ 14219

Last change on this file since 14219 was 14168, checked in by Don-vip, 6 years ago

fix #16656 - appveyor: tweak configuration and skip troublesome tests to get suite completing (patch by ris)

  • Property svn:eol-style set to native
File size: 6.3 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.assertFalse;
6import static org.junit.Assert.assertNotNull;
7import static org.junit.Assert.assertNull;
8import static org.junit.Assert.assertTrue;
9import static org.junit.Assume.assumeFalse;
10import static org.junit.Assert.fail;
11
12import java.io.File;
13import java.io.IOException;
14import java.security.KeyStore;
15import java.security.KeyStore.TrustedCertificateEntry;
16import java.security.KeyStoreException;
17import java.util.Collection;
18
19import org.junit.BeforeClass;
20import org.junit.Test;
21import org.openstreetmap.josm.JOSMFixture;
22import org.openstreetmap.josm.io.remotecontrol.RemoteControlHttpsServer;
23import org.openstreetmap.josm.io.remotecontrol.RemoteControlTest;
24import org.openstreetmap.josm.spi.preferences.Config;
25
26/**
27 * Unit tests of {@link PlatformHookWindows} class.
28 */
29public class PlatformHookWindowsTest {
30
31 static PlatformHookWindows hook;
32
33 /**
34 * Setup test.
35 */
36 @BeforeClass
37 public static void setUp() {
38 JOSMFixture.createUnitTestFixture().init();
39 hook = new PlatformHookWindows();
40 }
41
42 /**
43 * Test method for {@code PlatformHookWindows#startupHook}
44 */
45 @Test
46 public void testStartupHook() {
47 hook.startupHook((a, b, c, d) -> System.out.println("callback"));
48 }
49
50 /**
51 * Test method for {@code PlatformHookWindows#getRootKeystore}
52 * @throws Exception if an error occurs
53 */
54 @Test
55 public void testGetRootKeystore() throws Exception {
56 if (PlatformManager.isPlatformWindows()) {
57 assertNotNull(PlatformHookWindows.getRootKeystore());
58 } else {
59 try {
60 PlatformHookWindows.getRootKeystore();
61 fail("Expected KeyStoreException");
62 } catch (KeyStoreException e) {
63 Logging.info(e.getMessage());
64 }
65 }
66 }
67
68 /**
69 * Test method for {@code PlatformHookWindows#removeInsecureCertificates}
70 * @throws Exception if an error occurs
71 */
72 @Test
73 public void testRemoveInsecureCertificates() throws Exception {
74 if (PlatformManager.isPlatformWindows()) {
75 PlatformHookWindows.removeInsecureCertificates();
76 } else {
77 try {
78 PlatformHookWindows.removeInsecureCertificates();
79 fail("Expected KeyStoreException");
80 } catch (KeyStoreException e) {
81 Logging.info(e.getMessage());
82 }
83 }
84 }
85
86 /**
87 * Test method for {@code PlatformHookWindows#setupHttpsCertificate}
88 * @throws Exception if an error occurs
89 */
90 @Test
91 public void testSetupHttpsCertificate() throws Exception {
92 // appveyor doesn't like us tinkering with the root keystore
93 assumeFalse(PlatformManager.isPlatformWindows() && "True".equals(System.getenv("APPVEYOR")));
94
95 RemoteControlTest.deleteKeystore();
96 KeyStore ks = RemoteControlHttpsServer.loadJosmKeystore();
97 TrustedCertificateEntry trustedCert = new KeyStore.TrustedCertificateEntry(ks.getCertificate(ks.aliases().nextElement()));
98 if (PlatformManager.isPlatformWindows()) {
99 hook.setupHttpsCertificate(RemoteControlHttpsServer.ENTRY_ALIAS, trustedCert);
100 } else {
101 try {
102 hook.setupHttpsCertificate(RemoteControlHttpsServer.ENTRY_ALIAS, trustedCert);
103 fail("Expected KeyStoreException");
104 } catch (KeyStoreException e) {
105 Logging.info(e.getMessage());
106 }
107 }
108 }
109
110 /**
111 * Test method for {@code PlatformHookWindows#afterPrefStartupHook}
112 */
113 @Test
114 public void testAfterPrefStartupHook() {
115 hook.afterPrefStartupHook();
116 }
117
118 /**
119 * Test method for {@code PlatformHookWindows#openUrl}
120 * @throws IOException if an error occurs
121 */
122 @Test
123 public void testOpenUrl() throws IOException {
124 if (PlatformManager.isPlatformWindows()) {
125 hook.openUrl(Config.getUrls().getJOSMWebsite());
126 } else {
127 try {
128 hook.openUrl(Config.getUrls().getJOSMWebsite());
129 fail("Expected IOException");
130 } catch (IOException e) {
131 Logging.info(e.getMessage());
132 }
133 }
134 }
135
136 /**
137 * Test method for {@code PlatformHookWindows#getAdditionalFonts}
138 */
139 @Test
140 public void testGetAdditionalFonts() {
141 assertFalse(hook.getAdditionalFonts().isEmpty());
142 }
143
144 /**
145 * Test method for {@code PlatformHookWindows#getDefaultCacheDirectory}
146 */
147 @Test
148 public void testGetDefaultCacheDirectory() {
149 File cache = hook.getDefaultCacheDirectory();
150 assertNotNull(cache);
151 if (PlatformManager.isPlatformWindows()) {
152 assertTrue(cache.toString().contains(":"));
153 }
154 }
155
156 /**
157 * Test method for {@code PlatformHookWindows#getDefaultPrefDirectory}
158 */
159 @Test
160 public void testGetDefaultPrefDirectory() {
161 File cache = hook.getDefaultPrefDirectory();
162 assertNotNull(cache);
163 if (PlatformManager.isPlatformWindows()) {
164 assertTrue(cache.toString().contains(":"));
165 }
166 }
167
168 /**
169 * Test method for {@code PlatformHookWindows#getDefaultStyle}
170 */
171 @Test
172 public void testGetDefaultStyle() {
173 assertEquals("com.sun.java.swing.plaf.windows.WindowsLookAndFeel", hook.getDefaultStyle());
174 }
175
176 /**
177 * Test method for {@code PlatformHookWindows#getInstalledFonts}
178 */
179 @Test
180 public void testGetInstalledFonts() {
181 Collection<String> fonts = hook.getInstalledFonts();
182 if (PlatformManager.isPlatformWindows()) {
183 assertFalse(fonts.isEmpty());
184 } else {
185 assertNull(fonts);
186 }
187 }
188
189 /**
190 * Test method for {@code PlatformHookWindows#getOSDescription}
191 */
192 @Test
193 public void testGetOSDescription() {
194 String os = hook.getOSDescription();
195 if (PlatformManager.isPlatformWindows()) {
196 assertTrue(os.contains("Windows"));
197 } else {
198 assertFalse(os.contains("Windows"));
199 }
200 }
201
202 /**
203 * Test method for {@code PlatformHookWindows#initSystemShortcuts}
204 */
205 @Test
206 public void testInitSystemShortcuts() {
207 hook.initSystemShortcuts();
208 }
209}
Note: See TracBrowser for help on using the repository browser.