/*
 * 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.test;

import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.*;

import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;

import org.junit.Rule;
import org.junit.rules.TestName;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.deployer.resource.maven.MavenProperties;
import org.springframework.cloud.deployer.resource.maven.MavenResource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * Abstract base class containing infrastructure for the TCK, common to both
 * {@link org.springframework.cloud.deployer.spi.app.AppDeployer} and
 * {@link org.springframework.cloud.deployer.spi.task.TaskLauncher} tests.
 *
 * @author Eric Bottard
 */

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment= NONE)
public abstract class AbstractIntegrationTests {

	protected final Logger log = LoggerFactory.getLogger(this.getClass());

	@Rule
	public TestName name = new TestName();

	@Autowired(required = false)
	protected MavenProperties mavenProperties;

	// No duplicates, but keep insertion order
	protected Set<String> deployments = new LinkedHashSet<>();

	protected String randomName() {
		return name.getMethodName() + "-" + UUID.randomUUID().toString();
	}

	/**
	 * Record the fact that something was deployed, resulting in the given deployment id.
	 * Useful for cleaning up resources in an implementation-specific way in subclasses.
	 *
	 * @return the deployment id, for chaining calls.
	 */
	protected String record(String deployment) {
		deployments.add(deployment);
		return deployment;
	}

	/**
	 * Return the timeout to use for repeatedly querying app status while it is being deployed.
	 * Default value is one minute, being queried every 5 seconds.
	 */
	protected Timeout deploymentTimeout() {
		return new Timeout(12, 5000);
	}

	/**
	 * Return the timeout to use for repeatedly querying app status while it is being un-deployed.
	 * Default value is one minute, being queried every 5 seconds.
	 */
	protected Timeout undeploymentTimeout() {
		return new Timeout(20, 5000);
	}

	/**
	 * Return the time to wait between reusing deployment requests. This could be necessary to give
	 * some platforms time to clean up after undeployment.
	 */
	protected int redeploymentPause() {
		return 0;
	}

	/**
	 * Return a resource corresponding to the spring-cloud-deployer-spi-test-app app suitable for the target runtime.
	 *
	 * The default implementation returns an uber-jar fetched via Maven. Subclasses may override.
	 */
	protected Resource testApplication() {
		Properties properties = new Properties();
		try {
			properties.load(new ClassPathResource("integration-test-app.properties").getInputStream());
		}
		catch (IOException e) {
			throw new RuntimeException("Failed to determine which version of spring-cloud-deployer-spi-test-app to use", e);
		}
		return new MavenResource.Builder(mavenProperties)
				.groupId("org.springframework.cloud")
				.artifactId("spring-cloud-deployer-spi-test-app")
				.classifier("exec")
				.version(properties.getProperty("version"))
				.extension("jar")
				.build();
	}

	@Configuration
	public static class Config {
		@Bean
		@ConfigurationProperties("maven")
		public MavenProperties mavenProperties() {
			return new MavenProperties();
		}
	}

}

@@ -1582,32 +1582,94 @@
 re.io.Resource;%0A
+import org.springframework.test.context.ContextConfiguration;%0A
 import org.sprin
@@ -1713,16 +1713,16 @@
 Runner;%0A
-
 %0A/**%0A * 
@@ -1943,16 +1943,153 @@
 sts.%0A *%0A
+ * %3Cp%3ESubclasses should explicitly declare additional config that should be used via the use of%0A * %7B@linkg ContextConfiguration%7D.%3C/p%3E%0A *%0A
  * @auth
@@ -2176,16 +2176,87 @@
 = NONE)%0A
+@ContextConfiguration(classes = AbstractIntegrationTests.Config.class)%0A
 public a
@@ -2418,16 +2418,16 @@
 ame();%0A%0A
+
 %09@Autowi
@@ -2433,26 +2433,8 @@
 ired
-(required = false)
 %0A%09pr

Fix abstract IT to actually use its config