maven profile changes, model class change

This commit is contained in:
mujah 2016-11-12 12:21:46 +08:00
parent 1f0e30b81c
commit de948bc4ab
5 changed files with 130 additions and 132 deletions

View File

@ -1,69 +1,107 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId> <groupId>com.baeldung</groupId>
<artifactId>spring-data-solr</artifactId> <artifactId>spring-data-solr</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>spring-data-solr</name> <name>spring-data-solr</name>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>4.2.5.RELEASE</spring.version> <spring.version>4.2.5.RELEASE</spring.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version> <maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
<spring-data-solr>2.0.4.RELEASE</spring-data-solr> <spring-data-solr>2.0.4.RELEASE</spring-data-solr>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId> <artifactId>spring-core</artifactId>
<version>${spring.version}</version> <version>${spring.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.data</groupId> <groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId> <artifactId>spring-data-solr</artifactId>
<version>${spring-data-solr}</version> <version>${spring-data-solr}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId> <artifactId>spring-context</artifactId>
<version>${spring.version}</version> <version>${spring.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>log4j</groupId> <groupId>log4j</groupId>
<artifactId>log4j</artifactId> <artifactId>log4j</artifactId>
<version>1.2.16</version> <version>1.2.16</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>4.12</version> <version>4.12</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId> <artifactId>spring-test</artifactId>
<version>${spring.version}</version> <version>${spring.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId>
<artifactId>maven-surefire-plugin</artifactId> </plugin>
<version>${maven-surefire-plugin.version}</version> <plugin>
<configuration> <groupId>org.apache.maven.plugins</groupId>
<includes> <artifactId>maven-surefire-plugin</artifactId>
<include>**/*IntegrationTest.java</include> <version>${maven-surefire-plugin.version}</version>
</includes> <configuration>
</configuration> <excludes>
</plugin> <exclude>**/*IntegrationTest.java</exclude>
</plugins> <exclude>**/*LiveTest.java</exclude>
</build> </excludes>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project> </project>

View File

@ -14,11 +14,6 @@ public class Product {
@Indexed(name = "name", type = "string") @Indexed(name = "name", type = "string")
private String name; private String name;
@Indexed(name = "category", type = "string")
private String category;
@Indexed(name = "description", type = "string")
private String description;
public String getId() { public String getId() {
return id; return id;
@ -36,20 +31,4 @@ public class Product {
this.name = name; 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;
}
} }

View File

@ -11,12 +11,12 @@ import com.baeldung.spring.data.solr.model.Product;
public interface ProductRepository extends SolrCrudRepository<Product, String> { public interface ProductRepository extends SolrCrudRepository<Product, String> {
public List<Product> findByName(String name); public List<Product> findByName(String name);
@Query("name:*?0* OR category:*?0* OR description:*?0*") @Query("name:*?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

@ -1 +1 @@
Product.findByNamedQuery=name:*?0* OR category:*?0* OR description:*?0* Product.findByNamedQuery=name:*?0* OR description:*?0*

View File

@ -35,8 +35,6 @@ public class ProductRepositoryIntegrationTest {
final Product product = new Product(); final Product product = new Product();
product.setId("P000089998"); product.setId("P000089998");
product.setName("Desk"); product.setName("Desk");
product.setCategory("Furniture");
product.setDescription("New Desk");
productRepository.save(product); productRepository.save(product);
final Product retrievedProduct = productRepository.findOne(product.getId()); final Product retrievedProduct = productRepository.findOne(product.getId());
assertEquals(product.getId(), retrievedProduct.getId()); assertEquals(product.getId(), retrievedProduct.getId());
@ -47,15 +45,14 @@ public class ProductRepositoryIntegrationTest {
final Product product = new Product(); final Product product = new Product();
product.setId("P0001"); product.setId("P0001");
product.setName("T-Shirt"); product.setName("T-Shirt");
product.setCategory("Kitchen");
product.setDescription("New T-Shirt");
productRepository.save(product); productRepository.save(product);
product.setCategory("Clothes"); product.setName("Shirt");
productRepository.save(product); productRepository.save(product);
final Product retrievedProduct = productRepository.findOne(product.getId()); final Product retrievedProduct = productRepository.findOne(product.getId());
assertEquals(product.getCategory(), retrievedProduct.getCategory()); assertEquals(product.getName(), retrievedProduct.getName());
} }
@Test @Test
@ -63,8 +60,6 @@ public class ProductRepositoryIntegrationTest {
final Product product = new Product(); final Product product = new Product();
product.setId("P0001"); product.setId("P0001");
product.setName("Desk"); product.setName("Desk");
product.setCategory("Furniture");
product.setDescription("New Desk");
productRepository.save(product); productRepository.save(product);
productRepository.delete(product); productRepository.delete(product);
@ -79,8 +74,6 @@ public class ProductRepositoryIntegrationTest {
Product phone = new Product(); Product phone = new Product();
phone.setId("P0001"); phone.setId("P0001");
phone.setName("Phone"); phone.setName("Phone");
phone.setCategory("Electronics");
phone.setDescription("New Phone");
productRepository.save(phone); productRepository.save(phone);
List<Product> retrievedProducts = productRepository.findByName("Phone"); List<Product> retrievedProducts = productRepository.findByName("Phone");
@ -89,26 +82,20 @@ public class ProductRepositoryIntegrationTest {
@Test @Test
public void whenSearchingProductsByQuery_thenAllMatchingProductsShouldAvialble() throws Exception { public void whenSearchingProductsByQuery_thenAllMatchingProductsShouldAvialble() throws Exception {
final Product phone = new Product(); final Product phone = new Product();
phone.setId("P0001"); phone.setId("P0001");
phone.setName("Smart Phone"); phone.setName("Smart Phone");
phone.setCategory("Electronics"); productRepository.save(phone);
phone.setDescription("New Item");
productRepository.save(phone); final Product phoneCover = new Product();
phoneCover.setId("P0002");
final Product phoneCover = new Product(); phoneCover.setName("Phone Cover");
phoneCover.setId("P0002"); productRepository.save(phoneCover);
phoneCover.setName("Cover");
phoneCover.setCategory("Phone"); final Product wirelessCharger = new Product();
phoneCover.setDescription("New Product"); wirelessCharger.setId("P0003");
productRepository.save(phoneCover); wirelessCharger.setName("Phone Charging Cable");
productRepository.save(wirelessCharger);
final Product wirelessCharger = new Product();
wirelessCharger.setId("P0003");
wirelessCharger.setName("Charging Cable");
wirelessCharger.setCategory("Cable");
wirelessCharger.setDescription("Wireless Charger for Phone");
productRepository.save(wirelessCharger);
Page<Product> result = productRepository.findByCustomQuery("Phone", new PageRequest(0, 10)); Page<Product> result = productRepository.findByCustomQuery("Phone", new PageRequest(0, 10));
assertEquals(3, result.getNumberOfElements()); assertEquals(3, result.getNumberOfElements());
@ -119,22 +106,16 @@ public class ProductRepositoryIntegrationTest {
final Product phone = new Product(); final Product phone = new Product();
phone.setId("P0001"); phone.setId("P0001");
phone.setName("Smart Phone"); phone.setName("Smart Phone");
phone.setCategory("Electronics");
phone.setDescription("New Item");
productRepository.save(phone); productRepository.save(phone);
final Product phoneCover = new Product(); final Product phoneCover = new Product();
phoneCover.setId("P0002"); phoneCover.setId("P0002");
phoneCover.setName("Cover"); phoneCover.setName("Phone Cover");
phoneCover.setCategory("Phone");
phoneCover.setDescription("New Product");
productRepository.save(phoneCover); productRepository.save(phoneCover);
final Product wirelessCharger = new Product(); final Product wirelessCharger = new Product();
wirelessCharger.setId("P0003"); wirelessCharger.setId("P0003");
wirelessCharger.setName("Charging Cable"); wirelessCharger.setName("Phone Charging Cable");
wirelessCharger.setCategory("Cable");
wirelessCharger.setDescription("Wireless Charger for Phone");
productRepository.save(wirelessCharger); productRepository.save(wirelessCharger);
Page<Product> result = productRepository.findByNamedQuery("one", new PageRequest(0, 10)); Page<Product> result = productRepository.findByNamedQuery("one", new PageRequest(0, 10));