Skip to content
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

Merged
merged 6 commits into from
Dec 5, 2020
Merged

Add test cases for soul-admin HttpSyncProperties #544

merged 6 commits into from
Dec 5, 2020

Conversation

onlyonezhongjinhui
Copy link
Contributor

No description provided.

Copy link
Member

@dengliming dengliming left a 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-io
Copy link

codecov-io commented Dec 5, 2020

Codecov Report

Merging #544 (92cbf1e) into master (45287d3) will increase coverage by 0.06%.
The diff coverage is n/a.

Impacted file tree graph

@@             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              
Impacted Files Coverage Δ Complexity Δ
.../dromara/soul/admin/config/HttpSyncProperties.java 100.00% <0.00%> (+100.00%) 1.00% <0.00%> (+1.00%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 45287d3...92cbf1e. Read the comment docs.

@dengliming dengliming added this to the 2.3.0 milestone Dec 5, 2020
@dengliming dengliming merged commit 2c23fe8 into apache:master Dec 5, 2020
@onlyonezhongjinhui onlyonezhongjinhui deleted the #508 branch December 5, 2020 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants