-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* bean on switch smoke test * fix format * fix format --------- Co-authored-by: yuanxuan <wt150181@antgroup.com>
- Loading branch information
Showing
9 changed files
with
208 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
sofa-boot-project/sofa-boot/src/main/resources/sofa-boot/scenes/function.properties
This file was deleted.
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
...test/java/com/alipay/sofa/boot/initializer/SampleSwitchSpringContextInitializerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* 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.alipay.sofa.boot.initializer; | ||
|
||
import com.alipay.sofa.boot.Initializer.SwitchableApplicationContextInitializer; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.core.env.Profiles; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* @author yuanxuan | ||
* @version : SampleSwitchSpringContextInitializerTests.java, v 0.1 2023年02月22日 11:30 yuanxuan Exp $ | ||
*/ | ||
public class SampleSwitchSpringContextInitializerTests { | ||
|
||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() | ||
.withInitializer(new SampleSwitchSpringContextInitializer()); | ||
|
||
@Test | ||
void enableFalse() { | ||
contextRunner.withPropertyValues("sofa.boot.switch.initializer.sampleswitchabletest.enabled=false").run(context -> { | ||
assertThat(context.getEnvironment().acceptsProfiles(Profiles.of("sampleswitchtest"))).isFalse(); | ||
}); | ||
} | ||
|
||
static class SampleSwitchSpringContextInitializer extends | ||
SwitchableApplicationContextInitializer { | ||
|
||
@Override | ||
protected void doInitialize(ConfigurableApplicationContext applicationContext) { | ||
applicationContext.getEnvironment().addActiveProfile("sampleswitchtest"); | ||
} | ||
|
||
@Override | ||
protected String switchKey() { | ||
return CONFIG_KEY_PREFIX + "sampleswitchabletest"; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,4 @@ | |
</dependency> | ||
</dependencies> | ||
|
||
</project> | ||
</project> |
23 changes: 23 additions & 0 deletions
23
...oke-tests/sofa-boot-smoke-tests-boot/src/main/resources/config/application-dev.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You 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 | ||
# | ||
# 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. | ||
# | ||
|
||
spring.config.activate.on-profile=function | ||
|
||
sofa.boot.switch.bean.functionBean.enabled=true | ||
|
||
|
||
|
23 changes: 23 additions & 0 deletions
23
...ests/sofa-boot-smoke-tests-boot/src/main/resources/config/application-function.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You 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 | ||
# | ||
# 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. | ||
# | ||
|
||
spring.config.activate.on-profile=function | ||
|
||
sofa.boot.switch.bean.functionBean.enabled=false | ||
|
||
|
||
|
19 changes: 19 additions & 0 deletions
19
...t-smoke-tests/sofa-boot-smoke-tests-boot/src/main/resources/config/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,25 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You 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 | ||
# | ||
# 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. | ||
# | ||
|
||
spring.application.name=smoke-tests-boot | ||
logging.path=./logs | ||
logging.level.com.alipay.test=INFO | ||
logging.level.com.test.demo=WARN | ||
|
||
any.key=any.value | ||
|
||
|
77 changes: 77 additions & 0 deletions
77
...tests-boot/src/test/java/com/alipay/sofa/smoke/tests/boot/SofaConditionOnSwitchTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* 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.alipay.sofa.smoke.tests.boot; | ||
|
||
import com.alipay.sofa.boot.autoconfigure.condition.ConditionalOnSwitch; | ||
import com.alipay.sofa.smoke.tests.boot.SofaConditionOnSwitchTests.BeanTestConfiguration; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatNoException; | ||
import static org.assertj.core.api.Assertions.catchException; | ||
|
||
/** | ||
* @author yuanxuan | ||
* @version : SofaConditionOnSwitchTests.java, v 0.1 2023年02月22日 10:09 yuanxuan Exp $ | ||
*/ | ||
@SpringBootTest(classes = { BootSofaBootApplication.class, BeanTestConfiguration.class }, properties = { "spring.profiles.active=function" }) | ||
public class SofaConditionOnSwitchTests { | ||
|
||
@Autowired | ||
private ApplicationContext context; | ||
|
||
@Test | ||
void beanSwitchOnScene() { | ||
assertThat(catchException(() -> { | ||
context.getBean(FunctionBean.class); | ||
})).hasMessage("No qualifying bean of type 'com.alipay.sofa.smoke.tests.boot.SofaConditionOnSwitchTests$FunctionBean' " | ||
+ "available"); | ||
assertThatNoException().isThrownBy(() -> { | ||
context.getBean(FunctionFeatureBean.class); | ||
}); | ||
} | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
@ConditionalOnSwitch | ||
static class BeanTestConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnSwitch | ||
public FunctionBean functionBean() { | ||
return new FunctionBean(); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnSwitch | ||
public FunctionFeatureBean functionFeatureBean() { | ||
return new FunctionFeatureBean(); | ||
} | ||
} | ||
|
||
static class FunctionBean { | ||
|
||
} | ||
|
||
static class FunctionFeatureBean { | ||
|
||
} | ||
} |