Skip to content

Commit de948bc

Browse files
committed
maven profile changes, model class change
1 parent 1f0e30b commit de948bc

5 files changed

Lines changed: 130 additions & 132 deletions

File tree

‎spring-data-solr/pom.xml‎

Lines changed: 105 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,107 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
4-
<modelVersion>4.0.0</modelVersion>
5-
<groupId>com.baeldung</groupId>
6-
<artifactId>spring-data-solr</artifactId>
7-
<version>0.0.1-SNAPSHOT</version>
8-
<packaging>jar</packaging>
9-
<name>spring-data-solr</name>
10-
11-
12-
<properties>
13-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14-
<spring.version>4.2.5.RELEASE</spring.version>
15-
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
16-
<spring-data-solr>2.0.4.RELEASE</spring-data-solr>
17-
</properties>
18-
19-
<dependencies>
20-
<dependency>
21-
<groupId>org.springframework</groupId>
22-
<artifactId>spring-core</artifactId>
23-
<version>${spring.version}</version>
24-
</dependency>
25-
<dependency>
26-
<groupId>org.springframework.data</groupId>
27-
<artifactId>spring-data-solr</artifactId>
28-
<version>${spring-data-solr}</version>
29-
</dependency>
30-
<dependency>
31-
<groupId>org.springframework</groupId>
32-
<artifactId>spring-context</artifactId>
33-
<version>${spring.version}</version>
34-
</dependency>
35-
<dependency>
36-
<groupId>log4j</groupId>
37-
<artifactId>log4j</artifactId>
38-
<version>1.2.16</version>
39-
</dependency>
40-
<dependency>
41-
<groupId>junit</groupId>
42-
<artifactId>junit</artifactId>
43-
<version>4.12</version>
44-
<scope>test</scope>
45-
</dependency>
46-
<dependency>
47-
<groupId>org.springframework</groupId>
48-
<artifactId>spring-test</artifactId>
49-
<version>${spring.version}</version>
50-
<scope>test</scope>
51-
</dependency>
52-
</dependencies>
53-
54-
<build>
55-
<plugins>
56-
<plugin>
57-
<groupId>org.apache.maven.plugins</groupId>
58-
<artifactId>maven-surefire-plugin</artifactId>
59-
<version>${maven-surefire-plugin.version}</version>
60-
<configuration>
61-
<includes>
62-
<include>**/*IntegrationTest.java</include>
63-
</includes>
64-
</configuration>
65-
</plugin>
66-
</plugins>
67-
</build>
68-
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.baeldung</groupId>
6+
<artifactId>spring-data-solr</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
<name>spring-data-solr</name>
10+
11+
12+
<properties>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
<spring.version>4.2.5.RELEASE</spring.version>
15+
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
16+
<spring-data-solr>2.0.4.RELEASE</spring-data-solr>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.springframework</groupId>
22+
<artifactId>spring-core</artifactId>
23+
<version>${spring.version}</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.springframework.data</groupId>
27+
<artifactId>spring-data-solr</artifactId>
28+
<version>${spring-data-solr}</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.springframework</groupId>
32+
<artifactId>spring-context</artifactId>
33+
<version>${spring.version}</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>log4j</groupId>
37+
<artifactId>log4j</artifactId>
38+
<version>1.2.16</version>
39+
</dependency>
40+
<dependency>
41+
<groupId>junit</groupId>
42+
<artifactId>junit</artifactId>
43+
<version>4.12</version>
44+
<scope>test</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.springframework</groupId>
48+
<artifactId>spring-test</artifactId>
49+
<version>${spring.version}</version>
50+
<scope>test</scope>
51+
</dependency>
52+
</dependencies>
53+
54+
<build>
55+
<plugins>
56+
<plugin>
57+
<artifactId>maven-compiler-plugin</artifactId>
58+
</plugin>
59+
<plugin>
60+
<groupId>org.apache.maven.plugins</groupId>
61+
<artifactId>maven-surefire-plugin</artifactId>
62+
<version>${maven-surefire-plugin.version}</version>
63+
<configuration>
64+
<excludes>
65+
<exclude>**/*IntegrationTest.java</exclude>
66+
<exclude>**/*LiveTest.java</exclude>
67+
</excludes>
68+
</configuration>
69+
</plugin>
70+
</plugins>
71+
</build>
72+
73+
<profiles>
74+
<profile>
75+
<id>integration</id>
76+
<build>
77+
<plugins>
78+
<plugin>
79+
<groupId>org.apache.maven.plugins</groupId>
80+
<artifactId>maven-surefire-plugin</artifactId>
81+
<executions>
82+
<execution>
83+
<phase>integration-test</phase>
84+
<goals>
85+
<goal>test</goal>
86+
</goals>
87+
<configuration>
88+
<excludes>
89+
<exclude>**/*LiveTest.java</exclude>
90+
</excludes>
91+
<includes>
92+
<include>**/*IntegrationTest.java</include>
93+
</includes>
94+
</configuration>
95+
</execution>
96+
</executions>
97+
<configuration>
98+
<systemPropertyVariables>
99+
<test.mime>json</test.mime>
100+
</systemPropertyVariables>
101+
</configuration>
102+
</plugin>
103+
</plugins>
104+
</build>
105+
</profile>
106+
</profiles>
69107
</project>

‎spring-data-solr/src/main/java/com/baeldung/spring/data/solr/model/Product.java‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ public class Product {
1414
@Indexed(name = "name", type = "string")
1515
private String name;
1616

17-
@Indexed(name = "category", type = "string")
18-
private String category;
19-
20-
@Indexed(name = "description", type = "string")
21-
private String description;
2217

2318
public String getId() {
2419
return id;
@@ -36,20 +31,4 @@ public void setName(String name) {
3631
this.name = name;
3732
}
3833

39-
public String getCategory() {
40-
return category;
41-
}
42-
43-
public void setCategory(String category) {
44-
this.category = category;
45-
}
46-
47-
public String getDescription() {
48-
return description;
49-
}
50-
51-
public void setDescription(String description) {
52-
this.description = description;
53-
}
54-
5534
}

‎spring-data-solr/src/main/java/com/baeldung/spring/data/solr/repository/ProductRepository.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
public interface ProductRepository extends SolrCrudRepository<Product, String> {
1313

14-
public List<Product> findByName(String name);
14+
public List<Product> findByName(String name);
1515

16-
@Query("name:*?0* OR category:*?0* OR description:*?0*")
17-
public Page<Product> findByCustomQuery(String searchTerm, Pageable pageable);
16+
@Query("name:*?0* OR description:*?0*")
17+
public Page<Product> findByCustomQuery(String searchTerm, Pageable pageable);
1818

19-
@Query(name = "Product.findByNamedQuery")
20-
public Page<Product> findByNamedQuery(String searchTerm, Pageable pageable);
19+
@Query(name = "Product.findByNamedQuery")
20+
public Page<Product> findByNamedQuery(String searchTerm, Pageable pageable);
2121

2222
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Product.findByNamedQuery=name:*?0* OR category:*?0* OR description:*?0*
1+
Product.findByNamedQuery=name:*?0* OR description:*?0*

‎spring-data-solr/src/test/java/com/baeldung/spring/data/solr/repo/ProductRepositoryIntegrationTest.java‎

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ public void whenSavingProduct_thenAvailableOnRetrieval() throws Exception {
3535
final Product product = new Product();
3636
product.setId("P000089998");
3737
product.setName("Desk");
38-
product.setCategory("Furniture");
39-
product.setDescription("New Desk");
4038
productRepository.save(product);
4139
final Product retrievedProduct = productRepository.findOne(product.getId());
4240
assertEquals(product.getId(), retrievedProduct.getId());
@@ -47,24 +45,21 @@ public void whenUpdatingProduct_thenChangeAvailableOnRetrieval() throws Exceptio
4745
final Product product = new Product();
4846
product.setId("P0001");
4947
product.setName("T-Shirt");
50-
product.setCategory("Kitchen");
51-
product.setDescription("New T-Shirt");
48+
5249
productRepository.save(product);
5350

54-
product.setCategory("Clothes");
51+
product.setName("Shirt");
5552
productRepository.save(product);
5653

5754
final Product retrievedProduct = productRepository.findOne(product.getId());
58-
assertEquals(product.getCategory(), retrievedProduct.getCategory());
55+
assertEquals(product.getName(), retrievedProduct.getName());
5956
}
6057

6158
@Test
6259
public void whenDeletingProduct_thenNotAvailableOnRetrieval() throws Exception {
6360
final Product product = new Product();
6461
product.setId("P0001");
6562
product.setName("Desk");
66-
product.setCategory("Furniture");
67-
product.setDescription("New Desk");
6863
productRepository.save(product);
6964

7065
productRepository.delete(product);
@@ -79,8 +74,6 @@ public void whenFindByName_thenAvailableOnRetrieval() throws Exception {
7974
Product phone = new Product();
8075
phone.setId("P0001");
8176
phone.setName("Phone");
82-
phone.setCategory("Electronics");
83-
phone.setDescription("New Phone");
8477
productRepository.save(phone);
8578

8679
List<Product> retrievedProducts = productRepository.findByName("Phone");
@@ -89,26 +82,20 @@ public void whenFindByName_thenAvailableOnRetrieval() throws Exception {
8982

9083
@Test
9184
public void whenSearchingProductsByQuery_thenAllMatchingProductsShouldAvialble() throws Exception {
92-
final Product phone = new Product();
93-
phone.setId("P0001");
94-
phone.setName("Smart Phone");
95-
phone.setCategory("Electronics");
96-
phone.setDescription("New Item");
97-
productRepository.save(phone);
98-
99-
final Product phoneCover = new Product();
100-
phoneCover.setId("P0002");
101-
phoneCover.setName("Cover");
102-
phoneCover.setCategory("Phone");
103-
phoneCover.setDescription("New Product");
104-
productRepository.save(phoneCover);
105-
106-
final Product wirelessCharger = new Product();
107-
wirelessCharger.setId("P0003");
108-
wirelessCharger.setName("Charging Cable");
109-
wirelessCharger.setCategory("Cable");
110-
wirelessCharger.setDescription("Wireless Charger for Phone");
111-
productRepository.save(wirelessCharger);
85+
final Product phone = new Product();
86+
phone.setId("P0001");
87+
phone.setName("Smart Phone");
88+
productRepository.save(phone);
89+
90+
final Product phoneCover = new Product();
91+
phoneCover.setId("P0002");
92+
phoneCover.setName("Phone Cover");
93+
productRepository.save(phoneCover);
94+
95+
final Product wirelessCharger = new Product();
96+
wirelessCharger.setId("P0003");
97+
wirelessCharger.setName("Phone Charging Cable");
98+
productRepository.save(wirelessCharger);
11299

113100
Page<Product> result = productRepository.findByCustomQuery("Phone", new PageRequest(0, 10));
114101
assertEquals(3, result.getNumberOfElements());
@@ -119,22 +106,16 @@ public void whenSearchingProductsByNamedQuery_thenAllMatchingProductsShouldAvial
119106
final Product phone = new Product();
120107
phone.setId("P0001");
121108
phone.setName("Smart Phone");
122-
phone.setCategory("Electronics");
123-
phone.setDescription("New Item");
124109
productRepository.save(phone);
125110

126111
final Product phoneCover = new Product();
127112
phoneCover.setId("P0002");
128-
phoneCover.setName("Cover");
129-
phoneCover.setCategory("Phone");
130-
phoneCover.setDescription("New Product");
113+
phoneCover.setName("Phone Cover");
131114
productRepository.save(phoneCover);
132115

133116
final Product wirelessCharger = new Product();
134117
wirelessCharger.setId("P0003");
135-
wirelessCharger.setName("Charging Cable");
136-
wirelessCharger.setCategory("Cable");
137-
wirelessCharger.setDescription("Wireless Charger for Phone");
118+
wirelessCharger.setName("Phone Charging Cable");
138119
productRepository.save(wirelessCharger);
139120

140121
Page<Product> result = productRepository.findByNamedQuery("one", new PageRequest(0, 10));

0 commit comments

Comments
 (0)