PageRenderTime 33ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/OData Producer for PHP/Tests/UriProcessor/UriProcessorTest.php

#
PHP | 2461 lines | 1975 code | 149 blank | 337 comment | 134 complexity | 5840980579cbdb4b484766a33ca79aa8 MD5 | raw file
  1. <?php
  2. /**
  3. * Mainly test UriProcessor, but also do some partial test for DataService class.
  4. */
  5. use ODataProducer\UriProcessor\QueryProcessor\ExpandProjectionParser\ProjectionNode;
  6. use ODataProducer\UriProcessor\QueryProcessor\ExpandProjectionParser\ExpandedProjectionNode;
  7. use ODataProducer\UriProcessor\QueryProcessor\ExpandProjectionParser\RootProjectionNode;
  8. use ODataProducer\UriProcessor\QueryProcessor\AnonymousFunction;
  9. use ODataProducer\UriProcessor\QueryProcessor\OrderByParser\OrderBySubPathSegment;
  10. use ODataProducer\UriProcessor\QueryProcessor\OrderByParser\OrderByPathSegment;
  11. use ODataProducer\UriProcessor\QueryProcessor\SkipTokenParser\InternalSkipTokenInfo;
  12. use ODataProducer\UriProcessor\QueryProcessor\SkipTokenParser\SkipTokenInfo;
  13. use ODataProducer\UriProcessor\QueryProcessor\ExpressionParser\InternalFilterInfo;
  14. use ODataProducer\UriProcessor\QueryProcessor\OrderByParser\InternalOrderByInfo;
  15. use ODataProducer\UriProcessor\RequestCountOption;
  16. use ODataProducer\Configuration\DataServiceProtocolVersion;
  17. use ODataProducer\UriProcessor\ResourcePathProcessor\SegmentParser\RequestTargetKind;
  18. use ODataProducer\UriProcessor\ResourcePathProcessor\SegmentParser\RequestTargetSource;
  19. use ODataProducer\Providers\Metadata\Type\Int32;
  20. use ODataProducer\Providers\Metadata\Type\DateTime;
  21. use ODataProducer\Common\Url;
  22. use ODataProducer\Common\Version;
  23. use ODataProducer\Common\ODataException;
  24. require_once 'PHPUnit\Framework\Assert.php';
  25. require_once 'PHPUnit\Framework\Test.php';
  26. require_once 'PHPUnit\Framework\SelfDescribing.php';
  27. require_once 'PHPUnit\Framework\TestCase.php';
  28. require_once 'PHPUnit\Framework\TestSuite.php';
  29. require_once 'ODataProducer\Common\ClassAutoLoader.php';
  30. require_once (dirname(__FILE__) . "\.\..\Resources\NorthWindMetadata.php");
  31. require_once (dirname(__FILE__) . "\.\..\Resources\NorthWindDataServiceV1.php");
  32. require_once (dirname(__FILE__) . "\.\..\Resources\NorthWindDataService.php");
  33. require_once (dirname(__FILE__) . "\.\..\Resources\NorthWindDataServiceV3.php");
  34. require_once (dirname(__FILE__) . "\.\..\Resources\DataServiceHost2.php");
  35. ODataProducer\Common\ClassAutoLoader::register();
  36. class TestUriProcessor extends PHPUnit_Framework_TestCase
  37. {
  38. protected function setUp()
  39. {
  40. }
  41. /**
  42. * The request uri should be based on the service uri specified in the configuration.
  43. */
  44. /**public function testRequestUriWithInvalidBaseUri()
  45. {
  46. try {
  47. $hostInfo = array('AbsoluteRequestUri' =>
  48. new Url('http://localhost:8083/NorthWindDataService.svc'),
  49. 'AbsoluteServiceUri' =>
  50. new Url('http://localhost:8083/XX/NorthWindDataService.svc'),
  51. 'QueryString' =>
  52. null);
  53. $host = new DataServiceHost2($hostInfo);
  54. $dataService = new NorthWindDataService2();
  55. $dataService->setHost($host);
  56. $exceptionThrown = false;
  57. try {
  58. $dataService->handleRequest();
  59. } catch (ODataException $odataException) {
  60. $exceptionThrown = true;
  61. $this->assertStringStartsWith("The URI 'http://localhost:8083/NorthWindDataService.svc' is not ", $odataException->getMessage());
  62. }
  63. if (!$exceptionThrown) {
  64. $this->fail('An expected ODataException for invalid base uri in the request uri has not been thrown');
  65. }
  66. } catch (\Exception $exception) {
  67. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  68. }
  69. }**/
  70. /**
  71. * Test with request uri where RequestTargetKind is NONE. RequestTargetKind will be
  72. * NONE for service directory, metadata and batch.
  73. */
  74. public function testUriProcessorWithRequestUriOfNoneTargetSourceKind()
  75. {
  76. try {
  77. //Request for service directory
  78. $hostInfo = array('AbsoluteRequestUri' =>
  79. new Url('http://localhost:8083/NorthWindDataService.svc'),
  80. 'AbsoluteServiceUri' =>
  81. new Url('http://localhost:8083/NorthWindDataService.svc'),
  82. 'QueryString' =>
  83. null);
  84. $host = new DataServiceHost2($hostInfo);
  85. $dataService = new NorthWindDataService2();
  86. $dataService->setHost($host);
  87. $exceptionThrown = false;
  88. $uriProcessor = $dataService->handleRequest();
  89. $requestDescripton = $uriProcessor->getRequestDescription();
  90. $this->assertEquals($requestDescripton->getTargetSource(), RequestTargetSource::NONE);
  91. $this->assertEquals($requestDescripton->getTargetKind(), RequestTargetKind::SERVICE_DIRECTORY);
  92. // Context is a singleton class reset it
  93. $host->getWebOperationContext()->resetWebContextInternal();
  94. //Request for metadata
  95. $hostInfo = array('AbsoluteRequestUri' =>
  96. new Url('http://localhost:8083/NorthWindDataService.svc/$metadata'),
  97. 'AbsoluteServiceUri' =>
  98. new Url('http://localhost:8083/NorthWindDataService.svc'),
  99. 'QueryString' =>
  100. null);
  101. $host = new DataServiceHost2($hostInfo);
  102. $dataService = new NorthWindDataService2();
  103. $dataService->setHost($host);
  104. $exceptionThrown = false;
  105. $requestDescripton = $uriProcessor = null;
  106. $uriProcessor = $dataService->handleRequest();
  107. $requestDescripton = $uriProcessor->getRequestDescription();
  108. $this->assertEquals($requestDescripton->getTargetSource(), RequestTargetSource::NONE);
  109. $this->assertEquals($requestDescripton->getTargetKind(), RequestTargetKind::METADATA);
  110. // Context is a singleton class reset it
  111. $host->getWebOperationContext()->resetWebContextInternal();
  112. //Request for batch
  113. $hostInfo = array('AbsoluteRequestUri' =>
  114. new Url('http://localhost:8083/NorthWindDataService.svc/$batch'),
  115. 'AbsoluteServiceUri' =>
  116. new Url('http://localhost:8083/NorthWindDataService.svc'),
  117. 'QueryString' =>
  118. null);
  119. $host = new DataServiceHost2($hostInfo);
  120. $dataService = new NorthWindDataService2();
  121. $dataService->setHost($host);
  122. $exceptionThrown = false;
  123. $uriProcessor = $dataService->handleRequest();
  124. $requestDescripton = $uriProcessor->getRequestDescription();
  125. $this->assertEquals($requestDescripton->getTargetSource(), RequestTargetSource::NONE);
  126. $this->assertEquals($requestDescripton->getTargetKind(), RequestTargetKind::BATCH);
  127. // Context is a singleton class reset it
  128. $host->getWebOperationContext()->resetWebContextInternal();
  129. } catch (\Exception $exception) {
  130. if ($host != null) {
  131. $host->getWebOperationContext()->resetWebContextInternal();
  132. }
  133. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  134. }
  135. }
  136. /**
  137. * Test request uri for row count ($count)
  138. * DataServiceVersion and MaxDataServiceVersion should be >= 2.0 for $count
  139. */
  140. public function testUriProcessorForCountRequest1()
  141. {
  142. try {
  143. //Test $count with DataServiceVersion < 2.0
  144. $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
  145. 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
  146. 'QueryString' => null,
  147. 'DataServiceVersion' => new Version(1, 0),
  148. 'MaxDataServiceVersion' => new Version(2, 0));
  149. $host = new DataServiceHost2($hostInfo);
  150. $dataService = new NorthWindDataService2();
  151. $dataService->setHost($host);
  152. $exceptionThrown = false;
  153. try {
  154. $uriProcessor = $dataService->handleRequest();
  155. } catch (ODataException $odataException) {
  156. $exceptionThrown = true;
  157. $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0", $odataException->getMessage());
  158. }
  159. if (!$exceptionThrown) {
  160. $this->fail('An expected ODataException for failure of capability negoitation over DataServiceVersion has not been thrown');
  161. }
  162. // Context is a singleton class reset it
  163. $host->getWebOperationContext()->resetWebContextInternal();
  164. //Test $count with MaxDataServiceVersion < 2.0
  165. $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
  166. 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
  167. 'QueryString' => null,
  168. 'DataServiceVersion' => new Version(2, 0),
  169. 'MaxDataServiceVersion' => new Version(1, 0));
  170. $host = new DataServiceHost2($hostInfo);
  171. $dataService = new NorthWindDataService2();
  172. $dataService->setHost($host);
  173. $exceptionThrown = false;
  174. try {
  175. $uriProcessor = $dataService->handleRequest();
  176. } catch (ODataException $odataException) {
  177. $exceptionThrown = true;
  178. $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0", $odataException->getMessage());
  179. }
  180. if (!$exceptionThrown) {
  181. $this->fail('An expected ODataException for failure of capability negoitation over MaxDataServiceVersion has not been thrown');
  182. }
  183. $host->getWebOperationContext()->resetWebContextInternal();
  184. } catch (\Exception $exception) {
  185. if ($host != null) {
  186. $host->getWebOperationContext()->resetWebContextInternal();
  187. }
  188. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  189. }
  190. }
  191. /**
  192. * Test request uri for row count ($count)
  193. * $count is a version 2 feature so service devloper should use protocol version 2.0
  194. */
  195. public function testUriProcessorForCountRequest2()
  196. {
  197. try {
  198. $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
  199. 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
  200. 'QueryString' => null,
  201. 'DataServiceVersion' => new Version(2, 0),
  202. 'MaxDataServiceVersion' => new Version(2, 0));
  203. $host = new DataServiceHost2($hostInfo);
  204. $dataService = new NorthWindDataServiceV1();
  205. $dataService->setHost($host);
  206. $exceptionThrown = false;
  207. try {
  208. $uriProcessor = $dataService->handleRequest();
  209. } catch (ODataException $odataException) {
  210. $exceptionThrown = true;
  211. $this->assertStringStartsWith("The response requires that version 2.0 of the protocol be used, but the MaxProtocolVersion of the data service is set to 1.0", $odataException->getMessage());
  212. }
  213. if (!$exceptionThrown) {
  214. $this->fail('An expected ODataException for failure of capability negoitation due to V1 configuration has not been thrown');
  215. }
  216. $host->getWebOperationContext()->resetWebContextInternal();
  217. } catch (\Exception $exception) {
  218. if ($host != null) {
  219. $host->getWebOperationContext()->resetWebContextInternal();
  220. }
  221. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  222. }
  223. }
  224. /**
  225. * Test request uri for row count ($count)
  226. *
  227. * Suppose $top option is absent, still
  228. * RequestDescription::topCount will be set if the resource targetted by the
  229. * uri has paging enabled, if RequestDescription::topCount
  230. * is set then internal orderby info will be generated. But if the request
  231. * is for raw count for a resource collection then paging is not applicable
  232. * for that, so topCount will be null and internal orderby info will not be
  233. * generated.
  234. */
  235. public function testUriProcessorForCountRequest3()
  236. {
  237. try {
  238. $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
  239. 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
  240. 'QueryString' => null,
  241. 'DataServiceVersion' => new Version(2, 0),
  242. 'MaxDataServiceVersion' => new Version(2, 0));
  243. $host = new DataServiceHost2($hostInfo);
  244. $dataService = new NorthWindDataService2();
  245. $dataService->setHost($host);
  246. $exceptionThrown = false;
  247. $uriProcessor = $dataService->handleRequest();
  248. $requestDescription = $uriProcessor->getRequestDescription();
  249. $this->assertTrue(!is_null($requestDescription));
  250. $this->assertTrue(is_null($requestDescription->getInternalOrderByInfo()));
  251. $host->getWebOperationContext()->resetWebContextInternal();
  252. } catch (\Exception $exception) {
  253. if ($host != null) {
  254. $host->getWebOperationContext()->resetWebContextInternal();
  255. }
  256. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  257. }
  258. }
  259. /**
  260. * Test request uri for row count ($count)
  261. *
  262. * $orderby option can be applied to a $count request.
  263. */
  264. public function testUriProcessorForCountRequest4()
  265. {
  266. try {
  267. $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
  268. 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
  269. 'QueryString' => '$orderby=Country',
  270. 'DataServiceVersion' => new Version(2, 0),
  271. 'MaxDataServiceVersion' => new Version(2, 0));
  272. $host = new DataServiceHost2($hostInfo);
  273. $dataService = new NorthWindDataService2();
  274. $dataService->setHost($host);
  275. $exceptionThrown = false;
  276. $uriProcessor = $dataService->handleRequest();
  277. $requestDescription = $uriProcessor->getRequestDescription();
  278. $this->assertTrue(!is_null($requestDescription));
  279. $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
  280. $this->assertTrue(!is_null($internalOrderByInfo));
  281. $object = $internalOrderByInfo->getDummyObject();
  282. $this->assertTrue(!is_null($object));
  283. $this->assertTrue($object instanceof Customer2);
  284. $host->getWebOperationContext()->resetWebContextInternal();
  285. } catch (\Exception $exception) {
  286. if ($host != null) {
  287. $host->getWebOperationContext()->resetWebContextInternal();
  288. }
  289. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  290. }
  291. }
  292. /**
  293. * Test request uri for row count ($count)
  294. *
  295. * $skip and $top options can be applied to $count request, this cause
  296. * processor to generate internalorderinfo.
  297. */
  298. public function testUriProcessorForCountRequest5()
  299. {
  300. try {
  301. $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
  302. 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
  303. 'QueryString' => '$skip=2&$top=4',
  304. 'DataServiceVersion' => new Version(2, 0),
  305. 'MaxDataServiceVersion' => new Version(2, 0));
  306. $host = new DataServiceHost2($hostInfo);
  307. $dataService = new NorthWindDataService2();
  308. $dataService->setHost($host);
  309. $exceptionThrown = false;
  310. $uriProcessor = $dataService->handleRequest();
  311. $requestDescription = $uriProcessor->getRequestDescription();
  312. $this->assertTrue(!is_null($requestDescription));
  313. $this->assertEquals($requestDescription->getTopCount(), 4);
  314. $this->assertEquals($requestDescription->getSkipCount(), 2);
  315. $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
  316. $this->assertTrue(!is_null($internalOrderByInfo));
  317. $object = $internalOrderByInfo->getDummyObject();
  318. $this->assertTrue(!is_null($object));
  319. $this->assertTrue($object instanceof Customer2);
  320. $host->getWebOperationContext()->resetWebContextInternal();
  321. } catch (\Exception $exception) {
  322. if ($host != null) {
  323. $host->getWebOperationContext()->resetWebContextInternal();
  324. }
  325. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  326. }
  327. }
  328. /**
  329. * Test request uri for row count ($count)
  330. *
  331. * $skip and/or $top options along with $orderby option cause internalOrderInfo
  332. * to include sorter functions using keys + paths in the $orderby clause
  333. */
  334. public function testUriProcessorForCountRequest6()
  335. {
  336. try {
  337. $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
  338. 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
  339. 'QueryString' => '$skip=2&$top=4&$orderby=Country',
  340. 'DataServiceVersion' => new Version(2, 0),
  341. 'MaxDataServiceVersion' => new Version(2, 0));
  342. $host = new DataServiceHost2($hostInfo);
  343. $dataService = new NorthWindDataService2();
  344. $dataService->setHost($host);
  345. $exceptionThrown = false;
  346. $uriProcessor = $dataService->handleRequest();
  347. $requestDescription = $uriProcessor->getRequestDescription();
  348. $this->assertTrue(!is_null($requestDescription));
  349. $this->assertEquals($requestDescription->getTopCount(), 4);
  350. $this->assertEquals($requestDescription->getSkipCount(), 2);
  351. $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
  352. $this->assertTrue(!is_null($internalOrderByInfo));
  353. $object = $internalOrderByInfo->getDummyObject();
  354. $this->assertTrue(!is_null($object));
  355. $this->assertTrue($object instanceof Customer2);
  356. $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
  357. $this->assertTrue(!is_null($pathSegments));
  358. $this->assertTrue(is_array($pathSegments));
  359. $this->assertEquals(count($pathSegments), 3);
  360. $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
  361. $subPathSegments = $pathSegments[0]->getSubPathSegments();
  362. $this->assertTrue(!is_null($subPathSegments));
  363. $this->assertTrue(is_array($subPathSegments));
  364. $this->assertEquals(count($subPathSegments), 1);
  365. $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
  366. $this->assertEquals($subPathSegments[0]->getName(), 'Country');
  367. $this->assertTrue($pathSegments[1] instanceof OrderByPathSegment);
  368. $subPathSegments = $pathSegments[1]->getSubPathSegments();
  369. $this->assertTrue(!is_null($subPathSegments));
  370. $this->assertTrue(is_array($subPathSegments));
  371. $this->assertEquals(count($subPathSegments), 1);
  372. $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
  373. $this->assertEquals($subPathSegments[0]->getName(), 'CustomerID');
  374. $this->assertTrue($pathSegments[2] instanceof OrderByPathSegment);
  375. $subPathSegments = $pathSegments[2]->getSubPathSegments();
  376. $this->assertTrue(!is_null($subPathSegments));
  377. $this->assertTrue(is_array($subPathSegments));
  378. $this->assertEquals(count($subPathSegments), 1);
  379. $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
  380. $this->assertEquals($subPathSegments[0]->getName(), 'CustomerGuid');
  381. $host->getWebOperationContext()->resetWebContextInternal();
  382. } catch (\Exception $exception) {
  383. if ($host != null) {
  384. $host->getWebOperationContext()->resetWebContextInternal();
  385. }
  386. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  387. }
  388. }
  389. /**
  390. * Test request uri for row count ($count)
  391. * $skiptoken is not applicable for $count request, as it requires
  392. * paging and paging is not applicable for $count request
  393. */
  394. public function testUriProcessorForCountRequest7()
  395. {
  396. try {
  397. $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
  398. 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
  399. 'QueryString' => '$top=1&$skiptoken=\'ALFKI\',guid\'05b242e752eb46bd8f0e6568b72cd9a5\'',
  400. 'DataServiceVersion' => new Version(2, 0),
  401. 'MaxDataServiceVersion' => new Version(2, 0));
  402. $host = new DataServiceHost2($hostInfo);
  403. $dataService = new NorthWindDataService2();
  404. $dataService->setHost($host);
  405. $exceptionThrown = false;
  406. try {
  407. $uriProcessor = $dataService->handleRequest();
  408. } catch (ODataException $odataException) {
  409. $exceptionThrown = true;
  410. $this->assertStringStartsWith("Query option \$skiptoken cannot be applied to the requested resource", $odataException->getMessage());
  411. }
  412. if (!$exceptionThrown) {
  413. $this->fail('An expected ODataException for applying $skiptoken on $count has not been thrown');
  414. }
  415. $host->getWebOperationContext()->resetWebContextInternal();
  416. } catch (\Exception $exception) {
  417. if ($host != null) {
  418. $host->getWebOperationContext()->resetWebContextInternal();
  419. }
  420. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  421. }
  422. }
  423. /**
  424. * Test request uri for row count ($count)
  425. *
  426. * $filter is applicable for $count segment.
  427. */
  428. public function testUriProcessorForCountRequest8()
  429. {
  430. try {
  431. $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
  432. 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
  433. 'QueryString' => '$filter=Country eq \'USA\'',
  434. 'DataServiceVersion' => new Version(2, 0),
  435. 'MaxDataServiceVersion' => new Version(2, 0));
  436. $host = new DataServiceHost2($hostInfo);
  437. $dataService = new NorthWindDataService2();
  438. $dataService->setHost($host);
  439. $uriProcessor = $dataService->handleRequest();
  440. $requestDescription = $uriProcessor->getRequestDescription();
  441. $this->assertTrue(!is_null($requestDescription));
  442. $internalFilterInfo = $requestDescription->getInternalFilterInfo();
  443. $this->assertTrue(!is_null($internalFilterInfo));
  444. $filterInfo = $internalFilterInfo->getFilterInfo();
  445. $this->assertTrue(!is_null($filterInfo));
  446. $this->assertTrue(is_null($filterInfo->getNavigationPropertiesUsed()));
  447. $filterFunction = $internalFilterInfo->getFilterFunction();
  448. $this->assertTrue(!is_null($filterFunction));
  449. $this->assertTrue($filterFunction instanceof AnonymousFunction);
  450. $host->getWebOperationContext()->resetWebContextInternal();
  451. } catch (\Exception $exception) {
  452. if ($host != null) {
  453. $host->getWebOperationContext()->resetWebContextInternal();
  454. }
  455. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  456. }
  457. }
  458. /**
  459. * Test request uri for row count ($count)
  460. *
  461. * $select and $expand options are applicable for $count segment.
  462. * but when we do query execution we will ignore them.
  463. */
  464. public function testUriProcessorForCountRequest9()
  465. {
  466. try {
  467. $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
  468. 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
  469. 'QueryString' => '$select=Country&$expand=Orders',
  470. 'DataServiceVersion' => new Version(2, 0),
  471. 'MaxDataServiceVersion' => new Version(2, 0));
  472. $host = new DataServiceHost2($hostInfo);
  473. $dataService = new NorthWindDataService2();
  474. $dataService->setHost($host);
  475. $uriProcessor = $dataService->handleRequest();
  476. $requestDescription = $uriProcessor->getRequestDescription();
  477. $this->assertTrue(!is_null($requestDescription));
  478. $projectionTreeRoot = $requestDescription->getRootProjectionNode();
  479. $this->assertTrue(!is_null($projectionTreeRoot));
  480. $this->assertTrue($projectionTreeRoot instanceof RootProjectionNode);
  481. //There will be one child node for 'Country', 'Orders' wont be included
  482. //as its not selected
  483. $childNodes = $projectionTreeRoot->getChildNodes();
  484. $this->assertTrue(!is_null($childNodes));
  485. $this->assertTrue(is_array($childNodes));
  486. $this->assertEquals(count($childNodes), 1);
  487. $this->assertTrue(array_key_exists('Country', $childNodes));
  488. $this->assertTrue($childNodes['Country'] instanceof ProjectionNode);
  489. $host->getWebOperationContext()->resetWebContextInternal();
  490. } catch (\Exception $exception) {
  491. if ($host != null) {
  492. $host->getWebOperationContext()->resetWebContextInternal();
  493. }
  494. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  495. }
  496. }
  497. /**
  498. * Test request uri for row count ($count)
  499. * $count with $inlinecount not allowed
  500. */
  501. public function testUriProcessorForCountWithInline()
  502. {
  503. try {
  504. $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
  505. 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
  506. 'QueryString' => '$inlinecount=allpages',
  507. 'DataServiceVersion' => new Version(2, 0),
  508. 'MaxDataServiceVersion' => new Version(2, 0));
  509. $host = new DataServiceHost2($hostInfo);
  510. $dataService = new NorthWindDataService2();
  511. $dataService->setHost($host);
  512. $exceptionThrown = false;
  513. try {
  514. $uriProcessor = $dataService->handleRequest();
  515. } catch (ODataException $odataException) {
  516. $exceptionThrown = true;
  517. $this->assertStringStartsWith("\$inlinecount cannot be applied to the resource segment \$count", $odataException->getMessage());
  518. }
  519. if (!$exceptionThrown) {
  520. $this->fail('An expected ODataException for applying $skiptoken on $count has not been thrown');
  521. }
  522. $host->getWebOperationContext()->resetWebContextInternal();
  523. } catch (\Exception $exception) {
  524. if ($host != null) {
  525. $host->getWebOperationContext()->resetWebContextInternal();
  526. }
  527. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  528. }
  529. }
  530. /**
  531. * If paging is enabled for a resource set, then the uri
  532. * processor should generate orderinfo irrespective of
  533. * whether $top or $orderby is specified or not.
  534. *
  535. * Request DataServiceVersion => 1.0
  536. * Request MaxDataServiceVersion => 2.0
  537. */
  538. public function testUriProcessorForResourcePageInfo1()
  539. {
  540. try {
  541. //Test for generation of orderinfo for resource set
  542. //with request DataServiceVersion 1.0
  543. $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers'),
  544. 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
  545. 'QueryString' => null,
  546. 'DataServiceVersion' => new Version(1, 0),
  547. 'MaxDataServiceVersion' => new Version(2, 0));
  548. $host = new DataServiceHost2($hostInfo);
  549. $dataService = new NorthWindDataService2();
  550. $dataService->setHost($host);
  551. $uriProcessor = $dataService->handleRequest();
  552. $requestDescription = $uriProcessor->getRequestDescription();
  553. $this->assertTrue(!is_null($requestDescription));
  554. //Page size is 5, so take count is 5
  555. $this->assertEquals($requestDescription->getTopCount(), 5);
  556. //order info is required for pagination
  557. $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
  558. $this->assertTrue(!is_null($internalOrderByInfo));
  559. $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
  560. $this->assertTrue(!is_null($pathSegments));
  561. $this->assertTrue(is_array($pathSegments));
  562. //Customer has two keys
  563. $this->assertEquals(count($pathSegments), 2);
  564. $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
  565. $subPathSegments = $pathSegments[0]->getSubPathSegments();
  566. $this->assertTrue(!is_null($subPathSegments));
  567. $this->assertTrue(is_array($subPathSegments));
  568. $this->assertEquals(count($subPathSegments), 1);
  569. $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
  570. $this->assertEquals($subPathSegments[0]->getName(), 'CustomerID');
  571. $this->assertTrue($pathSegments[1] instanceof OrderByPathSegment);
  572. $subPathSegments = $pathSegments[1]->getSubPathSegments();
  573. $this->assertTrue(!is_null($subPathSegments));
  574. $this->assertTrue(is_array($subPathSegments));
  575. $this->assertEquals(count($subPathSegments), 1);
  576. $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
  577. $this->assertEquals($subPathSegments[0]->getName(), 'CustomerGuid');
  578. $host->getWebOperationContext()->resetWebContextInternal();
  579. } catch (\Exception $exception) {
  580. if ($host != null) {
  581. $host->getWebOperationContext()->resetWebContextInternal();
  582. }
  583. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  584. }
  585. }
  586. /**
  587. * If paging is enabled for a resource set, then the uri
  588. * processor should generate orderinfo irrespective of
  589. * whether $top or $orderby is specified or not.
  590. *
  591. * Request DataServiceVersion => 1.0
  592. * Request MaxDataServiceVersion => 1.0
  593. *
  594. * This will fail as paging requires version 2.0 or above
  595. */
  596. public function testUriProcessorForResourcePageInfo2()
  597. {
  598. try {
  599. //Test for generation of orderinfo for resource set
  600. //with request DataServiceVersion 1.0
  601. $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers'),
  602. 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
  603. 'QueryString' => null,
  604. 'DataServiceVersion' => new Version(1, 0),
  605. 'MaxDataServiceVersion' => new Version(1, 0));
  606. $host = new DataServiceHost2($hostInfo);
  607. $dataService = new NorthWindDataService2();
  608. $dataService->setHost($host);
  609. $exceptionThrown = false;
  610. try {
  611. $uriProcessor = $dataService->handleRequest();
  612. } catch (ODataException $odataException) {
  613. $exceptionThrown = true;
  614. $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0'", $odataException->getMessage());
  615. }
  616. if (!$exceptionThrown) {
  617. $this->fail('An expected ODataException due to capability negotiation has not been thrown (paged result but client\'s max supportedd version is 1.0)');
  618. }
  619. $host->getWebOperationContext()->resetWebContextInternal();
  620. } catch (\Exception $exception) {
  621. if ($host != null) {
  622. $host->getWebOperationContext()->resetWebContextInternal();
  623. }
  624. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  625. }
  626. }
  627. /**
  628. * Paging is enabled only for resource set, so with resource set
  629. * reference there will not be any paginginfo.
  630. */
  631. public function testUriProcessorForResourcePageInfo3()
  632. {
  633. try {
  634. //Test for generation of orderinfo for resource set
  635. //with request DataServiceVersion 1.0
  636. $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Orders(123)'),
  637. 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
  638. 'QueryString' => null,
  639. 'DataServiceVersion' => new Version(1, 0),
  640. 'MaxDataServiceVersion' => new Version(2, 0));
  641. $host = new DataServiceHost2($hostInfo);
  642. $dataService = new NorthWindDataService2();
  643. $dataService->setHost($host);
  644. $uriProcessor = $dataService->handleRequest();
  645. $requestDescription = $uriProcessor->getRequestDescription();
  646. $this->assertTrue(!is_null($requestDescription));
  647. //Page is not appliable for single resouce
  648. $this->assertEquals($requestDescription->getTopCount(), null);
  649. //order info wont be generated as resource is not applicable for pagination
  650. $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
  651. $this->assertTrue(is_null($internalOrderByInfo));
  652. $host->getWebOperationContext()->resetWebContextInternal();
  653. } catch (\Exception $exception) {
  654. if ($host != null) {
  655. $host->getWebOperationContext()->resetWebContextInternal();
  656. }
  657. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  658. }
  659. }
  660. /**
  661. * If paging is enabled for a resource set, then $link request for that resource set
  662. * will also paged
  663. * e.g. http://host/service.svc/Customers('A')/$links/Orders
  664. * here if paging is enabled for Orders then prcoessor must generate orderbyinfo for
  665. * this.
  666. */
  667. public function testUriProcessorForResourcePageInfo4()
  668. {
  669. try {
  670. //Test for generation of orderinfo for resource set in $links query
  671. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  672. $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
  673. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  674. 'AbsoluteServiceUri' => new Url($baseUri),
  675. 'QueryString' => null,
  676. 'DataServiceVersion' => new Version(1, 0),
  677. 'MaxDataServiceVersion' => new Version(2, 0));
  678. $host = new DataServiceHost2($hostInfo);
  679. $dataService = new NorthWindDataService2();
  680. $dataService->setHost($host);
  681. $uriProcessor = $dataService->handleRequest();
  682. $requestDescription = $uriProcessor->getRequestDescription();
  683. $this->assertTrue(!is_null($requestDescription));
  684. //Page size is 5, so take count is 5
  685. $this->assertEquals($requestDescription->getTopCount(), 5);
  686. //order info is required for pagination
  687. $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
  688. $this->assertTrue(!is_null($internalOrderByInfo));
  689. $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
  690. $this->assertTrue(!is_null($pathSegments));
  691. $this->assertTrue(is_array($pathSegments));
  692. //Order has one key
  693. $this->assertEquals(count($pathSegments), 1);
  694. $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
  695. $subPathSegments = $pathSegments[0]->getSubPathSegments();
  696. $this->assertTrue(!is_null($subPathSegments));
  697. $this->assertTrue(is_array($subPathSegments));
  698. $this->assertEquals(count($subPathSegments), 1);
  699. $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
  700. $this->assertEquals($subPathSegments[0]->getName(), 'OrderID');
  701. $host->getWebOperationContext()->resetWebContextInternal();
  702. } catch (\Exception $exception) {
  703. if ($host != null) {
  704. $host->getWebOperationContext()->resetWebContextInternal();
  705. }
  706. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  707. }
  708. }
  709. /**
  710. * $orderby option can be applied to $links resource set
  711. */
  712. public function testUriProcessorForLinksResourceSet1()
  713. {
  714. try {
  715. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  716. $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
  717. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  718. 'AbsoluteServiceUri' => new Url($baseUri),
  719. 'QueryString' => '$orderby=ShipName asc, OrderDate desc',
  720. 'DataServiceVersion' => new Version(2, 0),
  721. 'MaxDataServiceVersion' => new Version(2, 0));
  722. $host = new DataServiceHost2($hostInfo);
  723. $dataService = new NorthWindDataService2();
  724. $dataService->setHost($host);
  725. $uriProcessor = $dataService->handleRequest();
  726. $requestDescription = $uriProcessor->getRequestDescription();
  727. $this->assertTrue(!is_null($requestDescription));
  728. $this->assertEquals($requestDescription->isSingleResult(), false);
  729. //Page size is 5, so take count is 5 means you will get only 5 links for a request
  730. $this->assertEquals($requestDescription->getTopCount(), 5);
  731. //Paging requires ordering, the result should be ordered like
  732. //Note: additional ordering constraint
  733. //
  734. //SELECT links(d.orderID) FROM Customers JOIN Orders WHERE CustomerID='ALFKI' AND
  735. //CustomerGuid=guid'05b242e752eb46bd8f0e6568b72cd9a5' ORDER BY
  736. //d.ShipName ASC, d.OrderDate DESC, d.OrderID ASC
  737. $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
  738. $this->assertTrue(!is_null($internalOrderByInfo));
  739. $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
  740. $this->assertTrue(!is_null($pathSegments));
  741. $this->assertTrue(is_array($pathSegments));
  742. $this->assertEquals(count($pathSegments), 3);
  743. $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
  744. $subPathSegments = $pathSegments[0]->getSubPathSegments();
  745. $this->assertTrue($pathSegments[0]->isAscending());
  746. $this->assertTrue(!is_null($subPathSegments));
  747. $this->assertTrue(is_array($subPathSegments));
  748. $this->assertEquals(count($subPathSegments), 1);
  749. $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
  750. $this->assertEquals($subPathSegments[0]->getName(), 'ShipName');
  751. $this->assertTrue($pathSegments[1] instanceof OrderByPathSegment);
  752. $this->assertFalse($pathSegments[1]->isAscending());
  753. $subPathSegments = $pathSegments[1]->getSubPathSegments();
  754. $this->assertTrue(!is_null($subPathSegments));
  755. $this->assertTrue(is_array($subPathSegments));
  756. $this->assertEquals(count($subPathSegments), 1);
  757. $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
  758. $this->assertEquals($subPathSegments[0]->getName(), 'OrderDate');
  759. $this->assertTrue($pathSegments[2] instanceof OrderByPathSegment);
  760. $this->assertTrue($pathSegments[2]->isAscending());
  761. $subPathSegments = $pathSegments[2]->getSubPathSegments();
  762. $this->assertTrue(!is_null($subPathSegments));
  763. $this->assertTrue(is_array($subPathSegments));
  764. $this->assertEquals(count($subPathSegments), 1);
  765. $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
  766. $this->assertEquals($subPathSegments[0]->getName(), 'OrderID');
  767. $host->getWebOperationContext()->resetWebContextInternal();
  768. } catch (\Exception $exception) {
  769. if ($host != null) {
  770. $host->getWebOperationContext()->resetWebContextInternal();
  771. }
  772. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  773. }
  774. }
  775. /**
  776. * $skiptoken option can be applied to $links resource set
  777. */
  778. public function testUriProcessorForLinksResourceSet2()
  779. {
  780. try {
  781. //Test with skiptoken that corrosponds to default ordering key
  782. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  783. $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
  784. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  785. 'AbsoluteServiceUri' => new Url($baseUri),
  786. 'QueryString' => '$skiptoken=123',
  787. 'DataServiceVersion' => new Version(2, 0),
  788. 'MaxDataServiceVersion' => new Version(2, 0));
  789. $host = new DataServiceHost2($hostInfo);
  790. $dataService = new NorthWindDataService2();
  791. $dataService->setHost($host);
  792. $uriProcessor = $dataService->handleRequest();
  793. $requestDescription = $uriProcessor->getRequestDescription();
  794. $this->assertTrue(!is_null($requestDescription));
  795. $this->assertEquals($requestDescription->isSingleResult(), false);
  796. //Page size is 5, so take count is 5 means you will get only 5 links for a request
  797. $this->assertEquals($requestDescription->getTopCount(), 5);
  798. //paging requires ordering
  799. $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
  800. $this->assertTrue(!is_null($internalOrderByInfo));
  801. $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
  802. $this->assertTrue(!is_null($pathSegments));
  803. $this->assertTrue(is_array($pathSegments));
  804. $this->assertEquals(count($pathSegments), 1);
  805. $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
  806. $subPathSegments = $pathSegments[0]->getSubPathSegments();
  807. $this->assertTrue($pathSegments[0]->isAscending());
  808. $this->assertTrue(!is_null($subPathSegments));
  809. $this->assertTrue(is_array($subPathSegments));
  810. $this->assertEquals(count($subPathSegments), 1);
  811. $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
  812. $this->assertEquals($subPathSegments[0]->getName(), 'OrderID');
  813. //check the skiptoken details
  814. $internalSkiptokenInfo = $requestDescription->getInternalSkipTokenInfo();
  815. $this->assertTrue(!is_null($internalSkiptokenInfo));
  816. $this->assertTrue($internalSkiptokenInfo instanceof InternalSkipTokenInfo);
  817. $skipTokenInfo = $internalSkiptokenInfo->getSkipTokenInfo();
  818. $this->assertTrue(!is_null($skipTokenInfo));
  819. $this->assertTrue($skipTokenInfo instanceof SkipTokenInfo);
  820. $orderByValuesInSkipToken = $skipTokenInfo->getOrderByKeysInToken();
  821. $this->assertTrue(!is_null($orderByValuesInSkipToken));
  822. $this->assertTrue(is_array($orderByValuesInSkipToken));
  823. $this->assertEquals(count($orderByValuesInSkipToken), 1);
  824. $this->assertTrue(!is_null($orderByValuesInSkipToken[0]));
  825. $this->assertTrue(is_array($orderByValuesInSkipToken[0]));
  826. $this->assertEquals(count($orderByValuesInSkipToken[0]), 2);
  827. $this->assertEquals($orderByValuesInSkipToken[0][0], 123);
  828. $this->assertTrue(is_object($orderByValuesInSkipToken[0][1]));
  829. $this->assertTrue($orderByValuesInSkipToken[0][1] instanceof Int32);
  830. $host->getWebOperationContext()->resetWebContextInternal();
  831. //Test with skiptoken that corrosponds to explict ordering keys
  832. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  833. $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
  834. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  835. 'AbsoluteServiceUri' => new Url($baseUri),
  836. 'QueryString' => '$orderby=OrderID asc, OrderDate desc&$skiptoken=123, datetime\'2000-11-11\'',
  837. 'DataServiceVersion' => new Version(2, 0),
  838. 'MaxDataServiceVersion' => new Version(2, 0));
  839. $host = new DataServiceHost2($hostInfo);
  840. $dataService = new NorthWindDataService2();
  841. $dataService->setHost($host);
  842. $uriProcessor = $dataService->handleRequest();
  843. $requestDescription = $uriProcessor->getRequestDescription();
  844. $this->assertTrue(!is_null($requestDescription));
  845. $this->assertEquals($requestDescription->isSingleResult(), false);
  846. //Page size is 5, so take count is 5 means you will get only 5 links for a request
  847. $this->assertEquals($requestDescription->getTopCount(), 5);
  848. //paging requires ordering
  849. $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
  850. $this->assertTrue(!is_null($internalOrderByInfo));
  851. $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
  852. $this->assertTrue(!is_null($pathSegments));
  853. $this->assertTrue(is_array($pathSegments));
  854. $this->assertEquals(count($pathSegments), 2);
  855. $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
  856. $subPathSegments = $pathSegments[0]->getSubPathSegments();
  857. $this->assertTrue($pathSegments[0]->isAscending());
  858. $this->assertTrue(!is_null($subPathSegments));
  859. $this->assertTrue(is_array($subPathSegments));
  860. $this->assertEquals(count($subPathSegments), 1);
  861. $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
  862. $this->assertEquals($subPathSegments[0]->getName(), 'OrderID');
  863. $this->assertTrue($pathSegments[1] instanceof OrderByPathSegment);
  864. $this->assertFalse($pathSegments[1]->isAscending());
  865. $subPathSegments = $pathSegments[1]->getSubPathSegments();
  866. $this->assertTrue(!is_null($subPathSegments));
  867. $this->assertTrue(is_array($subPathSegments));
  868. $this->assertEquals(count($subPathSegments), 1);
  869. $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
  870. $this->assertEquals($subPathSegments[0]->getName(), 'OrderDate');
  871. //check the skiptoken details
  872. $internalSkiptokenInfo = $requestDescription->getInternalSkipTokenInfo();
  873. $this->assertTrue(!is_null($internalSkiptokenInfo));
  874. $this->assertTrue($internalSkiptokenInfo instanceof InternalSkipTokenInfo);
  875. $skipTokenInfo = $internalSkiptokenInfo->getSkipTokenInfo();
  876. $this->assertTrue(!is_null($skipTokenInfo));
  877. $this->assertTrue($skipTokenInfo instanceof SkipTokenInfo);
  878. $orderByValuesInSkipToken = $skipTokenInfo->getOrderByKeysInToken();
  879. $this->assertTrue(!is_null($orderByValuesInSkipToken));
  880. $this->assertTrue(is_array($orderByValuesInSkipToken));
  881. $this->assertEquals(count($orderByValuesInSkipToken), 2);
  882. $this->assertTrue(!is_null($orderByValuesInSkipToken[0]));
  883. $this->assertTrue(is_array($orderByValuesInSkipToken[0]));
  884. $this->assertEquals(count($orderByValuesInSkipToken[0]), 2);
  885. $this->assertEquals($orderByValuesInSkipToken[0][0], 123);
  886. $this->assertTrue(is_object($orderByValuesInSkipToken[0][1]));
  887. $this->assertTrue($orderByValuesInSkipToken[0][1] instanceof Int32);
  888. $this->assertTrue(!is_null($orderByValuesInSkipToken[1]));
  889. $this->assertTrue(is_array($orderByValuesInSkipToken[1]));
  890. $this->assertEquals(count($orderByValuesInSkipToken[1]), 2);
  891. $this->assertEquals($orderByValuesInSkipToken[1][0], '\'2000-11-11\'');
  892. $this->assertTrue(is_object($orderByValuesInSkipToken[1][1]));
  893. $this->assertTrue($orderByValuesInSkipToken[1][1] instanceof DateTime);
  894. $host->getWebOperationContext()->resetWebContextInternal();
  895. } catch (\Exception $exception) {
  896. if ($host != null) {
  897. $host->getWebOperationContext()->resetWebContextInternal();
  898. }
  899. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  900. }
  901. }
  902. /**
  903. * $top and $skip option can be applied to $links resource set
  904. */
  905. public function testUriProcessorForLinksResourceSet3()
  906. {
  907. try {
  908. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  909. $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
  910. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  911. 'AbsoluteServiceUri' => new Url($baseUri),
  912. 'QueryString' => '$skip=1',
  913. 'DataServiceVersion' => new Version(2, 0),
  914. 'MaxDataServiceVersion' => new Version(2, 0));
  915. $host = new DataServiceHost2($hostInfo);
  916. $dataService = new NorthWindDataService2();
  917. $dataService->setHost($host);
  918. $uriProcessor = $dataService->handleRequest();
  919. $requestDescription = $uriProcessor->getRequestDescription();
  920. $this->assertTrue(!is_null($requestDescription));
  921. $this->assertEquals($requestDescription->isSingleResult(), false);
  922. //$skip has been specified
  923. $this->assertEquals($requestDescription->getSkipCount(), 1);
  924. //Page size is 5, so take count is 5 means you will get only 5 links for a request
  925. $this->assertEquals($requestDescription->getTopCount(), 5);
  926. //paging requires ordering
  927. $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
  928. $this->assertTrue(!is_null($internalOrderByInfo));
  929. $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
  930. $this->assertTrue(!is_null($pathSegments));
  931. $this->assertTrue(is_array($pathSegments));
  932. $this->assertEquals(count($pathSegments), 1);
  933. $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
  934. $subPathSegments = $pathSegments[0]->getSubPathSegments();
  935. $this->assertTrue($pathSegments[0]->isAscending());
  936. $this->assertTrue(!is_null($subPathSegments));
  937. $this->assertTrue(is_array($subPathSegments));
  938. $this->assertEquals(count($subPathSegments), 1);
  939. $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
  940. $this->assertEquals($subPathSegments[0]->getName(), 'OrderID');
  941. $host->getWebOperationContext()->resetWebContextInternal();
  942. //specification of a $top value less than pagesize also need sorting,
  943. //$skiptoken also applicable, only thing is nextlink will be absent
  944. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  945. $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
  946. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  947. 'AbsoluteServiceUri' => new Url($baseUri),
  948. 'QueryString' => '$top=4&$skiptoken=1234',
  949. 'DataServiceVersion' => new Version(2, 0),
  950. 'MaxDataServiceVersion' => new Version(2, 0));
  951. $host = new DataServiceHost2($hostInfo);
  952. $dataService = new NorthWindDataService2();
  953. $dataService->setHost($host);
  954. $uriProcessor = $dataService->handleRequest();
  955. $requestDescription = $uriProcessor->getRequestDescription();
  956. $this->assertTrue(!is_null($requestDescription));
  957. $this->assertEquals($requestDescription->isSingleResult(), false);
  958. //$skip has not been specified
  959. $this->assertEquals($requestDescription->getSkipCount(), null);
  960. //top is specified and is less than page size
  961. $this->assertEquals($requestDescription->getTopCount(), 4);
  962. //top requires ordering
  963. $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
  964. $this->assertTrue(!is_null($internalOrderByInfo));
  965. $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
  966. $this->assertTrue(!is_null($pathSegments));
  967. $this->assertTrue(is_array($pathSegments));
  968. $this->assertEquals(count($pathSegments), 1);
  969. $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
  970. $subPathSegments = $pathSegments[0]->getSubPathSegments();
  971. $this->assertTrue($pathSegments[0]->isAscending());
  972. $this->assertTrue(!is_null($subPathSegments));
  973. $this->assertTrue(is_array($subPathSegments));
  974. $this->assertEquals(count($subPathSegments), 1);
  975. $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
  976. $this->assertEquals($subPathSegments[0]->getName(), 'OrderID');
  977. //$skiptoken is specified
  978. $internalSkiptokenInfo = $requestDescription->getInternalSkipTokenInfo();
  979. $this->assertTrue(!is_null($internalSkiptokenInfo));
  980. $this->assertTrue($internalSkiptokenInfo instanceof InternalSkipTokenInfo);
  981. $skipTokenInfo = $internalSkiptokenInfo->getSkipTokenInfo();
  982. $this->assertTrue($skipTokenInfo instanceof SkipTokenInfo);
  983. $orderByValuesInSkipToken = $skipTokenInfo->getOrderByKeysInToken();
  984. $this->assertTrue(!is_null($orderByValuesInSkipToken));
  985. $this->assertTrue(is_array($orderByValuesInSkipToken));
  986. $this->assertEquals(count($orderByValuesInSkipToken), 1);
  987. $this->assertTrue(!is_null($orderByValuesInSkipToken[0]));
  988. $this->assertTrue(is_array($orderByValuesInSkipToken[0]));
  989. $this->assertEquals(count($orderByValuesInSkipToken[0]), 2);
  990. $this->assertEquals($orderByValuesInSkipToken[0][0], 1234);
  991. $this->assertTrue(is_object($orderByValuesInSkipToken[0][1]));
  992. $this->assertTrue($orderByValuesInSkipToken[0][1] instanceof Int32);
  993. $host->getWebOperationContext()->resetWebContextInternal();
  994. //specification of a $top value greater than pagesize
  995. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  996. $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
  997. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  998. 'AbsoluteServiceUri' => new Url($baseUri),
  999. 'QueryString' => '$top=10&$skiptoken=1234',
  1000. 'DataServiceVersion' => new Version(2, 0),
  1001. 'MaxDataServiceVersion' => new Version(2, 0));
  1002. $host = new DataServiceHost2($hostInfo);
  1003. $dataService = new NorthWindDataService2();
  1004. $dataService->setHost($host);
  1005. $uriProcessor = $dataService->handleRequest();
  1006. $requestDescription = $uriProcessor->getRequestDescription();
  1007. $this->assertTrue(!is_null($requestDescription));
  1008. $this->assertEquals($requestDescription->isSingleResult(), false);
  1009. //$skip has not been specified
  1010. $this->assertEquals($requestDescription->getSkipCount(), null);
  1011. //top is specified and is greater than page size, so take count should be page size
  1012. $this->assertEquals($requestDescription->getTopCount(), 5);
  1013. //top requires ordering
  1014. $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
  1015. $this->assertTrue(!is_null($internalOrderByInfo));
  1016. //$skiptoken is specified
  1017. $internalSkiptokenInfo = $requestDescription->getInternalSkipTokenInfo();
  1018. $this->assertTrue(!is_null($internalSkiptokenInfo));
  1019. $host->getWebOperationContext()->resetWebContextInternal();
  1020. } catch (\Exception $exception) {
  1021. if ($host != null) {
  1022. $host->getWebOperationContext()->resetWebContextInternal();
  1023. }
  1024. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1025. }
  1026. }
  1027. /**
  1028. * $filter option can be applied to $links resource set
  1029. */
  1030. public function testUriProcessorForLinksResourceSet4()
  1031. {
  1032. try {
  1033. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1034. $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
  1035. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1036. 'AbsoluteServiceUri' => new Url($baseUri),
  1037. 'QueryString' => '$filter=OrderID eq 123 and OrderDate le datetime\'2000-11-11\'',
  1038. 'DataServiceVersion' => new Version(2, 0),
  1039. 'MaxDataServiceVersion' => new Version(2, 0));
  1040. $host = new DataServiceHost2($hostInfo);
  1041. $dataService = new NorthWindDataService2();
  1042. $dataService->setHost($host);
  1043. $uriProcessor = $dataService->handleRequest();
  1044. $requestDescription = $uriProcessor->getRequestDescription();
  1045. $this->assertTrue(!is_null($requestDescription));
  1046. $this->assertEquals($requestDescription->isSingleResult(), false);
  1047. $this->assertEquals($requestDescription->getTopCount(), 5);
  1048. //paging enabled
  1049. $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
  1050. $this->assertTrue(!is_null($internalOrderByInfo));
  1051. //$filter applied
  1052. $internalFilterInfo = $requestDescription->getInternalFilterInfo();
  1053. $this->assertTrue(!is_null($internalFilterInfo));
  1054. $this->assertTrue($internalFilterInfo instanceof InternalFilterInfo);
  1055. $filterFunction = $internalFilterInfo->getFilterFunction();
  1056. $this->assertTrue(!is_null($filterFunction));
  1057. $this->assertTrue($filterFunction instanceof AnonymousFunction);
  1058. $code = $filterFunction->getCode();
  1059. $this->assertEquals($code,
  1060. 'if(((!(is_null($lt->OrderID)) && !(is_null($lt->OrderDate))) && (($lt->OrderID == 123) && (ODataProducer\Providers\Metadata\Type\DateTime::dateTimeCmp($lt->OrderDate, \'2000-11-11\') <= 0)))) { return true; } else { return false;}');
  1061. $host->getWebOperationContext()->resetWebContextInternal();
  1062. } catch (\Exception $exception) {
  1063. if ($host != null) {
  1064. $host->getWebOperationContext()->resetWebContextInternal();
  1065. }
  1066. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1067. }
  1068. }
  1069. /**
  1070. * $inlinecount can be applied to $links identifying resource set
  1071. */
  1072. public function testUriProcessorForLinksResourceSet5()
  1073. {
  1074. try {
  1075. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1076. $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
  1077. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1078. 'AbsoluteServiceUri' => new Url($baseUri),
  1079. 'QueryString' => '$inlinecount=allpages',
  1080. 'DataServiceVersion' => new Version(2, 0),
  1081. 'MaxDataServiceVersion' => new Version(2, 0));
  1082. $host = new DataServiceHost2($hostInfo);
  1083. $dataService = new NorthWindDataService2();
  1084. $dataService->setHost($host);
  1085. $uriProcessor = $dataService->handleRequest();
  1086. $requestDescription = $uriProcessor->getRequestDescription();
  1087. $this->assertTrue(!is_null($requestDescription));
  1088. $this->assertEquals($requestDescription->isSingleResult(), false);
  1089. $this->assertEquals($requestDescription->getTopCount(), 5);
  1090. //paging enabled
  1091. $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
  1092. $this->assertTrue(!is_null($internalOrderByInfo));
  1093. //count mode is all pages
  1094. $this->assertEquals($requestDescription->getRequestCountOption(), RequestCountOption::INLINE);
  1095. $host->getWebOperationContext()->resetWebContextInternal();
  1096. } catch (\Exception $exception) {
  1097. if ($host != null) {
  1098. $host->getWebOperationContext()->resetWebContextInternal();
  1099. }
  1100. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1101. }
  1102. }
  1103. /**
  1104. * $filter option can be applied to $links resource set reference
  1105. */
  1106. public function testUriProcessorForLinksResourceSetReference1()
  1107. {
  1108. try {
  1109. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1110. $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders(123)';
  1111. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1112. 'AbsoluteServiceUri' => new Url($baseUri),
  1113. 'QueryString' => '$filter=OrderID eq 123 and OrderDate le datetime\'2000-11-11\'',
  1114. 'DataServiceVersion' => new Version(2, 0),
  1115. 'MaxDataServiceVersion' => new Version(2, 0));
  1116. $host = new DataServiceHost2($hostInfo);
  1117. $dataService = new NorthWindDataService2();
  1118. $dataService->setHost($host);
  1119. $uriProcessor = $dataService->handleRequest();
  1120. $requestDescription = $uriProcessor->getRequestDescription();
  1121. $this->assertTrue(!is_null($requestDescription));
  1122. $this->assertEquals($requestDescription->isSingleResult(), true);
  1123. $this->assertEquals($requestDescription->getTopCount(), null);
  1124. $this->assertEquals($requestDescription->getSkipCount(), null);
  1125. //paging not applicable enabled
  1126. $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
  1127. $this->assertTrue(is_null($internalOrderByInfo));
  1128. //$filter applied
  1129. $internalFilterInfo = $requestDescription->getInternalFilterInfo();
  1130. $this->assertTrue(!is_null($internalFilterInfo));
  1131. $this->assertTrue($internalFilterInfo instanceof InternalFilterInfo);
  1132. $filterFunction = $internalFilterInfo->getFilterFunction();
  1133. $this->assertTrue(!is_null($filterFunction));
  1134. $this->assertTrue($filterFunction instanceof AnonymousFunction);
  1135. $code = $filterFunction->getCode();
  1136. $this->assertEquals($code,
  1137. 'if(((!(is_null($lt->OrderID)) && !(is_null($lt->OrderDate))) && (($lt->OrderID == 123) && (ODataProducer\Providers\Metadata\Type\DateTime::dateTimeCmp($lt->OrderDate, \'2000-11-11\') <= 0)))) { return true; } else { return false;}');
  1138. $host->getWebOperationContext()->resetWebContextInternal();
  1139. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1140. $resourcePath = 'Orders(1234)/$links/Customer';
  1141. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1142. 'AbsoluteServiceUri' => new Url($baseUri),
  1143. 'QueryString' => '$filter=true',
  1144. 'DataServiceVersion' => new Version(2, 0),
  1145. 'MaxDataServiceVersion' => new Version(2, 0));
  1146. $host = new DataServiceHost2($hostInfo);
  1147. $dataService = new NorthWindDataService2();
  1148. $dataService->setHost($host);
  1149. $uriProcessor = $dataService->handleRequest();
  1150. $requestDescription = $uriProcessor->getRequestDescription();
  1151. $this->assertTrue(!is_null($requestDescription));
  1152. $this->assertEquals($requestDescription->isSingleResult(), true);
  1153. $this->assertEquals($requestDescription->getTopCount(), null);
  1154. $this->assertEquals($requestDescription->getSkipCount(), null);
  1155. //paging not applicable enabled
  1156. $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
  1157. $this->assertTrue(is_null($internalOrderByInfo));
  1158. //$filter applied
  1159. $internalFilterInfo = $requestDescription->getInternalFilterInfo();
  1160. $this->assertTrue(!is_null($internalFilterInfo));
  1161. $this->assertTrue($internalFilterInfo instanceof InternalFilterInfo);
  1162. $filterFunction = $internalFilterInfo->getFilterFunction();
  1163. $this->assertTrue(!is_null($filterFunction));
  1164. $this->assertTrue($filterFunction instanceof AnonymousFunction);
  1165. $code = $filterFunction->getCode();
  1166. $this->assertEquals($code, 'if(true) { return true; } else { return false;}');
  1167. $host->getWebOperationContext()->resetWebContextInternal();
  1168. } catch (\Exception $exception) {
  1169. if ($host != null) {
  1170. $host->getWebOperationContext()->resetWebContextInternal();
  1171. }
  1172. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1173. }
  1174. }
  1175. /**
  1176. * $orderby option cannot be applied to $links resource set reference
  1177. */
  1178. public function testUriProcessorForLinksResourceSetReference2()
  1179. {
  1180. try {
  1181. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1182. $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders(123)';
  1183. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1184. 'AbsoluteServiceUri' => new Url($baseUri),
  1185. 'QueryString' => '$orderby=OrderID',
  1186. 'DataServiceVersion' => new Version(2, 0),
  1187. 'MaxDataServiceVersion' => new Version(2, 0));
  1188. $host = new DataServiceHost2($hostInfo);
  1189. $dataService = new NorthWindDataService2();
  1190. $dataService->setHost($host);
  1191. $exceptionThrown = false;
  1192. try {
  1193. $dataService->handleRequest();
  1194. } catch (ODataException $odataException) {
  1195. $exceptionThrown = true;
  1196. $this->assertStringStartsWith('Query options $orderby, $inlinecount, $skip and $top cannot be applied to the requested resource', $odataException->getMessage());
  1197. }
  1198. if (!$exceptionThrown) {
  1199. $this->fail('An expected ODataException for $orderby query option on non-set has not been thrown');
  1200. }
  1201. $host->getWebOperationContext()->resetWebContextInternal();
  1202. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1203. $resourcePath = 'Orders(1234)/$links/Customer';
  1204. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1205. 'AbsoluteServiceUri' => new Url($baseUri),
  1206. 'QueryString' => '$orderby=CustomerID',
  1207. 'DataServiceVersion' => new Version(2, 0),
  1208. 'MaxDataServiceVersion' => new Version(2, 0));
  1209. $host = new DataServiceHost2($hostInfo);
  1210. $dataService = new NorthWindDataService2();
  1211. $dataService->setHost($host);
  1212. $exceptionThrown = false;
  1213. try {
  1214. $dataService->handleRequest();
  1215. } catch (ODataException $odataException) {
  1216. $exceptionThrown = true;
  1217. $this->assertStringStartsWith('Query options $orderby, $inlinecount, $skip and $top cannot be applied to the requested resource', $odataException->getMessage());
  1218. }
  1219. if (!$exceptionThrown) {
  1220. $this->fail('An expected ODataException for $orderby query option on non-set has not been thrown');
  1221. }
  1222. $host->getWebOperationContext()->resetWebContextInternal();
  1223. } catch (\Exception $exception) {
  1224. if ($host != null) {
  1225. $host->getWebOperationContext()->resetWebContextInternal();
  1226. }
  1227. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1228. }
  1229. }
  1230. /**
  1231. * $skiptoken option cannot be applied to $links resource set reference
  1232. */
  1233. public function testUriProcessorForLinksResourceSetReference3()
  1234. {
  1235. try {
  1236. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1237. $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders(123)';
  1238. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1239. 'AbsoluteServiceUri' => new Url($baseUri),
  1240. 'QueryString' => '$skiptoken=345',
  1241. 'DataServiceVersion' => new Version(2, 0),
  1242. 'MaxDataServiceVersion' => new Version(2, 0));
  1243. $host = new DataServiceHost2($hostInfo);
  1244. $dataService = new NorthWindDataService2();
  1245. $dataService->setHost($host);
  1246. $exceptionThrown = false;
  1247. try {
  1248. $dataService->handleRequest();
  1249. } catch (ODataException $odataException) {
  1250. $exceptionThrown = true;
  1251. $this->assertStringStartsWith('Query option $skiptoken cannot be applied to the requested resource', $odataException->getMessage());
  1252. }
  1253. if (!$exceptionThrown) {
  1254. $this->fail('An expected ODataException for $skiptoken query option on non-set has not been thrown');
  1255. }
  1256. $host->getWebOperationContext()->resetWebContextInternal();
  1257. } catch (\Exception $exception) {
  1258. if ($host != null) {
  1259. $host->getWebOperationContext()->resetWebContextInternal();
  1260. }
  1261. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1262. }
  1263. }
  1264. /**
  1265. * $top and $skip option cannot be applied to $links resource set reference
  1266. */
  1267. public function testUriProcessorForLinksResourceSetReference4()
  1268. {
  1269. try {
  1270. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1271. $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders(123)';
  1272. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1273. 'AbsoluteServiceUri' => new Url($baseUri),
  1274. 'QueryString' => '$skip=1',
  1275. 'DataServiceVersion' => new Version(2, 0),
  1276. 'MaxDataServiceVersion' => new Version(2, 0));
  1277. $host = new DataServiceHost2($hostInfo);
  1278. $dataService = new NorthWindDataService2();
  1279. $dataService->setHost($host);
  1280. $exceptionThrown = false;
  1281. try {
  1282. $dataService->handleRequest();
  1283. } catch (ODataException $odataException) {
  1284. $exceptionThrown = true;
  1285. $this->assertStringStartsWith('Query options $orderby, $inlinecount, $skip and $top cannot be applied to the requested resource', $odataException->getMessage());
  1286. }
  1287. if (!$exceptionThrown) {
  1288. $this->fail('An expected ODataException for $skip query option on non-set has not been thrown');
  1289. }
  1290. $host->getWebOperationContext()->resetWebContextInternal();
  1291. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1292. $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders(234)';
  1293. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1294. 'AbsoluteServiceUri' => new Url($baseUri),
  1295. 'QueryString' => '$top=4',
  1296. 'DataServiceVersion' => new Version(2, 0),
  1297. 'MaxDataServiceVersion' => new Version(2, 0));
  1298. $host = new DataServiceHost2($hostInfo);
  1299. $dataService = new NorthWindDataService2();
  1300. $dataService->setHost($host);
  1301. $exceptionThrown = false;
  1302. try {
  1303. $dataService->handleRequest();
  1304. } catch (ODataException $odataException) {
  1305. $exceptionThrown = true;
  1306. $this->assertStringStartsWith('Query options $orderby, $inlinecount, $skip and $top cannot be applied to the requested resource', $odataException->getMessage());
  1307. }
  1308. if (!$exceptionThrown) {
  1309. $this->fail('An expected ODataException for $top query option on non-set has not been thrown');
  1310. }
  1311. $host->getWebOperationContext()->resetWebContextInternal();
  1312. } catch (\Exception $exception) {
  1313. if ($host != null) {
  1314. $host->getWebOperationContext()->resetWebContextInternal();
  1315. }
  1316. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1317. }
  1318. }
  1319. /**
  1320. * $inlinecount option cannot be applied to $links resource set reference
  1321. */
  1322. public function testUriProcessorForLinksResourceSetReference5()
  1323. {
  1324. try {
  1325. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1326. $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders(123)';
  1327. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1328. 'AbsoluteServiceUri' => new Url($baseUri),
  1329. 'QueryString' => '$inlinecount=allpages',
  1330. 'DataServiceVersion' => new Version(2, 0),
  1331. 'MaxDataServiceVersion' => new Version(2, 0));
  1332. $host = new DataServiceHost2($hostInfo);
  1333. $dataService = new NorthWindDataService2();
  1334. $dataService->setHost($host);
  1335. $exceptionThrown = false;
  1336. try {
  1337. $dataService->handleRequest();
  1338. } catch (ODataException $odataException) {
  1339. $exceptionThrown = true;
  1340. $this->assertStringStartsWith('Query options $orderby, $inlinecount, $skip and $top cannot be applied to the requested resource', $odataException->getMessage());
  1341. }
  1342. if (!$exceptionThrown) {
  1343. $this->fail('An expected ODataException for $inlinecount query option on non-set has not been thrown');
  1344. }
  1345. $host->getWebOperationContext()->resetWebContextInternal();
  1346. } catch (\Exception $exception) {
  1347. if ($host != null) {
  1348. $host->getWebOperationContext()->resetWebContextInternal();
  1349. }
  1350. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1351. }
  1352. }
  1353. /**
  1354. * $expand, $select option cannot be applied to $links resource set reference or $link resource set
  1355. */
  1356. public function testUriProcessorForLinksResource()
  1357. {
  1358. try {
  1359. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1360. $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders(123)';
  1361. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1362. 'AbsoluteServiceUri' => new Url($baseUri),
  1363. 'QueryString' => '$expand=Order_Details',
  1364. 'DataServiceVersion' => new Version(2, 0),
  1365. 'MaxDataServiceVersion' => new Version(2, 0));
  1366. $host = new DataServiceHost2($hostInfo);
  1367. $dataService = new NorthWindDataService2();
  1368. $dataService->setHost($host);
  1369. $exceptionThrown = false;
  1370. try {
  1371. $dataService->handleRequest();
  1372. } catch (ODataException $odataException) {
  1373. $exceptionThrown = true;
  1374. $this->assertStringStartsWith('Query option $expand cannot be applied to the requested resource', $odataException->getMessage());
  1375. }
  1376. if (!$exceptionThrown) {
  1377. $this->fail('An expected ODataException for $expand query option on $link resource has not been thrown');
  1378. }
  1379. $host->getWebOperationContext()->resetWebContextInternal();
  1380. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1381. $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders(123)';
  1382. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1383. 'AbsoluteServiceUri' => new Url($baseUri),
  1384. 'QueryString' => '$select=OrderID',
  1385. 'DataServiceVersion' => new Version(2, 0),
  1386. 'MaxDataServiceVersion' => new Version(2, 0));
  1387. $host = new DataServiceHost2($hostInfo);
  1388. $dataService = new NorthWindDataService2();
  1389. $dataService->setHost($host);
  1390. $exceptionThrown = false;
  1391. try {
  1392. $dataService->handleRequest();
  1393. } catch (ODataException $odataException) {
  1394. $exceptionThrown = true;
  1395. $this->assertStringStartsWith('Query option $select cannot be applied to the requested resource', $odataException->getMessage());
  1396. }
  1397. if (!$exceptionThrown) {
  1398. $this->fail('An expected ODataException for $select query option on $link resource has not been thrown');
  1399. }
  1400. $host->getWebOperationContext()->resetWebContextInternal();
  1401. } catch (\Exception $exception) {
  1402. if ($host != null) {
  1403. $host->getWebOperationContext()->resetWebContextInternal();
  1404. }
  1405. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1406. }
  1407. }
  1408. /**
  1409. * $inline count is not supported for protocol version V1
  1410. */
  1411. public function testUriProcessorForInlineCount1()
  1412. {
  1413. try {
  1414. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1415. $resourcePath = 'Products(11)/Order_Details';
  1416. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1417. 'AbsoluteServiceUri' => new Url($baseUri),
  1418. //Paging is enabled this cause skiptoken to be included
  1419. //in the response, thus reponse version become 2.0
  1420. //But if $top is specified and its value is less than page size
  1421. //then we don't need to include $skiptoken in response
  1422. //so response version is 1.0.
  1423. //If the paging is enabled and protocol to be used is V1
  1424. //then a request (without a $top or $top value > pagesize)
  1425. //cause the repsonse version of 2.0 to be used, but server
  1426. //will throw error as protocol version is set to V1.
  1427. //This error will be thrown from ProcessSkipAndTopCount function.
  1428. //$inlinecount is a V2 feature, so with configured version of V1
  1429. //ProcessCount will thorow error.
  1430. //We are adding a $top value (< pagesize) with $inlinecount so that
  1431. //version error will be thrown from ProcessCount instead of from
  1432. //ProcessSkipAndTopCount
  1433. 'QueryString' => '$inlinecount=allpages&$top=3',
  1434. 'DataServiceVersion' => new Version(2, 0),
  1435. 'MaxDataServiceVersion' => new Version(2, 0));
  1436. $host = new DataServiceHost2($hostInfo);
  1437. $dataService = new NorthWindDataServiceV1();
  1438. $dataService->setHost($host);
  1439. $exceptionThrown = false;
  1440. try {
  1441. $dataService->handleRequest();
  1442. } catch (ODataException $odataException) {
  1443. $exceptionThrown = true;
  1444. $this->assertStringStartsWith('The response requires that version 2.0 of the protocol be used, but the MaxProtocolVersion of the data service is set to 1.0', $odataException->getMessage());
  1445. }
  1446. if (!$exceptionThrown) {
  1447. $this->fail('An expected ODataException for $inlinecount query option with V1 configured service has not been thrown');
  1448. }
  1449. $host->getWebOperationContext()->resetWebContextInternal();
  1450. } catch (\Exception $exception) {
  1451. if ($host != null) {
  1452. $host->getWebOperationContext()->resetWebContextInternal();
  1453. }
  1454. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1455. }
  1456. }
  1457. /**
  1458. * For $inline request, client's DataServiceVersion header must be >= 2.0
  1459. */
  1460. public function testUriProcessorForInlineCount2()
  1461. {
  1462. try {
  1463. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1464. $resourcePath = 'Products(11)/Order_Details';
  1465. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1466. 'AbsoluteServiceUri' => new Url($baseUri),
  1467. 'QueryString' => '$inlinecount=allpages',
  1468. 'DataServiceVersion' => new Version(1, 0),
  1469. 'MaxDataServiceVersion' => new Version(2, 0));
  1470. $host = new DataServiceHost2($hostInfo);
  1471. $dataService = new NorthWindDataService2();
  1472. $dataService->setHost($host);
  1473. $exceptionThrown = false;
  1474. try {
  1475. $dataService->handleRequest();
  1476. } catch (ODataException $odataException) {
  1477. $exceptionThrown = true;
  1478. $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0'", $odataException->getMessage());
  1479. }
  1480. if (!$exceptionThrown) {
  1481. $this->fail('An expected ODataException for $inlinecount query option request DataServiceVersion 1.0 has not been thrown');
  1482. }
  1483. $host->getWebOperationContext()->resetWebContextInternal();
  1484. } catch (\Exception $exception) {
  1485. if ($host != null) {
  1486. $host->getWebOperationContext()->resetWebContextInternal();
  1487. }
  1488. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1489. }
  1490. }
  1491. /**
  1492. * For $inline request, client's MaxDataServiceVersion header must be >= 2.0
  1493. */
  1494. public function testUriProcessorForInlineCount3()
  1495. {
  1496. try {
  1497. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1498. $resourcePath = 'Products(11)/Order_Details';
  1499. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1500. 'AbsoluteServiceUri' => new Url($baseUri),
  1501. 'QueryString' => '$inlinecount=allpages',
  1502. 'DataServiceVersion' => new Version(2, 0),
  1503. 'MaxDataServiceVersion' => new Version(1, 0));
  1504. $host = new DataServiceHost2($hostInfo);
  1505. $dataService = new NorthWindDataService2();
  1506. $dataService->setHost($host);
  1507. $exceptionThrown = false;
  1508. try {
  1509. $dataService->handleRequest();
  1510. } catch (ODataException $odataException) {
  1511. $exceptionThrown = true;
  1512. $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0'", $odataException->getMessage());
  1513. }
  1514. if (!$exceptionThrown) {
  1515. $this->fail('An expected ODataException for $inlinecount query option with request DataServiceVersion 1.0 has not been thrown');
  1516. }
  1517. $host->getWebOperationContext()->resetWebContextInternal();
  1518. } catch (\Exception $exception) {
  1519. if ($host != null) {
  1520. $host->getWebOperationContext()->resetWebContextInternal();
  1521. }
  1522. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1523. }
  1524. }
  1525. /**
  1526. * only supported $inlinecount valus are 'allpages' and 'none'
  1527. */
  1528. public function testUriProcessorForInlineCount4()
  1529. {
  1530. try {
  1531. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1532. $resourcePath = 'Products(11)/Order_Details';
  1533. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1534. 'AbsoluteServiceUri' => new Url($baseUri),
  1535. 'QueryString' => '$inlinecount=partialpages',
  1536. 'DataServiceVersion' => new Version(2, 0),
  1537. 'MaxDataServiceVersion' => new Version(2, 0));
  1538. $host = new DataServiceHost2($hostInfo);
  1539. $dataService = new NorthWindDataService2();
  1540. $dataService->setHost($host);
  1541. $exceptionThrown = false;
  1542. try {
  1543. $dataService->handleRequest();
  1544. } catch (ODataException $odataException) {
  1545. $exceptionThrown = true;
  1546. $this->assertStringStartsWith('Unknown $inlinecount option, only "allpages" and "none" are supported', $odataException->getMessage());
  1547. }
  1548. if (!$exceptionThrown) {
  1549. $this->fail('An expected ODataException for invalid $inlinecount query option has not been thrown');
  1550. }
  1551. $host->getWebOperationContext()->resetWebContextInternal();
  1552. } catch (\Exception $exception) {
  1553. if ($host != null) {
  1554. $host->getWebOperationContext()->resetWebContextInternal();
  1555. }
  1556. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1557. }
  1558. }
  1559. /**
  1560. * $filter can be applied on complex resource
  1561. */
  1562. public function testUriProcessorForFilterOnComplex()
  1563. {
  1564. try {
  1565. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1566. $resourcePath = 'Orders(123)/Customer/Address';
  1567. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1568. 'AbsoluteServiceUri' => new Url($baseUri),
  1569. 'QueryString' => '$filter=HouseNumber eq null',
  1570. 'DataServiceVersion' => new Version(1, 0),
  1571. 'MaxDataServiceVersion' => new Version(1, 0));
  1572. $host = new DataServiceHost2($hostInfo);
  1573. $dataService = new NorthWindDataService2();
  1574. $dataService->setHost($host);
  1575. $exceptionThrown = false;
  1576. $dataService->handleRequest();
  1577. $uriProcessor = $dataService->handleRequest();
  1578. $requestDescription = $uriProcessor->getRequestDescription();
  1579. $this->assertTrue(!is_null($requestDescription));
  1580. $this->assertEquals($requestDescription->isSingleResult(), true);
  1581. //$filter applied
  1582. $internalFilterInfo = $requestDescription->getInternalFilterInfo();
  1583. $this->assertTrue(!is_null($internalFilterInfo));
  1584. $this->assertTrue($internalFilterInfo instanceof InternalFilterInfo);
  1585. $filterFunction = $internalFilterInfo->getFilterFunction();
  1586. $this->assertTrue(!is_null($filterFunction));
  1587. $this->assertTrue($filterFunction instanceof AnonymousFunction);
  1588. $code = $filterFunction->getCode();
  1589. $this->assertTrue(is_null($requestDescription->getRootProjectionNode()));
  1590. $host->getWebOperationContext()->resetWebContextInternal();
  1591. } catch (\Exception $exception) {
  1592. if ($host != null) {
  1593. $host->getWebOperationContext()->resetWebContextInternal();
  1594. }
  1595. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1596. }
  1597. }
  1598. /**
  1599. * $filter cannot be applied on primitve resource
  1600. */
  1601. public function testUriProcessorForFilterOnPrimitiveType()
  1602. {
  1603. try {
  1604. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1605. $resourcePath = 'Products(11)/ProductID';
  1606. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1607. 'AbsoluteServiceUri' => new Url($baseUri),
  1608. 'QueryString' => '$filter=true',
  1609. 'DataServiceVersion' => new Version(1, 0),
  1610. 'MaxDataServiceVersion' => new Version(1, 0));
  1611. $host = new DataServiceHost2($hostInfo);
  1612. $dataService = new NorthWindDataService2();
  1613. $dataService->setHost($host);
  1614. $exceptionThrown = false;
  1615. try {
  1616. $dataService->handleRequest();
  1617. } catch (ODataException $odataException) {
  1618. $exceptionThrown = true;
  1619. $this->assertStringStartsWith('Query option $filter cannot be applied to the requested resource', $odataException->getMessage());
  1620. }
  1621. if (!$exceptionThrown) {
  1622. $this->fail('An expected ODataException for $filter query on primitve has not been thrown');
  1623. }
  1624. $host->getWebOperationContext()->resetWebContextInternal();
  1625. } catch (\Exception $exception) {
  1626. if ($host != null) {
  1627. $host->getWebOperationContext()->resetWebContextInternal();
  1628. }
  1629. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1630. }
  1631. }
  1632. /**
  1633. * $filter cannot be applied on bag resource
  1634. */
  1635. public function testUriProcessorForFilterOnBag()
  1636. {
  1637. try {
  1638. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1639. $resourcePath = 'Employees(\'EMP1\')/Emails';
  1640. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1641. 'AbsoluteServiceUri' => new Url($baseUri),
  1642. 'QueryString' => '$filter=true',
  1643. 'DataServiceVersion' => new Version(3, 0),
  1644. 'MaxDataServiceVersion' => new Version(3, 0));
  1645. $host = new DataServiceHost2($hostInfo);
  1646. //Note we are using V3 data service
  1647. $dataService = new NorthWindDataServiceV3();
  1648. $dataService->setHost($host);
  1649. $exceptionThrown = false;
  1650. try {
  1651. $dataService->handleRequest();
  1652. } catch (ODataException $odataException) {
  1653. $exceptionThrown = true;
  1654. $this->assertStringStartsWith('Query option $filter cannot be applied to the requested resource', $odataException->getMessage());
  1655. }
  1656. if (!$exceptionThrown) {
  1657. $this->fail('An expected ODataException for $filter query option on bag has not been thrown');
  1658. }
  1659. $host->getWebOperationContext()->resetWebContextInternal();
  1660. } catch (\Exception $exception) {
  1661. if ($host != null) {
  1662. $host->getWebOperationContext()->resetWebContextInternal();
  1663. }
  1664. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1665. }
  1666. }
  1667. /**
  1668. * $filter cannot be applied on primitve value
  1669. */
  1670. public function testUriProcessorForFilterOnValue()
  1671. {
  1672. try {
  1673. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1674. $resourcePath = 'Orders(11)/Customer/CustomerID/$value';
  1675. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1676. 'AbsoluteServiceUri' => new Url($baseUri),
  1677. 'QueryString' => '$filter=true',
  1678. 'DataServiceVersion' => new Version(1, 0),
  1679. 'MaxDataServiceVersion' => new Version(1, 0));
  1680. $host = new DataServiceHost2($hostInfo);
  1681. $dataService = new NorthWindDataService2();
  1682. $dataService->setHost($host);
  1683. $exceptionThrown = false;
  1684. try {
  1685. $dataService->handleRequest();
  1686. } catch (ODataException $odataException) {
  1687. $exceptionThrown = true;
  1688. $this->assertStringStartsWith('Query option $filter cannot be applied to the requested resource', $odataException->getMessage());
  1689. }
  1690. if (!$exceptionThrown) {
  1691. $this->fail('An expected ODataException for $filter query option on primitve value has not been thrown');
  1692. }
  1693. $host->getWebOperationContext()->resetWebContextInternal();
  1694. } catch (\Exception $exception) {
  1695. if ($host != null) {
  1696. $host->getWebOperationContext()->resetWebContextInternal();
  1697. }
  1698. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1699. }
  1700. }
  1701. /**
  1702. * When requesting for a bag DataServiceVersion should be >= 3.0
  1703. */
  1704. public function testUriProcessorWithTargetAsBag1()
  1705. {
  1706. try {
  1707. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1708. $resourcePath = 'Employees(\'EMP1\')/Emails';
  1709. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1710. 'AbsoluteServiceUri' => new Url($baseUri),
  1711. 'QueryString' => null,
  1712. 'DataServiceVersion' => new Version(2, 0),
  1713. 'MaxDataServiceVersion' => new Version(2, 0));
  1714. $host = new DataServiceHost2($hostInfo);
  1715. $dataService = new NorthWindDataService2();
  1716. $dataService->setHost($host);
  1717. $exceptionThrown = false;
  1718. try {
  1719. $dataService->handleRequest();
  1720. } catch (ODataException $odataException) {
  1721. $exceptionThrown = true;
  1722. $this->assertStringStartsWith("Request version '2.0' is not supported for the request payload. The only supported version is '3.0'", $odataException->getMessage());
  1723. }
  1724. if (!$exceptionThrown) {
  1725. $this->fail('An expected ODataException for a bag request with MaxDataServiceVersion < 3.0 has not been thrown');
  1726. }
  1727. $host->getWebOperationContext()->resetWebContextInternal();
  1728. } catch (\Exception $exception) {
  1729. if ($host != null) {
  1730. $host->getWebOperationContext()->resetWebContextInternal();
  1731. }
  1732. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1733. }
  1734. }
  1735. /**
  1736. * The MaxProtocolVersion configured for the service should be >=3.0 to respond to request for Bag
  1737. */
  1738. public function testUriProcessorWithTargetAsBag2()
  1739. {
  1740. try {
  1741. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1742. $resourcePath = 'Employees(\'EMP1\')/Emails';
  1743. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1744. 'AbsoluteServiceUri' => new Url($baseUri),
  1745. 'QueryString' => null,
  1746. 'DataServiceVersion' => new Version(3, 0),
  1747. 'MaxDataServiceVersion' => new Version(3, 0));
  1748. $host = new DataServiceHost2($hostInfo);
  1749. $dataService = new NorthWindDataService2();
  1750. $dataService->setHost($host);
  1751. $exceptionThrown = false;
  1752. try {
  1753. $dataService->handleRequest();
  1754. } catch (ODataException $odataException) {
  1755. $exceptionThrown = true;
  1756. $this->assertStringStartsWith("The response requires that version 3.0 of the protocol be used, but the MaxProtocolVersion of the data service is set to 2.0", $odataException->getMessage());
  1757. }
  1758. if (!$exceptionThrown) {
  1759. $this->fail('An expected ODataException for a bag request to a service configured with V2 has not been thrown');
  1760. }
  1761. $host->getWebOperationContext()->resetWebContextInternal();
  1762. } catch (\Exception $exception) {
  1763. if ($host != null) {
  1764. $host->getWebOperationContext()->resetWebContextInternal();
  1765. }
  1766. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1767. }
  1768. }
  1769. /**
  1770. * $select cannot be applied if its disabled on configuration
  1771. */
  1772. public function testUriProcessorForSelectWhereProjectionDisabled()
  1773. {
  1774. try {
  1775. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1776. $resourcePath = 'Orders(11)/Customer';
  1777. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1778. 'AbsoluteServiceUri' => new Url($baseUri),
  1779. 'QueryString' => '$expand=Orders&$select=CustomerID,Orders',
  1780. 'DataServiceVersion' => new Version(1, 0),
  1781. 'MaxDataServiceVersion' => new Version(1, 0));
  1782. $host = new DataServiceHost2($hostInfo);
  1783. $dataService = new NorthWindDataServiceV3();
  1784. $dataService->setHost($host);
  1785. $exceptionThrown = false;
  1786. try {
  1787. $dataService->handleRequest();
  1788. } catch (ODataException $odataException) {
  1789. $exceptionThrown = true;
  1790. $this->assertStringStartsWith('The ability to use the $select query option to define a projection in a data service query is disabled', $odataException->getMessage());
  1791. }
  1792. if (!$exceptionThrown) {
  1793. $this->fail('An expected ODataException for $select option on projection disabled service has not been thrown');
  1794. }
  1795. $host->getWebOperationContext()->resetWebContextInternal();
  1796. } catch (\Exception $exception) {
  1797. if ($host != null) {
  1798. $host->getWebOperationContext()->resetWebContextInternal();
  1799. }
  1800. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1801. }
  1802. }
  1803. /**
  1804. * select and expand can be applied to request url identifying resource set
  1805. */
  1806. /** public function testUriProcessorForSelelctExpandOnResourceSet()
  1807. {
  1808. }
  1809. /**
  1810. * $select is a V2 feature so client should request with 'DataServiceVersion' 2.0
  1811. * but the response of select can be handled by V1 client so a value of 1.0 for MaxDataServiceVersion
  1812. * will work
  1813. */
  1814. public function testUriProcessorForSelectExpandOnResourceWithDataServiceVersion1_0()
  1815. {
  1816. try {
  1817. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1818. $resourcePath = 'Orders(11)/Customer';
  1819. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1820. 'AbsoluteServiceUri' => new Url($baseUri),
  1821. 'QueryString' => '$expand=Orders&$select=CustomerID,Orders',
  1822. //use of $select requires this header to 2.0
  1823. 'DataServiceVersion' => new Version(1, 0),
  1824. 'MaxDataServiceVersion' => new Version(1, 0));
  1825. $host = new DataServiceHost2($hostInfo);
  1826. $dataService = new NorthWindDataService2();
  1827. $dataService->setHost($host);
  1828. $exceptionThrown = false;
  1829. try {
  1830. $dataService->handleRequest();
  1831. } catch (ODataException $odataException) {
  1832. $exceptionThrown = true;
  1833. $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0'", $odataException->getMessage());
  1834. }
  1835. if (!$exceptionThrown) {
  1836. $this->fail('An expected ODataException for $select query option with DataServiceVersion 1.0 has not been thrown');
  1837. }
  1838. $host->getWebOperationContext()->resetWebContextInternal();
  1839. } catch (\Exception $exception) {
  1840. if ($host != null) {
  1841. $host->getWebOperationContext()->resetWebContextInternal();
  1842. }
  1843. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1844. }
  1845. }
  1846. /**
  1847. * if paging is applicable for top level resource
  1848. * (1) Paging enabled and $top > pageSize => require next link
  1849. * (2) Paging enabled and no $top => require next link
  1850. * Then 'MaxDataServiceVersion' in request header must be >= 2.0
  1851. */
  1852. public function testUriProcessorForPagedTopLevelResourceWithMaxDataServiceVersion1_0()
  1853. {
  1854. try {
  1855. //Paging enabled for top level resource set and $top > pageSize => require next link
  1856. //so MaxDataServiceVersion 1.0 will not work
  1857. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1858. $resourcePath = 'Orders';
  1859. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1860. 'AbsoluteServiceUri' => new Url($baseUri),
  1861. 'QueryString' => '$top=10&$expand=Customer',
  1862. 'DataServiceVersion' => new Version(1, 0),
  1863. 'MaxDataServiceVersion' => new Version(1, 0));
  1864. $host = new DataServiceHost2($hostInfo);
  1865. $dataService = new NorthWindDataService2();
  1866. $dataService->setHost($host);
  1867. $exceptionThrown = false;
  1868. try {
  1869. $dataService->handleRequest();
  1870. } catch (ODataException $odataException) {
  1871. $exceptionThrown = true;
  1872. $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0'", $odataException->getMessage());
  1873. }
  1874. if (!$exceptionThrown) {
  1875. $this->fail('An expected ODataException for a paged top level result (having $top) with MaxDataServiceVersion 1.0 has not been thrown');
  1876. }
  1877. $host->getWebOperationContext()->resetWebContextInternal();
  1878. //Paging enabled for top level resource set and no $top => require next link
  1879. //so MaxDataServiceVersion 1.0 will not work
  1880. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1881. $resourcePath = 'Orders';
  1882. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1883. 'AbsoluteServiceUri' => new Url($baseUri),
  1884. //error will be thrown from processskipAndTopOption before processor process expand
  1885. 'QueryString' => '$expand=Customer',
  1886. //DataServiceVersion can be 1.0 no issue
  1887. 'DataServiceVersion' => new Version(1, 0),
  1888. //But MaxDataServiceVersion must be 2.0 as respose will include
  1889. //a nextlink for expanded 'Orders' property
  1890. 'MaxDataServiceVersion' => new Version(1, 0));
  1891. $host = new DataServiceHost2($hostInfo);
  1892. $dataService = new NorthWindDataService2();
  1893. $dataService->setHost($host);
  1894. $exceptionThrown = false;
  1895. try {
  1896. $dataService->handleRequest();
  1897. } catch (ODataException $odataException) {
  1898. $exceptionThrown = true;
  1899. $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0'", $odataException->getMessage());
  1900. }
  1901. if (!$exceptionThrown) {
  1902. $this->fail('An expected ODataException for a paged top level result with MaxDataServiceVersion 1.0 has not been thrown');
  1903. }
  1904. $host->getWebOperationContext()->resetWebContextInternal();
  1905. //Paging enabled for top level resource set and $top < pageSize => not require next link
  1906. //so MaxDataServiceVersion 1.0 will work
  1907. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1908. $resourcePath = 'Orders';
  1909. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1910. 'AbsoluteServiceUri' => new Url($baseUri),
  1911. 'QueryString' => '$top=2&$expand=Customer',
  1912. 'DataServiceVersion' => new Version(1, 0),
  1913. 'MaxDataServiceVersion' => new Version(1, 0));
  1914. $host = new DataServiceHost2($hostInfo);
  1915. $dataService = new NorthWindDataService2();
  1916. $dataService->setHost($host);
  1917. $uriProcessor = $dataService->handleRequest();
  1918. $requestDescription = $uriProcessor->getRequestDescription();
  1919. $this->assertTrue(!is_null($requestDescription));
  1920. $this->assertEquals($requestDescription->isSingleResult(), false);
  1921. $this->assertEquals($requestDescription->getTopCount(), 2);
  1922. //has orderby infor
  1923. $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
  1924. $this->assertTrue(!is_null($internalOrderByInfo));
  1925. $projectionTreeRoot = $requestDescription->getRootProjectionNode();
  1926. $this->assertTrue(!is_null($projectionTreeRoot));
  1927. $this->assertTrue($projectionTreeRoot instanceof RootProjectionNode);
  1928. //There will be one child nodes
  1929. //Expand Projection Node => 'Customer'
  1930. $childNodes = $projectionTreeRoot->getChildNodes();
  1931. $this->assertTrue(!is_null($childNodes));
  1932. $this->assertTrue(is_array($childNodes));
  1933. //$this->assertEquals(count($childNodes), 1);
  1934. $this->assertTrue(array_key_exists('Customer', $childNodes));
  1935. $this->assertTrue($childNodes['Customer'] instanceof ExpandedProjectionNode);
  1936. $customerExpandedNode = $childNodes['Customer'];
  1937. //Sort info will not be there for expanded 'Customer' as its resource set reference
  1938. $internalOrderByInfo = $customerExpandedNode->getInternalOrderByInfo();
  1939. $this->assertTrue(is_null($internalOrderByInfo));
  1940. $host->getWebOperationContext()->resetWebContextInternal();
  1941. } catch (\Exception $exception) {
  1942. if ($host != null) {
  1943. $host->getWebOperationContext()->resetWebContextInternal();
  1944. }
  1945. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1946. }
  1947. }
  1948. /**
  1949. * If paging is enabled expanded result is resource set (top level is resource set reference
  1950. * so no paging for top level resoure) then client should request with
  1951. * MaxDataServiceVersion >= 2.0
  1952. */
  1953. public function testUriProcessorForPagedExpandedResourceSetWithMaxDataServiceVersion1_0()
  1954. {
  1955. try {
  1956. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1957. $resourcePath = 'Orders(11)/Customer';
  1958. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1959. 'AbsoluteServiceUri' => new Url($baseUri),
  1960. 'QueryString' => '$expand=Orders',
  1961. //DataServiceVersion can be 1.0 no issue
  1962. 'DataServiceVersion' => new Version(1, 0),
  1963. //But MaxDataServiceVersion must be 2.0 as respose will include
  1964. //a nextlink for expanded 'Orders' property
  1965. 'MaxDataServiceVersion' => new Version(1, 0));
  1966. $host = new DataServiceHost2($hostInfo);
  1967. $dataService = new NorthWindDataService2();
  1968. $dataService->setHost($host);
  1969. $exceptionThrown = false;
  1970. try {
  1971. $dataService->handleRequest();
  1972. } catch (ODataException $odataException) {
  1973. $exceptionThrown = true;
  1974. $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0'", $odataException->getMessage());
  1975. }
  1976. if (!$exceptionThrown) {
  1977. $this->fail('An expected ODataException for an paged expanded result with MaxDataServiceVersion 1.0 has not been thrown');
  1978. }
  1979. $host->getWebOperationContext()->resetWebContextInternal();
  1980. } catch (\Exception $exception) {
  1981. if ($host != null) {
  1982. $host->getWebOperationContext()->resetWebContextInternal();
  1983. }
  1984. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  1985. }
  1986. }
  1987. /**
  1988. * select and expand can be applied to request url identifying resource set reference
  1989. * Here the top level resource will not be paged as its a resource set reference
  1990. * But if there is an expansion that leads to resource set then paging will be required for
  1991. * the expanded result means hould request with MaxDataServiceVersion 2_0
  1992. */
  1993. public function testUriProcessorForSelectExpandOnResourceSetReference()
  1994. {
  1995. try {
  1996. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  1997. $resourcePath = 'Orders(11)/Customer';
  1998. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  1999. 'AbsoluteServiceUri' => new Url($baseUri),
  2000. 'QueryString' => '$expand=Orders&$select=CustomerID,Orders',
  2001. //use of $select requires this header to 1.0
  2002. 'DataServiceVersion' => new Version(2, 0),
  2003. //The expanded property will be paged, so skiptoken will be there
  2004. //client says i can handle it
  2005. 'MaxDataServiceVersion' => new Version(2, 0));
  2006. $host = new DataServiceHost2($hostInfo);
  2007. $dataService = new NorthWindDataService2();
  2008. $dataService->setHost($host);
  2009. $uriProcessor = $dataService->handleRequest();
  2010. $requestDescription = $uriProcessor->getRequestDescription();
  2011. $this->assertTrue(!is_null($requestDescription));
  2012. $this->assertEquals($requestDescription->isSingleResult(), true);
  2013. //paging is not applicable for resource set reference 'Customer'
  2014. $this->assertEquals($requestDescription->getTopCount(), null);
  2015. //no orderby infor
  2016. $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
  2017. $this->assertTrue(is_null($internalOrderByInfo));
  2018. $projectionTreeRoot = $requestDescription->getRootProjectionNode();
  2019. $this->assertTrue(!is_null($projectionTreeRoot));
  2020. $this->assertTrue($projectionTreeRoot instanceof RootProjectionNode);
  2021. //There will be two child nodes
  2022. //Expand Projection Node => 'Orders'
  2023. //Projection Node => 'CustomerID'
  2024. $childNodes = $projectionTreeRoot->getChildNodes();
  2025. $this->assertTrue(!is_null($childNodes));
  2026. $this->assertTrue(is_array($childNodes));
  2027. $this->assertEquals(count($childNodes), 2);
  2028. $this->assertTrue(array_key_exists('Orders', $childNodes));
  2029. $this->assertTrue($childNodes['Orders'] instanceof ExpandedProjectionNode);
  2030. $this->assertTrue(array_key_exists('Orders', $childNodes));
  2031. $this->assertTrue($childNodes['Orders'] instanceof ProjectionNode);
  2032. $ordersExpandedNode = $childNodes['Orders'];
  2033. //Sort info will be there for expanded 'Orders' as paging is
  2034. //enabled for this resource set
  2035. $internalOrderByInfo = $ordersExpandedNode->getInternalOrderByInfo();
  2036. $this->assertTrue(!is_null($internalOrderByInfo));
  2037. $this->assertTrue($internalOrderByInfo instanceof InternalOrderByInfo);
  2038. $host->getWebOperationContext()->resetWebContextInternal();
  2039. } catch (\Exception $exception) {
  2040. if ($host != null) {
  2041. $host->getWebOperationContext()->resetWebContextInternal();
  2042. }
  2043. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  2044. }
  2045. }
  2046. /**
  2047. * select and expand can be applied to only request uri identifying a resource set
  2048. * or resource set refernce.
  2049. */
  2050. public function testUriProcessorForSelectExpandOnNonResourceSetOrReference()
  2051. {
  2052. try {
  2053. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  2054. $resourcePath = 'Orders(123)/Customer/Address';
  2055. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  2056. 'AbsoluteServiceUri' => new Url($baseUri),
  2057. 'QueryString' => '$expand=Address2',
  2058. 'DataServiceVersion' => new Version(2, 0),
  2059. 'MaxDataServiceVersion' => new Version(2, 0));
  2060. $host = new DataServiceHost2($hostInfo);
  2061. $dataService = new NorthWindDataService2();
  2062. $dataService->setHost($host);
  2063. $exceptionThrown = false;
  2064. try {
  2065. $dataService->handleRequest();
  2066. } catch (ODataException $odataException) {
  2067. $exceptionThrown = true;
  2068. $this->assertStringStartsWith('Query option $expand cannot be applied to the requested resource', $odataException->getMessage());
  2069. }
  2070. if (!$exceptionThrown) {
  2071. $this->fail('An expected ODataException for $expand on non resource set or resource set refernce has not been thrown');
  2072. }
  2073. $host->getWebOperationContext()->resetWebContextInternal();
  2074. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  2075. $resourcePath = 'Orders(123)/Customer/Address';
  2076. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  2077. 'AbsoluteServiceUri' => new Url($baseUri),
  2078. 'QueryString' => '$select=LineNumber',
  2079. 'DataServiceVersion' => new Version(2, 0),
  2080. 'MaxDataServiceVersion' => new Version(2, 0));
  2081. $host = new DataServiceHost2($hostInfo);
  2082. $dataService = new NorthWindDataService2();
  2083. $dataService->setHost($host);
  2084. $exceptionThrown = false;
  2085. try {
  2086. $dataService->handleRequest();
  2087. } catch (ODataException $odataException) {
  2088. $exceptionThrown = true;
  2089. $this->assertStringStartsWith('Query option $select cannot be applied to the requested resource', $odataException->getMessage());
  2090. }
  2091. if (!$exceptionThrown) {
  2092. $this->fail('An expected ODataException for $select on non resource set or resource set refernce has not been thrown');
  2093. }
  2094. $host->getWebOperationContext()->resetWebContextInternal();
  2095. } catch (\Exception $exception) {
  2096. if ($host != null) {
  2097. $host->getWebOperationContext()->resetWebContextInternal();
  2098. }
  2099. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  2100. }
  2101. }
  2102. /**
  2103. * Test uri prcoessor for $skip and $top options
  2104. */
  2105. public function testUriPrcoessorForSkipAndTop()
  2106. {
  2107. try {
  2108. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  2109. $resourcePath = 'Orders';
  2110. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  2111. 'AbsoluteServiceUri' => new Url($baseUri),
  2112. 'QueryString' => '$top=\'ABC\'',
  2113. 'DataServiceVersion' => new Version(2, 0),
  2114. 'MaxDataServiceVersion' => new Version(2, 0));
  2115. $host = new DataServiceHost2($hostInfo);
  2116. $dataService = new NorthWindDataService2();
  2117. $dataService->setHost($host);
  2118. $exceptionThrown = false;
  2119. try {
  2120. $dataService->handleRequest();
  2121. } catch (ODataException $odataException) {
  2122. $exceptionThrown = true;
  2123. $this->assertStringStartsWith("Incorrect format for \$top", $odataException->getMessage());
  2124. }
  2125. if (!$exceptionThrown) {
  2126. $this->fail('An expected ODataException for incorrect $top value has not been thrown');
  2127. }
  2128. $host->getWebOperationContext()->resetWebContextInternal();
  2129. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  2130. $resourcePath = 'Orders';
  2131. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  2132. 'AbsoluteServiceUri' => new Url($baseUri),
  2133. 'QueryString' => '$top=-123',
  2134. 'DataServiceVersion' => new Version(2, 0),
  2135. 'MaxDataServiceVersion' => new Version(2, 0));
  2136. $host = new DataServiceHost2($hostInfo);
  2137. $dataService = new NorthWindDataService2();
  2138. $dataService->setHost($host);
  2139. $exceptionThrown = false;
  2140. try {
  2141. $dataService->handleRequest();
  2142. } catch (ODataException $odataException) {
  2143. $exceptionThrown = true;
  2144. $this->assertStringStartsWith('Incorrect format for $top', $odataException->getMessage());
  2145. }
  2146. if (!$exceptionThrown) {
  2147. $this->fail('An expected ODataException for incorrect $top value has not been thrown');
  2148. }
  2149. $host->getWebOperationContext()->resetWebContextInternal();
  2150. } catch (\Exception $exception) {
  2151. if ($host != null) {
  2152. $host->getWebOperationContext()->resetWebContextInternal();
  2153. }
  2154. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  2155. }
  2156. try {
  2157. $host->getWebOperationContext()->resetWebContextInternal();
  2158. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  2159. $resourcePath = 'Orders';
  2160. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  2161. 'AbsoluteServiceUri' => new Url($baseUri),
  2162. 'QueryString' => '$skip=\'ABC\'',
  2163. 'DataServiceVersion' => new Version(2, 0),
  2164. 'MaxDataServiceVersion' => new Version(2, 0));
  2165. $host = new DataServiceHost2($hostInfo);
  2166. $dataService = new NorthWindDataService2();
  2167. $dataService->setHost($host);
  2168. $exceptionThrown = false;
  2169. try {
  2170. $dataService->handleRequest();
  2171. } catch (ODataException $odataException) {
  2172. $exceptionThrown = true;
  2173. $this->assertStringStartsWith("Incorrect format for \$skip", $odataException->getMessage());
  2174. }
  2175. if (!$exceptionThrown) {
  2176. $this->fail('An expected ODataException for incorrect $skip value has not been thrown');
  2177. }
  2178. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  2179. $resourcePath = 'Orders';
  2180. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  2181. 'AbsoluteServiceUri' => new Url($baseUri),
  2182. 'QueryString' => '$skip=-123',
  2183. 'DataServiceVersion' => new Version(2, 0),
  2184. 'MaxDataServiceVersion' => new Version(2, 0));
  2185. $host = new DataServiceHost2($hostInfo);
  2186. $dataService = new NorthWindDataService2();
  2187. $dataService->setHost($host);
  2188. $exceptionThrown = false;
  2189. try {
  2190. $dataService->handleRequest();
  2191. } catch (ODataException $odataException) {
  2192. $exceptionThrown = true;
  2193. $this->assertStringStartsWith('Incorrect format for $skip', $odataException->getMessage());
  2194. }
  2195. if (!$exceptionThrown) {
  2196. $this->fail('An expected ODataException for incorrect $skip value has not been thrown');
  2197. }
  2198. $host->getWebOperationContext()->resetWebContextInternal();
  2199. } catch (\Exception $exception) {
  2200. if ($host != null) {
  2201. $host->getWebOperationContext()->resetWebContextInternal();
  2202. }
  2203. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  2204. }
  2205. }
  2206. /**
  2207. * Test uri processor with all options
  2208. */
  2209. public function testUriProcessorWithBigQuery()
  2210. {
  2211. try {
  2212. $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
  2213. $resourcePath = 'Orders(123)/Customer/Orders';
  2214. $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
  2215. 'AbsoluteServiceUri' => new Url($baseUri),
  2216. 'QueryString' => '$expand=Customer&$select=Customer,OrderDate&$filter=OrderID eq 123&$orderby=OrderDate&top=6&$skip=10&$skiptoken=datetime\'2000-11-11\',567',
  2217. 'DataServiceVersion' => new Version(2, 0),
  2218. 'MaxDataServiceVersion' => new Version(2, 0));
  2219. $host = new DataServiceHost2($hostInfo);
  2220. $dataService = new NorthWindDataService2();
  2221. $dataService->setHost($host);
  2222. $uriProcessor = $dataService->handleRequest();
  2223. $requestDescription = $uriProcessor->getRequestDescription();
  2224. $this->assertEquals($requestDescription->getTopCount(), 5);
  2225. $this->assertEquals($requestDescription->getSkipCount(), 10);
  2226. $this->assertTrue(!is_null($requestDescription->getInternalOrderByInfo()));
  2227. $this->assertTrue(!is_null($requestDescription->getInternalFilterInfo()));
  2228. $this->assertTrue(!is_null($requestDescription->getInternalSkipTokenInfo()));
  2229. $this->assertTrue(!is_null($requestDescription->getRootProjectionNode()));
  2230. $host->getWebOperationContext()->resetWebContextInternal();
  2231. } catch (\Exception $exception) {
  2232. if ($host != null) {
  2233. $host->getWebOperationContext()->resetWebContextInternal();
  2234. }
  2235. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  2236. }
  2237. }
  2238. /**
  2239. * test Request Description with all geter method.
  2240. */
  2241. public function testRequestDescription()
  2242. {
  2243. try {
  2244. $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Orders'),
  2245. 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
  2246. 'QueryString' => null,
  2247. 'DataServiceVersion' => new Version(1, 0),
  2248. 'MaxDataServiceVersion' => new Version(2, 0));
  2249. $host = new DataServiceHost2($hostInfo);
  2250. $dataService = new NorthWindDataService2();
  2251. $dataService->setHost($host);
  2252. $uriProcessor = $dataService->handleRequest();
  2253. $requestDescription = $uriProcessor->getRequestDescription();
  2254. $this->assertTrue(!is_null($requestDescription));
  2255. $countValue = $requestDescription->getCountValue();
  2256. $this->assertTrue(is_null($countValue));
  2257. $identifier = $requestDescription->getIdentifier();
  2258. $this->assertTrue(!is_null($identifier));
  2259. $internalFilterInfo = $requestDescription->getInternalFilterInfo();
  2260. $this->assertTrue(is_null($internalFilterInfo));
  2261. $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
  2262. $this->assertTrue(!is_null($internalOrderByInfo));
  2263. $internalSkipTokenInfo = $requestDescription->getInternalSkipTokenInfo();
  2264. $this->assertTrue(is_null($internalSkipTokenInfo));
  2265. $knownDataServiceVersions = $requestDescription->getKnownDataServiceVersions();
  2266. $this->assertTrue(!is_null($knownDataServiceVersions));
  2267. $lastSegmentDescriptor = $requestDescription->getLastSegmentDescriptor();
  2268. $this->assertTrue(!is_null($lastSegmentDescriptor));
  2269. $projectedProperty = $requestDescription->getProjectedProperty();
  2270. $this->assertTrue(is_null($projectedProperty));
  2271. $requestCountOption = $requestDescription->getRequestCountOption();
  2272. $this->assertTrue(!is_null($requestCountOption));
  2273. $requestUri = $requestDescription->getRequestUri();
  2274. $this->assertTrue(!is_null($requestUri));
  2275. $resourceStreamInfo = $requestDescription->getResourceStreamInfo();
  2276. $this->assertTrue(is_null($resourceStreamInfo));
  2277. $rootProjectionNode = $requestDescription->getRootProjectionNode();
  2278. $this->assertTrue(!is_null($rootProjectionNode));
  2279. $segmentDescriptors = $requestDescription->getSegmentDescriptors();
  2280. $this->assertTrue(!is_null($segmentDescriptors));
  2281. $skipCount = $requestDescription->getSkipCount();
  2282. $this->assertTrue(is_null($skipCount));
  2283. $targetKind = $requestDescription->getTargetKind();
  2284. $this->assertTrue(!is_null($targetKind));
  2285. $targetResourceSetWrapper = $requestDescription->getTargetResourceSetWrapper();
  2286. $this->assertTrue(!is_null($targetResourceSetWrapper));
  2287. $targetResourceType = $requestDescription->getTargetResourceType();
  2288. $this->assertTrue(!is_null($targetResourceType));
  2289. $targetSource = $requestDescription->getTargetSource();
  2290. $this->assertTrue(!is_null($targetSource));
  2291. $topCount = $requestDescription->getTopCount();
  2292. $this->assertTrue(!is_null($topCount));
  2293. $host->getWebOperationContext()->resetWebContextInternal();
  2294. } catch (\Exception $exception) {
  2295. $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  2296. }
  2297. }
  2298. protected function tearDown()
  2299. {
  2300. }
  2301. }
  2302. ?>