GqlServiceImpl implements GqlService { @Override public Collection<Entity> executeGqlRequest(String gqlRequest, Integer offset, Integer limit) { AppEngineHelper.disableApiHooks(); FetchOptions fetchOptions = FetchOptions.Builder.withDefaults(); GqlQuery gql; if (offset != null) { fetchOptions.offset(offset); } if (limit != null) { fetchOptions.limit(limit); } try { gql = new GqlQuery(gqlRequest); return datastoreHelper.queryOnAllNamespaces(gql.query(), fetchOptions); } catch (IllegalArgumentException | NullPointerException e) { throw new InvalidGqlSyntaxException(); } } @Inject  GqlServiceImpl(
            DatastoreHelper datastoreHelper); @Override Collection<Entity> executeGqlRequest(String gqlRequest, Integer offset, Integer limit);  }
@Test public void executeSelectReturnAllEntities() { createCars(); Collection<Entity> result = gqlService.executeGqlRequest("SELECT * FROM Car", null, null); assertEquals(3, result.size()); }
@Test public void executeWhereReturnOneRelevantEntity() { createCars(); Collection<Entity> result = gqlService.executeGqlRequest("SELECT * FROM Car WHERE make = 'Canada'", null, null); assertEquals(1, result.size()); }
@Test public void executeWhereReturnZeroMatchedEntity() { createCars(); Collection<Entity> result = gqlService.executeGqlRequest("SELECT * FROM Car WHERE make = 'Italy'", null, null); assertTrue(result.isEmpty()); }
@Test public void executeFromUnknowEntityZeroMatchedEntity() { createCars(); Collection<Entity> result = gqlService.executeGqlRequest("SELECT * FROM Autos WHERE make = 'Canada'", null, null); assertTrue(result.isEmpty()); }
@Test public void executeRequestWithLimit() { createCars(); Collection<Entity> result = gqlService.executeGqlRequest("SELECT * FROM Car", 0, 2); assertEquals(2, result.size()); }
@Test public void executeRequestWithDownLimit() { createCars(); createCars(); Collection<Entity> result = gqlService.executeGqlRequest("SELECT * FROM Car", 2, 4); assertEquals(4, result.size()); }