/*
 * Copyright 2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.cloud.deployer.spi.cloudfoundry;

import org.junit.After;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.deployer.spi.task.TaskLauncher;
import org.springframework.cloud.deployer.spi.test.AbstractTaskLauncherIntegrationTests;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;

/**
 * Runs integration tests for {@link CloudFoundry2630AndLaterTaskLauncher}, using the production configuration,
 * that may be configured via {@link CloudFoundryConnectionProperties}.
 *
 * Tests are only run if a successful connection can be made at startup.
 *
 * @author Eric Bottard
 * @author Greg Turnquist
 * @author Michael Minella
 * @author Ben Hale
 */
@ContextConfiguration(classes=CloudFoundryTaskLauncherIntegrationTests.Config.class)
public class CloudFoundryTaskLauncherIntegrationTests extends AbstractTaskLauncherIntegrationTests {

	@ClassRule
	public static CloudFoundryTestSupport cfAvailable = new CloudFoundryTestSupport();

	@Autowired
	private TaskLauncher taskLauncher;

	@Override
	protected TaskLauncher provideTaskLauncher() {
		return taskLauncher;
	}

	/*
	 * Allow for a small pause so that each each TL.destroy() at the end of tests actually completes,
	 * as this is asynchronous.
	 */
	@After
	public void pause() throws InterruptedException {
		Thread.sleep(500);
	}

	@Test
	@Override
	@Ignore("CF Deployer incorrectly reports status as failed instead of canceled")
	public void testSimpleCancel() throws InterruptedException {
		super.testSimpleCancel();
	}

	/**
	 * This triggers the use of {@link CloudFoundryDeployerAutoConfiguration}.
	 *
	 * @author Eric Bottard
	 */
	@Configuration
	@EnableAutoConfiguration
	@EnableConfigurationProperties
	public static class Config {

	}

}

@@ -692,24 +692,49 @@
 unit.After;%0A
+import org.junit.Before;%0A
 import org.j
@@ -749,16 +749,16 @@
 ssRule;%0A
-
 import o
@@ -1168,16 +1168,76 @@
 nTests;%0A
+import org.springframework.cloud.deployer.spi.test.Timeout;%0A
 import o
@@ -2053,16 +2053,471 @@
 ncher;%0A%0A
+%09/**%0A%09 * Execution environments may override this default value to have tests wait longer for a deployment, for example if%0A%09 * running in an environment that is known to be slow.%0A%09 */%0A%09protected double timeoutMultiplier = 1.0D;%0A%0A%09protected int maxRetries = 60;%0A%0A%09@Before%0A%09public void init() %7B%0A%09%09String multiplier = System.getenv(%22CF_DEPLOYER_TIMEOUT_MULTIPLIER%22);%0A%09%09if (multiplier != null) %7B%0A%09%09%09timeoutMultiplier = Double.parseDouble(multiplier);%0A%09%09%7D%0A%09%7D%0A%0A
 %09@Overri
@@ -3004,20 +3004,272 @@
 ncel();%0A
-
 %09%7D%0A%0A
+%09@Override%0A%09protected Timeout deploymentTimeout() %7B%0A%09%09return new Timeout(maxRetries, (int) (5000 * timeoutMultiplier));%0A%09%7D%0A%0A%09@Override%0A%09protected Timeout undeploymentTimeout() %7B%0A%09%09return new Timeout(maxRetries, (int) (5000 * timeoutMultiplier));%0A%09%7D%0A%0A%0A%0A
 %09/**%0A%09 *

Use timeout multiplier for task ITs as well