From c6b04618b9c0a06cc1301c49842754424be28b7b Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 16 Aug 2012 10:48:53 +0200 Subject: [PATCH] DATACMNS-216 - Removed deprecations from AbstractMappingContext. Removed the deprecation as it might still be necessary to set the ApplicationEventPublisher to emit MappingContextEvents. --- .../context/AbstractMappingContext.java | 44 +++++++------------ .../data/mapping/MappingMetadataTests.java | 16 +++---- .../AbstractMappingContextUnitTests.java | 18 ++++++-- 3 files changed, 40 insertions(+), 38 deletions(-) diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java index 94bd61669..105f7365a 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java @@ -35,7 +35,6 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantReadWriteLock; import org.springframework.beans.BeansException; -import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationEventPublisher; @@ -66,15 +65,16 @@ import org.springframework.util.ReflectionUtils.FieldCallback; * @author Oliver Gierke */ public abstract class AbstractMappingContext, P extends PersistentProperty

> - implements MappingContext, InitializingBean, ApplicationEventPublisherAware, ApplicationContextAware, + implements MappingContext, ApplicationContextAware, ApplicationEventPublisherAware, ApplicationListener { private static final Set UNMAPPED_FIELDS = new HashSet(Arrays.asList("class", "this$0")); private final ConcurrentMap, E> persistentEntities = new ConcurrentHashMap, E>(); - private ApplicationEventPublisher applicationEventPublisher; private ApplicationContext applicationContext; + private ApplicationEventPublisher applicationEventPublisher; + private Set> initialEntitySet = new HashSet>(); private boolean strict = false; private SimpleTypeHolder simpleTypeHolder = new SimpleTypeHolder(); @@ -83,23 +83,26 @@ public abstract class AbstractMappingContext + * Integration tests for Mapping metadata. + * + * @author Jon Brisbin + * @author Oliver Gierke */ public class MappingMetadataTests { @@ -44,11 +46,10 @@ public class MappingMetadataTests { } @Test - @SuppressWarnings("deprecation") public void testPojoWithId() { ctx.setInitialEntitySet(Collections.singleton(PersonWithId.class)); - ctx.afterPropertiesSet(); + ctx.initialize(); PersistentEntity person = ctx.getPersistentEntity(PersonWithId.class); assertNotNull(person.getIdProperty()); @@ -56,11 +57,10 @@ public class MappingMetadataTests { } @Test - @SuppressWarnings("deprecation") public void testAssociations() { ctx.setInitialEntitySet(Collections.singleton(PersonWithChildren.class)); - ctx.afterPropertiesSet(); + ctx.initialize(); PersistentEntity person = ctx.getPersistentEntity(PersonWithChildren.class); person.doWithAssociations(new AssociationHandler() { diff --git a/spring-data-commons-core/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextUnitTests.java b/spring-data-commons-core/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextUnitTests.java index c54d378bb..6c3d7db85 100644 --- a/spring-data-commons-core/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextUnitTests.java +++ b/spring-data-commons-core/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextUnitTests.java @@ -1,3 +1,18 @@ +/* + * Copyright 2011-2012 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.mapping.context; import static org.hamcrest.Matchers.*; @@ -61,7 +76,6 @@ public class AbstractMappingContextUnitTests { } @Test - @SuppressWarnings("deprecation") public void registersEntitiesOnContextRefreshedEvent() { ApplicationContext context = mock(ApplicationContext.class); @@ -69,9 +83,7 @@ public class AbstractMappingContextUnitTests { DummyMappingContext mappingContext = new DummyMappingContext(); mappingContext.setInitialEntitySet(Collections.singleton(Person.class)); mappingContext.setApplicationContext(context); - mappingContext.setApplicationEventPublisher(context); - mappingContext.afterPropertiesSet(); verify(context, times(0)).publishEvent(Mockito.any(ApplicationEvent.class)); mappingContext.onApplicationEvent(new ContextRefreshedEvent(context));