Polish Pivotal GemFire starter and sample
Closes gh-5439
This commit is contained in:
committed by
Stephane Nicoll
parent
63a3d003dd
commit
67f92bff1e
@@ -16,20 +16,20 @@
|
||||
|
||||
package sample.data.gemfire;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
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.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import sample.data.gemfire.domain.Gemstone;
|
||||
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
|
||||
@@ -42,9 +42,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class SampleDataGemFireApplicationTests {
|
||||
|
||||
@Autowired
|
||||
@SuppressWarnings("unused")
|
||||
private GemstoneService gemstoneService;
|
||||
|
||||
private final AtomicLong ID_GENERATOR = new AtomicLong(0l);
|
||||
private final AtomicLong idGenerator = new AtomicLong(0l);
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@@ -52,7 +53,7 @@ public class SampleDataGemFireApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGemstonesApp() {
|
||||
public void gemstonesAppServiceEndpoints() {
|
||||
assertThat(this.gemstoneService.count()).isEqualTo(0);
|
||||
assertThat(this.gemstoneService.list()).isEmpty();
|
||||
|
||||
@@ -60,37 +61,41 @@ public class SampleDataGemFireApplicationTests {
|
||||
this.gemstoneService.save(createGemstone("Ruby"));
|
||||
|
||||
assertThat(this.gemstoneService.count()).isEqualTo(2);
|
||||
assertThat(this.gemstoneService.list()).contains(getGemstones("Diamond", "Ruby"));
|
||||
assertThat(this.gemstoneService.list()).contains(
|
||||
getGemstones("Diamond", "Ruby"));
|
||||
|
||||
try {
|
||||
this.gemstoneService.save(createGemstone("Coal"));
|
||||
}
|
||||
catch (IllegalGemstoneException ex) {
|
||||
// Expected
|
||||
catch (IllegalGemstoneException ignore) {
|
||||
// expected
|
||||
}
|
||||
|
||||
assertThat(this.gemstoneService.count()).isEqualTo(2);
|
||||
assertThat(this.gemstoneService.list()).contains(getGemstones("Diamond", "Ruby"));
|
||||
assertThat(this.gemstoneService.list()).contains(
|
||||
getGemstones("Diamond", "Ruby"));
|
||||
|
||||
this.gemstoneService.save(createGemstone("Pearl"));
|
||||
this.gemstoneService.save(createGemstone("Sapphire"));
|
||||
|
||||
assertThat(this.gemstoneService.count()).isEqualTo(4);
|
||||
assertThat(this.gemstoneService.list())
|
||||
.contains(getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"));
|
||||
assertThat(this.gemstoneService.list()).contains(
|
||||
getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"));
|
||||
|
||||
try {
|
||||
this.gemstoneService.save(createGemstone("Quartz"));
|
||||
}
|
||||
catch (IllegalGemstoneException expected) {
|
||||
catch (IllegalGemstoneException ignore) {
|
||||
// expected
|
||||
}
|
||||
|
||||
assertThat(this.gemstoneService.count()).isEqualTo(4);
|
||||
assertThat(this.gemstoneService.list())
|
||||
.contains(getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"));
|
||||
assertThat(this.gemstoneService.get("Diamond"))
|
||||
.isEqualTo(createGemstone("Diamond"));
|
||||
assertThat(this.gemstoneService.get("Pearl")).isEqualTo(createGemstone("Pearl"));
|
||||
assertThat(this.gemstoneService.list()).contains(
|
||||
getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"));
|
||||
assertThat(this.gemstoneService.get("Diamond")).isEqualTo(
|
||||
createGemstone("Diamond"));
|
||||
assertThat(this.gemstoneService.get("Pearl")).isEqualTo(
|
||||
createGemstone("Pearl"));
|
||||
}
|
||||
|
||||
private Gemstone[] getGemstones(String... names) {
|
||||
@@ -102,7 +107,7 @@ public class SampleDataGemFireApplicationTests {
|
||||
}
|
||||
|
||||
private Gemstone createGemstone(String name) {
|
||||
return createGemstone(this.ID_GENERATOR.incrementAndGet(), name);
|
||||
return createGemstone(this.idGenerator.incrementAndGet(), name);
|
||||
}
|
||||
|
||||
private Gemstone createGemstone(Long id, String name) {
|
||||
|
||||
Reference in New Issue
Block a user