Commit d4a1365a authored by Stephane Nicoll's avatar Stephane Nicoll

Polish contribution

Closes gh-5444
parent 67f92bff
...@@ -21,22 +21,26 @@ ...@@ -21,22 +21,26 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId> <artifactId>spring-boot-starter-data-gemfire</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.shell</groupId>
<artifactId>spring-shell</artifactId>
<scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-gemfire</artifactId> <artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.shell</groupId>
<artifactId>spring-shell</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
......
/* /*
* Copyright 2010-2013 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -18,7 +18,11 @@ package sample.data.gemfire; ...@@ -18,7 +18,11 @@ package sample.data.gemfire;
import java.util.Properties; import java.util.Properties;
import org.springframework.beans.factory.annotation.Autowired; import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.RegionAttributes;
import sample.data.gemfire.config.SampleDataGemFireProperties;
import sample.data.gemfire.domain.Gemstone;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
...@@ -30,12 +34,6 @@ import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; ...@@ -30,12 +34,6 @@ import org.springframework.data.gemfire.ReplicatedRegionFactoryBean;
import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories; import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.RegionAttributes;
import sample.data.gemfire.config.SampleDataGemFireApplicationProperties;
import sample.data.gemfire.domain.Gemstone;
/** /**
* The GemstoneAppConfiguration class for allowing Spring Boot to pick up additional * The GemstoneAppConfiguration class for allowing Spring Boot to pick up additional
* application Spring configuration meta-data for GemFire, which must be specified in * application Spring configuration meta-data for GemFire, which must be specified in
...@@ -46,29 +44,21 @@ import sample.data.gemfire.domain.Gemstone; ...@@ -46,29 +44,21 @@ import sample.data.gemfire.domain.Gemstone;
@SpringBootApplication @SpringBootApplication
@EnableGemfireRepositories @EnableGemfireRepositories
@EnableTransactionManagement @EnableTransactionManagement
@EnableConfigurationProperties(SampleDataGemFireApplicationProperties.class) @EnableConfigurationProperties(SampleDataGemFireProperties.class)
@SuppressWarnings("unused")
public class SampleDataGemFireApplication { public class SampleDataGemFireApplication {
protected static final String GEMSTONES_REGION_NAME = "Gemstones"; protected static final String GEMSTONES_REGION_NAME = "Gemstones";
private final SampleDataGemFireProperties applicationProperties;
public SampleDataGemFireApplication(SampleDataGemFireProperties applicationProperties) {
this.applicationProperties = applicationProperties;
}
public static void main(final String[] args) { public static void main(final String[] args) {
SpringApplication.run(SampleDataGemFireApplication.class, args); SpringApplication.run(SampleDataGemFireApplication.class, args);
} }
@Autowired
SampleDataGemFireApplicationProperties applicationProperties;
Properties gemfireProperties() {
Properties gemfireProperties = new Properties();
gemfireProperties.setProperty("name", SampleDataGemFireApplication.class.getSimpleName());
gemfireProperties.setProperty("mcast-port", "0");
gemfireProperties.setProperty("locators", "");
gemfireProperties.setProperty("log-level", applicationProperties.getLogLevel());
return gemfireProperties;
}
@Bean @Bean
CacheFactoryBean gemfireCache() { CacheFactoryBean gemfireCache() {
...@@ -80,12 +70,23 @@ public class SampleDataGemFireApplication { ...@@ -80,12 +70,23 @@ public class SampleDataGemFireApplication {
return gemfireCache; return gemfireCache;
} }
private Properties gemfireProperties() {
Properties gemfireProperties = new Properties();
gemfireProperties.setProperty("name", SampleDataGemFireApplication.class.getSimpleName());
gemfireProperties.setProperty("mcast-port", "0");
gemfireProperties.setProperty("locators", "");
gemfireProperties.setProperty("log-level", this.applicationProperties.getLogLevel());
return gemfireProperties;
}
@Bean(name = GEMSTONES_REGION_NAME) @Bean(name = GEMSTONES_REGION_NAME)
ReplicatedRegionFactoryBean<Long, Gemstone> gemstonesRegion(Cache gemfireCache, ReplicatedRegionFactoryBean<Long, Gemstone> gemstonesRegion(Cache gemfireCache,
RegionAttributes<Long, Gemstone> gemstonesRegionAttributes) { RegionAttributes<Long, Gemstone> gemstonesRegionAttributes) {
ReplicatedRegionFactoryBean<Long, Gemstone> gemstonesRegion = ReplicatedRegionFactoryBean<Long, Gemstone> gemstonesRegion =
new ReplicatedRegionFactoryBean<Long, Gemstone>(); new ReplicatedRegionFactoryBean<Long, Gemstone>();
gemstonesRegion.setAttributes(gemstonesRegionAttributes); gemstonesRegion.setAttributes(gemstonesRegionAttributes);
gemstonesRegion.setClose(false); gemstonesRegion.setClose(false);
...@@ -100,7 +101,7 @@ public class SampleDataGemFireApplication { ...@@ -100,7 +101,7 @@ public class SampleDataGemFireApplication {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
RegionAttributesFactoryBean gemstonesRegionAttributes() { RegionAttributesFactoryBean gemstonesRegionAttributes() {
RegionAttributesFactoryBean gemstonesRegionAttributes = RegionAttributesFactoryBean gemstonesRegionAttributes =
new RegionAttributesFactoryBean(); new RegionAttributesFactoryBean();
gemstonesRegionAttributes.setKeyConstraint(Long.class); gemstonesRegionAttributes.setKeyConstraint(Long.class);
gemstonesRegionAttributes.setValueConstraint(Gemstone.class); gemstonesRegionAttributes.setValueConstraint(Gemstone.class);
......
/* /*
* Copyright 2010-2013 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
...@@ -17,27 +17,22 @@ ...@@ -17,27 +17,22 @@
package sample.data.gemfire.config; package sample.data.gemfire.config;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.StringUtils;
/** /**
* The SampleDataGemFireApplicationProperties class... * Configuration properties for Gemfire sample.
* *
* @author John Blum * @author John Blum
* @since 1.0.0
*/ */
@ConfigurationProperties(prefix = "sample.data.gemfire") @ConfigurationProperties(prefix = "sample.data.gemfire")
public class SampleDataGemFireApplicationProperties { public class SampleDataGemFireProperties {
protected static final String DEFAULT_LOG_LEVEL = "config"; /**
* Caching log level.
private String logLevel = DEFAULT_LOG_LEVEL; */
private String logLevel = "config";
protected String defaultIfEmpty(String value, String defaultValue) {
return (StringUtils.hasText(value) ? value : defaultValue);
}
public String getLogLevel() { public String getLogLevel() {
return defaultIfEmpty(this.logLevel, DEFAULT_LOG_LEVEL); return this.logLevel;
} }
public void setLogLevel(String logLevel) { public void setLogLevel(String logLevel) {
......
/* /*
* Copyright 2010-2013 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
/* /*
* Copyright 2010-2015 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -19,15 +19,16 @@ package sample.data.gemfire.service; ...@@ -19,15 +19,16 @@ package sample.data.gemfire.service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import sample.data.gemfire.domain.Gemstone;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import sample.data.gemfire.domain.Gemstone;
/** /**
* The GemstoneServiceImpl class is a Service object implementing the GemstoneService * The GemstoneServiceImpl class is a Service object implementing the GemstoneService
* interface containing business logic and rules in addition to data services for * interface containing business logic and rules in addition to data services for
...@@ -39,16 +40,17 @@ import sample.data.gemfire.domain.Gemstone; ...@@ -39,16 +40,17 @@ import sample.data.gemfire.domain.Gemstone;
public class GemstoneServiceImpl implements GemstoneService { public class GemstoneServiceImpl implements GemstoneService {
protected static final List<String> APPROVED_GEMS = new ArrayList<String>( protected static final List<String> APPROVED_GEMS = new ArrayList<String>(
Arrays.asList("ALEXANDRITE", "AQUAMARINE", "DIAMOND", "OPAL", "PEARL", "RUBY", Arrays.asList("ALEXANDRITE", "AQUAMARINE", "DIAMOND", "OPAL", "PEARL", "RUBY",
"SAPPHIRE", "SPINEL", "TOPAZ")); "SAPPHIRE", "SPINEL", "TOPAZ"));
private final GemstoneRepository gemstoneRepository;
@Autowired public GemstoneServiceImpl(GemstoneRepository gemstoneRepository) {
@SuppressWarnings("unused") this.gemstoneRepository = gemstoneRepository;
private GemstoneRepository gemstoneRepository; }
@PostConstruct @PostConstruct
public void init() { public void init() {
Assert.notNull(gemstoneRepository, "'gemstoneRepository' was not properly initialized");
System.out.printf("[%1$s] initialized!%n", getClass().getSimpleName()); System.out.printf("[%1$s] initialized!%n", getClass().getSimpleName());
} }
...@@ -126,7 +128,7 @@ public class GemstoneServiceImpl implements GemstoneService { ...@@ -126,7 +128,7 @@ public class GemstoneServiceImpl implements GemstoneService {
Gemstone savedGemstone = validate(this.gemstoneRepository.save(gemstone)); Gemstone savedGemstone = validate(this.gemstoneRepository.save(gemstone));
Assert.state(savedGemstone.equals(get(gemstone.getId())), String.format( Assert.state(savedGemstone.equals(get(gemstone.getId())), String.format(
"Failed to find Gemstone (%1$s) in GemFire's Cache Region 'Gemstones'!", "Failed to find Gemstone (%1$s) in GemFire's Cache Region 'Gemstones'!",
gemstone)); gemstone));
System.out.printf("Saved Gemstone [%1$s]%n", savedGemstone.getName()); System.out.printf("Saved Gemstone [%1$s]%n", savedGemstone.getName());
...@@ -146,24 +148,12 @@ public class GemstoneServiceImpl implements GemstoneService { ...@@ -146,24 +148,12 @@ public class GemstoneServiceImpl implements GemstoneService {
return gemstone; return gemstone;
} }
@SuppressWarnings("unused")
public static final class IllegalGemstoneException extends IllegalArgumentException { public static final class IllegalGemstoneException extends IllegalArgumentException {
public IllegalGemstoneException() { public IllegalGemstoneException(String message) {
}
public IllegalGemstoneException(final String message) {
super(message); super(message);
} }
public IllegalGemstoneException(final Throwable cause) {
super(cause);
}
public IllegalGemstoneException(final String message, final Throwable cause) {
super(message, cause);
}
} }
} }
...@@ -16,24 +16,22 @@ ...@@ -16,24 +16,22 @@
package sample.data.gemfire; package sample.data.gemfire;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import sample.data.gemfire.domain.Gemstone;
import sample.data.gemfire.service.GemstoneService;
import sample.data.gemfire.service.GemstoneServiceImpl.IllegalGemstoneException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import sample.data.gemfire.domain.Gemstone; import static org.assertj.core.api.Assertions.assertThat;
import sample.data.gemfire.service.GemstoneService;
import sample.data.gemfire.service.GemstoneServiceImpl.IllegalGemstoneException;
/** /**
* The SampleDataGemFireApplicationTests class is a test suite with test cases testing the * Tests for {@link SampleDataGemFireApplication}.
* SampleDataGemFireApplication in Spring Boot.
* *
* @author John Blum * @author John Blum
*/ */
...@@ -42,15 +40,9 @@ import sample.data.gemfire.service.GemstoneServiceImpl.IllegalGemstoneException; ...@@ -42,15 +40,9 @@ import sample.data.gemfire.service.GemstoneServiceImpl.IllegalGemstoneException;
public class SampleDataGemFireApplicationTests { public class SampleDataGemFireApplicationTests {
@Autowired @Autowired
@SuppressWarnings("unused")
private GemstoneService gemstoneService; private GemstoneService gemstoneService;
private final AtomicLong idGenerator = new AtomicLong(0l); private final AtomicLong idGenerator = new AtomicLong(0L);
@Before
public void setup() {
assertThat(this.gemstoneService).isNotNull();
}
@Test @Test
public void gemstonesAppServiceEndpoints() { public void gemstonesAppServiceEndpoints() {
...@@ -62,7 +54,7 @@ public class SampleDataGemFireApplicationTests { ...@@ -62,7 +54,7 @@ public class SampleDataGemFireApplicationTests {
assertThat(this.gemstoneService.count()).isEqualTo(2); assertThat(this.gemstoneService.count()).isEqualTo(2);
assertThat(this.gemstoneService.list()).contains( assertThat(this.gemstoneService.list()).contains(
getGemstones("Diamond", "Ruby")); getGemstones("Diamond", "Ruby"));
try { try {
this.gemstoneService.save(createGemstone("Coal")); this.gemstoneService.save(createGemstone("Coal"));
...@@ -73,14 +65,14 @@ public class SampleDataGemFireApplicationTests { ...@@ -73,14 +65,14 @@ public class SampleDataGemFireApplicationTests {
assertThat(this.gemstoneService.count()).isEqualTo(2); assertThat(this.gemstoneService.count()).isEqualTo(2);
assertThat(this.gemstoneService.list()).contains( assertThat(this.gemstoneService.list()).contains(
getGemstones("Diamond", "Ruby")); getGemstones("Diamond", "Ruby"));
this.gemstoneService.save(createGemstone("Pearl")); this.gemstoneService.save(createGemstone("Pearl"));
this.gemstoneService.save(createGemstone("Sapphire")); this.gemstoneService.save(createGemstone("Sapphire"));
assertThat(this.gemstoneService.count()).isEqualTo(4); assertThat(this.gemstoneService.count()).isEqualTo(4);
assertThat(this.gemstoneService.list()).contains( assertThat(this.gemstoneService.list()).contains(
getGemstones("Diamond", "Ruby", "Pearl", "Sapphire")); getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"));
try { try {
this.gemstoneService.save(createGemstone("Quartz")); this.gemstoneService.save(createGemstone("Quartz"));
...@@ -91,11 +83,11 @@ public class SampleDataGemFireApplicationTests { ...@@ -91,11 +83,11 @@ public class SampleDataGemFireApplicationTests {
assertThat(this.gemstoneService.count()).isEqualTo(4); assertThat(this.gemstoneService.count()).isEqualTo(4);
assertThat(this.gemstoneService.list()).contains( assertThat(this.gemstoneService.list()).contains(
getGemstones("Diamond", "Ruby", "Pearl", "Sapphire")); getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"));
assertThat(this.gemstoneService.get("Diamond")).isEqualTo( assertThat(this.gemstoneService.get("Diamond")).isEqualTo(
createGemstone("Diamond")); createGemstone("Diamond"));
assertThat(this.gemstoneService.get("Pearl")).isEqualTo( assertThat(this.gemstoneService.get("Pearl")).isEqualTo(
createGemstone("Pearl")); createGemstone("Pearl"));
} }
private Gemstone[] getGemstones(String... names) { private Gemstone[] getGemstones(String... names) {
......
...@@ -8,9 +8,8 @@ ...@@ -8,9 +8,8 @@
</parent> </parent>
<artifactId>spring-boot-starter-data-gemfire</artifactId> <artifactId>spring-boot-starter-data-gemfire</artifactId>
<name>Spring Boot Data GemFire Starter</name> <name>Spring Boot Data GemFire Starter</name>
<description> <description>Starter for using GemFire distributed data store and Spring Data
Starter for using GemFire distributed data store and Spring Data GemFire. GemFire</description>
</description>
<url>http://projects.spring.io/spring-boot/</url> <url>http://projects.spring.io/spring-boot/</url>
<organization> <organization>
<name>Pivotal Software, Inc.</name> <name>Pivotal Software, Inc.</name>
...@@ -38,7 +37,6 @@ ...@@ -38,7 +37,6 @@
<repositories> <repositories>
<repository> <repository>
<id>repo.spring.io</id> <id>repo.spring.io</id>
<name>Spring libs-release Maven Repository</name>
<url>http://repo.spring.io/libs-release</url> <url>http://repo.spring.io/libs-release</url>
<releases> <releases>
<enabled>true</enabled> <enabled>true</enabled>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment