/**
  * Creates ServiceProperties object from parsed XML response.
  *
  * @param array $parsedResponse XML response parsed into array.
  * 
  * @return MicrosoftAzure\Storage\Common\Models\ServiceProperties.
  */
 public static function create($parsedResponse)
 {
     $result = new ServiceProperties();
     $result->setLogging(Logging::create($parsedResponse['Logging']));
     $result->setMetrics(Metrics::create($parsedResponse['HourMetrics']));
     return $result;
 }
 /**
  * @covers MicrosoftAzure\Storage\Common\Models\GetServicePropertiesResult::setValue
  */
 public function testSetValue()
 {
     // Setup
     $result = new GetServicePropertiesResult();
     $expected = ServiceProperties::create(TestResources::getServicePropertiesSample());
     // Test
     $result->setValue($expected);
     // Assert
     $this->assertEquals($expected, $result->getValue());
 }
 /**
  * @covers MicrosoftAzure\Storage\Common\Internal\Serialization\XmlSerializer::serialize
  * @covers MicrosoftAzure\Storage\Common\Internal\Serialization\XmlSerializer::_arr2xml
  */
 public function testSerialize()
 {
     // Setup
     $xmlSerializer = new XmlSerializer();
     $propertiesSample = TestResources::getServicePropertiesSample();
     $properties = ServiceProperties::create($propertiesSample);
     $expected = $properties->toXml($xmlSerializer);
     $array = $properties->toArray();
     $serializerProperties = array(XmlSerializer::ROOT_NAME => ServiceProperties::$xmlRootName);
     // Test
     $actual = $xmlSerializer->serialize($array, $serializerProperties);
     $this->assertEquals($expected, $actual);
 }
 private function _createDefaultProperties()
 {
     $this->propertiesChanged = false;
     $propertiesArray = array();
     $propertiesArray['Logging']['Version'] = '1.0';
     $propertiesArray['Logging']['Delete'] = 'false';
     $propertiesArray['Logging']['Read'] = 'false';
     $propertiesArray['Logging']['Write'] = 'false';
     $propertiesArray['Logging']['RetentionPolicy']['Enabled'] = 'false';
     $propertiesArray['HourMetrics']['Version'] = '1.0';
     $propertiesArray['HourMetrics']['Enabled'] = 'false';
     $propertiesArray['HourMetrics']['IncludeAPIs'] = 'false';
     $propertiesArray['HourMetrics']['RetentionPolicy']['Enabled'] = 'false';
     $this->defaultProperties = ServiceProperties::create($propertiesArray);
 }
 /**
  * @covers MicrosoftAzure\Storage\Common\Internal\Utilities::serialize
  * @covers MicrosoftAzure\Storage\Common\Internal\Utilities::_arr2xml
  */
 public function testSerialize()
 {
     // Setup
     $propertiesSample = TestResources::getServicePropertiesSample();
     $properties = ServiceProperties::create($propertiesSample);
     $expected = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
     $expected .= '<StorageServiceProperties><Logging><Version>1.0</Version><Delete>true</Delete>';
     $expected .= '<Read>false</Read><Write>true</Write><RetentionPolicy><Enabled>true</Enabled>';
     $expected .= '<Days>20</Days></RetentionPolicy></Logging><HourMetrics><Version>1.0</Version>';
     $expected .= '<Enabled>true</Enabled><IncludeAPIs>false</IncludeAPIs><RetentionPolicy>';
     $expected .= '<Enabled>true</Enabled><Days>20</Days></RetentionPolicy></HourMetrics></StorageServiceProperties>';
     $array = $properties->toArray();
     // Test
     $actual = Utilities::serialize($array, ServiceProperties::$xmlRootName);
     $this->assertEquals($expected, $actual);
 }
 public static function getInterestingServiceProperties()
 {
     $ret = array();
     // This is the default that comes from the server.
     array_push($ret, self::getDefaultServiceProperties());
     $rp = new RetentionPolicy();
     $rp->setEnabled(true);
     $rp->setDays(10);
     $l = new Logging();
     $l->setRetentionPolicy($rp);
     // Note: looks like only v1.0 is available now.
     // http://msdn.microsoft.com/en-us/library/windowsazure/hh360996.aspx
     $l->setVersion('1.0');
     $l->setDelete(true);
     $l->setRead(true);
     $l->setWrite(true);
     $m = new Metrics();
     $m->setRetentionPolicy($rp);
     $m->setVersion('1.0');
     $m->setEnabled(true);
     $m->setIncludeAPIs(true);
     $sp = new ServiceProperties();
     $sp->setLogging($l);
     $sp->setMetrics($m);
     array_push($ret, $sp);
     $rp = new RetentionPolicy();
     // The service does not accept setting days when enabled is false.
     $rp->setEnabled(false);
     $rp->setDays(null);
     $l = new Logging();
     $l->setRetentionPolicy($rp);
     // Note: looks like only v1.0 is available now.
     // http://msdn.microsoft.com/en-us/library/windowsazure/hh360996.aspx
     $l->setVersion('1.0');
     $l->setDelete(false);
     $l->setRead(false);
     $l->setWrite(false);
     $m = new Metrics();
     $m->setRetentionPolicy($rp);
     $m->setVersion('1.0');
     $m->setEnabled(true);
     $m->setIncludeAPIs(true);
     $sp = new ServiceProperties();
     $sp->setLogging($l);
     $sp->setMetrics($m);
     array_push($ret, $sp);
     $rp = new RetentionPolicy();
     $rp->setEnabled(true);
     // Days has to be 0 < days <= 365
     $rp->setDays(364);
     $l = new Logging();
     $l->setRetentionPolicy($rp);
     // Note: looks like only v1.0 is available now.
     // http://msdn.microsoft.com/en-us/library/windowsazure/hh360996.aspx
     $l->setVersion('1.0');
     $l->setDelete(false);
     $l->setRead(false);
     $l->setWrite(false);
     $m = new Metrics();
     $m->setVersion('1.0');
     $m->setEnabled(false);
     $m->setIncludeAPIs(null);
     $m->setRetentionPolicy($rp);
     $sp = new ServiceProperties();
     $sp->setLogging($l);
     $sp->setMetrics($m);
     array_push($ret, $sp);
     return $ret;
 }
 public function testCheckServiceProperties()
 {
     // Check that the default values of options are reasonable
     $l = new Logging();
     $m = new Metrics();
     $sp = new ServiceProperties();
     $this->assertNull($sp->getLogging(), 'Default ServiceProperties->getLogging should not be null');
     $this->assertNull($sp->getMetrics(), 'Default ServiceProperties->getMetrics should not be null');
     $sp->setLogging($l);
     $sp->setMetrics($m);
     $this->assertEquals($sp->getLogging(), $l, 'Set ServiceProperties->getLogging');
     $this->assertEquals($sp->getMetrics(), $m, 'Set ServiceProperties->getMetrics');
 }
 public function testCheckServiceProperties()
 {
     $l = new Logging();
     $m = new Metrics();
     $sp = new ServiceProperties();
     $this->assertNull($sp->getLogging(), 'Default ServiceProperties->getLogging should not be null');
     $this->assertNull($sp->getMetrics(), 'Default ServiceProperties->getMetrics should not be null');
     $sp->setLogging($l);
     $sp->setMetrics($m);
     $this->assertEquals($sp->getLogging(), $l, 'Set ServiceProperties->getLogging');
     $this->assertEquals($sp->getMetrics(), $m, 'Set ServiceProperties->getMetrics');
 }
 /**
  * Creates object from $parsedResponse.
  * 
  * @param array $parsedResponse XML response parsed into array.
  * 
  * @return MicrosoftAzure\Storage\Common\Models\GetServicePropertiesResult
  */
 public static function create($parsedResponse)
 {
     $result = new GetServicePropertiesResult();
     $result->_serviceProperties = ServiceProperties::create($parsedResponse);
     return $result;
 }
 /**
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::setServiceProperties
  */
 public function testSetServiceProperties()
 {
     $this->skipIfEmulated();
     // Setup
     $expected = ServiceProperties::create(TestResources::setServicePropertiesSample());
     // Test
     $this->setServiceProperties($expected);
     $actual = $this->restProxy->getServiceProperties();
     // Assert
     $this->assertEquals($expected->toXml($this->xmlSerializer), $actual->getValue()->toXml($this->xmlSerializer));
 }
 /**
  * Sets the properties of the Table service.
  *
  * It's recommended to use getServiceProperties, alter the returned object and
  * then use setServiceProperties with this altered object.
  *
  * @param ServiceProperties          $serviceProperties new service properties
  * @param Models\TableServiceOptions $options           optional parameters
  *
  * @return none.
  *
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/hh452240.aspx
  */
 public function setServiceProperties($serviceProperties, $options = null)
 {
     Validate::isTrue($serviceProperties instanceof ServiceProperties, Resources::INVALID_SVC_PROP_MSG);
     $method = Resources::HTTP_PUT;
     $headers = array();
     $postParams = array();
     $queryParams = array();
     $statusCode = Resources::STATUS_ACCEPTED;
     $path = Resources::EMPTY_STRING;
     $body = Resources::EMPTY_STRING;
     if (is_null($options)) {
         $options = new TableServiceOptions();
     }
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $this->addOptionalQueryParam($queryParams, Resources::QP_REST_TYPE, 'service');
     $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'properties');
     $this->addOptionalHeader($headers, Resources::CONTENT_TYPE, Resources::XML_ATOM_CONTENT_TYPE);
     $body = $serviceProperties->toXml($this->dataSerializer);
     $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode, $body);
 }
 /**
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::setServiceProperties
  * @covers MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy::sendContext
  */
 public function testSetServicePropertiesWithEmptyParts()
 {
     $this->skipIfEmulated();
     // Setup
     $xml = TestResources::setServicePropertiesSample();
     $xml['HourMetrics']['RetentionPolicy'] = null;
     $expected = ServiceProperties::create($xml);
     // Test
     $this->setServiceProperties($expected);
     $actual = $this->restProxy->getServiceProperties();
     // Assert
     $this->assertEquals($expected->toXml($this->xmlSerializer), $actual->getValue()->toXml($this->xmlSerializer));
 }
 /**
  * @covers MicrosoftAzure\Storage\Common\Models\ServiceProperties::toXml
  */
 public function testToXml()
 {
     // Setup
     $properties = ServiceProperties::create(TestResources::getServicePropertiesSample());
     $xmlSerializer = new XmlSerializer();
     // Test
     $actual = $properties->toXml($xmlSerializer);
     // Assert
     $actualParsed = Utilities::unserialize($actual);
     $actualProperties = GetServicePropertiesResult::create($actualParsed);
     $this->assertEquals($actualProperties->getValue(), $properties);
 }