PageRenderTime 56ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/codes-php/phpjakarta/tests/functional/WindowsAzure/Table/TableServiceFunctionalTest.php

http://bukuphpjs.codeplex.com
PHP | 1975 lines | 1380 code | 195 blank | 400 comment | 222 complexity | 45bfb747e3f26ec0d597f9d27c702176 MD5 | raw file
Possible License(s): Apache-2.0, MIT, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * LICENSE: Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. *
  14. * PHP version 5
  15. *
  16. * @category Microsoft
  17. * @package Tests\Functional\WindowsAzure\Table
  18. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  19. * @copyright 2012 Microsoft Corporation
  20. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  21. * @link https://github.com/windowsazure/azure-sdk-for-php
  22. */
  23. namespace Tests\Functional\WindowsAzure\Table;
  24. use Tests\Framework\TestResources;
  25. use Tests\Functional\WindowsAzure\Table\Enums\ConcurType;
  26. use Tests\Functional\WindowsAzure\Table\Enums\MutatePivot;
  27. use Tests\Functional\WindowsAzure\Table\Enums\OpType;
  28. use Tests\Functional\WindowsAzure\Table\Models\BatchWorkerConfig;
  29. use Tests\Functional\WindowsAzure\Table\Models\FakeTableInfoEntry;
  30. use WindowsAzure\Common\Internal\Utilities;
  31. use WindowsAzure\Common\ServiceException;
  32. use WindowsAzure\Table\Models\BatchError;
  33. use WindowsAzure\Table\Models\BatchOperations;
  34. use WindowsAzure\Table\Models\DeleteEntityOptions;
  35. use WindowsAzure\Table\Models\EdmType;
  36. use WindowsAzure\Table\Models\Entity;
  37. use WindowsAzure\Table\Models\InsertEntityResult;
  38. use WindowsAzure\Table\Models\Property;
  39. use WindowsAzure\Table\Models\QueryEntitiesOptions;
  40. use WindowsAzure\Table\Models\QueryTablesOptions;
  41. use WindowsAzure\Table\Models\TableServiceOptions;
  42. use WindowsAzure\Table\Models\UpdateEntityResult;
  43. class TableServiceFunctionalTest extends FunctionalTestBase
  44. {
  45. /**
  46. * @covers WindowsAzure\Table\TableRestProxy::getServiceProperties
  47. * @covers WindowsAzure\Table\TableRestProxy::setServiceProperties
  48. */
  49. public function testGetServicePropertiesNoOptions()
  50. {
  51. $serviceProperties = TableServiceFunctionalTestData::getDefaultServiceProperties();
  52. $shouldReturn = false;
  53. try {
  54. $this->restProxy->setServiceProperties($serviceProperties);
  55. $this->assertFalse($this->isEmulated(), 'Should succeed when not running in emulator');
  56. } catch (ServiceException $e) {
  57. // Expect failure in emulator, as v1.6 doesn't support this method
  58. if ($this->isEmulated()) {
  59. $this->assertEquals(TestResources::STATUS_BAD_REQUEST, $e->getCode(), 'getCode');
  60. $shouldReturn = true;
  61. } else {
  62. throw $e;
  63. }
  64. }
  65. if($shouldReturn) {
  66. return;
  67. }
  68. $this->getServicePropertiesWorker(null);
  69. }
  70. /**
  71. * @covers WindowsAzure\Table\TableRestProxy::getServiceProperties
  72. * @covers WindowsAzure\Table\TableRestProxy::setServiceProperties
  73. */
  74. public function testGetServiceProperties()
  75. {
  76. $serviceProperties = TableServiceFunctionalTestData::getDefaultServiceProperties();
  77. try {
  78. $this->restProxy->setServiceProperties($serviceProperties);
  79. $this->assertFalse($this->isEmulated(), 'Should succeed when not running in emulator');
  80. } catch (ServiceException $e) {
  81. // Expect failure in emulator, as v1.6 doesn't support this method
  82. if ($this->isEmulated()) {
  83. $this->assertEquals(TestResources::STATUS_BAD_REQUEST, $e->getCode(), 'getCode');
  84. } else {
  85. throw $e;
  86. }
  87. }
  88. }
  89. /**
  90. * @covers WindowsAzure\Table\TableRestProxy::getServiceProperties
  91. */
  92. private function getServicePropertiesWorker($options)
  93. {
  94. self::println( 'Trying $options: ' . self::tmptostring($options));
  95. $effOptions = (is_null($options) ? new TableServiceOptions() : $options);
  96. try {
  97. $ret = (is_null($options) ? $this->restProxy->getServiceProperties() : $this->restProxy->getServiceProperties($effOptions));
  98. $this->assertFalse($this->isEmulated(), 'Should succeed when not running in emulator');
  99. $this->verifyServicePropertiesWorker($ret, null);
  100. } catch (ServiceException $e) {
  101. if ($this->isEmulated()) {
  102. // Expect failure in emulator, as v1.6 doesn't support this method
  103. $this->assertEquals(TestResources::STATUS_BAD_REQUEST, $e->getCode(), 'getCode');
  104. } else {
  105. $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'getCode');
  106. }
  107. }
  108. }
  109. private function verifyServicePropertiesWorker($ret, $serviceProperties)
  110. {
  111. if (is_null($serviceProperties)) {
  112. $serviceProperties = TableServiceFunctionalTestData::getDefaultServiceProperties();
  113. }
  114. $sp = $ret->getValue();
  115. $this->assertNotNull($sp, 'getValue should be non-null');
  116. $l = $sp->getLogging();
  117. $this->assertNotNull($l, 'getValue()->getLogging() should be non-null');
  118. $this->assertEquals($serviceProperties->getLogging()->getVersion(), $l->getVersion(), 'getValue()->getLogging()->getVersion');
  119. $this->assertEquals($serviceProperties->getLogging()->getDelete(), $l->getDelete(), 'getValue()->getLogging()->getDelete');
  120. $this->assertEquals($serviceProperties->getLogging()->getRead(), $l->getRead(), 'getValue()->getLogging()->getRead');
  121. $this->assertEquals($serviceProperties->getLogging()->getWrite(), $l->getWrite(), 'getValue()->getLogging()->getWrite');
  122. $r = $l->getRetentionPolicy();
  123. $this->assertNotNull($r, 'getValue()->getLogging()->getRetentionPolicy should be non-null');
  124. $this->assertEquals($serviceProperties->getLogging()->getRetentionPolicy()->getDays(), $r->getDays(), 'getValue()->getLogging()->getRetentionPolicy()->getDays');
  125. $m = $sp->getMetrics();
  126. $this->assertNotNull($m, 'getValue()->getMetrics() should be non-null');
  127. $this->assertEquals($serviceProperties->getMetrics()->getVersion(), $m->getVersion(), 'getValue()->getMetrics()->getVersion');
  128. $this->assertEquals($serviceProperties->getMetrics()->getEnabled(), $m->getEnabled(), 'getValue()->getMetrics()->getEnabled');
  129. $this->assertEquals($serviceProperties->getMetrics()->getIncludeAPIs(), $m->getIncludeAPIs(), 'getValue()->getMetrics()->getIncludeAPIs');
  130. $r = $m->getRetentionPolicy();
  131. $this->assertNotNull($r, 'getValue()->getMetrics()->getRetentionPolicy should be non-null');
  132. $this->assertEquals($serviceProperties->getMetrics()->getRetentionPolicy()->getDays(), $r->getDays(), 'getValue()->getMetrics()->getRetentionPolicy()->getDays');
  133. }
  134. /**
  135. * @covers WindowsAzure\Table\TableRestProxy::getServiceProperties
  136. * @covers WindowsAzure\Table\TableRestProxy::setServiceProperties
  137. */
  138. public function testSetServicePropertiesNoOptions()
  139. {
  140. $serviceProperties = TableServiceFunctionalTestData::getDefaultServiceProperties();
  141. $this->setServicePropertiesWorker($serviceProperties, null);
  142. }
  143. /**
  144. * @covers WindowsAzure\Table\TableRestProxy::getServiceProperties
  145. * @covers WindowsAzure\Table\TableRestProxy::setServiceProperties
  146. */
  147. public function testSetServiceProperties()
  148. {
  149. $interestingServiceProperties = TableServiceFunctionalTestData::getInterestingServiceProperties();
  150. foreach($interestingServiceProperties as $serviceProperties) {
  151. $options = new TableServiceOptions();
  152. $this->setServicePropertiesWorker($serviceProperties, $options);
  153. }
  154. if (!$this->isEmulated()) {
  155. $serviceProperties = TableServiceFunctionalTestData::getDefaultServiceProperties();
  156. $this->restProxy->setServiceProperties($serviceProperties);
  157. }
  158. }
  159. /**
  160. * @covers WindowsAzure\Table\TableRestProxy::getServiceProperties
  161. * @covers WindowsAzure\Table\TableRestProxy::setServiceProperties
  162. */
  163. private function setServicePropertiesWorker($serviceProperties, $options)
  164. {
  165. try {
  166. if (is_null($options)) {
  167. $this->restProxy->setServiceProperties($serviceProperties);
  168. } else {
  169. $this->restProxy->setServiceProperties($serviceProperties, $options);
  170. }
  171. $this->assertFalse($this->isEmulated(), 'Should succeed when not running in emulator');
  172. $ret = (is_null($options) ? $this->restProxy->getServiceProperties() : $this->restProxy->getServiceProperties($options));
  173. $this->verifyServicePropertiesWorker($ret, $serviceProperties);
  174. } catch (ServiceException $e) {
  175. if ($this->isEmulated()) {
  176. $this->assertEquals(TestResources::STATUS_BAD_REQUEST, $e->getCode(), 'getCode');
  177. } else {
  178. throw $e;
  179. }
  180. }
  181. }
  182. /**
  183. * @covers WindowsAzure\Table\TableRestProxy::queryTables
  184. */
  185. public function testQueryTablesNoOptions()
  186. {
  187. $this->queryTablesWorker(null);
  188. }
  189. /**
  190. * @covers WindowsAzure\Table\TableRestProxy::queryTables
  191. */
  192. public function testQueryTables()
  193. {
  194. $interestingqueryTablesOptions = TableServiceFunctionalTestData::getInterestingQueryTablesOptions($this->isEmulated());
  195. foreach($interestingqueryTablesOptions as $options) {
  196. $this->queryTablesWorker($options);
  197. }
  198. }
  199. /**
  200. * @covers WindowsAzure\Table\TableRestProxy::queryTables
  201. */
  202. private function queryTablesWorker($options)
  203. {
  204. try {
  205. $ret = (is_null($options) ? $this->restProxy->queryTables() : $this->restProxy->queryTables($options));
  206. if (is_null($options)) {
  207. $options = new QueryTablesOptions();
  208. }
  209. if ((!is_null($options->getTop()) && $options->getTop() <= 0)) {
  210. if ($this->isEmulated()) {
  211. $this->assertEquals(0, count($ret->getTables()), "should be no tables");
  212. } else {
  213. $this->fail('Expect non-positive Top in $options to throw');
  214. }
  215. }
  216. $this->verifyqueryTablesWorker($ret, $options);
  217. } catch (ServiceException $e) {
  218. if ((!is_null($options->getTop()) && $options->getTop() <= 0) && !$this->isEmulated()) {
  219. $this->assertEquals(TestResources::STATUS_BAD_REQUEST, $e->getCode(), 'getCode');
  220. } else {
  221. throw $e;
  222. }
  223. }
  224. }
  225. private function verifyqueryTablesWorker($ret, $options)
  226. {
  227. $this->assertNotNull($ret->getTables(), 'getTables');
  228. $effectivePrefix = $options->getPrefix();
  229. if (is_null($effectivePrefix)) {
  230. $effectivePrefix = '';
  231. }
  232. $expectedFilter = $options->getFilter();
  233. if (TableServiceFunctionalTestUtils::isEqNotInTopLevel($expectedFilter)) {
  234. // This seems wrong, but appears to be a bug in the $service itself.
  235. // So working around the limitation.
  236. $expectedFilter = TableServiceFunctionalTestUtils::cloneRemoveEqNotInTopLevel($expectedFilter);
  237. }
  238. $expectedData = array();
  239. foreach(TableServiceFunctionalTestData::$testTableNames as $s) {
  240. if (substr($s, 0, strlen($effectivePrefix)) == $effectivePrefix) {
  241. $fte = new FakeTableInfoEntry();
  242. $fte->TableName = $s;
  243. array_push($expectedData, $fte);
  244. }
  245. }
  246. if (!is_null($options->getNextTableName())) {
  247. $tmpExpectedData = array();
  248. $foundNext = false;
  249. foreach($expectedData as $s) {
  250. if ($s == $options->getNextTableName()) {
  251. $foundNext = true;
  252. }
  253. if (!$foundNext) {
  254. continue;
  255. }
  256. if (substr($s, 0, strlen($effectivePrefix)) == $effectivePrefix) {
  257. $fte = new FakeTableInfoEntry();
  258. $fte->TableName = $s;
  259. array_push($expectedData, $fte);
  260. }
  261. }
  262. $expectedData = $tmpExpectedData;
  263. }
  264. $expectedData = TableServiceFunctionalTestUtils::filterList($expectedFilter, $expectedData);
  265. $effectiveTop = (is_null($options->getTop()) ? 100000 : $options->getTop());
  266. $expectedCount = min($effectiveTop, count($expectedData));
  267. $tables = $ret->getTables();
  268. for ($i = 0; $i < $expectedCount; $i++) {
  269. $expected = $expectedData[$i]->TableName;
  270. // Assume there are other tables. Make sure the expected ones are there.
  271. $foundNext = false;
  272. foreach($tables as $actual) {
  273. if ($expected == $actual) {
  274. $foundNext = true;
  275. break;
  276. }
  277. }
  278. $this->assertTrue($foundNext, $expected . ' should be in getTables');
  279. }
  280. }
  281. /**
  282. * @covers WindowsAzure\Table\TableRestProxy::createTable
  283. * @covers WindowsAzure\Table\TableRestProxy::deleteTable
  284. * @covers WindowsAzure\Table\TableRestProxy::queryTables
  285. */
  286. public function testCreateTableNoOptions()
  287. {
  288. $this->createTableWorker(null);
  289. }
  290. /**
  291. * @covers WindowsAzure\Table\TableRestProxy::createTable
  292. * @covers WindowsAzure\Table\TableRestProxy::deleteTable
  293. * @covers WindowsAzure\Table\TableRestProxy::queryTables
  294. */
  295. public function testCreateTable()
  296. {
  297. $options = new TableServiceOptions();
  298. $this->createTableWorker($options);
  299. }
  300. /**
  301. * @covers WindowsAzure\Table\TableRestProxy::createTable
  302. * @covers WindowsAzure\Table\TableRestProxy::deleteTable
  303. * @covers WindowsAzure\Table\TableRestProxy::queryTables
  304. */
  305. private function createTableWorker($options)
  306. {
  307. $table = TableServiceFunctionalTestData::getInterestingTableName();
  308. $created = false;
  309. // Make sure that the list of all applicable Tables is correctly updated.
  310. $qto = new QueryTablesOptions();
  311. if (!$this->isEmulated()) {
  312. // The emulator has problems with some queries,
  313. // but full Azure allow this to be more efficient:
  314. $qto->setPrefix(TableServiceFunctionalTestData::$testUniqueId);
  315. }
  316. $qsStart = $this->restProxy->queryTables($qto);
  317. if (is_null($options)) {
  318. $this->restProxy->createTable($table);
  319. } else {
  320. $this->restProxy->createTable($table, $options);
  321. }
  322. $created = true;
  323. if (is_null($options)) {
  324. $options = new TableServiceOptions();
  325. }
  326. // Make sure that the list of all applicable Tables is correctly updated.
  327. $qs = $this->restProxy->queryTables($qto);
  328. if ($created) {
  329. $this->restProxy->deleteTable($table);
  330. }
  331. $this->assertEquals(count($qsStart->getTables()) + 1, count($qs->getTables()), 'After adding one, with Prefix=(\'' . TableServiceFunctionalTestData::$testUniqueId . '\'), then count(Tables)');
  332. }
  333. /**
  334. * @covers WindowsAzure\Table\TableRestProxy::createTable
  335. * @covers WindowsAzure\Table\TableRestProxy::deleteTable
  336. * @covers WindowsAzure\Table\TableRestProxy::queryTables
  337. */
  338. public function testDeleteTableNoOptions()
  339. {
  340. $this->deleteTableWorker(null);
  341. }
  342. /**
  343. * @covers WindowsAzure\Table\TableRestProxy::createTable
  344. * @covers WindowsAzure\Table\TableRestProxy::deleteTable
  345. * @covers WindowsAzure\Table\TableRestProxy::queryTables
  346. */
  347. public function testDeleteTable()
  348. {
  349. $options = new TableServiceOptions();
  350. $this->deleteTableWorker($options);
  351. }
  352. /**
  353. * @covers WindowsAzure\Table\TableRestProxy::createTable
  354. * @covers WindowsAzure\Table\TableRestProxy::deleteTable
  355. * @covers WindowsAzure\Table\TableRestProxy::queryTables
  356. */
  357. private function deleteTableWorker($options)
  358. {
  359. $Table = TableServiceFunctionalTestData::getInterestingTableName();
  360. // Make sure that the list of all applicable Tables is correctly updated.
  361. $qto = new QueryTablesOptions();
  362. if (!$this->isEmulated()) {
  363. // The emulator has problems with some queries,
  364. // but full Azure allow this to be more efficient:
  365. $qto->setPrefix(TableServiceFunctionalTestData::$testUniqueId);
  366. }
  367. $qsStart = $this->restProxy->queryTables($qto);
  368. // Make sure there is something to delete.
  369. $this->restProxy->createTable($Table);
  370. // Make sure that the list of all applicable Tables is correctly updated.
  371. $qs = $this->restProxy->queryTables($qto);
  372. $this->assertEquals(count($qsStart->getTables()) + 1, count($qs->getTables()), 'After adding one, with Prefix=(\'' . TableServiceFunctionalTestData::$testUniqueId . '\'), then count Tables');
  373. $deleted = false;
  374. if (is_null($options)) {
  375. $this->restProxy->deleteTable($Table);
  376. } else {
  377. $this->restProxy->deleteTable($Table, $options);
  378. }
  379. $deleted = true;
  380. if (is_null($options)) {
  381. $options = new TableServiceOptions();
  382. }
  383. // Make sure that the list of all applicable Tables is correctly updated.
  384. $qs = $this->restProxy->queryTables($qto);
  385. if (!$deleted) {
  386. $this->println('Test didn\'t delete the $Table, so try again more simply');
  387. // Try again. If it doesn't work, not much else to try.
  388. $this->restProxy->deleteTable($Table);
  389. }
  390. $this->assertEquals(count($qsStart->getTables()), count($qs->getTables()),'After adding then deleting one, with Prefix=(\'' . TableServiceFunctionalTestData::$testUniqueId . '\'), then count(Tables)');
  391. }
  392. /**
  393. * @covers WindowsAzure\Table\TableRestProxy::createTable
  394. * @covers WindowsAzure\Table\TableRestProxy::deleteTable
  395. * @covers WindowsAzure\Table\TableRestProxy::getTable
  396. */
  397. public function testGetTableNoOptions()
  398. {
  399. $this->getTableWorker(null);
  400. }
  401. /**
  402. * @covers WindowsAzure\Table\TableRestProxy::createTable
  403. * @covers WindowsAzure\Table\TableRestProxy::deleteTable
  404. * @covers WindowsAzure\Table\TableRestProxy::getTable
  405. */
  406. public function testGetTable()
  407. {
  408. $options = new TableServiceOptions();
  409. $this->getTableWorker($options);
  410. }
  411. /**
  412. * @covers WindowsAzure\Table\TableRestProxy::createTable
  413. * @covers WindowsAzure\Table\TableRestProxy::deleteTable
  414. * @covers WindowsAzure\Table\TableRestProxy::getTable
  415. */
  416. private function getTableWorker($options)
  417. {
  418. $table = TableServiceFunctionalTestData::getInterestingTableName();
  419. $created = false;
  420. $this->restProxy->createTable($table);
  421. $created = true;
  422. $ret = (is_null($options) ? $this->restProxy->getTable($table) : $this->restProxy->getTable($table, $options));
  423. if (is_null($options)) {
  424. $options = new TableServiceOptions();
  425. }
  426. $this->verifygetTableWorker($ret, $table);
  427. if ($created) {
  428. $this->restProxy->deleteTable($table);
  429. }
  430. }
  431. private function verifygetTableWorker($ret, $tableName)
  432. {
  433. $this->assertNotNull($ret, 'getTableEntry');
  434. $this->assertEquals($tableName, $ret->getName(), 'getTableEntry->Name');
  435. }
  436. /**
  437. * @covers WindowsAzure\Table\TableRestProxy::getEntity
  438. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  439. */
  440. public function testGetEntity()
  441. {
  442. $ents = TableServiceFunctionalTestData::getInterestingEntities();
  443. foreach($ents as $ent) {
  444. $options = new TableServiceOptions();
  445. $this->getEntityWorker($ent, true, $options);
  446. }
  447. }
  448. /**
  449. * @covers WindowsAzure\Table\TableRestProxy::getEntity
  450. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  451. */
  452. private function getEntityWorker($ent, $isGood, $options)
  453. {
  454. $table = $this->getCleanTable();
  455. try {
  456. // Upload the entity.
  457. $this->restProxy->insertEntity($table, $ent);
  458. $qer = (is_null($options) ? $this->restProxy->getEntity($table, $ent->getPartitionKey(), $ent->getRowKey()) : $this->restProxy->getEntity($table, $ent->getPartitionKey(), $ent->getRowKey(), $options));
  459. if (is_null($options)) {
  460. $options = new TableServiceOptions();
  461. }
  462. $this->assertNotNull($qer->getEntity(), 'getEntity()');
  463. $this->verifygetEntityWorker($ent, $qer->getEntity());
  464. } catch (ServiceException $e) {
  465. if (!$isGood) {
  466. $this->assertEquals(TestResources::STATUS_BAD_REQUEST, $e->getCode(), 'getCode');
  467. } else if (is_null($ent->getPartitionKey()) || is_null($ent->getRowKey())) {
  468. $this->assertEquals(TestResources::STATUS_BAD_REQUEST, $e->getCode(), 'getCode');
  469. } else {
  470. throw $e;
  471. }
  472. }
  473. $this->clearTable($table);
  474. }
  475. private function verifygetEntityWorker($ent, $entReturned)
  476. {
  477. $expectedProps = array();
  478. foreach($ent->getProperties() as $pname => $actualProp) {
  479. if (is_null($actualProp) || !is_null($actualProp->getValue())) {
  480. $cloneProp = null;
  481. if (!is_null($actualProp)) {
  482. $cloneProp = new Property();
  483. $cloneProp->setEdmType($actualProp->getEdmType());
  484. $cloneProp->setValue($actualProp->getValue());
  485. }
  486. $expectedProps[$pname] = $cloneProp;
  487. }
  488. }
  489. // Compare the entities to make sure they match.
  490. $this->assertEquals($ent->getPartitionKey(), $entReturned->getPartitionKey(), 'getPartitionKey');
  491. $this->assertEquals($ent->getRowKey(), $entReturned->getRowKey(), 'getRowKey');
  492. $this->assertNotNull($entReturned->getETag(), 'getETag');
  493. if (!is_null($ent->getETag())) {
  494. $this->assertEquals($ent->getETag(), $entReturned->getETag(), 'getETag');
  495. }
  496. $this->assertNotNull($entReturned->getTimestamp(), 'getTimestamp');
  497. if (is_null($ent->getTimestamp())) {
  498. // This property will come back, so need to account for it.
  499. $expectedProps['Timestamp'] = null;
  500. } else {
  501. $this->assertEquals($ent->getTimestamp(), $entReturned->getTimestamp(), 'getTimestamp');
  502. }
  503. $this->assertNotNull($ent->getProperties(), 'getProperties');
  504. $nullCount = 0;
  505. foreach($entReturned->getProperties() as $pname => $actualProp) {
  506. if (is_null($actualProp->getValue())) {
  507. $nullCount++;
  508. }
  509. }
  510. // Need to skip null values from the count.
  511. $this->assertEquals(count($expectedProps) + $nullCount, count($entReturned->getProperties()), 'getProperties()');
  512. foreach($entReturned->getProperties() as $pname => $actualProp) {
  513. $this->println($actualProp->getEdmType() . ':' . (is_null($actualProp->getValue()) ? 'NULL' :
  514. ($actualProp->getValue() instanceof \DateTime ? "date" : $actualProp->getValue())));
  515. }
  516. foreach($entReturned->getProperties() as $pname => $actualProp) {
  517. $expectedProp = Utilities::tryGetValue($expectedProps, $pname, null);
  518. $this->assertNotNull($actualProp, 'getProperties[\'' . $pname . '\']');
  519. if (!is_null($expectedProp)) {
  520. $this->compareProperties($pname, $actualProp, $expectedProp);
  521. }
  522. $this->assertEquals($entReturned->getProperty($pname), $actualProp, 'getProperty(\'' . $pname . '\')');
  523. $this->assertEquals($entReturned->getPropertyValue($pname), $actualProp->getValue(), 'getPropertyValue(\'' . $pname . '\')');
  524. }
  525. }
  526. /**
  527. * @covers WindowsAzure\Table\TableRestProxy::deleteEntity
  528. * @covers WindowsAzure\Table\TableRestProxy::getEntity
  529. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  530. */
  531. public function testDeleteEntity()
  532. {
  533. $ents = TableServiceFunctionalTestData::getSimpleEntities(3);
  534. for ($useETag = 0; $useETag <= 2; $useETag++) {
  535. foreach($ents as $ent) {
  536. $options = new DeleteEntityOptions();
  537. $this->deleteEntityWorker($ent, $useETag, $options);
  538. }
  539. }
  540. }
  541. /**
  542. * @covers WindowsAzure\Table\TableRestProxy::deleteEntity
  543. * @covers WindowsAzure\Table\TableRestProxy::getEntity
  544. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  545. */
  546. private function deleteEntityWorker($ent, $useETag, $options)
  547. {
  548. $table = $this->getCleanTable();
  549. try {
  550. // Upload the entity.
  551. $ier = $this->restProxy->insertEntity($table, $ent);
  552. if ($useETag == 1) {
  553. $options->setETag($ier->getEntity()->getETag());
  554. } else if ($useETag == 2) {
  555. $options->setETag('W/"datetime\'2012-03-05T21%3A46%3A25->5385467Z\'"');
  556. }
  557. $this->restProxy->deleteEntity($table, $ent->getPartitionKey(), $ent->getRowKey(), $options);
  558. if ($useETag == 2) {
  559. $this->fail('Expect bad etag throws');
  560. }
  561. // Check that the entity really is gone
  562. $gotError = false;
  563. try {
  564. $this->restProxy->getEntity($table, $ent->getPartitionKey(), $ent->getRowKey());
  565. } catch (ServiceException $e2) {
  566. $gotError = ($e2->getCode() == TestResources::STATUS_NOT_FOUND);
  567. }
  568. $this->assertTrue($gotError, 'Expect error when entity is deleted');
  569. } catch (ServiceException $e) {
  570. if ($useETag == 2) {
  571. $this->assertEquals(TestResources::STATUS_PRECONDITION_FAILED, $e->getCode(), 'getCode');
  572. } else {
  573. throw $e;
  574. }
  575. }
  576. $this->clearTable($table);
  577. }
  578. /**
  579. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  580. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  581. */
  582. public function testInsertEntity()
  583. {
  584. $ents = TableServiceFunctionalTestData::getInterestingEntities();
  585. foreach($ents as $ent) {
  586. $options = new TableServiceOptions();
  587. $this->insertEntityWorker($ent, true, $options);
  588. }
  589. }
  590. /**
  591. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  592. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  593. */
  594. public function testInsertBadEntity()
  595. {
  596. $ents = TableServiceFunctionalTestData::getInterestingBadEntities();
  597. foreach($ents as $ent) {
  598. $options = new TableServiceOptions();
  599. try {
  600. $this->insertEntityWorker($ent, true, $options);
  601. $this->fail('this call should fail');
  602. } catch (\InvalidArgumentException $e) {
  603. $this->assertEquals(0, $e->getCode(), 'getCode');
  604. $this->assertTrue(true, 'got expected exception');
  605. }
  606. }
  607. }
  608. /**
  609. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  610. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  611. */
  612. public function testInsertEntityBoolean()
  613. {
  614. foreach(TableServiceFunctionalTestData::getInterestingGoodBooleans() as $o) {
  615. $ent = new Entity();
  616. $ent->setPartitionKey(TableServiceFunctionalTestData::getNewKey());
  617. $ent->setRowKey(TableServiceFunctionalTestData::getNewKey());
  618. $ent->addProperty('BOOLEAN', EdmType::BOOLEAN, $o);
  619. $this->insertEntityWorker($ent, true, null, $o);
  620. }
  621. }
  622. /**
  623. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  624. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  625. */
  626. public function testInsertEntityBooleanNegative()
  627. {
  628. foreach(TableServiceFunctionalTestData::getInterestingBadBooleans() as $o) {
  629. $ent = new Entity();
  630. $ent->setPartitionKey(TableServiceFunctionalTestData::getNewKey());
  631. $ent->setRowKey(TableServiceFunctionalTestData::getNewKey());
  632. try {
  633. $ent->addProperty('BOOLEAN', EdmType::BOOLEAN, $o);
  634. $this->fail('Should get an exception when trying to parse this value');
  635. $this->insertEntityWorker($ent, false, null, $o);
  636. } catch (\Exception $e) {
  637. $this->assertEquals(0, $e->getCode(), 'getCode');
  638. $this->assertTrue(true, 'got expected exception');
  639. }
  640. }
  641. }
  642. /**
  643. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  644. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  645. */
  646. public function testInsertEntityDate()
  647. {
  648. foreach(TableServiceFunctionalTestData::getInterestingGoodDates() as $o) {
  649. $ent = new Entity();
  650. $ent->setPartitionKey(TableServiceFunctionalTestData::getNewKey());
  651. $ent->setRowKey(TableServiceFunctionalTestData::getNewKey());
  652. $ent->addProperty('DATETIME', EdmType::DATETIME, $o);
  653. $this->insertEntityWorker($ent, true, null, $o);
  654. }
  655. }
  656. /**
  657. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  658. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  659. */
  660. public function testInsertEntityDateNegative()
  661. {
  662. foreach(TableServiceFunctionalTestData::getInterestingBadDates() as $o) {
  663. $ent = new Entity();
  664. $ent->setPartitionKey(TableServiceFunctionalTestData::getNewKey());
  665. $ent->setRowKey(TableServiceFunctionalTestData::getNewKey());
  666. try {
  667. $ent->addProperty('DATETIME', EdmType::DATETIME, $o);
  668. $this->fail('Should get an exception when trying to parse this value');
  669. $this->insertEntityWorker($ent, false, null, $o);
  670. } catch (\Exception $e) {
  671. $this->assertEquals(0, $e->getCode(), 'getCode');
  672. $this->assertTrue(true, 'got expected exception');
  673. }
  674. }
  675. }
  676. /**
  677. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  678. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  679. */
  680. public function testInsertEntityDouble()
  681. {
  682. foreach(TableServiceFunctionalTestData::getInterestingGoodDoubles() as $o) {
  683. $ent = new Entity();
  684. $ent->setPartitionKey(TableServiceFunctionalTestData::getNewKey());
  685. $ent->setRowKey(TableServiceFunctionalTestData::getNewKey());
  686. $ent->addProperty('DOUBLE', EdmType::DOUBLE, $o);
  687. $this->insertEntityWorker($ent, true, null, $o);
  688. }
  689. }
  690. /**
  691. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  692. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  693. */
  694. public function testInsertEntityDoubleNegative()
  695. {
  696. foreach(TableServiceFunctionalTestData::getInterestingBadDoubles() as $o) {
  697. $ent = new Entity();
  698. $ent->setPartitionKey(TableServiceFunctionalTestData::getNewKey());
  699. $ent->setRowKey(TableServiceFunctionalTestData::getNewKey());
  700. try {
  701. $ent->addProperty('DOUBLE', EdmType::DOUBLE, $o);
  702. $this->fail('Should get an exception when trying to parse this value');
  703. $this->insertEntityWorker($ent, false, null, $o);
  704. } catch (\Exception $e) {
  705. $this->assertEquals(0, $e->getCode(), 'getCode');
  706. $this->assertTrue(true, 'got expected exception');
  707. }
  708. }
  709. }
  710. /**
  711. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  712. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  713. */
  714. public function testInsertEntityGuid()
  715. {
  716. foreach(TableServiceFunctionalTestData::getInterestingGoodGuids() as $o) {
  717. $ent = new Entity();
  718. $ent->setPartitionKey(TableServiceFunctionalTestData::getNewKey());
  719. $ent->setRowKey(TableServiceFunctionalTestData::getNewKey());
  720. $ent->addProperty('GUID', EdmType::GUID, $o);
  721. $this->insertEntityWorker($ent, true, null, $o);
  722. }
  723. }
  724. /**
  725. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  726. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  727. */
  728. public function testInsertEntityGuidNegative()
  729. {
  730. foreach(TableServiceFunctionalTestData::getInterestingBadGuids() as $o) {
  731. $ent = new Entity();
  732. $ent->setPartitionKey(TableServiceFunctionalTestData::getNewKey());
  733. $ent->setRowKey(TableServiceFunctionalTestData::getNewKey());
  734. try {
  735. $ent->addProperty('GUID', EdmType::GUID, $o);
  736. $this->fail('Should get an exception when trying to parse this value');
  737. $this->insertEntityWorker($ent, false, null, $o);
  738. } catch (\Exception $e) {
  739. $this->assertEquals(0, $e->getCode(), 'getCode');
  740. $this->assertTrue(true, 'got expected exception');
  741. }
  742. }
  743. }
  744. /**
  745. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  746. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  747. */
  748. public function testInsertEntityInt()
  749. {
  750. foreach(TableServiceFunctionalTestData::getInterestingGoodInts() as $o) {
  751. $ent = new Entity();
  752. $ent->setPartitionKey(TableServiceFunctionalTestData::getNewKey());
  753. $ent->setRowKey(TableServiceFunctionalTestData::getNewKey());
  754. $ent->addProperty('INT32', EdmType::INT32, $o);
  755. $this->insertEntityWorker($ent, true, null, $o);
  756. }
  757. }
  758. /**
  759. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  760. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  761. */
  762. public function testInsertEntityIntNegative()
  763. {
  764. foreach(TableServiceFunctionalTestData::getInterestingBadInts() as $o) {
  765. $ent = new Entity();
  766. $ent->setPartitionKey(TableServiceFunctionalTestData::getNewKey());
  767. $ent->setRowKey(TableServiceFunctionalTestData::getNewKey());
  768. try {
  769. $ent->addProperty('INT32', EdmType::INT32, $o);
  770. $this->fail('Should get an exception when trying to parse this value');
  771. $this->insertEntityWorker($ent, false, null, $o);
  772. } catch (\Exception $e) {
  773. $this->assertEquals(0, $e->getCode(), 'getCode');
  774. $this->assertTrue(true, 'got expected exception');
  775. }
  776. }
  777. }
  778. /**
  779. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  780. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  781. */
  782. public function testInsertEntityLong()
  783. {
  784. foreach(TableServiceFunctionalTestData::getInterestingGoodLongs() as $o) {
  785. $ent = new Entity();
  786. $ent->setPartitionKey(TableServiceFunctionalTestData::getNewKey());
  787. $ent->setRowKey(TableServiceFunctionalTestData::getNewKey());
  788. $ent->addProperty('INT64', EdmType::INT64, $o);
  789. $this->insertEntityWorker($ent, true, null, $o);
  790. }
  791. }
  792. /**
  793. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  794. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  795. */
  796. public function testInsertEntityLongNegative()
  797. {
  798. foreach(TableServiceFunctionalTestData::getInterestingBadLongs() as $o) {
  799. $ent = new Entity();
  800. $ent->setPartitionKey(TableServiceFunctionalTestData::getNewKey());
  801. $ent->setRowKey(TableServiceFunctionalTestData::getNewKey());
  802. try {
  803. $ent->addProperty('INT64', EdmType::INT64, $o);
  804. $this->fail('Should get an exception when trying to parse this value');
  805. $this->insertEntityWorker($ent, false, null, $o);
  806. } catch (\Exception $e) {
  807. $this->assertEquals(0, $e->getCode(), 'getCode');
  808. $this->assertTrue(true, 'got expected exception');
  809. }
  810. }
  811. }
  812. /**
  813. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  814. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  815. */
  816. public function testInsertEntityBinary()
  817. {
  818. foreach(TableServiceFunctionalTestData::getInterestingGoodBinaries() as $o) {
  819. $ent = new Entity();
  820. $ent->setPartitionKey(TableServiceFunctionalTestData::getNewKey());
  821. $ent->setRowKey(TableServiceFunctionalTestData::getNewKey());
  822. $ent->addProperty('BINARY', EdmType::BINARY, $o);
  823. $this->insertEntityWorker($ent, true, null, $o);
  824. }
  825. }
  826. /**
  827. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  828. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  829. */
  830. public function testInsertEntityBinaryNegative()
  831. {
  832. foreach(TableServiceFunctionalTestData::getInterestingBadBinaries() as $o) {
  833. $ent = new Entity();
  834. $ent->setPartitionKey(TableServiceFunctionalTestData::getNewKey());
  835. $ent->setRowKey(TableServiceFunctionalTestData::getNewKey());
  836. try {
  837. $ent->addProperty('BINARY', EdmType::BINARY, $o);
  838. $this->fail('Should get an exception when trying to parse this value');
  839. $this->insertEntityWorker($ent, false, null, $o);
  840. } catch (\Exception $e) {
  841. $this->assertEquals(0, $e->getCode(), 'getCode');
  842. $this->assertTrue(true, 'got expected exception');
  843. }
  844. }
  845. }
  846. /**
  847. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  848. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  849. */
  850. public function testInsertEntityString()
  851. {
  852. foreach(TableServiceFunctionalTestData::getInterestingGoodStrings() as $o) {
  853. $ent = new Entity();
  854. $ent->setPartitionKey(TableServiceFunctionalTestData::getNewKey());
  855. $ent->setRowKey(TableServiceFunctionalTestData::getNewKey());
  856. $ent->addProperty('STRING', EdmType::STRING, $o);
  857. $this->insertEntityWorker($ent, true, null, $o);
  858. }
  859. }
  860. /**
  861. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  862. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  863. */
  864. private function insertEntityWorker($ent, $isGood, $options, $specialValue = null)
  865. {
  866. $table = $this->getCleanTable();
  867. try {
  868. $ret = (is_null($options) ? $this->restProxy->insertEntity($table, $ent) : $this->restProxy->insertEntity($table, $ent, $options));
  869. if (is_null($options)) {
  870. $options = new TableServiceOptions();
  871. }
  872. // Check that the message matches
  873. $this->assertNotNull($ret->getEntity(), 'getEntity()');
  874. $this->verifyinsertEntityWorker($ent, $ret->getEntity());
  875. if (is_null($ent->getPartitionKey()) || is_null($ent->getRowKey())) {
  876. $this->fail('Expect missing keys throw');
  877. }
  878. if (!$isGood) {
  879. $this->fail('Expect bad values to throw: ' . self::tmptostring($specialValue));
  880. }
  881. // Check that the message matches
  882. $qer = $this->restProxy->queryEntities($table);
  883. $this->assertNotNull($qer->getEntities(), 'getEntities()');
  884. $this->assertEquals(1, count($qer->getEntities()), 'getEntities() count');
  885. $entReturned = $qer->getEntities();
  886. $entReturned = $entReturned[0];
  887. $this->assertNotNull($entReturned, 'getEntities()[0]');
  888. $this->verifyinsertEntityWorker($ent, $entReturned);
  889. } catch (ServiceException $e) {
  890. if (!$isGood) {
  891. $this->assertEquals(TestResources::STATUS_BAD_REQUEST, $e->getCode(), 'getCode');
  892. } else if (is_null($ent->getPartitionKey()) || is_null($ent->getRowKey())) {
  893. $this->assertEquals(TestResources::STATUS_BAD_REQUEST, $e->getCode(), 'getCode');
  894. } else {
  895. throw $e;
  896. }
  897. }
  898. $this->clearTable($table);
  899. }
  900. /**
  901. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  902. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  903. * @covers WindowsAzure\Table\TableRestProxy::updateEntity
  904. */
  905. public function testUpdateEntity()
  906. {
  907. $ents = TableServiceFunctionalTestData::getSimpleEntities(2);
  908. foreach(MutatePivot::values() as $mutatePivot) {
  909. foreach($ents as $initialEnt) {
  910. $options = new TableServiceOptions();
  911. $ent = TableServiceFunctionalTestUtils::cloneEntity($initialEnt);
  912. TableServiceFunctionalTestUtils::mutateEntity($ent, $mutatePivot);
  913. $this->updateEntityWorker($initialEnt, $ent, $options);
  914. }
  915. }
  916. }
  917. /**
  918. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  919. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  920. * @covers WindowsAzure\Table\TableRestProxy::updateEntity
  921. */
  922. private function updateEntityWorker($initialEnt, $ent, $options)
  923. {
  924. $table = $this->getCleanTable();
  925. // Upload the entity.
  926. $this->restProxy->insertEntity($table, $initialEnt);
  927. if (is_null($options)) {
  928. $this->restProxy->updateEntity($table, $ent);
  929. } else {
  930. $this->restProxy->updateEntity($table, $ent, $options);
  931. }
  932. if (is_null($options)) {
  933. $options = new TableServiceOptions();
  934. }
  935. // Check that the message matches
  936. $qer = $this->restProxy->queryEntities($table);
  937. $this->assertNotNull($qer->getEntities(), 'getEntities()');
  938. $this->assertEquals(1, count($qer->getEntities()), 'getEntities()');
  939. $entReturned = $qer->getEntities();
  940. $entReturned = $entReturned[0];
  941. $this->assertNotNull($entReturned, 'getEntities()[0]');
  942. $this->verifyinsertEntityWorker($ent, $entReturned);
  943. $this->clearTable($table);
  944. }
  945. /**
  946. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  947. * @covers WindowsAzure\Table\TableRestProxy::mergeEntity
  948. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  949. */
  950. public function testMergeEntity()
  951. {
  952. $ents = TableServiceFunctionalTestData::getSimpleEntities(2);
  953. foreach(MutatePivot::values() as $mutatePivot) {
  954. foreach($ents as $initialEnt) {
  955. $options = new TableServiceOptions();
  956. $ent = TableServiceFunctionalTestUtils::cloneEntity($initialEnt);
  957. TableServiceFunctionalTestUtils::mutateEntity($ent, $mutatePivot);
  958. $this->mergeEntityWorker($initialEnt, $ent, $options);
  959. }
  960. }
  961. }
  962. /**
  963. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  964. * @covers WindowsAzure\Table\TableRestProxy::mergeEntity
  965. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  966. */
  967. private function mergeEntityWorker($initialEnt, $ent, $options)
  968. {
  969. $table = $this->getCleanTable();
  970. // Upload the entity.
  971. $this->restProxy->insertEntity($table, $initialEnt);
  972. if (is_null($options)) {
  973. $this->restProxy->mergeEntity($table, $ent);
  974. } else {
  975. $this->restProxy->mergeEntity($table, $ent, $options);
  976. }
  977. if (is_null($options)) {
  978. $options = new TableServiceOptions();
  979. }
  980. // Check that the message matches
  981. $qer = $this->restProxy->queryEntities($table);
  982. $this->assertNotNull($qer->getEntities(), 'getEntities()');
  983. $this->assertEquals(1, count($qer->getEntities()), 'getEntities() count');
  984. $entReturned = $qer->getEntities();
  985. $entReturned = $entReturned[0];
  986. $this->assertNotNull($entReturned, 'getEntities()[0]');
  987. $this->verifymergeEntityWorker($initialEnt, $ent, $entReturned);
  988. $this->clearTable($table);
  989. }
  990. /**
  991. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  992. * @covers WindowsAzure\Table\TableRestProxy::insertOrReplaceEntity
  993. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  994. */
  995. public function testInsertOrReplaceEntity()
  996. {
  997. $ents = TableServiceFunctionalTestData::getSimpleEntities(2);
  998. foreach(MutatePivot::values() as $mutatePivot) {
  999. foreach($ents as $initialEnt) {
  1000. $options = new TableServiceOptions();
  1001. $ent = TableServiceFunctionalTestUtils::cloneEntity($initialEnt);
  1002. TableServiceFunctionalTestUtils::mutateEntity($ent, $mutatePivot);
  1003. try {
  1004. $this->insertOrReplaceEntityWorker($initialEnt, $ent, $options);
  1005. $this->assertFalse($this->isEmulated(), 'Should succeed when not running in emulator');
  1006. } catch (ServiceException $e) {
  1007. // Expect failure in emulator, as v1.6 doesn't support this method
  1008. if ($this->isEmulated()) {
  1009. $this->assertEquals(TestResources::STATUS_BAD_REQUEST, $e->getCode(), 'getCode');
  1010. } else {
  1011. throw $e;
  1012. }
  1013. }
  1014. }
  1015. }
  1016. }
  1017. /**
  1018. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  1019. * @covers WindowsAzure\Table\TableRestProxy::insertOrReplaceEntity
  1020. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  1021. */
  1022. private function insertOrReplaceEntityWorker($initialEnt, $ent, $options)
  1023. {
  1024. $table = $this->getCleanTable();
  1025. // Upload the entity.
  1026. $this->restProxy->insertEntity($table, $initialEnt);
  1027. if (is_null($options)) {
  1028. $this->restProxy->insertOrReplaceEntity($table, $ent);
  1029. } else {
  1030. $this->restProxy->insertOrReplaceEntity($table, $ent, $options);
  1031. }
  1032. if (is_null($options)) {
  1033. $options = new TableServiceOptions();
  1034. }
  1035. // Check that the message matches
  1036. $qer = $this->restProxy->queryEntities($table);
  1037. $this->assertNotNull($qer->getEntities(), 'getEntities()');
  1038. $this->assertEquals(1, count($qer->getEntities()), 'getEntities() count');
  1039. $entReturned = $qer->getEntities();
  1040. $entReturned = $entReturned[0];
  1041. $this->assertNotNull($entReturned, 'getEntities()[0]');
  1042. $this->verifyinsertEntityWorker($ent, $entReturned);
  1043. $this->clearTable($table);
  1044. }
  1045. /**
  1046. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  1047. * @covers WindowsAzure\Table\TableRestProxy::insertOrMergeEntity
  1048. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  1049. */
  1050. public function testInsertOrMergeEntity()
  1051. {
  1052. $ents = TableServiceFunctionalTestData::getSimpleEntities(2);
  1053. foreach(MutatePivot::values() as $mutatePivot) {
  1054. foreach($ents as $initialEnt) {
  1055. $options = new TableServiceOptions();
  1056. $ent = TableServiceFunctionalTestUtils::cloneEntity($initialEnt);
  1057. TableServiceFunctionalTestUtils::mutateEntity($ent, $mutatePivot);
  1058. try {
  1059. $this->insertOrMergeEntityWorker($initialEnt, $ent, $options);
  1060. $this->assertFalse($this->isEmulated(), 'Should succeed when not running in emulator');
  1061. } catch (ServiceException $e) {
  1062. // Expect failure in emulator, as v1.6 doesn't support this method
  1063. if ($this->isEmulated()) {
  1064. $this->assertEquals(TestResources::STATUS_BAD_REQUEST, $e->getCode(), 'getCode');
  1065. } else {
  1066. throw $e;
  1067. }
  1068. }
  1069. }
  1070. }
  1071. }
  1072. /**
  1073. * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  1074. * @covers WindowsAzure\Table\TableRestProxy::insertOrMergeEntity
  1075. * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  1076. */
  1077. private function insertOrMergeEntityWorker($initialEnt, $ent, $options)
  1078. {
  1079. $table = $this->getCleanTable();
  1080. // Upload the entity.
  1081. $this->restProxy->insertEntity($table, $initialEnt);
  1082. if (i

Large files files are truncated, but you can click here to view the full file