@Test public void addSubscriptionWithBadDurationTest() throws SubscriptionException, URISyntaxException, SubscriptionPersistenceException { thrown.expect(SubscriptionException.class); thrown.expectMessage("bad duration: PIPO"); SubscribeContext subscribeContext = createSubscribeContextTemperature(); subscribeContext.setDuration("PIPO"); subscriptions.addSubscription(subscribeContext); Assert.isTrue(subscriptionsRepository.getAllSubscriptions().size()==0); }
public String addSubscription(SubscribeContext subscribeContext) throws SubscriptionException, SubscriptionPersistenceException { Duration duration = convertDuration(subscribeContext.getDuration()); if (duration.isNegative()) { throw new SubscriptionException("negative duration is not allowed", new Throwable()); } if (duration.isZero()) { duration = convertDuration("P1M"); } try { subscribeContext.getEntityIdList().forEach(patterns::getPattern); } catch (PatternSyntaxException e) { throw new SubscriptionException("bad pattern", e); } String subscriptionId = UUID.randomUUID().toString(); Subscription subscription = new Subscription(subscriptionId, Instant.now().plus(duration), subscribeContext); subscriptionsRepository.saveSubscription(subscription); subscriptions.put(subscriptionId, subscription); return subscriptionId; }
Subscriptions { public String addSubscription(SubscribeContext subscribeContext) throws SubscriptionException, SubscriptionPersistenceException { Duration duration = convertDuration(subscribeContext.getDuration()); if (duration.isNegative()) { throw new SubscriptionException("negative duration is not allowed", new Throwable()); } if (duration.isZero()) { duration = convertDuration("P1M"); } try { subscribeContext.getEntityIdList().forEach(patterns::getPattern); } catch (PatternSyntaxException e) { throw new SubscriptionException("bad pattern", e); } String subscriptionId = UUID.randomUUID().toString(); Subscription subscription = new Subscription(subscriptionId, Instant.now().plus(duration), subscribeContext); subscriptionsRepository.saveSubscription(subscription); subscriptions.put(subscriptionId, subscription); return subscriptionId; } }
Subscriptions { public String addSubscription(SubscribeContext subscribeContext) throws SubscriptionException, SubscriptionPersistenceException { Duration duration = convertDuration(subscribeContext.getDuration()); if (duration.isNegative()) { throw new SubscriptionException("negative duration is not allowed", new Throwable()); } if (duration.isZero()) { duration = convertDuration("P1M"); } try { subscribeContext.getEntityIdList().forEach(patterns::getPattern); } catch (PatternSyntaxException e) { throw new SubscriptionException("bad pattern", e); } String subscriptionId = UUID.randomUUID().toString(); Subscription subscription = new Subscription(subscriptionId, Instant.now().plus(duration), subscribeContext); subscriptionsRepository.saveSubscription(subscription); subscriptions.put(subscriptionId, subscription); return subscriptionId; }  }
Subscriptions { public String addSubscription(SubscribeContext subscribeContext) throws SubscriptionException, SubscriptionPersistenceException { Duration duration = convertDuration(subscribeContext.getDuration()); if (duration.isNegative()) { throw new SubscriptionException("negative duration is not allowed", new Throwable()); } if (duration.isZero()) { duration = convertDuration("P1M"); } try { subscribeContext.getEntityIdList().forEach(patterns::getPattern); } catch (PatternSyntaxException e) { throw new SubscriptionException("bad pattern", e); } String subscriptionId = UUID.randomUUID().toString(); Subscription subscription = new Subscription(subscriptionId, Instant.now().plus(duration), subscribeContext); subscriptionsRepository.saveSubscription(subscription); subscriptions.put(subscriptionId, subscription); return subscriptionId; }  String addSubscription(SubscribeContext subscribeContext); boolean deleteSubscription(UnsubscribeContext unsubscribeContext); Iterator<Subscription> findSubscriptions(EntityId searchEntityId, Set<String> searchAttributes); @Scheduled(fixedDelay = 60000) void purgeExpiredSubscriptions(); Subscription getSubscription(String subscriptionId); }
Subscriptions { public String addSubscription(SubscribeContext subscribeContext) throws SubscriptionException, SubscriptionPersistenceException { Duration duration = convertDuration(subscribeContext.getDuration()); if (duration.isNegative()) { throw new SubscriptionException("negative duration is not allowed", new Throwable()); } if (duration.isZero()) { duration = convertDuration("P1M"); } try { subscribeContext.getEntityIdList().forEach(patterns::getPattern); } catch (PatternSyntaxException e) { throw new SubscriptionException("bad pattern", e); } String subscriptionId = UUID.randomUUID().toString(); Subscription subscription = new Subscription(subscriptionId, Instant.now().plus(duration), subscribeContext); subscriptionsRepository.saveSubscription(subscription); subscriptions.put(subscriptionId, subscription); return subscriptionId; }  String addSubscription(SubscribeContext subscribeContext); boolean deleteSubscription(UnsubscribeContext unsubscribeContext); Iterator<Subscription> findSubscriptions(EntityId searchEntityId, Set<String> searchAttributes); @Scheduled(fixedDelay = 60000) void purgeExpiredSubscriptions(); Subscription getSubscription(String subscriptionId);  }