11 changed files with 216 additions and 5 deletions
@ -0,0 +1,113 @@
@@ -0,0 +1,113 @@
|
||||
/* |
||||
* Copyright 2017-2020 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 |
||||
* |
||||
* https://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.core; |
||||
|
||||
import org.junit.ClassRule; |
||||
import org.junit.Rule; |
||||
import org.junit.Test; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.context.ApplicationEventPublisher; |
||||
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.core.convert.DataAccessStrategy; |
||||
import org.springframework.data.jdbc.core.convert.JdbcConverter; |
||||
import org.springframework.data.jdbc.testing.TestConfiguration; |
||||
import org.springframework.data.relational.core.mapping.NamingStrategy; |
||||
import org.springframework.data.relational.core.mapping.RelationalMappingContext; |
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; |
||||
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 static org.assertj.core.api.Assertions.*; |
||||
|
||||
/** |
||||
* Integration tests for {@link JdbcAggregateTemplate} using an entity mapped with an explicite schema. |
||||
* |
||||
* @author Jens Schauder |
||||
*/ |
||||
@ContextConfiguration |
||||
@Transactional |
||||
public class JdbcAggregateTemplateSchemaIntegrationTests { |
||||
|
||||
@ClassRule public static final SpringClassRule classRule = new SpringClassRule(); |
||||
@Rule public SpringMethodRule methodRule = new SpringMethodRule(); |
||||
|
||||
@Autowired JdbcAggregateOperations template; |
||||
@Autowired NamedParameterJdbcOperations jdbcTemplate; |
||||
|
||||
|
||||
@Test |
||||
public void insertFindUpdateDelete() { |
||||
|
||||
DummyEntity entity = new DummyEntity(); |
||||
entity.name = "Alfred"; |
||||
entity.reference = new Referenced(); |
||||
entity.reference.name = "Peter"; |
||||
|
||||
template.save(entity); |
||||
|
||||
DummyEntity reloaded = template.findById(entity.id, DummyEntity.class); |
||||
|
||||
assertThat(reloaded).isNotNull(); |
||||
|
||||
reloaded.name += " E. Neumann"; |
||||
|
||||
template.save(reloaded); |
||||
|
||||
template.deleteById(reloaded.id, DummyEntity.class); |
||||
} |
||||
|
||||
static class DummyEntity { |
||||
|
||||
@Id Long id; |
||||
String name; |
||||
Referenced reference; |
||||
} |
||||
|
||||
static class Referenced { |
||||
String name; |
||||
} |
||||
|
||||
@Configuration |
||||
@Import(TestConfiguration.class) |
||||
static class Config { |
||||
|
||||
@Bean |
||||
Class<?> testClass() { |
||||
return JdbcAggregateTemplateSchemaIntegrationTests.class; |
||||
} |
||||
|
||||
@Bean |
||||
JdbcAggregateOperations operations(ApplicationEventPublisher publisher, RelationalMappingContext context, |
||||
DataAccessStrategy dataAccessStrategy, JdbcConverter converter) { |
||||
return new JdbcAggregateTemplate(publisher, context, converter, dataAccessStrategy); |
||||
} |
||||
|
||||
@Bean |
||||
NamingStrategy namingStrategy() { |
||||
return new NamingStrategy() { |
||||
@Override |
||||
public String getSchema() { |
||||
return "other"; |
||||
} |
||||
}; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
CREATE SCHEMA OTHER; |
||||
|
||||
CREATE TABLE OTHER.DUMMY_ENTITY |
||||
( |
||||
ID SERIAL PRIMARY KEY, |
||||
NAME VARCHAR(30) |
||||
); |
||||
|
||||
CREATE TABLE OTHER.REFERENCED |
||||
( |
||||
DUMMY_ENTITY INTEGER, |
||||
NAME VARCHAR(30) |
||||
); |
||||
|
||||
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
CREATE SCHEMA OTHER; |
||||
|
||||
CREATE TABLE OTHER.DUMMY_ENTITY |
||||
( |
||||
ID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY, |
||||
NAME VARCHAR(30) |
||||
); |
||||
|
||||
|
||||
CREATE TABLE OTHER.REFERENCED |
||||
( |
||||
DUMMY_ENTITY INTEGER, |
||||
NAME VARCHAR(30) |
||||
); |
||||
|
||||
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
CREATE SCHEMA OTHER; |
||||
|
||||
CREATE TABLE OTHER.DUMMY_ENTITY |
||||
( |
||||
ID BIGINT AUTO_INCREMENT PRIMARY KEY, |
||||
NAME VARCHAR(30) |
||||
); |
||||
|
||||
|
||||
CREATE TABLE OTHER.REFERENCED |
||||
( |
||||
DUMMY_ENTITY INTEGER, |
||||
NAME VARCHAR(30) |
||||
); |
||||
|
||||
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
CREATE SCHEMA OTHER; |
||||
|
||||
CREATE TABLE OTHER.DUMMY_ENTITY |
||||
( |
||||
ID BIGINT AUTO_INCREMENT PRIMARY KEY, |
||||
NAME VARCHAR(30) |
||||
); |
||||
|
||||
|
||||
CREATE TABLE OTHER.REFERENCED |
||||
( |
||||
DUMMY_ENTITY INTEGER, |
||||
NAME VARCHAR(30) |
||||
); |
||||
|
||||
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
CREATE SCHEMA OTHER; |
||||
|
||||
CREATE TABLE OTHER.DUMMY_ENTITY |
||||
( |
||||
ID SERIAL PRIMARY KEY, |
||||
NAME VARCHAR(30) |
||||
); |
||||
|
||||
CREATE TABLE OTHER.REFERENCED |
||||
( |
||||
DUMMY_ENTITY INTEGER, |
||||
NAME VARCHAR(30) |
||||
); |
||||
|
||||
Loading…
Reference in new issue