-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test cases for soul-admin HttpSyncProperties #544
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey~ these cases only cover the default config and It's too simple. I also want to test the @ConfigurationProperties(prefix = "soul-.sync.http ")
configuration which can be dynamically modified. here is my simple example. If that makes sense to you, check it out. Thanks.
Click to expand
import org.dromara.soul.admin.config.HttpSyncProperties;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.support.TestPropertySourceUtils;
import java.time.Duration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class HttpSyncPropertiesTest {
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@AfterEach
void cleanup() {
this.context.close();
}
@Test
public void testDefault() {
load(HttpSyncPropertiesConfiguration.class);
HttpSyncProperties httpSyncProperties = this.context.getBean(HttpSyncProperties.class);
assertTrue(httpSyncProperties.isEnabled());
assertEquals(Duration.ofMinutes(5), httpSyncProperties.getRefreshInterval());
}
@Test
public void testSpecified() {
load(HttpSyncPropertiesConfiguration.class, "soul.sync.http.enabled=false", "soul.sync.http.refreshInterval=4m");
HttpSyncProperties httpSyncProperties = this.context.getBean(HttpSyncProperties.class);
assertFalse(httpSyncProperties.isEnabled());
assertEquals(Duration.ofMinutes(4), httpSyncProperties.getRefreshInterval());
}
private AnnotationConfigApplicationContext load(Class<?> configuration, String... inlinedProperties) {
return load(new Class<?>[]{configuration}, inlinedProperties);
}
private AnnotationConfigApplicationContext load(Class<?>[] configuration, String... inlinedProperties) {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, inlinedProperties);
this.context.register(configuration);
this.context.refresh();
return this.context;
}
@Configuration
@EnableConfigurationProperties(HttpSyncProperties.class)
static class HttpSyncPropertiesConfiguration {
}
}
Codecov Report
@@ Coverage Diff @@
## master #544 +/- ##
============================================
+ Coverage 22.42% 22.48% +0.06%
- Complexity 373 374 +1
============================================
Files 197 197
Lines 4656 4656
Branches 496 496
============================================
+ Hits 1044 1047 +3
+ Misses 3511 3508 -3
Partials 101 101
Continue to review full report at Codecov.
|
No description provided.