@Test public void testQueryCreationSingleProperty() throws NoSuchMethodException, SecurityException { Method method = SampleRepository.class.getMethod("findByText", String.class); SolrQueryMethod queryMethod = new SolrQueryMethod(method, metadataMock, entityInformationCreatorMock); StringBasedSolrQuery solrQuery = new StringBasedSolrQuery(queryMethod, solrOperationsMock); org.springframework.data.solr.core.query.Query query = solrQuery.createQuery( new SolrParametersParameterAccessor(queryMethod, new Object[] {"j73x73r"})); Assert.assertEquals("textGeneral:j73x73r", queryParser.getQueryString(query)); }
@Test public void testQueryCreationMultiyProperty() throws NoSuchMethodException, SecurityException { Method method = SampleRepository.class.getMethod("findByPopularityAndPrice", Integer.class, Float.class); SolrQueryMethod queryMethod = new SolrQueryMethod(method, metadataMock, entityInformationCreatorMock); StringBasedSolrQuery solrQuery = new StringBasedSolrQuery(queryMethod, solrOperationsMock); org.springframework.data.solr.core.query.Query query = solrQuery.createQuery( new SolrParametersParameterAccessor( queryMethod, new Object[] {Integer.valueOf(1), Float.valueOf(2f)})); Assert.assertEquals("popularity:1 AND price:2.0", queryParser.getQueryString(query)); }
@Test public void testWithProjectionOnSingleField() throws NoSuchMethodException, SecurityException { Method method = SampleRepository.class.getMethod("findByNameProjectionOnPopularity", String.class); SolrQueryMethod queryMethod = new SolrQueryMethod(method, metadataMock, entityInformationCreatorMock); StringBasedSolrQuery solrQuery = new StringBasedSolrQuery(queryMethod, solrOperationsMock); org.springframework.data.solr.core.query.Query query = solrQuery.createQuery( new SolrParametersParameterAccessor(queryMethod, new Object[] {"christoph"})); Assert.assertEquals("name:christoph*", queryParser.getQueryString(query)); Assert.assertEquals(1, query.getProjectionOnFields().size()); Assert.assertEquals("popularity", query.getProjectionOnFields().get(0).getName()); }
@Test public void testWithSort() throws NoSuchMethodException, SecurityException { Method method = SampleRepository.class.getMethod("findByNameWithSort", String.class, Sort.class); SolrQueryMethod queryMethod = new SolrQueryMethod(method, metadataMock, entityInformationCreatorMock); StringBasedSolrQuery solrQuery = new StringBasedSolrQuery(queryMethod, solrOperationsMock); Sort sort = new Sort(Direction.DESC, "popularity", "price"); org.springframework.data.solr.core.query.Query query = solrQuery.createQuery( new SolrParametersParameterAccessor(queryMethod, new Object[] {"spring", sort})); Assert.assertEquals("name:spring", queryParser.getQueryString(query)); Assert.assertEquals(sort, query.getSort()); }
@Test public void testWithPointProperty() throws NoSuchMethodException, SecurityException { Method method = SampleRepository.class.getMethod("findByLocationNear", Point.class, Distance.class); SolrQueryMethod queryMethod = new SolrQueryMethod(method, metadataMock, entityInformationCreatorMock); StringBasedSolrQuery solrQuery = new StringBasedSolrQuery(queryMethod, solrOperationsMock); org.springframework.data.solr.core.query.Query query = solrQuery.createQuery( new SolrParametersParameterAccessor( queryMethod, new Object[] {new Point(48.303056, 14.290556), new Distance(5)})); Assert.assertEquals( "{!geofilt pt=48.303056,14.290556 sfield=store d=5.0}", queryParser.getQueryString(query)); }