<commit_before>/*
 * Copyright 2013-2020 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.kubernetes.client.config;

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ConfigurableApplicationContext;

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

/**
 * @author wind57
 */
public class KubernetesClientBootstrapConfigurationTests {

	@SpringBootApplication
	static class Application {

	}

	@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
			properties = { "spring.cloud.kubernetes.enabled=false", "kubernetes.informer.enabled=false",
					"kubernetes.manifests.enabled=false" })
	@Nested
	class KubernetesDisabled {

		@Autowired
		ConfigurableApplicationContext context;

		@Test
		void configAndSecretsBeansAreNotPresent() {
			assertThat(context.getBeanNamesForType(KubernetesClientConfigMapPropertySourceLocator.class)).hasSize(0);
			assertThat(context.getBeanNamesForType(KubernetesClientSecretsPropertySourceLocator.class)).hasSize(0);
		}

	}

	@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
			properties = { "spring.cloud.kubernetes.secrets.enabled=true",
					"spring.cloud.kubernetes.client.namespace=default", "spring.main.cloud-platform=KUBERNETES" })
	@Nested
	class KubernetesEnabledOnPurpose {

		@Autowired
		ConfigurableApplicationContext context;

		@Test
		void configAndSecretsBeansArePresent() {
			assertThat(context.getBeanNamesForType(KubernetesClientConfigMapPropertySourceLocator.class)).hasSize(1);
			assertThat(context.getBeanNamesForType(KubernetesClientSecretsPropertySourceLocator.class)).hasSize(1);
		}

	}

	@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
			properties = { "spring.cloud.kubernetes.client.namespace=default",
					"spring.main.cloud-platform=KUBERNETES" })
	@Nested
	class KubernetesEnabled {

		@Autowired
		ConfigurableApplicationContext context;

		@Test
		void configAndSecretsBeansArePresent() {
			assertThat(context.getBeanNamesForType(KubernetesClientConfigMapPropertySourceLocator.class)).hasSize(1);
			assertThat(context.getBeanNamesForType(KubernetesClientSecretsPropertySourceLocator.class)).hasSize(1);
		}

	}

	@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
			properties = { "spring.cloud.kubernetes.config.enabled=false", "spring.main.cloud-platform=KUBERNETES" })
	@Nested
	class KubernetesEnabledConfigDisabled {

		@Autowired
		ConfigurableApplicationContext context;

		@Test
		void secretsOnlyPresent() {
			assertThat(context.getBeanNamesForType(KubernetesClientConfigMapPropertySourceLocator.class)).hasSize(0);
			assertThat(context.getBeanNamesForType(KubernetesClientSecretsPropertySourceLocator.class)).hasSize(1);
		}

	}

	@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
			properties = { "spring.cloud.kubernetes.secrets.enabled=false",
					"spring.cloud.kubernetes.client.namespace=default", "spring.main.cloud-platform=KUBERNETES" })
	@Nested
	class KubernetesEnabledSecretsDisabled {

		@Autowired
		ConfigurableApplicationContext context;

		@Test
		void secretsOnlyPresent() {
			assertThat(context.getBeanNamesForType(KubernetesClientConfigMapPropertySourceLocator.class)).hasSize(1);
			assertThat(context.getBeanNamesForType(KubernetesClientSecretsPropertySourceLocator.class)).hasSize(0);
		}

	}

	@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
			properties = { "spring.cloud.kubernetes.secrets.enabled=false",
					"spring.cloud.kubernetes.config.enabled=false" })
	@Nested
	class KubernetesEnabledSecretsAndConfigDisabled {

		@Autowired
		ConfigurableApplicationContext context;

		@Test
		void secretsOnlyPresent() {
			assertThat(context.getBeanNamesForType(KubernetesClientConfigMapPropertySourceLocator.class)).hasSize(0);
			assertThat(context.getBeanNamesForType(KubernetesClientSecretsPropertySourceLocator.class)).hasSize(0);
		}

	}

	// tests that @ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) has the desired
	// effect, meaning when it is enabled, both property sources are present
	@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
			properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.client.namespace=abc" })
	@Nested
	class KubernetesClientBootstrapConfigurationInsideK8s {

		@Autowired
		ConfigurableApplicationContext context;

		@Test
		public void bothPresent() {
			assertThat(context.getBeanNamesForType(KubernetesClientConfigMapPropertySourceLocator.class)).hasSize(1);
			assertThat(context.getBeanNamesForType(KubernetesClientSecretsPropertySourceLocator.class)).hasSize(1);
		}

	}

	// tests that @ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) has the desired
	// effect, meaning when it is disabled, no property source bean is present
	@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class)
	@Nested
	class KubernetesClientBootstrapConfigurationNotInsideK8s {

		@Autowired
		ConfigurableApplicationContext context;

		@Test
		public void bothMissing() {
			assertThat(context.getBeanNamesForType(KubernetesClientConfigMapPropertySourceLocator.class)).hasSize(0);
			assertThat(context.getBeanNamesForType(KubernetesClientSecretsPropertySourceLocator.class)).hasSize(0);
		}

	}

}<commit_msg>Disables failing tests<commit_after>/*
 * Copyright 2013-2020 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.kubernetes.client.config;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ConfigurableApplicationContext;

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

/**
 * @author wind57
 */
public class KubernetesClientBootstrapConfigurationTests {

