| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.gui;
|
|---|
| 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.util.Arrays;
|
|---|
| 9 | import java.util.Collection;
|
|---|
| 10 |
|
|---|
| 11 | import javax.swing.event.ChangeEvent;
|
|---|
| 12 | import javax.swing.event.ChangeListener;
|
|---|
| 13 |
|
|---|
| 14 | import org.junit.BeforeClass;
|
|---|
| 15 | import org.junit.Test;
|
|---|
| 16 | import org.openstreetmap.josm.JOSMFixture;
|
|---|
| 17 | import org.openstreetmap.josm.gui.SplashScreen.SplashProgressMonitor;
|
|---|
| 18 | import org.openstreetmap.josm.plugins.PluginHandler;
|
|---|
| 19 | import org.openstreetmap.josm.plugins.PluginHandlerTestIT;
|
|---|
| 20 | import org.openstreetmap.josm.plugins.PluginInformation;
|
|---|
| 21 | import org.openstreetmap.josm.plugins.PluginListParseException;
|
|---|
| 22 | import org.openstreetmap.josm.plugins.PluginListParser;
|
|---|
| 23 |
|
|---|
| 24 | /**
|
|---|
| 25 | * Unit tests of {@link MainApplication} class.
|
|---|
| 26 | */
|
|---|
| 27 | public class MainApplicationTest {
|
|---|
| 28 |
|
|---|
| 29 | /**
|
|---|
| 30 | * Setup test.
|
|---|
| 31 | */
|
|---|
| 32 | @BeforeClass
|
|---|
| 33 | public static void setUp() {
|
|---|
| 34 | JOSMFixture.createUnitTestFixture().init(true);
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | /**
|
|---|
| 38 | * Test of {@link MainApplication#updateAndLoadEarlyPlugins} and {@link MainApplication#loadLatePlugins} methods.
|
|---|
| 39 | * @throws PluginListParseException if an error occurs
|
|---|
| 40 | */
|
|---|
| 41 | @Test
|
|---|
| 42 | public void testUpdateAndLoadPlugins() throws PluginListParseException {
|
|---|
| 43 | final String old = System.getProperty("josm.plugins");
|
|---|
| 44 | try {
|
|---|
| 45 | System.setProperty("josm.plugins", "buildings_tools,plastic_laf");
|
|---|
| 46 | SplashProgressMonitor monitor = new SplashProgressMonitor("foo", new ChangeListener() {
|
|---|
| 47 | @Override
|
|---|
| 48 | public void stateChanged(ChangeEvent e) {
|
|---|
| 49 | // Do nothing
|
|---|
| 50 | }
|
|---|
| 51 | });
|
|---|
| 52 | Collection<PluginInformation> plugins = MainApplication.updateAndLoadEarlyPlugins(null, monitor);
|
|---|
| 53 | if (plugins.isEmpty()) {
|
|---|
| 54 | PluginHandlerTestIT.downloadPlugins(Arrays.asList(
|
|---|
| 55 | newPluginInformation("buildings_tools"),
|
|---|
| 56 | newPluginInformation("plastic_laf")));
|
|---|
| 57 | plugins = MainApplication.updateAndLoadEarlyPlugins(null, monitor);
|
|---|
| 58 | }
|
|---|
| 59 | assertEquals(2, plugins.size());
|
|---|
| 60 | assertNotNull(PluginHandler.getPlugin("plastic_laf"));
|
|---|
| 61 | assertNull(PluginHandler.getPlugin("buildings_tools"));
|
|---|
| 62 | MainApplication.loadLatePlugins(null, monitor, plugins);
|
|---|
| 63 | assertNotNull(PluginHandler.getPlugin("buildings_tools"));
|
|---|
| 64 | } finally {
|
|---|
| 65 | if (old != null) {
|
|---|
| 66 | System.setProperty("josm.plugins", old);
|
|---|
| 67 | } else {
|
|---|
| 68 | System.clearProperty("josm.plugins");
|
|---|
| 69 | }
|
|---|
| 70 | }
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | private static PluginInformation newPluginInformation(String plugin) throws PluginListParseException {
|
|---|
| 74 | //return new PluginInformation(new File(TestUtils.getTestDataRoot()+File.separator+"plugin"+File.separator+plugin+".jar"));
|
|---|
| 75 | return PluginListParser.createInfo(plugin+".jar", "https://svn.openstreetmap.org/applications/editors/josm/dist/"+plugin+".jar",
|
|---|
| 76 | "");
|
|---|
| 77 | }
|
|---|
| 78 | }
|
|---|