Permalink
Browse files

Refactor underlying components used in REST service construction

  • Loading branch information...
1 parent 0777354 commit 53388a6af2ed84592212c6e9f790e6e3f3a0df0a Abdelrahman Elogeel committed Jun 19, 2012
View
74 WindowsAzure/Common/Internal/ServicesBuilder.php
@@ -63,6 +63,46 @@
class ServicesBuilder implements IServicesBuilder
{
/**
+ * Gets the HTTP client used in the REST services construction.
+ *
+ * @return WindowsAzure\Common\Internal\Http\IHttpClient
+ */
+ protected function httpClient()
+ {
+ return new HttpClient();
+ }
+
+ /**
+ * Gets the serializer used in the REST services construction.
+ *
+ * @return WindowsAzure\Common\Internal\Serialization\ISerializer
+ */
+ protected function serializer()
+ {
+ return new XmlSerializer();
+ }
+
+ /**
+ * Gets the MIME serializer used in the REST services construction.
+ *
+ * @return \WindowsAzure\Table\Internal\IMimeReaderWriter
+ */
+ protected function mimeSerializer()
+ {
+ return new MimeReaderWriter();
+ }
+
+ /**
+ * Gets the Atom serializer used in the REST services construction.
+ *
+ * @return \WindowsAzure\Table\Internal\IAtomReaderWriter
+ */
+ protected function atomSerializer()
+ {
+ return new AtomReaderWriter();
+ }
+
+ /**
* Adds HeadersFilter with constant headers for each service wrapper.
*
* @param mix $wrapper service wrapper
@@ -115,8 +155,8 @@ public function buildQueue($config)
{
$this->_validateConfig($config, Resources::QUEUE_TYPE_NAME);
- $httpClient = new HttpClient();
- $xmlSerializer = new XmlSerializer();
+ $httpClient = $this->httpClient();
+ $serializer = $this->serializer();
$uri = Utilities::tryAddUrlScheme(
$config->getProperty(QueueSettings::URI)
);
@@ -125,7 +165,7 @@ public function buildQueue($config)
$httpClient,
$uri,
Resources::EMPTY_STRING,
- $xmlSerializer
+ $serializer
);
// Adding headers filter
@@ -160,8 +200,8 @@ public function buildBlob($config)
{
$this->_validateConfig($config, Resources::BLOB_TYPE_NAME);
- $httpClient = new HttpClient();
- $xmlSerializer = new XmlSerializer();
+ $httpClient = $this->httpClient();
+ $serializer = $this->serializer();
$uri = Utilities::tryAddUrlScheme(
$config->getProperty(BlobSettings::URI)
);
@@ -170,7 +210,7 @@ public function buildBlob($config)
$httpClient,
$uri,
$config->getProperty(BlobSettings::ACCOUNT_NAME),
- $xmlSerializer
+ $serializer
);
// Adding headers filter
@@ -205,10 +245,10 @@ public function buildTable($config)
{
$this->_validateConfig($config, Resources::TABLE_TYPE_NAME);
- $httpClient = new HttpClient();
- $atomSerializer = new AtomReaderWriter();
- $mimeSerializer = new MimeReaderWriter();
- $xmlSerializer = new XmlSerializer();
+ $httpClient = $this->httpClient();
+ $atomSerializer = $this->atomSerializer();
+ $mimeSerializer = $this->mimeSerializer();
+ $serializer = $this->serializer();
$uri = Utilities::tryAddUrlScheme(
$config->getProperty(TableSettings::URI)
);
@@ -218,7 +258,7 @@ public function buildTable($config)
$uri,
$atomSerializer,
$mimeSerializer,
- $xmlSerializer
+ $serializer
);
// Adding headers filter
@@ -254,12 +294,12 @@ public function buildServiceBus($config)
{
$this->_validateConfig($config, Resources::SERVICE_BUS_TYPE_NAME);
- $httpClient = new HttpClient();
- $xmlSerializer = new XmlSerializer();
+ $httpClient = $this->httpClient();
+ $serializer = $this->serializer();
$serviceBusWrapper = new ServiceBusRestProxy(
$httpClient,
$config->getProperty(ServiceBusSettings::URI),
- $xmlSerializer
+ $serializer
);
$wrapFilter = new WrapFilter(
@@ -286,7 +326,7 @@ public function buildServiceManagement($config)
ServiceManagementSettings::CERTIFICATE_PATH
);
$httpClient = new HttpClient($certificatePath);
- $xmlSerializer = new XmlSerializer();
+ $serializer = $this->serializer();
$uri = Utilities::tryAddUrlScheme(
$config->getProperty(ServiceManagementSettings::URI),
Resources::HTTPS_SCHEME
@@ -296,7 +336,7 @@ public function buildServiceManagement($config)
$httpClient,
$config->getProperty(ServiceManagementSettings::SUBSCRIPTION_ID),
$uri,
- $xmlSerializer
+ $serializer
);
// Adding headers filter
@@ -318,7 +358,7 @@ public function buildWrap($config)
{
$this->_validateConfig($config, Resources::WRAP_TYPE_NAME);
- $httpClient = new HttpClient();
+ $httpClient = $this->httpClient();
$wrapWrapper = new WrapRestProxy(
$httpClient,
$config->getProperty(ServiceBusSettings::WRAP_URI)
View
10 tests/unit/WindowsAzure/Common/Internal/ServicesBuilderTest.php
@@ -48,6 +48,8 @@ class ServicesBuilderTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers WindowsAzure\Common\Internal\ServicesBuilder::buildQueue
+ * @covers WindowsAzure\Common\Internal\ServicesBuilder::httpClient
+ * @covers WindowsAzure\Common\Internal\ServicesBuilder::serializer
* @covers WindowsAzure\Common\Internal\ServicesBuilder::_addHeadersFilter
* @covers WindowsAzure\Common\Internal\ServicesBuilder::_validateConfig
*/
@@ -70,6 +72,8 @@ public function testBuildForQueue()
/**
* @covers WindowsAzure\Common\Internal\ServicesBuilder::buildBlob
+ * @covers WindowsAzure\Common\Internal\ServicesBuilder::httpClient
+ * @covers WindowsAzure\Common\Internal\ServicesBuilder::serializer
* @covers WindowsAzure\Common\Internal\ServicesBuilder::_addHeadersFilter
* @covers WindowsAzure\Common\Internal\ServicesBuilder::_validateConfig
*/
@@ -92,6 +96,10 @@ public function testBuildForBlob()
/**
* @covers WindowsAzure\Common\Internal\ServicesBuilder::buildTable
+ * @covers WindowsAzure\Common\Internal\ServicesBuilder::httpClient
+ * @covers WindowsAzure\Common\Internal\ServicesBuilder::serializer
+ * @covers WindowsAzure\Common\Internal\ServicesBuilder::mimeSerializer
+ * @covers WindowsAzure\Common\Internal\ServicesBuilder::atomSerializer
* @covers WindowsAzure\Common\Internal\ServicesBuilder::_addHeadersFilter
* @covers WindowsAzure\Common\Internal\ServicesBuilder::_validateConfig
*/
@@ -114,6 +122,8 @@ public function testBuildForTable()
/**
* @covers WindowsAzure\Common\Internal\ServicesBuilder::buildServiceManagement
+ * @covers WindowsAzure\Common\Internal\ServicesBuilder::httpClient
+ * @covers WindowsAzure\Common\Internal\ServicesBuilder::serializer
* @covers WindowsAzure\Common\Internal\ServicesBuilder::_addHeadersFilter
* @covers WindowsAzure\Common\Internal\ServicesBuilder::_validateConfig
*/

0 comments on commit 53388a6

Please sign in to comment.