DATACOUCH-273 - Integrate Data Commons Java 8 upgrade branch.
Replace PersistentEntity.doWithProperties(…) and .doWithAssociations(…) with stream processing using PersistentEntity.getPersistentProperties() and PersistentEntity.getAssociations().
This commit is contained in:
@@ -67,7 +67,7 @@ public class PageAndSliceTests {
|
||||
assertEquals(10, page3.getNumberOfElements());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void shouldThrowWhenPageableIsNullInPageQuery() {
|
||||
repository.findByAgeGreaterThan(9, null);
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public class PageAndSliceTests {
|
||||
assertEquals(9, allMatching.size());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void shouldThrowWhenPageableIsNullSliceQuery() {
|
||||
repository.findByAgeLessThan(9, null);
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@ package org.springframework.data.couchbase.repository;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.couchbase.client.java.Bucket;
|
||||
import com.couchbase.client.java.document.JsonDocument;
|
||||
@@ -25,6 +27,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Simon Baslé
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestApplicationConfig.class)
|
||||
@@ -50,9 +53,8 @@ public class QueryDerivationConversionTests {
|
||||
|
||||
@Test
|
||||
public void testConvertsDateParameterInN1qlQuery() {
|
||||
Party partyApril = repository.findOne("testparty-3");
|
||||
assertNotNull(partyApril);
|
||||
System.out.println(partyApril);
|
||||
Optional<Party> partyApril = repository.findOne("testparty-3");
|
||||
assertTrue(partyApril.isPresent());
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.clear();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -49,6 +49,7 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
@@ -56,6 +57,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Michael Nitschinger
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestApplicationConfig.class)
|
||||
@@ -97,14 +99,18 @@ public class SimpleCouchbaseRepositoryTests {
|
||||
User instance = new User(key, "foobar", 22);
|
||||
repository.save(instance);
|
||||
|
||||
User found = repository.findOne(key);
|
||||
assertEquals(instance.getKey(), found.getKey());
|
||||
assertEquals(instance.getUsername(), found.getUsername());
|
||||
Optional<User> found = repository.findOne(key);
|
||||
assertTrue(found.isPresent());
|
||||
|
||||
assertTrue(repository.exists(key));
|
||||
repository.delete(found);
|
||||
found.ifPresent(actual -> {
|
||||
assertEquals(instance.getKey(), actual.getKey());
|
||||
assertEquals(instance.getUsername(), actual.getUsername());
|
||||
|
||||
assertNull(repository.findOne(key));
|
||||
assertTrue(repository.exists(key));
|
||||
repository.delete(actual);
|
||||
});
|
||||
|
||||
assertFalse(repository.findOne(key).isPresent());
|
||||
assertFalse(repository.exists(key));
|
||||
}
|
||||
|
||||
@@ -214,20 +220,26 @@ public class SimpleCouchbaseRepositoryTests {
|
||||
versionedDataRepository.save(initial);
|
||||
assertNotEquals(0L, initial.version);
|
||||
|
||||
VersionedData fetch1 = versionedDataRepository.findOne(key);
|
||||
assertNotSame(initial, fetch1);
|
||||
assertEquals(fetch1.version, initial.version);
|
||||
Optional<VersionedData> fetch1 = versionedDataRepository.findOne(key);
|
||||
|
||||
assertTrue(fetch1.isPresent());
|
||||
fetch1.ifPresent(actual -> {
|
||||
assertNotSame(initial, actual);
|
||||
assertEquals(actual.version, initial.version);
|
||||
});
|
||||
|
||||
VersionedData versionedData = fetch1.get();
|
||||
|
||||
JsonDocument bypass = client.get(key);
|
||||
bypass.content().put("data", "BBBB");
|
||||
JsonDocument bypassed = client.upsert(bypass);
|
||||
|
||||
assertNotEquals(bypassed.cas(), fetch1.version);
|
||||
assertNotEquals(bypassed.cas(), versionedData.version);
|
||||
System.out.println(bypassed.cas());
|
||||
|
||||
try {
|
||||
fetch1.setData("ZZZZ");
|
||||
versionedDataRepository.save(fetch1);
|
||||
versionedData.setData("ZZZZ");
|
||||
versionedDataRepository.save(versionedData);
|
||||
fail("Expected CAS failure");
|
||||
} catch (OptimisticLockingFailureException e) {
|
||||
//success
|
||||
@@ -255,7 +267,7 @@ public class SimpleCouchbaseRepositoryTests {
|
||||
boolean updated = false;
|
||||
while(!updated) {
|
||||
long counterValue = counter.incrementAndGet();
|
||||
VersionedData messageData = versionedDataRepository.findOne(key);
|
||||
VersionedData messageData = versionedDataRepository.findOne(key).get();
|
||||
messageData.data = "value-" + counterValue;
|
||||
try {
|
||||
versionedDataRepository.save(messageData);
|
||||
@@ -269,7 +281,7 @@ public class SimpleCouchbaseRepositoryTests {
|
||||
};
|
||||
AsyncUtils.executeConcurrently(5, task);
|
||||
|
||||
assertNotEquals(initial.data, versionedDataRepository.findOne(key).data);
|
||||
assertNotEquals(initial.data, versionedDataRepository.findOne(key).get().data);
|
||||
assertEquals(5, updatedCounter.intValue());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
package org.springframework.data.couchbase.repository.auditing;
|
||||
|
||||
import org.springframework.data.domain.AuditorAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class AuditedAuditorAware implements AuditorAware<String> {
|
||||
|
||||
private String auditor = "auditor";
|
||||
private Optional<String> auditor = Optional.of("auditor");
|
||||
|
||||
@Override
|
||||
public String getCurrentAuditor() {
|
||||
public Optional<String> getCurrentAuditor() {
|
||||
return auditor;
|
||||
}
|
||||
|
||||
public void setAuditor(String auditor) {
|
||||
this.auditor = auditor;
|
||||
this.auditor = Optional.of(auditor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,19 +3,19 @@ package org.springframework.data.couchbase.repository.auditing;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataRetrievalFailureException;
|
||||
import org.springframework.data.couchbase.repository.CouchbaseRepository;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Simon Baslé
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = AuditedApplicationConfig.class)
|
||||
@@ -42,20 +42,24 @@ public class AuditingTests {
|
||||
|
||||
auditorAware.setAuditor("auditor");
|
||||
repository.save(item);
|
||||
AuditedItem persisted = repository.findOne(KEY);
|
||||
Optional<AuditedItem> persisted = repository.findOne(KEY);
|
||||
|
||||
assertNotNull("expected entity to be persisted", persisted);
|
||||
assertNotNull("expected creation date audit trail", persisted.getCreationDate());
|
||||
assertEquals("expected creation user audit trail", "auditor", persisted.getCreator());
|
||||
assertTrue(persisted.isPresent());
|
||||
|
||||
assertTrue("creation date is too early", persisted.getCreationDate().after(start));
|
||||
assertTrue("creation date is too late", persisted.getCreationDate().before(new Date()));
|
||||
persisted.ifPresent(actual -> {
|
||||
|
||||
assertNull("expected modification date to be empty", persisted.getLastModification());
|
||||
assertNull("expected modification user to be empty", persisted.getLastModifiedBy());
|
||||
assertNotNull("expected creation date audit trail", actual.getCreationDate());
|
||||
assertEquals("expected creation user audit trail", "auditor", actual.getCreator());
|
||||
|
||||
assertNotNull("expected version to be non null", persisted.getVersion());
|
||||
assertTrue("expected version to be greater than 0", persisted.getVersion() > 0L);
|
||||
assertTrue("creation date is too early", actual.getCreationDate().after(start));
|
||||
assertTrue("creation date is too late", actual.getCreationDate().before(new Date()));
|
||||
|
||||
assertNull("expected modification date to be empty", actual.getLastModification());
|
||||
assertNull("expected modification user to be empty", actual.getLastModifiedBy());
|
||||
|
||||
assertNotNull("expected version to be non null", actual.getVersion());
|
||||
assertTrue("expected version to be greater than 0", actual.getVersion() > 0L);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,11 +72,11 @@ public class AuditingTests {
|
||||
auditorAware.setAuditor(expectedCreator);
|
||||
|
||||
repository.save(item);
|
||||
AuditedItem created = repository.findOne(KEY);
|
||||
AuditedItem created = repository.findOne(KEY).orElse(null);
|
||||
|
||||
auditorAware.setAuditor(expectedUpdater);
|
||||
repository.save(item);
|
||||
AuditedItem updated = repository.findOne(KEY);
|
||||
AuditedItem updated = repository.findOne(KEY).orElse(null);
|
||||
|
||||
assertNotNull("expected entity to be persisted", updated);
|
||||
assertNotNull("expected creation date audit trail", updated.getCreationDate());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.couchbase.client.java.Bucket;
|
||||
import com.couchbase.client.java.view.DefaultView;
|
||||
@@ -89,10 +90,12 @@ public class CdiRepositoryTests {
|
||||
|
||||
assertTrue(repository.exists(bean.getId()));
|
||||
|
||||
Person retrieved = repository.findOne(bean.getId());
|
||||
assertNotNull(retrieved);
|
||||
assertEquals(bean.getName(), retrieved.getName());
|
||||
assertEquals(bean.getId(), retrieved.getId());
|
||||
Optional<Person> retrieved = repository.findOne(bean.getId());
|
||||
assertTrue(retrieved.isPresent());
|
||||
retrieved.ifPresent(actual -> {
|
||||
assertEquals(bean.getName(), actual.getName());
|
||||
assertEquals(bean.getId(), actual.getId());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,10 +112,12 @@ public class CdiRepositoryTests {
|
||||
|
||||
assertTrue(qualifiedPersonRepository.exists(bean.getId()));
|
||||
|
||||
Person retrieved = qualifiedPersonRepository.findOne(bean.getId());
|
||||
assertNotNull(retrieved);
|
||||
assertEquals(bean.getName(), retrieved.getName());
|
||||
assertEquals(bean.getId(), retrieved.getId());
|
||||
Optional<Person> retrieved = qualifiedPersonRepository.findOne(bean.getId());
|
||||
assertTrue(retrieved.isPresent());
|
||||
retrieved.ifPresent(actual -> {
|
||||
assertEquals(bean.getName(), actual.getName());
|
||||
assertEquals(bean.getId(), actual.getId());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,7 +29,7 @@ public class MyRepositoryImpl implements MyRepositoryCustom {
|
||||
CouchbasePersistentEntity<Object> itemPersistenceEntity = (CouchbasePersistentEntity<Object>)
|
||||
template.getConverter()
|
||||
.getMappingContext()
|
||||
.getPersistentEntity(MyItem.class);
|
||||
.getRequiredPersistentEntity(MyItem.class);
|
||||
|
||||
CouchbaseEntityInformation<? extends Object, String> itemEntityInformation =
|
||||
new MappingCouchbaseEntityInformation<Object, String>(itemPersistenceEntity);
|
||||
|
||||
@@ -5,6 +5,7 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.couchbase.client.java.cluster.ClusterInfo;
|
||||
import com.couchbase.client.java.util.features.CouchbaseFeature;
|
||||
@@ -33,6 +34,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* underlying {@link CouchbaseOperations} beans.
|
||||
*
|
||||
* @author Simon Baslé
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@SuppressWarnings("SpringJavaAutowiringInspection")
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@@ -128,13 +130,15 @@ public class RepositoryTemplateWiringTests {
|
||||
|
||||
boolean existA = repositoryA.exists("testA");
|
||||
boolean existB = repositoryB.exists("testB");
|
||||
Misc valueC = repositoryC.findOne("toto");
|
||||
Optional<Misc> valueC = repositoryC.findOne("toto");
|
||||
|
||||
assertTrue(existA);
|
||||
assertFalse(existB);
|
||||
assertNotNull(valueC);
|
||||
assertEquals("mock", valueC.id);
|
||||
assertEquals(true, valueC.random);
|
||||
assertTrue(valueC.isPresent());
|
||||
valueC.ifPresent(actual -> {
|
||||
assertEquals("mock", actual.id);
|
||||
assertEquals(true, actual.random);
|
||||
});
|
||||
|
||||
verify(mockOpsA).exists("testA");
|
||||
verify(mockOpsB).exists("testB");
|
||||
|
||||
Reference in New Issue
Block a user