parent
e1b577e30e
commit
42331ac626
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* 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.extend.nacos;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.tencent.polaris.client.api.SDKContext;
|
||||||
|
import com.tencent.polaris.factory.config.global.ServerConnectorConfigImpl;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for {@link NacosContextProperties}.
|
||||||
|
*
|
||||||
|
* @author lingxiao.wlx
|
||||||
|
*/
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest(classes = NacosContextPropertiesTest.TestApplication.class)
|
||||||
|
@ActiveProfiles("test")
|
||||||
|
public class NacosContextPropertiesTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NacosContextProperties nacosContextProperties;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SDKContext sdkContext;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDefaultInitialization() {
|
||||||
|
assertThat(nacosContextProperties).isNotNull();
|
||||||
|
assertThat(nacosContextProperties.isEnabled()).isTrue();
|
||||||
|
assertThat(nacosContextProperties.getServerAddr()).isEqualTo("127.0.0.1:8848");
|
||||||
|
assertThat(nacosContextProperties.isRegisterEnabled()).isTrue();
|
||||||
|
assertThat(nacosContextProperties.isDiscoveryEnabled()).isTrue();
|
||||||
|
assertThat(nacosContextProperties.getGroup()).isNotBlank();
|
||||||
|
assertThat(nacosContextProperties.getClusterName()).isNotBlank();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testModify() {
|
||||||
|
assertThat(sdkContext).isNotNull();
|
||||||
|
com.tencent.polaris.api.config.Configuration configuration = sdkContext.getConfig();
|
||||||
|
List<ServerConnectorConfigImpl> serverConnectorConfigs = configuration.getGlobal().getServerConnectors();
|
||||||
|
Map<String, String> metadata = null;
|
||||||
|
for (ServerConnectorConfigImpl serverConnectorConfig : serverConnectorConfigs) {
|
||||||
|
if (serverConnectorConfig.getId().equals("nacos")) {
|
||||||
|
metadata = serverConnectorConfig.getMetadata();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertThat(metadata).isNotNull();
|
||||||
|
assertThat(metadata.get("internal-nacos-cluster")).isEqualTo("polaris");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
protected static class TestApplication {
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue