From de948bc4ab9a7b87afe1ba5f6e51265af69936b7 Mon Sep 17 00:00:00 2001 From: mujah Date: Sat, 12 Nov 2016 12:21:46 +0800 Subject: [PATCH 1/5] maven profile changes, model class change --- spring-data-solr/pom.xml | 172 +++++++++++------- .../spring/data/solr/model/Product.java | 21 --- .../solr/repository/ProductRepository.java | 10 +- .../resources/solr-named-queries.properties | 2 +- .../ProductRepositoryIntegrationTest.java | 57 ++---- 5 files changed, 130 insertions(+), 132 deletions(-) diff --git a/spring-data-solr/pom.xml b/spring-data-solr/pom.xml index bd48a53d06..6724c56add 100644 --- a/spring-data-solr/pom.xml +++ b/spring-data-solr/pom.xml @@ -1,69 +1,107 @@ - - 4.0.0 - com.baeldung - spring-data-solr - 0.0.1-SNAPSHOT - jar - spring-data-solr - - - - UTF-8 - 4.2.5.RELEASE - 2.19.1 - 2.0.4.RELEASE - - - - - org.springframework - spring-core - ${spring.version} - - - org.springframework.data - spring-data-solr - ${spring-data-solr} - - - org.springframework - spring-context - ${spring.version} - - - log4j - log4j - 1.2.16 - - - junit - junit - 4.12 - test - - - org.springframework - spring-test - ${spring.version} - test - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - **/*IntegrationTest.java - - - - - - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + 4.0.0 + com.baeldung + spring-data-solr + 0.0.1-SNAPSHOT + jar + spring-data-solr + + + + UTF-8 + 4.2.5.RELEASE + 2.19.1 + 2.0.4.RELEASE + + + + + org.springframework + spring-core + ${spring.version} + + + org.springframework.data + spring-data-solr + ${spring-data-solr} + + + org.springframework + spring-context + ${spring.version} + + + log4j + log4j + 1.2.16 + + + junit + junit + 4.12 + test + + + org.springframework + spring-test + ${spring.version} + test + + + + + + + maven-compiler-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + **/*IntegrationTest.java + **/*LiveTest.java + + + + + + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + + + **/*IntegrationTest.java + + + + + + + json + + + + + + + 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 7cd0890718..466af54191 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 @@ -14,11 +14,6 @@ public class Product { @Indexed(name = "name", type = "string") private String name; - @Indexed(name = "category", type = "string") - private String category; - - @Indexed(name = "description", type = "string") - private String description; public String getId() { return id; @@ -36,20 +31,4 @@ public class Product { this.name = name; } - public String getCategory() { - return category; - } - - public void setCategory(String category) { - this.category = category; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - } 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 01ec1fb909..d016e46f52 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 @@ -11,12 +11,12 @@ import com.baeldung.spring.data.solr.model.Product; public interface ProductRepository extends SolrCrudRepository { - public List findByName(String name); + public List findByName(String name); - @Query("name:*?0* OR category:*?0* OR description:*?0*") - public Page findByCustomQuery(String searchTerm, Pageable pageable); + @Query("name:*?0* OR description:*?0*") + public Page findByCustomQuery(String searchTerm, Pageable pageable); - @Query(name = "Product.findByNamedQuery") - public Page findByNamedQuery(String searchTerm, Pageable pageable); + @Query(name = "Product.findByNamedQuery") + public Page findByNamedQuery(String searchTerm, Pageable pageable); } diff --git a/spring-data-solr/src/main/resources/solr-named-queries.properties b/spring-data-solr/src/main/resources/solr-named-queries.properties index cec59cbebd..ed3f9a534a 100644 --- a/spring-data-solr/src/main/resources/solr-named-queries.properties +++ b/spring-data-solr/src/main/resources/solr-named-queries.properties @@ -1 +1 @@ -Product.findByNamedQuery=name:*?0* OR category:*?0* OR description:*?0* \ No newline at end of file +Product.findByNamedQuery=name:*?0* OR description:*?0* \ No newline at end of file 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 74d94ef91c..815a188c06 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 @@ -35,8 +35,6 @@ public class ProductRepositoryIntegrationTest { final Product product = new Product(); product.setId("P000089998"); product.setName("Desk"); - product.setCategory("Furniture"); - product.setDescription("New Desk"); productRepository.save(product); final Product retrievedProduct = productRepository.findOne(product.getId()); assertEquals(product.getId(), retrievedProduct.getId()); @@ -47,15 +45,14 @@ public class ProductRepositoryIntegrationTest { final Product product = new Product(); product.setId("P0001"); product.setName("T-Shirt"); - product.setCategory("Kitchen"); - product.setDescription("New T-Shirt"); + productRepository.save(product); - product.setCategory("Clothes"); + product.setName("Shirt"); productRepository.save(product); final Product retrievedProduct = productRepository.findOne(product.getId()); - assertEquals(product.getCategory(), retrievedProduct.getCategory()); + assertEquals(product.getName(), retrievedProduct.getName()); } @Test @@ -63,8 +60,6 @@ public class ProductRepositoryIntegrationTest { final Product product = new Product(); product.setId("P0001"); product.setName("Desk"); - product.setCategory("Furniture"); - product.setDescription("New Desk"); productRepository.save(product); productRepository.delete(product); @@ -79,8 +74,6 @@ public class ProductRepositoryIntegrationTest { Product phone = new Product(); phone.setId("P0001"); phone.setName("Phone"); - phone.setCategory("Electronics"); - phone.setDescription("New Phone"); productRepository.save(phone); List retrievedProducts = productRepository.findByName("Phone"); @@ -89,26 +82,20 @@ public class ProductRepositoryIntegrationTest { @Test public void whenSearchingProductsByQuery_thenAllMatchingProductsShouldAvialble() throws Exception { - final Product phone = new Product(); - phone.setId("P0001"); - phone.setName("Smart Phone"); - phone.setCategory("Electronics"); - phone.setDescription("New Item"); - productRepository.save(phone); - - final Product phoneCover = new Product(); - phoneCover.setId("P0002"); - phoneCover.setName("Cover"); - phoneCover.setCategory("Phone"); - phoneCover.setDescription("New Product"); - productRepository.save(phoneCover); - - final Product wirelessCharger = new Product(); - wirelessCharger.setId("P0003"); - wirelessCharger.setName("Charging Cable"); - wirelessCharger.setCategory("Cable"); - wirelessCharger.setDescription("Wireless Charger for Phone"); - productRepository.save(wirelessCharger); + final Product phone = new Product(); + phone.setId("P0001"); + phone.setName("Smart Phone"); + productRepository.save(phone); + + final Product phoneCover = new Product(); + phoneCover.setId("P0002"); + phoneCover.setName("Phone Cover"); + productRepository.save(phoneCover); + + final Product wirelessCharger = new Product(); + wirelessCharger.setId("P0003"); + wirelessCharger.setName("Phone Charging Cable"); + productRepository.save(wirelessCharger); Page result = productRepository.findByCustomQuery("Phone", new PageRequest(0, 10)); assertEquals(3, result.getNumberOfElements()); @@ -119,22 +106,16 @@ public class ProductRepositoryIntegrationTest { final Product phone = new Product(); phone.setId("P0001"); phone.setName("Smart Phone"); - phone.setCategory("Electronics"); - phone.setDescription("New Item"); productRepository.save(phone); final Product phoneCover = new Product(); phoneCover.setId("P0002"); - phoneCover.setName("Cover"); - phoneCover.setCategory("Phone"); - phoneCover.setDescription("New Product"); + phoneCover.setName("Phone Cover"); productRepository.save(phoneCover); final Product wirelessCharger = new Product(); wirelessCharger.setId("P0003"); - wirelessCharger.setName("Charging Cable"); - wirelessCharger.setCategory("Cable"); - wirelessCharger.setDescription("Wireless Charger for Phone"); + wirelessCharger.setName("Phone Charging Cable"); productRepository.save(wirelessCharger); Page result = productRepository.findByNamedQuery("one", new PageRequest(0, 10)); From 26864e2897a255e6582a17a09fbe62091feaad46 Mon Sep 17 00:00:00 2001 From: mujah Date: Sat, 12 Nov 2016 12:32:30 +0800 Subject: [PATCH 2/5] query changes --- .../baeldung/spring/data/solr/repository/ProductRepository.java | 2 +- .../src/main/resources/solr-named-queries.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 d016e46f52..0ab1418a1d 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 @@ -13,7 +13,7 @@ public interface ProductRepository extends SolrCrudRepository { public List findByName(String name); - @Query("name:*?0* OR description:*?0*") + @Query("id:*?0* OR name:*?0*") public Page findByCustomQuery(String searchTerm, Pageable pageable); @Query(name = "Product.findByNamedQuery") diff --git a/spring-data-solr/src/main/resources/solr-named-queries.properties b/spring-data-solr/src/main/resources/solr-named-queries.properties index ed3f9a534a..c00b5bace9 100644 --- a/spring-data-solr/src/main/resources/solr-named-queries.properties +++ b/spring-data-solr/src/main/resources/solr-named-queries.properties @@ -1 +1 @@ -Product.findByNamedQuery=name:*?0* OR description:*?0* \ No newline at end of file +Product.findByNamedQuery=id:*?0* OR name:*?0* \ No newline at end of file From 8ccfd201e6be15a6fbbfd972c2f9c2c27eec4489 Mon Sep 17 00:00:00 2001 From: mujah Date: Sat, 12 Nov 2016 12:35:55 +0800 Subject: [PATCH 3/5] formatting --- .../spring/data/solr/config/SolrConfig.java | 16 +- .../ProductRepositoryIntegrationTest.java | 202 +++++++++--------- 2 files changed, 109 insertions(+), 109 deletions(-) diff --git a/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/config/SolrConfig.java b/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/config/SolrConfig.java index 1fe1e5468b..73f5b36d45 100644 --- a/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/config/SolrConfig.java +++ b/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/config/SolrConfig.java @@ -13,13 +13,13 @@ import org.springframework.data.solr.repository.config.EnableSolrRepositories; @ComponentScan public class SolrConfig { - @Bean - public SolrClient solrClient() { - return new HttpSolrClient("http://localhost:8983/solr"); - } + @Bean + public SolrClient solrClient() { + return new HttpSolrClient("http://localhost:8983/solr"); + } - @Bean - public SolrTemplate solrTemplate(SolrClient client) throws Exception { - return new SolrTemplate(client); - } + @Bean + public SolrTemplate solrTemplate(SolrClient client) throws Exception { + return new SolrTemplate(client); + } } 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 815a188c06..1335e82392 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 @@ -21,105 +21,105 @@ 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() { - productRepository.deleteAll(); - } - - @Test - public void whenSavingProduct_thenAvailableOnRetrieval() throws Exception { - final Product product = new Product(); - product.setId("P000089998"); - product.setName("Desk"); - productRepository.save(product); - final Product retrievedProduct = productRepository.findOne(product.getId()); - assertEquals(product.getId(), retrievedProduct.getId()); - } - - @Test - public void whenUpdatingProduct_thenChangeAvailableOnRetrieval() throws Exception { - final Product product = new Product(); - product.setId("P0001"); - product.setName("T-Shirt"); - - productRepository.save(product); - - product.setName("Shirt"); - productRepository.save(product); - - final Product retrievedProduct = productRepository.findOne(product.getId()); - assertEquals(product.getName(), retrievedProduct.getName()); - } - - @Test - public void whenDeletingProduct_thenNotAvailableOnRetrieval() throws Exception { - final Product product = new Product(); - product.setId("P0001"); - product.setName("Desk"); - productRepository.save(product); - - productRepository.delete(product); - - Product retrievedProduct = productRepository.findOne(product.getId()); - assertNull(retrievedProduct); - - } - - @Test - public void whenFindByName_thenAvailableOnRetrieval() throws Exception { - Product phone = new Product(); - phone.setId("P0001"); - phone.setName("Phone"); - productRepository.save(phone); - - List retrievedProducts = productRepository.findByName("Phone"); - assertEquals(phone.getId(), retrievedProducts.get(0).getId()); - } - - @Test - public void whenSearchingProductsByQuery_thenAllMatchingProductsShouldAvialble() throws Exception { - final Product phone = new Product(); - phone.setId("P0001"); - phone.setName("Smart Phone"); - productRepository.save(phone); - - final Product phoneCover = new Product(); - phoneCover.setId("P0002"); - phoneCover.setName("Phone Cover"); - productRepository.save(phoneCover); - - final Product wirelessCharger = new Product(); - wirelessCharger.setId("P0003"); - wirelessCharger.setName("Phone Charging Cable"); - productRepository.save(wirelessCharger); - - Page result = productRepository.findByCustomQuery("Phone", new PageRequest(0, 10)); - assertEquals(3, result.getNumberOfElements()); - } - - @Test - public void whenSearchingProductsByNamedQuery_thenAllMatchingProductsShouldAvialble() throws Exception { - final Product phone = new Product(); - phone.setId("P0001"); - phone.setName("Smart Phone"); - productRepository.save(phone); - - final Product phoneCover = new Product(); - phoneCover.setId("P0002"); - phoneCover.setName("Phone Cover"); - productRepository.save(phoneCover); - - final Product wirelessCharger = new Product(); - wirelessCharger.setId("P0003"); - wirelessCharger.setName("Phone Charging Cable"); - productRepository.save(wirelessCharger); - - Page result = productRepository.findByNamedQuery("one", new PageRequest(0, 10)); - assertEquals(3, result.getNumberOfElements()); - } - + + @Autowired + private ProductRepository productRepository; + + @Before + public void clearSolrData() { + productRepository.deleteAll(); + } + + @Test + public void whenSavingProduct_thenAvailableOnRetrieval() throws Exception { + final Product product = new Product(); + product.setId("P000089998"); + product.setName("Desk"); + productRepository.save(product); + final Product retrievedProduct = productRepository.findOne(product.getId()); + assertEquals(product.getId(), retrievedProduct.getId()); + } + + @Test + public void whenUpdatingProduct_thenChangeAvailableOnRetrieval() throws Exception { + final Product product = new Product(); + product.setId("P0001"); + product.setName("T-Shirt"); + + productRepository.save(product); + + product.setName("Shirt"); + productRepository.save(product); + + final Product retrievedProduct = productRepository.findOne(product.getId()); + assertEquals(product.getName(), retrievedProduct.getName()); + } + + @Test + public void whenDeletingProduct_thenNotAvailableOnRetrieval() throws Exception { + final Product product = new Product(); + product.setId("P0001"); + product.setName("Desk"); + productRepository.save(product); + + productRepository.delete(product); + + Product retrievedProduct = productRepository.findOne(product.getId()); + assertNull(retrievedProduct); + + } + + @Test + public void whenFindByName_thenAvailableOnRetrieval() throws Exception { + Product phone = new Product(); + phone.setId("P0001"); + phone.setName("Phone"); + productRepository.save(phone); + + List retrievedProducts = productRepository.findByName("Phone"); + assertEquals(phone.getId(), retrievedProducts.get(0).getId()); + } + + @Test + public void whenSearchingProductsByQuery_thenAllMatchingProductsShouldAvialble() throws Exception { + final Product phone = new Product(); + phone.setId("P0001"); + phone.setName("Smart Phone"); + productRepository.save(phone); + + final Product phoneCover = new Product(); + phoneCover.setId("P0002"); + phoneCover.setName("Phone Cover"); + productRepository.save(phoneCover); + + final Product wirelessCharger = new Product(); + wirelessCharger.setId("P0003"); + wirelessCharger.setName("Phone Charging Cable"); + productRepository.save(wirelessCharger); + + Page result = productRepository.findByCustomQuery("Phone", new PageRequest(0, 10)); + assertEquals(3, result.getNumberOfElements()); + } + + @Test + public void whenSearchingProductsByNamedQuery_thenAllMatchingProductsShouldAvialble() throws Exception { + final Product phone = new Product(); + phone.setId("P0001"); + phone.setName("Smart Phone"); + productRepository.save(phone); + + final Product phoneCover = new Product(); + phoneCover.setId("P0002"); + phoneCover.setName("Phone Cover"); + productRepository.save(phoneCover); + + final Product wirelessCharger = new Product(); + wirelessCharger.setId("P0003"); + wirelessCharger.setName("Phone Charging Cable"); + productRepository.save(wirelessCharger); + + Page result = productRepository.findByNamedQuery("one", new PageRequest(0, 10)); + assertEquals(3, result.getNumberOfElements()); + } + } From 046b23685e3fcff325491ef06f33c5c7f36448a0 Mon Sep 17 00:00:00 2001 From: mujah Date: Sun, 13 Nov 2016 23:40:17 +0800 Subject: [PATCH 4/5] formatting changes --- spring-data-solr/pom.xml | 102 +++++------ .../spring/data/solr/config/SolrConfig.java | 16 +- .../spring/data/solr/model/Product.java | 15 +- .../solr/repository/ProductRepository.java | 10 +- .../ProductRepositoryIntegrationTest.java | 158 +++++++++--------- 5 files changed, 150 insertions(+), 151 deletions(-) diff --git a/spring-data-solr/pom.xml b/spring-data-solr/pom.xml index 6724c56add..ea9b282f66 100644 --- a/spring-data-solr/pom.xml +++ b/spring-data-solr/pom.xml @@ -1,55 +1,55 @@ - - 4.0.0 - com.baeldung - spring-data-solr - 0.0.1-SNAPSHOT - jar - spring-data-solr - - - - UTF-8 - 4.2.5.RELEASE - 2.19.1 - 2.0.4.RELEASE - - - - - org.springframework - spring-core - ${spring.version} - - - org.springframework.data - spring-data-solr - ${spring-data-solr} - - - org.springframework - spring-context - ${spring.version} - - - log4j - log4j - 1.2.16 - - - junit - junit - 4.12 - test - - - org.springframework - spring-test - ${spring.version} - test - - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + 4.0.0 + com.baeldung + spring-data-solr + 0.0.1-SNAPSHOT + jar + spring-data-solr + + + + UTF-8 + 4.2.5.RELEASE + 2.19.1 + 2.0.4.RELEASE + + + + + org.springframework + spring-core + ${spring.version} + + + org.springframework.data + spring-data-solr + ${spring-data-solr} + + + org.springframework + spring-context + ${spring.version} + + + log4j + log4j + 1.2.16 + + + junit + junit + 4.12 + test + + + org.springframework + spring-test + ${spring.version} + test + + diff --git a/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/config/SolrConfig.java b/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/config/SolrConfig.java index 73f5b36d45..1fe1e5468b 100644 --- a/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/config/SolrConfig.java +++ b/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/config/SolrConfig.java @@ -13,13 +13,13 @@ import org.springframework.data.solr.repository.config.EnableSolrRepositories; @ComponentScan public class SolrConfig { - @Bean - public SolrClient solrClient() { - return new HttpSolrClient("http://localhost:8983/solr"); - } + @Bean + public SolrClient solrClient() { + return new HttpSolrClient("http://localhost:8983/solr"); + } - @Bean - public SolrTemplate solrTemplate(SolrClient client) throws Exception { - return new SolrTemplate(client); - } + @Bean + public SolrTemplate solrTemplate(SolrClient client) throws Exception { + return new SolrTemplate(client); + } } 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 466af54191..5286f53309 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 @@ -6,29 +6,28 @@ import org.springframework.data.solr.core.mapping.SolrDocument; @SolrDocument(solrCoreName = "product") public class Product { - + @Id @Indexed(name = "id", type = "string") private String id; - + @Indexed(name = "name", type = "string") private String name; - - + public String getId() { return id; } - + public void setId(String id) { this.id = id; } - + public String getName() { return name; } - + public void setName(String name) { this.name = name; } - + } 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 0ab1418a1d..5649cd7888 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 @@ -11,12 +11,12 @@ import com.baeldung.spring.data.solr.model.Product; public interface ProductRepository extends SolrCrudRepository { - public List findByName(String name); + public List findByName(String name); - @Query("id:*?0* OR name:*?0*") - public Page findByCustomQuery(String searchTerm, Pageable pageable); + @Query("id:*?0* OR name:*?0*") + public Page findByCustomQuery(String searchTerm, Pageable pageable); - @Query(name = "Product.findByNamedQuery") - public Page findByNamedQuery(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 1335e82392..a3765a74ec 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 @@ -22,104 +22,104 @@ import com.baeldung.spring.data.solr.repository.ProductRepository; @ContextConfiguration(classes = SolrConfig.class) public class ProductRepositoryIntegrationTest { - @Autowired - private ProductRepository productRepository; + @Autowired + private ProductRepository productRepository; - @Before - public void clearSolrData() { - productRepository.deleteAll(); - } + @Before + public void clearSolrData() { + productRepository.deleteAll(); + } - @Test - public void whenSavingProduct_thenAvailableOnRetrieval() throws Exception { - final Product product = new Product(); - product.setId("P000089998"); - product.setName("Desk"); - productRepository.save(product); - final Product retrievedProduct = productRepository.findOne(product.getId()); - assertEquals(product.getId(), retrievedProduct.getId()); - } + @Test + public void whenSavingProduct_thenAvailableOnRetrieval() throws Exception { + final Product product = new Product(); + product.setId("P000089998"); + product.setName("Desk"); + productRepository.save(product); + final Product retrievedProduct = productRepository.findOne(product.getId()); + assertEquals(product.getId(), retrievedProduct.getId()); + } - @Test - public void whenUpdatingProduct_thenChangeAvailableOnRetrieval() throws Exception { - final Product product = new Product(); - product.setId("P0001"); - product.setName("T-Shirt"); + @Test + public void whenUpdatingProduct_thenChangeAvailableOnRetrieval() throws Exception { + final Product product = new Product(); + product.setId("P0001"); + product.setName("T-Shirt"); - productRepository.save(product); + productRepository.save(product); - product.setName("Shirt"); - productRepository.save(product); + product.setName("Shirt"); + productRepository.save(product); - final Product retrievedProduct = productRepository.findOne(product.getId()); - assertEquals(product.getName(), retrievedProduct.getName()); - } + final Product retrievedProduct = productRepository.findOne(product.getId()); + assertEquals(product.getName(), retrievedProduct.getName()); + } - @Test - public void whenDeletingProduct_thenNotAvailableOnRetrieval() throws Exception { - final Product product = new Product(); - product.setId("P0001"); - product.setName("Desk"); - productRepository.save(product); + @Test + public void whenDeletingProduct_thenNotAvailableOnRetrieval() throws Exception { + final Product product = new Product(); + product.setId("P0001"); + product.setName("Desk"); + productRepository.save(product); - productRepository.delete(product); + productRepository.delete(product); - Product retrievedProduct = productRepository.findOne(product.getId()); - assertNull(retrievedProduct); + Product retrievedProduct = productRepository.findOne(product.getId()); + assertNull(retrievedProduct); - } + } - @Test - public void whenFindByName_thenAvailableOnRetrieval() throws Exception { - Product phone = new Product(); - phone.setId("P0001"); - phone.setName("Phone"); - productRepository.save(phone); + @Test + public void whenFindByName_thenAvailableOnRetrieval() throws Exception { + Product phone = new Product(); + phone.setId("P0001"); + phone.setName("Phone"); + productRepository.save(phone); - List retrievedProducts = productRepository.findByName("Phone"); - assertEquals(phone.getId(), retrievedProducts.get(0).getId()); - } + List retrievedProducts = productRepository.findByName("Phone"); + assertEquals(phone.getId(), retrievedProducts.get(0).getId()); + } - @Test - public void whenSearchingProductsByQuery_thenAllMatchingProductsShouldAvialble() throws Exception { - final Product phone = new Product(); - phone.setId("P0001"); - phone.setName("Smart Phone"); - productRepository.save(phone); + @Test + public void whenSearchingProductsByQuery_thenAllMatchingProductsShouldAvialble() throws Exception { + final Product phone = new Product(); + phone.setId("P0001"); + phone.setName("Smart Phone"); + productRepository.save(phone); - final Product phoneCover = new Product(); - phoneCover.setId("P0002"); - phoneCover.setName("Phone Cover"); - productRepository.save(phoneCover); + final Product phoneCover = new Product(); + phoneCover.setId("P0002"); + phoneCover.setName("Phone Cover"); + productRepository.save(phoneCover); - final Product wirelessCharger = new Product(); - wirelessCharger.setId("P0003"); - wirelessCharger.setName("Phone Charging Cable"); - productRepository.save(wirelessCharger); + final Product wirelessCharger = new Product(); + wirelessCharger.setId("P0003"); + wirelessCharger.setName("Phone Charging Cable"); + productRepository.save(wirelessCharger); - Page result = productRepository.findByCustomQuery("Phone", new PageRequest(0, 10)); - assertEquals(3, result.getNumberOfElements()); - } + Page result = productRepository.findByCustomQuery("Phone", new PageRequest(0, 10)); + assertEquals(3, result.getNumberOfElements()); + } - @Test - public void whenSearchingProductsByNamedQuery_thenAllMatchingProductsShouldAvialble() throws Exception { - final Product phone = new Product(); - phone.setId("P0001"); - phone.setName("Smart Phone"); - productRepository.save(phone); + @Test + public void whenSearchingProductsByNamedQuery_thenAllMatchingProductsShouldAvialble() throws Exception { + final Product phone = new Product(); + phone.setId("P0001"); + phone.setName("Smart Phone"); + productRepository.save(phone); - final Product phoneCover = new Product(); - phoneCover.setId("P0002"); - phoneCover.setName("Phone Cover"); - productRepository.save(phoneCover); + final Product phoneCover = new Product(); + phoneCover.setId("P0002"); + phoneCover.setName("Phone Cover"); + productRepository.save(phoneCover); - final Product wirelessCharger = new Product(); - wirelessCharger.setId("P0003"); - wirelessCharger.setName("Phone Charging Cable"); - productRepository.save(wirelessCharger); + final Product wirelessCharger = new Product(); + wirelessCharger.setId("P0003"); + wirelessCharger.setName("Phone Charging Cable"); + productRepository.save(wirelessCharger); - Page result = productRepository.findByNamedQuery("one", new PageRequest(0, 10)); - assertEquals(3, result.getNumberOfElements()); - } + Page result = productRepository.findByNamedQuery("one", new PageRequest(0, 10)); + assertEquals(3, result.getNumberOfElements()); + } } From 082ae7b0da38b9005b578b94ee19ffa55e72b5d8 Mon Sep 17 00:00:00 2001 From: mujah Date: Wed, 16 Nov 2016 21:39:13 +0800 Subject: [PATCH 5/5] xml formatting --- spring-data-solr/pom.xml | 114 +++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/spring-data-solr/pom.xml b/spring-data-solr/pom.xml index ea9b282f66..ec6eb7bf46 100644 --- a/spring-data-solr/pom.xml +++ b/spring-data-solr/pom.xml @@ -1,21 +1,21 @@ - + 4.0.0 com.baeldung spring-data-solr 0.0.1-SNAPSHOT jar spring-data-solr - - + + UTF-8 4.2.5.RELEASE 2.19.1 2.0.4.RELEASE - + org.springframework @@ -51,57 +51,57 @@ - - - - maven-compiler-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - **/*IntegrationTest.java - **/*LiveTest.java - - - - - + + + + maven-compiler-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + **/*IntegrationTest.java + **/*LiveTest.java + + + + + - - - integration - - - - org.apache.maven.plugins - maven-surefire-plugin - - - integration-test - - test - - - - **/*LiveTest.java - - - **/*IntegrationTest.java - - - - - - - json - - - - - - - - + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + + + **/*IntegrationTest.java + + + + + + + json + + + + + + + + \ No newline at end of file