@Test
public void testCreateEnvironment() throws Exception
{

    doReturn( environment ).when( environmentManager ).createEmptyEnvironment( topology );
    EnvironmentCreationWorkflow environmentCreationWorkflow = mock( EnvironmentCreationWorkflow.class );
    doReturn( environmentCreationWorkflow ).when( environmentManager )
                                           .getEnvironmentCreationWorkflow( environment, topology,
                                                   TestHelper.SSH_KEY, trackerOperation );
    environmentManager.createEnvironment( topology, false, trackerOperation );
    verify( environmentCreationWorkflow ).join();
    //--------------------
    environmentManager.removeActiveWorkflow( TestHelper.ENV_ID );
    doReturn( true ).when( environmentCreationWorkflow ).isFailed();
    try
    {
        environmentManager.createEnvironment( topology, false, trackerOperation );
        fail( "Expected EnvironmentCreationException" );
    }
    catch ( EnvironmentCreationException e )
    {
    }
    //--------------------
    doReturn( false ).when( localPeer ).isOnline();
    try
    {
        environmentManager.createEnvironment( topology, false, trackerOperation );
        fail( "Expected EnvironmentCreationException" );
    }
    catch ( EnvironmentCreationException e )
    {
    }
    verify( trackerOperation ).addLogFailed( anyString() );
    //--------------------
    reset( environmentCreationWorkflow );
    doThrow( peerException ).when( environmentManager ).getPeers( topology );
    try
    {
        environmentManager.createEnvironment( topology, false, trackerOperation );
        fail( "Expected EnvironmentCreationException" );
    }
    catch ( EnvironmentCreationException e )
    {
    }
}