Skip to content

Commit d4a1365

Browse files
committed
Polish contribution
Closes gh-5444
1 parent 67f92bf commit d4a1365

File tree

7 files changed

+75
-95
lines changed

7 files changed

+75
-95
lines changed

spring-boot-samples/spring-boot-sample-data-gemfire/pom.xml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,26 @@
2121
<dependencies>
2222
<dependency>
2323
<groupId>org.springframework.boot</groupId>
24-
<artifactId>spring-boot-starter</artifactId>
24+
<artifactId>spring-boot-starter-data-gemfire</artifactId>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>org.springframework.shell</groupId>
29+
<artifactId>spring-shell</artifactId>
30+
<scope>runtime</scope>
2531
</dependency>
32+
2633
<dependency>
2734
<groupId>org.springframework.boot</groupId>
28-
<artifactId>spring-boot-starter-data-gemfire</artifactId>
35+
<artifactId>spring-boot-configuration-processor</artifactId>
36+
<optional>true</optional>
2937
</dependency>
38+
3039
<dependency>
3140
<groupId>org.springframework.boot</groupId>
3241
<artifactId>spring-boot-starter-test</artifactId>
3342
<scope>test</scope>
3443
</dependency>
35-
<dependency>
36-
<groupId>org.springframework.shell</groupId>
37-
<artifactId>spring-shell</artifactId>
38-
<scope>runtime</scope>
39-
</dependency>
4044
</dependencies>
4145
<build>
4246
<plugins>

spring-boot-samples/spring-boot-sample-data-gemfire/src/main/java/sample/data/gemfire/SampleDataGemFireApplication.java

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2013 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,11 @@
1818

1919
import java.util.Properties;
2020

21-
import org.springframework.beans.factory.annotation.Autowired;
21+
import com.gemstone.gemfire.cache.Cache;
22+
import com.gemstone.gemfire.cache.RegionAttributes;
23+
import sample.data.gemfire.config.SampleDataGemFireProperties;
24+
import sample.data.gemfire.domain.Gemstone;
25+
2226
import org.springframework.boot.SpringApplication;
2327
import org.springframework.boot.autoconfigure.SpringBootApplication;
2428
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -30,12 +34,6 @@
3034
import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories;
3135
import org.springframework.transaction.annotation.EnableTransactionManagement;
3236

