Skip to content

Commit 046b236

Browse files
committed
formatting changes
1 parent 8ccfd20 commit 046b236

5 files changed

Lines changed: 170 additions & 171 deletions

File tree

‎spring-data-solr/pom.xml‎

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
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>
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>
5353

5454
<build>
5555
<plugins>

‎spring-data-solr/src/main/java/com/baeldung/spring/data/solr/config/SolrConfig.java‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
@ComponentScan
1414
public class SolrConfig {
1515

16-
@Bean
17-
public SolrClient solrClient() {
18-
return new HttpSolrClient("http://localhost:8983/solr");
19-
}
16+
@Bean
17+
public SolrClient solrClient() {
18+
return new HttpSolrClient("http://localhost:8983/solr");
19+
}
2020

21-
@Bean
22-
public SolrTemplate solrTemplate(SolrClient client) throws Exception {
23-
return new SolrTemplate(client);
24-
}
21+
@Bean
22+
public SolrTemplate solrTemplate(SolrClient client) throws Exception {
23+
return new SolrTemplate(client);
24+
}
2525
}

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,28 @@
66

77
@SolrDocument(solrCoreName = "product")
88
public class Product {
9-
9+
1010
@Id
1111
@Indexed(name = "id", type = "string")
1212
private String id;
13-
13+
1414
@Indexed(name = "name", type = "string")
1515
private String name;
16-
17-
16+
1817
public String getId() {
1918
return id;
2019
}
21-
20+
2221
public void setId(String id) {
2322
this.id = id;
2423
}
25-
24+
2625
public String getName() {
2726
return name;
2827
}
29-
28+
3029
public void setName(String name) {
3130
this.name = name;
3231
}
33-
32+
3433
}

‎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("id:*?0* OR name:*?0*")
17-
public Page<Product> findByCustomQuery(String searchTerm, Pageable pageable);
16+
@Query("id:*?0* OR name:*?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
}

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

