formatting format changes

This commit is contained in:
mujah 2016-10-30 17:12:50 +08:00
parent d9eeb7c21a
commit b3976c7fb5
3 changed files with 32 additions and 38 deletions

View File

@ -20,7 +20,6 @@ public class Product {
@Field("description") @Field("description")
private String description; private String description;
public Product(String id, String name, String category) { public Product(String id, String name, String category) {
this.id = id; this.id = id;
this.name = name; this.name = name;

View File

@ -1,6 +1,5 @@
package com.baeldung.spring.data.solr.repository; package com.baeldung.spring.data.solr.repository;
import java.util.List; import java.util.List;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@ -17,8 +16,7 @@ public interface ProductRepository extends SolrCrudRepository<Product, String>{
@Query("name:*?0* OR category:*?0* OR description:*?0*") @Query("name:*?0* OR category:*?0* OR description:*?0*")
public Page<Product> findByCustomQuery(String searchTerm, Pageable pageable); public Page<Product> findByCustomQuery(String searchTerm, Pageable pageable);
@Query(name = "Product.findByNamedQuery")
// @Query(name="Product.findByNamedQuery")
public Page<Product> findByNamedQuery(String searchTerm, Pageable pageable); public Page<Product> findByNamedQuery(String searchTerm, Pageable pageable);
} }

View File

@ -18,7 +18,6 @@ import com.baeldung.spring.data.solr.config.SolrConfig;
import com.baeldung.spring.data.solr.model.Product; import com.baeldung.spring.data.solr.model.Product;
import com.baeldung.spring.data.solr.repository.ProductRepository; import com.baeldung.spring.data.solr.repository.ProductRepository;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SolrConfig.class) @ContextConfiguration(classes = SolrConfig.class)
public class ProductRepositoryIntegrationTest { public class ProductRepositoryIntegrationTest {
@ -53,8 +52,6 @@ public class ProductRepositoryIntegrationTest {
assertEquals(product.getCategory(), retrievedProduct.getCategory()); assertEquals(product.getCategory(), retrievedProduct.getCategory());
} }
@Test @Test
public void whenDeletingProduct_thenNotAvailableOnRetrieval() throws Exception { public void whenDeletingProduct_thenNotAvailableOnRetrieval() throws Exception {
final Product product = new Product("P0001", "Desk", "Furniture"); final Product product = new Product("P0001", "Desk", "Furniture");
@ -70,7 +67,7 @@ public class ProductRepositoryIntegrationTest {
@Test @Test
public void whenFindByName_thenAvailableOnRetrieval() throws Exception { public void whenFindByName_thenAvailableOnRetrieval() throws Exception {
final Product phone = new Product("P0001", "Phone", "Electronics"); Product phone = new Product("P0001", "Phone", "Electronics");
phone.setDescription("New Phone"); phone.setDescription("New Phone");
productRepository.save(phone); productRepository.save(phone);
@ -92,7 +89,7 @@ public class ProductRepositoryIntegrationTest {
wirelessCharger.setDescription("Wireless Charger for Phone"); wirelessCharger.setDescription("Wireless Charger for Phone");
productRepository.save(wirelessCharger); productRepository.save(wirelessCharger);
Page<Product> result = productRepository.findByCustomQuery("Pho", new PageRequest(0, 10)); Page<Product> result = productRepository.findByCustomQuery("Phone", new PageRequest(0, 10));
assertEquals(3, result.getNumberOfElements()); assertEquals(3, result.getNumberOfElements());
} }