Skip to content

Commit

Permalink
Merge pull request #91 from mercyblitz/dev-1.x
Browse files Browse the repository at this point in the history
[Codebase] Sync code from 1.x branch to main branch
  • Loading branch information
mercyblitz authored Jan 10, 2025
2 parents daa561d + 6a19df7 commit 7f55dfb
Show file tree
Hide file tree
Showing 24 changed files with 133 additions and 167 deletions.
6 changes: 0 additions & 6 deletions microsphere-spring-context/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition;
import static org.springframework.beans.factory.support.BeanDefinitionReaderUtils.generateBeanName;
import static org.springframework.util.ClassUtils.getUserClass;
import static org.springframework.util.ClassUtils.resolveClassName;
import static org.springframework.util.StringUtils.hasText;

/**
Expand Down Expand Up @@ -207,7 +208,7 @@ public static Class<?> resolveBeanType(String beanClassName, ClassLoader classLo

Class<?> beanType = null;
try {
beanType = resolveClass(beanClassName, classLoader);
beanType = resolveClassName(beanClassName, classLoader);
beanType = getUserClass(beanType);
} catch (Exception e) {
if (logger.isErrorEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package io.microsphere.spring.beans.factory;

import io.microsphere.collection.CollectionUtils;
import io.microsphere.collection.SetUtils;
import io.microsphere.lang.function.ThrowableAction;
import io.microsphere.logging.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import io.microsphere.spring.cache.annotation.TTLCachePut;
import io.microsphere.spring.cache.annotation.TTLCacheable;
import io.microsphere.spring.context.event.OnceApplicationContextEventListener;
import io.microsphere.util.ArrayUtils;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.interceptor.CacheOperation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import static io.microsphere.spring.beans.factory.config.BeanDefinitionUtils.getInstanceSupplier;
import static io.microsphere.spring.core.MethodParameterUtils.forParameter;
import static io.microsphere.util.ArrayUtils.EMPTY_PARAMETER_ARRAY;
import static io.microsphere.util.ClassLoaderUtils.resolveClass;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptySet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package io.microsphere.spring.beans.factory;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
Expand Down Expand Up @@ -49,6 +48,8 @@
import static io.microsphere.util.ArrayUtils.of;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -79,11 +80,11 @@ public void testGetOptionalBean() {

applicationContext.register(BaseTestBean.class);

applicationContext.refresh();
this.applicationContext.refresh();

BaseTestBean testBean = getOptionalBean(applicationContext, "baseTestBean", BaseTestBean.class);

Assert.assertNotNull(testBean);
assertNotNull(testBean);

assertEquals("Hello,World", testBean.getName());

Expand All @@ -92,27 +93,27 @@ public void testGetOptionalBean() {
@Test
public void testGetOptionalBeanIfAbsent() {

applicationContext.refresh();
this.applicationContext.refresh();

BaseTestBean testBean = getOptionalBean(applicationContext, "baseTestBean", BaseTestBean.class);

Assert.assertNull(testBean);
assertNull(testBean);

testBean = getOptionalBean(applicationContext, "1", BaseTestBean.class);

Assert.assertNull(testBean);
assertNull(testBean);

testBean = getOptionalBean(applicationContext, null, BaseTestBean.class);

Assert.assertNull(testBean);
assertNull(testBean);
}

@Test
public void testGetBeans() {

applicationContext.register(BaseTestBean.class, BaseTestBean2.class);
this.applicationContext.register(BaseTestBean.class, BaseTestBean2.class);

applicationContext.refresh();
this.applicationContext.refresh();

List<BaseTestBean> testBeans = getBeans(applicationContext, new String[]{"baseTestBean"}, BaseTestBean.class);

Expand All @@ -136,7 +137,7 @@ public void testGetBeans() {
@Test
public void testGetBeansIfAbsent() {

applicationContext.refresh();
this.applicationContext.refresh();

List<BaseTestBean> testBeans = getBeans(applicationContext, new String[]{"baseTestBean"}, BaseTestBean.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package io.microsphere.spring.beans.factory.annotation;

import io.microsphere.spring.util.User;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -27,14 +26,17 @@
import org.springframework.core.Ordered;
import org.springframework.core.env.Environment;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* {@link AnnotatedInjectionBeanPostProcessor} Test
*
* @since 1.0.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {
AnnotationInjectedBeanPostProcessorTest.TestConfiguration.class,
AnnotatedInjectionBeanPostProcessorTest.ReferencedInjectedBeanPostProcessor.class,
Expand Down Expand Up @@ -69,26 +71,26 @@ public class AnnotatedInjectionBeanPostProcessorTest {
@Test
public void testCustomizedAnnotationBeanPostProcessor() {

Assert.assertEquals(environment, processor.getEnvironment());
Assert.assertEquals(beanFactory.getBeanClassLoader(), processor.getClassLoader());
Assert.assertEquals(beanFactory, processor.getBeanFactory());
assertEquals(environment, processor.getEnvironment());
assertEquals(beanFactory.getBeanClassLoader(), processor.getClassLoader());
assertEquals(beanFactory, processor.getBeanFactory());

Assert.assertEquals(1, processor.getAnnotationTypes().size());
Assert.assertTrue(processor.getAnnotationTypes().contains(Referenced.class));
Assert.assertEquals(Ordered.LOWEST_PRECEDENCE - 3, processor.getOrder());
assertEquals(1, processor.getAnnotationTypes().size());
assertTrue(processor.getAnnotationTypes().contains(Referenced.class));
assertEquals(Ordered.LOWEST_PRECEDENCE - 3, processor.getOrder());
}

@Test
public void testReferencedUser() {
Assert.assertEquals("mercyblitz", parent.user.getName());
Assert.assertEquals(32, parent.user.getAge());
Assert.assertEquals(parent.user, parent.parentUser);
Assert.assertEquals(parent.user, child.childUser);
Assert.assertEquals(parent.user, userHolder.user);
Assert.assertEquals(parent.user, genericChild.s);
Assert.assertEquals(parent.user, genericChild.s1);
Assert.assertEquals(parent.user, genericChild.s2);
Assert.assertEquals(parent.user, child.user);
assertEquals("mercyblitz", parent.user.getName());
assertEquals(32, parent.user.getAge());
assertEquals(parent.user, parent.parentUser);
assertEquals(parent.user, child.childUser);
assertEquals(parent.user, userHolder.user);
assertEquals(parent.user, genericChild.s);
assertEquals(parent.user, genericChild.s1);
assertEquals(parent.user, genericChild.s2);
assertEquals(parent.user, child.user);
}

public static class ReferencedInjectedBeanPostProcessor extends AnnotatedInjectionBeanPostProcessor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
Expand All @@ -44,7 +44,7 @@
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @since 1.0.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {
AnnotationBeanDefinitionRegistryPostProcessorTest.ServiceAnnotationBeanDefinitionRegistryPostProcessor.class,
AnnotationBeanDefinitionRegistryPostProcessorTest.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package io.microsphere.spring.beans.factory.annotation;

import io.microsphere.spring.util.User;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -28,15 +27,18 @@
import org.springframework.core.Ordered;
import org.springframework.core.env.Environment;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* {@link AnnotationInjectedBeanPostProcessor} Test
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @since 1.0.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {
AnnotationInjectedBeanPostProcessorTest.TestConfiguration.class,
AnnotationInjectedBeanPostProcessorTest.ReferencedAnnotationInjectedBeanPostProcessor.class
Expand Down Expand Up @@ -67,25 +69,25 @@ public class AnnotationInjectedBeanPostProcessorTest {
@Test
public void testCustomizedAnnotationBeanPostProcessor() {

Assert.assertEquals(environment, processor.getEnvironment());
Assert.assertEquals(beanFactory.getBeanClassLoader(), processor.getClassLoader());
Assert.assertEquals(beanFactory, processor.getBeanFactory());
assertEquals(environment, processor.getEnvironment());
assertEquals(beanFactory.getBeanClassLoader(), processor.getClassLoader());
assertEquals(beanFactory, processor.getBeanFactory());

Assert.assertEquals(Referenced.class, processor.getAnnotationType());
Assert.assertEquals(1, processor.getInjectedObjects().size());
Assert.assertTrue(processor.getInjectedObjects().contains(parent.parentUser));
Assert.assertEquals(2, processor.getInjectedFieldObjectsMap().size());
Assert.assertEquals(1, processor.getInjectedMethodObjectsMap().size());
Assert.assertEquals(Ordered.HIGHEST_PRECEDENCE, processor.getOrder());
assertEquals(Referenced.class, processor.getAnnotationType());
assertEquals(1, processor.getInjectedObjects().size());
assertTrue(processor.getInjectedObjects().contains(parent.parentUser));
assertEquals(2, processor.getInjectedFieldObjectsMap().size());
assertEquals(1, processor.getInjectedMethodObjectsMap().size());
assertEquals(Ordered.HIGHEST_PRECEDENCE, processor.getOrder());
}

@Test
public void testReferencedUser() {
Assert.assertEquals("mercyblitz", parent.user.getName());
Assert.assertEquals(32, parent.user.getAge());
Assert.assertEquals(parent.user, parent.parentUser);
Assert.assertEquals(parent.user, child.childUser);
Assert.assertEquals(parent.user, userHolder.user);
assertEquals("mercyblitz", parent.user.getName());
assertEquals(32, parent.user.getAge());
assertEquals(parent.user, parent.parentUser);
assertEquals(parent.user, child.childUser);
assertEquals(parent.user, userHolder.user);
}

static class TestConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
* @since 1.0.0
*/

