|
2 | 2 |
|
3 | 3 | import org.apache.kafka.common.config.ConfigDef; |
4 | 4 | import org.apache.kafka.common.config.ConfigValue; |
| 5 | +import org.junit.Before; |
5 | 6 | import org.junit.Test; |
6 | 7 | import java.util.HashMap; |
7 | 8 | import java.util.Map; |
|
11 | 12 | public class GitHubSourceConnectorConfigTest { |
12 | 13 |
|
13 | 14 | private ConfigDef configDef = GitHubSourceConnectorConfig.conf(); |
14 | | - |
15 | | - private Map<String, String> initialConfig() { |
16 | | - Map<String, String> baseProps = new HashMap<>(); |
17 | | - baseProps.put(OWNER_CONFIG, "foo"); |
18 | | - baseProps.put(REPO_CONFIG, "bar"); |
19 | | - baseProps.put(SINCE_CONFIG, "2017-04-26T01:23:45Z"); |
20 | | - baseProps.put(BATCH_SIZE_CONFIG, "100"); |
21 | | - baseProps.put(TOPIC_CONFIG, "github-issues"); |
22 | | - return baseProps; |
| 15 | + private Map<String, String> config; |
| 16 | + |
| 17 | + @Before |
| 18 | + public void setUpInitialConfig() { |
| 19 | + config = new HashMap<>(); |
| 20 | + config.put(OWNER_CONFIG, "foo"); |
| 21 | + config.put(REPO_CONFIG, "bar"); |
| 22 | + config.put(SINCE_CONFIG, "2017-04-26T01:23:45Z"); |
| 23 | + config.put(BATCH_SIZE_CONFIG, "100"); |
| 24 | + config.put(TOPIC_CONFIG, "github-issues"); |
23 | 25 | } |
24 | 26 |
|
25 | | - |
26 | 27 | @Test |
27 | 28 | public void doc() { |
28 | 29 | System.out.println(GitHubSourceConnectorConfig.conf().toRst()); |
29 | 30 | } |
30 | 31 |
|
31 | 32 | @Test |
32 | 33 | public void initialConfigIsValid() { |
33 | | - assert (configDef.validate(initialConfig()) |
| 34 | + assert (configDef.validate(config) |
34 | 35 | .stream() |
35 | 36 | .allMatch(configValue -> configValue.errorMessages().size() == 0)); |
36 | 37 | } |
37 | 38 |
|
38 | 39 | @Test |
39 | 40 | public void canReadConfigCorrectly() { |
40 | | - GitHubSourceConnectorConfig config = new GitHubSourceConnectorConfig(initialConfig()); |
| 41 | + GitHubSourceConnectorConfig config = new GitHubSourceConnectorConfig(this.config); |
41 | 42 | config.getAuthPassword(); |
42 | 43 |
|
43 | 44 | } |
44 | 45 |
|
45 | | - |
46 | 46 | @Test |
47 | 47 | public void validateSince() { |
48 | | - Map<String, String> config = initialConfig(); |
49 | 48 | config.put(SINCE_CONFIG, "not-a-date"); |
50 | 49 | ConfigValue configValue = configDef.validateAll(config).get(SINCE_CONFIG); |
51 | 50 | assert (configValue.errorMessages().size() > 0); |
52 | 51 | } |
53 | 52 |
|
54 | 53 | @Test |
55 | 54 | public void validateBatchSize() { |
56 | | - Map<String, String> config = initialConfig(); |
57 | 55 | config.put(BATCH_SIZE_CONFIG, "-1"); |
58 | 56 | ConfigValue configValue = configDef.validateAll(config).get(BATCH_SIZE_CONFIG); |
59 | 57 | assert (configValue.errorMessages().size() > 0); |
60 | 58 |
|
61 | | - config = initialConfig(); |
62 | 59 | config.put(BATCH_SIZE_CONFIG, "101"); |
63 | 60 | configValue = configDef.validateAll(config).get(BATCH_SIZE_CONFIG); |
64 | 61 | assert (configValue.errorMessages().size() > 0); |
65 | | - |
66 | 62 | } |
67 | 63 |
|
68 | 64 | @Test |
69 | 65 | public void validateUsername() { |
70 | | - Map<String, String> config = initialConfig(); |
71 | 66 | config.put(AUTH_USERNAME_CONFIG, "username"); |
72 | 67 | ConfigValue configValue = configDef.validateAll(config).get(AUTH_USERNAME_CONFIG); |
73 | 68 | assert (configValue.errorMessages().size() == 0); |
74 | 69 | } |
75 | 70 |
|
76 | 71 | @Test |
77 | 72 | public void validatePassword() { |
78 | | - Map<String, String> config = initialConfig(); |
79 | 73 | config.put(AUTH_PASSWORD_CONFIG, "password"); |
80 | 74 | ConfigValue configValue = configDef.validateAll(config).get(AUTH_PASSWORD_CONFIG); |
81 | 75 | assert (configValue.errorMessages().size() == 0); |
|
0 commit comments