Add Nacos import check integration tests.

pull/2427/head
Freeman Lau 3 years ago
parent 7fd4e73e4a
commit d2e88157dc

@ -30,7 +30,7 @@ import org.springframework.cloud.client.ServiceInstance;
* Cache serviceIds and corresponding instances in Nacos.
*
* @author freeman
* @since 2022.0
* @since 2021.0.1.0
*/
public final class ServiceCache {

@ -16,7 +16,6 @@
package com.alibaba.cloud.tests.nacos.config;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@ -27,8 +26,4 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
@EnableConfigurationProperties(UserProperties.class)
public class NacosConfigTestApplication {
public static void main(String[] args) {
SpringApplication.run(NacosConfigTestApplication.class, args);
}
}

@ -42,7 +42,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
* @author freeman
*/
@HasDockerAndItEnabled
@SpringBootTest(webEnvironment = RANDOM_PORT, properties = {
@SpringBootTest(classes = NacosConfigTestApplication.class, webEnvironment = RANDOM_PORT, properties = {
"spring.profiles.active=nacos-config-refresh"
})
@Import(PushConfigConfiguration.class)

@ -0,0 +1,55 @@
/*
* Copyright 2013-2022 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
*
* 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,
* 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.alibaba.cloud.tests.nacos.config;
import com.alibaba.cloud.testsupport.HasDockerAndItEnabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.builder.SpringApplicationBuilder;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.springframework.cloud.commons.ConfigDataMissingEnvironmentPostProcessor.ImportException;
/**
*
* @author freeman
*/
@HasDockerAndItEnabled
public class NacosImportCheckTest {
@Test
public void testImportCheckEnabled() {
assertThatExceptionOfType(ImportException.class).isThrownBy(
() -> new SpringApplicationBuilder(NacosConfigTestApplication.class)
.properties("server.port=0")
.properties("spring.application.name=import-check-enabled")
.run());
}
@Test
public void testImportCheckDisabled() {
assertThatCode(
() -> new SpringApplicationBuilder(NacosConfigTestApplication.class)
.properties("server.port=0")
.properties("spring.application.name=import-check-disabled")
.properties(
"spring.cloud.nacos.config.import-check.enabled=false")
.run()).doesNotThrowAnyException();
}
}
Loading…
Cancel
Save