@@ -0,0 +1,3039 @@
+package org.safehaus.subutai.core.metric.impl;%0A%0A%0Aimport java.io.PrintStream;%0Aimport java.util.Collections;%0Aimport java.util.UUID;%0A%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.Mock;%0Aimport org.mockito.runners.MockitoJUnitRunner;%0Aimport org.safehaus.subutai.core.messenger.api.Message;%0Aimport org.safehaus.subutai.core.messenger.api.MessageException;%0Aimport org.safehaus.subutai.core.messenger.api.Messenger;%0Aimport org.safehaus.subutai.core.metric.api.ContainerHostMetric;%0Aimport org.safehaus.subutai.core.peer.api.Peer;%0Aimport org.safehaus.subutai.core.peer.api.PeerManager;%0A%0Aimport com.google.common.collect.Sets;%0A%0Aimport static org.mockito.Matchers.any;%0Aimport static org.mockito.Matchers.anyInt;%0Aimport static org.mockito.Matchers.anyString;%0Aimport static org.mockito.Matchers.isA;%0Aimport static org.mockito.Mockito.doThrow;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.reset;%0Aimport static org.mockito.Mockito.times;%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.mockito.Mockito.when;%0A%0A%0A@RunWith( MockitoJUnitRunner.class )%0Apublic class ContainerHostMetricRequestListenerTest%0A%7B%0A%0A    private static final UUID ENVIRONMENT_ID = UUID.randomUUID();%0A    @Mock%0A    Messenger messenger;%0A    @Mock%0A    MonitorImpl monitor;%0A    @Mock%0A    PeerManager peerManager;%0A%0A    ContainerHostMetricRequestListener listener;%0A%0A%0A    @Before%0A    public void setUp() throws Exception%0A    %7B%0A        listener = new ContainerHostMetricRequestListener( monitor, messenger, peerManager );%0A    %7D%0A%0A%0A    @Test%0A    public void testOnMessage() throws Exception%0A    %7B%0A        Message message = mock( Message.class );%0A        ContainerHostMetricRequest request = mock( ContainerHostMetricRequest.class );%0A        when( request.getEnvironmentId() ).thenReturn( ENVIRONMENT_ID );%0A        when( message.getPayload( ContainerHostMetricRequest.class ) ).thenReturn( request );%0A        ContainerHostMetric metric = mock( ContainerHostMetric.class );%0A        when( monitor.getLocalContainerHostMetrics( ENVIRONMENT_ID ) ).thenReturn( Sets.newHashSet( metric ) );%0A%0A        listener.onMessage( message );%0A%0A        verify( peerManager ).getPeer( any( UUID.class ) );%0A        verify( messenger ).createMessage( isA( ContainerHostMetricResponse.class ) );%0A        verify( messenger ).sendMessage( any( Peer.class ), any( Message.class ), anyString(), anyInt() );%0A%0A%0A        MessageException exception = mock( MessageException.class );%0A        doThrow( exception ).when( messenger )%0A                            .sendMessage( any( Peer.class ), any( Message.class ), anyString(), anyInt() );%0A%0A        listener.onMessage( message );%0A%0A        verify( exception ).printStackTrace( any( PrintStream.class ) );%0A%0A        when( monitor.getLocalContainerHostMetrics( ENVIRONMENT_ID ) )%0A                .thenReturn( Collections.%3CContainerHostMetric%3EemptySet() );%0A%0A        reset( request );%0A%0A        listener.onMessage( message );%0A%0A        verify( request, times( 2 ) ).getEnvironmentId();%0A    %7D%0A%7D%0A

monitor module in progress