Test:add sct-stater-polaris-router junit. (#768)

pull/778/head
Haotian Zhang 2 years ago committed by GitHub
parent fe5a2894e9
commit 70a23e36cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -15,3 +15,4 @@
- [adapt polaris-java 1.10.1 version](https://github.com/Tencent/spring-cloud-tencent/pull/747) - [adapt polaris-java 1.10.1 version](https://github.com/Tencent/spring-cloud-tencent/pull/747)
- [Optimize: change RouteArgument.buildCustom to RouteArgument.fromLabel](https://github.com/Tencent/spring-cloud-tencent/pull/751) - [Optimize: change RouteArgument.buildCustom to RouteArgument.fromLabel](https://github.com/Tencent/spring-cloud-tencent/pull/751)
- [Optimize: support delete config for ConfigurationProperties bean ](https://github.com/Tencent/spring-cloud-tencent/pull/756) - [Optimize: support delete config for ConfigurationProperties bean ](https://github.com/Tencent/spring-cloud-tencent/pull/756)
- [Test:add sct-stater-polaris-router junit.](https://github.com/Tencent/spring-cloud-tencent/pull/768)

@ -0,0 +1,54 @@
/*
* 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.polaris.router.config.properties;
import org.junit.Before;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* test for {@link PolarisMetadataRouterProperties}.
*/
public class PolarisMetadataRouterPropertiesTest {
PolarisMetadataRouterProperties properties;
@Before
public void setUp() {
properties = new PolarisMetadataRouterProperties();
}
@Test
public void isEnabled() {
assertThat(properties.isEnabled()).isEqualTo(true);
}
@Test
public void setEnabled() {
properties.setEnabled(false);
assertThat(properties.isEnabled()).isEqualTo(false);
}
@Test
public void testToString() {
assertThat(properties.toString())
.isEqualTo("PolarisMetadataRouterProperties{enabled=true}");
}
}

@ -0,0 +1,56 @@
/*
* 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.polaris.router.config.properties;
import org.junit.Before;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* test for {@link PolarisNearByRouterProperties}.
*/
public class PolarisNearByRouterPropertiesTest {
PolarisNearByRouterProperties properties;
@Before
public void setUp() {
properties = new PolarisNearByRouterProperties();
}
@Test
public void isEnabled() {
assertThat(properties.isEnabled()).isEqualTo(true);
}
@Test
public void setEnabled() {
properties.setEnabled(false);
assertThat(properties.isEnabled()).isEqualTo(false);
}
@Test
public void testToString() {
assertThat(properties.toString())
.isEqualTo("PolarisNearByRouterProperties{enabled=true}");
}
}

@ -0,0 +1,55 @@
/*
* 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.polaris.router.config.properties;
import org.junit.Before;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* test for {@link PolarisRuleBasedRouterProperties}.
*/
public class PolarisRuleBasedRouterPropertiesTest {
PolarisRuleBasedRouterProperties properties;
@Before
public void setUp() {
properties = new PolarisRuleBasedRouterProperties();
}
@Test
public void isEnabled() {
assertThat(properties.isEnabled()).isEqualTo(true);
}
@Test
public void setEnabled() {
properties.setEnabled(false);
assertThat(properties.isEnabled()).isEqualTo(false);
}
@Test
public void testToString() {
assertThat(properties.toString())
.isEqualTo("PolarisNearByRouterProperties{enabled=true}");
}
}

@ -0,0 +1,65 @@
/*
* 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.polaris.router.endpoint;
import com.tencent.cloud.polaris.context.ServiceRuleManager;
import com.tencent.polaris.client.api.SDKContext;
import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
/**
* test for {@link PolarisRouterEndpointAutoConfiguration}.
* @author dongyinuo
*/
public class PolarisRouterEndpointAutoConfigurationTests {
private ServiceRuleManager serviceRuleManager;
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(
TestServiceRuleManagerConfiguration.class,
PolarisRouterEndpointAutoConfiguration.class))
.withPropertyValues("endpoints.polaris-router.enabled=true");
@Test
public void polarisRouterEndpoint() {
contextRunner.run(context -> {
assertThat(context).hasSingleBean(PolarisRouterEndpointAutoConfiguration.class);
});
}
@Configuration
static class TestServiceRuleManagerConfiguration {
@Bean
public ServiceRuleManager serviceRuleManager(SDKContext sdkContext) {
return new ServiceRuleManager(sdkContext);
}
@Bean
public SDKContext sdkContext() {
return SDKContext.initContext();
}
}
}

@ -46,6 +46,7 @@ import org.mockito.MockedStatic;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -72,6 +73,8 @@ public class RouterLabelFeignInterceptorTest {
Collections.singletonList(routerLabelResolver), Collections.singletonList(routerLabelResolver),
staticMetadataManager, routerRuleLabelResolver, polarisContextProperties); staticMetadataManager, routerRuleLabelResolver, polarisContextProperties);
assertThat(routerLabelFeignInterceptor.getOrder()).isEqualTo(0);
// mock request template // mock request template
RequestTemplate requestTemplate = new RequestTemplate(); RequestTemplate requestTemplate = new RequestTemplate();
String headerUidKey = "uid"; String headerUidKey = "uid";

@ -52,6 +52,7 @@ import org.springframework.mock.web.server.MockServerWebExchange;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -88,7 +89,7 @@ public class PolarisLoadBalancerClientFilterTest {
mockedApplicationContextAwareUtils.when(() -> ApplicationContextAwareUtils.getProperties(anyString())) mockedApplicationContextAwareUtils.when(() -> ApplicationContextAwareUtils.getProperties(anyString()))
.thenReturn(callerService); .thenReturn(callerService);
MetadataContext metadataContext = Mockito.mock(MetadataContext.class); MetadataContext metadataContext = mock(MetadataContext.class);
// mock transitive metadata // mock transitive metadata
Map<String, String> transitiveLabels = new HashMap<>(); Map<String, String> transitiveLabels = new HashMap<>();

Loading…
Cancel
Save