MessagingMngrImpl implements IMessagingMngr { @Override public void sendMessageDirectly( ManagedApplication ma, Instance scopedInstance, Message message ) throws IOException { this.messagingClient.sendMessageToAgent( ma.getApplication(), scopedInstance, message ); }  void setMessagingClient( RCDm messagingClient ); @Override void sendMessageSafely( ManagedApplication ma, Instance instance, Message message ); @Override void sendMessageDirectly( ManagedApplication ma, Instance scopedInstance, Message message ); @Override void sendStoredMessages( ManagedApplication ma, Instance instance ); @Override void sendMessageToTheDm( Message message ); @Override IDmClient getMessagingClient(); @Override void checkMessagingConfiguration();  }
@Test public void testSendMessageDirectly_normal() throws Exception { TestApplication app = new TestApplication(); ManagedApplication ma = new ManagedApplication( app ); Message msg = new MsgCmdRemoveInstance( "/" ); for( InstanceStatus status : InstanceStatus.values()) { Mockito.reset( this.msgClient ); app.getMySqlVm().setStatus( status ); Mockito.verifyZeroInteractions( this.msgClient ); this.mngr.sendMessageDirectly( ma, app.getMySqlVm(), msg ); Mockito.verify( this.msgClient, Mockito.times( 1 )).sendMessageToAgent( Mockito.eq( app ), Mockito.eq( app.getMySqlVm()), Mockito.eq( msg )); } }
@Test( expected = IOException.class ) public void testSendMessageDirectly_messagingError() throws Exception { TestApplication app = new TestApplication(); ManagedApplication ma = new ManagedApplication( app ); Message msg = new MsgCmdRemoveInstance( "/" ); Mockito.doThrow( new IOException( "for test" )).when( this.msgClient ).sendMessageToAgent( Mockito.any( Application.class ), Mockito.any( Instance.class ), Mockito.any( Message.class )); Mockito.verifyZeroInteractions( this.msgClient ); this.mngr.sendMessageDirectly( ma, app.getMySqlVm(), msg ); }