protected void store() { try { ConfigurationManager.getInstance().store(this); } catch (Exception e) { logger.error("There was an error storing the new configuration for: "+this.getName(),e); } }
public void actionPerformed(ActionEvent arg0) { String menus = menuItems.getText(); try { workbenchConfiguration.setMaxMenuItems(Integer.valueOf(menus)); } catch (IllegalArgumentException e) { String message = "Invalid menu items number " + menus + ":\n" + e.getLocalizedMessage(); JOptionPane.showMessageDialog(panel, message, "Invalid menu items", JOptionPane.WARNING_MESSAGE); return; } workbenchConfiguration.setCaptureConsole(captureConsole.isSelected()); workbenchConfiguration.setWarnInternalErrors(warnInternal.isSelected()); workbenchConfiguration.setDotLocation(dotLocation.getText()); try { configurationManager.store(workbenchConfiguration); String message = "For the new configuration to be fully applied, it is advised to restart Taverna."; JOptionPane.showMessageDialog(panel, message, "Restart adviced", JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { logger.error("Error storing updated configuration", e); } } });
@Test public void testStore() throws Exception { Configurable conf = DummyConfigurable.getInstance(); ConfigurationManager manager = ConfigurationManager.getInstance(); manager.store(conf); assertTrue(configFile.exists()); }
@Test public void saveColoursForDummyColourable() { String dummy = ""; ColourManager manager=ColourManager.getInstance(); manager.setProperty(dummy.getClass().getCanonicalName(), "#000000"); ConfigurationManager instance = ConfigurationManager.getInstance(); instance.setBaseConfigLocation(new File(System.getProperty("java.io.tmpdir")+File.separatorChar+"scratch")); try { instance.store(manager); } catch (Exception e1) { e1.printStackTrace(); } try { instance.populate(manager); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Test public void testRemoveNotDefaultValue() throws Exception { Configurable conf = DummyConfigurable.getInstance(); ConfigurationManager manager = ConfigurationManager.getInstance(); conf.setProperty("hhh", "iii"); manager.store(conf); Properties props = new Properties(); props.load(new FileInputStream(configFile)); assertEquals("The stored file should contain the new entry","iii",props.get("hhh")); conf.deleteProperty("hhh"); manager.store(conf); manager.populate(conf); assertNull("The removed value should no longer exist",conf.getProperty("hhh")); props.clear(); props.load(new FileInputStream(configFile)); assertNull("The stored file should no longer contain the deleted entry",props.get("hhh")); }
@Test public void testRemoveNotDefaultValue() throws Exception { Configurable conf = DummyConfigurable.getInstance(); ConfigurationManager manager = ConfigurationManager.getInstance(); conf.setProperty("hhh", "iii"); manager.store(conf); Properties props = new Properties(); props.load(new FileInputStream(configFile)); assertEquals("The stored file should contain the new entry","iii",props.get("hhh")); conf.deleteProperty("hhh"); manager.store(conf); manager.populate(conf); assertNull("The removed value should no longer exist",conf.getProperty("hhh")); props.clear(); props.load(new FileInputStream(configFile)); assertNull("The stored file should no longer contain the deleted entry",props.get("hhh")); }
@Test public void testStore() throws Exception { Configurable conf = DummyConfigurable.getInstance(); ConfigurationManager manager = ConfigurationManager.getInstance(); manager.store(conf); assertTrue(configFile.exists()); }
@Test public void saveColoursForDummyColourable() { String dummy = ""; ColourManager manager=ColourManager.getInstance(); manager.setProperty(dummy.getClass().getCanonicalName(), "#000000"); ConfigurationManager instance = ConfigurationManager.getInstance(); instance.setBaseConfigLocation(new File(System.getProperty("java.io.tmpdir")+File.separatorChar+"scratch")); try { instance.store(manager); } catch (Exception e1) { e1.printStackTrace(); } try { instance.populate(manager); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Test public void saveAsWrongArrayType() throws Exception { String dummy = ""; ColourManager manager = ColourManager.getInstance(); manager.setProperty(dummy.getClass().getCanonicalName(), "#ffffff"); ConfigurationManager instance = ConfigurationManager.getInstance(); File baseLoc = File.createTempFile("test", "scratch"); baseLoc.delete(); assertTrue("Could not make directory " + baseLoc, baseLoc.mkdir()); instance.setBaseConfigLocation(baseLoc); instance.store(manager); instance.populate(manager); manager.getPreferredColour(dummy); }
@Test public void saveAsWrongArrayType() throws Exception { String dummy = ""; ColourManager manager = ColourManager.getInstance(); manager.setProperty(dummy.getClass().getCanonicalName(), "#ffffff"); ConfigurationManager instance = ConfigurationManager.getInstance(); File baseLoc = File.createTempFile("test", "scratch"); baseLoc.delete(); assertTrue("Could not make directory " + baseLoc, baseLoc.mkdir()); instance.setBaseConfigLocation(baseLoc); instance.store(manager); instance.populate(manager); manager.getPreferredColour(dummy); }
@Test public void testDefaultValues() throws Exception { Configurable conf = DummyConfigurable.getInstance(); ConfigurationManager manager = ConfigurationManager.getInstance(); assertEquals("name should equal john","john",conf.getProperty("name")); manager.store(conf); Properties props = new Properties(); props.load(new FileInputStream(configFile)); assertFalse("stored properties should not contain the default value",props.containsKey("name")); manager.populate(conf); assertEquals("default property name should still exist after re-populating","john",conf.getProperty("name")); }
@Test public void testDefaultValues() throws Exception { Configurable conf = DummyConfigurable.getInstance(); ConfigurationManager manager = ConfigurationManager.getInstance(); assertEquals("name should equal john","john",conf.getProperty("name")); manager.store(conf); Properties props = new Properties(); props.load(new FileInputStream(configFile)); assertFalse("stored properties should not contain the default value",props.containsKey("name")); manager.populate(conf); assertEquals("default property name should still exist after re-populating","john",conf.getProperty("name")); }
@Test public void testList() throws Exception { List<String> list = new ArrayList<String>(); list.add("fred"); list.add("bloggs"); conf.setPropertyStringList("list", list); ConfigurationManager.getInstance().store(conf); ConfigurationManager.getInstance().populate(conf); assertTrue("should be an ArrayList",conf.getPropertyStringList("list") instanceof List); List<String> l = conf.getPropertyStringList("list"); assertEquals("There should be 1 element",2,l.size()); assertEquals("Its value should be fred","fred",l.get(0)); assertEquals("Its value should be bloggs","bloggs",l.get(1)); }
@Test public void testNewValues() throws Exception { Configurable conf = DummyConfigurable.getInstance(); conf.setProperty("country", "france"); ConfigurationManager manager = ConfigurationManager.getInstance(); assertEquals("country should equal france","france",conf.getProperty("country")); manager.store(conf); Properties props = new Properties(); props.load(new FileInputStream(configFile)); assertTrue("stored properties should contain the default value",props.containsKey("country")); assertEquals("stored property country should equal france","france",props.getProperty("country")); manager.populate(conf); assertEquals("default property name should still exist after re-populating","france",conf.getProperty("country")); }
@SuppressWarnings("unchecked") @Test public void testSingleItem() throws Exception { List<String> list = new ArrayList<String>(); list.add("fred"); conf.setPropertyStringList("single", list); ConfigurationManager.getInstance().store(conf); ConfigurationManager.getInstance().populate(conf); assertTrue("should be an ArrayList",conf.getPropertyStringList("single") instanceof List); List<String> l = conf.getPropertyStringList("single"); assertEquals("There should be 1 element",1,l.size()); assertEquals("Its value should be fred","fred",l.get(0)); }
@Test public void testNewValues() throws Exception { Configurable conf = DummyConfigurable.getInstance(); conf.setProperty("country", "france"); ConfigurationManager manager = ConfigurationManager.getInstance(); assertEquals("country should equal france","france",conf.getProperty("country")); manager.store(conf); Properties props = new Properties(); props.load(new FileInputStream(configFile)); assertTrue("stored properties should contain the default value",props.containsKey("country")); assertEquals("stored property country should equal france","france",props.getProperty("country")); manager.populate(conf); assertEquals("default property name should still exist after re-populating","france",conf.getProperty("country")); }
@Test public void testDeleteDefaultProperty() throws Exception { AbstractConfigurable conf = DummyConfigurable.getInstance(); ConfigurationManager manager = ConfigurationManager.getInstance(); assertEquals("name should equal john","john",conf.getProperty("name")); conf.deleteProperty("name"); manager.store(conf); manager.populate(conf); assertNull("value for name should be null",conf.getProperty("name")); Properties props = new Properties(); props.load(new FileInputStream(configFile)); assertTrue("Key name should be in stored props because its a deleted default value",props.containsKey("name")); assertEquals("name should have the special value to indicate its been deleted",ConfigurationManager.DELETED_VALUE_CODE,props.getProperty("name")); }
@Test public void testDeleteDefaultProperty() throws Exception { AbstractConfigurable conf = DummyConfigurable.getInstance(); ConfigurationManager manager = ConfigurationManager.getInstance(); assertEquals("name should equal john","john",conf.getProperty("name")); conf.deleteProperty("name"); manager.store(conf); manager.populate(conf); assertNull("value for name should be null",conf.getProperty("name")); Properties props = new Properties(); props.load(new FileInputStream(configFile)); assertTrue("Key name should be in stored props because its a deleted default value",props.containsKey("name")); assertEquals("name should have the special value to indicate its been deleted",ConfigurationManager.DELETED_VALUE_CODE,props.getProperty("name")); }
@SuppressWarnings("unchecked") @Test public void testEmptyList() throws Exception { conf.setPropertyStringList("list", new ArrayList<String>()); assertTrue("Result was not a list but was:"+conf.getProperty("list"),conf.getPropertyStringList("list") instanceof List); ConfigurationManager.getInstance().store(conf); ConfigurationManager.getInstance().populate(conf); assertTrue("Result was not a list but was:"+conf.getPropertyStringList("list"),conf.getPropertyStringList("list") instanceof List); List<String> list = conf.getPropertyStringList("list"); assertEquals("There should be 0 elements",0,list.size()); }
instance.setBaseConfigLocation(new File("/Users/Ian/scratch")); try { instance.store(manager); } catch (Exception e1) { e1.printStackTrace();