Browse Source
The custom MongodbSerializer considers mapping information when building keys for the Querydsl queries to be executed.pull/1/head
3 changed files with 98 additions and 2 deletions
@ -0,0 +1,50 @@
@@ -0,0 +1,50 @@
|
||||
/* |
||||
* Copyright 2011 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.mongodb.repository.support; |
||||
|
||||
import static org.hamcrest.CoreMatchers.*; |
||||
import static org.junit.Assert.*; |
||||
|
||||
import org.junit.Test; |
||||
import org.springframework.data.mongodb.core.mapping.MongoMappingContext; |
||||
import org.springframework.data.mongodb.repository.QPerson; |
||||
import org.springframework.data.mongodb.repository.support.QueryDslMongoRepository.SpringDataMongodbSerializer; |
||||
|
||||
import com.mysema.query.types.path.StringPath; |
||||
|
||||
/** |
||||
* Unit tests for {@link SpringDataMongodbSerializer}. |
||||
* |
||||
* @author Oliver Gierke |
||||
*/ |
||||
public class SpringDataMongodbSerializerUnitTests { |
||||
|
||||
MongoMappingContext context = new MongoMappingContext(); |
||||
SpringDataMongodbSerializer serializer = new QueryDslMongoRepository.SpringDataMongodbSerializer(context); |
||||
|
||||
@Test |
||||
public void uses_idAsKeyForIdProperty() { |
||||
|
||||
StringPath path = QPerson.person.id; |
||||
assertThat(serializer.getKeyForPath(path, path.getMetadata()), is("_id")); |
||||
} |
||||
|
||||
@Test |
||||
public void buildsNestedKeyCorrectly() { |
||||
StringPath path = QPerson.person.address.street; |
||||
assertThat(serializer.getKeyForPath(path, path.getMetadata()), is("street")); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue