Merge pull request #261 from AndreasMager/adding-assertj
This commit is contained in:
@@ -136,6 +136,15 @@
|
||||
<version>9.2.0.M1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<!-- use 2.6.0 for Java 7 projects -->
|
||||
<version>2.6.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
|
||||
+130
-135
@@ -25,17 +25,16 @@ import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public class SubscriptionsStoreTest {
|
||||
|
||||
|
||||
private SubscriptionsStore store;
|
||||
private ISessionsStore sessionsStore;
|
||||
|
||||
@@ -50,58 +49,58 @@ public class SubscriptionsStoreTest {
|
||||
this.sessionsStore = storageService.sessionsStore();
|
||||
store.init(sessionsStore);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testParseTopic() throws ParseException {
|
||||
List<Token> tokens = store.parseTopic("finance/stock/ibm");
|
||||
assertEqualsSeq(asArray("finance", "stock", "ibm"), tokens);
|
||||
List<Token> tokens = SubscriptionsStore.parseTopic("finance/stock/ibm");
|
||||
assertThat(tokens).containsExactlyInAnyOrder(asArray("finance", "stock", "ibm"));
|
||||
|
||||
tokens = store.parseTopic("/finance/stock/ibm");
|
||||
assertEqualsSeq(asArray(Token.EMPTY, "finance", "stock", "ibm"), tokens);
|
||||
tokens = SubscriptionsStore.parseTopic("/finance/stock/ibm");
|
||||
assertThat(tokens).containsExactlyInAnyOrder(asArray(Token.EMPTY, "finance", "stock", "ibm"));
|
||||
|
||||
tokens = store.parseTopic("/");
|
||||
assertEqualsSeq(asArray(Token.EMPTY, Token.EMPTY), tokens);
|
||||
tokens = SubscriptionsStore.parseTopic("/");
|
||||
assertThat(tokens).containsExactlyInAnyOrder(asArray(Token.EMPTY, Token.EMPTY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseTopicMultiValid() throws ParseException {
|
||||
List<Token> tokens = store.parseTopic("finance/stock/#");
|
||||
assertEqualsSeq(asArray("finance", "stock", Token.MULTI), tokens);
|
||||
List<Token> tokens = SubscriptionsStore.parseTopic("finance/stock/#");
|
||||
assertThat(tokens).containsExactlyInAnyOrder(asArray("finance", "stock", Token.MULTI));
|
||||
|
||||
tokens = store.parseTopic("#");
|
||||
assertEqualsSeq(asArray(Token.MULTI), tokens);
|
||||
tokens = SubscriptionsStore.parseTopic("#");
|
||||
assertThat(tokens).containsExactlyInAnyOrder(asArray(Token.MULTI));
|
||||
}
|
||||
|
||||
@Test(expected = ParseException.class)
|
||||
public void testParseTopicMultiInTheMiddleNotValid() throws ParseException {
|
||||
store.parseTopic("finance/#/closingprice");
|
||||
SubscriptionsStore.parseTopic("finance/#/closingprice");
|
||||
}
|
||||
|
||||
@Test(expected = ParseException.class)
|
||||
public void testParseTopicMultiNotAfterSeparatorNotValid() throws ParseException {
|
||||
store.parseTopic("finance#");
|
||||
SubscriptionsStore.parseTopic("finance#");
|
||||
}
|
||||
|
||||
@Test(expected = ParseException.class)
|
||||
public void testParseTopicMultiNotAlone() throws ParseException {
|
||||
store.parseTopic("/finance/#closingprice");
|
||||
SubscriptionsStore.parseTopic("/finance/#closingprice");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseTopicSingleValid() throws ParseException {
|
||||
List<Token> tokens = store.parseTopic("finance/stock/+");
|
||||
assertEqualsSeq(asArray("finance", "stock", Token.SINGLE), tokens);
|
||||
List<Token> tokens = SubscriptionsStore.parseTopic("finance/stock/+");
|
||||
assertThat(tokens).containsExactlyInAnyOrder(asArray("finance", "stock", Token.SINGLE));
|
||||
|
||||
tokens = store.parseTopic("+");
|
||||
assertEqualsSeq(asArray(Token.SINGLE), tokens);
|
||||
tokens = SubscriptionsStore.parseTopic("+");
|
||||
assertThat(tokens).containsExactlyInAnyOrder(asArray(Token.SINGLE));
|
||||
|
||||
tokens = store.parseTopic("finance/+/ibm");
|
||||
assertEqualsSeq(asArray("finance", Token.SINGLE, "ibm"), tokens);
|
||||
tokens = SubscriptionsStore.parseTopic("finance/+/ibm");
|
||||
assertThat(tokens).containsExactlyInAnyOrder(asArray("finance", Token.SINGLE, "ibm"));
|
||||
}
|
||||
|
||||
@Test(expected = ParseException.class)
|
||||
public void testParseTopicSingleNotAferSeparatorNotValid() throws ParseException {
|
||||
store.parseTopic("finance+");
|
||||
SubscriptionsStore.parseTopic("finance+");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -109,30 +108,30 @@ public class SubscriptionsStoreTest {
|
||||
Subscription slashSub = new Subscription("FAKE_CLI_ID_1", "/", MqttQoS.AT_MOST_ONCE);
|
||||
sessionsStore.addNewSubscription(slashSub);
|
||||
store.add(slashSub.asClientTopicCouple());
|
||||
assertTrue(store.matches("finance").isEmpty());
|
||||
assertThat(store.matches("finance")).isEmpty();
|
||||
|
||||
Subscription slashFinanceSub = new Subscription("FAKE_CLI_ID_1", "/finance", MqttQoS.AT_MOST_ONCE);
|
||||
sessionsStore.addNewSubscription(slashFinanceSub);
|
||||
store.add(slashFinanceSub.asClientTopicCouple());
|
||||
assertTrue(store.matches("finance").isEmpty());
|
||||
|
||||
assertTrue(store.matches("/finance").contains(slashFinanceSub));
|
||||
assertTrue(store.matches("/").contains(slashSub));
|
||||
assertThat(store.matches("finance")).isEmpty();
|
||||
|
||||
assertThat(store.matches("/finance")).contains(slashFinanceSub);
|
||||
assertThat(store.matches("/")).contains(slashSub);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchSimpleMulti() {
|
||||
Subscription anySub = new Subscription("FAKE_CLI_ID_1", "#", MqttQoS.AT_MOST_ONCE);
|
||||
sessionsStore.addNewSubscription(anySub);
|
||||
store.add(anySub.asClientTopicCouple());
|
||||
assertTrue(store.matches("finance").contains(anySub));
|
||||
|
||||
assertThat(store.matches("finance")).contains(anySub);
|
||||
|
||||
Subscription financeAnySub = new Subscription("FAKE_CLI_ID_2", "finance/#", MqttQoS.AT_MOST_ONCE);
|
||||
sessionsStore.addNewSubscription(financeAnySub);
|
||||
store.add(financeAnySub.asClientTopicCouple());
|
||||
assertTrue(store.matches("finance").containsAll(Arrays.asList(financeAnySub, anySub)));
|
||||
assertThat(store.matches("finance")).containsExactlyInAnyOrder(financeAnySub, anySub);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchingDeepMulti_one_layer() {
|
||||
Subscription anySub = new Subscription("FAKE_CLI_ID_1", "#", MqttQoS.AT_MOST_ONCE);
|
||||
@@ -141,47 +140,47 @@ public class SubscriptionsStoreTest {
|
||||
sessionsStore.addNewSubscription(financeAnySub);
|
||||
store.add(anySub.asClientTopicCouple());
|
||||
store.add(financeAnySub.asClientTopicCouple());
|
||||
|
||||
|
||||
//Verify
|
||||
assertTrue(store.matches("finance/stock").containsAll(Arrays.asList(financeAnySub, anySub)));
|
||||
assertTrue(store.matches("finance/stock/ibm").containsAll(Arrays.asList(financeAnySub, anySub)));
|
||||
assertThat(store.matches("finance/stock")).containsExactlyInAnyOrder(financeAnySub, anySub);
|
||||
assertThat(store.matches("finance/stock/ibm")).containsExactlyInAnyOrder(financeAnySub, anySub);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchingDeepMulti_two_layer() {
|
||||
Subscription financeAnySub = new Subscription("FAKE_CLI_ID_1", "finance/stock/#", MqttQoS.AT_MOST_ONCE);
|
||||
sessionsStore.addNewSubscription(financeAnySub);
|
||||
store.add(financeAnySub.asClientTopicCouple());
|
||||
|
||||
|
||||
//Verify
|
||||
assertTrue(store.matches("finance/stock/ibm").contains(financeAnySub));
|
||||
assertThat(store.matches("finance/stock/ibm")).containsExactly(financeAnySub);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchSimpleSingle() {
|
||||
Subscription anySub = new Subscription("FAKE_CLI_ID_1", "+", MqttQoS.AT_MOST_ONCE);
|
||||
sessionsStore.addNewSubscription(anySub);
|
||||
store.add(anySub.asClientTopicCouple());
|
||||
assertTrue(store.matches("finance").contains(anySub));
|
||||
|
||||
assertThat(store.matches("finance")).containsExactly(anySub);
|
||||
|
||||
Subscription financeOne = new Subscription("FAKE_CLI_ID_1", "finance/+", MqttQoS.AT_MOST_ONCE);
|
||||
sessionsStore.addNewSubscription(financeOne);
|
||||
store.add(financeOne.asClientTopicCouple());
|
||||
assertTrue(store.matches("finance/stock").contains(financeOne));
|
||||
assertThat(store.matches("finance/stock")).containsExactly(financeOne);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchManySingle() {
|
||||
Subscription manySub = new Subscription("FAKE_CLI_ID_1", "+/+", MqttQoS.AT_MOST_ONCE);
|
||||
sessionsStore.addNewSubscription(manySub);
|
||||
store.add(manySub.asClientTopicCouple());
|
||||
|
||||
|
||||
//verify
|
||||
assertTrue(store.matches("/finance").contains(manySub));
|
||||
assertThat(store.matches("/finance")).contains(manySub);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchSlashSingle() {
|
||||
Subscription slashPlusSub = new Subscription("FAKE_CLI_ID_1", "/+", MqttQoS.AT_MOST_ONCE);
|
||||
@@ -190,26 +189,25 @@ public class SubscriptionsStoreTest {
|
||||
Subscription anySub = new Subscription("FAKE_CLI_ID_1", "+", MqttQoS.AT_MOST_ONCE);
|
||||
sessionsStore.addNewSubscription(anySub);
|
||||
store.add(anySub.asClientTopicCouple());
|
||||
|
||||
|
||||
//Verify
|
||||
assertEquals(1, store.matches("/finance").size());
|
||||
assertTrue(store.matches("/finance").contains(slashPlusSub));
|
||||
assertFalse(store.matches("/finance").contains(anySub));
|
||||
assertThat(store.matches("/finance")).containsOnly(slashPlusSub);
|
||||
assertThat(store.matches("/finance")).doesNotContain(anySub);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchManyDeepSingle() {
|
||||
Subscription slashPlusSub = new Subscription("FAKE_CLI_ID_1", "/finance/+/ibm", MqttQoS.AT_MOST_ONCE);
|
||||
sessionsStore.addNewSubscription(slashPlusSub);
|
||||
store.add(slashPlusSub.asClientTopicCouple());
|
||||
|
||||
|
||||
Subscription slashPlusDeepSub = new Subscription("FAKE_CLI_ID_2", "/+/stock/+", MqttQoS.AT_MOST_ONCE);
|
||||
sessionsStore.addNewSubscription(slashPlusDeepSub);
|
||||
store.add(slashPlusDeepSub.asClientTopicCouple());
|
||||
|
||||
|
||||
//Verify
|
||||
assertTrue(store.matches("/finance/stock/ibm").containsAll(Arrays.asList(slashPlusSub, slashPlusDeepSub)));
|
||||
assertThat(store.matches("/finance/stock/ibm")).containsExactlyInAnyOrder(slashPlusSub, slashPlusDeepSub);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -217,8 +215,8 @@ public class SubscriptionsStoreTest {
|
||||
Subscription sub = new Subscription("FAKE_CLI_ID_1", "#", MqttQoS.AT_MOST_ONCE);
|
||||
sessionsStore.addNewSubscription(sub);
|
||||
store.add(sub.asClientTopicCouple());
|
||||
assertFalse(store.matches("finance").isEmpty());
|
||||
assertFalse(store.matches("finance/ibm").isEmpty());
|
||||
assertThat(store.matches("finance")).isNotEmpty();
|
||||
assertThat(store.matches("finance/ibm")).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -227,9 +225,9 @@ public class SubscriptionsStoreTest {
|
||||
Subscription sub = new Subscription("FAKE_CLI_ID_1", "finance/#", MqttQoS.AT_MOST_ONCE);
|
||||
sessionsStore.addNewSubscription(sub);
|
||||
store.add(sub.asClientTopicCouple());
|
||||
assertFalse(store.matches("finance").isEmpty());
|
||||
assertThat(store.matches("finance")).isNotEmpty();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void rogerLightTopicMatches() {
|
||||
assertMatch("foo/bar", "foo/bar");
|
||||
@@ -253,7 +251,7 @@ public class SubscriptionsStoreTest {
|
||||
assertMatch("foo/+/+/baz", "foo///baz");
|
||||
assertMatch("foo/bar/+", "foo/bar/");
|
||||
}
|
||||
|
||||
|
||||
private void assertMatch(String subscription, String topic) {
|
||||
store = new SubscriptionsStore();
|
||||
MemoryStorageService memStore = new MemoryStorageService();
|
||||
@@ -263,9 +261,9 @@ public class SubscriptionsStoreTest {
|
||||
Subscription sub = new Subscription("FAKE_CLI_ID_1", subscription, MqttQoS.AT_MOST_ONCE);
|
||||
aSessionsStore.addNewSubscription(sub);
|
||||
store.add(sub.asClientTopicCouple());
|
||||
assertFalse(store.matches(topic).isEmpty());
|
||||
assertThat(store.matches(topic)).isNotEmpty();
|
||||
}
|
||||
|
||||
|
||||
private void assertNotMatch(String subscription, String topic) {
|
||||
store = new SubscriptionsStore();
|
||||
MemoryStorageService memStore = new MemoryStorageService();
|
||||
@@ -274,36 +272,36 @@ public class SubscriptionsStoreTest {
|
||||
Subscription sub = new Subscription("FAKE_CLI_ID_1", subscription, MqttQoS.AT_MOST_ONCE);
|
||||
sessionsStore.addNewSubscription(sub);
|
||||
store.add(sub.asClientTopicCouple());
|
||||
assertTrue(store.matches(topic).isEmpty());
|
||||
assertThat(store.matches(topic)).isEmpty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testRemoveClientSubscriptions_existingClientID() {
|
||||
String cliendID = "FAKE_CLID_1";
|
||||
Subscription sub = new Subscription(cliendID, "finance/#", MqttQoS.AT_MOST_ONCE);
|
||||
sessionsStore.addNewSubscription(sub);
|
||||
store.add(sub.asClientTopicCouple());
|
||||
|
||||
|
||||
//Exercise
|
||||
store.removeForClient(cliendID);
|
||||
|
||||
|
||||
//Verify
|
||||
assertEquals(0, store.size());
|
||||
assertThat(store.size()).isZero();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRemoveClientSubscriptions_notexistingClientID() {
|
||||
String clientID = "FAKE_CLID_1";
|
||||
Subscription s = new Subscription(clientID, "finance/#", MqttQoS.AT_MOST_ONCE);
|
||||
sessionsStore.addNewSubscription(s);
|
||||
store.add(s.asClientTopicCouple());
|
||||
|
||||
|
||||
//Exercise
|
||||
store.removeForClient("FAKE_CLID_2");
|
||||
|
||||
|
||||
//Verify
|
||||
assertEquals(1, store.size());
|
||||
assertThat(store.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -316,61 +314,61 @@ public class SubscriptionsStoreTest {
|
||||
store.add(specificSub.asClientTopicCouple());
|
||||
|
||||
//Verify
|
||||
assertEquals(1, store.matches("a/b").size());
|
||||
assertThat(store.matches("a/b").size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchTopics_simple() {
|
||||
assertTrue(SubscriptionsStore.matchTopics("/", "/"));
|
||||
assertTrue(SubscriptionsStore.matchTopics("/finance", "/finance"));
|
||||
assertThat(SubscriptionsStore.matchTopics("/", "/")).isTrue();
|
||||
assertThat(SubscriptionsStore.matchTopics("/finance", "/finance")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchTopics_multi() {
|
||||
assertTrue(SubscriptionsStore.matchTopics("finance", "#"));
|
||||
assertTrue(SubscriptionsStore.matchTopics("finance", "finance/#"));
|
||||
assertTrue(SubscriptionsStore.matchTopics("finance/stock", "finance/#"));
|
||||
assertTrue(SubscriptionsStore.matchTopics("finance/stock/ibm", "finance/#"));
|
||||
assertThat(SubscriptionsStore.matchTopics("finance", "#")).isTrue();
|
||||
assertThat(SubscriptionsStore.matchTopics("finance", "finance/#")).isTrue();
|
||||
assertThat(SubscriptionsStore.matchTopics("finance/stock", "finance/#")).isTrue();
|
||||
assertThat(SubscriptionsStore.matchTopics("finance/stock/ibm", "finance/#")).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchTopics_single() {
|
||||
assertTrue(SubscriptionsStore.matchTopics("finance", "+"));
|
||||
assertTrue(SubscriptionsStore.matchTopics("finance/stock", "finance/+"));
|
||||
assertFalse(SubscriptionsStore.matchTopics("finance", "finance/+"));
|
||||
assertTrue(SubscriptionsStore.matchTopics("/finance", "/+"));
|
||||
assertFalse(SubscriptionsStore.matchTopics("/finance", "+"));
|
||||
assertTrue(SubscriptionsStore.matchTopics("/finance", "+/+"));
|
||||
assertTrue(SubscriptionsStore.matchTopics("/finance/stock/ibm", "/finance/+/ibm"));
|
||||
assertTrue(SubscriptionsStore.matchTopics("/", "+/+"));
|
||||
assertTrue(SubscriptionsStore.matchTopics("sport/", "sport/+"));
|
||||
assertFalse(SubscriptionsStore.matchTopics("/finance/stock", "+"));
|
||||
assertThat(SubscriptionsStore.matchTopics("finance", "+")).isTrue();
|
||||
assertThat(SubscriptionsStore.matchTopics("finance/stock", "finance/+")).isTrue();
|
||||
assertThat(SubscriptionsStore.matchTopics("finance", "finance/+")).isFalse();
|
||||
assertThat(SubscriptionsStore.matchTopics("/finance", "/+")).isTrue();
|
||||
assertThat(SubscriptionsStore.matchTopics("/finance", "+")).isFalse();
|
||||
assertThat(SubscriptionsStore.matchTopics("/finance", "+/+")).isTrue();
|
||||
assertThat(SubscriptionsStore.matchTopics("/finance/stock/ibm", "/finance/+/ibm")).isTrue();
|
||||
assertThat(SubscriptionsStore.matchTopics("/", "+/+")).isTrue();
|
||||
assertThat(SubscriptionsStore.matchTopics("sport/", "sport/+")).isTrue();
|
||||
assertThat(SubscriptionsStore.matchTopics("/finance/stock", "+")).isFalse();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void rogerLightMatchTopics() {
|
||||
assertTrue(SubscriptionsStore.matchTopics("foo/bar", "foo/bar"));
|
||||
assertTrue(SubscriptionsStore.matchTopics("foo/bar", "foo/+"));
|
||||
assertTrue(SubscriptionsStore.matchTopics("foo/bar/baz", "foo/+/baz"));
|
||||
assertTrue(SubscriptionsStore.matchTopics("foo/bar/baz", "foo/+/#"));
|
||||
assertTrue(SubscriptionsStore.matchTopics("foo/bar/baz", "#"));
|
||||
|
||||
assertFalse(SubscriptionsStore.matchTopics("foo", "foo/bar"));
|
||||
assertFalse(SubscriptionsStore.matchTopics("foo/bar/baz", "foo/+"));
|
||||
assertFalse(SubscriptionsStore.matchTopics("foo/bar/bar", "foo/+/baz"));
|
||||
assertFalse(SubscriptionsStore.matchTopics("fo2/bar/baz", "foo/+/#"));
|
||||
|
||||
assertTrue(SubscriptionsStore.matchTopics("/foo/bar", "#"));
|
||||
assertTrue(SubscriptionsStore.matchTopics("/foo/bar", "/#"));
|
||||
assertFalse(SubscriptionsStore.matchTopics("foo/bar", "/#"));
|
||||
|
||||
assertTrue(SubscriptionsStore.matchTopics("foo//bar", "foo//bar"));
|
||||
assertTrue(SubscriptionsStore.matchTopics("foo//bar", "foo//+"));
|
||||
assertTrue(SubscriptionsStore.matchTopics("foo///baz", "foo/+/+/baz"));
|
||||
assertTrue(SubscriptionsStore.matchTopics("foo/bar/", "foo/bar/+"));
|
||||
assertThat(SubscriptionsStore.matchTopics("foo/bar", "foo/bar")).isTrue();
|
||||
assertThat(SubscriptionsStore.matchTopics("foo/bar", "foo/+")).isTrue();
|
||||
assertThat(SubscriptionsStore.matchTopics("foo/bar/baz", "foo/+/baz")).isTrue();
|
||||
assertThat(SubscriptionsStore.matchTopics("foo/bar/baz", "foo/+/#")).isTrue();
|
||||
assertThat(SubscriptionsStore.matchTopics("foo/bar/baz", "#")).isTrue();
|
||||
|
||||
assertThat(SubscriptionsStore.matchTopics("foo", "foo/bar")).isFalse();
|
||||
assertThat(SubscriptionsStore.matchTopics("foo/bar/baz", "foo/+")).isFalse();
|
||||
assertThat(SubscriptionsStore.matchTopics("foo/bar/bar", "foo/+/baz")).isFalse();
|
||||
assertThat(SubscriptionsStore.matchTopics("fo2/bar/baz", "foo/+/#")).isFalse();
|
||||
|
||||
assertThat(SubscriptionsStore.matchTopics("/foo/bar", "#")).isTrue();
|
||||
assertThat(SubscriptionsStore.matchTopics("/foo/bar", "/#")).isTrue();
|
||||
assertThat(SubscriptionsStore.matchTopics("foo/bar", "/#")).isFalse();
|
||||
|
||||
assertThat(SubscriptionsStore.matchTopics("foo//bar", "foo//bar")).isTrue();
|
||||
assertThat(SubscriptionsStore.matchTopics("foo//bar", "foo//+")).isTrue();
|
||||
assertThat(SubscriptionsStore.matchTopics("foo///baz", "foo/+/+/baz")).isTrue();
|
||||
assertThat(SubscriptionsStore.matchTopics("foo/bar/", "foo/bar/+")).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void removeSubscription_withDifferentClients_subscribedSameTopic() {
|
||||
SubscriptionsStore aStore = new SubscriptionsStore();
|
||||
@@ -388,13 +386,13 @@ public class SubscriptionsStoreTest {
|
||||
Subscription slashSub2 = new Subscription("FAKE_CLI_ID_2", "/topic", MqttQoS.AT_MOST_ONCE);
|
||||
sessionsStore.addNewSubscription(slashSub2);
|
||||
aStore.add(new ClientTopicCouple("FAKE_CLI_ID_2", "/topic"));
|
||||
|
||||
|
||||
//Exercise
|
||||
aStore.removeSubscription("/topic", slashSub2.getClientId());
|
||||
|
||||
|
||||
//Verify
|
||||
Subscription remainedSubscription = aStore.matches("/topic").get(0);
|
||||
assertEquals(slashSub.getClientId(), remainedSubscription.getClientId());
|
||||
assertThat(remainedSubscription.getClientId()).isEqualTo(slashSub.getClientId());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -419,12 +417,14 @@ public class SubscriptionsStoreTest {
|
||||
|
||||
//Verify
|
||||
List<Subscription> subscriptions = store.matches("client/test/b");
|
||||
assertTrue(subscriptions.contains(client1SubQoS2));
|
||||
assertTrue(subscriptions.contains(client2Sub));
|
||||
assertThat(subscriptions).contains(client1SubQoS2);
|
||||
assertThat(subscriptions).contains(client2Sub);
|
||||
|
||||
Subscription client1Sub = subscriptions.get(subscriptions.indexOf(client1SubQoS0));
|
||||
assertFalse(client1SubQoS0.getRequestedQos().equals(client1Sub.getRequestedQos()));
|
||||
assertEquals(client1SubQoS2.getRequestedQos(), client1Sub.getRequestedQos()); //client1SubQoS2 should override client1SubQoS0
|
||||
assertThat(client1SubQoS0.getRequestedQos()).isNotEqualTo(client1Sub.getRequestedQos());
|
||||
|
||||
//client1SubQoS2 should override client1SubQoS0
|
||||
assertThat(client1Sub.getRequestedQos()).isEqualTo(client1SubQoS2.getRequestedQos());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -433,10 +433,10 @@ public class SubscriptionsStoreTest {
|
||||
final SubscriptionsStore.NodeCouple resp = store.recreatePath("/finance", oldRoot);
|
||||
|
||||
//Verify
|
||||
assertNotNull(resp.root);
|
||||
assertNull(resp.root.m_token);
|
||||
assertEquals(1, resp.root.m_children.size());
|
||||
assertEquals(resp.createdNode, resp.root.m_children.get(0).m_children.get(0));
|
||||
assertThat(resp.root).isNotNull();
|
||||
assertThat(resp.root.m_token).isNull();
|
||||
assertThat(resp.root.m_children).hasSize(1);
|
||||
assertThat(resp.root.m_children.get(0).m_children).contains(resp.createdNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -446,11 +446,11 @@ public class SubscriptionsStoreTest {
|
||||
final SubscriptionsStore.NodeCouple respPlus = store.recreatePath("/+", respFinance.root);
|
||||
|
||||
//Verify
|
||||
assertNotNull(respPlus.root);
|
||||
assertNull(respPlus.root.m_token);
|
||||
assertEquals(1, respPlus.root.m_children.size());
|
||||
assertTrue(respPlus.root.m_children.get(0).m_children.contains(respPlus.createdNode));
|
||||
assertTrue(respPlus.root.m_children.get(0).m_children.contains(respFinance.createdNode));
|
||||
assertThat(respPlus.root).isNotNull();
|
||||
assertThat(respPlus.root.m_token).isNull();
|
||||
assertThat(respPlus.root.m_children.size()).isEqualTo(1);
|
||||
assertThat(respPlus.root.m_children.get(0).m_children).contains(respPlus.createdNode);
|
||||
assertThat(respPlus.root.m_children.get(0).m_children).contains(respFinance.createdNode);
|
||||
}
|
||||
|
||||
private static Token[] asArray(Object... l) {
|
||||
@@ -466,9 +466,4 @@ public class SubscriptionsStoreTest {
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
private void assertEqualsSeq(Token[] exptected, List<Token> result) {
|
||||
List<Token> expectedList = Arrays.asList(exptected);
|
||||
assertEquals(expectedList, result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user