Browse Source
Fixed using the actual field reference instead of the field name on resolving. Added equals(…) and hashCode() methods to value objects. Added unit tests for TypeBasedAggregationOperationContext.pull/59/head
7 changed files with 196 additions and 15 deletions
@ -0,0 +1,92 @@
@@ -0,0 +1,92 @@
|
||||
/* |
||||
* Copyright 2013 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.core.aggregation; |
||||
|
||||
import static org.hamcrest.CoreMatchers.*; |
||||
import static org.junit.Assert.*; |
||||
|
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
import org.mockito.Mock; |
||||
import org.mockito.runners.MockitoJUnitRunner; |
||||
import org.springframework.data.mapping.PropertyReferenceException; |
||||
import org.springframework.data.mongodb.MongoDbFactory; |
||||
import org.springframework.data.mongodb.core.convert.MappingMongoConverter; |
||||
import org.springframework.data.mongodb.core.convert.QueryMapper; |
||||
import org.springframework.data.mongodb.core.mapping.MongoMappingContext; |
||||
|
||||
/** |
||||
* Unit tests for {@link TypeBasedAggregationOperationContext}. |
||||
* |
||||
* @author Oliver Gierke |
||||
*/ |
||||
@RunWith(MockitoJUnitRunner.class) |
||||
public class TypeBasedAggregationOperationContextUnitTests { |
||||
|
||||
MongoMappingContext context; |
||||
MappingMongoConverter converter; |
||||
QueryMapper mapper; |
||||
|
||||
@Mock MongoDbFactory dbFactory; |
||||
|
||||
@Before |
||||
public void setUp() { |
||||
|
||||
this.context = new MongoMappingContext(); |
||||
this.converter = new MappingMongoConverter(dbFactory, context); |
||||
this.mapper = new QueryMapper(converter); |
||||
} |
||||
|
||||
@Test |
||||
public void findsSimpleReference() { |
||||
assertThat(getContext(Foo.class).getReference("bar"), is(notNullValue())); |
||||
} |
||||
|
||||
@Test(expected = PropertyReferenceException.class) |
||||
public void rejectsInvalidFieldReference() { |
||||
getContext(Foo.class).getReference("foo"); |
||||
} |
||||
|
||||
/** |
||||
* @see DATAMONGO-741 |
||||
*/ |
||||
@Test |
||||
public void returnsReferencesToNestedFieldsCorrectly() { |
||||
|
||||
AggregationOperationContext context = getContext(Foo.class); |
||||
|
||||
Field field = Fields.field("bar.name"); |
||||
|
||||
assertThat(context.getReference("bar.name"), is(notNullValue())); |
||||
assertThat(context.getReference(field), is(notNullValue())); |
||||
assertThat(context.getReference(field), is(context.getReference("bar.name"))); |
||||
} |
||||
|
||||
private TypeBasedAggregationOperationContext getContext(Class<?> type) { |
||||
return new TypeBasedAggregationOperationContext(type, context, mapper); |
||||
} |
||||
|
||||
static class Foo { |
||||
|
||||
Bar bar; |
||||
} |
||||
|
||||
static class Bar { |
||||
|
||||
String name; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue