ReloadConfigurationCommand implements Action { @Override public Object execute() throws Exception { if( this.reconfigurables != null ) { for( IReconfigurable reconfigurable : this.reconfigurables ) { try { this.logger.fine( "Forcing reconfiguration from a Karaf command." ); reconfigurable.reconfigure(); } catch( Exception e ) { this.logger.warning( "An error occurred while reloading the configuration. " + e.getMessage()); Utils.logException( this.logger, e ); } } } return null; }  @Override Object execute();  }
@Test public void testExecute_noReconfigurable() throws Exception { ReloadConfigurationCommand cmd = new ReloadConfigurationCommand(); Assert.assertNull( cmd.execute()); }
@Test public void testExecute_emptyReconfigurableList() throws Exception { ReloadConfigurationCommand cmd = new ReloadConfigurationCommand(); cmd.reconfigurables = new ArrayList<>( 0 ); Assert.assertNull( cmd.execute()); }
@Test public void testExecute_twoReconfigurables() throws Exception { ReloadConfigurationCommand cmd = new ReloadConfigurationCommand(); IReconfigurable r1 = Mockito.mock( IReconfigurable.class ); IReconfigurable r2 = Mockito.mock( IReconfigurable.class ); cmd.reconfigurables = Arrays.asList( r1, r2 ); Assert.assertNull( cmd.execute()); Mockito.verify( r1, Mockito.only()).reconfigure(); Mockito.verify( r2, Mockito.only()).reconfigure(); }
@Test public void testExecute_testException() throws Exception { ReloadConfigurationCommand cmd = new ReloadConfigurationCommand(); IReconfigurable r1 = Mockito.mock( IReconfigurable.class ); Mockito.doThrow( new RuntimeException( "for test" )).when( r1 ).reconfigure(); cmd.reconfigurables = Arrays.asList( r1 ); Assert.assertNull( cmd.execute()); Mockito.verify( r1, Mockito.only()).reconfigure(); }