/** * Populates the properties with the response from the list rules request. * * @param string $response The body of the response of the list rules request. * * @return none */ public function parseXml($response) { parent::parseXml($response); $listRulesResultXml = new \SimpleXMLElement($response); $this->_ruleInfos = array(); foreach ($listRulesResultXml->entry as $entry) { $ruleInfo = new RuleInfo(); $ruleInfo->parseXml($entry->asXml()); $this->_ruleInfos[] = $ruleInfo; } }
/** * Gets a rule. * * @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780772 * * @param string $topicPath The path of the topic. * @param string $subscriptionName The name of the subscription. * @param string $ruleName The name of the rule. * * @return RuleInfo */ public function getRule($topicPath, $subscriptionName, $ruleName) { $httpCallContext = new HttpCallContext(); $httpCallContext->setMethod(Resources::HTTP_GET); $httpCallContext->addStatusCode(Resources::STATUS_OK); $rulePath = sprintf(Resources::RULE_PATH, $topicPath, $subscriptionName, $ruleName); $httpCallContext->setPath($rulePath); $response = $this->sendContext($httpCallContext); $ruleInfo = new RuleInfo(); $ruleInfo->parseXml($response->getBody()); return $ruleInfo; }
/** * @covers WindowsAzure\ServiceBus\ServiceBusRestProxy::createRule * @covers WindowsAzure\ServiceBus\ServiceBusRestProxy::deleteRule * @covers WindowsAzure\ServiceBus\ServiceBusRestProxy::listRules */ private function setupRules() { // See this topic for more information on what SQL filter strings are allowed: // http://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.sqlfilter.sqlexpression.aspx // See this topic for more information on what SQL action strings are allowed: // http://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.sqlruleaction.sqlexpression // subscriptionName1 is left unchanged // subscriptionName2 gets a rule that works on integers $this->restProxy->deleteRule($this->topicName, $this->subscriptionName2, '$Default'); $rule2 = new RuleInfo('intType'); $rule2->withSqlFilter('int < 53'); $this->restProxy->createRule($this->topicName, $this->subscriptionName2, $rule2); // subscriptionName3 gets a rule that works on strings and booleans $this->restProxy->deleteRule($this->topicName, $this->subscriptionName3, '$Default'); $rule3 = new RuleInfo('strAndBoolRule'); $rule3->withSqlFilter('name LIKE \'%3\' OR user.even = TRUE'); $this->restProxy->createRule($this->topicName, $this->subscriptionName3, $rule3); // subscriptionName4 gets two rules to enable duplicate messages $lst = $this->restProxy->listRules($this->topicName, $this->subscriptionName4)->getRuleInfos(); $rule4a = $lst[0]; $rule4a->withSqlRuleAction('SET trueRuleA=TRUE; ' . 'SET actionGuid=newid(); ' . 'SET actionDouble=3.5; ' . 'REMOVE int;'); $this->restProxy->deleteRule($this->topicName, $this->subscriptionName4, $rule4a->getTitle()); $this->restProxy->createRule($this->topicName, $this->subscriptionName4, $rule4a); $rule4b = new RuleInfo('trueRuleB'); $rule4b->withTrueFilter(); $action = 'SET trueRuleB=TRUE; ' . 'SET actionString=\'hello\'; ' . 'SET actionStringSingleQuote=\'\'\'\'; ' . 'SET actionStringDoubleQuote=\'"\'; ' . 'SET actionStringReverseSolidus=\'\\\'; ' . 'SET actionStringSlashN=\'' . "\n" . '\'; ' . 'SET actionStringTab=\'' . "\t" . '\'; ' . 'SET actionNull=null; ' . 'SET test=\'1999-12-25\'; ' . 'SET actionNewDate=\'1999-12-25\'; ' . 'REMOVE float;'; $rule4b->withSqlRuleAction($action); $this->restProxy->createRule($this->topicName, $this->subscriptionName4, $rule4b); $this->showRules($this->subscriptionName1); $this->showRules($this->subscriptionName2); $this->showRules($this->subscriptionName3); $this->showRules($this->subscriptionName4); }
/** * @covers WindowsAzure\ServiceBus\Models\RuleInfo::getName * @covers WindowsAzure\ServiceBus\Models\RuleInfo::setName */ public function testGetSetName() { // Setup $expected = 'testName'; $ruleInfo = new RuleInfo(); // Test $ruleInfo->setName($expected); $actual = $ruleInfo->getName(); // Assert $this->assertEquals($expected, $actual); }
/** * @covers WindowsAzure\ServiceBus\ServiceBusRestProxy::getRule */ public function testRulesMayHaveActionAndFilter() { // Setup $topicName = 'testRulesMayHaveActionAndFilter'; $subscriptionName = 'sub'; $topicInfo = new TopicInfo($topicName); $subscriptionInfo = new SubscriptionInfo($subscriptionName); $this->safeDeleteSubscription($topicName, $subscriptionName); $this->safeDeleteTopic($topicName); $createTopicResult = $this->createTopic($topicInfo); $subscriptionInfo = $this->createSubscription($topicName, $subscriptionInfo); $expectedRuleOne = new RuleInfo('one'); $expectedRuleOne->withCorrelationFilter('my-id'); $expectedRuleTwo = new RuleInfo('two'); $expectedRuleTwo->withTrueFilter(); $expectedRuleThree = new RuleInfo('three'); $expectedRuleThree->withFalseFilter(); $expectedRuleFour = new RuleInfo('four'); $expectedRuleFour->withEmptyRuleAction(); $expectedRuleFive = new RuleInfo('five'); $expectedRuleFive->withSqlRuleAction('SET x = 5'); $expectedRuleSix = new RuleInfo('six'); $expectedRuleSix->withSqlFilter('x != 5'); // Test $actualRuleOne = $this->restProxy->createRule($topicName, $subscriptionName, $expectedRuleOne); $actualRuleTwo = $this->restProxy->createRule($topicName, $subscriptionName, $expectedRuleTwo); $actualRuleThree = $this->restProxy->createRule($topicName, $subscriptionName, $expectedRuleThree); $actualRuleFour = $this->restProxy->createRule($topicName, $subscriptionName, $expectedRuleFour); $actualRuleFive = $this->restProxy->createRule($topicName, $subscriptionName, $expectedRuleFive); $actualRuleSix = $this->restProxy->createRule($topicName, $subscriptionName, $expectedRuleSix); // Assert $this->assertNotNull($createTopicResult); $this->assertNotNull($subscriptionInfo); $this->assertInstanceOf('WindowsAzure\\ServiceBus\\Models\\CorrelationFilter', $actualRuleOne->getFilter()); $this->assertInstanceOf('WindowsAzure\\ServiceBus\\Models\\TrueFilter', $actualRuleTwo->getFilter()); $this->assertInstanceOf('WindowsAzure\\ServiceBus\\Models\\FalseFilter', $actualRuleThree->getFilter()); $this->assertInstanceOf('WindowsAzure\\ServiceBus\\Models\\EmptyRuleAction', $actualRuleFour->getAction()); $this->assertInstanceOf('WindowsAzure\\ServiceBus\\Models\\SqlRuleAction', $actualRuleFive->getAction()); $this->assertInstanceOf('WindowsAzure\\ServiceBus\\Models\\SqlFilter', $actualRuleSix->getFilter()); }
/** * @covers WindowsAzure\ServiceBus\ServiceBusRestProxy::createRule * @covers WindowsAzure\ServiceBus\ServiceBusRestProxy::createSubscription * @covers WindowsAzure\ServiceBus\ServiceBusRestProxy::createTopic */ public function testRulesMayHaveActionAndFilter() { // Arrange $topicName = 'TestRulesMayHaveAnActionAndFilter'; $this->restProxy->createTopic(new TopicInfo($topicName)); $this->restProxy->createSubscription($topicName, new SubscriptionInfo('sub')); // Act $ruleInfoOne = new RuleInfo('One'); $ruleInfoOne->withCorrelationFilter('my-id'); $ruleOne = $this->restProxy->createRule($topicName, 'sub', $ruleInfoOne); $ruleInfoTwo = new RuleInfo('Two'); $ruleInfoTwo->withTrueFilter(); $ruleTwo = $this->restProxy->createRule($topicName, 'sub', $ruleInfoTwo); $ruleInfoThree = new RuleInfo('Three'); $ruleInfoThree->withFalseFilter(); $ruleThree = $this->restProxy->createRule($topicName, 'sub', $ruleInfoThree); $ruleInfoFour = new RuleInfo('Four'); $ruleInfoFour->withEmptyRuleAction(); $ruleFour = $this->restProxy->createRule($topicName, 'sub', $ruleInfoFour); $ruleInfoFive = new RuleInfo('Five'); $ruleInfoFive->withSqlRuleAction('SET x = 5'); $ruleFive = $this->restProxy->createRule($topicName, 'sub', $ruleInfoFive); $ruleInfoSix = new RuleInfo('Six'); $ruleInfoSix->withSqlFilter('x != 5'); $ruleSix = $this->restProxy->createRule($topicName, 'sub', $ruleInfoSix); // Assert $this->assertTrue($ruleOne->getFilter() instanceof \WindowsAzure\ServiceBus\Models\CorrelationFilter, '$ruleOne->getFilter() instanceof CorrelationFilter'); $this->assertTrue($ruleTwo->getFilter() instanceof \WindowsAzure\ServiceBus\Models\TrueFilter, '$ruleTwo->getFilter() instanceof TrueFilter'); $this->assertTrue($ruleThree->getFilter() instanceof \WindowsAzure\ServiceBus\Models\FalseFilter, '$ruleThree->getFilter() instanceof FalseFilter'); $this->assertTrue($ruleFour->getAction() instanceof \WindowsAzure\ServiceBus\Models\EmptyRuleAction, '$ruleFour->getAction() instanceof EmptyRuleAction'); $this->assertTrue($ruleFive->getAction() instanceof \WindowsAzure\ServiceBus\Models\SqlRuleAction, '$ruleFive->getAction() instanceof SqlRuleAction'); $this->assertTrue($ruleSix->getFilter() instanceof \WindowsAzure\ServiceBus\Models\SqlFilter, '$ruleSix->getFilter() instanceof SqlFilter'); }