@Test
public void testModifyEnvironment() throws Exception
{

    Set<String> removedContainers = Sets.newHashSet( TestHelper.CONTAINER_ID );
    Map<String, ContainerQuota> changedContainers = Maps.newHashMap();
    changedContainers.put( TestHelper.CONTAINER_ID, new ContainerQuota( ContainerSize.LARGE ) );
    EnvironmentModifyWorkflow environmentModifyWorkflow = mock( EnvironmentModifyWorkflow.class );
    doReturn( environmentModifyWorkflow ).when( environmentManager )
                                         .getEnvironmentModifyingWorkflow( environment, topology, trackerOperation,
                                                 removedContainers, changedContainers );
    doNothing().when( environmentManager ).registerActiveWorkflow( environment, environmentModifyWorkflow );
    assertNotNull( environmentManager
            .modifyEnvironment( TestHelper.ENV_ID, topology, removedContainers, changedContainers, false ) );
    //-----
    doReturn( true ).when( environmentModifyWorkflow ).isFailed();
    try
    {
        environmentManager
                .modifyEnvironment( TestHelper.ENV_ID, topology, removedContainers, changedContainers, false );
        fail( "Expected EnvironmentModificationException" );
    }
    catch ( EnvironmentModificationException e )
    {
    }
    //-----
    doReturn( EnvironmentStatus.UNDER_MODIFICATION ).when( environment ).getStatus();
    try
    {
        environmentManager
                .modifyEnvironment( TestHelper.ENV_ID, topology, removedContainers, changedContainers, false );
        fail( "Expected EnvironmentModificationException" );
    }
    catch ( EnvironmentModificationException e )
    {
    }
    verify( trackerOperation ).addLogFailed( anyString() );
    //-----
    doReturn( false ).when( localPeer ).isOnline();
    try
    {
        environmentManager
                .modifyEnvironment( TestHelper.ENV_ID, topology, removedContainers, changedContainers, false );
        fail( "Expected EnvironmentModificationException" );
    }
    catch ( EnvironmentModificationException e )
    {
    }
    verify( trackerOperation, times( 2 ) ).addLogFailed( anyString() );
    //-----
    doThrow( new PeerException() ).when( environment ).getPeers();
    try
    {
        environmentManager
                .modifyEnvironment( TestHelper.ENV_ID, topology, removedContainers, changedContainers, false );
        fail( "Expected EnvironmentModificationException" );
    }
    catch ( EnvironmentModificationException e )
    {
    }
    verify( trackerOperation, times( 3 ) ).addLogFailed( anyString() );
}