From b3976c7fb59be85afb7ad1ff153b9b09346373e2 Mon Sep 17 00:00:00 2001 From: mujah Date: Sun, 30 Oct 2016 17:12:50 +0800 Subject: [PATCH] formatting format changes --- .../spring/data/solr/model/Product.java | 7 ++- .../solr/repository/ProductRepository.java | 18 ++++---- .../ProductRepositoryIntegrationTest.java | 45 +++++++++---------- 3 files changed, 32 insertions(+), 38 deletions(-) diff --git a/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/model/Product.java b/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/model/Product.java index 2c16a2cdbf..d08640123a 100644 --- a/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/model/Product.java +++ b/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/model/Product.java @@ -4,7 +4,7 @@ import org.apache.solr.client.solrj.beans.Field; import org.springframework.data.annotation.Id; import org.springframework.data.solr.core.mapping.SolrDocument; -@SolrDocument(solrCoreName="product") +@SolrDocument(solrCoreName = "product") public class Product { @Id @@ -20,13 +20,12 @@ public class Product { @Field("description") private String description; - - public Product(String id,String name,String category){ + public Product(String id, String name, String category) { this.id = id; this.name = name; this.category = category; } - + public String getId() { return id; } diff --git a/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/repository/ProductRepository.java b/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/repository/ProductRepository.java index 1f57816dd6..01ec1fb909 100644 --- a/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/repository/ProductRepository.java +++ b/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/repository/ProductRepository.java @@ -1,6 +1,5 @@ package com.baeldung.spring.data.solr.repository; - import java.util.List; import org.springframework.data.domain.Page; @@ -10,15 +9,14 @@ import org.springframework.data.solr.repository.SolrCrudRepository; import com.baeldung.spring.data.solr.model.Product; -public interface ProductRepository extends SolrCrudRepository{ - +public interface ProductRepository extends SolrCrudRepository { + public List findByName(String name); - + @Query("name:*?0* OR category:*?0* OR description:*?0*") - public Page findByCustomQuery(String searchTerm,Pageable pageable); - - - // @Query(name="Product.findByNamedQuery") - public Page findByNamedQuery(String searchTerm,Pageable pageable); - + public Page findByCustomQuery(String searchTerm, Pageable pageable); + + @Query(name = "Product.findByNamedQuery") + public Page findByNamedQuery(String searchTerm, Pageable pageable); + } diff --git a/spring-data-solr/src/test/java/com/baeldung/spring/data/solr/repo/ProductRepositoryIntegrationTest.java b/spring-data-solr/src/test/java/com/baeldung/spring/data/solr/repo/ProductRepositoryIntegrationTest.java index 52a1a2837d..b55e65e04a 100644 --- a/spring-data-solr/src/test/java/com/baeldung/spring/data/solr/repo/ProductRepositoryIntegrationTest.java +++ b/spring-data-solr/src/test/java/com/baeldung/spring/data/solr/repo/ProductRepositoryIntegrationTest.java @@ -18,59 +18,56 @@ import com.baeldung.spring.data.solr.config.SolrConfig; import com.baeldung.spring.data.solr.model.Product; import com.baeldung.spring.data.solr.repository.ProductRepository; - @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = SolrConfig.class) public class ProductRepositoryIntegrationTest { - + @Autowired private ProductRepository productRepository; - + @Before - public void clearSolrData(){ + public void clearSolrData() { productRepository.deleteAll(); } - + @Test - public void whenSavingProduct_thenAvailableOnRetrieval() throws Exception{ - final Product product = new Product("P00001","Desk","Furniture"); + public void whenSavingProduct_thenAvailableOnRetrieval() throws Exception { + final Product product = new Product("P00001", "Desk", "Furniture"); product.setDescription("New Desk"); productRepository.save(product); final Product retrievedProduct = productRepository.findOne(product.getId()); - assertEquals(product.getId(),retrievedProduct.getId()); + assertEquals(product.getId(), retrievedProduct.getId()); } - + @Test public void whenUpdatingProduct_thenChangeAvailableOnRetrieval() throws Exception { - final Product product = new Product("P0001", "T-Shirt","Kitchen"); + final Product product = new Product("P0001", "T-Shirt", "Kitchen"); product.setDescription("New T-Shirt"); productRepository.save(product); - + product.setCategory("Clothes"); productRepository.save(product); - + final Product retrievedProduct = productRepository.findOne(product.getId()); assertEquals(product.getCategory(), retrievedProduct.getCategory()); } - - - + @Test public void whenDeletingProduct_thenNotAvailableOnRetrieval() throws Exception { - final Product product = new Product("P0001", "Desk","Furniture"); + final Product product = new Product("P0001", "Desk", "Furniture"); product.setDescription("New Desk"); productRepository.save(product); - + productRepository.delete(product); - - Product retrievedProduct = productRepository.findOne(product.getId()); + + Product retrievedProduct = productRepository.findOne(product.getId()); assertNull(retrievedProduct); - + } - + @Test - public void whenFindByName_thenAvailableOnRetrieval() throws Exception{ - final Product phone = new Product("P0001", "Phone", "Electronics"); + public void whenFindByName_thenAvailableOnRetrieval() throws Exception { + Product phone = new Product("P0001", "Phone", "Electronics"); phone.setDescription("New Phone"); productRepository.save(phone); @@ -92,7 +89,7 @@ public class ProductRepositoryIntegrationTest { wirelessCharger.setDescription("Wireless Charger for Phone"); productRepository.save(wirelessCharger); - Page result = productRepository.findByCustomQuery("Pho", new PageRequest(0, 10)); + Page result = productRepository.findByCustomQuery("Phone", new PageRequest(0, 10)); assertEquals(3, result.getNumberOfElements()); }