DATAJDBC-258 - Polishing.
Simplified id value retrieval. Simplified ignoring tests for a specific database. Fixed property name in pom.xml. Original pull request: #98.
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -29,7 +29,7 @@
|
||||
<degraph-check.version>0.1.4</degraph-check.version>
|
||||
|
||||
<hsqldb.version>2.2.8</hsqldb.version>
|
||||
<mssql.verion>7.0.0.jre8</mssql.verion>
|
||||
<mssql.version>7.0.0.jre8</mssql.version>
|
||||
<mybatis.version>3.4.6</mybatis.version>
|
||||
<mybatis-spring.version>1.3.2</mybatis-spring.version>
|
||||
<mysql-connector-java.version>5.1.41</mysql-connector-java.version>
|
||||
|
||||
@@ -161,7 +161,7 @@
|
||||
<dependency>
|
||||
<groupId>com.microsoft.sqlserver</groupId>
|
||||
<artifactId>mssql-jdbc</artifactId>
|
||||
<version>${mssql.verion}</version>
|
||||
<version>${mssql.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -319,13 +319,16 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy {
|
||||
|| (idProperty.getType() == long.class && idValue.equals(0L));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private <S> Object getIdFromHolder(KeyHolder holder, RelationalPersistentEntity<S> persistentEntity) {
|
||||
|
||||
try {
|
||||
// MySQL just returns one value with a special name
|
||||
return holder.getKey();
|
||||
} catch (InvalidDataAccessApiUsageException e) {
|
||||
} catch (DataRetrievalFailureException | InvalidDataAccessApiUsageException e) {
|
||||
// Postgres returns a value for each column
|
||||
// MS SQL Server returns a value that might be null.
|
||||
|
||||
Map<String, Object> keys = holder.getKeys();
|
||||
|
||||
if (keys == null || persistentEntity.getIdProperty() == null) {
|
||||
@@ -333,17 +336,6 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy {
|
||||
}
|
||||
|
||||
return keys.get(persistentEntity.getIdColumn());
|
||||
} catch (DataRetrievalFailureException e) {
|
||||
// thomas.lang@th-deg.de
|
||||
// mssql causes org.springframework.dao.DataRetrievalFailureException:
|
||||
// The generated key is not of a supported numeric type. Unable to cast [null] to [java.lang.Number]
|
||||
// see what happens here
|
||||
|
||||
Map<String, Object> keys = holder.getKeys();
|
||||
if (keys == null || persistentEntity.getIdProperty() == null) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,9 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.assertj.core.api.SoftAssertions;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
@@ -30,19 +33,18 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.jdbc.testing.DatabaseProfileValueSource;
|
||||
import org.springframework.data.jdbc.testing.TestConfiguration;
|
||||
import org.springframework.data.relational.core.conversion.RelationalConverter;
|
||||
import org.springframework.data.relational.core.mapping.Column;
|
||||
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
import org.springframework.test.annotation.ProfileValueSourceConfiguration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.rules.SpringClassRule;
|
||||
import org.springframework.test.context.junit4.rules.SpringMethodRule;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link JdbcAggregateTemplate}.
|
||||
*
|
||||
@@ -51,6 +53,7 @@ import java.util.List;
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@Transactional
|
||||
@ProfileValueSourceConfiguration(DatabaseProfileValueSource.class)
|
||||
public class AggregateTemplateIntegrationTests {
|
||||
|
||||
@ClassRule public static final SpringClassRule classRule = new SpringClassRule();
|
||||
@@ -145,7 +148,7 @@ public class AggregateTemplateIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-112
|
||||
@IfProfileValue(name = "spring.profiles.active", values = {"mysql", "postgres", "mariadb", "default"}) // DATAJDBC-278
|
||||
@IfProfileValue(name = "current.database.is.not.mssql", value = "true") // DATAJDBC-278
|
||||
public void updateReferencedEntityFromNull() {
|
||||
|
||||
legoSet.setManual(null);
|
||||
@@ -204,7 +207,7 @@ public class AggregateTemplateIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-112
|
||||
@IfProfileValue(name = "spring.profiles.active", values = {"mysql", "postgres", "mariadb", "default"}) // DATAJDBC-278
|
||||
@IfProfileValue(name = "current.database.is.not.mssql", value = "true") // DATAJDBC-278
|
||||
public void changeReferencedEntity() {
|
||||
|
||||
template.save(legoSet);
|
||||
@@ -296,6 +299,7 @@ public class AggregateTemplateIntegrationTests {
|
||||
|
||||
softly.assertAll();
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-276
|
||||
public void saveAndLoadAnEntityWithListOfElementsWithoutId() {
|
||||
|
||||
@@ -368,7 +372,6 @@ public class AggregateTemplateIntegrationTests {
|
||||
private String content;
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@Import(TestConfiguration.class)
|
||||
static class Config {
|
||||
|
||||
@@ -40,10 +40,12 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
|
||||
import org.springframework.data.jdbc.testing.DatabaseProfileValueSource;
|
||||
import org.springframework.data.jdbc.testing.TestConfiguration;
|
||||
import org.springframework.data.relational.core.mapping.event.BeforeSaveEvent;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
import org.springframework.test.annotation.ProfileValueSourceConfiguration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.rules.SpringClassRule;
|
||||
import org.springframework.test.context.junit4.rules.SpringMethodRule;
|
||||
@@ -57,6 +59,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @author Thomas Lang
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@ProfileValueSourceConfiguration(DatabaseProfileValueSource.class)
|
||||
@Transactional
|
||||
public class JdbcRepositoryPropertyConversionIntegrationTests {
|
||||
|
||||
@@ -90,7 +93,7 @@ public class JdbcRepositoryPropertyConversionIntegrationTests {
|
||||
@Autowired DummyEntityRepository repository;
|
||||
|
||||
@Test // DATAJDBC-95
|
||||
@IfProfileValue(name = "spring.profiles.active", values = {"mysql", "postgres", "mariadb", "default"}) // DATAJDBC-278
|
||||
@IfProfileValue(name = "current.database.is.not.mssql", value = "true") // DATAJDBC-278
|
||||
public void saveAndLoadAnEntity() {
|
||||
|
||||
EntityWithColumnsRequiringConversions entity = repository.save(createDummyEntity());
|
||||
@@ -109,7 +112,7 @@ public class JdbcRepositoryPropertyConversionIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-95
|
||||
@IfProfileValue(name = "spring.profiles.active", values = {"mysql", "postgres", "mariadb", "default"}) // DATAJDBC-278
|
||||
@IfProfileValue(name = "current.database.is.not.mssql", value = "true") // DATAJDBC-278
|
||||
public void existsById() {
|
||||
|
||||
EntityWithColumnsRequiringConversions entity = repository.save(createDummyEntity());
|
||||
@@ -118,7 +121,7 @@ public class JdbcRepositoryPropertyConversionIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-95
|
||||
@IfProfileValue(name = "spring.profiles.active", values = {"mysql", "postgres", "mariadb", "default"}) // DATAJDBC-278
|
||||
@IfProfileValue(name = "current.database.is.not.mssql", value = "true") // DATAJDBC-278
|
||||
public void findAllById() {
|
||||
|
||||
EntityWithColumnsRequiringConversions entity = repository.save(createDummyEntity());
|
||||
@@ -127,7 +130,7 @@ public class JdbcRepositoryPropertyConversionIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-95
|
||||
@IfProfileValue(name = "spring.profiles.active", values = {"mysql", "postgres", "mariadb", "default"}) // DATAJDBC-278
|
||||
@IfProfileValue(name = "current.database.is.not.mssql", value = "true") // DATAJDBC-278
|
||||
public void deleteAll() {
|
||||
|
||||
EntityWithColumnsRequiringConversions entity = repository.save(createDummyEntity());
|
||||
@@ -138,7 +141,7 @@ public class JdbcRepositoryPropertyConversionIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-95
|
||||
@IfProfileValue(name = "spring.profiles.active", values = {"mysql", "postgres", "mariadb", "default"}) // DATAJDBC-278
|
||||
@IfProfileValue(name = "current.database.is.not.mssql", value = "true") // DATAJDBC-278
|
||||
public void deleteById() {
|
||||
|
||||
EntityWithColumnsRequiringConversions entity = repository.save(createDummyEntity());
|
||||
|
||||
@@ -34,10 +34,12 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
|
||||
import org.springframework.data.jdbc.testing.DatabaseProfileValueSource;
|
||||
import org.springframework.data.jdbc.testing.TestConfiguration;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
import org.springframework.test.annotation.ProfileValueSourceConfiguration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.rules.SpringClassRule;
|
||||
import org.springframework.test.context.junit4.rules.SpringMethodRule;
|
||||
@@ -50,6 +52,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @author Thomas Lang
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@ProfileValueSourceConfiguration(DatabaseProfileValueSource.class)
|
||||
@Transactional
|
||||
public class JdbcRepositoryWithCollectionsIntegrationTests {
|
||||
|
||||
@@ -136,7 +139,7 @@ public class JdbcRepositoryWithCollectionsIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-113
|
||||
@IfProfileValue(name = "spring.profiles.active", values = {"mysql", "postgres", "mariadb", "default"}) // DATAJDBC-278
|
||||
@IfProfileValue(name = "current.database.is.not.mssql", value = "true") // DATAJDBC-278
|
||||
public void updateSet() {
|
||||
|
||||
Element element1 = createElement("one");
|
||||
|
||||
@@ -34,10 +34,12 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
|
||||
import org.springframework.data.jdbc.testing.DatabaseProfileValueSource;
|
||||
import org.springframework.data.jdbc.testing.TestConfiguration;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
import org.springframework.test.annotation.ProfileValueSourceConfiguration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.rules.SpringClassRule;
|
||||
import org.springframework.test.context.junit4.rules.SpringMethodRule;
|
||||
@@ -50,6 +52,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @author Thomas Lang
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@ProfileValueSourceConfiguration(DatabaseProfileValueSource.class)
|
||||
@Transactional
|
||||
public class JdbcRepositoryWithListsIntegrationTests {
|
||||
|
||||
@@ -136,7 +139,7 @@ public class JdbcRepositoryWithListsIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-130
|
||||
@IfProfileValue(name = "spring.profiles.active", values = {"mysql", "postgres", "mariadb", "default"}) // DATAJDBC-278
|
||||
@IfProfileValue(name = "current.database.is.not.mssql", value = "true") // DATAJDBC-278
|
||||
public void updateList() {
|
||||
|
||||
Element element1 = createElement("one");
|
||||
|
||||
@@ -33,10 +33,12 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
|
||||
import org.springframework.data.jdbc.testing.DatabaseProfileValueSource;
|
||||
import org.springframework.data.jdbc.testing.TestConfiguration;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
import org.springframework.test.annotation.ProfileValueSourceConfiguration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.rules.SpringClassRule;
|
||||
import org.springframework.test.context.junit4.rules.SpringMethodRule;
|
||||
@@ -49,6 +51,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @author Thomas Lang
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@ProfileValueSourceConfiguration(DatabaseProfileValueSource.class)
|
||||
@Transactional
|
||||
public class JdbcRepositoryWithMapsIntegrationTests {
|
||||
|
||||
@@ -135,7 +138,7 @@ public class JdbcRepositoryWithMapsIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-131
|
||||
@IfProfileValue(name = "spring.profiles.active", values = {"mysql", "postgres", "mariadb", "default"}) // DATAJDBC-278
|
||||
@IfProfileValue(name = "current.database.is.not.mssql", value = "true") // DATAJDBC-278
|
||||
public void updateMap() {
|
||||
|
||||
Element element1 = createElement("one");
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2018 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.jdbc.testing;
|
||||
|
||||
import org.springframework.test.annotation.ProfileValueSource;
|
||||
|
||||
/**
|
||||
* This {@link ProfileValueSource} offers a single set of keys {@code current.database.is.not.<database>} where
|
||||
* {@code <database> } is a database as used in active profiles to enable integration tests to run with a certain
|
||||
* database. The value returned for these keys is {@code "true"} or {@code "false"} depending on if the database is
|
||||
* actually the one currently used by integration tests.
|
||||
*
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
public class DatabaseProfileValueSource implements ProfileValueSource {
|
||||
|
||||
private final String currentDatabase;
|
||||
|
||||
DatabaseProfileValueSource() {
|
||||
|
||||
currentDatabase = System.getProperty("spring.profiles.active", "hsqldb");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(String key) {
|
||||
|
||||
if (!key.startsWith("current.database.is.not.")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Boolean.toString(!key.endsWith(currentDatabase)).toLowerCase();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user