33-
import com.gemstone.gemfire.cache.Cache;
34-
import com.gemstone.gemfire.cache.RegionAttributes;
35-
36-
import sample.data.gemfire.config.SampleDataGemFireApplicationProperties;
37-
import sample.data.gemfire.domain.Gemstone;
38-
3937
/**
4038
* The GemstoneAppConfiguration class for allowing Spring Boot to pick up additional
4139
* application Spring configuration meta-data for GemFire, which must be specified in
@@ -46,29 +44,21 @@
4644
@SpringBootApplication
4745
@EnableGemfireRepositories
4846
@EnableTransactionManagement
49-
@EnableConfigurationProperties(SampleDataGemFireApplicationProperties.class)
50-
@SuppressWarnings("unused")
47+
@EnableConfigurationProperties(SampleDataGemFireProperties.class)
5148
public class SampleDataGemFireApplication {
5249

5350
protected static final String GEMSTONES_REGION_NAME = "Gemstones";
5451

52+
private final SampleDataGemFireProperties applicationProperties;
53+
54+
public SampleDataGemFireApplication(SampleDataGemFireProperties applicationProperties) {
55+
this.applicationProperties = applicationProperties;
56+
}
57+
5558
public static void main(final String[] args) {
5659
SpringApplication.run(SampleDataGemFireApplication.class, args);
5760
}
5861

59-
@Autowired
60-
SampleDataGemFireApplicationProperties applicationProperties;
61-
62-
Properties gemfireProperties() {
63-
Properties gemfireProperties = new Properties();
64-
65-
gemfireProperties.setProperty("name", SampleDataGemFireApplication.class.getSimpleName());
66-
gemfireProperties.setProperty("mcast-port", "0");
67-
gemfireProperties.setProperty("locators", "");
68-
gemfireProperties.setProperty("log-level", applicationProperties.getLogLevel());
69-
70-
return gemfireProperties;
71-
}
7262

7363
@Bean
7464
CacheFactoryBean gemfireCache() {
@@ -80,12 +70,23 @@ CacheFactoryBean gemfireCache() {
8070
return gemfireCache;
8171
}
8272

73+
private Properties gemfireProperties() {
74+
Properties gemfireProperties = new Properties();
75+
76+
gemfireProperties.setProperty("name", SampleDataGemFireApplication.class.getSimpleName());
77+
gemfireProperties.setProperty("mcast-port", "0");
78+
gemfireProperties.setProperty("locators", "");
79+
gemfireProperties.setProperty("log-level", this.applicationProperties.getLogLevel());
80+
81+
return gemfireProperties;
82+
}
83+
8384
@Bean(name = GEMSTONES_REGION_NAME)
8485
ReplicatedRegionFactoryBean<Long, Gemstone> gemstonesRegion(Cache gemfireCache,
8586
RegionAttributes<Long, Gemstone> gemstonesRegionAttributes) {
8687

8788
ReplicatedRegionFactoryBean<Long, Gemstone> gemstonesRegion =
88-
new ReplicatedRegionFactoryBean<Long, Gemstone>();
89+
new ReplicatedRegionFactoryBean<Long, Gemstone>();
8990

9091
gemstonesRegion.setAttributes(gemstonesRegionAttributes);
9192
gemstonesRegion.setClose(false);
@@ -100,7 +101,7 @@ ReplicatedRegionFactoryBean<Long, Gemstone> gemstonesRegion(Cache gemfireCache,
100101
@SuppressWarnings("unchecked")
101102
RegionAttributesFactoryBean gemstonesRegionAttributes() {
102103
RegionAttributesFactoryBean gemstonesRegionAttributes =
103-
new RegionAttributesFactoryBean();
104+
new RegionAttributesFactoryBean();
104105

105106
gemstonesRegionAttributes.setKeyConstraint(Long.class);
106107
gemstonesRegionAttributes.setValueConstraint(Gemstone.class);
Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2010-2013 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,27 +17,22 @@
1717
package sample.data.gemfire.config;
1818

1919
import org.springframework.boot.context.properties.ConfigurationProperties;
20-
import org.springframework.util.StringUtils;
2120

2221
/**
23-
* The SampleDataGemFireApplicationProperties class...
22+
* Configuration properties for Gemfire sample.
2423
*
2524
* @author John Blum
26-
* @since 1.0.0
2725
*/
2826
@ConfigurationProperties(prefix = "sample.data.gemfire")
29-
public class SampleDataGemFireApplicationProperties {
27+
public class SampleDataGemFireProperties {
3028

31-
protected static final String DEFAULT_LOG_LEVEL = "config";
32-
33-
private String logLevel = DEFAULT_LOG_LEVEL;
34-
35-
protected String defaultIfEmpty(String value, String defaultValue) {
36-
return (StringUtils.hasText(value) ? value : defaultValue);
37-
}
29+
/**
30+
* Caching log level.
31+
*/
32+
private String logLevel = "config";
3833

3934
public String getLogLevel() {
40-
return defaultIfEmpty(this.logLevel, DEFAULT_LOG_LEVEL);
35+
return this.logLevel;
4136
}
4237

4338
public void setLogLevel(String logLevel) {

spring-boot-samples/spring-boot-sample-data-gemfire/src/main/java/sample/data/gemfire/domain/Gemstone.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2013 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-boot-samples/spring-boot-sample-data-gemfire/src/main/java/sample/data/gemfire/service/GemstoneServiceImpl.java

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2015 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,15 +19,16 @@
1919
import java.util.ArrayList;
2020
import java.util.Arrays;
2121
import java.util.List;
22+
2223
import javax.annotation.PostConstruct;
2324

25+
import sample.data.gemfire.domain.Gemstone;
26+
2427
import org.springframework.beans.factory.annotation.Autowired;
2528
import org.springframework.stereotype.Service;
2629
import org.springframework.transaction.annotation.Transactional;
2730
import org.springframework.util.Assert;
2831

29-
import sample.data.gemfire.domain.Gemstone;
30-
3132
/**
3233
* The GemstoneServiceImpl class is a Service object implementing the GemstoneService
3334
* interface containing business logic and rules in addition to data services for
@@ -39,16 +40,17 @@
3940
public class GemstoneServiceImpl implements GemstoneService {
4041

4142
protected static final List<String> APPROVED_GEMS = new ArrayList<String>(
42-
Arrays.asList("ALEXANDRITE", "AQUAMARINE", "DIAMOND", "OPAL", "PEARL", "RUBY",
43-
"SAPPHIRE", "SPINEL", "TOPAZ"));
43+
Arrays.asList("ALEXANDRITE", "AQUAMARINE", "DIAMOND", "OPAL", "PEARL", "RUBY",
44+
"SAPPHIRE", "SPINEL", "TOPAZ"));
45+
46+
private final GemstoneRepository gemstoneRepository;
4447

45-
@Autowired
46-
@SuppressWarnings("unused")
47-
private GemstoneRepository gemstoneRepository;
48+
public GemstoneServiceImpl(GemstoneRepository gemstoneRepository) {
49+
this.gemstoneRepository = gemstoneRepository;
50+
}
4851

4952
@PostConstruct
5053
public void init() {
51-
Assert.notNull(gemstoneRepository, "'gemstoneRepository' was not properly initialized");
5254
System.out.printf("[%1$s] initialized!%n", getClass().getSimpleName());
5355
}
5456

@@ -126,7 +128,7 @@ public Gemstone save(Gemstone gemstone) {
126128
Gemstone savedGemstone = validate(this.gemstoneRepository.save(gemstone));
127129

128130
Assert.state(savedGemstone.equals(get(gemstone.getId())), String.format(
129-
"Failed to find Gemstone (%1$s) in GemFire's Cache Region 'Gemstones'!",
131+
"Failed to find Gemstone (%1$s) in GemFire's Cache Region 'Gemstones'!",
130132
gemstone));
131133

132134
System.out.printf("Saved Gemstone [%1$s]%n", savedGemstone.getName());
@@ -146,24 +148,12 @@ Gemstone validate(Gemstone gemstone) {
146148
return gemstone;
147149
}
148150

149-
@SuppressWarnings("unused")
150151
public static final class IllegalGemstoneException extends IllegalArgumentException {
151152

152-
public IllegalGemstoneException() {
153-
}
154-
155-
public IllegalGemstoneException(final String message) {
153+
public IllegalGemstoneException(String message) {
156154
super(message);
157155
}
158156

159-
public IllegalGemstoneException(final Throwable cause) {
160-
super(cause);
161-
}
162-
163-
public IllegalGemstoneException(final String message, final Throwable cause) {
164-
super(message, cause);
165-
}
166-
167157
}
168158

169159
}

spring-boot-samples/spring-boot-sample-data-gemfire/src/test/java/sample/data/gemfire/SampleDataGemFireApplicationTests.java

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,22 @@
1616

1717
package sample.data.gemfire;
1818

19-
import static org.assertj.core.api.Assertions.assertThat;
20-
2119
import java.util.concurrent.atomic.AtomicLong;
2220

23-
import org.junit.Before;
2421
import org.junit.Test;
2522
import org.junit.runner.RunWith;
23+
import sample.data.gemfire.domain.Gemstone;
24+
import sample.data.gemfire.service.GemstoneService;
25+
import sample.data.gemfire.service.GemstoneServiceImpl.IllegalGemstoneException;
26+
2627
import org.springframework.beans.factory.annotation.Autowired;
2728
import org.springframework.boot.test.context.SpringBootTest;
2829
import org.springframework.test.context.junit4.SpringRunner;
2930

30-
import sample.data.gemfire.domain.Gemstone;
31-
import sample.data.gemfire.service.GemstoneService;
32-
import sample.data.gemfire.service.GemstoneServiceImpl.IllegalGemstoneException;
31+
import static org.assertj.core.api.Assertions.assertThat;
3332

3433
/**
35-
* The SampleDataGemFireApplicationTests class is a test suite with test cases testing the
36-
* SampleDataGemFireApplication in Spring Boot.
34+
* Tests for {@link SampleDataGemFireApplication}.
3735
*
3836
* @author John Blum
3937
*/
@@ -42,15 +40,9 @@
4240
public class SampleDataGemFireApplicationTests {
4341

4442
@Autowired
45-
@SuppressWarnings("unused")
4643
private GemstoneService gemstoneService;
4744

48-
private final AtomicLong idGenerator = new AtomicLong(0l);
49-
50-
@Before
51-
public void setup() {
52-
assertThat(this.gemstoneService).isNotNull();
53-
}
45+
private final AtomicLong idGenerator = new AtomicLong(0L);
5446

5547
@Test
5648
public void gemstonesAppServiceEndpoints() {
@@ -62,7 +54,7 @@ public void gemstonesAppServiceEndpoints() {
6254

6355
assertThat(this.gemstoneService.count()).isEqualTo(2);
6456
assertThat(this.gemstoneService.list()).contains(
65-
getGemstones("Diamond", "Ruby"));
57+
getGemstones("Diamond", "Ruby"));
6658

6759
try {
6860
this.gemstoneService.save(createGemstone("Coal"));
@@ -73,14 +65,14 @@ public void gemstonesAppServiceEndpoints() {
7365

7466
assertThat(this.gemstoneService.count()).isEqualTo(2);
7567
assertThat(this.gemstoneService.list()).contains(
76-
getGemstones("Diamond", "Ruby"));
68+
getGemstones("Diamond", "Ruby"));
7769

7870
this.gemstoneService.save(createGemstone("Pearl"));
7971
this.gemstoneService.save(createGemstone("Sapphire"));
8072

8173
assertThat(this.gemstoneService.count()).isEqualTo(4);
8274
assertThat(this.gemstoneService.list()).contains(
83-
getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"));
75+
getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"));
8476

8577
try {
8678
this.gemstoneService.save(createGemstone("Quartz"));
@@ -91,11 +83,11 @@ public void gemstonesAppServiceEndpoints() {
9183

9284
assertThat(this.gemstoneService.count()).isEqualTo(4);
9385
assertThat(this.gemstoneService.list()).contains(
94-
getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"));
86+
getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"));
9587
assertThat(this.gemstoneService.get("Diamond")).isEqualTo(
96-
createGemstone("Diamond"));
88+
createGemstone("Diamond"));
9789
assertThat(this.gemstoneService.get("Pearl")).isEqualTo(
98-
createGemstone("Pearl"));
90+
createGemstone("Pearl"));
9991
}
10092

10193
private Gemstone[] getGemstones(String... names) {

spring-boot-starters/spring-boot-starter-data-gemfire/pom.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
</parent>
99
<artifactId>spring-boot-starter-data-gemfire</artifactId>
1010
<name>Spring Boot Data GemFire Starter</name>
11-
<description>
12-
Starter for using GemFire distributed data store and Spring Data GemFire.
13-
</description>
11+
<description>Starter for using GemFire distributed data store and Spring Data
12+
GemFire</description>
1413
<url>http://projects.spring.io/spring-boot/</url>
1514
<organization>
1615
<name>Pivotal Software, Inc.</name>
@@ -38,7 +37,6 @@
3837
<repositories>
3938
<repository>
4039
<id>repo.spring.io</id>
41-
<name>Spring libs-release Maven Repository</name>
4240
<url>http://repo.spring.io/libs-release</url>
4341
<releases>
4442
<enabled>true</enabled>

0 commit comments

Comments
 (0)