Ejemplo n.º 1
0
 /**
  * 
  * @see library/ODataProducer/ODataProducer.IServiceProvider::getService()
  * 
  * @return object
  */
 public function getService($serviceType)
 {
     if ($serviceType === 'IDataServiceMetadataProvider') {
         if (is_null($this->_northWindMetadata)) {
             $this->_northWindMetadata = CreateNorthWindMetadata3::Create();
         }
         return $this->_northWindMetadata;
     } else {
         if ($serviceType === 'IDataServiceQueryProvider') {
             return new NorthWindQueryProvider2();
         } else {
             if ($serviceType === 'IDataServiceStreamProvider') {
                 return null;
             }
         }
     }
     return null;
 }
Ejemplo n.º 2
0
 /**
  * Test whether order by parser identify and remove path duplication
  */
 public function testOrderByWithPathDuplication()
 {
     try {
         $northWindMetadata = CreateNorthWindMetadata3::Create();
         $configuration = new DataServiceConfiguration($northWindMetadata);
         $configuration->setEntitySetAccessRule('*', EntitySetRights::ALL);
         $metaQueryProverWrapper = new MetadataQueryProviderWrapper($northWindMetadata, null, $configuration, false);
         $resourceSetWrapper = $metaQueryProverWrapper->resolveResourceSet('Order_Details');
         $resourceType = $resourceSetWrapper->getResourceType();
         $orderBy = 'Order/Price desc, Product/ProductName asc, Order/Price asc';
         $internalOrderInfo = OrderByParser::parseOrderByClause($resourceSetWrapper, $resourceType, $orderBy, $metaQueryProverWrapper);
         //The orderby path Order/Price appears twice, but parser will consider only first path
         $orderByInfo = $internalOrderInfo->getOrderByInfo();
         //There are navigation (resource reference) properties in the orderby path so getNavigationPropertiesUsed should
         //not be null
         $naviUsed = $orderByInfo->getNavigationPropertiesUsed();
         $this->assertFalse(is_null($naviUsed));
         //3 path segment are there, but last one is duplicate of first one, so parser removes last one
         $this->assertEquals(count($naviUsed), 2);
         $this->assertTrue(is_array($naviUsed[0]));
         $this->assertTrue(is_array($naviUsed[1]));
         //one navgations used in first orderby 'Order'
         $this->assertEquals(count($naviUsed[0]), 1);
         //one navgations used in second orderby 'Prodcut'
         $this->assertEquals(count($naviUsed[1]), 1);
         $this->assertEquals($naviUsed[0][0]->getName(), 'Order');
         $this->assertEquals($naviUsed[1][0]->getName(), 'Product');
         $orderByPathSegments = $orderByInfo->getOrderByPathSegments();
         $this->assertEquals(count($orderByPathSegments), 2);
     } catch (\Exception $exception) {
         $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
     }
 }
 protected function setUp()
 {
     $this->_northWindMetadata = CreateNorthWindMetadata3::Create();
     $this->_dataServiceConfiguration = new DataServiceConfiguration($this->_northWindMetadata);
 }
 /**
  * If last sub path segment specified in the select clause does not appear in the prjection tree,
  * then parser will create 'ProjectionNode' for them
  */
 public function testPrjectionNodeCreation()
 {
     try {
         $northWindMetadata = CreateNorthWindMetadata3::Create();
         $queryProvider = new NorthWindQueryProvider2();
         $configuration = new DataServiceConfiguration($northWindMetadata);
         $configuration->setEntitySetAccessRule('*', EntitySetRights::ALL);
         $metaQueryProverWrapper = new MetadataQueryProviderWrapper($northWindMetadata, $queryProvider, $configuration, false);
         $ordersResourceSetWrapper = $metaQueryProverWrapper->resolveResourceSet('Orders');
         $orderResourceType = $ordersResourceSetWrapper->getResourceType();
         //test selection of properties which is not included in expand clause
         //1 primitve ('Order_Details/UnitPrice') and 1 link to navigation 'Customer'
         $projectionTreeRoot = ExpandProjectionParser::parseExpandAndSelectClause($ordersResourceSetWrapper, $orderResourceType, null, null, null, 'Order_Details', 'Order_Details/UnitPrice, Customer', $metaQueryProverWrapper);
         //expand option is absent
         $this->assertTrue($projectionTreeRoot->isExpansionSpecified());
         //select is applied
         $this->assertTrue($projectionTreeRoot->isSelectionSpecified());
         $this->assertFalse($projectionTreeRoot->canSelectAllImmediateProperties());
         $this->assertFalse($projectionTreeRoot->canSelectAllProperties());
         //there are 2 child nodes for the root
         $this->assertEquals(count($projectionTreeRoot->getChildNodes()), 2);
         //The child nodes one 'ProjectionNode' Customer and one 'ExpandedProjectionNode' for 'Order'
         $childNodes = $projectionTreeRoot->getChildNodes();
         $this->assertTrue(array_key_exists('Order_Details', $childNodes));
         $this->assertTrue(array_key_exists('Customer', $childNodes));
         $this->assertTrue($childNodes['Order_Details'] instanceof ExpandedProjectionNode);
         $this->assertTrue($childNodes['Customer'] instanceof ProjectionNode);
         //'Order_Detials' has a child node
         $childNodes = $childNodes['Order_Details']->getChildNodes();
         $this->assertEquals(count($childNodes), 1);
         $this->assertTrue(array_key_exists('UnitPrice', $childNodes));
         $this->assertTrue($childNodes['UnitPrice'] instanceof ProjectionNode);
     } catch (\Exception $exception) {
         $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
     }
 }
