diff --git a/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/endpoint/PolarisRouterEndpointTest.java b/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/endpoint/PolarisRouterEndpointTest.java index 27183c2a5..295ca2ef2 100644 --- a/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/endpoint/PolarisRouterEndpointTest.java +++ b/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/endpoint/PolarisRouterEndpointTest.java @@ -42,7 +42,7 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.when; /** - * Test for {@link PolarisRouterEndpoint} + * Test for {@link PolarisRouterEndpoint}. * @author lepdou 2022-07-25 */ @RunWith(MockitoJUnitRunner.class) diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/pom.xml b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/pom.xml index 9a5e0cb69..7ad4982e9 100644 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/pom.xml +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/pom.xml @@ -21,6 +21,18 @@ com.tencent.cloud spring-cloud-tencent-polaris-context + + org.springframework.boot + spring-boot-test + 2.6.10 + test + + + org.assertj + assertj-core + 3.21.0 + test + \ No newline at end of file diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayAutoConfiguration.java b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayAutoConfiguration.java index ecf8cdbdb..26477a423 100644 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayAutoConfiguration.java +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayAutoConfiguration.java @@ -18,8 +18,8 @@ package com.tencent.cloud.plugin.pushgateway; +import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -29,7 +29,7 @@ import org.springframework.core.env.Environment; * @author lingxiao.wlx */ @Configuration(proxyBeanMethods = false) -@ConditionalOnProperty(value = "spring.cloud.polaris.stat.pushgateway.enabled", havingValue = "true") +@ConditionalOnPolarisEnabled @EnableConfigurationProperties(PolarisStatPushGatewayProperties.class) public class PolarisStatPushGatewayAutoConfiguration { diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayAutoConfigurationTest.java b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayAutoConfigurationTest.java new file mode 100644 index 000000000..59ca67546 --- /dev/null +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayAutoConfigurationTest.java @@ -0,0 +1,46 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 com.tencent.cloud.plugin.pushgateway; + +import org.junit.Test; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +import static org.assertj.core.api.Assertions.assertThat; + + +/** + * Test for {@link PolarisStatPushGatewayAutoConfiguration}. + * + * @author lingxiao.wlx + */ +public class PolarisStatPushGatewayAutoConfigurationTest { + + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(PolarisStatPushGatewayAutoConfiguration.class)); + + @Test + public void testDefaultInitialization() { + this.contextRunner.run(context -> { + assertThat(context).hasSingleBean(PolarisStatPushGatewayProperties.class); + assertThat(context).hasSingleBean(PolarisStatPushGatewayModifier.class); + assertThat(context).hasSingleBean(PolarisStatPushGatewayProperties.class); + }); + } +} diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayBootstrapConfigurationTest.java b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayBootstrapConfigurationTest.java new file mode 100644 index 000000000..5dd8d1fa7 --- /dev/null +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayBootstrapConfigurationTest.java @@ -0,0 +1,47 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 com.tencent.cloud.plugin.pushgateway; + +import org.junit.Test; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for {@link PolarisStatPushGatewayBootstrapConfiguration}. + * + * @author lingxiao.wlx + */ +public class PolarisStatPushGatewayBootstrapConfigurationTest { + + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(PolarisStatPushGatewayBootstrapConfiguration.class)) + .withPropertyValues("spring.cloud.polaris.enabled=true"); + + @Test + public void testDefaultInitialization() { + this.contextRunner.run(context -> { + assertThat(context).hasSingleBean(PolarisStatPushGatewayProperties.class); + assertThat(context).hasSingleBean(PolarisStatPushGatewayModifier.class); + assertThat(context).hasSingleBean(PolarisStatPushGatewayProperties.class); + assertThat(context).hasSingleBean(PolarisStatPushGatewayBootstrapConfiguration.class); + }); + } +} diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayPropertiesTest.java b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayPropertiesTest.java new file mode 100644 index 000000000..8ce149796 --- /dev/null +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayPropertiesTest.java @@ -0,0 +1,53 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 com.tencent.cloud.plugin.pushgateway; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +/** + * Test for {@link PolarisStatPushGatewayProperties}. + * + * @author lingxiao.wlx + */ +public class PolarisStatPushGatewayPropertiesTest { + + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(PolarisStatPushGatewayBootstrapConfiguration.class)) + .withPropertyValues("spring.cloud.polaris.enabled=true") + .withPropertyValues("spring.cloud.polaris.stat.pushgateway.enabled=true") + .withPropertyValues("spring.cloud.polaris.stat.pushgateway.address=127.0.0.1:9091") + .withPropertyValues("spring.cloud.polaris.stat.pushgateway.namespace=default") + .withPropertyValues("spring.cloud.polaris.stat.pushgateway.push-interval=1000") + .withPropertyValues("spring.cloud.polaris.stat.pushgateway.service=grpc://183.47.111.80:8091"); + + @Test + public void polarisStatPushGatewayPropertiesTest() { + contextRunner.run(context -> { + PolarisStatPushGatewayProperties polarisStatPushGatewayProperties = context.getBean(PolarisStatPushGatewayProperties.class); + Assert.assertTrue(polarisStatPushGatewayProperties.isEnabled()); + Assert.assertEquals("127.0.0.1:9091", polarisStatPushGatewayProperties.getAddress()); + Assert.assertEquals("default", polarisStatPushGatewayProperties.getNamespace()); + Assert.assertEquals("1000", polarisStatPushGatewayProperties.getPushInterval().toString()); + Assert.assertEquals("grpc://183.47.111.80:8091", polarisStatPushGatewayProperties.getService()); + }); + } +}