formatting work
This commit is contained in:
+1
-1
@@ -4,6 +4,6 @@ import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages={"com.baeldung.couchbase.async"})
|
||||
@ComponentScan(basePackages = { "com.baeldung.couchbase.async" })
|
||||
public class AsyncIntegrationTestConfig {
|
||||
}
|
||||
|
||||
+77
-84
@@ -29,10 +29,10 @@ public class PersonCrudServiceIntegrationTest extends AsyncIntegrationTest {
|
||||
@Autowired
|
||||
@Qualifier("TutorialBucketService")
|
||||
private BucketService bucketService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private PersonDocumentConverter converter;
|
||||
|
||||
|
||||
private Bucket bucket;
|
||||
|
||||
@PostConstruct
|
||||
@@ -42,182 +42,175 @@ public class PersonCrudServiceIntegrationTest extends AsyncIntegrationTest {
|
||||
|
||||
@Test
|
||||
public final void givenRandomPerson_whenCreate_thenPersonPersisted() {
|
||||
//create person
|
||||
// create person
|
||||
Person person = randomPerson();
|
||||
personService.create(person);
|
||||
|
||||
//check results
|
||||
|
||||
// check results
|
||||
assertNotNull(person.getId());
|
||||
assertNotNull(bucket.get(person.getId()));
|
||||
|
||||
//cleanup
|
||||
|
||||
// cleanup
|
||||
bucket.remove(person.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void givenId_whenRead_thenReturnsPerson() {
|
||||
//create and insert person document
|
||||
// create and insert person document
|
||||
String id = insertRandomPersonDocument().id();
|
||||
|
||||
//read person and check results
|
||||
// read person and check results
|
||||
assertNotNull(personService.read(id));
|
||||
|
||||
//cleanup
|
||||
|
||||
// cleanup
|
||||
bucket.remove(id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void givenNewHometown_whenUpdate_thenNewHometownPersisted() {
|
||||
//create and insert person document
|
||||
// create and insert person document
|
||||
JsonDocument doc = insertRandomPersonDocument();
|
||||
|
||||
//update person
|
||||
|
||||
// update person
|
||||
Person expected = converter.fromDocument(doc);
|
||||
String updatedHomeTown = RandomStringUtils.randomAlphabetic(12);
|
||||
expected.setHomeTown(updatedHomeTown);
|
||||
personService.update(expected);
|
||||
|
||||
//check results
|
||||
|
||||
// check results
|
||||
JsonDocument actual = bucket.get(expected.getId());
|
||||
assertNotNull(actual);
|
||||
assertNotNull(actual.content());
|
||||
assertEquals(expected.getHomeTown(), actual.content().getString("homeTown"));
|
||||
|
||||
//cleanup
|
||||
|
||||
// cleanup
|
||||
bucket.remove(expected.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void givenRandomPerson_whenDelete_thenPersonNotInBucket() {
|
||||
//create and insert person document
|
||||
// create and insert person document
|
||||
String id = insertRandomPersonDocument().id();
|
||||
|
||||
//delete person and check results
|
||||
// delete person and check results
|
||||
personService.delete(id);
|
||||
assertNull(bucket.get(id));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public final void givenIds_whenReadBulk_thenReturnsOnlyPersonsWithMatchingIds() {
|
||||
List<String> ids = new ArrayList<>();
|
||||
|
||||
//add some person documents
|
||||
for(int i=0; i<5; i++) {
|
||||
|
||||
// add some person documents
|
||||
for (int i = 0; i < 5; i++) {
|
||||
ids.add(insertRandomPersonDocument().id());
|
||||
}
|
||||
|
||||
//perform bulk read
|
||||
|
||||
// perform bulk read
|
||||
List<Person> persons = personService.readBulk(ids);
|
||||
|
||||
//check results
|
||||
for(Person person : persons) {
|
||||
|
||||
// check results
|
||||
for (Person person : persons) {
|
||||
assertTrue(ids.contains(person.getId()));
|
||||
}
|
||||
|
||||
//cleanup
|
||||
for(String id : ids) {
|
||||
|
||||
// cleanup
|
||||
for (String id : ids) {
|
||||
bucket.remove(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public final void givenPersons_whenInsertBulk_thenPersonsAreInserted() {
|
||||
|
||||
//create some persons
|
||||
|
||||
// create some persons
|
||||
List<Person> persons = new ArrayList<>();
|
||||
for(int i=0; i<5; i++) {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
persons.add(randomPerson());
|
||||
}
|
||||
|
||||
//perform bulk insert
|
||||
// perform bulk insert
|
||||
personService.createBulk(persons);
|
||||
|
||||
//check results
|
||||
for(Person person : persons) {
|
||||
|
||||
// check results
|
||||
for (Person person : persons) {
|
||||
assertNotNull(bucket.get(person.getId()));
|
||||
}
|
||||
|
||||
//cleanup
|
||||
for(Person person : persons) {
|
||||
|
||||
// cleanup
|
||||
for (Person person : persons) {
|
||||
bucket.remove(person.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void givenPersons_whenUpdateBulk_thenPersonsAreUpdated() {
|
||||
|
||||
|
||||
List<String> ids = new ArrayList<>();
|
||||
|
||||
//add some person documents
|
||||
for(int i=0; i<5; i++) {
|
||||
|
||||
// add some person documents
|
||||
for (int i = 0; i < 5; i++) {
|
||||
ids.add(insertRandomPersonDocument().id());
|
||||
}
|
||||
|
||||
//load persons from Couchbase
|
||||
// load persons from Couchbase
|
||||
List<Person> persons = new ArrayList<>();
|
||||
for(String id : ids) {
|
||||
for (String id : ids) {
|
||||
persons.add(converter.fromDocument(bucket.get(id)));
|
||||
}
|
||||
|
||||
//modify persons
|
||||
for(Person person : persons) {
|
||||
// modify persons
|
||||
for (Person person : persons) {
|
||||
person.setHomeTown(RandomStringUtils.randomAlphabetic(10));
|
||||
}
|
||||
|
||||
//perform bulk update
|
||||
|
||||
// perform bulk update
|
||||
personService.updateBulk(persons);
|
||||
|
||||
//check results
|
||||
for(Person person : persons) {
|
||||
|
||||
// check results
|
||||
for (Person person : persons) {
|
||||
JsonDocument doc = bucket.get(person.getId());
|
||||
assertEquals(person.getName(), doc.content().getString("name"));
|
||||
assertEquals(person.getHomeTown(), doc.content().getString("homeTown"));
|
||||
}
|
||||
|
||||
//cleanup
|
||||
for(String id : ids) {
|
||||
|
||||
// cleanup
|
||||
for (String id : ids) {
|
||||
bucket.remove(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenIds_whenDeleteBulk_thenPersonsAreDeleted() {
|
||||
|
||||
|
||||
List<String> ids = new ArrayList<>();
|
||||
|
||||
//add some person documents
|
||||
for(int i=0; i<5; i++) {
|
||||
|
||||
// add some person documents
|
||||
for (int i = 0; i < 5; i++) {
|
||||
ids.add(insertRandomPersonDocument().id());
|
||||
}
|
||||
|
||||
//perform bulk delete
|
||||
|
||||
// perform bulk delete
|
||||
personService.deleteBulk(ids);
|
||||
|
||||
//check results
|
||||
for(String id : ids) {
|
||||
|
||||
// check results
|
||||
for (String id : ids) {
|
||||
assertNull(bucket.get(id));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private JsonDocument insertRandomPersonDocument() {
|
||||
Person expected = randomPersonWithId();
|
||||
JsonDocument doc = converter.toDocument(expected);
|
||||
return bucket.insert(doc);
|
||||
return bucket.insert(doc);
|
||||
}
|
||||
|
||||
private Person randomPerson() {
|
||||
return Person.Builder.newInstance()
|
||||
.name(RandomStringUtils.randomAlphabetic(10))
|
||||
.homeTown(RandomStringUtils.randomAlphabetic(10))
|
||||
.build();
|
||||
return Person.Builder.newInstance().name(RandomStringUtils.randomAlphabetic(10)).homeTown(RandomStringUtils.randomAlphabetic(10)).build();
|
||||
}
|
||||
|
||||
private Person randomPersonWithId() {
|
||||
return Person.Builder.newInstance()
|
||||
.id(UUID.randomUUID().toString())
|
||||
.name(RandomStringUtils.randomAlphabetic(10))
|
||||
.homeTown(RandomStringUtils.randomAlphabetic(10))
|
||||
.build();
|
||||
return Person.Builder.newInstance().id(UUID.randomUUID().toString()).name(RandomStringUtils.randomAlphabetic(10)).homeTown(RandomStringUtils.randomAlphabetic(10)).build();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,9 +22,9 @@ public class ClusterServiceIntegrationTest extends AsyncIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private ClusterService couchbaseService;
|
||||
|
||||
|
||||
private Bucket defaultBucket;
|
||||
|
||||
|
||||
@Test
|
||||
public void whenOpenBucket_thenBucketIsNotNull() throws Exception {
|
||||
defaultBucket = couchbaseService.openBucket("default", "");
|
||||
|
||||
+1
-1
@@ -4,6 +4,6 @@ import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages={"com.baeldung.couchbase.spring"})
|
||||
@ComponentScan(basePackages = { "com.baeldung.couchbase.spring" })
|
||||
public class IntegrationTestConfig {
|
||||
}
|
||||
|
||||
+4
-11
@@ -24,7 +24,7 @@ public class PersonCrudServiceIntegrationTest extends IntegrationTest {
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
clarkKent = personService.read(CLARK_KENT_ID);
|
||||
if(clarkKent == null) {
|
||||
if (clarkKent == null) {
|
||||
clarkKent = buildClarkKent();
|
||||
personService.create(clarkKent);
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class PersonCrudServiceIntegrationTest extends IntegrationTest {
|
||||
personService.create(expected);
|
||||
String updatedHomeTown = RandomStringUtils.randomAlphabetic(12);
|
||||
expected.setHomeTown(updatedHomeTown);
|
||||
personService.update(expected);
|
||||
personService.update(expected);
|
||||
Person actual = personService.read(expected.getId());
|
||||
assertNotNull(actual);
|
||||
assertEquals(expected.getHomeTown(), actual.getHomeTown());
|
||||
@@ -66,17 +66,10 @@ public class PersonCrudServiceIntegrationTest extends IntegrationTest {
|
||||
}
|
||||
|
||||
private Person buildClarkKent() {
|
||||
return Person.Builder.newInstance()
|
||||
.id(CLARK_KENT_ID)
|
||||
.name(CLARK_KENT)
|
||||
.homeTown(SMALLVILLE)
|
||||
.build();
|
||||
return Person.Builder.newInstance().id(CLARK_KENT_ID).name(CLARK_KENT).homeTown(SMALLVILLE).build();
|
||||
}
|
||||
|
||||
private Person randomPerson() {
|
||||
return Person.Builder.newInstance()
|
||||
.name(RandomStringUtils.randomAlphabetic(10))
|
||||
.homeTown(RandomStringUtils.randomAlphabetic(10))
|
||||
.build();
|
||||
return Person.Builder.newInstance().name(RandomStringUtils.randomAlphabetic(10)).homeTown(RandomStringUtils.randomAlphabetic(10)).build();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -21,9 +21,9 @@ public class ClusterServiceIntegrationTest extends IntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private ClusterService couchbaseService;
|
||||
|
||||
|
||||
private Bucket defaultBucket;
|
||||
|
||||
|
||||
@Test
|
||||
public void whenOpenBucket_thenBucketIsNotNull() throws Exception {
|
||||
defaultBucket = couchbaseService.openBucket("default", "");
|
||||
|
||||
Reference in New Issue
Block a user