Ejemplo n.º 5
0
 protected function setUp()
 {
     $this->_northWindMetadata = CreateNorthWindMetadata3::Create();
 }
Ejemplo n.º 6
0
 public function testCreateSegments_NavigationSegment()
 {
     try {
         //Test navigation segment followed by primitve property
         $segments = array("Customers(CustomerID='ALFKI', CustomerGuid=guid'15b242e7-52eb-46bd-8f0e-6568b72cd9a6')", 'Orders(789)', 'Customer', 'CustomerName');
         $segmentDescriptors = SegmentParser::parseRequestUriSegements($segments, $this->_metadataProviderWrapper);
         $this->assertEquals(count($segmentDescriptors), 4);
         $this->assertEquals($segmentDescriptors[0]->getIdentifier(), 'Customers');
         $this->assertEquals($segmentDescriptors[1]->getIdentifier(), 'Orders');
         $this->assertEquals($segmentDescriptors[2]->getIdentifier(), 'Customer');
         $this->assertEquals($segmentDescriptors[3]->getIdentifier(), 'CustomerName');
         $keyDescriptor = $segmentDescriptors[0]->getKeyDescriptor();
         $this->assertFalse(is_null($keyDescriptor));
         $keyDescriptor = $segmentDescriptors[1]->getKeyDescriptor();
         $this->assertFalse(is_null($keyDescriptor));
         $keyDescriptor = $segmentDescriptors[2]->getKeyDescriptor();
         $this->assertTrue(is_null($keyDescriptor));
         $keyDescriptor = $segmentDescriptors[3]->getKeyDescriptor();
         $this->assertTrue(is_null($keyDescriptor));
         $keyDescriptor = $segmentDescriptors[0]->getKeyDescriptor();
         $this->assertEquals($keyDescriptor->valueCount(), 2);
         $namedKeyValues = $keyDescriptor->getValidatedNamedValues();
         $this->assertTrue(array_key_exists('CustomerID', $namedKeyValues));
         $this->assertTrue(array_key_exists('CustomerGuid', $namedKeyValues));
         $this->assertEquals($namedKeyValues['CustomerID'][0], '\'ALFKI\'');
         $this->assertEquals($namedKeyValues['CustomerGuid'][0], '\'15b242e7-52eb-46bd-8f0e-6568b72cd9a6\'');
         $keyDescriptor = $segmentDescriptors[1]->getKeyDescriptor();
         $this->assertEquals($keyDescriptor->valueCount(), 1);
         $namedKeyValues = $keyDescriptor->getValidatedNamedValues();
         $this->assertTrue(array_key_exists('OrderID', $namedKeyValues));
         $this->assertEquals($namedKeyValues['OrderID'][0], 789);
         $this->assertEquals($segmentDescriptors[0]->getTargetKind(), RequestTargetKind::RESOURCE);
         $this->assertEquals($segmentDescriptors[1]->getTargetKind(), RequestTargetKind::RESOURCE);
         $this->assertEquals($segmentDescriptors[2]->getTargetKind(), RequestTargetKind::RESOURCE);
         $this->assertEquals($segmentDescriptors[3]->getTargetKind(), RequestTargetKind::PRIMITIVE);
         $this->assertEquals($segmentDescriptors[0]->getTargetSource(), RequestTargetSource::ENTITY_SET);
         $this->assertEquals($segmentDescriptors[1]->getTargetSource(), RequestTargetSource::PROPERTY);
         $this->assertEquals($segmentDescriptors[2]->getTargetSource(), RequestTargetSource::PROPERTY);
         $this->assertEquals($segmentDescriptors[3]->getTargetSource(), RequestTargetSource::PROPERTY);
         $resourceSetWrapper = $segmentDescriptors[0]->getTargetResourcesetWrapper();
         $this->assertFalse(is_null($resourceSetWrapper));
         $resourceSetWrapper = $segmentDescriptors[1]->getTargetResourcesetWrapper();
         $this->assertFalse(is_null($resourceSetWrapper));
         $resourceSetWrapper = $segmentDescriptors[2]->getTargetResourcesetWrapper();
         $this->assertFalse(is_null($resourceSetWrapper));
         $resourceSetWrapper = $segmentDescriptors[3]->getTargetResourcesetWrapper();
         $this->assertTrue(is_null($resourceSetWrapper));
         $this->assertTrue($segmentDescriptors[0]->isSingleResult());
         $this->assertTrue($segmentDescriptors[0]->isSingleResult());
         $this->assertTrue($segmentDescriptors[0]->isSingleResult());
         $this->assertTrue($segmentDescriptors[0]->isSingleResult());
         //Test invisible navigation segment
         //Creates a provider wrapper for NorthWind service with 'Orders' entity set as invisible
         $metadataProvider = CreateNorthWindMetadata3::Create();
         $serviceConfiguration = new DataServiceConfiguration($this->_metadataProvider);
         $serviceConfiguration->setEntitySetAccessRule('Customers', EntitySetRights::READ_ALL);
         $serviceConfiguration->setEntitySetAccessRule('Orders', EntitySetRights::NONE);
         $metadataProviderWrapper = new MetadataQueryProviderWrapper($metadataProvider, null, $serviceConfiguration, false);
         $segments = array("Customers(CustomerID='ALFKI', CustomerGuid=guid'15b242e7-52eb-46bd-8f0e-6568b72cd9a6')", 'Orders(789)', 'OrderID');
         $exceptionThrown = false;
         try {
             SegmentParser::parseRequestUriSegements($segments, $metadataProviderWrapper);
         } catch (ODataException $exception) {
             $exceptionThrown = true;
             $this->assertEquals('Resource not found for the segment \'Orders\'', $exception->getMessage());
         }
         if (!$exceptionThrown) {
             $this->fail('An expected ODataException for \'Orders\' resource not found error has not been thrown');
         }
     } catch (\Exception $exception) {
         $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
     }
 }
