public void testRemoveFromProducer() throws Exception { Topic topic = new Topic(); topic.setName("foo"); topic.setNs("http://bar"); topic.setPrefix("s"); for (int i = 0; i < 3; i++) { Subscription subscription = new Subscription( UUID.randomUUID().toString(), "http://subscriber", "http://provider" + i, topic, System.currentTimeMillis()); registry.addSubscription(subscription); } for (int i = 0; i < 10; i++) { Subscription subscription = new Subscription( UUID.randomUUID().toString(), "http://subscriber" + i, "http://provider", topic, System.currentTimeMillis()); registry.addSubscription(subscription); } assertEquals(13, registry.getSubscriptions().size()); registry.removeAllFromProvider("http://provider"); assertEquals(3, registry.getSubscriptions().size()); // TODO : Guava should have the stuff to handle that List<Subscription> remain = registry.getSubscriptions(); for (Subscription subscription : remain) { if ("http://provider".equals(subscription.getProvider())) { fail("It remains a subscription in the collection!!!"); } } }
public void testGetFilteredSubscriptions() throws Exception { Topic topic = new Topic(); topic.setName("foo"); topic.setNs("http://bar"); topic.setPrefix("s"); for (int i = 0; i < 20; i++) { Subscription subscription = new Subscription( UUID.randomUUID().toString(), "http://subscriber" + i, "http://provider", topic, System.currentTimeMillis()); registry.addSubscription(subscription); } List<Subscription> filtered = registry.getSubscriptions(null); assertEquals(20, filtered.size()); // get all from provider Subscription filter = new Subscription(); filter.setProvider("http://provider"); filtered = registry.getSubscriptions(filter); assertEquals(20, filtered.size()); // get all from provider and consumer filter = new Subscription(); filter.setProvider("http://provider"); filter.setSubscriber("http://subscriber0"); filtered = registry.getSubscriptions(filter); assertEquals(1, filtered.size()); // get all from bad provider filter = new Subscription(); filter.setProvider("http://fooooo"); filtered = registry.getSubscriptions(filter); assertEquals(0, filtered.size()); // get all from a provider and bad topic filter = new Subscription(); filter.setProvider("http://provider"); Topic t = new Topic(); t.setName("123"); filter.setTopic(t); filtered = registry.getSubscriptions(filter); assertEquals(0, filtered.size()); // get all from topic filter = new Subscription(); Topic tt = new Topic(); tt.setName("foo"); filter.setTopic(tt); filtered = registry.getSubscriptions(filter); assertEquals(20, filtered.size()); topic = new Topic(); topic.setName("fooo"); topic.setNs("http://bar"); topic.setPrefix("s"); Subscription subscription = new Subscription( UUID.randomUUID().toString(), "http://subscriberFOO", "http://provider", topic, System.currentTimeMillis()); registry.addSubscription(subscription); filter = new Subscription(); Topic ttt = new Topic(); ttt.setName("fooo"); filter.setTopic(ttt); filtered = registry.getSubscriptions(filter); assertEquals(1, filtered.size()); // filter on NS filter = new Subscription(); Topic tttt = new Topic(); tttt.setNs("http://bar"); filter.setTopic(tttt); filtered = registry.getSubscriptions(filter); assertEquals(21, filtered.size()); }