/*
 * Copyright 2013-2019 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
 *
 *      https://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.consul.config;

import com.ecwid.consul.transport.TransportException;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.test.system.OutputCaptureRule;
import org.springframework.context.annotation.Configuration;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * @author Spencer Gibb
 */
/*
 * @RunWith(SpringRunner.class)
 *
 * @SpringBootTest(classes = ConsulPropertySourceLocatorRetryTests.Config.class,
 * properties = { "spring.application.name=testConsulPropertySourceLocatorRetry",
 * "spring.cloud.consul.host=53210a7c-4809-42cb-8b30-057d2db85fcc",
 * "logging.level.org.springframework.retry=TRACE", "spring.cloud.consul.port=65530",
 * "spring.cloud.consul.retry.maxAttempts=1", "spring.cloud.consul.config.failFast=true"
 * }, webEnvironment = RANDOM_PORT)
 */
public class ConsulPropertySourceLocatorRetryTests {

	@Rule
	public OutputCaptureRule output = new OutputCaptureRule();

	@Test
	public void testRetry() {
		Assert.assertThrows(TransportException.class, () -> {
			new SpringApplicationBuilder(Config.class).properties(
					"spring.application.name=testConsulPropertySourceLocatorRetry",
					"spring.cloud.consul.host=53210a7c-4809-42cb-8b30-057d2db85fcc",
					"logging.level.org.springframework.retry=TRACE", "server.port=0",
					"spring.cloud.consul.port=65530",
					"spring.cloud.consul.retry.maxAttempts=1",
					"spring.cloud.consul.config.failFast=true").run();
		});
		assertThat(output).contains("RetryContext retrieved");
	}

	@Configuration(proxyBeanMethods = false)
	@EnableAutoConfiguration
	static class Config {

	}

}

@@ -1787,16 +1787,18 @@
 y() %7B%0A%09%09
+//
 Assert.a
@@ -1843,16 +1843,24 @@
 () -%3E %7B%0A
+%09%09try %7B%0A
 %09%09%09new S
@@ -2264,16 +2264,125 @@
 un();%0A%09%09
+%09Assert.fail(%22Did not throw TransportException%22);%0A%09%09%7D%0A%09%09catch (TransportException e) %7B%0A%09%09%09// success%0A%09%09%7D%0A%09%09//
 %7D);%0A%09%09as

Move to try/catch for test