add PostInitPolarisSDKContextTest (#397)

* add PostInitPolarisSDKContextTest

Co-authored-by: Haotian Zhang <928016560@qq.com>
pull/398/head
weihubeats 2 years ago committed by GitHub
parent 98e6bb04be
commit 8a451a2892
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -38,3 +38,4 @@
- [docs:update docs](https://github.com/Tencent/spring-cloud-tencent/pull/378) - [docs:update docs](https://github.com/Tencent/spring-cloud-tencent/pull/378)
- [docs:optimize example](https://github.com/Tencent/spring-cloud-tencent/pull/385) - [docs:optimize example](https://github.com/Tencent/spring-cloud-tencent/pull/385)
- [Feature: format code](https://github.com/Tencent/spring-cloud-tencent/pull/394) - [Feature: format code](https://github.com/Tencent/spring-cloud-tencent/pull/394)
- [test: add PostInitPolarisSDKContextTest](https://github.com/Tencent/spring-cloud-tencent/pull/397)

@ -0,0 +1,50 @@
package com.tencent.cloud.polaris.context;
import com.tencent.cloud.common.metadata.StaticMetadataManager;
import com.tencent.polaris.api.plugin.common.ValueContext;
import com.tencent.polaris.api.plugin.route.LocationLevel;
import com.tencent.polaris.client.api.SDKContext;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.mockito.Mockito.when;
/**
* Test for {@link PostInitPolarisSDKContext}.
*
* @author wh
*/
@RunWith(MockitoJUnitRunner.class)
public class PostInitPolarisSDKContextTest {
@Mock
private SDKContext sdkContext;
@Mock
private StaticMetadataManager staticMetadataManager;
private static final String region = "region";
private static final String zone = "zone";
private static final String campus = "campus";
@Test
public void PostInitPolarisSDKContextTest() {
ValueContext valueContext = new ValueContext();
when(sdkContext.getValueContext()).thenReturn(valueContext);
when(staticMetadataManager.getRegion()).thenReturn(region);
when(staticMetadataManager.getZone()).thenReturn(zone);
when(staticMetadataManager.getCampus()).thenReturn(campus);
new PostInitPolarisSDKContext(sdkContext, staticMetadataManager);
assertThat(valueContext.getValue(LocationLevel.region.name()), is(region));
assertThat(valueContext.getValue(LocationLevel.zone.name()), is(zone));
assertThat(valueContext.getValue(LocationLevel.campus.name()), is(campus));
}
}
Loading…
Cancel
Save