SimpleDbTest.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Cloud_DocumentService
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. // Call Zend_Cloud_DocumentService_Adapter_SimpleDbTest::main() if this source file is executed directly.
  22. if (!defined("PHPUnit_MAIN_METHOD")) {
  23. define("PHPUnit_MAIN_METHOD", "Zend_Cloud_DocumentService_Adapter_SimpleDbTest::main");
  24. }
  25. /**
  26. * Test helper
  27. */
  28. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  29. /**
  30. * @see Zend_Cloud_DocumentServiceTestCase
  31. */
  32. require_once 'Zend/Cloud/DocumentService/TestCase.php';
  33. /** @see Zend_Cloud_DocumenteService_Factory */
  34. require_once 'Zend/Cloud/DocumentService/Factory.php';
  35. /** @see Zend_Cloud_DocumenteService_Adapter_SimpleDb */
  36. require_once 'Zend/Cloud/DocumentService/Adapter/SimpleDb.php';
  37. /** @see Zend_Config */
  38. require_once 'Zend/Config.php';
  39. /**
  40. * @category Zend
  41. * @package Zend_Cloud
  42. * @subpackage UnitTests
  43. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  44. * @license http://framework.zend.com/license/new-bsd New BSD License
  45. */
  46. class Zend_Cloud_DocumentService_Adapter_SimpleDbTest
  47. extends Zend_Cloud_DocumentService_TestCase
  48. {
  49. /**
  50. * Period to wait for propagation in seconds
  51. * Should be set by adapter
  52. *
  53. * @var int
  54. */
  55. protected $_waitPeriod = 10;
  56. protected $_clientType = 'Zend_Service_Amazon_SimpleDb';
  57. /**
  58. * Runs the test methods of this class.
  59. *
  60. * @access public
  61. * @static
  62. */
  63. public static function main()
  64. {
  65. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  66. $result = PHPUnit_TextUI_TestRunner::run($suite);
  67. }
  68. public function testUpdateDocumentMergeAll()
  69. {
  70. $data = $this->_getDocumentData();
  71. $name = $this->_collectionName("testMerge");
  72. $this->_commonDocument->createCollection($name);
  73. $doc = $this->_makeDocument($data[0]);
  74. $this->_commonDocument->insertDocument($name, $doc);
  75. $doc1 = $this->_makeDocument($data[1]);
  76. $this->_wait();
  77. $this->_commonDocument->updateDocument($name, $doc->getID(), $doc1,
  78. array(Zend_Cloud_DocumentService_Adapter_SimpleDb::MERGE_OPTION => true));
  79. $this->_wait();
  80. $fetchdoc = $this->_commonDocument->fetchDocument($name, $doc->getID());
  81. $this->assertTrue($fetchdoc instanceof Zend_Cloud_DocumentService_Document, "New document not found");
  82. $this->assertContains($doc->name, $fetchdoc->name, "Name field did not update: " . var_export($fetchdoc->getFields(), 1));
  83. $this->assertContains($doc1->name, $fetchdoc->name, "Name field did not update: " . var_export($fetchdoc->getFields(), 1));
  84. $this->assertContains((string) $doc->year, $fetchdoc->year, "Year field did not update: " . var_export($fetchdoc->getFields(), 1));
  85. $this->assertContains((string) $doc1->year, $fetchdoc->year, "Year field did not update: " . var_export($fetchdoc->getFields(), 1));
  86. $this->_commonDocument->deleteCollection($name);
  87. }
  88. public function testUpdateDocumentMergeSome()
  89. {
  90. $data = $this->_getDocumentData();
  91. $name = $this->_collectionName("testMerge");
  92. $this->_commonDocument->createCollection($name);
  93. $doc = $this->_makeDocument($data[0]);
  94. $this->_commonDocument->insertDocument($name, $doc);
  95. $doc1 = $this->_makeDocument($data[1]);
  96. $this->_wait();
  97. $this->_commonDocument->updateDocument($name, $doc->getID(), $doc1,
  98. array(Zend_Cloud_DocumentService_Adapter_SimpleDb::MERGE_OPTION =>
  99. array("year" => true, "pages" => true)));
  100. $this->_wait();
  101. $fetchdoc = $this->_commonDocument->fetchDocument($name, $doc->getID());
  102. $this->assertTrue($fetchdoc instanceof Zend_Cloud_DocumentService_Document, "New document not found");
  103. $this->assertEquals($doc1->name, $fetchdoc->name, "Name field did not update");
  104. $this->assertContains((string) $doc1->pages, $fetchdoc->pages, "Page field did not update");
  105. $this->assertContains((string) $doc->pages, $fetchdoc->pages, "Page field did not update");
  106. $this->assertContains((string) $doc1->year, $fetchdoc->year, "Year field did not update");
  107. $this->assertContains((string) $doc->year, $fetchdoc->year, "Year field did not update");
  108. $this->_commonDocument->deleteCollection($name);
  109. }
  110. static function getConfigArray()
  111. {
  112. return array(
  113. Zend_Cloud_DocumentService_Factory::DOCUMENT_ADAPTER_KEY => 'Zend_Cloud_DocumentService_Adapter_SimpleDb',
  114. Zend_Cloud_DocumentService_Adapter_SimpleDb::AWS_ACCESS_KEY => constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID'),
  115. Zend_Cloud_DocumentService_Adapter_SimpleDb::AWS_SECRET_KEY => constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY'),
  116. );
  117. }
  118. protected function _getConfig()
  119. {
  120. if (!defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ENABLED') ||
  121. !constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ENABLED') ||
  122. !defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID') ||
  123. !defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY')) {
  124. $this->markTestSkipped("Amazon SimpleDB access not configured, skipping test");
  125. }
  126. $config = new Zend_Config(self::getConfigArray());
  127. return $config;
  128. }
  129. protected function _getDocumentData()
  130. {
  131. return array(
  132. array(
  133. parent::ID_FIELD => "0385333498",
  134. "name" => "The Sirens of Titan",
  135. "author" => "Kurt Vonnegut",
  136. "year" => 1959,
  137. "pages" => 336,
  138. "keyword" => array("Book", "Paperback")
  139. ),
  140. array(
  141. parent::ID_FIELD => "0802131786",
  142. "name" => "Tropic of Cancer",
  143. "author" => "Henry Miller",
  144. "year" => 1934,
  145. "pages" => 318,
  146. "keyword" => array("Book")
  147. ),
  148. array(
  149. parent::ID_FIELD => "B000T9886K",
  150. "name" => "In Between",
  151. "author" => "Paul Van Dyk",
  152. "year" => 2007,
  153. "keyword" => array("CD", "Music")
  154. ),
  155. array(
  156. parent::ID_FIELD => "1579124585",
  157. "name" => "The Right Stuff",
  158. "author" => "Tom Wolfe",
  159. "year" => 1979,
  160. "pages" => 304,
  161. "keyword" => array("American", "Book", "Hardcover")
  162. ),
  163. );
  164. }
  165. protected function _queryString($domain, $s1, $s2)
  166. {
  167. return "select * from $domain where itemName() = '$s1' OR itemName() = '$s2'";
  168. }
  169. }
  170. if (PHPUnit_MAIN_METHOD == 'Zend_Cloud_DocumentService_Adapter_SimpleDbTest::main') {
  171. Zend_Cloud_DocumentService_Adapter_SimpleDbTest::main();
  172. }