/OData Producer for PHP/Tests/UriProcessor/UriProcessorTest.php
PHP | 2461 lines | 1975 code | 149 blank | 337 comment | 134 complexity | 5840980579cbdb4b484766a33ca79aa8 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * Mainly test UriProcessor, but also do some partial test for DataService class.
- */
- use ODataProducer\UriProcessor\QueryProcessor\ExpandProjectionParser\ProjectionNode;
- use ODataProducer\UriProcessor\QueryProcessor\ExpandProjectionParser\ExpandedProjectionNode;
- use ODataProducer\UriProcessor\QueryProcessor\ExpandProjectionParser\RootProjectionNode;
- use ODataProducer\UriProcessor\QueryProcessor\AnonymousFunction;
- use ODataProducer\UriProcessor\QueryProcessor\OrderByParser\OrderBySubPathSegment;
- use ODataProducer\UriProcessor\QueryProcessor\OrderByParser\OrderByPathSegment;
- use ODataProducer\UriProcessor\QueryProcessor\SkipTokenParser\InternalSkipTokenInfo;
- use ODataProducer\UriProcessor\QueryProcessor\SkipTokenParser\SkipTokenInfo;
- use ODataProducer\UriProcessor\QueryProcessor\ExpressionParser\InternalFilterInfo;
- use ODataProducer\UriProcessor\QueryProcessor\OrderByParser\InternalOrderByInfo;
- use ODataProducer\UriProcessor\RequestCountOption;
- use ODataProducer\Configuration\DataServiceProtocolVersion;
- use ODataProducer\UriProcessor\ResourcePathProcessor\SegmentParser\RequestTargetKind;
- use ODataProducer\UriProcessor\ResourcePathProcessor\SegmentParser\RequestTargetSource;
- use ODataProducer\Providers\Metadata\Type\Int32;
- use ODataProducer\Providers\Metadata\Type\DateTime;
- use ODataProducer\Common\Url;
- use ODataProducer\Common\Version;
- use ODataProducer\Common\ODataException;
- require_once 'PHPUnit\Framework\Assert.php';
- require_once 'PHPUnit\Framework\Test.php';
- require_once 'PHPUnit\Framework\SelfDescribing.php';
- require_once 'PHPUnit\Framework\TestCase.php';
- require_once 'PHPUnit\Framework\TestSuite.php';
- require_once 'ODataProducer\Common\ClassAutoLoader.php';
- require_once (dirname(__FILE__) . "\.\..\Resources\NorthWindMetadata.php");
- require_once (dirname(__FILE__) . "\.\..\Resources\NorthWindDataServiceV1.php");
- require_once (dirname(__FILE__) . "\.\..\Resources\NorthWindDataService.php");
- require_once (dirname(__FILE__) . "\.\..\Resources\NorthWindDataServiceV3.php");
- require_once (dirname(__FILE__) . "\.\..\Resources\DataServiceHost2.php");
- ODataProducer\Common\ClassAutoLoader::register();
- class TestUriProcessor extends PHPUnit_Framework_TestCase
- {
- protected function setUp()
- {
- }
-
- /**
- * The request uri should be based on the service uri specified in the configuration.
- */
- /**public function testRequestUriWithInvalidBaseUri()
- {
- try {
- $hostInfo = array('AbsoluteRequestUri' =>
- new Url('http://localhost:8083/NorthWindDataService.svc'),
- 'AbsoluteServiceUri' =>
- new Url('http://localhost:8083/XX/NorthWindDataService.svc'),
- 'QueryString' =>
- null);
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $exceptionThrown = false;
- try {
- $dataService->handleRequest();
- } catch (ODataException $odataException) {
- $exceptionThrown = true;
- $this->assertStringStartsWith("The URI 'http://localhost:8083/NorthWindDataService.svc' is not ", $odataException->getMessage());
- }
-
- if (!$exceptionThrown) {
- $this->fail('An expected ODataException for invalid base uri in the request uri has not been thrown');
- }
-
- } catch (\Exception $exception) {
- $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
- }
-
-
- }**/
-
- /**
- * Test with request uri where RequestTargetKind is NONE. RequestTargetKind will be
- * NONE for service directory, metadata and batch.
- */
- public function testUriProcessorWithRequestUriOfNoneTargetSourceKind()
- {
- try {
- //Request for service directory
- $hostInfo = array('AbsoluteRequestUri' =>
- new Url('http://localhost:8083/NorthWindDataService.svc'),
- 'AbsoluteServiceUri' =>
- new Url('http://localhost:8083/NorthWindDataService.svc'),
- 'QueryString' =>
- null);
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $exceptionThrown = false;
- $uriProcessor = $dataService->handleRequest();
- $requestDescripton = $uriProcessor->getRequestDescription();
- $this->assertEquals($requestDescripton->getTargetSource(), RequestTargetSource::NONE);
- $this->assertEquals($requestDescripton->getTargetKind(), RequestTargetKind::SERVICE_DIRECTORY);
- // Context is a singleton class reset it
- $host->getWebOperationContext()->resetWebContextInternal();
-
- //Request for metadata
- $hostInfo = array('AbsoluteRequestUri' =>
- new Url('http://localhost:8083/NorthWindDataService.svc/$metadata'),
- 'AbsoluteServiceUri' =>
- new Url('http://localhost:8083/NorthWindDataService.svc'),
- 'QueryString' =>
- null);
-
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $exceptionThrown = false;
- $requestDescripton = $uriProcessor = null;
- $uriProcessor = $dataService->handleRequest();
- $requestDescripton = $uriProcessor->getRequestDescription();
- $this->assertEquals($requestDescripton->getTargetSource(), RequestTargetSource::NONE);
- $this->assertEquals($requestDescripton->getTargetKind(), RequestTargetKind::METADATA);
- // Context is a singleton class reset it
- $host->getWebOperationContext()->resetWebContextInternal();
-
- //Request for batch
- $hostInfo = array('AbsoluteRequestUri' =>
- new Url('http://localhost:8083/NorthWindDataService.svc/$batch'),
- 'AbsoluteServiceUri' =>
- new Url('http://localhost:8083/NorthWindDataService.svc'),
- 'QueryString' =>
- null);
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $exceptionThrown = false;
- $uriProcessor = $dataService->handleRequest();
- $requestDescripton = $uriProcessor->getRequestDescription();
- $this->assertEquals($requestDescripton->getTargetSource(), RequestTargetSource::NONE);
- $this->assertEquals($requestDescripton->getTargetKind(), RequestTargetKind::BATCH);
- // Context is a singleton class reset it
- $host->getWebOperationContext()->resetWebContextInternal();
- } catch (\Exception $exception) {
- if ($host != null) {
- $host->getWebOperationContext()->resetWebContextInternal();
- }
- $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
- }
- }
-
- /**
- * Test request uri for row count ($count)
- * DataServiceVersion and MaxDataServiceVersion should be >= 2.0 for $count
- */
- public function testUriProcessorForCountRequest1()
- {
- try {
- //Test $count with DataServiceVersion < 2.0
- $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
- 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
- 'QueryString' => null,
- 'DataServiceVersion' => new Version(1, 0),
- 'MaxDataServiceVersion' => new Version(2, 0));
-
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $exceptionThrown = false;
- try {
- $uriProcessor = $dataService->handleRequest();
- } catch (ODataException $odataException) {
- $exceptionThrown = true;
- $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0", $odataException->getMessage());
- }
-
- if (!$exceptionThrown) {
- $this->fail('An expected ODataException for failure of capability negoitation over DataServiceVersion has not been thrown');
- }
-
- // Context is a singleton class reset it
- $host->getWebOperationContext()->resetWebContextInternal();
- //Test $count with MaxDataServiceVersion < 2.0
- $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
- 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
- 'QueryString' => null,
- 'DataServiceVersion' => new Version(2, 0),
- 'MaxDataServiceVersion' => new Version(1, 0));
-
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $exceptionThrown = false;
- try {
- $uriProcessor = $dataService->handleRequest();
- } catch (ODataException $odataException) {
- $exceptionThrown = true;
- $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0", $odataException->getMessage());
- }
-
- if (!$exceptionThrown) {
- $this->fail('An expected ODataException for failure of capability negoitation over MaxDataServiceVersion has not been thrown');
- }
- $host->getWebOperationContext()->resetWebContextInternal();
- } catch (\Exception $exception) {
- if ($host != null) {
- $host->getWebOperationContext()->resetWebContextInternal();
- }
- $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
- }
- }
-
- /**
- * Test request uri for row count ($count)
- * $count is a version 2 feature so service devloper should use protocol version 2.0
- */
- public function testUriProcessorForCountRequest2()
- {
- try {
- $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
- 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
- 'QueryString' => null,
- 'DataServiceVersion' => new Version(2, 0),
- 'MaxDataServiceVersion' => new Version(2, 0));
-
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataServiceV1();
- $dataService->setHost($host);
- $exceptionThrown = false;
- try {
- $uriProcessor = $dataService->handleRequest();
- } catch (ODataException $odataException) {
- $exceptionThrown = true;
- $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());
- }
-
- if (!$exceptionThrown) {
- $this->fail('An expected ODataException for failure of capability negoitation due to V1 configuration has not been thrown');
- }
- $host->getWebOperationContext()->resetWebContextInternal();
- } catch (\Exception $exception) {
- if ($host != null) {
- $host->getWebOperationContext()->resetWebContextInternal();
- }
- $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
- }
- }
-
- /**
- * Test request uri for row count ($count)
- *
- * Suppose $top option is absent, still
- * RequestDescription::topCount will be set if the resource targetted by the
- * uri has paging enabled, if RequestDescription::topCount
- * is set then internal orderby info will be generated. But if the request
- * is for raw count for a resource collection then paging is not applicable
- * for that, so topCount will be null and internal orderby info will not be
- * generated.
- */
- public function testUriProcessorForCountRequest3()
- {
- try {
- $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
- 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
- 'QueryString' => null,
- 'DataServiceVersion' => new Version(2, 0),
- 'MaxDataServiceVersion' => new Version(2, 0));
-
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $exceptionThrown = false;
- $uriProcessor = $dataService->handleRequest();
- $requestDescription = $uriProcessor->getRequestDescription();
- $this->assertTrue(!is_null($requestDescription));
- $this->assertTrue(is_null($requestDescription->getInternalOrderByInfo()));
- $host->getWebOperationContext()->resetWebContextInternal();
-
- } catch (\Exception $exception) {
- if ($host != null) {
- $host->getWebOperationContext()->resetWebContextInternal();
- }
- $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
- }
- }
-
- /**
- * Test request uri for row count ($count)
- *
- * $orderby option can be applied to a $count request.
- */
- public function testUriProcessorForCountRequest4()
- {
- try {
- $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
- 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
- 'QueryString' => '$orderby=Country',
- 'DataServiceVersion' => new Version(2, 0),
- 'MaxDataServiceVersion' => new Version(2, 0));
-
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $exceptionThrown = false;
- $uriProcessor = $dataService->handleRequest();
- $requestDescription = $uriProcessor->getRequestDescription();
- $this->assertTrue(!is_null($requestDescription));
- $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
- $this->assertTrue(!is_null($internalOrderByInfo));
- $object = $internalOrderByInfo->getDummyObject();
- $this->assertTrue(!is_null($object));
- $this->assertTrue($object instanceof Customer2);
- $host->getWebOperationContext()->resetWebContextInternal();
-
- } catch (\Exception $exception) {
- if ($host != null) {
- $host->getWebOperationContext()->resetWebContextInternal();
- }
- $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
- }
- }
-
- /**
- * Test request uri for row count ($count)
- *
- * $skip and $top options can be applied to $count request, this cause
- * processor to generate internalorderinfo.
- */
- public function testUriProcessorForCountRequest5()
- {
- try {
- $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
- 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
- 'QueryString' => '$skip=2&$top=4',
- 'DataServiceVersion' => new Version(2, 0),
- 'MaxDataServiceVersion' => new Version(2, 0));
-
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $exceptionThrown = false;
- $uriProcessor = $dataService->handleRequest();
- $requestDescription = $uriProcessor->getRequestDescription();
- $this->assertTrue(!is_null($requestDescription));
- $this->assertEquals($requestDescription->getTopCount(), 4);
- $this->assertEquals($requestDescription->getSkipCount(), 2);
- $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
- $this->assertTrue(!is_null($internalOrderByInfo));
- $object = $internalOrderByInfo->getDummyObject();
- $this->assertTrue(!is_null($object));
- $this->assertTrue($object instanceof Customer2);
- $host->getWebOperationContext()->resetWebContextInternal();
- } catch (\Exception $exception) {
- if ($host != null) {
- $host->getWebOperationContext()->resetWebContextInternal();
- }
- $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
- }
- }
-
- /**
- * Test request uri for row count ($count)
- *
- * $skip and/or $top options along with $orderby option cause internalOrderInfo
- * to include sorter functions using keys + paths in the $orderby clause
- */
- public function testUriProcessorForCountRequest6()
- {
- try {
- $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
- 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
- 'QueryString' => '$skip=2&$top=4&$orderby=Country',
- 'DataServiceVersion' => new Version(2, 0),
- 'MaxDataServiceVersion' => new Version(2, 0));
-
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $exceptionThrown = false;
- $uriProcessor = $dataService->handleRequest();
- $requestDescription = $uriProcessor->getRequestDescription();
- $this->assertTrue(!is_null($requestDescription));
- $this->assertEquals($requestDescription->getTopCount(), 4);
- $this->assertEquals($requestDescription->getSkipCount(), 2);
- $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
- $this->assertTrue(!is_null($internalOrderByInfo));
- $object = $internalOrderByInfo->getDummyObject();
- $this->assertTrue(!is_null($object));
- $this->assertTrue($object instanceof Customer2);
- $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
- $this->assertTrue(!is_null($pathSegments));
- $this->assertTrue(is_array($pathSegments));
- $this->assertEquals(count($pathSegments), 3);
- $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
- $subPathSegments = $pathSegments[0]->getSubPathSegments();
- $this->assertTrue(!is_null($subPathSegments));
- $this->assertTrue(is_array($subPathSegments));
- $this->assertEquals(count($subPathSegments), 1);
- $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
- $this->assertEquals($subPathSegments[0]->getName(), 'Country');
-
- $this->assertTrue($pathSegments[1] instanceof OrderByPathSegment);
- $subPathSegments = $pathSegments[1]->getSubPathSegments();
- $this->assertTrue(!is_null($subPathSegments));
- $this->assertTrue(is_array($subPathSegments));
- $this->assertEquals(count($subPathSegments), 1);
- $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
- $this->assertEquals($subPathSegments[0]->getName(), 'CustomerID');
-
- $this->assertTrue($pathSegments[2] instanceof OrderByPathSegment);
- $subPathSegments = $pathSegments[2]->getSubPathSegments();
- $this->assertTrue(!is_null($subPathSegments));
- $this->assertTrue(is_array($subPathSegments));
- $this->assertEquals(count($subPathSegments), 1);
- $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
- $this->assertEquals($subPathSegments[0]->getName(), 'CustomerGuid');
- $host->getWebOperationContext()->resetWebContextInternal();
- } catch (\Exception $exception) {
- if ($host != null) {
- $host->getWebOperationContext()->resetWebContextInternal();
- }
- $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
- }
- }
-
- /**
- * Test request uri for row count ($count)
- * $skiptoken is not applicable for $count request, as it requires
- * paging and paging is not applicable for $count request
- */
- public function testUriProcessorForCountRequest7()
- {
- try {
- $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
- 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
- 'QueryString' => '$top=1&$skiptoken=\'ALFKI\',guid\'05b242e752eb46bd8f0e6568b72cd9a5\'',
- 'DataServiceVersion' => new Version(2, 0),
- 'MaxDataServiceVersion' => new Version(2, 0));
-
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $exceptionThrown = false;
- try {
- $uriProcessor = $dataService->handleRequest();
- } catch (ODataException $odataException) {
- $exceptionThrown = true;
- $this->assertStringStartsWith("Query option \$skiptoken cannot be applied to the requested resource", $odataException->getMessage());
- }
-
- if (!$exceptionThrown) {
- $this->fail('An expected ODataException for applying $skiptoken on $count has not been thrown');
- }
-
- $host->getWebOperationContext()->resetWebContextInternal();
- } catch (\Exception $exception) {
- if ($host != null) {
- $host->getWebOperationContext()->resetWebContextInternal();
- }
- $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
- }
- }
-
- /**
- * Test request uri for row count ($count)
- *
- * $filter is applicable for $count segment.
- */
- public function testUriProcessorForCountRequest8()
- {
- try {
- $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
- 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
- 'QueryString' => '$filter=Country eq \'USA\'',
- 'DataServiceVersion' => new Version(2, 0),
- 'MaxDataServiceVersion' => new Version(2, 0));
-
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $uriProcessor = $dataService->handleRequest();
- $requestDescription = $uriProcessor->getRequestDescription();
- $this->assertTrue(!is_null($requestDescription));
- $internalFilterInfo = $requestDescription->getInternalFilterInfo();
- $this->assertTrue(!is_null($internalFilterInfo));
- $filterInfo = $internalFilterInfo->getFilterInfo();
- $this->assertTrue(!is_null($filterInfo));
- $this->assertTrue(is_null($filterInfo->getNavigationPropertiesUsed()));
- $filterFunction = $internalFilterInfo->getFilterFunction();
- $this->assertTrue(!is_null($filterFunction));
- $this->assertTrue($filterFunction instanceof AnonymousFunction);
- $host->getWebOperationContext()->resetWebContextInternal();
- } catch (\Exception $exception) {
- if ($host != null) {
- $host->getWebOperationContext()->resetWebContextInternal();
- }
- $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
- }
- }
-
- /**
- * Test request uri for row count ($count)
- *
- * $select and $expand options are applicable for $count segment.
- * but when we do query execution we will ignore them.
- */
- public function testUriProcessorForCountRequest9()
- {
- try {
- $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
- 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
- 'QueryString' => '$select=Country&$expand=Orders',
- 'DataServiceVersion' => new Version(2, 0),
- 'MaxDataServiceVersion' => new Version(2, 0));
-
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $uriProcessor = $dataService->handleRequest();
- $requestDescription = $uriProcessor->getRequestDescription();
- $this->assertTrue(!is_null($requestDescription));
- $projectionTreeRoot = $requestDescription->getRootProjectionNode();
- $this->assertTrue(!is_null($projectionTreeRoot));
- $this->assertTrue($projectionTreeRoot instanceof RootProjectionNode);
- //There will be one child node for 'Country', 'Orders' wont be included
- //as its not selected
- $childNodes = $projectionTreeRoot->getChildNodes();
- $this->assertTrue(!is_null($childNodes));
- $this->assertTrue(is_array($childNodes));
- $this->assertEquals(count($childNodes), 1);
- $this->assertTrue(array_key_exists('Country', $childNodes));
- $this->assertTrue($childNodes['Country'] instanceof ProjectionNode);
- $host->getWebOperationContext()->resetWebContextInternal();
- } catch (\Exception $exception) {
- if ($host != null) {
- $host->getWebOperationContext()->resetWebContextInternal();
- }
- $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
- }
- }
-
- /**
- * Test request uri for row count ($count)
- * $count with $inlinecount not allowed
- */
- public function testUriProcessorForCountWithInline()
- {
- try {
- $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'),
- 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
- 'QueryString' => '$inlinecount=allpages',
- 'DataServiceVersion' => new Version(2, 0),
- 'MaxDataServiceVersion' => new Version(2, 0));
-
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $exceptionThrown = false;
- try {
- $uriProcessor = $dataService->handleRequest();
- } catch (ODataException $odataException) {
- $exceptionThrown = true;
- $this->assertStringStartsWith("\$inlinecount cannot be applied to the resource segment \$count", $odataException->getMessage());
- }
-
- if (!$exceptionThrown) {
- $this->fail('An expected ODataException for applying $skiptoken on $count has not been thrown');
- }
- $host->getWebOperationContext()->resetWebContextInternal();
- } catch (\Exception $exception) {
- if ($host != null) {
- $host->getWebOperationContext()->resetWebContextInternal();
- }
- $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
- }
- }
-
- /**
- * If paging is enabled for a resource set, then the uri
- * processor should generate orderinfo irrespective of
- * whether $top or $orderby is specified or not.
- *
- * Request DataServiceVersion => 1.0
- * Request MaxDataServiceVersion => 2.0
- */
- public function testUriProcessorForResourcePageInfo1()
- {
- try {
- //Test for generation of orderinfo for resource set
- //with request DataServiceVersion 1.0
- $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers'),
- 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
- 'QueryString' => null,
- 'DataServiceVersion' => new Version(1, 0),
- 'MaxDataServiceVersion' => new Version(2, 0));
-
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $uriProcessor = $dataService->handleRequest();
- $requestDescription = $uriProcessor->getRequestDescription();
- $this->assertTrue(!is_null($requestDescription));
- //Page size is 5, so take count is 5
- $this->assertEquals($requestDescription->getTopCount(), 5);
-
- //order info is required for pagination
- $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
- $this->assertTrue(!is_null($internalOrderByInfo));
- $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
- $this->assertTrue(!is_null($pathSegments));
- $this->assertTrue(is_array($pathSegments));
- //Customer has two keys
- $this->assertEquals(count($pathSegments), 2);
- $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
- $subPathSegments = $pathSegments[0]->getSubPathSegments();
- $this->assertTrue(!is_null($subPathSegments));
- $this->assertTrue(is_array($subPathSegments));
- $this->assertEquals(count($subPathSegments), 1);
- $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
- $this->assertEquals($subPathSegments[0]->getName(), 'CustomerID');
-
- $this->assertTrue($pathSegments[1] instanceof OrderByPathSegment);
- $subPathSegments = $pathSegments[1]->getSubPathSegments();
- $this->assertTrue(!is_null($subPathSegments));
- $this->assertTrue(is_array($subPathSegments));
- $this->assertEquals(count($subPathSegments), 1);
- $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
- $this->assertEquals($subPathSegments[0]->getName(), 'CustomerGuid');
- $host->getWebOperationContext()->resetWebContextInternal();
- } catch (\Exception $exception) {
- if ($host != null) {
- $host->getWebOperationContext()->resetWebContextInternal();
- }
- $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
- }
- }
-
- /**
- * If paging is enabled for a resource set, then the uri
- * processor should generate orderinfo irrespective of
- * whether $top or $orderby is specified or not.
- *
- * Request DataServiceVersion => 1.0
- * Request MaxDataServiceVersion => 1.0
- *
- * This will fail as paging requires version 2.0 or above
- */
- public function testUriProcessorForResourcePageInfo2()
- {
- try {
- //Test for generation of orderinfo for resource set
- //with request DataServiceVersion 1.0
- $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers'),
- 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
- 'QueryString' => null,
- 'DataServiceVersion' => new Version(1, 0),
- 'MaxDataServiceVersion' => new Version(1, 0));
-
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $exceptionThrown = false;
- try {
- $uriProcessor = $dataService->handleRequest();
- } catch (ODataException $odataException) {
- $exceptionThrown = true;
- $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0'", $odataException->getMessage());
- }
-
- if (!$exceptionThrown) {
- $this->fail('An expected ODataException due to capability negotiation has not been thrown (paged result but client\'s max supportedd version is 1.0)');
- }
- $host->getWebOperationContext()->resetWebContextInternal();
- } catch (\Exception $exception) {
- if ($host != null) {
- $host->getWebOperationContext()->resetWebContextInternal();
- }
- $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
- }
- }
-
- /**
- * Paging is enabled only for resource set, so with resource set
- * reference there will not be any paginginfo.
- */
- public function testUriProcessorForResourcePageInfo3()
- {
- try {
- //Test for generation of orderinfo for resource set
- //with request DataServiceVersion 1.0
- $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Orders(123)'),
- 'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
- 'QueryString' => null,
- 'DataServiceVersion' => new Version(1, 0),
- 'MaxDataServiceVersion' => new Version(2, 0));
-
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $uriProcessor = $dataService->handleRequest();
- $requestDescription = $uriProcessor->getRequestDescription();
- $this->assertTrue(!is_null($requestDescription));
- //Page is not appliable for single resouce
- $this->assertEquals($requestDescription->getTopCount(), null);
- //order info wont be generated as resource is not applicable for pagination
- $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
- $this->assertTrue(is_null($internalOrderByInfo));
- $host->getWebOperationContext()->resetWebContextInternal();
- } catch (\Exception $exception) {
- if ($host != null) {
- $host->getWebOperationContext()->resetWebContextInternal();
- }
- $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
- }
- }
-
- /**
- * If paging is enabled for a resource set, then $link request for that resource set
- * will also paged
- * e.g. http://host/service.svc/Customers('A')/$links/Orders
- * here if paging is enabled for Orders then prcoessor must generate orderbyinfo for
- * this.
- */
- public function testUriProcessorForResourcePageInfo4()
- {
- try {
- //Test for generation of orderinfo for resource set in $links query
- $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
- $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
- $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
- 'AbsoluteServiceUri' => new Url($baseUri),
- 'QueryString' => null,
- 'DataServiceVersion' => new Version(1, 0),
- 'MaxDataServiceVersion' => new Version(2, 0));
-
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $uriProcessor = $dataService->handleRequest();
- $requestDescription = $uriProcessor->getRequestDescription();
- $this->assertTrue(!is_null($requestDescription));
- //Page size is 5, so take count is 5
- $this->assertEquals($requestDescription->getTopCount(), 5);
- //order info is required for pagination
- $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
- $this->assertTrue(!is_null($internalOrderByInfo));
- $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
- $this->assertTrue(!is_null($pathSegments));
- $this->assertTrue(is_array($pathSegments));
- //Order has one key
- $this->assertEquals(count($pathSegments), 1);
- $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
- $subPathSegments = $pathSegments[0]->getSubPathSegments();
- $this->assertTrue(!is_null($subPathSegments));
- $this->assertTrue(is_array($subPathSegments));
- $this->assertEquals(count($subPathSegments), 1);
- $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
- $this->assertEquals($subPathSegments[0]->getName(), 'OrderID');
- $host->getWebOperationContext()->resetWebContextInternal();
- } catch (\Exception $exception) {
- if ($host != null) {
- $host->getWebOperationContext()->resetWebContextInternal();
- }
- $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
- }
- }
-
- /**
- * $orderby option can be applied to $links resource set
- */
- public function testUriProcessorForLinksResourceSet1()
- {
- try {
- $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
- $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
- $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
- 'AbsoluteServiceUri' => new Url($baseUri),
- 'QueryString' => '$orderby=ShipName asc, OrderDate desc',
- 'DataServiceVersion' => new Version(2, 0),
- 'MaxDataServiceVersion' => new Version(2, 0));
-
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $uriProcessor = $dataService->handleRequest();
- $requestDescription = $uriProcessor->getRequestDescription();
- $this->assertTrue(!is_null($requestDescription));
- $this->assertEquals($requestDescription->isSingleResult(), false);
- //Page size is 5, so take count is 5 means you will get only 5 links for a request
- $this->assertEquals($requestDescription->getTopCount(), 5);
- //Paging requires ordering, the result should be ordered like
- //Note: additional ordering constraint
- //
- //SELECT links(d.orderID) FROM Customers JOIN Orders WHERE CustomerID='ALFKI' AND
- //CustomerGuid=guid'05b242e752eb46bd8f0e6568b72cd9a5' ORDER BY
- //d.ShipName ASC, d.OrderDate DESC, d.OrderID ASC
-
- $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
- $this->assertTrue(!is_null($internalOrderByInfo));
- $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
- $this->assertTrue(!is_null($pathSegments));
- $this->assertTrue(is_array($pathSegments));
- $this->assertEquals(count($pathSegments), 3);
- $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
- $subPathSegments = $pathSegments[0]->getSubPathSegments();
- $this->assertTrue($pathSegments[0]->isAscending());
- $this->assertTrue(!is_null($subPathSegments));
- $this->assertTrue(is_array($subPathSegments));
- $this->assertEquals(count($subPathSegments), 1);
- $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
- $this->assertEquals($subPathSegments[0]->getName(), 'ShipName');
- $this->assertTrue($pathSegments[1] instanceof OrderByPathSegment);
- $this->assertFalse($pathSegments[1]->isAscending());
- $subPathSegments = $pathSegments[1]->getSubPathSegments();
- $this->assertTrue(!is_null($subPathSegments));
- $this->assertTrue(is_array($subPathSegments));
- $this->assertEquals(count($subPathSegments), 1);
- $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
- $this->assertEquals($subPathSegments[0]->getName(), 'OrderDate');
- $this->assertTrue($pathSegments[2] instanceof OrderByPathSegment);
- $this->assertTrue($pathSegments[2]->isAscending());
- $subPathSegments = $pathSegments[2]->getSubPathSegments();
- $this->assertTrue(!is_null($subPathSegments));
- $this->assertTrue(is_array($subPathSegments));
- $this->assertEquals(count($subPathSegments), 1);
- $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
- $this->assertEquals($subPathSegments[0]->getName(), 'OrderID');
- $host->getWebOperationContext()->resetWebContextInternal();
- } catch (\Exception $exception) {
- if ($host != null) {
- $host->getWebOperationContext()->resetWebContextInternal();
- }
- $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
- }
- }
-
- /**
- * $skiptoken option can be applied to $links resource set
- */
- public function testUriProcessorForLinksResourceSet2()
- {
- try {
- //Test with skiptoken that corrosponds to default ordering key
- $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
- $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
- $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
- 'AbsoluteServiceUri' => new Url($baseUri),
- 'QueryString' => '$skiptoken=123',
- 'DataServiceVersion' => new Version(2, 0),
- 'MaxDataServiceVersion' => new Version(2, 0));
-
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $uriProcessor = $dataService->handleRequest();
- $requestDescription = $uriProcessor->getRequestDescription();
- $this->assertTrue(!is_null($requestDescription));
- $this->assertEquals($requestDescription->isSingleResult(), false);
- //Page size is 5, so take count is 5 means you will get only 5 links for a request
- $this->assertEquals($requestDescription->getTopCount(), 5);
- //paging requires ordering
- $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
- $this->assertTrue(!is_null($internalOrderByInfo));
- $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
- $this->assertTrue(!is_null($pathSegments));
- $this->assertTrue(is_array($pathSegments));
- $this->assertEquals(count($pathSegments), 1);
- $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
- $subPathSegments = $pathSegments[0]->getSubPathSegments();
- $this->assertTrue($pathSegments[0]->isAscending());
- $this->assertTrue(!is_null($subPathSegments));
- $this->assertTrue(is_array($subPathSegments));
- $this->assertEquals(count($subPathSegments), 1);
- $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
- $this->assertEquals($subPathSegments[0]->getName(), 'OrderID');
- //check the skiptoken details
- $internalSkiptokenInfo = $requestDescription->getInternalSkipTokenInfo();
- $this->assertTrue(!is_null($internalSkiptokenInfo));
- $this->assertTrue($internalSkiptokenInfo instanceof InternalSkipTokenInfo);
- $skipTokenInfo = $internalSkiptokenInfo->getSkipTokenInfo();
- $this->assertTrue(!is_null($skipTokenInfo));
- $this->assertTrue($skipTokenInfo instanceof SkipTokenInfo);
- $orderByValuesInSkipToken = $skipTokenInfo->getOrderByKeysInToken();
- $this->assertTrue(!is_null($orderByValuesInSkipToken));
- $this->assertTrue(is_array($orderByValuesInSkipToken));
- $this->assertEquals(count($orderByValuesInSkipToken), 1);
- $this->assertTrue(!is_null($orderByValuesInSkipToken[0]));
- $this->assertTrue(is_array($orderByValuesInSkipToken[0]));
- $this->assertEquals(count($orderByValuesInSkipToken[0]), 2);
- $this->assertEquals($orderByValuesInSkipToken[0][0], 123);
- $this->assertTrue(is_object($orderByValuesInSkipToken[0][1]));
- $this->assertTrue($orderByValuesInSkipToken[0][1] instanceof Int32);
- $host->getWebOperationContext()->resetWebContextInternal();
-
- //Test with skiptoken that corrosponds to explict ordering keys
- $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
- $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
- $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
- 'AbsoluteServiceUri' => new Url($baseUri),
- 'QueryString' => '$orderby=OrderID asc, OrderDate desc&$skiptoken=123, datetime\'2000-11-11\'',
- 'DataServiceVersion' => new Version(2, 0),
- 'MaxDataServiceVersion' => new Version(2, 0));
- $host = new DataServiceHost2($hostInfo);
- $dataService = new NorthWindDataService2();
- $dataService->setHost($host);
- $uriProcessor = $dataService->handleRequest();
- $requestDescription = $uriProcessor->getRequestDescription();
- $this->assertTrue(!is_null($requestDescription));
- $this->assertEquals($requestDescription->isSingleResult(), false);
- //Page size is 5, so take count is 5 means you will get only 5 links for a request
- $this->assertEquals($requestDescription->getTopCount(), 5);
- //paging requires ordering
- $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
- $this->assertTrue(!is_null($internalOrderByInfo));
- $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
- $this->assertTrue(!is_null($pathSegments));
- $this->assertTrue(is_array($pathSegments));
- $this->assertEquals(count($pathSegments), 2);
- $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
- $subPathSegments = $pathSegments[0]->getSubPathSegments();
- $this->assertTrue($pathSegments[0]->isAscending());
- $this->assertTrue(!is_null($subPathSegments));
- $this->assertTrue(is_array($subPathSegments));
- $this->assertEquals(count($subPathSegments), 1);
- $this->assertTrue($subPathSegments[0…
Large files files are truncated, but you can click here to view the full file