Skip to content

Commit

Permalink
Merge pull request #148 from loudej/servicebus-rule-methods
Browse files Browse the repository at this point in the history
ASK MODE: Including methods model data modifiers to hide serialization types. Fixes #73
  • Loading branch information
rpaquay committed Nov 30, 2011
2 parents c60ba71 + 3bc0585 commit af9252f
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
import javax.ws.rs.core.MediaType;

import com.microsoft.windowsazure.services.serviceBus.implementation.Content;
import com.microsoft.windowsazure.services.serviceBus.implementation.CorrelationFilter;
import com.microsoft.windowsazure.services.serviceBus.implementation.EmptyRuleAction;
import com.microsoft.windowsazure.services.serviceBus.implementation.Entry;
import com.microsoft.windowsazure.services.serviceBus.implementation.EntryModel;
import com.microsoft.windowsazure.services.serviceBus.implementation.FalseFilter;
import com.microsoft.windowsazure.services.serviceBus.implementation.Filter;
import com.microsoft.windowsazure.services.serviceBus.implementation.RuleAction;
import com.microsoft.windowsazure.services.serviceBus.implementation.RuleDescription;
import com.microsoft.windowsazure.services.serviceBus.implementation.SqlRuleAction;
import com.microsoft.windowsazure.services.serviceBus.implementation.TrueFilter;

/**
* Represents a rule.
Expand Down Expand Up @@ -113,4 +118,35 @@ public RuleInfo setAction(RuleAction value) {
return this;
}

public RuleInfo withCorrelationIdFilter(String correlationId) {
CorrelationFilter filter = new CorrelationFilter();
filter.setCorrelationId(correlationId);
return setFilter(filter);
}

public RuleInfo withTrueSqlExpressionFilter(String sqlExpression) {
TrueFilter filter = new TrueFilter();
filter.setSqlExpression(sqlExpression);
filter.setCompatibilityLevel(20);
return setFilter(filter);
}

public RuleInfo withFalseSqlExpressionFilter(String sqlExpression) {
FalseFilter filter = new FalseFilter();
filter.setSqlExpression(sqlExpression);
filter.setCompatibilityLevel(20);
return setFilter(filter);
}

public RuleInfo withEmptyRuleAction() {
EmptyRuleAction action = new EmptyRuleAction();
return setAction(action);
}

public RuleInfo withSqlRuleAction(String sqlExpression) {
SqlRuleAction action = new SqlRuleAction();
action.setSqlExpression(sqlExpression);
action.setCompatibilityLevel(20);
return setAction(action);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;

import com.microsoft.windowsazure.services.core.Builder;
import com.microsoft.windowsazure.services.core.Builder.Alteration;
import com.microsoft.windowsazure.services.core.Builder.Registry;
import com.microsoft.windowsazure.services.core.Configuration;
import com.microsoft.windowsazure.services.core.ServiceException;
import com.microsoft.windowsazure.services.core.ServiceFilter;
import com.microsoft.windowsazure.services.core.ServiceFilter.Request;
import com.microsoft.windowsazure.services.core.ServiceFilter.Response;
import com.microsoft.windowsazure.services.serviceBus.implementation.CorrelationFilter;
import com.microsoft.windowsazure.services.serviceBus.implementation.EmptyRuleAction;
import com.microsoft.windowsazure.services.serviceBus.implementation.FalseFilter;
import com.microsoft.windowsazure.services.serviceBus.implementation.SqlRuleAction;
import com.microsoft.windowsazure.services.serviceBus.implementation.TrueFilter;
import com.microsoft.windowsazure.services.serviceBus.models.BrokeredMessage;
import com.microsoft.windowsazure.services.serviceBus.models.ListQueuesResult;
import com.microsoft.windowsazure.services.serviceBus.models.ListRulesResult;
Expand All @@ -25,6 +34,8 @@
import com.microsoft.windowsazure.services.serviceBus.models.RuleInfo;
import com.microsoft.windowsazure.services.serviceBus.models.SubscriptionInfo;
import com.microsoft.windowsazure.services.serviceBus.models.TopicInfo;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.filter.LoggingFilter;

public class ServiceBusIntegrationTest extends IntegrationTestBase {

Expand All @@ -36,13 +47,27 @@ public class ServiceBusIntegrationTest extends IntegrationTestBase {

@Before
public void createService() throws Exception {
Configuration config = Configuration.getInstance();
// reinitialize configuration from known state
Configuration config = Configuration.load();
overrideWithEnv(config, ServiceBusConfiguration.URI);
overrideWithEnv(config, ServiceBusConfiguration.WRAP_URI);
overrideWithEnv(config, ServiceBusConfiguration.WRAP_NAME);
overrideWithEnv(config, ServiceBusConfiguration.WRAP_PASSWORD);
overrideWithEnv(config, ServiceBusConfiguration.WRAP_SCOPE);
service = ServiceBusService.create(config);

// add LoggingFilter to any pipeline that is created
Registry builder = (Registry) config.getBuilder();
builder.alter(Client.class, new Alteration<Client>() {
@Override
public Client alter(Client instance, Builder builder, Map<String, Object> properties) {
instance.addFilter(new LoggingFilter());
return instance;
}
});

// applied as default configuration
Configuration.setInstance(config);
service = ServiceBusService.create();
}

private static void overrideWithEnv(Configuration config, String key) {
Expand Down Expand Up @@ -428,4 +453,31 @@ public void rulesMayBeDeleted() throws Exception {
assertEquals(1, result.getItems().size());
assertEquals("MyRule4", result.getItems().get(0).getName());
}

@Test
public void rulesMayHaveActionAndFilter() throws ServiceException {
// Arrange
String topicName = "TestRulesMayHaveAnActionAndFilter";
service.createTopic(new TopicInfo(topicName));
service.createSubscription(topicName, new SubscriptionInfo("sub"));

// Act
RuleInfo ruleOne = service.createRule(topicName, "sub", new RuleInfo("One").withCorrelationIdFilter("my-id"))
.getValue();
RuleInfo ruleTwo = service.createRule(topicName, "sub",
new RuleInfo("Two").withTrueSqlExpressionFilter("my-true-expression")).getValue();
RuleInfo ruleThree = service.createRule(topicName, "sub",
new RuleInfo("Three").withFalseSqlExpressionFilter("my-false-expression")).getValue();
RuleInfo ruleFour = service.createRule(topicName, "sub", new RuleInfo("Four").withEmptyRuleAction()).getValue();
RuleInfo ruleFive = service.createRule(topicName, "sub", new RuleInfo("Five").withSqlRuleAction("SET x = 5"))
.getValue();

// Assert
assertEquals(CorrelationFilter.class, ruleOne.getFilter().getClass());
assertEquals(TrueFilter.class, ruleTwo.getFilter().getClass());
assertEquals(FalseFilter.class, ruleThree.getFilter().getClass());
assertEquals(EmptyRuleAction.class, ruleFour.getAction().getClass());
assertEquals(SqlRuleAction.class, ruleFive.getAction().getClass());

}
}

0 comments on commit af9252f

Please sign in to comment.