Polishing.
Refine tests. Extend comment for future-me. See #1900 Original pull request: #1903
This commit is contained in:
@@ -221,7 +221,8 @@ public class StringBasedJdbcQuery extends AbstractJdbcQuery {
|
||||
|
||||
TypeInformation<?> actualType = typeInformation.getActualType();
|
||||
|
||||
// tuple-binding
|
||||
// allow tuple-binding for collection of byte arrays to be used as BINARY,
|
||||
// we do not want to convert to column arrays.
|
||||
if (actualType != null && actualType.getType().isArray() && !actualType.getType().equals(byte[].class)) {
|
||||
|
||||
TypeInformation<?> nestedElementType = actualType.getRequiredActualType();
|
||||
|
||||
@@ -34,6 +34,7 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -41,6 +42,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.PropertiesFactoryBean;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
@@ -50,7 +52,16 @@ import org.springframework.context.annotation.Import;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.domain.*;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.domain.ExampleMatcher;
|
||||
import org.springframework.data.domain.Limit;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.ScrollPosition;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Window;
|
||||
import org.springframework.data.jdbc.core.mapping.AggregateReference;
|
||||
import org.springframework.data.jdbc.repository.query.Modifying;
|
||||
import org.springframework.data.jdbc.repository.query.Query;
|
||||
@@ -107,18 +118,6 @@ public class JdbcRepositoryIntegrationTests {
|
||||
|
||||
@Autowired WithDelimitedColumnRepository withDelimitedColumnRepository;
|
||||
|
||||
private static DummyEntity createDummyEntity() {
|
||||
return createDummyEntity("Entity Name");
|
||||
}
|
||||
|
||||
private static DummyEntity createDummyEntity(String entityName) {
|
||||
|
||||
DummyEntity entity = new DummyEntity();
|
||||
entity.setName(entityName);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
|
||||
@@ -130,7 +129,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-95
|
||||
public void savesAnEntity() {
|
||||
|
||||
DummyEntity entity = repository.save(createDummyEntity());
|
||||
DummyEntity entity = repository.save(createEntity());
|
||||
|
||||
assertThat(JdbcTestUtils.countRowsInTableWhere(template.getJdbcOperations(), "dummy_entity",
|
||||
"id_Prop = " + entity.getIdProp())).isEqualTo(1);
|
||||
@@ -139,7 +138,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-95
|
||||
public void saveAndLoadAnEntity() {
|
||||
|
||||
DummyEntity entity = repository.save(createDummyEntity());
|
||||
DummyEntity entity = repository.save(createEntity());
|
||||
|
||||
assertThat(repository.findById(entity.getIdProp())).hasValueSatisfying(it -> {
|
||||
|
||||
@@ -151,8 +150,8 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-97
|
||||
public void insertsManyEntities() {
|
||||
|
||||
DummyEntity entity = createDummyEntity();
|
||||
DummyEntity other = createDummyEntity();
|
||||
DummyEntity entity = createEntity();
|
||||
DummyEntity other = createEntity();
|
||||
|
||||
repository.saveAll(asList(entity, other));
|
||||
|
||||
@@ -164,7 +163,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-97
|
||||
public void existsReturnsTrueIffEntityExists() {
|
||||
|
||||
DummyEntity entity = repository.save(createDummyEntity());
|
||||
DummyEntity entity = repository.save(createEntity());
|
||||
|
||||
assertThat(repository.existsById(entity.getIdProp())).isTrue();
|
||||
assertThat(repository.existsById(entity.getIdProp() + 1)).isFalse();
|
||||
@@ -173,8 +172,8 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-97
|
||||
public void findAllFindsAllEntities() {
|
||||
|
||||
DummyEntity entity = repository.save(createDummyEntity());
|
||||
DummyEntity other = repository.save(createDummyEntity());
|
||||
DummyEntity entity = repository.save(createEntity());
|
||||
DummyEntity other = repository.save(createEntity());
|
||||
|
||||
Iterable<DummyEntity> all = repository.findAll();
|
||||
|
||||
@@ -186,8 +185,8 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-97
|
||||
public void findAllFindsAllSpecifiedEntities() {
|
||||
|
||||
DummyEntity entity = repository.save(createDummyEntity());
|
||||
DummyEntity other = repository.save(createDummyEntity());
|
||||
DummyEntity entity = repository.save(createEntity());
|
||||
DummyEntity other = repository.save(createEntity());
|
||||
|
||||
assertThat(repository.findAllById(asList(entity.getIdProp(), other.getIdProp())))//
|
||||
.extracting(DummyEntity::getIdProp)//
|
||||
@@ -197,9 +196,9 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-97
|
||||
public void countsEntities() {
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
repository.save(createEntity());
|
||||
repository.save(createEntity());
|
||||
|
||||
assertThat(repository.count()).isEqualTo(3L);
|
||||
}
|
||||
@@ -207,9 +206,9 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-97
|
||||
public void deleteById() {
|
||||
|
||||
DummyEntity one = repository.save(createDummyEntity());
|
||||
DummyEntity two = repository.save(createDummyEntity());
|
||||
DummyEntity three = repository.save(createDummyEntity());
|
||||
DummyEntity one = repository.save(createEntity());
|
||||
DummyEntity two = repository.save(createEntity());
|
||||
DummyEntity three = repository.save(createEntity());
|
||||
|
||||
repository.deleteById(two.getIdProp());
|
||||
|
||||
@@ -221,9 +220,9 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-97
|
||||
public void deleteByEntity() {
|
||||
|
||||
DummyEntity one = repository.save(createDummyEntity());
|
||||
DummyEntity two = repository.save(createDummyEntity());
|
||||
DummyEntity three = repository.save(createDummyEntity());
|
||||
DummyEntity one = repository.save(createEntity());
|
||||
DummyEntity two = repository.save(createEntity());
|
||||
DummyEntity three = repository.save(createEntity());
|
||||
|
||||
repository.delete(one);
|
||||
|
||||
@@ -235,9 +234,9 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-97
|
||||
public void deleteByList() {
|
||||
|
||||
DummyEntity one = repository.save(createDummyEntity());
|
||||
DummyEntity two = repository.save(createDummyEntity());
|
||||
DummyEntity three = repository.save(createDummyEntity());
|
||||
DummyEntity one = repository.save(createEntity());
|
||||
DummyEntity two = repository.save(createEntity());
|
||||
DummyEntity three = repository.save(createEntity());
|
||||
|
||||
repository.deleteAll(asList(one, three));
|
||||
|
||||
@@ -249,9 +248,9 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-629
|
||||
public void deleteByIdList() {
|
||||
|
||||
DummyEntity one = repository.save(createDummyEntity());
|
||||
DummyEntity two = repository.save(createDummyEntity());
|
||||
DummyEntity three = repository.save(createDummyEntity());
|
||||
DummyEntity one = repository.save(createEntity());
|
||||
DummyEntity two = repository.save(createEntity());
|
||||
DummyEntity three = repository.save(createEntity());
|
||||
|
||||
repository.deleteAllById(asList(one.idProp, three.idProp));
|
||||
|
||||
@@ -263,9 +262,9 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-97
|
||||
public void deleteAll() {
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
repository.save(createEntity());
|
||||
repository.save(createEntity());
|
||||
|
||||
assertThat(repository.findAll()).isNotEmpty();
|
||||
|
||||
@@ -277,7 +276,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-98
|
||||
public void update() {
|
||||
|
||||
DummyEntity entity = repository.save(createDummyEntity());
|
||||
DummyEntity entity = repository.save(createEntity());
|
||||
|
||||
entity.setName("something else");
|
||||
DummyEntity saved = repository.save(entity);
|
||||
@@ -290,8 +289,8 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-98
|
||||
public void updateMany() {
|
||||
|
||||
DummyEntity entity = repository.save(createDummyEntity());
|
||||
DummyEntity other = repository.save(createDummyEntity());
|
||||
DummyEntity entity = repository.save(createEntity());
|
||||
DummyEntity other = repository.save(createEntity());
|
||||
|
||||
entity.setName("something else");
|
||||
other.setName("others Name");
|
||||
@@ -306,9 +305,9 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-537
|
||||
void insertsOrUpdatesManyEntities() {
|
||||
|
||||
DummyEntity entity = repository.save(createDummyEntity());
|
||||
DummyEntity entity = repository.save(createEntity());
|
||||
entity.setName("something else");
|
||||
DummyEntity other = createDummyEntity();
|
||||
DummyEntity other = createEntity();
|
||||
other.setName("others name");
|
||||
repository.saveAll(asList(other, entity));
|
||||
|
||||
@@ -342,7 +341,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-318
|
||||
public void queryMethodShouldEmitEvents() {
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
eventListener.events.clear();
|
||||
|
||||
repository.findAllWithSql();
|
||||
@@ -353,7 +352,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-318
|
||||
public void queryMethodWithCustomRowMapperDoesNotEmitEvents() {
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
eventListener.events.clear();
|
||||
|
||||
repository.findAllWithCustomMapper();
|
||||
@@ -364,14 +363,14 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-234
|
||||
public void findAllByQueryName() {
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
assertThat(repository.findAllByNamedQuery()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void findAllByFirstnameWithLock() {
|
||||
|
||||
DummyEntity dummyEntity = createDummyEntity();
|
||||
DummyEntity dummyEntity = createEntity();
|
||||
repository.save(dummyEntity);
|
||||
assertThat(repository.findAllByName(dummyEntity.getName())).hasSize(1);
|
||||
}
|
||||
@@ -379,14 +378,14 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1022
|
||||
public void findAllByCustomQueryName() {
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
assertThat(repository.findAllByCustomNamedQuery()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-341
|
||||
public void findWithMissingQuery() {
|
||||
|
||||
DummyEntity dummy = repository.save(createDummyEntity());
|
||||
DummyEntity dummy = repository.save(createEntity());
|
||||
|
||||
DummyEntity loaded = repository.withMissingColumn(dummy.idProp);
|
||||
|
||||
@@ -398,7 +397,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-529
|
||||
public void existsWorksAsExpected() {
|
||||
|
||||
DummyEntity dummy = repository.save(createDummyEntity());
|
||||
DummyEntity dummy = repository.save(createEntity());
|
||||
|
||||
assertSoftly(softly -> {
|
||||
|
||||
@@ -414,7 +413,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-604
|
||||
public void existsInWorksAsExpected() {
|
||||
|
||||
DummyEntity dummy = repository.save(createDummyEntity());
|
||||
DummyEntity dummy = repository.save(createEntity());
|
||||
|
||||
assertSoftly(softly -> {
|
||||
|
||||
@@ -430,7 +429,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-604
|
||||
public void existsNotInWorksAsExpected() {
|
||||
|
||||
DummyEntity dummy = repository.save(createDummyEntity());
|
||||
DummyEntity dummy = repository.save(createEntity());
|
||||
|
||||
assertSoftly(softly -> {
|
||||
|
||||
@@ -446,10 +445,10 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // DATAJDBC-534
|
||||
public void countByQueryDerivation() {
|
||||
|
||||
DummyEntity one = createDummyEntity();
|
||||
DummyEntity two = createDummyEntity();
|
||||
DummyEntity one = createEntity();
|
||||
DummyEntity two = createEntity();
|
||||
two.name = "other";
|
||||
DummyEntity three = createDummyEntity();
|
||||
DummyEntity three = createEntity();
|
||||
|
||||
repository.saveAll(asList(one, two, three));
|
||||
|
||||
@@ -458,7 +457,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
|
||||
@Test // GH-619
|
||||
public void findBySpElWorksAsExpected() {
|
||||
DummyEntity r = repository.save(createDummyEntity());
|
||||
DummyEntity r = repository.save(createEntity());
|
||||
|
||||
// assign the new id to the global ID provider holder; this is similar to Spring Security's SecurityContextHolder
|
||||
MyIdContextProvider.ExtensionRoot.ID = r.getIdProp();
|
||||
@@ -530,7 +529,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-971
|
||||
public void stringQueryProjectionShouldReturnProjectedEntities() {
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
|
||||
List<DummyProjection> result = repository.findProjectedWithSql(DummyProjection.class);
|
||||
|
||||
@@ -541,7 +540,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-971
|
||||
public void stringQueryProjectionShouldReturnDtoProjectedEntities() {
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
|
||||
List<DtoProjection> result = repository.findProjectedWithSql(DtoProjection.class);
|
||||
|
||||
@@ -552,7 +551,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-971
|
||||
public void partTreeQueryProjectionShouldReturnProjectedEntities() {
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
|
||||
List<DummyProjection> result = repository.findProjectedByName("Entity Name");
|
||||
|
||||
@@ -563,7 +562,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-971
|
||||
public void pageQueryProjectionShouldReturnProjectedEntities() {
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
|
||||
Page<DummyProjection> result = repository.findPageProjectionByName("Entity Name", PageRequest.ofSize(10));
|
||||
|
||||
@@ -581,8 +580,8 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-908
|
||||
void derivedQueryWithBooleanLiteralFindsCorrectValues() {
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
DummyEntity entity = createDummyEntity();
|
||||
repository.save(createEntity());
|
||||
DummyEntity entity = createEntity();
|
||||
entity.flag = true;
|
||||
entity = repository.save(entity);
|
||||
|
||||
@@ -594,8 +593,8 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-987
|
||||
void queryBySimpleReference() {
|
||||
|
||||
DummyEntity one = repository.save(createDummyEntity());
|
||||
DummyEntity two = createDummyEntity();
|
||||
DummyEntity one = repository.save(createEntity());
|
||||
DummyEntity two = createEntity();
|
||||
two.ref = AggregateReference.to(one.idProp);
|
||||
two = repository.save(two);
|
||||
|
||||
@@ -607,8 +606,8 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-987
|
||||
void queryByAggregateReference() {
|
||||
|
||||
DummyEntity one = repository.save(createDummyEntity());
|
||||
DummyEntity two = createDummyEntity();
|
||||
DummyEntity one = repository.save(createEntity());
|
||||
DummyEntity two = createEntity();
|
||||
two.ref = AggregateReference.to(one.idProp);
|
||||
two = repository.save(two);
|
||||
|
||||
@@ -620,7 +619,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1167
|
||||
void stringResult() {
|
||||
|
||||
repository.save(createDummyEntity()); // just ensure we have data in the table
|
||||
repository.save(createEntity()); // just ensure we have data in the table
|
||||
|
||||
assertThat(repository.returnInput("HELLO")).isEqualTo("HELLO");
|
||||
}
|
||||
@@ -628,7 +627,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1167
|
||||
void nullStringResult() {
|
||||
|
||||
repository.save(createDummyEntity()); // just ensure we have data in the table
|
||||
repository.save(createEntity()); // just ensure we have data in the table
|
||||
|
||||
assertThat(repository.returnInput(null)).isNull();
|
||||
}
|
||||
@@ -726,11 +725,11 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1192
|
||||
void findOneByExampleShouldGetOne() {
|
||||
|
||||
DummyEntity dummyEntity1 = createDummyEntity();
|
||||
DummyEntity dummyEntity1 = createEntity();
|
||||
dummyEntity1.setFlag(true);
|
||||
repository.save(dummyEntity1);
|
||||
|
||||
DummyEntity dummyEntity2 = createDummyEntity();
|
||||
DummyEntity dummyEntity2 = createEntity();
|
||||
dummyEntity2.setName("Diego");
|
||||
repository.save(dummyEntity2);
|
||||
|
||||
@@ -743,10 +742,10 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1192
|
||||
void findOneByExampleMultipleMatchShouldGetOne() {
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
repository.save(createEntity());
|
||||
|
||||
Example<DummyEntity> example = Example.of(createDummyEntity());
|
||||
Example<DummyEntity> example = Example.of(createEntity());
|
||||
|
||||
assertThatThrownBy(() -> repository.findOne(example)).isInstanceOf(IncorrectResultSizeDataAccessException.class)
|
||||
.hasMessageContaining("expected 1, actual 2");
|
||||
@@ -755,7 +754,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1192
|
||||
void findOneByExampleShouldGetNone() {
|
||||
|
||||
DummyEntity dummyEntity1 = createDummyEntity();
|
||||
DummyEntity dummyEntity1 = createEntity();
|
||||
dummyEntity1.setFlag(true);
|
||||
repository.save(dummyEntity1);
|
||||
|
||||
@@ -769,11 +768,11 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1192
|
||||
void findAllByExampleShouldGetOne() {
|
||||
|
||||
DummyEntity dummyEntity1 = createDummyEntity();
|
||||
DummyEntity dummyEntity1 = createEntity();
|
||||
dummyEntity1.setFlag(true);
|
||||
repository.save(dummyEntity1);
|
||||
|
||||
DummyEntity dummyEntity2 = createDummyEntity();
|
||||
DummyEntity dummyEntity2 = createEntity();
|
||||
dummyEntity2.setName("Diego");
|
||||
repository.save(dummyEntity2);
|
||||
|
||||
@@ -788,10 +787,10 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1192
|
||||
void findAllByExampleMultipleMatchShouldGetOne() {
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
repository.save(createEntity());
|
||||
|
||||
Example<DummyEntity> example = Example.of(createDummyEntity());
|
||||
Example<DummyEntity> example = Example.of(createEntity());
|
||||
|
||||
Iterable<DummyEntity> allFound = repository.findAll(example);
|
||||
|
||||
@@ -804,7 +803,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1192
|
||||
void findAllByExampleShouldGetNone() {
|
||||
|
||||
DummyEntity dummyEntity1 = createDummyEntity();
|
||||
DummyEntity dummyEntity1 = createEntity();
|
||||
dummyEntity1.setFlag(true);
|
||||
|
||||
repository.save(dummyEntity1);
|
||||
@@ -819,12 +818,12 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1192
|
||||
void findAllByExamplePageableShouldGetOne() {
|
||||
|
||||
DummyEntity dummyEntity1 = createDummyEntity();
|
||||
DummyEntity dummyEntity1 = createEntity();
|
||||
dummyEntity1.setFlag(true);
|
||||
|
||||
repository.save(dummyEntity1);
|
||||
|
||||
DummyEntity dummyEntity2 = createDummyEntity();
|
||||
DummyEntity dummyEntity2 = createEntity();
|
||||
dummyEntity2.setName("Diego");
|
||||
|
||||
repository.save(dummyEntity2);
|
||||
@@ -841,10 +840,10 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1192
|
||||
void findAllByExamplePageableMultipleMatchShouldGetOne() {
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
repository.save(createEntity());
|
||||
|
||||
Example<DummyEntity> example = Example.of(createDummyEntity());
|
||||
Example<DummyEntity> example = Example.of(createEntity());
|
||||
Pageable pageRequest = PageRequest.of(0, 10);
|
||||
|
||||
Iterable<DummyEntity> allFound = repository.findAll(example, pageRequest);
|
||||
@@ -858,7 +857,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1192
|
||||
void findAllByExamplePageableShouldGetNone() {
|
||||
|
||||
DummyEntity dummyEntity1 = createDummyEntity();
|
||||
DummyEntity dummyEntity1 = createEntity();
|
||||
dummyEntity1.setFlag(true);
|
||||
|
||||
repository.save(dummyEntity1);
|
||||
@@ -874,10 +873,10 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1192
|
||||
void findAllByExamplePageableOutsidePageShouldGetNone() {
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
repository.save(createEntity());
|
||||
|
||||
Example<DummyEntity> example = Example.of(createDummyEntity());
|
||||
Example<DummyEntity> example = Example.of(createEntity());
|
||||
Pageable pageRequest = PageRequest.of(10, 10);
|
||||
|
||||
Iterable<DummyEntity> allFound = repository.findAll(example, pageRequest);
|
||||
@@ -892,14 +891,14 @@ public class JdbcRepositoryIntegrationTests {
|
||||
void findAllByExamplePageable(Pageable pageRequest, int size, int totalPages, List<String> notContains) {
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
DummyEntity dummyEntity = createDummyEntity();
|
||||
DummyEntity dummyEntity = createEntity();
|
||||
dummyEntity.setFlag(true);
|
||||
dummyEntity.setName("" + i);
|
||||
|
||||
repository.save(dummyEntity);
|
||||
}
|
||||
|
||||
DummyEntity dummyEntityExample = createDummyEntity();
|
||||
DummyEntity dummyEntityExample = createEntity();
|
||||
dummyEntityExample.setName(null);
|
||||
dummyEntityExample.setFlag(true);
|
||||
|
||||
@@ -939,11 +938,11 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1192
|
||||
void existsByExampleShouldGetOne() {
|
||||
|
||||
DummyEntity dummyEntity1 = createDummyEntity();
|
||||
DummyEntity dummyEntity1 = createEntity();
|
||||
dummyEntity1.setFlag(true);
|
||||
repository.save(dummyEntity1);
|
||||
|
||||
DummyEntity dummyEntity2 = createDummyEntity();
|
||||
DummyEntity dummyEntity2 = createEntity();
|
||||
dummyEntity2.setName("Diego");
|
||||
repository.save(dummyEntity2);
|
||||
|
||||
@@ -957,13 +956,13 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1192
|
||||
void existsByExampleMultipleMatchShouldGetOne() {
|
||||
|
||||
DummyEntity dummyEntity1 = createDummyEntity();
|
||||
DummyEntity dummyEntity1 = createEntity();
|
||||
repository.save(dummyEntity1);
|
||||
|
||||
DummyEntity dummyEntity2 = createDummyEntity();
|
||||
DummyEntity dummyEntity2 = createEntity();
|
||||
repository.save(dummyEntity2);
|
||||
|
||||
Example<DummyEntity> example = Example.of(createDummyEntity());
|
||||
Example<DummyEntity> example = Example.of(createEntity());
|
||||
|
||||
boolean exists = repository.exists(example);
|
||||
assertThat(exists).isTrue();
|
||||
@@ -972,7 +971,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1192
|
||||
void existsByExampleShouldGetNone() {
|
||||
|
||||
DummyEntity dummyEntity1 = createDummyEntity();
|
||||
DummyEntity dummyEntity1 = createEntity();
|
||||
dummyEntity1.setFlag(true);
|
||||
|
||||
repository.save(dummyEntity1);
|
||||
@@ -989,14 +988,14 @@ public class JdbcRepositoryIntegrationTests {
|
||||
|
||||
Instant pointInTime = Instant.now().truncatedTo(ChronoUnit.MILLIS).minusSeconds(10000);
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
|
||||
DummyEntity two = createDummyEntity();
|
||||
DummyEntity two = createEntity();
|
||||
two.setName("Diego");
|
||||
two.setPointInTime(pointInTime);
|
||||
repository.save(two);
|
||||
|
||||
DummyEntity exampleEntitiy = createDummyEntity();
|
||||
DummyEntity exampleEntitiy = createEntity();
|
||||
exampleEntitiy.setName("Diego");
|
||||
exampleEntitiy.setPointInTime(pointInTime);
|
||||
|
||||
@@ -1009,12 +1008,12 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1192
|
||||
void countByExampleShouldGetOne() {
|
||||
|
||||
DummyEntity dummyEntity1 = createDummyEntity();
|
||||
DummyEntity dummyEntity1 = createEntity();
|
||||
dummyEntity1.setFlag(true);
|
||||
|
||||
repository.save(dummyEntity1);
|
||||
|
||||
DummyEntity dummyEntity2 = createDummyEntity();
|
||||
DummyEntity dummyEntity2 = createEntity();
|
||||
dummyEntity2.setName("Diego");
|
||||
|
||||
repository.save(dummyEntity2);
|
||||
@@ -1029,13 +1028,13 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1192
|
||||
void countByExampleMultipleMatchShouldGetOne() {
|
||||
|
||||
DummyEntity dummyEntity1 = createDummyEntity();
|
||||
DummyEntity dummyEntity1 = createEntity();
|
||||
repository.save(dummyEntity1);
|
||||
|
||||
DummyEntity dummyEntity2 = createDummyEntity();
|
||||
DummyEntity dummyEntity2 = createEntity();
|
||||
repository.save(dummyEntity2);
|
||||
|
||||
Example<DummyEntity> example = Example.of(createDummyEntity());
|
||||
Example<DummyEntity> example = Example.of(createEntity());
|
||||
|
||||
long count = repository.count(example);
|
||||
assertThat(count).isEqualTo(2);
|
||||
@@ -1044,7 +1043,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1192
|
||||
void countByExampleShouldGetNone() {
|
||||
|
||||
DummyEntity dummyEntity1 = createDummyEntity();
|
||||
DummyEntity dummyEntity1 = createEntity();
|
||||
dummyEntity1.setFlag(true);
|
||||
|
||||
repository.save(dummyEntity1);
|
||||
@@ -1060,14 +1059,14 @@ public class JdbcRepositoryIntegrationTests {
|
||||
void countByExampleComplex() {
|
||||
|
||||
Instant pointInTime = Instant.now().minusSeconds(10000).truncatedTo(ChronoUnit.MILLIS);
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
|
||||
DummyEntity two = createDummyEntity();
|
||||
DummyEntity two = createEntity();
|
||||
two.setName("Diego");
|
||||
two.setPointInTime(pointInTime);
|
||||
repository.save(two);
|
||||
|
||||
DummyEntity exampleEntitiy = createDummyEntity();
|
||||
DummyEntity exampleEntitiy = createEntity();
|
||||
exampleEntitiy.setName("Diego");
|
||||
exampleEntitiy.setPointInTime(pointInTime);
|
||||
|
||||
@@ -1083,7 +1082,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
String searchName = "Diego";
|
||||
Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS);
|
||||
|
||||
DummyEntity two = createDummyEntity();
|
||||
DummyEntity two = createEntity();
|
||||
|
||||
two.setName(searchName);
|
||||
two.setPointInTime(now.minusSeconds(10000));
|
||||
@@ -1092,7 +1091,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
// I'm looking at you MariaDb.
|
||||
two = repository.findById(two.idProp).orElseThrow();
|
||||
|
||||
DummyEntity third = createDummyEntity();
|
||||
DummyEntity third = createEntity();
|
||||
third.setName(searchName);
|
||||
third.setPointInTime(now.minusSeconds(200000));
|
||||
third = repository.save(third);
|
||||
@@ -1100,7 +1099,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
// I'm looking at you MariaDb.
|
||||
third = repository.findById(third.idProp).orElseThrow();
|
||||
|
||||
DummyEntity exampleEntitiy = createDummyEntity();
|
||||
DummyEntity exampleEntitiy = createEntity();
|
||||
exampleEntitiy.setName(searchName);
|
||||
|
||||
Example<DummyEntity> example = Example.of(exampleEntitiy);
|
||||
@@ -1151,20 +1150,20 @@ public class JdbcRepositoryIntegrationTests {
|
||||
String searchName = "Diego";
|
||||
Instant now = Instant.now();
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
|
||||
DummyEntity two = createDummyEntity();
|
||||
DummyEntity two = createEntity();
|
||||
|
||||
two.setName(searchName);
|
||||
two.setPointInTime(now.minusSeconds(10000));
|
||||
repository.save(two);
|
||||
|
||||
DummyEntity third = createDummyEntity();
|
||||
DummyEntity third = createEntity();
|
||||
third.setName(searchName);
|
||||
third.setPointInTime(now.minusSeconds(200000));
|
||||
repository.save(third);
|
||||
|
||||
DummyEntity exampleEntitiy = createDummyEntity();
|
||||
DummyEntity exampleEntitiy = createEntity();
|
||||
exampleEntitiy.setName(searchName);
|
||||
|
||||
Example<DummyEntity> example = Example.of(exampleEntitiy);
|
||||
@@ -1179,9 +1178,9 @@ public class JdbcRepositoryIntegrationTests {
|
||||
String searchName = "Diego";
|
||||
Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS);
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
|
||||
DummyEntity two = createDummyEntity();
|
||||
DummyEntity two = createEntity();
|
||||
|
||||
two.setName(searchName);
|
||||
two.setPointInTime(now.minusSeconds(10000));
|
||||
@@ -1190,12 +1189,12 @@ public class JdbcRepositoryIntegrationTests {
|
||||
// I'm looking at you MariaDb.
|
||||
two = repository.findById(two.idProp).orElseThrow();
|
||||
|
||||
DummyEntity third = createDummyEntity();
|
||||
DummyEntity third = createEntity();
|
||||
third.setName(searchName);
|
||||
third.setPointInTime(now.minusSeconds(200000));
|
||||
repository.save(third);
|
||||
|
||||
DummyEntity exampleEntity = createDummyEntity();
|
||||
DummyEntity exampleEntity = createEntity();
|
||||
exampleEntity.setName(searchName);
|
||||
|
||||
Example<DummyEntity> example = Example.of(exampleEntity);
|
||||
@@ -1212,19 +1211,19 @@ public class JdbcRepositoryIntegrationTests {
|
||||
String searchName = "Diego";
|
||||
Instant now = Instant.now();
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
|
||||
DummyEntity two = createDummyEntity();
|
||||
DummyEntity two = createEntity();
|
||||
two.setName(searchName);
|
||||
two.setPointInTime(now.minusSeconds(10000));
|
||||
repository.save(two);
|
||||
|
||||
DummyEntity third = createDummyEntity();
|
||||
DummyEntity third = createEntity();
|
||||
third.setName(searchName);
|
||||
third.setPointInTime(now.minusSeconds(200000));
|
||||
repository.save(third);
|
||||
|
||||
DummyEntity exampleEntitiy = createDummyEntity();
|
||||
DummyEntity exampleEntitiy = createEntity();
|
||||
exampleEntitiy.setName(searchName);
|
||||
|
||||
Example<DummyEntity> example = Example.of(exampleEntitiy);
|
||||
@@ -1239,9 +1238,9 @@ public class JdbcRepositoryIntegrationTests {
|
||||
String searchName = "Diego";
|
||||
Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS);
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
|
||||
DummyEntity two = createDummyEntity();
|
||||
DummyEntity two = createEntity();
|
||||
two.setName(searchName);
|
||||
two.setPointInTime(now.minusSeconds(10000));
|
||||
two = repository.save(two);
|
||||
@@ -1249,7 +1248,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
// I'm looking at you MariaDb.
|
||||
two = repository.findById(two.idProp).orElseThrow();
|
||||
|
||||
DummyEntity exampleEntitiy = createDummyEntity();
|
||||
DummyEntity exampleEntitiy = createEntity();
|
||||
exampleEntitiy.setName(searchName);
|
||||
|
||||
Example<DummyEntity> example = Example.of(exampleEntitiy);
|
||||
@@ -1265,14 +1264,14 @@ public class JdbcRepositoryIntegrationTests {
|
||||
String searchName = "Diego";
|
||||
Instant now = Instant.now();
|
||||
|
||||
repository.save(createDummyEntity());
|
||||
repository.save(createEntity());
|
||||
|
||||
DummyEntity two = createDummyEntity();
|
||||
DummyEntity two = createEntity();
|
||||
two.setName(searchName);
|
||||
two.setPointInTime(now.minusSeconds(10000));
|
||||
two = repository.save(two);
|
||||
|
||||
DummyEntity exampleEntity = createDummyEntity();
|
||||
DummyEntity exampleEntity = createEntity();
|
||||
exampleEntity.setName(searchName);
|
||||
|
||||
Example<DummyEntity> example = Example.of(exampleEntity);
|
||||
@@ -1333,9 +1332,9 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@EnabledOnFeature(TestDatabaseFeatures.Feature.WHERE_IN_TUPLE)
|
||||
void queryWithTupleIn() {
|
||||
|
||||
DummyEntity one = repository.save(createDummyEntity("one"));
|
||||
DummyEntity two = repository.save(createDummyEntity("two"));
|
||||
DummyEntity three = repository.save(createDummyEntity("three"));
|
||||
DummyEntity one = repository.save(createEntity("one"));
|
||||
DummyEntity two = repository.save(createEntity("two"));
|
||||
DummyEntity three = repository.save(createEntity("three"));
|
||||
|
||||
List<Object[]> tuples = List.of(new Object[] { two.idProp, "two" }, // matches "two"
|
||||
new Object[] { three.idProp, "two" } // matches nothing
|
||||
@@ -1349,22 +1348,12 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1900
|
||||
void queryByListOfByteArray() {
|
||||
|
||||
byte[] oneBytes = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||
DummyEntity one = createDummyEntity("one");
|
||||
one.setBytes(oneBytes);
|
||||
one = repository.save(one);
|
||||
DummyEntity one = repository.save(createEntity("one", it -> it.setBytes(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 })));
|
||||
DummyEntity two = repository.save(createEntity("two", it -> it.setBytes(new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 })));
|
||||
DummyEntity three = repository
|
||||
.save(createEntity("three", it -> it.setBytes(new byte[] { 3, 3, 3, 3, 3, 3, 3, 3 })));
|
||||
|
||||
byte[] twoBytes = { 8, 7, 6, 5, 4, 3, 2, 1 };
|
||||
DummyEntity two = createDummyEntity("two");
|
||||
two.setBytes(twoBytes);
|
||||
two = repository.save(two);
|
||||
|
||||
byte[] threeBytes = { 3, 3, 3, 3, 3, 3, 3, 3 };
|
||||
DummyEntity three = createDummyEntity("three");
|
||||
three.setBytes(threeBytes);
|
||||
three = repository.save(three);
|
||||
|
||||
List<DummyEntity> result = repository.findByBytesIn(List.of(threeBytes, oneBytes));
|
||||
List<DummyEntity> result = repository.findByBytesIn(List.of(three.getBytes(), one.getBytes()));
|
||||
|
||||
assertThat(result).extracting("idProp").containsExactlyInAnyOrder(one.idProp, three.idProp);
|
||||
}
|
||||
@@ -1372,22 +1361,12 @@ public class JdbcRepositoryIntegrationTests {
|
||||
@Test // GH-1900
|
||||
void queryByByteArray() {
|
||||
|
||||
byte[] oneBytes = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||
DummyEntity one = createDummyEntity("one");
|
||||
one.setBytes(oneBytes);
|
||||
one = repository.save(one);
|
||||
DummyEntity one = repository.save(createEntity("one", it -> it.setBytes(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 })));
|
||||
DummyEntity two = repository.save(createEntity("two", it -> it.setBytes(new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 })));
|
||||
DummyEntity three = repository
|
||||
.save(createEntity("three", it -> it.setBytes(new byte[] { 3, 3, 3, 3, 3, 3, 3, 3 })));
|
||||
|
||||
byte[] twoBytes = { 8, 7, 6, 5, 4, 3, 2, 1 };
|
||||
DummyEntity two = createDummyEntity("two");
|
||||
two.setBytes(twoBytes);
|
||||
two = repository.save(two);
|
||||
|
||||
byte[] threeBytes = { 3, 3, 3, 3, 3, 3, 3, 3 };
|
||||
DummyEntity three = createDummyEntity("three");
|
||||
three.setBytes(threeBytes);
|
||||
three = repository.save(three);
|
||||
|
||||
List<DummyEntity> result = repository.findByBytes(twoBytes);
|
||||
List<DummyEntity> result = repository.findByBytes(two.getBytes());
|
||||
|
||||
assertThat(result).extracting("idProp").containsExactly(two.idProp);
|
||||
}
|
||||
@@ -1419,7 +1398,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
|
||||
Instant now = Instant.now();
|
||||
|
||||
DummyEntity first = createDummyEntity();
|
||||
DummyEntity first = createEntity();
|
||||
Instant earlier = now.minusSeconds(1000L);
|
||||
OffsetDateTime earlierPlus3 = earlier.atOffset(ZoneOffset.ofHours(3));
|
||||
first.setPointInTime(earlier);
|
||||
@@ -1427,7 +1406,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
|
||||
first.setName("first");
|
||||
|
||||
DummyEntity second = createDummyEntity();
|
||||
DummyEntity second = createEntity();
|
||||
Instant later = now.plusSeconds(1000L);
|
||||
OffsetDateTime laterPlus3 = later.atOffset(ZoneOffset.ofHours(3));
|
||||
second.setPointInTime(later);
|
||||
@@ -1842,6 +1821,24 @@ public class JdbcRepositoryIntegrationTests {
|
||||
}
|
||||
}
|
||||
|
||||
private static DummyEntity createEntity() {
|
||||
return createEntity("Entity Name");
|
||||
}
|
||||
|
||||
private static DummyEntity createEntity(String entityName) {
|
||||
return createEntity(entityName, it -> {});
|
||||
}
|
||||
|
||||
private static DummyEntity createEntity(String entityName, Consumer<DummyEntity> customizer) {
|
||||
|
||||
DummyEntity entity = new DummyEntity();
|
||||
entity.setName(entityName);
|
||||
|
||||
customizer.accept(entity);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
static class DummyEntity {
|
||||
|
||||
String name;
|
||||
@@ -1936,6 +1933,10 @@ public class JdbcRepositoryIntegrationTests {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DummyEntity{" + "name='" + name + '\'' + ", idProp=" + idProp + '}';
|
||||
|
||||
Reference in New Issue
Block a user