Changeset 9524 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/CustomConfigurator.java
r9498 r9524 97 97 } 98 98 99 /** 100 * Resets the log. 101 */ 102 public static void resetLog() { 103 summary = new StringBuilder(); 104 } 105 106 /** 107 * Read configuration script from XML file, modifying main preferences 108 * @param dir - directory 109 * @param fileName - XML file name 110 */ 99 111 public static void readXML(String dir, String fileName) { 100 112 readXML(new File(dir, fileName)); … … 474 486 try { 475 487 this.mainPrefs = mainPrefs; 476 summary = new StringBuilder();477 engine = new ScriptEngineManager().getEngineByName(" rhino");488 resetLog(); 489 engine = new ScriptEngineManager().getEngineByName("JavaScript"); 478 490 engine.eval("API={}; API.pref={}; API.fragments={};"); 479 491 … … 493 505 } catch (Exception ex) { 494 506 log("Error: initializing script engine: "+ex.getMessage()); 507 Main.error(ex); 495 508 } 496 509 } -
trunk/test/unit/org/openstreetmap/josm/data/CustomConfiguratorTest.java
r9498 r9524 3 3 4 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertFalse; 5 6 import static org.junit.Assert.assertTrue; 6 7 … … 10 11 import java.nio.file.Files; 11 12 import java.util.Arrays; 13 import java.util.Collections; 12 14 15 import org.junit.Before; 13 16 import org.junit.BeforeClass; 14 17 import org.junit.Test; 15 18 import org.openstreetmap.josm.JOSMFixture; 16 19 import org.openstreetmap.josm.Main; 20 import org.openstreetmap.josm.TestUtils; 17 21 import org.openstreetmap.josm.tools.Utils; 18 22 … … 26 30 */ 27 31 @BeforeClass 28 public static void setUp () {32 public static void setUpBeforeClass() { 29 33 JOSMFixture.createUnitTestFixture().init(); 34 } 35 36 /** 37 * Setup test. 38 */ 39 @Before 40 public void setUp() { 41 CustomConfigurator.resetLog(); 30 42 } 31 43 … … 79 91 Utils.deleteFile(tmp); 80 92 } 93 94 /** 95 * Test method for {@link CustomConfigurator#readXML}. 96 * @throws IOException if any I/O error occurs 97 */ 98 @Test 99 public void testReadXML() throws IOException { 100 // Test 1 - read(dir, file) + append 101 Main.pref.putCollection("test", Collections.<String>emptyList()); 102 assertTrue(Main.pref.getCollection("test").isEmpty()); 103 CustomConfigurator.readXML(TestUtils.getTestDataRoot() + "customconfigurator", "append.xml"); 104 String log = CustomConfigurator.getLog(); 105 System.out.println(log); 106 assertFalse(log.contains("Error")); 107 assertFalse(Main.pref.getCollection("test").isEmpty()); 108 109 // Test 1 - read(file, pref) + replace 110 Preferences pref = new Preferences(); 111 pref.putCollection("lorem_ipsum", Arrays.asList("only 1 string")); 112 assertEquals(1, pref.getCollection("lorem_ipsum").size()); 113 CustomConfigurator.readXML(new File(TestUtils.getTestDataRoot() + "customconfigurator", "replace.xml"), pref); 114 log = CustomConfigurator.getLog(); 115 System.out.println(log); 116 assertFalse(log.contains("Error")); 117 assertEquals(9, pref.getCollection("lorem_ipsum").size()); 118 } 81 119 }
Note:
See TracChangeset
for help on using the changeset viewer.