Fixed tokenization to handle multi-level sign

This commit is contained in:
andsel
2012-08-03 17:34:16 +02:00
parent 3be3f614c2
commit bf1db7b207
2 changed files with 30 additions and 2 deletions
@@ -85,10 +85,18 @@ public class SubscriptionsStore {
String s = splitted[i];
if (s.isEmpty()) {
if (i != 0){
throw new ParseException("Bad format of topic, expetec toppic name between separators", i);
throw new ParseException("Bad format of topic, expetec topic name between separators", i);
}
res.add(Token.EMPTY);
} else {
} else if (s.equals("#")) {
//check that multi is the last symbol
if (i != splitted.length - 1 ) {
throw new ParseException("Bad format of topic, the multi symbol (#) has to be the last one after a separator", i);
}
res.add(Token.MULTI);
} else if (s.contains("#")) {
throw new ParseException("Bad format of topic, invalid subtopic name: " + s, i);
}else {
res.add(new Token(s));
}
}
@@ -39,6 +39,26 @@ public class SubscriptionsStoreTest {
store.splitTopic("/finance//stock/ibm");
}
@Test
public void testSplitTopicMultiValid() throws ParseException {
List tokens = store.splitTopic("finance/stock/#");
assertEqualsSeq(asArray("finance", "stock", Token.MULTI), tokens);
tokens = store.splitTopic("#");
assertEqualsSeq(asArray(Token.MULTI), tokens);
}
@Test(expected = ParseException.class)
public void testSplitTopicMultiInTheMiddleNotValid() throws ParseException {
store.splitTopic("finance/#/closingprice");
}
@Test(expected = ParseException.class)
public void testSplitTopicMultiNotAferSeparatorNotValid() throws ParseException {
store.splitTopic("finance#");
}
private static Token[] asArray(Object... l) {
Token[] tokens = new Token[l.length];
for (int i = 0; i < l.length; i++) {