1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

format code with maven plugins

This commit is contained in:
fangjian0423
2019-09-26 17:15:41 +08:00
parent ed6942d9df
commit 2435167e1e
529 changed files with 6304 additions and 5164 deletions

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,6 +16,11 @@
package com.alibaba.alicloud.ans;
import com.alibaba.alicloud.ans.registry.AnsAutoServiceRegistration;
import com.alibaba.alicloud.ans.registry.AnsRegistration;
import com.alibaba.alicloud.ans.registry.AnsServiceRegistry;
import com.alibaba.alicloud.context.ans.AnsProperties;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -28,18 +33,15 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.alibaba.alicloud.ans.registry.AnsAutoServiceRegistration;
import com.alibaba.alicloud.ans.registry.AnsRegistration;
import com.alibaba.alicloud.ans.registry.AnsServiceRegistry;
import com.alibaba.alicloud.context.ans.AnsProperties;
/**
* @author xiaolongzuo
*/
@Configuration
@EnableConfigurationProperties
@ConditionalOnClass(name = "org.springframework.boot.web.context.WebServerInitializedEvent")
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true)
@ConditionalOnClass(
name = "org.springframework.boot.web.context.WebServerInitializedEvent")
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled",
matchIfMissing = true)
@ConditionalOnAnsEnabled
@AutoConfigureAfter({ AutoServiceRegistrationConfiguration.class,
AutoServiceRegistrationAutoConfiguration.class })
@@ -52,7 +54,9 @@ public class AnsAutoConfiguration {
@Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true)
@ConditionalOnProperty(
value = "spring.cloud.service-registry.auto-registration.enabled",
matchIfMissing = true)
public AnsRegistration ansRegistration(AnsProperties ansProperties,
ApplicationContext applicationContext) {
return new AnsRegistration(ansProperties, applicationContext);
@@ -60,7 +64,9 @@ public class AnsAutoConfiguration {
@Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true)
@ConditionalOnProperty(
value = "spring.cloud.service-registry.auto-registration.enabled",
matchIfMissing = true)
public AnsAutoServiceRegistration ansAutoServiceRegistration(
AnsServiceRegistry registry,
AutoServiceRegistrationProperties autoServiceRegistrationProperties,

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -23,18 +23,21 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import com.alibaba.ans.core.NamingService;
import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
/**
* @author xiaolongzuo
* @author pbting
*/
public class AnsDiscoveryClient implements DiscoveryClient {
/**
* Description of Ans Discovery.
*/
public static final String DESCRIPTION = "Spring Cloud ANS Discovery Client";
@Override

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -30,4 +30,5 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@Target({ ElementType.TYPE, ElementType.METHOD })
@ConditionalOnProperty(value = "spring.cloud.ans.enabled", matchIfMissing = true)
public @interface ConditionalOnAnsEnabled {
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -21,14 +21,14 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import com.alibaba.alicloud.context.ans.AnsProperties;
import com.alibaba.ans.core.NamingService;
import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
/**
* @author xiaolongzuo

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,13 +16,13 @@
package com.alibaba.alicloud.ans.endpoint;
import com.alibaba.alicloud.context.ans.AnsProperties;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import com.alibaba.alicloud.context.ans.AnsProperties;
/**
* @author xiaolongzuo
*/
@@ -34,4 +34,5 @@ public class AnsEndpointAutoConfiguration {
public AnsEndpoint ansEndpoint(AnsProperties ansProperties) {
return new AnsEndpoint(ansProperties);
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -18,6 +18,7 @@ package com.alibaba.alicloud.ans.registry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration;
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
@@ -30,6 +31,7 @@ import org.springframework.util.StringUtils;
*/
public class AnsAutoServiceRegistration
extends AbstractAutoServiceRegistration<AnsRegistration> {
private static final Logger log = LoggerFactory
.getLogger(AnsAutoServiceRegistration.class);

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -21,6 +21,8 @@ import java.util.Map;
import javax.annotation.PostConstruct;
import com.alibaba.alicloud.context.ans.AnsProperties;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.ManagementServerPortUtils;
@@ -29,8 +31,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
import com.alibaba.alicloud.context.ans.AnsProperties;
/**
* @author xiaolongzuo
*/
@@ -42,6 +42,7 @@ public class AnsRegistration implements Registration, ServiceInstance {
static final String MANAGEMENT_ENDPOINT_BASE_PATH = "management.endpoints.web.base-path";
private AnsProperties ansProperties;
private ApplicationContext context;
public AnsRegistration(AnsProperties ansProperties, ApplicationContext context) {

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -20,13 +20,13 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.alibaba.ans.core.NamingService;
import com.alibaba.ans.shaded.com.taobao.vipserver.client.ipms.NodeReactor;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
import com.alibaba.ans.core.NamingService;
import com.alibaba.ans.shaded.com.taobao.vipserver.client.ipms.NodeReactor;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
/**
* @author xiaolongzuo

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,13 +16,13 @@
package com.alibaba.alicloud.ans.ribbon;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.ServerList;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.ServerList;
/**
* @author xiaolongzuo
* @author pbting
@@ -37,4 +37,4 @@ public class AnsRibbonClientConfiguration {
return serverList;
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -20,7 +20,6 @@ import java.util.Collections;
import java.util.Map;
import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host;
import com.netflix.loadbalancer.Server;
/**
@@ -29,7 +28,9 @@ import com.netflix.loadbalancer.Server;
public class AnsServer extends Server {
private final MetaInfo metaInfo;
private final Host host;
private final Map<String, String> metadata;
public AnsServer(final Host host, final String dom) {
@@ -78,4 +79,5 @@ public class AnsServer extends Server {
return "AnsServer{" + "metaInfo=" + metaInfo + ", host=" + host + ", metadata="
+ metadata + '}';
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -21,7 +21,6 @@ import java.util.List;
import com.alibaba.ans.core.NamingService;
import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.AbstractServerList;
@@ -76,4 +75,5 @@ public class AnsServerList extends AbstractServerList<AnsServer> {
public void initWithNiwsConfig(IClientConfig iClientConfig) {
this.dom = iClientConfig.getClientName();
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,6 +16,8 @@
package com.alibaba.alicloud.ans.ribbon;
import com.alibaba.alicloud.ans.ConditionalOnAnsEnabled;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -24,8 +26,6 @@ import org.springframework.cloud.netflix.ribbon.RibbonClients;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.context.annotation.Configuration;
import com.alibaba.alicloud.ans.ConditionalOnAnsEnabled;
/**
* @author xiaolongzuo
*/
@@ -37,4 +37,5 @@ import com.alibaba.alicloud.ans.ConditionalOnAnsEnabled;
@AutoConfigureAfter(RibbonAutoConfiguration.class)
@RibbonClients(defaultConfiguration = AnsRibbonClientConfiguration.class)
public class RibbonAnsAutoConfiguration {
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,26 +16,26 @@
package com.alibaba.alicloud.ans;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.alibaba.alicloud.ans.test.AnsMockTest;
import com.alibaba.ans.core.NamingService;
import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.springframework.cloud.client.ServiceInstance;
import com.alibaba.alicloud.ans.test.AnsMockTest;
import com.alibaba.ans.core.NamingService;
import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
/**
* @author xiaojing
@@ -45,7 +45,9 @@ import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host;
public class AnsDiscoveryClientTests {
private String host = "123.123.123.123";
private int port = 8888;
private String serviceName = "test-service";
@Test
@@ -113,4 +115,5 @@ public class AnsDiscoveryClientTests {
return "http://" + host + ":" + port;
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,12 +16,12 @@
package com.alibaba.alicloud.ans.registry;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import com.alibaba.alicloud.ans.AnsAutoConfiguration;
import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration;
import com.alibaba.alicloud.context.ans.AnsProperties;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
@@ -30,20 +30,20 @@ import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationC
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import com.alibaba.alicloud.ans.AnsAutoConfiguration;
import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration;
import com.alibaba.alicloud.context.ans.AnsProperties;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
/**
* @author xiaojing
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = AnsAutoServiceRegistrationEnabledTests.TestConfig.class, properties = {
"spring.application.name=myTestService1",
"spring.cloud.alicloud.ans.server-list=127.0.0.1",
"spring.cloud.alicloud.ans.server-port=8080",
"spring.cloud.alicloud.ans.register-enabled=false" }, webEnvironment = RANDOM_PORT)
@SpringBootTest(classes = AnsAutoServiceRegistrationEnabledTests.TestConfig.class,
properties = { "spring.application.name=myTestService1",
"spring.cloud.alicloud.ans.server-list=127.0.0.1",
"spring.cloud.alicloud.ans.server-port=8080",
"spring.cloud.alicloud.ans.register-enabled=false" },
webEnvironment = RANDOM_PORT)
public class AnsAutoServiceRegistrationEnabledTests {
@Autowired
@@ -57,19 +57,16 @@ public class AnsAutoServiceRegistrationEnabledTests {
@Test
public void contextLoads() throws Exception {
assertNotNull("AnsRegistration was not created", registration);
assertNotNull("AnsProperties was not created", properties);
assertNotNull("AnsAutoServiceRegistration was not created",
ansAutoServiceRegistration);
assertThat(registration).isNotNull();
assertThat(properties).isNotNull();
assertThat(ansAutoServiceRegistration).isNotNull();
checkEnabled();
}
private void checkEnabled() {
assertFalse("Ans Auto Registration should not start",
ansAutoServiceRegistration.isEnabled());
assertThat(ansAutoServiceRegistration.isEnabled()).isEqualTo(Boolean.FALSE);
}
@Configuration
@@ -77,5 +74,7 @@ public class AnsAutoServiceRegistrationEnabledTests {
@ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class,
AnsDiscoveryClientAutoConfiguration.class, AnsAutoConfiguration.class })
public static class TestConfig {
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,17 +16,17 @@
package com.alibaba.alicloud.ans.registry;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
import com.alibaba.alicloud.ans.AnsAutoConfiguration;
import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration;
import com.alibaba.alicloud.context.ans.AnsProperties;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
@@ -36,19 +36,20 @@ import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import com.alibaba.alicloud.ans.AnsAutoConfiguration;
import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration;
import com.alibaba.alicloud.context.ans.AnsProperties;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
/**
* @author xiaojing
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = AnsAutoServiceRegistrationIpNetworkInterfaceTests.TestConfig.class, properties = {
"spring.application.name=myTestService1",
"spring.cloud.alicloud.ans.server-list=127.0.0.1",
"spring.cloud.alicloud.ans.server-port=8080" }, webEnvironment = RANDOM_PORT)
@SpringBootTest(
classes = AnsAutoServiceRegistrationIpNetworkInterfaceTests.TestConfig.class,
properties = { "spring.application.name=myTestService1",
"spring.cloud.alicloud.ans.server-list=127.0.0.1",
"spring.cloud.alicloud.ans.server-port=8080" },
webEnvironment = RANDOM_PORT)
public class AnsAutoServiceRegistrationIpNetworkInterfaceTests {
@Autowired
@@ -66,20 +67,17 @@ public class AnsAutoServiceRegistrationIpNetworkInterfaceTests {
@Test
public void contextLoads() throws Exception {
assertNotNull("AnsRegistration was not created", registration);
assertNotNull("AnsProperties was not created", properties);
assertNotNull("AnsAutoServiceRegistration was not created",
ansAutoServiceRegistration);
assertThat(registration).isNotNull();
assertThat(properties).isNotNull();
assertThat(ansAutoServiceRegistration).isNotNull();
checkoutAnsDiscoveryServiceIP();
}
private void checkoutAnsDiscoveryServiceIP() {
assertEquals("AnsProperties service IP was wrong",
getIPFromNetworkInterface(TestConfig.netWorkInterfaceName),
registration.getHost());
assertThat(registration.getHost())
.isEqualTo(getIPFromNetworkInterface(TestConfig.netWorkInterfaceName));
}
private String getIPFromNetworkInterface(String networkInterface) {
@@ -143,6 +141,7 @@ public class AnsAutoServiceRegistrationIpNetworkInterfaceTests {
}
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,12 +16,12 @@
package com.alibaba.alicloud.ans.registry;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import com.alibaba.alicloud.ans.AnsAutoConfiguration;
import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration;
import com.alibaba.alicloud.context.ans.AnsProperties;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
@@ -30,22 +30,22 @@ import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationC
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import com.alibaba.alicloud.ans.AnsAutoConfiguration;
import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration;
import com.alibaba.alicloud.context.ans.AnsProperties;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
/**
* @author xiaojing
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = AnsAutoServiceRegistrationIpTests.TestConfig.class, properties = {
"spring.application.name=myTestService1",
"spring.cloud.alicloud.ans.client-domains=myTestService2",
"spring.cloud.alicloud.ans.server-list=127.0.0.1",
"spring.cloud.alicloud.ans.client-weight=2",
"spring.cloud.alicloud.ans.server-port=8080",
"spring.cloud.alicloud.ans.client-ip=123.123.123.123" }, webEnvironment = RANDOM_PORT)
@SpringBootTest(classes = AnsAutoServiceRegistrationIpTests.TestConfig.class,
properties = { "spring.application.name=myTestService1",
"spring.cloud.alicloud.ans.client-domains=myTestService2",
"spring.cloud.alicloud.ans.server-list=127.0.0.1",
"spring.cloud.alicloud.ans.client-weight=2",
"spring.cloud.alicloud.ans.server-port=8080",
"spring.cloud.alicloud.ans.client-ip=123.123.123.123" },
webEnvironment = RANDOM_PORT)
public class AnsAutoServiceRegistrationIpTests {
@Autowired
@@ -60,10 +60,9 @@ public class AnsAutoServiceRegistrationIpTests {
@Test
public void contextLoads() throws Exception {
assertNotNull("AnsRegistration was not created", registration);
assertNotNull("AnsProperties was not created", properties);
assertNotNull("AnsAutoServiceRegistration was not created",
ansAutoServiceRegistration);
assertThat(registration).isNotNull();
assertThat(properties).isNotNull();
assertThat(ansAutoServiceRegistration).isNotNull();
checkoutAnsDiscoveryServiceIP();
checkoutAnsDiscoveryServiceName();
@@ -71,17 +70,15 @@ public class AnsAutoServiceRegistrationIpTests {
}
private void checkoutAnsDiscoveryServiceIP() {
assertEquals("AnsProperties service IP was wrong", "123.123.123.123",
registration.getHost());
assertThat(registration.getHost()).isEqualTo("123.123.123.123");
}
private void checkoutAnsDiscoveryServiceName() {
assertEquals("AnsDiscoveryProperties service name was wrong", "myTestService2",
properties.getClientDomains());
assertThat(properties.getClientDomains()).isEqualTo("myTestService2");
}
private void checkoutAnsDiscoveryWeight() {
assertEquals(2L, properties.getClientWeight(), 0);
assertThat(properties.getClientWeight()).isEqualTo(2L);
}
@Configuration
@@ -89,5 +86,7 @@ public class AnsAutoServiceRegistrationIpTests {
@ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class,
AnsDiscoveryClientAutoConfiguration.class, AnsAutoConfiguration.class })
public static class TestConfig {
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,12 +16,12 @@
package com.alibaba.alicloud.ans.registry;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import com.alibaba.alicloud.ans.AnsAutoConfiguration;
import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration;
import com.alibaba.alicloud.context.ans.AnsProperties;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
@@ -30,20 +30,21 @@ import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationC
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import com.alibaba.alicloud.ans.AnsAutoConfiguration;
import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration;
import com.alibaba.alicloud.context.ans.AnsProperties;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
/**
* @author xiaojing
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = AnsAutoServiceRegistrationManagementPortTests.TestConfig.class, properties = {
"spring.application.name=myTestService1", "management.server.port=8888",
"management.server.servlet.context-path=/test-context-path",
"spring.cloud.alicloud.ans.server-list=127.0.0.1",
"spring.cloud.alicloud.ans.server-port=8080" }, webEnvironment = RANDOM_PORT)
@SpringBootTest(classes = AnsAutoServiceRegistrationManagementPortTests.TestConfig.class,
properties = { "spring.application.name=myTestService1",
"management.server.port=8888",
"management.server.servlet.context-path=/test-context-path",
"spring.cloud.alicloud.ans.server-list=127.0.0.1",
"spring.cloud.alicloud.ans.server-port=8080" },
webEnvironment = RANDOM_PORT)
public class AnsAutoServiceRegistrationManagementPortTests {
@Autowired
@@ -58,23 +59,20 @@ public class AnsAutoServiceRegistrationManagementPortTests {
@Test
public void contextLoads() throws Exception {
assertNotNull("AnsRegistration was not created", registration);
assertNotNull("AnsProperties was not created", properties);
assertNotNull("AnsAutoServiceRegistration was not created",
ansAutoServiceRegistration);
assertThat(registration).isNotNull();
assertThat(properties).isNotNull();
assertThat(ansAutoServiceRegistration).isNotNull();
checkoutNacosDiscoveryManagementData();
}
private void checkoutNacosDiscoveryManagementData() {
assertEquals("AnsProperties management port was wrong", "8888",
properties.getClientMetadata().get(AnsRegistration.MANAGEMENT_PORT));
assertEquals("AnsProperties management context path was wrong",
"/test-context-path", properties.getClientMetadata()
.get(AnsRegistration.MANAGEMENT_CONTEXT_PATH));
assertThat(properties.getClientMetadata().get(AnsRegistration.MANAGEMENT_PORT))
.isEqualTo("8888");
assertThat(properties.getClientMetadata()
.get(AnsRegistration.MANAGEMENT_CONTEXT_PATH))
.isEqualTo("/test-context-path");
}
@Configuration
@@ -82,5 +80,7 @@ public class AnsAutoServiceRegistrationManagementPortTests {
@ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class,
AnsDiscoveryClientAutoConfiguration.class, AnsAutoConfiguration.class })
public static class TestConfig {
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,12 +16,12 @@
package com.alibaba.alicloud.ans.registry;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import com.alibaba.alicloud.ans.AnsAutoConfiguration;
import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration;
import com.alibaba.alicloud.context.ans.AnsProperties;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
@@ -30,20 +30,20 @@ import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationC
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import com.alibaba.alicloud.ans.AnsAutoConfiguration;
import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration;
import com.alibaba.alicloud.context.ans.AnsProperties;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
/**
* @author xiaojing
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = AnsAutoServiceRegistrationPortTests.TestConfig.class, properties = {
"spring.application.name=myTestService1",
"spring.cloud.alicloud.ans.server-list=127.0.0.1",
"spring.cloud.alicloud.ans.server-port=8080",
"spring.cloud.alicloud.ans.client-port=8888" }, webEnvironment = RANDOM_PORT)
@SpringBootTest(classes = AnsAutoServiceRegistrationPortTests.TestConfig.class,
properties = { "spring.application.name=myTestService1",
"spring.cloud.alicloud.ans.server-list=127.0.0.1",
"spring.cloud.alicloud.ans.server-port=8080",
"spring.cloud.alicloud.ans.client-port=8888" },
webEnvironment = RANDOM_PORT)
public class AnsAutoServiceRegistrationPortTests {
@Autowired
@@ -58,19 +58,16 @@ public class AnsAutoServiceRegistrationPortTests {
@Test
public void contextLoads() throws Exception {
assertNotNull("AnsRegistration was not created", registration);
assertNotNull("AnsDiscoveryProperties was not created", properties);
assertNotNull("AnsAutoServiceRegistration was not created",
ansAutoServiceRegistration);
assertThat(registration).isNotNull();
assertThat(properties).isNotNull();
assertThat(ansAutoServiceRegistration).isNotNull();
checkoutAnsDiscoveryServicePort();
}
private void checkoutAnsDiscoveryServicePort() {
assertEquals("AnsDiscoveryProperties service Port was wrong", 8888,
registration.getPort());
assertThat(registration.getPort()).isEqualTo(8888);
}
@Configuration
@@ -78,5 +75,7 @@ public class AnsAutoServiceRegistrationPortTests {
@ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class,
AnsDiscoveryClientAutoConfiguration.class, AnsAutoConfiguration.class })
public static class TestConfig {
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,18 +16,20 @@
package com.alibaba.alicloud.ans.registry;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.alibaba.alicloud.ans.AnsAutoConfiguration;
import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration;
import com.alibaba.alicloud.ans.endpoint.AnsEndpoint;
import com.alibaba.alicloud.context.ans.AnsProperties;
import com.alibaba.ans.core.NamingService;
import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
@@ -38,24 +40,21 @@ import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import com.alibaba.alicloud.ans.AnsAutoConfiguration;
import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration;
import com.alibaba.alicloud.ans.endpoint.AnsEndpoint;
import com.alibaba.alicloud.context.ans.AnsProperties;
import com.alibaba.ans.core.NamingService;
import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
/**
* @author xiaojing
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = AnsAutoServiceRegistrationTests.TestConfig.class, properties = {
"spring.application.name=myTestService1",
"spring.cloud.alicloud.ans.server-list=127.0.0.1",
"spring.cloud.alicloud.ans.server-port=8080",
"spring.cloud.alicloud.ans.secure=true",
"spring.cloud.alicloud.ans.endpoint=test-endpoint" }, webEnvironment = RANDOM_PORT)
@SpringBootTest(classes = AnsAutoServiceRegistrationTests.TestConfig.class,
properties = { "spring.application.name=myTestService1",
"spring.cloud.alicloud.ans.server-list=127.0.0.1",
"spring.cloud.alicloud.ans.server-port=8080",
"spring.cloud.alicloud.ans.secure=true",
"spring.cloud.alicloud.ans.endpoint=test-endpoint" },
webEnvironment = RANDOM_PORT)
public class AnsAutoServiceRegistrationTests {
@Autowired
@@ -76,10 +75,9 @@ public class AnsAutoServiceRegistrationTests {
@Test
public void contextLoads() throws Exception {
assertNotNull("AnsRegistration was not created", registration);
assertNotNull("AnsProperties was not created", properties);
assertNotNull("AnsAutoServiceRegistration was not created",
ansAutoServiceRegistration);
assertThat(registration).isNotNull();
assertThat(properties).isNotNull();
assertThat(ansAutoServiceRegistration).isNotNull();
checkoutAnsDiscoveryServerList();
checkoutAnsDiscoveryServerPort();
@@ -96,45 +94,39 @@ public class AnsAutoServiceRegistrationTests {
}
private void checkAutoRegister() {
assertTrue("Ans Auto Registration was not start",
ansAutoServiceRegistration.isRunning());
assertThat(ansAutoServiceRegistration.isRunning()).isEqualTo(Boolean.TRUE);
}
private void checkoutAnsDiscoveryServerList() {
assertEquals("AnsDiscoveryProperties server list was wrong", "127.0.0.1",
properties.getServerList());
assertThat(properties.getServerList()).isEqualTo("127.0.0.1");
}
private void checkoutAnsDiscoveryServerPort() {
assertEquals("AnsDiscoveryProperties server port was wrong", "8080",
properties.getServerPort());
assertThat(properties.getServerPort()).isEqualTo("8080");
}
private void checkoutAnsDiscoveryServiceName() {
assertEquals("AnsDiscoveryProperties service name was wrong", "myTestService1",
properties.getClientDomains());
assertThat(properties.getClientDomains()).isEqualTo("myTestService1");
}
private void checkoutAnsDiscoveryServiceIP() {
assertEquals("AnsDiscoveryProperties service IP was wrong",
inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(),
registration.getHost());
assertThat(registration.getHost())
.isEqualTo(inetUtils.findFirstNonLoopbackHostInfo().getIpAddress());
}
private void checkoutAnsDiscoveryServicePort() {
assertEquals("AnsDiscoveryProperties service Port was wrong", port,
registration.getPort());
assertThat(registration.getPort()).isEqualTo(port);
}
private void checkoutAnsDiscoverySecure() {
assertTrue("AnsDiscoveryProperties secure should be true", properties.isSecure());
assertThat(properties.isSecure()).isEqualTo(Boolean.TRUE);
}
private void checkoutEndpoint() throws Exception {
AnsEndpoint ansEndpoint = new AnsEndpoint(properties);
Map<String, Object> map = ansEndpoint.invoke();
assertEquals(map.get("ansProperties"), properties);
assertThat(properties).isEqualTo(map.get("ansProperties"));
Map<String, Object> subscribes = new HashMap<>();
Set<String> subscribeServices = NamingService.getDomsSubscribed();
@@ -148,7 +140,7 @@ public class AnsAutoServiceRegistrationTests {
}
}
assertEquals(map.get("subscribes"), subscribes);
assertThat(subscribes).isEqualTo(map.get("subscribes"));
}
@Configuration
@@ -156,5 +148,7 @@ public class AnsAutoServiceRegistrationTests {
@ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class,
AnsDiscoveryClientAutoConfiguration.class, AnsAutoConfiguration.class })
public static class TestConfig {
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,11 +16,13 @@
package com.alibaba.alicloud.ans.ribbon;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import com.alibaba.alicloud.ans.AnsAutoConfiguration;
import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration;
import com.netflix.client.config.DefaultClientConfigImpl;
import com.netflix.client.config.IClientConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
@@ -32,21 +34,19 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;
import com.alibaba.alicloud.ans.AnsAutoConfiguration;
import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration;
import com.netflix.client.config.DefaultClientConfigImpl;
import com.netflix.client.config.IClientConfig;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
/**
* @author xiaojing
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = AnsRibbonClientConfigurationTests.TestConfig.class, properties = {
"spring.application.name=myTestService1",
"spring.cloud.alicloud.ans.server-list=127.0.0.1",
"spring.cloud.alicloud.ans.server-port=8080",
"spring.cloud.alicloud.ans.endpoint=test-endpoint" }, webEnvironment = RANDOM_PORT)
@SpringBootTest(classes = AnsRibbonClientConfigurationTests.TestConfig.class,
properties = { "spring.application.name=myTestService1",
"spring.cloud.alicloud.ans.server-list=127.0.0.1",
"spring.cloud.alicloud.ans.server-port=8080",
"spring.cloud.alicloud.ans.endpoint=test-endpoint" },
webEnvironment = RANDOM_PORT)
public class AnsRibbonClientConfigurationTests {
@Autowired
@@ -82,6 +82,7 @@ public class AnsRibbonClientConfigurationTests {
AnsRibbonTestConfiguration.class, RibbonAnsAutoConfiguration.class,
AnsRibbonClientConfiguration.class })
public static class TestConfig {
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,18 +16,16 @@
package com.alibaba.alicloud.ans.ribbon;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import com.alibaba.alicloud.ans.test.AnsMockTest;
import com.alibaba.ans.core.NamingService;
import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host;
import com.netflix.client.config.IClientConfig;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -35,11 +33,11 @@ import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import com.alibaba.alicloud.ans.test.AnsMockTest;
import com.alibaba.ans.core.NamingService;
import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host;
import com.netflix.client.config.IClientConfig;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* @author xiaojing
@@ -139,4 +137,5 @@ public class AnsServerListTests {
assertThat(servers.get(0).getHealthService().isValid()).isEqualTo(true);
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,20 +16,16 @@
package com.alibaba.alicloud.ans.ribbon;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import java.util.Arrays;
import java.util.List;
import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host;
import com.netflix.loadbalancer.Server;
import org.junit.Test;
import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host;
import com.netflix.loadbalancer.Server;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* @author xiaolongzuo
@@ -44,19 +40,18 @@ public class AnsServiceListTests {
public void testAnsServer() {
AnsServerList serverList = getAnsServerList();
List<AnsServer> servers = serverList.getInitialListOfServers();
assertNotNull("servers was null", servers);
assertEquals("servers was not size 1", 1, servers.size());
assertThat(servers).isNotNull();
assertThat(servers.size()).isEqualTo(1);
Server des = assertAnsServer(servers);
assertEquals("hostPort was wrong", IP_ADDR + ":" + PORT, des.getHostPort());
assertThat(des.getHostPort()).isEqualTo(IP_ADDR + ":" + PORT);
}
protected Server assertAnsServer(List<AnsServer> servers) {
Server actualServer = servers.get(0);
assertTrue("server was not a DomainExtractingServer",
actualServer instanceof AnsServer);
assertThat(actualServer instanceof AnsServer).isEqualTo(Boolean.TRUE);
AnsServer des = AnsServer.class.cast(actualServer);
assertNotNull("host is null", des.getHealthService());
assertEquals("unit was wrong", "DEFAULT", des.getHealthService().getUnit());
assertThat(des.getHealthService()).isNotNull();
assertThat(des.getHealthService().getUnit()).isEqualTo("DEFAULT");
return des;
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2018 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -42,4 +42,5 @@ public class AnsMockTest {
host.setHostname(serviceName);
return host;
}
}