Ejemplo n.º 7
0
 /**
  * test the creation of nextlink from an object.
  * Test building of link with guid sub-value
  */
 public function testCreationOfNextLink4()
 {
     try {
         $northWindMetadata = CreateNorthWindMetadata3::Create();
         $configuration = new DataServiceConfiguration($northWindMetadata);
         $configuration->setEntitySetAccessRule('*', EntitySetRights::ALL);
         $metaQueryProverWrapper = new MetadataQueryProviderWrapper($northWindMetadata, null, $configuration, false);
         $resourceSetWrapper = $metaQueryProverWrapper->resolveResourceSet('Customers');
         $resourceType = $resourceSetWrapper->getResourceType();
         $orderBy = 'CustomerID, CustomerGuid';
         $internalOrderByInfo = OrderByParser::parseOrderByClause($resourceSetWrapper, $resourceType, $orderBy, $metaQueryProverWrapper);
         $skipToken = "null, guid'05b242e752eb46bd8f0e6568b72cd9a5'";
         $internalSkipTokenInfo = SkipTokenParser::parseSkipTokenClause($resourceType, $internalOrderByInfo, $skipToken);
         $keyObject = $internalSkipTokenInfo->getKeyObject();
         $lastObject = new Customer2();
         $lastObject->CustomerID = 'ABC';
         $lastObject->CustomerGuid = '{05b242e7-52eb-46bd-8f0e-6568b72cd9a5}';
         $nextLink = $internalSkipTokenInfo->buildNextPageLink($lastObject);
         $this->assertEquals($nextLink, "'ABC', guid'%7B05b242e7-52eb-46bd-8f0e-6568b72cd9a5%7D'");
     } catch (\Exception $exception) {
         $this->fail('An unexpected Exception has been raised.' . $exception->getMessage());
     }
 }
 /**
  * Creates a valid IDataServiceMetadataProvider implementation, and associated configuration
  * Note: This metadata is for positive testing
  * 
  * @param DataServiceConfiguration $configuration On return, this will hold reference to configuration object
  * 
  * @return IDataServiceMetadataProvider
  */
 private function _createMetadataAndConfiguration1(&$configuration)
 {
     $northWindMetadata = CreateNorthWindMetadata3::Create();
     $configuration = new DataServiceConfiguration($northWindMetadata);
     return $northWindMetadata;
 }
