@Test public void testSetFilterInt() { Query query = new Query(kindName, rootKey); List<Filter> filterList = new ArrayList<>(); filterList.add(Query.FilterOperator.EQUAL.of("intData", 20)); filterList.add(Query.FilterOperator.GREATER_THAN.of("intData", 0)); Filter filter = Query.CompositeFilterOperator.and(filterList); query.setFilter(filter); assertEquals(1, service.prepare(query).countEntities(fo)); }
@Test public void testStrFilter() { Query q = new Query(kindName); q.setAncestor(rootKey); Query.Filter filter = Query.CompositeFilterOperator.and( new FilterPredicate("stringData", Query.FilterOperator.LESS_THAN, "qqq"), new FilterPredicate("stringData", Query.FilterOperator.GREATER_THAN, "mmm")); q.setFilter(filter); q.addSort("stringData", Query.SortDirection.ASCENDING); assertEquals(2, service.prepare(q).countEntities(fo)); List<Entity> elist = service.prepare(q).asList(fo); assertEquals(Arrays.asList("abc", "xyz", "mno"), elist.get(0).getProperty("stringData")); assertEquals(Arrays.asList("ppp", "iii", "ddd"), elist.get(1).getProperty("stringData")); }
@Test public void testSetFilterRating() { Query query = new Query(kindName, rootKey); List<Filter> filterList = new ArrayList<>(); filterList.add(Query.FilterOperator.LESS_THAN.of("ratingData", new Rating(30))); filterList.add(Query.FilterOperator.GREATER_THAN.of("ratingData", new Rating(0))); Filter filter1 = Query.CompositeFilterOperator.or(filterList); Filter filter2 = Query.FilterOperator.EQUAL.of("ratingData", new Rating(20)); query.setFilter(Query.CompositeFilterOperator.and(filter1, filter2)); assertEquals(1, service.prepare(query).countEntities(fo)); }
@Test public void testQueryWithEqualityAndInequalityFiltersAndSortOnASinglePropertyDoesRequireConfiguredIndex() throws Exception { try { executeQuery( new Query("Unindexed") .setFilter( and(new Query.FilterPredicate("someProperty", GREATER_THAN, "a"), new Query.FilterPredicate("someProperty", EQUAL, "b"))) .addSort("someProperty")); } catch (Exception e) { assertTrue(EXPECTED_DS_INDEX_MSG + " instead got " + e.toString(), e instanceof DatastoreNeedIndexException); return; } fail(EXPECTED_DS_INDEX_MSG); }
/** * Google issueId:1458158 */ @Test public void testIntFilter() { Query q = new Query(kindName); Query.Filter filter = Query.CompositeFilterOperator.and( new FilterPredicate("intData1", Query.FilterOperator.LESS_THAN, 20), new FilterPredicate("intData1", Query.FilterOperator.GREATER_THAN, 1), new FilterPredicate("intData1", Query.FilterOperator.EQUAL, null)); q.setFilter(filter); q.addSort("intData1", Query.SortDirection.ASCENDING); q.setAncestor(rootKey); assertEquals(1, service.prepare(q).countEntities(fo)); List<Entity> elist = service.prepare(q).asList(fo); assertEquals(Arrays.asList(1L, 10L, null), elist.get(0).getProperty("intData1")); }
@Test public void queryWithMultipleEqualityFiltersOnMultivaluedPropertyReturnsEntityIfAllFiltersMatch() throws Exception { String testMethodName = "queryWithMultipleInequalityFiltersOnMultivaluedPropertyReturnsNothing"; Entity parentEntity = createTestEntityWithUniqueMethodNameKey(TEST_ENTITY_KIND, testMethodName); Key parentKey = parentEntity.getKey(); Entity entity = storeTestEntityWithSingleProperty(parentKey, Arrays.asList(1, 2)); assertSet( queryReturns(entity), whenFilteringWith(and( new FilterPredicate(SINGLE_PROPERTY_NAME, EQUAL, 1), new FilterPredicate(SINGLE_PROPERTY_NAME, EQUAL, 2)), parentKey) ); }
@Test public void queryWithMultipleInequalityFiltersOnMultivaluedPropertyReturnsNothing() throws Exception { String testMethodName = "queryWithMultipleEqualityFiltersOnMultivaluedPropertyReturnsEntityIfAllFiltersMatch"; Entity parentEntity = createTestEntityWithUniqueMethodNameKey(TEST_ENTITY_KIND, testMethodName); Key parentKey = parentEntity.getKey(); storeTestEntityWithSingleProperty(parentKey, Arrays.asList(1, 2)); assertSet( queryReturnsNothing(), whenFilteringWith(and( new FilterPredicate(SINGLE_PROPERTY_NAME, GREATER_THAN, 1), new FilterPredicate(SINGLE_PROPERTY_NAME, LESS_THAN, 2)), parentKey) ); }
@Ignore("Fails intermittently on appspot. Is an index needed in this case or not?") @Test(expected = DatastoreNeedIndexException.class) public void testQueryWithInequalityFilterOnSomePropertyAndEqualityFilterOnSamePropertyRequiresConfiguredIndex() throws Exception { executeQuery( new Query("Unindexed") .setFilter( and(new Query.FilterPredicate("someProperty", EQUAL, "b"), new Query.FilterPredicate("someProperty", GREATER_THAN, "a")))); }
@Test(expected = DatastoreNeedIndexException.class) public void testQueryWithEqualityFilterOnKeyPropertyAndInequalityFilterOnOtherPropertyRequiresConfiguredIndex() throws Exception { executeQuery( new Query("Unindexed") .setFilter( and(new Query.FilterPredicate(Entity.KEY_RESERVED_PROPERTY, EQUAL, KeyFactory.createKey("Unindexed", 1)), new Query.FilterPredicate("someProperty", GREATER_THAN, "a")))); }
@Test public void testQueryUsingOnlyInequalityFiltersOnSinglePropertyDoesNotRequireConfiguredIndex() throws Exception { executeQuery(new Query("Unindexed") .setFilter(new Query.FilterPredicate("someProperty", GREATER_THAN, "foo"))); executeQuery(new Query("Unindexed") .setFilter( and(new Query.FilterPredicate("someProperty", GREATER_THAN, "foo"), new Query.FilterPredicate("someProperty", LESS_THAN, "bar")))); }
private CompositeFilter getTestMethodFilter(String testMethodTag) { FilterPredicate testRunFilter = new FilterPredicate(TEST_RUN_ID, FilterOperator.EQUAL, testRunId); FilterPredicate method = new FilterPredicate(TEST_METHOD_TAG, FilterOperator.EQUAL, testMethodTag); return CompositeFilterOperator.and(testRunFilter, method); }
@Test public void testQueryUsingOnlyAncestorFiltersAndEqualityFiltersOnPropertiesAndInequalityFiltersOnKeysDoesNotRequireConfiguredIndex() throws Exception { executeQuery(new Query("Unindexed") .setAncestor(KeyFactory.createKey("Ancestor", 1)) .setFilter( and(new Query.FilterPredicate("someProperty", EQUAL, "foo"), new Query.FilterPredicate(Entity.KEY_RESERVED_PROPERTY, GREATER_THAN, KeyFactory.createKey("Unindexed", 1))))); }
@Test(expected = DatastoreNeedIndexException.class) public void testAncestorQueryWithInequalityFilterOnSomePropertyAndEqualityFilterOnSamePropertyRequiresConfiguredIndex() throws Exception { executeQuery( new Query("Unindexed") .setAncestor(KeyFactory.createKey("Ancestor", 1)) .setFilter( and(new Query.FilterPredicate("someProperty", EQUAL, "b"), new Query.FilterPredicate("someProperty", GREATER_THAN, "a")))); }
@Test(expected = DatastoreNeedIndexException.class) public void testQueryWithInequalityFilterOnSomePropertyAndEqualityFilterOnOtherPropertyRequiresConfiguredIndex() throws Exception { executeQuery( new Query("Unindexed") .setFilter( and(new Query.FilterPredicate("someProperty", GREATER_THAN, "a"), new Query.FilterPredicate("otherProperty", EQUAL, "b")))); }
@Test public void testQueryUsingOnlyAncestorAndEqualityFiltersDoesNotRequireConfiguredIndex() throws Exception { executeQuery(new Query("Unindexed") .setAncestor(KeyFactory.createKey("Ancestor", 1)) .setFilter(new Query.FilterPredicate("someProperty", EQUAL, "foo"))); executeQuery(new Query("Unindexed") .setAncestor(KeyFactory.createKey("Ancestor", 1)) .setFilter( and(new Query.FilterPredicate("someProperty", EQUAL, "foo"), new Query.FilterPredicate("otherProperty", EQUAL, "bar")))); }
@Test public void testQueryWithInequalityFiltersOnMultiplePropertiesThrowsIllegalArgumentException() throws Exception { Query query = createQuery() .setFilter(and( new Query.FilterPredicate("weight", GREATER_THAN, 3), new Query.FilterPredicate("size", GREATER_THAN, 5))); assertIAEWhenAccessingResult(service.prepare(query)); }
public Entity getMarker(String marker) { DatastoreService service = DatastoreServiceFactory.getDatastoreService(); FilterPredicate testRunFilter = new FilterPredicate(TEST_RUN_ID, FilterOperator.EQUAL, testRunId); FilterPredicate markerFilter = new FilterPredicate(MARKER, FilterOperator.EQUAL, marker); CompositeFilter filter = CompositeFilterOperator.and(testRunFilter, markerFilter); Query query = new Query(entityName).setFilter(filter); return service.prepare(query).asSingleEntity(); }
@Test public void testQueryUsingOnlyEqualityFiltersDoesNotRequireConfiguredIndex() throws Exception { executeQuery(new Query("Unindexed") .setFilter(new Query.FilterPredicate("someProperty", EQUAL, "foo"))); executeQuery(new Query("Unindexed") .setFilter( and(new Query.FilterPredicate("someProperty", EQUAL, "foo"), new Query.FilterPredicate("otherProperty", EQUAL, "bar")))); }
@Test public void testQueryWithEqalityAndInequalityFilterOnKeyPropertyDoesNotRequireConfiguredIndex() throws Exception { executeQuery( new Query("Unindexed") .setFilter( and(new Query.FilterPredicate(Entity.KEY_RESERVED_PROPERTY, GREATER_THAN, KeyFactory.createKey("Unindexed", 1)), new Query.FilterPredicate(Entity.KEY_RESERVED_PROPERTY, EQUAL, KeyFactory.createKey("Unindexed", 2))))); }
@Test public void testQueryWithInequalityFilterOnKeyPropertyAndEqualityFilterOnOtherPropertyDoesNotRequireConfiguredIndex() throws Exception { executeQuery( new Query("Unindexed") .setFilter( and(new Query.FilterPredicate(Entity.KEY_RESERVED_PROPERTY, GREATER_THAN, KeyFactory.createKey("Unindexed", 1)), new Query.FilterPredicate("otherProperty", EQUAL, "b")))); }