pull/399/head
weihu 3 years ago
parent db27afe540
commit e2eaeb94a9

@ -4,13 +4,12 @@ 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.assertj.core.api.Assertions;
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;
@ -20,31 +19,35 @@ import static org.mockito.Mockito.when;
* @author wh
*/
@RunWith(MockitoJUnitRunner.class)
public class PostInitPolarisSDKContextTest {
public final class PostInitPolarisSDKContextTest {
@Mock
private SDKContext sdkContext;
@Mock
private StaticMetadataManager staticMetadataManager;
private static final String region = "region";
private static final String REGION = "region";
private static final String zone = "zone";
private static final String ZONE = "zone";
private static final String campus = "campus";
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);
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));
String regionName = valueContext.getValue(LocationLevel.region.name());
String zoneName = valueContext.getValue(LocationLevel.zone.name());
String campusName = valueContext.getValue(LocationLevel.campus.name());
Assertions.assertThat(regionName).isEqualTo(REGION);
Assertions.assertThat(zoneName).isEqualTo(ZONE);
Assertions.assertThat(campusName).isEqualTo(CAMPUS);
}
}

Loading…
Cancel
Save