|
|
|
@ -22,6 +22,7 @@ import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import com.tencent.cloud.common.metadata.StaticMetadataManager;
|
|
|
|
|
import com.tencent.cloud.polaris.PolarisDiscoveryProperties;
|
|
|
|
|
import com.tencent.cloud.polaris.context.config.PolarisContextProperties;
|
|
|
|
|
import com.tencent.cloud.polaris.extend.consul.ConsulContextProperties;
|
|
|
|
|
import com.tencent.cloud.polaris.extend.nacos.NacosContextProperties;
|
|
|
|
|
import com.tencent.polaris.api.config.Configuration;
|
|
|
|
@ -62,6 +63,10 @@ public class PolarisRegistrationTest {
|
|
|
|
|
|
|
|
|
|
private PolarisRegistration polarisRegistration3;
|
|
|
|
|
|
|
|
|
|
private PolarisRegistration polarisRegistration4;
|
|
|
|
|
|
|
|
|
|
private static int testLocalPort = 10086;
|
|
|
|
|
|
|
|
|
|
@BeforeEach
|
|
|
|
|
void setUp() {
|
|
|
|
|
// mock PolarisDiscoveryProperties
|
|
|
|
@ -70,23 +75,27 @@ public class PolarisRegistrationTest {
|
|
|
|
|
doReturn("http").when(polarisDiscoveryProperties).getProtocol();
|
|
|
|
|
doReturn(true).when(polarisDiscoveryProperties).isRegisterEnabled();
|
|
|
|
|
|
|
|
|
|
// mock PolarisContextProperties
|
|
|
|
|
PolarisContextProperties polarisContextProperties = mock(PolarisContextProperties.class);
|
|
|
|
|
doReturn(testLocalPort).when(polarisContextProperties).getLocalPort();
|
|
|
|
|
|
|
|
|
|
// mock ConsulContextProperties
|
|
|
|
|
ConsulContextProperties consulContextProperties = mock(ConsulContextProperties.class);
|
|
|
|
|
doReturn(true).when(consulContextProperties).isEnabled();
|
|
|
|
|
doReturn(true).when(consulContextProperties).isRegister();
|
|
|
|
|
|
|
|
|
|
// mock NacosContextProperties
|
|
|
|
|
nacosContextProperties = new NacosContextProperties();
|
|
|
|
|
nacosContextProperties.setEnabled(true);
|
|
|
|
|
nacosContextProperties.setRegisterEnabled(true);
|
|
|
|
|
nacosContextProperties.setContextPath("/");
|
|
|
|
|
nacosContextProperties.setClusterName("cluster");
|
|
|
|
|
nacosContextProperties.setGroup("");
|
|
|
|
|
nacosContextProperties.setDiscoveryEnabled(true);
|
|
|
|
|
nacosContextProperties.setPassword("");
|
|
|
|
|
nacosContextProperties.setUsername("");
|
|
|
|
|
nacosContextProperties.setServerAddr("");
|
|
|
|
|
nacosContextProperties.toString();
|
|
|
|
|
// mock NacosContextProperties
|
|
|
|
|
nacosContextProperties = mock(NacosContextProperties.class);
|
|
|
|
|
doReturn(true).when(nacosContextProperties).isEnabled();
|
|
|
|
|
doReturn(true).when(nacosContextProperties).isRegisterEnabled();
|
|
|
|
|
doReturn("/").when(nacosContextProperties).getContextPath();
|
|
|
|
|
doReturn("cluster").when(nacosContextProperties).getClusterName();
|
|
|
|
|
doReturn("").when(nacosContextProperties).getGroup();
|
|
|
|
|
doReturn(true).when(nacosContextProperties).isDiscoveryEnabled();
|
|
|
|
|
doReturn("").when(nacosContextProperties).getPassword();
|
|
|
|
|
doReturn("").when(nacosContextProperties).getUsername();
|
|
|
|
|
doReturn("").when(nacosContextProperties).getServerAddr();
|
|
|
|
|
|
|
|
|
|
// mock SDKContext
|
|
|
|
|
APIConfig apiConfig = mock(APIConfig.class);
|
|
|
|
@ -114,15 +123,19 @@ public class PolarisRegistrationTest {
|
|
|
|
|
ReactiveWebServerApplicationContext reactiveWebServerApplicationContext = mock(ReactiveWebServerApplicationContext.class);
|
|
|
|
|
doReturn(reactiveWebServer).when(reactiveWebServerApplicationContext).getWebServer();
|
|
|
|
|
|
|
|
|
|
polarisRegistration1 = new PolarisRegistration(polarisDiscoveryProperties, consulContextProperties,
|
|
|
|
|
polarisRegistration1 = new PolarisRegistration(polarisDiscoveryProperties, null, consulContextProperties,
|
|
|
|
|
polarisContext, staticMetadataManager, nacosContextProperties,
|
|
|
|
|
servletWebServerApplicationContext, null);
|
|
|
|
|
|
|
|
|
|
polarisRegistration2 = new PolarisRegistration(polarisDiscoveryProperties, consulContextProperties,
|
|
|
|
|
polarisRegistration2 = new PolarisRegistration(polarisDiscoveryProperties, null, consulContextProperties,
|
|
|
|
|
polarisContext, staticMetadataManager, nacosContextProperties,
|
|
|
|
|
null, reactiveWebServerApplicationContext);
|
|
|
|
|
|
|
|
|
|
polarisRegistration3 = new PolarisRegistration(polarisDiscoveryProperties, consulContextProperties,
|
|
|
|
|
polarisRegistration3 = new PolarisRegistration(polarisDiscoveryProperties, null, consulContextProperties,
|
|
|
|
|
polarisContext, staticMetadataManager, nacosContextProperties,
|
|
|
|
|
null, null);
|
|
|
|
|
|
|
|
|
|
polarisRegistration4 = new PolarisRegistration(polarisDiscoveryProperties, polarisContextProperties, consulContextProperties,
|
|
|
|
|
polarisContext, staticMetadataManager, nacosContextProperties,
|
|
|
|
|
null, null);
|
|
|
|
|
}
|
|
|
|
@ -147,6 +160,7 @@ public class PolarisRegistrationTest {
|
|
|
|
|
catch (RuntimeException e) {
|
|
|
|
|
assertThat(e.getMessage()).isEqualTo("Unsupported web type.");
|
|
|
|
|
}
|
|
|
|
|
assertThat(polarisRegistration4.getPort()).isEqualTo(testLocalPort);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|