Changeset 14213 in josm for trunk/test/unit/org/openstreetmap/josm/gui/preferences
- Timestamp:
- 2018-09-01T00:06:40+02:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/preferences/plugin/PluginPreferenceHighLevelTest.java
r14153 r14213 804 804 805 805 assertEquals(1, jopsMocker.getInvocationLog().size()); 806 org.openstreetmap.josm.tools.Logging.error(jopsMocker.getInvocationLog().get(0)[0].toString());807 806 Object[] invocationLogEntry = jopsMocker.getInvocationLog().get(0); 808 807 assertEquals(JOptionPane.OK_OPTION, (int) invocationLogEntry[0]); … … 818 817 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/dummy_plugin.v31772.jar"))); 819 818 819 // the dummy_plugin jar has been installed 820 TestUtils.assertFileContentsEqual(this.referenceDummyJarNew, this.targetDummyJar); 821 // the baz_plugin jar has not 822 assertFalse(this.targetBazJar.exists()); 823 820 824 // loadPlugins(...) was called (with expected parameters) 821 825 assertTrue(loadPluginsCalled[0]); … … 827 831 assertEquals("999", Config.getPref().get("pluginmanager.lastupdate", "111")); 828 832 } 833 834 /** 835 * Tests installing a single plugin which has multiple versions advertised, with our JOSM version 836 * preventing us from using the latest version 837 * @throws Exception on failure 838 */ 839 @JOSMTestRules.OverrideAssumeRevision("Revision: 7000\n") 840 @Test 841 public void testInstallMultiVersion() throws Exception { 842 TestUtils.assumeWorkingJMockit(); 843 844 final String bazOldServePath = "/baz/old.jar"; 845 final PluginServer pluginServer = new PluginServer( 846 new PluginServer.RemotePlugin(this.referenceDummyJarNew), 847 new PluginServer.RemotePlugin(this.referenceBazJarNew, ImmutableMap.of( 848 "6800_Plugin-Url", "6;http://localhost:" + this.pluginServerRule.port() + bazOldServePath 849 )) 850 ); 851 pluginServer.applyToWireMockServer(this.pluginServerRule); 852 // need to actually serve this older jar from somewhere 853 this.pluginServerRule.stubFor( 854 WireMock.get(WireMock.urlEqualTo(bazOldServePath)).willReturn( 855 WireMock.aResponse().withStatus(200).withHeader("Content-Type", "application/java-archive").withBodyFile( 856 "plugin/baz_plugin.v6.jar" 857 ) 858 ) 859 ); 860 Config.getPref().putList("plugins", ImmutableList.of()); 861 862 final HelpAwareOptionPaneMocker haMocker = new HelpAwareOptionPaneMocker(ImmutableMap.of( 863 "<html>The following plugin has been downloaded <strong>successfully</strong>:" 864 + "<ul><li>baz_plugin (6)</li></ul>" 865 + "You have to restart JOSM for some settings to take effect.<br/><br/>" 866 + "Would you like to restart now?</html>", 867 "Cancel" 868 )); 869 final JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker(); 870 871 final PreferenceTabbedPane tabbedPane = new PreferenceTabbedPane(); 872 873 tabbedPane.buildGui(); 874 // PluginPreference is already added to PreferenceTabbedPane by default 875 tabbedPane.selectTabByPref(PluginPreference.class); 876 877 GuiHelper.runInEDTAndWait( 878 () -> ((javax.swing.JButton) TestUtils.getComponentByName(tabbedPane, "downloadListButton")).doClick() 879 ); 880 881 TestUtils.syncEDTAndWorkerThreads(); 882 883 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins"))); 884 WireMock.resetAllRequests(); 885 886 final PluginPreferencesModel model = (PluginPreferencesModel) TestUtils.getPrivateField( 887 tabbedPane.getPluginPreference(), 888 "model" 889 ); 890 891 assertTrue(model.getNewlyActivatedPlugins().isEmpty()); 892 assertTrue(model.getNewlyDeactivatedPlugins().isEmpty()); 893 assertTrue(model.getPluginsScheduledForUpdateOrDownload().isEmpty()); 894 assertEquals(model.getDisplayedPlugins(), model.getAvailablePlugins()); 895 896 assertEquals( 897 ImmutableList.of("baz_plugin", "dummy_plugin"), 898 model.getAvailablePlugins().stream().map((pi) -> pi.getName()).collect(ImmutableList.toImmutableList()) 899 ); 900 assertTrue(model.getSelectedPlugins().isEmpty()); 901 assertEquals( 902 ImmutableList.of("(null)", "(null)"), 903 model.getAvailablePlugins().stream().map( 904 (pi) -> pi.localversion == null ? "(null)" : pi.localversion 905 ).collect(ImmutableList.toImmutableList()) 906 ); 907 assertEquals( 908 ImmutableList.of("6", "31772"), 909 model.getAvailablePlugins().stream().map((pi) -> pi.version).collect(ImmutableList.toImmutableList()) 910 ); 911 912 // now we select dummy_plugin 913 model.setPluginSelected("baz_plugin", true); 914 915 // model should now reflect this 916 assertEquals( 917 ImmutableList.of("baz_plugin"), 918 model.getNewlyActivatedPlugins().stream().map( 919 pi -> pi.getName() 920 ).collect(ImmutableList.toImmutableList()) 921 ); 922 assertTrue(model.getNewlyDeactivatedPlugins().isEmpty()); 923 924 tabbedPane.savePreferences(); 925 926 TestUtils.syncEDTAndWorkerThreads(); 927 928 assertEquals(1, haMocker.getInvocationLog().size()); 929 Object[] invocationLogEntry = haMocker.getInvocationLog().get(0); 930 assertEquals(1, (int) invocationLogEntry[0]); 931 assertEquals("Restart", invocationLogEntry[2]); 932 933 assertTrue(jopsMocker.getInvocationLog().isEmpty()); 934 935 // any .jar.new files should have been deleted 936 assertFalse(targetDummyJarNew.exists()); 937 assertFalse(targetBazJarNew.exists()); 938 939 // dummy_plugin was fetched 940 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo(bazOldServePath))); 941 942 // the "old" baz_plugin jar has been installed 943 TestUtils.assertFileContentsEqual(this.referenceBazJarOld, this.targetBazJar); 944 // the dummy_plugin jar has not 945 assertFalse(this.targetDummyJar.exists()); 946 947 // pluginmanager.version has been set to the current version 948 assertEquals(7000, Config.getPref().getInt("pluginmanager.version", 111)); 949 // pluginmanager.lastupdate hasn't been updated 950 // questionably correct 951 assertEquals("999", Config.getPref().get("pluginmanager.lastupdate", "111")); 952 } 829 953 }
Note:
See TracChangeset
for help on using the changeset viewer.