import io.microsphere.spring.beans.BeanUtils;
import io.microsphere.spring.context.config.DefaultConfigurationBeanBinder;
import io.microsphere.spring.util.User;
import org.junit.Before;
Expand All @@ -32,6 +31,7 @@

import java.util.Collection;

import static io.microsphere.spring.beans.BeanUtils.getSortedBeans;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -61,7 +61,7 @@ public ConfigurationBeanBindingPostProcessor configurationBeanBindingPostProcess
public void init() {
aUser = context.getBean("a", User.class);
bUser = context.getBean("b", User.class);
users = BeanUtils.getSortedBeans(context, User.class);
users = getSortedBeans(context, User.class);
configurationBeanBindingPostProcessor = context.getBean("configurationBeanBindingPostProcessor", ConfigurationBeanBindingPostProcessor.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.microsphere.spring.test.Bean;
import io.microsphere.spring.test.TestBean;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.BeansException;

Expand Down Expand Up @@ -92,8 +91,8 @@ public void testPostProcess() {

String bean = "test";

Assert.assertEquals("test", beanPostProcessor.postProcessBeforeInitialization(bean, ""));
Assert.assertEquals("test", beanPostProcessor.postProcessAfterInitialization(bean, ""));
assertEquals("test", beanPostProcessor.postProcessBeforeInitialization(bean, ""));
assertEquals("test", beanPostProcessor.postProcessAfterInitialization(bean, ""));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.ApplicationListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;

import static org.junit.Assert.assertEquals;
Expand All @@ -38,7 +38,7 @@
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @since 1.0.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@ContextConfiguration(
classes = TestConfig.class,
loader = AnnotationConfigContextLoader.class
Expand Down
Loading

0 comments on commit 7f55dfb

Please sign in to comment.