Skip to content

Commit

Permalink
Merge pull request Azure#110 from gcheng/updateSub
Browse files Browse the repository at this point in the history
Enable update subscription.
  • Loading branch information
Albert Cheng committed Apr 19, 2013
2 parents 530b641 + 6f050b5 commit 05c351f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,19 +373,38 @@ CreateSubscriptionResult createSubscription(String topicPath, SubscriptionInfo s
ListSubscriptionsResult listSubscriptions(String topicPath) throws ServiceException;

/**
* List subscriptions.
* Returns a list of subscriptions.
*
* @param topicPath
* the topic path
* A <code>String</code> object that represents the name of the topic for the subscriptions to retrieve.
*
* @param options
* the options
* @return the list subscriptions result
* A <code>ListSubscriptionsOptions</code> object that represents the options to list subscriptions.
*
* @return A <code>ListSubscriptionsResult</code> object that represents the result.
*
* @throws ServiceException
* the service exception
*/
ListSubscriptionsResult listSubscriptions(String topicPath, ListSubscriptionsOptions options)
throws ServiceException;

/**
* Updates a subscription.
*
* @param topicName
* A <code>String</code> option which represents the name of the topic.
*
* @param subscriptionInfo
* A <code>SubscriptionInfo</code> option which represents the information of the subscription.
*
* @return A <code>SubscriptionInfo</code> object that represents the result.
*
* @exception ServiceException
* If a service exception is encountered.
*/
SubscriptionInfo updateSubscription(String topicName, SubscriptionInfo subscriptionInfo) throws ServiceException;

/**
* Creates a rule.
*
Expand Down Expand Up @@ -448,15 +467,16 @@ ListSubscriptionsResult listSubscriptions(String topicPath, ListSubscriptionsOpt
ListRulesResult listRules(String topicPath, String subscriptionName) throws ServiceException;

/**
* List rules.
* Returns a list of rules.
*
* @param topicPath
* the topic path
* A <code>String</code> object that represents the name of the topic for the subscription.
* @param subscriptionName
* the name of the subscription
* A <code>String</code> object that represents the name of the subscription whose rules are being
* retrieved.
* @param options
* the options
* @return the list rules result
* A <code>ListRulesOptions</code> object that represents the options to retrieve rules.
*
* @throws ServiceException
* If a service exception is encountered.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,20 @@ public ListSubscriptionsResult listSubscriptions(String topicPath) throws Servic
}
}

@Override
public SubscriptionInfo updateSubscription(String topicName, SubscriptionInfo subscriptionInfo)
throws ServiceException {
try {
return next.updateSubscription(topicName, subscriptionInfo);
}
catch (UniformInterfaceException e) {
throw processCatch(new ServiceException(e));
}
catch (ClientHandlerException e) {
throw processCatch(new ServiceException(e));
}
}

@Override
public CreateRuleResult createRule(String topicPath, String subscriptionName, RuleInfo rule)
throws ServiceException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,14 @@ public ListSubscriptionsResult listSubscriptions(String topicPath, ListSubscript
return result;
}

@Override
public SubscriptionInfo updateSubscription(String topicName, SubscriptionInfo subscriptionInfo)
throws ServiceException {
return getResource().path(topicName).path("subscriptions").path(subscriptionInfo.getName())
.type("application/atom+xml;type=entry;charset=utf-8").header("If-Match", "*")
.put(SubscriptionInfo.class, subscriptionInfo);
}

@Override
public CreateRuleResult createRule(String topicPath, String subscriptionName, RuleInfo rule) {
return new CreateRuleResult(getResource().path(topicPath).path("subscriptions").path(subscriptionName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,23 @@ public void subscriptionWillReceiveMessage() throws Exception {
assertEquals("text/html", message.getContentType());
}

@Test
public void subscriptionCanBeUpdated() throws Exception {
// Arrange
String topicName = "testSubscriptionCanBeUpdated";
service.createTopic(new TopicInfo(topicName));
SubscriptionInfo originalSubscription = service.createSubscription(topicName, new SubscriptionInfo("sub"))
.getValue();
Integer expectedMaxDeliveryCount = 1024;

// Act
SubscriptionInfo updatedSubscription = service.updateSubscription(topicName,
originalSubscription.setMaxDeliveryCount(expectedMaxDeliveryCount));

// Assert
assertEquals(expectedMaxDeliveryCount, updatedSubscription.getMaxDeliveryCount());
}

@Test
public void rulesCanBeCreatedOnSubscriptions() throws Exception {
// Arrange
Expand Down

0 comments on commit 05c351f

Please sign in to comment.