Skip to content

Commit 07e4456

Browse files
committed
Merge pull request #224 from surevine/issues/220
Add tests for loading autosubscribe channels. Fixes #220.
2 parents b7e7f62 + 30c7f1b commit 07e4456

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

src/main/java/org/buddycloud/channelserver/Configuration.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ private Configuration() {
6464
}
6565
} catch (Exception e) {
6666
LOGGER.error("Could not load " + CONFIGURATION_FILE + "!");
67-
System.out.println(e.getLocalizedMessage());
6867
System.exit(1);
6968
}
7069
}
@@ -92,6 +91,10 @@ public static Configuration getInstance() {
9291
public String getProperty(String key) {
9392
return conf.getProperty(key);
9493
}
94+
95+
public void clear() {
96+
conf.clear();
97+
}
9598

9699
public String getProperty(String key, String defaultValue) {
97100
return conf.getProperty(key, defaultValue);
@@ -113,12 +116,17 @@ private Collection<String> getStringArrayProperty(String key) {
113116
}
114117

115118
private Collection<JID> getJIDArrayProperty(String key) {
119+
System.out.println(conf.getProperty(CONFIGURATION_CHANNELS_AUTOSUBSCRIBE));
116120
Collection<String> props = getStringArrayProperty(key);
117121

118122
Collection<JID> jids = new ArrayList<JID>(props.size());
119123

120124
for (String prop : props) {
121-
jids.add(new JID(prop));
125+
try {
126+
jids.add(new JID(prop));
127+
} catch (IllegalArgumentException e) {
128+
LOGGER.error(e);
129+
}
122130
}
123131

124132
return jids;
@@ -171,4 +179,4 @@ public boolean getBooleanProperty(final String key,
171179

172180
return defaultValue;
173181
}
174-
}
182+
}

src/test/java/org/buddycloud/channelserver/ConfigurationTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.junit.Test;
1111
import org.xmpp.packet.JID;
1212

13+
import org.apache.commons.io.IOUtils;
14+
1315
public class ConfigurationTest {
1416

1517
private static final String CONFIGURATION_PROPERTIES = "src/test/resources/configuration.properties";
@@ -35,5 +37,31 @@ public void testGetAutoSubscribeChannels() {
3537
assertTrue("channel1@server1 not found", channels.contains(new JID("channel1@server1")));
3638
assertTrue("channel2@server1 not found", channels.contains(new JID("channel2@server1")));
3739
}
40+
41+
@Test
42+
public void handlesNoEntryForAutosubscribeChannels() throws Exception {
43+
44+
configuration.clear();
45+
configuration.load(IOUtils.toInputStream(
46+
Configuration.CONFIGURATION_SERVER_DOMAIN + "=domain.com\n"
47+
));
48+
assertEquals(0, configuration.getAutosubscribeChannels().size());
49+
}
50+
51+
@Test
52+
public void handlesIllegalAutosubscribeChannels() throws Exception {
53+
String configurationString = "" +
54+
Configuration.CONFIGURATION_CHANNELS_AUTOSUBSCRIBE + "=not-a-jid$$\n";
55+
configuration.load(IOUtils.toInputStream(configurationString));
56+
assertEquals(0, configuration.getAutosubscribeChannels().size());
57+
}
58+
59+
@Test
60+
public void handlesNullAutosubscribeChannelsValue() throws Exception {
61+
String configurationString = "" +
62+
Configuration.CONFIGURATION_CHANNELS_AUTOSUBSCRIBE + "=\n";
63+
configuration.load(IOUtils.toInputStream(configurationString));
64+
assertEquals(0, configuration.getAutosubscribeChannels().size());
65+
}
3866

3967
}

0 commit comments

Comments
 (0)