-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [ISSUE #315] Support spring 6.x
- Loading branch information
1 parent
e8cae2c
commit a61a02c
Showing
17 changed files
with
1,123 additions
and
21 deletions.
There are no files selected for viewing
642 changes: 642 additions & 0 deletions
642
...om/alibaba/nacos/spring/beans/factory/annotation/AbstractAnnotationBeanPostProcessor.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...libaba/nacos/spring/beans/factory/annotation/AbstractAnnotationBeanPostProcessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* | ||
* * Licensed to the Apache Software Foundation (ASF) under one or more | ||
* * contributor license agreements. See the NOTICE file distributed with | ||
* * this work for additional information regarding copyright ownership. | ||
* * The ASF licenses this file to You 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 com.alibaba.nacos.spring.beans.factory.annotation; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.beans.IntrospectionException; | ||
import java.beans.PropertyDescriptor; | ||
|
||
/** | ||
* {@link AbstractAnnotationBeanPostProcessor} Test | ||
* @author SuperZ1999 | ||
* @date 2023/9/28 | ||
*/ | ||
public class AbstractAnnotationBeanPostProcessorTest { | ||
@Test | ||
public void testPropertyDescriptor() throws IntrospectionException { | ||
PropertyDescriptor pd = new PropertyDescriptor("name", Student.class); | ||
Class<?> type = pd.getPropertyType(); | ||
Assert.assertEquals(type, String.class); | ||
} | ||
|
||
static class Student { | ||
String name; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...va/com/alibaba/nacos/spring/context/annotation/config/NacosPropertySourceBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* | ||
* * Licensed to the Apache Software Foundation (ASF) under one or more | ||
* * contributor license agreements. See the NOTICE file distributed with | ||
* * this work for additional information regarding copyright ownership. | ||
* * The ASF licenses this file to You 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 com.alibaba.nacos.spring.context.annotation.config; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.springframework.core.env.MapPropertySource; | ||
|
||
import java.util.HashMap; | ||
|
||
/** | ||
* {@link NacosPropertySourceBuilder} Test | ||
* @author SuperZ1999 | ||
* @date 2023/9/28 | ||
*/ | ||
public class NacosPropertySourceBuilderTest { | ||
@Test | ||
public void test() { | ||
MapPropertySource propertySource = new MapPropertySource("test", new HashMap<>()); | ||
Assert.assertNotNull(propertySource); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...aba/nacos/spring/context/annotation/config/NacosValueAnnotationBeanPostProcessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* | ||
* * Licensed to the Apache Software Foundation (ASF) under one or more | ||
* * contributor license agreements. See the NOTICE file distributed with | ||
* * this work for additional information regarding copyright ownership. | ||
* * The ASF licenses this file to You 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 com.alibaba.nacos.spring.context.annotation.config; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.TypeConverter; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.core.MethodParameter; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* {@link NacosValueAnnotationBeanPostProcessor} Test | ||
* @author SuperZ1999 | ||
* @date 2023/9/28 | ||
*/ | ||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration(classes = NacosValueAnnotationBeanPostProcessorTest.class) | ||
public class NacosValueAnnotationBeanPostProcessorTest { | ||
|
||
@Autowired | ||
private ConfigurableListableBeanFactory beanFactory; | ||
|
||
@Bean | ||
public NacosValueAnnotationBeanPostProcessor nacosValueAnnotationBeanPostProcessor() { | ||
return new NacosValueAnnotationBeanPostProcessor(); | ||
} | ||
|
||
@Test | ||
public void testConvertIfNecessary() throws NoSuchMethodException { | ||
TypeConverter converter = beanFactory.getTypeConverter(); | ||
Method method = NacosValueAnnotationBeanPostProcessorTest.class.getMethod("testMethodParameter", Integer.class); | ||
Integer integer = converter.convertIfNecessary("12", Integer.class, new MethodParameter(method, 0)); | ||
System.out.println(integer); | ||
Assert.assertEquals(integer, Integer.valueOf(12)); | ||
} | ||
|
||
public void testMethodParameter(Integer i) { | ||
System.out.println(i); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...com/alibaba/nacos/spring/context/config/xml/NacosPropertySourceXmlBeanDefinitionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* | ||
* * Licensed to the Apache Software Foundation (ASF) under one or more | ||
* * contributor license agreements. See the NOTICE file distributed with | ||
* * this work for additional information regarding copyright ownership. | ||
* * The ASF licenses this file to You 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 com.alibaba.nacos.spring.context.config.xml; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* {@link NacosPropertySourceXmlBeanDefinition} Test | ||
* @author SuperZ1999 | ||
* @date 2023/9/28 | ||
*/ | ||
public class NacosPropertySourceXmlBeanDefinitionTest { | ||
@Test | ||
public void test() { | ||
NacosPropertySourceXmlBeanDefinition beanDefinition = new NacosPropertySourceXmlBeanDefinition(); | ||
Assert.assertNotNull(beanDefinition); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...text/src/test/java/com/alibaba/nacos/spring/context/properties/config/DataBinderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* | ||
* * Licensed to the Apache Software Foundation (ASF) under one or more | ||
* * contributor license agreements. See the NOTICE file distributed with | ||
* * this work for additional information regarding copyright ownership. | ||
* * The ASF licenses this file to You 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 com.alibaba.nacos.spring.context.properties.config; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.springframework.beans.MutablePropertyValues; | ||
import org.springframework.validation.BindException; | ||
import org.springframework.validation.DataBinder; | ||
|
||
/** | ||
* {@link DataBinder} Test | ||
* @author SuperZ1999 | ||
* @date 2023/9/28 | ||
*/ | ||
public class DataBinderTest { | ||
@Test | ||
public void test() throws BindException { | ||
People people = new People(); | ||
MutablePropertyValues propertyValues = new MutablePropertyValues(); | ||
propertyValues.add("name", "SuperZ1999"); | ||
propertyValues.add("age", 24); | ||
DataBinder dataBinder = new DataBinder(people); | ||
dataBinder.setAutoGrowNestedPaths(false); | ||
dataBinder.setIgnoreInvalidFields(false); | ||
dataBinder.setIgnoreUnknownFields(true); | ||
dataBinder.bind(propertyValues); | ||
dataBinder.close(); | ||
|
||
Assert.assertEquals("SuperZ1999", people.getName()); | ||
Assert.assertEquals(24, people.getAge()); | ||
} | ||
|
||
static class People { | ||
private String name; | ||
private int age; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public int getAge() { | ||
return age; | ||
} | ||
|
||
public void setAge(int age) { | ||
this.age = age; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "People{" + | ||
"name='" + name + '\'' + | ||
", age=" + age + | ||
'}'; | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...t/src/test/java/com/alibaba/nacos/spring/factory/DelegatingNamingMaintainServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* | ||
* * Licensed to the Apache Software Foundation (ASF) under one or more | ||
* * contributor license agreements. See the NOTICE file distributed with | ||
* * this work for additional information regarding copyright ownership. | ||
* * The ASF licenses this file to You 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 com.alibaba.nacos.spring.factory; | ||
|
||
import com.alibaba.nacos.api.exception.NacosException; | ||
import com.alibaba.nacos.api.naming.pojo.Service; | ||
import com.alibaba.nacos.client.naming.NacosNamingMaintainService; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* {@link DelegatingNamingMaintainService} Test | ||
* @author SuperZ1999 | ||
* @date 2023/9/28 | ||
*/ | ||
public class DelegatingNamingMaintainServiceTest { | ||
@Test | ||
public void testNamingMaintainService() throws NacosException { | ||
NacosNamingMaintainService namingMaintainService = new NacosNamingMaintainService("127.0.0.1:8848"); | ||
Service service = namingMaintainService.queryService("example"); | ||
Assert.assertNotNull(service); | ||
} | ||
} |
Oops, something went wrong.