Ejemplo n.º 9
0
 public function testKeyDescriptorValidation()
 {
     try {
         $northWindMetadata = CreateNorthWindMetadata3::Create();
         $orderDetailsResourceType = $northWindMetadata->resolveResourceType('Order_Details');
         $this->assertFalse(is_null($orderDetailsResourceType));
         $keyDescriptor = null;
         //Test with a valid named value key predicate
         $keyPredicate = 'ProductID=11, OrderID=2546';
         $validPredicateSyntax = KeyDescriptor::tryParseKeysFromKeyPredicate($keyPredicate, $keyDescriptor);
         $this->assertTrue($validPredicateSyntax);
         $this->assertFalse(is_null($keyDescriptor));
         $keyDescriptor->validate('Order_Details(ProductID=11, OrderID=2546)', $orderDetailsResourceType);
         $validatedNamedValues = $keyDescriptor->getValidatedNamedValues();
         $this->assertTrue(array_key_exists('ProductID', $validatedNamedValues));
         $this->assertTrue(array_key_exists('OrderID', $validatedNamedValues));
         $productVal = $validatedNamedValues['ProductID'];
         $orderVal = $validatedNamedValues['OrderID'];
         $this->assertEquals($productVal[0], 11);
         $this->assertEquals($orderVal[0], 2546);
         $keyDescriptor = null;
         //Test with a valid positional value key predicate
         $keyPredicate = '11, 2546';
         $validPredicateSyntax = KeyDescriptor::tryParseKeysFromKeyPredicate($keyPredicate, $keyDescriptor);
         $this->assertTrue($validPredicateSyntax);
         $this->assertFalse(is_null($keyDescriptor));
         $keyDescriptor->validate('Order_Details(11, 2546)', $orderDetailsResourceType);
         $validatedNamedValues = $keyDescriptor->getValidatedNamedValues();
         $this->assertEquals(count($validatedNamedValues), 2);
         $this->assertTrue(array_key_exists('ProductID', $validatedNamedValues));
         $this->assertTrue(array_key_exists('OrderID', $validatedNamedValues));
         $productVal = $validatedNamedValues['ProductID'];
         $orderVal = $validatedNamedValues['OrderID'];
         $this->assertEquals($productVal[0], 11);
         $this->assertEquals($orderVal[0], 2546);
         //Test for key count
         $keyDescriptor = null;
         $keyPredicate = 'ProductID=11';
         $validPredicateSyntax = KeyDescriptor::tryParseKeysFromKeyPredicate($keyPredicate, $keyDescriptor);
         $exceptionThrown = false;
         try {
             $keyDescriptor->validate('Order_Details(ProductID=11)', $orderDetailsResourceType);
         } catch (ODataException $exception) {
             $this->assertStringEndsWith(' expect 2 keys but 1 provided', $exception->getMessage());
             $exceptionThrown = true;
         }
         if (!$exceptionThrown) {
             $this->fail('An expected ODataException for predicate key count has not been thrown');
         }
         //test for missing key
         $keyDescriptor = null;
         $keyPredicate = 'ProductID=11, OrderID1=2546';
         $validPredicateSyntax = KeyDescriptor::tryParseKeysFromKeyPredicate($keyPredicate, $keyDescriptor);
         $exceptionThrown = false;
         try {
             $keyDescriptor->validate('Order_Details(ProductID=11, OrderID1=2546)', $orderDetailsResourceType);
         } catch (ODataException $exception) {
             $this->assertStringEndsWith('The key predicate expect the keys \'ProductID, OrderID\'', $exception->getMessage());
             $exceptionThrown = true;
         }
         if (!$exceptionThrown) {
             $this->fail('An expected ODataException for missing of keys in the predicate has not been thrown');
         }
         //test for key type
         $keyDescriptor = null;
         $keyPredicate = 'ProductID=11.12, OrderID=2546';
         $validPredicateSyntax = KeyDescriptor::tryParseKeysFromKeyPredicate($keyPredicate, $keyDescriptor);
         $exceptionThrown = false;
         try {
             $keyDescriptor->validate('Order_Details(ProductID=11.12, OrderID=2546)', $orderDetailsResourceType);
         } catch (ODataException $exception) {
             $this->assertStringEndsWith('The value of key property \'ProductID\' should be of type Edm.Int32, given Edm.Double', $exception->getMessage());
             $exceptionThrown = true;
         }
         if (!$exceptionThrown) {
             $this->fail('An expected ODataException for type incompactibility has not been thrown');
         }
         //test for key type
         $keyDescriptor = null;
         $keyPredicate = '11, \'ABCD\'';
         $validPredicateSyntax = KeyDescriptor::tryParseKeysFromKeyPredicate($keyPredicate, $keyDescriptor);
         $exceptionThrown = false;
         try {
             $keyDescriptor->validate('Order_Details(11, \'ABCD\')', $orderDetailsResourceType);
         } catch (ODataException $exception) {
             $this->assertStringEndsWith('The value of key property \'OrderID\' at position 1 should be of type Edm.Int32, given Edm.String', $exception->getMessage());
             $exceptionThrown = true;
         }
         if (!$exceptionThrown) {
             $this->fail('An expected ODataException for type incompactibility has not been thrown');
         }
     } catch (\Exception $exception) {
         $this->fail('An unexpected Exception has been raised.' . $exception->getMessage());
     }
 }
 /**
  * One can expand a navigation property only if corrosponding resource set is visible
  * 
  */
 public function testExpandWithNonVisibleResourceSet()
 {
     try {
         $northWindMetadata = CreateNorthWindMetadata3::Create();
         $queryProvider = new NorthWindQueryProvider2();
         $configuration = new DataServiceConfiguration($northWindMetadata);
         //Make 'Customers' and 'Orders' visible, make 'Order_Details' invisible
         $configuration->setEntitySetAccessRule('Customers', EntitySetRights::ALL);
         $configuration->setEntitySetAccessRule('Orders', EntitySetRights::ALL);
         $metaQueryProverWrapper = new MetadataQueryProviderWrapper($northWindMetadata, $queryProvider, $configuration, false);
         $customersResourceSetWrapper = $metaQueryProverWrapper->resolveResourceSet('Customers');
         $customerResourceType = $customersResourceSetWrapper->getResourceType();
         $exceptionThrown = false;
         try {
             $projectionTree = ExpandProjectionParser::parseExpandAndSelectClause($customersResourceSetWrapper, $customerResourceType, null, null, null, 'Orders/Order_Details', null, $metaQueryProverWrapper);
         } catch (ODataException $odataException) {
             $exceptionThrown = true;
             $this->assertStringEndsWith("(Check the resource set of the navigation property 'Order_Details' is visible)", $odataException->getMessage());
         }
         if (!$exceptionThrown) {
             $this->fail('An expected ODataException for navigation to invisible resource set has not been thrown');
         }
     } catch (\Exception $exception) {
         $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
     }
 }