Lines changed: 99 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -22,104 +22,104 @@
2222
@ContextConfiguration(classes = SolrConfig.class)
2323
public class ProductRepositoryIntegrationTest {
2424

25-
@Autowired
26-
private ProductRepository productRepository;
27-
28-
@Before
29-
public void clearSolrData() {
30-
productRepository.deleteAll();
31-
}
32-
33-
@Test
34-
public void whenSavingProduct_thenAvailableOnRetrieval() throws Exception {
35-
final Product product = new Product();
36-
product.setId("P000089998");
37-
product.setName("Desk");
38-
productRepository.save(product);
39-
final Product retrievedProduct = productRepository.findOne(product.getId());
40-
assertEquals(product.getId(), retrievedProduct.getId());
41-
}
42-
43-
@Test
44-
public void whenUpdatingProduct_thenChangeAvailableOnRetrieval() throws Exception {
45-
final Product product = new Product();
46-
product.setId("P0001");
47-
product.setName("T-Shirt");
48-
49-
productRepository.save(product);
50-
51-
product.setName("Shirt");
52-
productRepository.save(product);
53-
54-
final Product retrievedProduct = productRepository.findOne(product.getId());
55-
assertEquals(product.getName(), retrievedProduct.getName());
56-
}
57-
58-
@Test
59-
public void whenDeletingProduct_thenNotAvailableOnRetrieval() throws Exception {
60-
final Product product = new Product();
61-
product.setId("P0001");
62-
product.setName("Desk");
63-
productRepository.save(product);
64-
65-
productRepository.delete(product);
66-
67-
Product retrievedProduct = productRepository.findOne(product.getId());
68-
assertNull(retrievedProduct);
69-
70-
}
71-
72-
@Test
73-
public void whenFindByName_thenAvailableOnRetrieval() throws Exception {
74-
Product phone = new Product();
75-
phone.setId("P0001");
76-
phone.setName("Phone");
77-
productRepository.save(phone);
78-
79-
List<Product> retrievedProducts = productRepository.findByName("Phone");
80-
assertEquals(phone.getId(), retrievedProducts.get(0).getId());
81-
}
82-
83-
@Test
84-
public void whenSearchingProductsByQuery_thenAllMatchingProductsShouldAvialble() throws Exception {
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);
99-
100-
Page<Product> result = productRepository.findByCustomQuery("Phone", new PageRequest(0, 10));
101-
assertEquals(3, result.getNumberOfElements());
102-
}
103-
104-
@Test
105-
public void whenSearchingProductsByNamedQuery_thenAllMatchingProductsShouldAvialble() throws Exception {
106-
final Product phone = new Product();
107-
phone.setId("P0001");
108-
phone.setName("Smart Phone");
109-
productRepository.save(phone);
110-
111-
final Product phoneCover = new Product();
112-
phoneCover.setId("P0002");
113-
phoneCover.setName("Phone Cover");
114-
productRepository.save(phoneCover);
115-
116-
final Product wirelessCharger = new Product();
117-
wirelessCharger.setId("P0003");
118-
wirelessCharger.setName("Phone Charging Cable");
119-
productRepository.save(wirelessCharger);
120-
121-
Page<Product> result = productRepository.findByNamedQuery("one", new PageRequest(0, 10));
122-
assertEquals(3, result.getNumberOfElements());
123-
}
25+
@Autowired
26+
private ProductRepository productRepository;
27+
28+
@Before
29+
public void clearSolrData() {
30+
productRepository.deleteAll();
31+
}
32+
33+
@Test
34+
public void whenSavingProduct_thenAvailableOnRetrieval() throws Exception {
35+
final Product product = new Product();
36+
product.setId("P000089998");
37+
product.setName("Desk");
38+
productRepository.save(product);
39+
final Product retrievedProduct = productRepository.findOne(product.getId());
40+
assertEquals(product.getId(), retrievedProduct.getId());
41+
}
42+
43+
@Test
44+
public void whenUpdatingProduct_thenChangeAvailableOnRetrieval() throws Exception {
45+
final Product product = new Product();
46+
product.setId("P0001");
47+
product.setName("T-Shirt");
48+
49+
productRepository.save(product);
50+
51+
product.setName("Shirt");
52+
productRepository.save(product);
53+
54+
final Product retrievedProduct = productRepository.findOne(product.getId());
55+
assertEquals(product.getName(), retrievedProduct.getName());
56+
}
57+
58+
@Test
59+
public void whenDeletingProduct_thenNotAvailableOnRetrieval() throws Exception {
60+
final Product product = new Product();
61+
product.setId("P0001");
62+
product.setName("Desk");
63+
productRepository.save(product);
64+
65+
productRepository.delete(product);
66+
67+
Product retrievedProduct = productRepository.findOne(product.getId());
68+
assertNull(retrievedProduct);
69+
70+
}
71+
72+
@Test
73+
public void whenFindByName_thenAvailableOnRetrieval() throws Exception {
74+
Product phone = new Product();
75+
phone.setId("P0001");
76+
phone.setName("Phone");
77+
productRepository.save(phone);
78+
79+
List<Product> retrievedProducts = productRepository.findByName("Phone");
80+
assertEquals(phone.getId(), retrievedProducts.get(0).getId());
81+
}
82+
83+
@Test
84+
public void whenSearchingProductsByQuery_thenAllMatchingProductsShouldAvialble() throws Exception {
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);
99+
100+
Page<Product> result = productRepository.findByCustomQuery("Phone", new PageRequest(0, 10));
101+
assertEquals(3, result.getNumberOfElements());
102+
}
103+
104+
@Test
105+
public void whenSearchingProductsByNamedQuery_thenAllMatchingProductsShouldAvialble() throws Exception {
106+
final Product phone = new Product();
107+
phone.setId("P0001");
108+
phone.setName("Smart Phone");
109+
productRepository.save(phone);
110+
111+
final Product phoneCover = new Product();
112+
phoneCover.setId("P0002");
113+
phoneCover.setName("Phone Cover");
114+
productRepository.save(phoneCover);
115+
116+
final Product wirelessCharger = new Product();
117+
wirelessCharger.setId("P0003");
118+
wirelessCharger.setName("Phone Charging Cable");
119+
productRepository.save(wirelessCharger);
120+
121+
Page<Product> result = productRepository.findByNamedQuery("one", new PageRequest(0, 10));
122+
assertEquals(3, result.getNumberOfElements());
123+
}
124124

125125
}

0 commit comments

Comments
 (0)