	@SpringBootApplication
	static class Application {

	}

	@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
			properties = { "spring.cloud.kubernetes.enabled=false", "kubernetes.informer.enabled=false",
					"kubernetes.manifests.enabled=false" })
	@Nested
	class KubernetesDisabled {

		@Autowired
		ConfigurableApplicationContext context;

		@Test
		void configAndSecretsBeansAreNotPresent() {
			assertThat(context.getBeanNamesForType(KubernetesClientConfigMapPropertySourceLocator.class)).hasSize(0);
			assertThat(context.getBeanNamesForType(KubernetesClientSecretsPropertySourceLocator.class)).hasSize(0);
		}

	}

	@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
			properties = { "spring.cloud.kubernetes.secrets.enabled=true",
					"spring.cloud.kubernetes.client.namespace=default", "spring.main.cloud-platform=KUBERNETES" })
	@Nested
	class KubernetesEnabledOnPurpose {

		@Autowired
		ConfigurableApplicationContext context;

		@Test
		void configAndSecretsBeansArePresent() {
			assertThat(context.getBeanNamesForType(KubernetesClientConfigMapPropertySourceLocator.class)).hasSize(1);
			assertThat(context.getBeanNamesForType(KubernetesClientSecretsPropertySourceLocator.class)).hasSize(1);
		}

	}

	@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
			properties = { "spring.cloud.kubernetes.client.namespace=default",
					"spring.main.cloud-platform=KUBERNETES" })
	@Nested
	class KubernetesEnabled {

		@Autowired
		ConfigurableApplicationContext context;

		@Test
		void configAndSecretsBeansArePresent() {
			assertThat(context.getBeanNamesForType(KubernetesClientConfigMapPropertySourceLocator.class)).hasSize(1);
			assertThat(context.getBeanNamesForType(KubernetesClientSecretsPropertySourceLocator.class)).hasSize(1);
		}

	}

	@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
			properties = { "spring.cloud.kubernetes.config.enabled=false", "spring.main.cloud-platform=KUBERNETES" })
	@Nested
	class KubernetesEnabledConfigDisabled {

		@Autowired
		ConfigurableApplicationContext context;

		@Test
		void secretsOnlyPresent() {
			assertThat(context.getBeanNamesForType(KubernetesClientConfigMapPropertySourceLocator.class)).hasSize(0);
			assertThat(context.getBeanNamesForType(KubernetesClientSecretsPropertySourceLocator.class)).hasSize(1);
		}

	}

	@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
			properties = { "spring.cloud.kubernetes.secrets.enabled=false",
					"spring.cloud.kubernetes.client.namespace=default", "spring.main.cloud-platform=KUBERNETES" })
	@Nested
	class KubernetesEnabledSecretsDisabled {

		@Autowired
		ConfigurableApplicationContext context;

		@Test
		void secretsOnlyPresent() {
			assertThat(context.getBeanNamesForType(KubernetesClientConfigMapPropertySourceLocator.class)).hasSize(1);
			assertThat(context.getBeanNamesForType(KubernetesClientSecretsPropertySourceLocator.class)).hasSize(0);
		}

	}

	@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
			properties = { "spring.cloud.kubernetes.secrets.enabled=false",
					"spring.cloud.kubernetes.config.enabled=false" })
	@Nested
	class KubernetesEnabledSecretsAndConfigDisabled {

		@Autowired
		ConfigurableApplicationContext context;

		@Test
		@Disabled("fails on jenkins https://github.com/spring-cloud/spring-cloud-kubernetes/issues/927")
		void secretsOnlyPresent() {
			assertThat(context.getBeanNamesForType(KubernetesClientConfigMapPropertySourceLocator.class)).hasSize(0);
			assertThat(context.getBeanNamesForType(KubernetesClientSecretsPropertySourceLocator.class)).hasSize(0);
		}

	}

	// tests that @ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) has the desired
	// effect, meaning when it is enabled, both property sources are present
	@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
			properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.client.namespace=abc" })
	@Nested
	class KubernetesClientBootstrapConfigurationInsideK8s {

		@Autowired
		ConfigurableApplicationContext context;

		@Test
		public void bothPresent() {
			assertThat(context.getBeanNamesForType(KubernetesClientConfigMapPropertySourceLocator.class)).hasSize(1);
			assertThat(context.getBeanNamesForType(KubernetesClientSecretsPropertySourceLocator.class)).hasSize(1);
		}

	}

	// tests that @ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) has the desired
	// effect, meaning when it is disabled, no property source bean is present
	@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class)
	@Nested
	class KubernetesClientBootstrapConfigurationNotInsideK8s {

		@Autowired
		ConfigurableApplicationContext context;

		@Test
		@Disabled("fails on jenkins https://github.com/spring-cloud/spring-cloud-kubernetes/issues/927")
		public void bothMissing() {
			assertThat(context.getBeanNamesForType(KubernetesClientConfigMapPropertySourceLocator.class)).hasSize(0);
			assertThat(context.getBeanNamesForType(KubernetesClientSecretsPropertySourceLocator.class)).hasSize(0);
		}

	}

}
{'fraction_non_alphanumeric': 0.0922614459688608, 'fraction_numerical': 0.005395406197009404, 'mean_word_length': 6.427017744705209, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1096267', 'n_tokens_mistral': 3943, 'n_tokens_neox': 3631, 'n_words': 598}