2 changed files with 85 additions and 1 deletions
@ -0,0 +1,84 @@
@@ -0,0 +1,84 @@
|
||||
/* |
||||
* 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.mapping.model; |
||||
|
||||
import org.junit.Test; |
||||
import org.springframework.data.mapping.PropertyPath; |
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; |
||||
|
||||
import java.util.List; |
||||
|
||||
import static org.assertj.core.api.Assertions.*; |
||||
import static org.mockito.Mockito.*; |
||||
|
||||
/** |
||||
* Unit tests for {@link JdbcMappingContext}. |
||||
* |
||||
* @author Jens Schauder |
||||
*/ |
||||
public class JdbcMappingContextUnitTests { |
||||
|
||||
NamingStrategy namingStrategy = new DefaultNamingStrategy(); |
||||
NamedParameterJdbcOperations jdbcTemplate = mock(NamedParameterJdbcOperations.class); |
||||
ConversionCustomizer customizer = mock(ConversionCustomizer.class); |
||||
|
||||
@Test // DATAJDBC-142
|
||||
public void referencedEntitiesGetFound() { |
||||
|
||||
JdbcMappingContext mappingContext = new JdbcMappingContext(namingStrategy, jdbcTemplate, customizer); |
||||
|
||||
List<PropertyPath> propertyPaths = mappingContext.referencedEntities(DummyEntity.class, null); |
||||
|
||||
assertThat(propertyPaths) //
|
||||
.extracting(PropertyPath::toDotPath) //
|
||||
.containsExactly( //
|
||||
"one.two", //
|
||||
"one" //
|
||||
); |
||||
} |
||||
|
||||
@Test // DATAJDBC-142
|
||||
public void propertyPathDoesNotDependOnNamingStrategy() { |
||||
|
||||
namingStrategy = mock(NamingStrategy.class); |
||||
|
||||
JdbcMappingContext mappingContext = new JdbcMappingContext(namingStrategy, jdbcTemplate, customizer); |
||||
|
||||
List<PropertyPath> propertyPaths = mappingContext.referencedEntities(DummyEntity.class, null); |
||||
|
||||
assertThat(propertyPaths) //
|
||||
.extracting(PropertyPath::toDotPath) //
|
||||
.containsExactly( //
|
||||
"one.two", //
|
||||
"one" //
|
||||
); |
||||
} |
||||
|
||||
private static class DummyEntity { |
||||
|
||||
String simpleProperty; |
||||
|
||||
LevelOne one; |
||||
} |
||||
|
||||
private static class LevelOne { |
||||
LevelTwo two; |
||||
} |
||||
|
||||
private static class LevelTwo { |
||||
String someValue; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue