public function testProcessRequestForCollectionWithInlineCountWhenServiceVersionIs10() { $requestURI = new Url('http://host.com/data.svc/Collection/?$inlinecount=allpages'); Phockito::when($this->mockServiceHost->getAbsoluteRequestUri())->return($requestURI); //mock inline count as all pages Phockito::when($this->mockServiceHost->getQueryStringItem(ODataConstants::HTTPQUERY_STRING_INLINECOUNT))->return("allpages"); $this->fakeServiceConfig->setAcceptCountRequests(true); $this->fakeServiceConfig->setMaxDataServiceVersion(ProtocolVersion::V1()); try { UriProcessor::process($this->mockService); $this->fail("Expected exception not thrown"); } catch (ODataException $ex) { $expected = Messages::requestVersionTooLow("1.0", "2.0"); $this->assertEquals($expected, $ex->getMessage(), $ex->getTraceAsString()); } }
/** * This function is used to perform following checking (validation) * for capability negotiation. * (1) Check client request's 'DataServiceVersion' header value is * less than or equal to the minimum version required to intercept * the response * (2) Check client request's 'MaxDataServiceVersion' header value is * less than or equal to the version of protocol required to generate * the response * (3) Check the configured maximum protocol version is less than or equal * to the version of protocol required to generate the response * In addition to these checking, this function is also responsible for * initializing the properties representing 'DataServiceVersion' and * 'MaxDataServiceVersion'. * * * @throws ODataException If any of the above 3 check fails. */ public function validateVersions() { //If the request version is below the minimum version required by supplied request arguments..throw an exception if ($this->requestVersion->compare($this->requiredMinRequestVersion) < 0) { throw ODataException::createBadRequestError(Messages::requestVersionTooLow($this->requestVersion->toString(), $this->requiredMinRequestVersion->toString())); } //If the requested max version is below the version required to fulfill the response...throw an exception if ($this->requestMaxVersion->compare($this->requiredMinResponseVersion) < 0) { throw ODataException::createBadRequestError(Messages::requestVersionTooLow($this->requestMaxVersion->toString(), $this->requiredMinResponseVersion->toString())); } //If the max version supported by the service is below the version required to fulfill the response..throw an exception if ($this->maxServiceVersion->compare($this->requiredMinResponseVersion) < 0) { throw ODataException::createBadRequestError(Messages::requestVersionIsBiggerThanProtocolVersion($this->requiredMinResponseVersion->toString(), $this->maxServiceVersion->toString())); } }
public function testGetResponseVersionConfigMaxVersion30RequestVersion30RequestMaxVersion20() { $requestVersion = "3.0"; $requestMaxVersion = "2.0"; $fakeConfigMaxVersion = Version::v3(); Phockito::when($this->mockServiceConfiguration->getMaxDataServiceVersion())->return($fakeConfigMaxVersion); $fakeURL = new Url("http://host/service.svc/Collection"); $fakeSegments = array(new SegmentDescriptor()); $request = new RequestDescription($fakeSegments, $fakeURL, $fakeConfigMaxVersion, $requestVersion, $requestMaxVersion); //This respects the max version $this->assertEquals(Version::v2(), $request->getResponseVersion()); $request->raiseResponseVersion(2, 0); //max is already 2, so this is allowed $this->assertEquals(Version::v2(), $request->getResponseVersion()); //moving to 3 is greater than max, so error should be thrown try { $request->raiseResponseVersion(3, 0); $this->fail("Expected exception not thrown"); } catch (ODataException $ex) { $this->assertEquals(Messages::requestVersionTooLow($requestMaxVersion, "3.0"), $ex->getMessage()); $this->assertEquals(400, $ex->getStatusCode()); } }