/trunk/tests/Microsoft/WindowsAzure/DynamicTableEntityTest.php
PHP | 181 lines | 103 code | 22 blank | 56 comment | 5 complexity | 245bad262c8a79e3620ec1e8afbc0c53 MD5 | raw file
Possible License(s): BSD-3-Clause
- <?php
- /**
- * Copyright (c) 2009 - 2012, RealDolmen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of RealDolmen nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * @category Microsoft
- * @package Microsoft_WindowsAzure
- * @subpackage UnitTests
- * @version $Id: BlobStorageTest.php 14561 2009-05-07 08:05:12Z unknown $
- * @copyright Copyright (c) 2009 - 2012, RealDolmen (http://www.realdolmen.com)
- * @license http://phpazure.codeplex.com/license
- */
- date_default_timezone_set('UTC');
- require_once dirname(__FILE__) . '/../../TestConfiguration.php';
- require_once 'PHPUnit/Framework/TestCase.php';
- require_once 'Microsoft/WindowsAzure/Storage/Table.php';
- require_once 'Microsoft/WindowsAzure/Storage/DynamicTableEntity.php';
- /**
- * @category Microsoft
- * @package Microsoft_WindowsAzure
- * @subpackage UnitTests
- * @version $Id: BlobStorageTest.php 14561 2009-05-07 08:05:12Z unknown $
- * @copyright Copyright (c) 2009 - 2012, RealDolmen (http://www.realdolmen.com)
- * @license http://phpazure.codeplex.com/license
- */
- class Microsoft_WindowsAzure_DynamicTableEntityTest extends PHPUnit_Framework_TestCase
- {
- /**
- * Test teardown
- */
- protected function tearDown()
- {
- $storageClient = $this->createStorageInstance();
- for ($i = 1; $i <= self::$uniqId; $i++)
- {
- try { $storageClient->deleteTable(TESTS_TABLE_TABLENAME_PREFIX . $i); } catch (Exception $e) { }
- }
- }
-
- protected function createStorageInstance()
- {
- $storageClient = null;
- if (TESTS_TABLE_RUNONPROD) {
- $storageClient = new Microsoft_WindowsAzure_Storage_Table(TESTS_TABLE_HOST_PROD, TESTS_STORAGE_ACCOUNT_PROD, TESTS_STORAGE_KEY_PROD, false, Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract::retryN(10, 250));
- } else {
- $storageClient = new Microsoft_WindowsAzure_Storage_Table(TESTS_TABLE_HOST_DEV, TESTS_STORAGE_ACCOUNT_DEV, TESTS_STORAGE_KEY_DEV, true, Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract::retryN(10, 250));
- }
-
- if (TESTS_STORAGE_USEPROXY) {
- $storageClient->setProxy(TESTS_STORAGE_USEPROXY, TESTS_STORAGE_PROXY, TESTS_STORAGE_PROXY_PORT, TESTS_STORAGE_PROXY_CREDENTIALS);
- }
- return $storageClient;
- }
-
- protected static $uniqId = 0;
-
- protected function generateName()
- {
- self::$uniqId++;
- return TESTS_TABLE_TABLENAME_PREFIX . self::$uniqId;
- }
-
- /**
- * Test constructor
- */
- public function testConstructor()
- {
- $target = new Microsoft_WindowsAzure_Storage_DynamicTableEntity('partition1', '000001');
- $this->assertEquals('partition1', $target->getPartitionKey());
- $this->assertEquals('000001', $target->getRowKey());
- }
-
- /**
- * Test get Azure values
- */
- public function testGetAzureValues()
- {
- $dateTimeValue = new DateTime();
-
- $target = new Microsoft_WindowsAzure_Storage_DynamicTableEntity('partition1', '000001');
- $target->Name = 'Name';
- $target->Age = 25;
- $target->DateInService = $dateTimeValue;
- $result = $target->getAzureValues();
- $this->assertEquals('Name', $result[0]->Name);
- $this->assertEquals('Name', $result[0]->Value);
- $this->assertEquals('Edm.String', $result[0]->Type);
-
- $this->assertEquals('Age', $result[1]->Name);
- $this->assertEquals(25, $result[1]->Value);
- $this->assertEquals('Edm.Int32', $result[1]->Type);
-
- $this->assertEquals('DateInService', $result[2]->Name);
- $this->assertEquals($dateTimeValue, $result[2]->Value);
- $this->assertEquals('Edm.DateTime', $result[2]->Type);
-
- $this->assertEquals('partition1', $result[3]->Value);
- $this->assertEquals('000001', $result[4]->Value);
- }
-
- /**
- * Test set Azure values
- */
- public function testSetAzureValues()
- {
- $dateTimeValue = new DateTime();
-
- $values = array(
- 'PartitionKey' => 'partition1',
- 'RowKey' => '000001',
- 'Name' => 'Maarten',
- 'Age' => 25,
- 'Visible' => true,
- 'DateInService' => $dateTimeValue
- );
-
- $target = new Microsoft_WindowsAzure_Storage_DynamicTableEntity();
- $target->setAzureValues($values);
- $target->setAzurePropertyType('Age', 'Edm.Int32');
- $this->assertEquals('partition1', $target->getPartitionKey());
- $this->assertEquals('000001', $target->getRowKey());
- $this->assertEquals('Maarten', $target->Name);
- $this->assertEquals(25, $target->Age);
- $this->assertEquals('Edm.Int32', $target->getAzurePropertyType('Age'));
- $this->assertEquals(true, $target->Visible);
- $this->assertEquals($dateTimeValue, $target->DateInService);
- $this->assertEquals('Edm.DateTime', $target->getAzurePropertyType('DateInService'));
- }
-
- /**
- * Test insert entity
- */
- public function testInsertEntity()
- {
- if (TESTS_TABLE_RUNTESTS) {
- $tableName = $this->generateName();
- $storageClient = $this->createStorageInstance();
- $storageClient->createTable($tableName);
-
- $entity = new Microsoft_WindowsAzure_Storage_DynamicTableEntity();
- $entity->Name = 'Maarten';
- $entity->Age = 25;
- $entity->Inserted = new DateTime();
- $entity->TestValue = 200000;
- $entity->NullStringValue = null;
-
- $result = $storageClient->insertEntity($tableName, $entity);
- $this->assertNotEquals('0001-01-01T00:00:00', $result->getTimestamp());
- $this->assertNotEquals('', $result->getEtag());
- $this->assertEquals($entity->getAzureValues(), $result->getAzureValues());
- }
- }
- }