@Test public void testSetName() throws URISyntaxException, IOException { SystemServiceImpl system = new SystemServiceImpl(); BundleContext bundleContext = EasyMock.createMock(BundleContext.class); URL propUrl = this.getClass().getClassLoader().getResource("etc/system.properties"); File propfile = new File(propUrl.toURI()); EasyMock.expect(bundleContext.getProperty("karaf.etc")).andReturn(propfile.getParentFile().getParent() + "/etc"); EasyMock.replay(bundleContext); system.setBundleContext(bundleContext); system.setName(NEW_NAME); EasyMock.verify(bundleContext); Properties props = new Properties(propfile); String nameAfter = props.getProperty("karaf.name"); Assert.assertEquals(NEW_NAME, nameAfter); }
@Override public void setName(String name) { try { String karafEtc = bundleContext.getProperty("karaf.etc"); File etcDir = new File(karafEtc); File syspropsFile = new File(etcDir, "system.properties"); FileInputStream fis = new FileInputStream(syspropsFile); Properties props = new Properties(); props.load(fis); fis.close(); props.setProperty("karaf.name", name); FileOutputStream fos = new FileOutputStream(syspropsFile); props.store(fos, ""); fos.close(); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }
SystemServiceImpl implements SystemService { @Override public void setName(String name) { try { String karafEtc = bundleContext.getProperty("karaf.etc"); File etcDir = new File(karafEtc); File syspropsFile = new File(etcDir, "system.properties"); FileInputStream fis = new FileInputStream(syspropsFile); Properties props = new Properties(); props.load(fis); fis.close(); props.setProperty("karaf.name", name); FileOutputStream fos = new FileOutputStream(syspropsFile); props.store(fos, ""); fos.close(); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } } }
SystemServiceImpl implements SystemService { @Override public void setName(String name) { try { String karafEtc = bundleContext.getProperty("karaf.etc"); File etcDir = new File(karafEtc); File syspropsFile = new File(etcDir, "system.properties"); FileInputStream fis = new FileInputStream(syspropsFile); Properties props = new Properties(); props.load(fis); fis.close(); props.setProperty("karaf.name", name); FileOutputStream fos = new FileOutputStream(syspropsFile); props.store(fos, ""); fos.close(); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }  }
SystemServiceImpl implements SystemService { @Override public void setName(String name) { try { String karafEtc = bundleContext.getProperty("karaf.etc"); File etcDir = new File(karafEtc); File syspropsFile = new File(etcDir, "system.properties"); FileInputStream fis = new FileInputStream(syspropsFile); Properties props = new Properties(); props.load(fis); fis.close(); props.setProperty("karaf.name", name); FileOutputStream fos = new FileOutputStream(syspropsFile); props.store(fos, ""); fos.close(); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }  void setBundleContext(BundleContext bundleContext); BundleContext getBundleContext(); void halt(); void halt(String time); void reboot(); void reboot(String time, Swipe cleanup); void setStartLevel(int startLevel); int getStartLevel(); @Override String getVersion(); @Override String getName(); @Override void setName(String name); FrameworkType getFramework(); void setFramework(FrameworkType framework); void setFrameworkDebug(boolean debug); @Override String setSystemProperty(String key, String value, boolean persist); }
SystemServiceImpl implements SystemService { @Override public void setName(String name) { try { String karafEtc = bundleContext.getProperty("karaf.etc"); File etcDir = new File(karafEtc); File syspropsFile = new File(etcDir, "system.properties"); FileInputStream fis = new FileInputStream(syspropsFile); Properties props = new Properties(); props.load(fis); fis.close(); props.setProperty("karaf.name", name); FileOutputStream fos = new FileOutputStream(syspropsFile); props.store(fos, ""); fos.close(); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }  void setBundleContext(BundleContext bundleContext); BundleContext getBundleContext(); void halt(); void halt(String time); void reboot(); void reboot(String time, Swipe cleanup); void setStartLevel(int startLevel); int getStartLevel(); @Override String getVersion(); @Override String getName(); @Override void setName(String name); FrameworkType getFramework(); void setFramework(FrameworkType framework); void setFrameworkDebug(boolean debug); @Override String setSystemProperty(String key, String value, boolean persist);  }