index
int64
0
0
repo_id
stringlengths
9
205
file_path
stringlengths
31
246
content
stringlengths
1
12.2M
__index_level_0__
int64
0
10k
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/Filter3.java
/* * 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 org.apache.dubbo.common.extension.support; import org.apache.dubbo.common.extension.Activate; @Activate(after = "_4") public class Filter3 implements Filter0 {}
5,200
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/Filter2.java
/* * 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 org.apache.dubbo.common.extension.support; import org.apache.dubbo.common.extension.Activate; @Activate(before = "_1") public class Filter2 implements Filter0 {}
5,201
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/Order0Filter2.java
/* * 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 org.apache.dubbo.common.extension.support; import org.apache.dubbo.common.extension.Activate; @Activate public class Order0Filter2 implements Order0Filter0 {}
5,202
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/Filter4.java
/* * 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 org.apache.dubbo.common.extension.support; import org.apache.dubbo.common.extension.Activate; @Activate(before = "_2") public class Filter4 implements Filter0 {}
5,203
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/activate/ActivateExt1.java
/* * 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 org.apache.dubbo.common.extension.activate; import org.apache.dubbo.common.extension.SPI; @SPI("impl1") public interface ActivateExt1 { String echo(String msg); }
5,204
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/activate
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/activate/impl/ActivateExt1Impl1.java
/* * 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 org.apache.dubbo.common.extension.activate.impl; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.extension.activate.ActivateExt1; @Activate( order = 1, group = {"default_group"}) public class ActivateExt1Impl1 implements ActivateExt1 { public String echo(String msg) { return msg; } }
5,205
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/activate
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/activate/impl/OldActivateExt1Impl2.java
/* * 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 org.apache.dubbo.common.extension.activate.impl; import org.apache.dubbo.common.extension.activate.ActivateExt1; import com.alibaba.dubbo.common.extension.Activate; @Activate(group = "old_group") public class OldActivateExt1Impl2 implements ActivateExt1 { public String echo(String msg) { return msg; } }
5,206
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/activate
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/activate/impl/OldActivateExt1Impl3.java
/* * 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 org.apache.dubbo.common.extension.activate.impl; import org.apache.dubbo.common.extension.activate.ActivateExt1; import com.alibaba.dubbo.common.extension.Activate; @Activate(group = "old_group") public class OldActivateExt1Impl3 implements ActivateExt1 { public String echo(String msg) { return msg; } }
5,207
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/common
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/common/utils/AnnotationUtilsTest.java
/* * 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 org.apache.dubbo.common.utils; import org.apache.dubbo.common.extension.Adaptive; import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.annotation.Service; import java.lang.annotation.Annotation; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.junit.jupiter.api.Test; import static java.util.Arrays.asList; import static org.apache.dubbo.common.utils.AnnotationUtils.excludedType; import static org.apache.dubbo.common.utils.AnnotationUtils.filterDefaultValues; import static org.apache.dubbo.common.utils.AnnotationUtils.findAnnotation; import static org.apache.dubbo.common.utils.AnnotationUtils.findMetaAnnotation; import static org.apache.dubbo.common.utils.AnnotationUtils.findMetaAnnotations; import static org.apache.dubbo.common.utils.AnnotationUtils.getAllDeclaredAnnotations; import static org.apache.dubbo.common.utils.AnnotationUtils.getAllMetaAnnotations; import static org.apache.dubbo.common.utils.AnnotationUtils.getAnnotation; import static org.apache.dubbo.common.utils.AnnotationUtils.getAttribute; import static org.apache.dubbo.common.utils.AnnotationUtils.getAttributes; import static org.apache.dubbo.common.utils.AnnotationUtils.getDeclaredAnnotations; import static org.apache.dubbo.common.utils.AnnotationUtils.getDefaultValue; import static org.apache.dubbo.common.utils.AnnotationUtils.getMetaAnnotations; import static org.apache.dubbo.common.utils.AnnotationUtils.getValue; import static org.apache.dubbo.common.utils.AnnotationUtils.isAnnotationPresent; import static org.apache.dubbo.common.utils.AnnotationUtils.isAnyAnnotationPresent; import static org.apache.dubbo.common.utils.AnnotationUtils.isSameType; import static org.apache.dubbo.common.utils.AnnotationUtils.isType; import static org.apache.dubbo.common.utils.MethodUtils.findMethod; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; /** * {@link AnnotationUtils} Test * * @since 2.7.6 */ class AnnotationUtilsTest { @Test void testIsType() { // null checking assertFalse(isType(null)); // Method checking assertFalse(isType(findMethod(A.class, "execute"))); // Class checking assertTrue(isType(A.class)); } @Test void testIsSameType() { assertTrue(isSameType(A.class.getAnnotation(Service.class), Service.class)); assertFalse(isSameType(A.class.getAnnotation(Service.class), Deprecated.class)); assertFalse(isSameType(A.class.getAnnotation(Service.class), null)); assertFalse(isSameType(null, Deprecated.class)); assertFalse(isSameType(null, null)); } @Test void testExcludedType() { assertFalse(excludedType(Service.class).test(A.class.getAnnotation(Service.class))); assertTrue(excludedType(Service.class).test(A.class.getAnnotation(Deprecated.class))); } @Test void testGetAttribute() { Annotation annotation = A.class.getAnnotation(Service.class); assertEquals("java.lang.CharSequence", getAttribute(annotation, "interfaceName")); assertEquals(CharSequence.class, getAttribute(annotation, "interfaceClass")); assertEquals("", getAttribute(annotation, "version")); assertEquals("", getAttribute(annotation, "group")); assertEquals("", getAttribute(annotation, "path")); assertEquals(true, getAttribute(annotation, "export")); assertEquals(false, getAttribute(annotation, "deprecated")); } @Test void testGetAttributesMap() { Annotation annotation = A.class.getAnnotation(Service.class); Map<String, Object> attributes = getAttributes(annotation, false); assertEquals("java.lang.CharSequence", attributes.get("interfaceName")); assertEquals(CharSequence.class, attributes.get("interfaceClass")); assertEquals("", attributes.get("group")); assertEquals(getDefaultValue(annotation, "export"), attributes.get("export")); Map<String, Object> filteredAttributes = filterDefaultValues(annotation, attributes); assertEquals(2, filteredAttributes.size()); assertEquals("java.lang.CharSequence", filteredAttributes.get("interfaceName")); assertEquals(CharSequence.class, filteredAttributes.get("interfaceClass")); assertFalse(filteredAttributes.containsKey("group")); assertFalse(filteredAttributes.containsKey("export")); Map<String, Object> nonDefaultAttributes = getAttributes(annotation, true); assertEquals(nonDefaultAttributes, filteredAttributes); } @Test void testGetValue() { Adaptive adaptive = A.class.getAnnotation(Adaptive.class); String[] value = getValue(adaptive); assertEquals(asList("a", "b", "c"), asList(value)); } @Test void testGetDeclaredAnnotations() { List<Annotation> annotations = getDeclaredAnnotations(A.class); assertADeclaredAnnotations(annotations, 0); annotations = getDeclaredAnnotations(A.class, a -> isSameType(a, Service.class)); assertEquals(1, annotations.size()); Service service = (Service) annotations.get(0); assertEquals("java.lang.CharSequence", service.interfaceName()); assertEquals(CharSequence.class, service.interfaceClass()); } @Test void testGetAllDeclaredAnnotations() { List<Annotation> annotations = getAllDeclaredAnnotations(A.class); assertADeclaredAnnotations(annotations, 0); annotations = getAllDeclaredAnnotations(B.class); assertTrue(isSameType(annotations.get(0), Service5.class)); assertADeclaredAnnotations(annotations, 1); annotations = new LinkedList<>(getAllDeclaredAnnotations(C.class)); assertTrue(isSameType(annotations.get(0), MyAdaptive.class)); assertTrue(isSameType(annotations.get(1), Service5.class)); assertADeclaredAnnotations(annotations, 2); annotations = getAllDeclaredAnnotations(findMethod(A.class, "execute")); MyAdaptive myAdaptive = (MyAdaptive) annotations.get(0); assertArrayEquals(new String[] {"e"}, myAdaptive.value()); annotations = getAllDeclaredAnnotations(findMethod(B.class, "execute")); Adaptive adaptive = (Adaptive) annotations.get(0); assertArrayEquals(new String[] {"f"}, adaptive.value()); } @Test void testGetMetaAnnotations() { List<Annotation> metaAnnotations = getMetaAnnotations(Service.class, a -> isSameType(a, Inherited.class)); assertEquals(1, metaAnnotations.size()); assertEquals(Inherited.class, metaAnnotations.get(0).annotationType()); metaAnnotations = getMetaAnnotations(Service.class); HashSet<Object> set1 = new HashSet<>(); metaAnnotations.forEach(t -> set1.add(t.annotationType())); HashSet<Object> set2 = new HashSet<>(); set2.add(Inherited.class); set2.add(Deprecated.class); assertEquals(2, metaAnnotations.size()); assertEquals(set1, set2); } @Test void testGetAllMetaAnnotations() { List<Annotation> metaAnnotations = getAllMetaAnnotations(Service5.class); int offset = 0; HashSet<Object> set1 = new HashSet<>(); metaAnnotations.forEach(t -> set1.add(t.annotationType())); HashSet<Object> set2 = new HashSet<>(); set2.add(Inherited.class); set2.add(DubboService.class); set2.add(Service4.class); set2.add(Service3.class); set2.add(Service2.class); assertEquals(9, metaAnnotations.size()); assertEquals(set1, set2); metaAnnotations = getAllMetaAnnotations(MyAdaptive.class); HashSet<Object> set3 = new HashSet<>(); metaAnnotations.forEach(t -> set3.add(t.annotationType())); HashSet<Object> set4 = new HashSet<>(); metaAnnotations.forEach(t -> set3.add(t.annotationType())); set4.add(Inherited.class); set4.add(Adaptive.class); assertEquals(2, metaAnnotations.size()); assertEquals(set3, set4); } @Test void testIsAnnotationPresent() { assertTrue(isAnnotationPresent(A.class, true, Service.class)); assertTrue( isAnnotationPresent(A.class, true, Service.class, com.alibaba.dubbo.config.annotation.Service.class)); assertTrue(isAnnotationPresent(A.class, Service.class)); assertTrue(isAnnotationPresent(A.class, "org.apache.dubbo.config.annotation.Service")); assertTrue(AnnotationUtils.isAllAnnotationPresent( A.class, Service.class, Service.class, com.alibaba.dubbo.config.annotation.Service.class)); assertTrue(isAnnotationPresent(A.class, Deprecated.class)); } @Test void testIsAnyAnnotationPresent() { assertTrue(isAnyAnnotationPresent( A.class, Service.class, com.alibaba.dubbo.config.annotation.Service.class, Deprecated.class)); assertTrue(isAnyAnnotationPresent(A.class, Service.class, com.alibaba.dubbo.config.annotation.Service.class)); assertTrue(isAnyAnnotationPresent(A.class, Service.class, Deprecated.class)); assertTrue( isAnyAnnotationPresent(A.class, com.alibaba.dubbo.config.annotation.Service.class, Deprecated.class)); assertTrue(isAnyAnnotationPresent(A.class, Service.class)); assertTrue(isAnyAnnotationPresent(A.class, com.alibaba.dubbo.config.annotation.Service.class)); assertTrue(isAnyAnnotationPresent(A.class, Deprecated.class)); } @Test void testGetAnnotation() { assertNotNull(getAnnotation(A.class, "org.apache.dubbo.config.annotation.Service")); assertNotNull(getAnnotation(A.class, "com.alibaba.dubbo.config.annotation.Service")); assertNotNull(getAnnotation(A.class, "org.apache.dubbo.common.extension.Adaptive")); assertNull(getAnnotation(A.class, "java.lang.Deprecated")); assertNull(getAnnotation(A.class, "java.lang.String")); assertNull(getAnnotation(A.class, "NotExistedClass")); } @Test void testFindAnnotation() { Service service = findAnnotation(A.class, Service.class); assertEquals("java.lang.CharSequence", service.interfaceName()); assertEquals(CharSequence.class, service.interfaceClass()); service = findAnnotation(B.class, Service.class); assertEquals(CharSequence.class, service.interfaceClass()); } @Test void testFindMetaAnnotations() { List<DubboService> services = findMetaAnnotations(B.class, DubboService.class); assertEquals(1, services.size()); DubboService service = services.get(0); assertEquals("", service.interfaceName()); assertEquals(Cloneable.class, service.interfaceClass()); services = findMetaAnnotations(Service5.class, DubboService.class); assertEquals(1, services.size()); service = services.get(0); assertEquals("", service.interfaceName()); assertEquals(Cloneable.class, service.interfaceClass()); } @Test void testFindMetaAnnotation() { DubboService service = findMetaAnnotation(B.class, DubboService.class); assertEquals(Cloneable.class, service.interfaceClass()); service = findMetaAnnotation(B.class, "org.apache.dubbo.config.annotation.DubboService"); assertEquals(Cloneable.class, service.interfaceClass()); service = findMetaAnnotation(Service5.class, DubboService.class); assertEquals(Cloneable.class, service.interfaceClass()); } @Service(interfaceName = "java.lang.CharSequence", interfaceClass = CharSequence.class) @com.alibaba.dubbo.config.annotation.Service( interfaceName = "java.lang.CharSequence", interfaceClass = CharSequence.class) @Adaptive(value = {"a", "b", "c"}) static class A { @MyAdaptive("e") public void execute() {} } @Documented @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) @Inherited @DubboService(interfaceClass = Cloneable.class) @interface Service2 {} @Documented @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) @Inherited @Service2 @interface Service3 {} @Documented @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) @Inherited @Service3 @interface Service4 {} @Documented @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) @Inherited @Service4 @interface Service5 {} @Documented @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD}) @Inherited @Adaptive @interface MyAdaptive { String[] value() default {}; } @Service5 static class B extends A { @Adaptive("f") @Override public void execute() {} } @MyAdaptive static class C extends B {} private void assertADeclaredAnnotations(List<Annotation> annotations, int offset) { int size = 3 + offset; assertEquals(size, annotations.size()); boolean apacheServiceFound = false; boolean alibabaServiceFound = false; boolean adaptiveFound = false; for (Annotation annotation : annotations) { if (!apacheServiceFound && (annotation instanceof Service)) { assertEquals("java.lang.CharSequence", ((Service) annotation).interfaceName()); assertEquals(CharSequence.class, ((Service) annotation).interfaceClass()); apacheServiceFound = true; continue; } if (!alibabaServiceFound && (annotation instanceof com.alibaba.dubbo.config.annotation.Service)) { assertEquals( "java.lang.CharSequence", ((com.alibaba.dubbo.config.annotation.Service) annotation).interfaceName()); assertEquals( CharSequence.class, ((com.alibaba.dubbo.config.annotation.Service) annotation).interfaceClass()); alibabaServiceFound = true; continue; } if (!adaptiveFound && (annotation instanceof Adaptive)) { assertArrayEquals(new String[] {"a", "b", "c"}, ((Adaptive) annotation).value()); adaptiveFound = true; continue; } } assertTrue(apacheServiceFound && alibabaServiceFound && adaptiveFound); } }
5,208
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/generic/GenericServiceTest.java
/* * 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 org.apache.dubbo.generic; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.compact.Dubbo2CompactUtils; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.utils.JsonUtils; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder; import org.apache.dubbo.metadata.definition.model.FullServiceDefinition; import org.apache.dubbo.metadata.definition.model.MethodDefinition; import org.apache.dubbo.metadata.definition.model.TypeDefinition; import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Protocol; import org.apache.dubbo.rpc.ProxyFactory; import org.apache.dubbo.rpc.service.GenericService; import org.apache.dubbo.service.ComplexObject; import org.apache.dubbo.service.DemoService; import org.apache.dubbo.service.DemoServiceImpl; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import com.alibaba.dubbo.config.ReferenceConfig; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; class GenericServiceTest { @BeforeEach public void beforeEach() { DubboBootstrap.reset(); } @Test void testGeneric() { DemoService server = new DemoServiceImpl(); ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension(); Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension(); URL url = URL.valueOf("dubbo://127.0.0.1:5342/" + DemoService.class.getName() + "?version=1.0.0"); Exporter<DemoService> exporter = protocol.export(proxyFactory.getInvoker(server, DemoService.class, url)); Invoker<DemoService> invoker = protocol.refer(DemoService.class, url); GenericService client = (GenericService) proxyFactory.getProxy(invoker, true); Object result = client.$invoke("sayHello", new String[] {"java.lang.String"}, new Object[] {"haha"}); Assertions.assertEquals("hello haha", result); org.apache.dubbo.rpc.service.GenericService newClient = (org.apache.dubbo.rpc.service.GenericService) proxyFactory.getProxy(invoker, true); Object res = newClient.$invoke("sayHello", new String[] {"java.lang.String"}, new Object[] {"hehe"}); Assertions.assertEquals("hello hehe", res); invoker.destroy(); exporter.unexport(); } @Test void testGeneric2() { DemoService server = new DemoServiceImpl(); ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension(); Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension(); URL url = URL.valueOf( "dubbo://127.0.0.1:5342/" + DemoService.class.getName() + "?version=1.0.0&generic=true$timeout=3000"); Exporter<DemoService> exporter = protocol.export(proxyFactory.getInvoker(server, DemoService.class, url)); Invoker<GenericService> invoker = protocol.refer(GenericService.class, url); GenericService client = proxyFactory.getProxy(invoker, true); Object result = client.$invoke("sayHello", new String[] {"java.lang.String"}, new Object[] {"haha"}); Assertions.assertEquals("hello haha", result); Invoker<DemoService> invoker2 = protocol.refer(DemoService.class, url); GenericService client2 = (GenericService) proxyFactory.getProxy(invoker2, true); Object result2 = client2.$invoke("sayHello", new String[] {"java.lang.String"}, new Object[] {"haha"}); Assertions.assertEquals("hello haha", result2); invoker.destroy(); exporter.unexport(); } @Test void testGenericCompatible() { DubboBootstrap.getInstance().application("test-app").initialize(); DemoService server = new DemoServiceImpl(); ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension(); Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension(); URL url = URL.valueOf( "dubbo://127.0.0.1:5342/" + DemoService.class.getName() + "?version=1.0.0&generic=true$timeout=3000"); Exporter<DemoService> exporter = protocol.export(proxyFactory.getInvoker(server, DemoService.class, url)); // simulate normal invoke ReferenceConfig oldReferenceConfig = new ReferenceConfig<>(); oldReferenceConfig.setGeneric(true); oldReferenceConfig.setInterface(DemoService.class.getName()); oldReferenceConfig.refresh(); Invoker invoker = protocol.refer(oldReferenceConfig.getInterfaceClass(), url); GenericService client = (GenericService) proxyFactory.getProxy(invoker, true); Assertions.assertInstanceOf(Dubbo2CompactUtils.getGenericServiceClass(), client); Object result = client.$invoke("sayHello", new String[] {"java.lang.String"}, new Object[] {"haha"}); Assertions.assertEquals("hello haha", result); invoker.destroy(); exporter.unexport(); } @Test void testGenericComplexCompute4FullServiceMetadata() { DemoService server = new DemoServiceImpl(); ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension(); Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension(); URL url = URL.valueOf( "dubbo://127.0.0.1:5342/" + DemoService.class.getName() + "?version=1.0.0&generic=true$timeout=3000"); Exporter<DemoService> exporter = protocol.export(proxyFactory.getInvoker(server, DemoService.class, url)); String var1 = "v1"; int var2 = 234; long l = 555; String[] var3 = {"var31", "var32"}; List<Integer> var4 = Arrays.asList(2, 4, 8); ComplexObject.TestEnum testEnum = ComplexObject.TestEnum.VALUE2; FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(DemoService.class); MethodDefinition methodDefinition = getMethod("complexCompute", fullServiceDefinition.getMethods()); Map mapObject = createComplexObject(fullServiceDefinition, var1, var2, l, var3, var4, testEnum); ComplexObject complexObject = map2bean(mapObject); Invoker<GenericService> invoker = protocol.refer(GenericService.class, url); GenericService client = proxyFactory.getProxy(invoker, true); Object result = client.$invoke( methodDefinition.getName(), methodDefinition.getParameterTypes(), new Object[] {"haha", mapObject}); Assertions.assertEquals("haha###" + complexObject.toString(), result); Invoker<DemoService> invoker2 = protocol.refer(DemoService.class, url); GenericService client2 = (GenericService) proxyFactory.getProxy(invoker2, true); Object result2 = client2.$invoke( "complexCompute", methodDefinition.getParameterTypes(), new Object[] {"haha2", mapObject}); Assertions.assertEquals("haha2###" + complexObject.toString(), result2); invoker.destroy(); exporter.unexport(); } @Test void testGenericFindComplexObject4FullServiceMetadata() { DemoService server = new DemoServiceImpl(); ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension(); Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension(); URL url = URL.valueOf( "dubbo://127.0.0.1:5342/" + DemoService.class.getName() + "?version=1.0.0&generic=true$timeout=3000"); Exporter<DemoService> exporter = protocol.export(proxyFactory.getInvoker(server, DemoService.class, url)); String var1 = "v1"; int var2 = 234; long l = 555; String[] var3 = {"var31", "var32"}; List<Integer> var4 = Arrays.asList(2, 4, 8); ComplexObject.TestEnum testEnum = ComplexObject.TestEnum.VALUE2; // ComplexObject complexObject = createComplexObject(var1, var2, l, var3, var4, testEnum); Invoker<GenericService> invoker = protocol.refer(GenericService.class, url); GenericService client = proxyFactory.getProxy(invoker, true); Object result = client.$invoke( "findComplexObject", new String[] { "java.lang.String", "int", "long", "java.lang.String[]", "java.util.List", "org.apache.dubbo.service.ComplexObject$TestEnum" }, new Object[] {var1, var2, l, var3, var4, testEnum}); Assertions.assertNotNull(result); ComplexObject r = map2bean((Map) result); Assertions.assertEquals(r, createComplexObject(var1, var2, l, var3, var4, testEnum)); invoker.destroy(); exporter.unexport(); } MethodDefinition getMethod(String methodName, List<MethodDefinition> list) { for (MethodDefinition methodDefinition : list) { if (methodDefinition.getName().equals(methodName)) { return methodDefinition; } } return null; } Map<String, Object> createComplexObject( FullServiceDefinition fullServiceDefinition, String var1, int var2, long l, String[] var3, List<Integer> var4, ComplexObject.TestEnum testEnum) { List<TypeDefinition> typeDefinitions = fullServiceDefinition.getTypes(); TypeDefinition topTypeDefinition = null; TypeDefinition innerTypeDefinition = null; TypeDefinition inner2TypeDefinition = null; TypeDefinition inner3TypeDefinition = null; for (TypeDefinition typeDefinition : typeDefinitions) { if (typeDefinition.getType().equals(ComplexObject.class.getCanonicalName())) { topTypeDefinition = typeDefinition; } else if (typeDefinition.getType().equals(ComplexObject.InnerObject.class.getCanonicalName())) { innerTypeDefinition = typeDefinition; } else if (typeDefinition.getType().equals(ComplexObject.InnerObject2.class.getCanonicalName())) { inner2TypeDefinition = typeDefinition; } else if (typeDefinition.getType().equals(ComplexObject.InnerObject3.class.getCanonicalName())) { inner3TypeDefinition = typeDefinition; } } Assertions.assertEquals("long", topTypeDefinition.getProperties().get("v")); Assertions.assertEquals( "java.util.Map<java.lang.String,java.lang.String>", topTypeDefinition.getProperties().get("maps")); Assertions.assertEquals( "org.apache.dubbo.service.ComplexObject.InnerObject", topTypeDefinition.getProperties().get("innerObject")); Assertions.assertEquals( "java.util.List<java.lang.Integer>", topTypeDefinition.getProperties().get("intList")); Assertions.assertEquals( "java.lang.String[]", topTypeDefinition.getProperties().get("strArrays")); Assertions.assertEquals( "org.apache.dubbo.service.ComplexObject.InnerObject3[]", topTypeDefinition.getProperties().get("innerObject3")); Assertions.assertEquals( "org.apache.dubbo.service.ComplexObject.TestEnum", topTypeDefinition.getProperties().get("testEnum")); Assertions.assertEquals( "java.util.List<org.apache.dubbo.service.ComplexObject.InnerObject2>", topTypeDefinition.getProperties().get("innerObject2")); Assertions.assertSame( "java.lang.String", innerTypeDefinition.getProperties().get("innerA")); Assertions.assertSame("int", innerTypeDefinition.getProperties().get("innerB")); Assertions.assertSame( "java.lang.String", inner2TypeDefinition.getProperties().get("innerA2")); Assertions.assertSame("int", inner2TypeDefinition.getProperties().get("innerB2")); Assertions.assertSame( "java.lang.String", inner3TypeDefinition.getProperties().get("innerA3")); Map<String, Object> result = new HashMap<>(); result.put("v", l); Map maps = new HashMap<>(4); maps.put(var1 + "_k1", var1 + "_v1"); maps.put(var1 + "_k2", var1 + "_v2"); result.put("maps", maps); result.put("intList", var4); result.put("strArrays", var3); result.put("testEnum", testEnum.name()); Map innerObjectMap = new HashMap<>(4); result.put("innerObject", innerObjectMap); innerObjectMap.put("innerA", var1); innerObjectMap.put("innerB", var2); List<Map> innerObject2List = new ArrayList<>(); result.put("innerObject2", innerObject2List); Map innerObject2Tmp1 = new HashMap<>(4); innerObject2Tmp1.put("innerA2", var1 + "_21"); innerObject2Tmp1.put("innerB2", var2 + 100000); Map innerObject2Tmp2 = new HashMap<>(4); innerObject2Tmp2.put("innerA2", var1 + "_22"); innerObject2Tmp2.put("innerB2", var2 + 200000); innerObject2List.add(innerObject2Tmp1); innerObject2List.add(innerObject2Tmp2); Map innerObject3Tmp1 = new HashMap<>(4); innerObject3Tmp1.put("innerA3", var1 + "_31"); Map innerObject3Tmp2 = new HashMap<>(4); innerObject3Tmp2.put("innerA3", var1 + "_32"); Map innerObject3Tmp3 = new HashMap<>(4); innerObject3Tmp3.put("innerA3", var1 + "_32"); result.put("innerObject3", new Map[] {innerObject3Tmp1, innerObject3Tmp2, innerObject3Tmp3}); return result; } Map<String, Object> bean2Map(ComplexObject complexObject) { return JsonUtils.toJavaObject(JsonUtils.toJson(complexObject), Map.class); } ComplexObject map2bean(Map<String, Object> map) { return JsonUtils.toJavaObject(JsonUtils.toJson(map), ComplexObject.class); } ComplexObject createComplexObject( String var1, int var2, long l, String[] var3, List<Integer> var4, ComplexObject.TestEnum testEnum) { return new ComplexObject(var1, var2, l, var3, var4, testEnum); } }
5,209
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/filter/MyFilter.java
/* * 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 org.apache.dubbo.filter; import com.alibaba.dubbo.rpc.Filter; import com.alibaba.dubbo.rpc.Invocation; import com.alibaba.dubbo.rpc.Invoker; import com.alibaba.dubbo.rpc.Result; import com.alibaba.dubbo.rpc.RpcException; import com.alibaba.dubbo.rpc.RpcResult; public class MyFilter implements Filter { public static int count = 0; @Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { count++; if (invocation.getArguments()[0].equals("aa")) { throw new RpcException(new IllegalArgumentException("arg0 illegal")); } if (invocation.getArguments()[0].equals("cc")) { return new RpcResult("123test"); } Result tmp = invoker.invoke(invocation); return tmp; } }
5,210
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/filter/FilterTest.java
/* * 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 org.apache.dubbo.filter; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.RpcInvocation; import com.alibaba.dubbo.rpc.Filter; import com.alibaba.dubbo.rpc.Invocation; import com.alibaba.dubbo.rpc.Invoker; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.fail; class FilterTest { Filter myFilter = new MyFilter(); @Test void testInvokeException() { try { Invoker<FilterTest> invoker = new LegacyInvoker<FilterTest>(null); Invocation invocation = new LegacyInvocation("aa"); myFilter.invoke(invoker, invocation); fail(); } catch (RpcException e) { Assertions.assertTrue(e.getMessage().contains("arg0 illegal")); } } @Test void testDefault() throws Throwable { Invoker<FilterTest> invoker = new LegacyInvoker<FilterTest>(null); org.apache.dubbo.rpc.Invocation invocation = new RpcInvocation( null, "echo", "DemoService", "DemoService", new Class[] {String.class}, new Object[] {"bbb"}); org.apache.dubbo.rpc.Result res = myFilter.invoke(invoker, invocation); Assertions.assertEquals("alibaba", res.recreate()); } @Test void testRecreate() throws Throwable { Invoker<FilterTest> invoker = new LegacyInvoker<FilterTest>(null); org.apache.dubbo.rpc.Invocation invocation = new RpcInvocation( null, "echo", "DemoService", "DemoService", new Class[] {String.class}, new Object[] {"cc"}); org.apache.dubbo.rpc.Result res = myFilter.invoke(invoker, invocation); Assertions.assertEquals("123test", res.recreate()); } @AfterAll public static void tear() { Assertions.assertEquals(3, MyFilter.count); } }
5,211
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/filter/LegacyInvocation.java
/* * 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 org.apache.dubbo.filter; import java.util.HashMap; import java.util.List; import java.util.Map; import com.alibaba.dubbo.rpc.Invocation; import com.alibaba.dubbo.rpc.Invoker; import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY; import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; import static org.apache.dubbo.rpc.Constants.TOKEN_KEY; /** * MockInvocation.java */ public class LegacyInvocation implements Invocation { private String arg0; public LegacyInvocation(String arg0) { this.arg0 = arg0; } @Override public String getTargetServiceUniqueName() { return null; } @Override public String getProtocolServiceKey() { return null; } public String getMethodName() { return "echo"; } public Class<?>[] getParameterTypes() { return new Class[] {String.class}; } public Object[] getArguments() { return new Object[] {arg0}; } public Map<String, String> getAttachments() { Map<String, String> attachments = new HashMap<String, String>(); attachments.put(PATH_KEY, "dubbo"); attachments.put(GROUP_KEY, "dubbo"); attachments.put(VERSION_KEY, "1.0.0"); attachments.put(DUBBO_VERSION_KEY, "1.0.0"); attachments.put(TOKEN_KEY, "sfag"); attachments.put(TIMEOUT_KEY, "1000"); return attachments; } public Invoker<?> getInvoker() { return null; } @Override public Object put(Object key, Object value) { return null; } @Override public Object get(Object key) { return null; } @Override public Map<Object, Object> getAttributes() { return null; } public String getAttachment(String key) { return getAttachments().get(key); } public String getAttachment(String key, String defaultValue) { return getAttachments().get(key); } @Override public void addInvokedInvoker(org.apache.dubbo.rpc.Invoker<?> invoker) {} @Override public List<org.apache.dubbo.rpc.Invoker<?>> getInvokedInvokers() { return null; } }
5,212
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/filter/LegacyInvoker.java
/* * 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 org.apache.dubbo.filter; import org.apache.dubbo.service.DemoService; import com.alibaba.dubbo.common.URL; import com.alibaba.dubbo.rpc.Invocation; import com.alibaba.dubbo.rpc.Invoker; import com.alibaba.dubbo.rpc.Result; import com.alibaba.dubbo.rpc.RpcException; import com.alibaba.dubbo.rpc.RpcResult; public class LegacyInvoker<T> implements Invoker<T> { URL url; Class<T> type; boolean hasException = false; public LegacyInvoker(URL url) { this.url = url; type = (Class<T>) DemoService.class; } public LegacyInvoker(URL url, boolean hasException) { this.url = url; type = (Class<T>) DemoService.class; this.hasException = hasException; } @Override public Class<T> getInterface() { return type; } public URL getUrl() { return url; } @Override public boolean isAvailable() { return false; } public Result invoke(Invocation invocation) throws RpcException { RpcResult result = new RpcResult(); if (!hasException) { result.setValue("alibaba"); } else { result.setException(new RuntimeException("mocked exception")); } return result; } @Override public void destroy() {} }
5,213
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/service/ComplexObject.java
/* * 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 org.apache.dubbo.service; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; /** * ON 2018/11/5 */ public class ComplexObject { public ComplexObject() {} public ComplexObject( String var1, int var2, long l, String[] var3, List<Integer> var4, ComplexObject.TestEnum testEnum) { this.setInnerObject(new ComplexObject.InnerObject()); this.getInnerObject().setInnerA(var1); this.getInnerObject().setInnerB(var2); this.setIntList(var4); this.setStrArrays(var3); this.setTestEnum(testEnum); this.setV(l); InnerObject2 io21 = new InnerObject2(); io21.setInnerA2(var1 + "_21"); io21.setInnerB2(var2 + 100000); InnerObject2 io22 = new InnerObject2(); io22.setInnerA2(var1 + "_22"); io22.setInnerB2(var2 + 200000); this.setInnerObject2(new ArrayList<>(Arrays.asList(io21, io22))); InnerObject3 io31 = new InnerObject3(); io31.setInnerA3(var1 + "_31"); InnerObject3 io32 = new InnerObject3(); io32.setInnerA3(var1 + "_32"); InnerObject3 io33 = new InnerObject3(); io33.setInnerA3(var1 + "_33"); this.setInnerObject3(new InnerObject3[] {io31, io32, io33}); this.maps = new HashMap<>(4); this.maps.put(var1 + "_k1", var1 + "_v1"); this.maps.put(var1 + "_k2", var1 + "_v2"); } private InnerObject innerObject; private List<InnerObject2> innerObject2; private InnerObject3[] innerObject3; private String[] strArrays; private List<Integer> intList; private long v; private TestEnum testEnum; private Map<String, String> maps; public InnerObject getInnerObject() { return innerObject; } public void setInnerObject(InnerObject innerObject) { this.innerObject = innerObject; } public String[] getStrArrays() { return strArrays; } public void setStrArrays(String[] strArrays) { this.strArrays = strArrays; } public List<Integer> getIntList() { return intList; } public void setIntList(List<Integer> intList) { this.intList = intList; } public long getV() { return v; } public void setV(long v) { this.v = v; } public TestEnum getTestEnum() { return testEnum; } public void setTestEnum(TestEnum testEnum) { this.testEnum = testEnum; } public List<InnerObject2> getInnerObject2() { return innerObject2; } public void setInnerObject2(List<InnerObject2> innerObject2) { this.innerObject2 = innerObject2; } public InnerObject3[] getInnerObject3() { return innerObject3; } public void setInnerObject3(InnerObject3[] innerObject3) { this.innerObject3 = innerObject3; } public Map<String, String> getMaps() { return maps; } public void setMaps(Map<String, String> maps) { this.maps = maps; } @Override public String toString() { return "ComplexObject{" + "innerObject=" + innerObject + ", innerObject2=" + innerObject2 + ", innerObject3=" + Arrays.toString(innerObject3) + ", strArrays=" + Arrays.toString(strArrays) + ", intList=" + intList + ", v=" + v + ", testEnum=" + testEnum + ", maps=" + maps + '}'; } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof ComplexObject)) return false; ComplexObject that = (ComplexObject) o; return getV() == that.getV() && Objects.equals(getInnerObject(), that.getInnerObject()) && Objects.equals(getInnerObject2(), that.getInnerObject2()) && Arrays.equals(getInnerObject3(), that.getInnerObject3()) && Arrays.equals(getStrArrays(), that.getStrArrays()) && Objects.equals(getIntList(), that.getIntList()) && getTestEnum() == that.getTestEnum() && Objects.equals(getMaps(), that.getMaps()); } @Override public int hashCode() { int result = Objects.hash(getInnerObject(), getInnerObject2(), getIntList(), getV(), getTestEnum(), getMaps()); result = 31 * result + Arrays.hashCode(getInnerObject3()); result = 31 * result + Arrays.hashCode(getStrArrays()); return result; } public enum TestEnum { VALUE1, VALUE2 } public static class InnerObject { String innerA; int innerB; public String getInnerA() { return innerA; } public void setInnerA(String innerA) { this.innerA = innerA; } public int getInnerB() { return innerB; } public void setInnerB(int innerB) { this.innerB = innerB; } @Override public String toString() { return "InnerObject{" + "innerA='" + innerA + '\'' + ", innerB=" + innerB + '}'; } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof InnerObject)) return false; InnerObject that = (InnerObject) o; return getInnerB() == that.getInnerB() && Objects.equals(getInnerA(), that.getInnerA()); } @Override public int hashCode() { return Objects.hash(getInnerA(), getInnerB()); } } public static class InnerObject2 { String innerA2; int innerB2; public String getInnerA2() { return innerA2; } public void setInnerA2(String innerA2) { this.innerA2 = innerA2; } public int getInnerB2() { return innerB2; } public void setInnerB2(int innerB2) { this.innerB2 = innerB2; } @Override public String toString() { return "InnerObject{" + "innerA='" + innerA2 + '\'' + ", innerB=" + innerB2 + '}'; } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof InnerObject2)) return false; InnerObject2 that = (InnerObject2) o; return getInnerB2() == that.getInnerB2() && Objects.equals(getInnerA2(), that.getInnerA2()); } @Override public int hashCode() { return Objects.hash(getInnerA2(), getInnerB2()); } } public static class InnerObject3 { String innerA3; public String getInnerA3() { return innerA3; } public void setInnerA3(String innerA3) { this.innerA3 = innerA3; } @Override public String toString() { return "InnerObject3{" + "innerA3='" + innerA3 + '\'' + '}'; } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof InnerObject3)) return false; InnerObject3 that = (InnerObject3) o; return Objects.equals(getInnerA3(), that.getInnerA3()); } @Override public int hashCode() { return Objects.hash(getInnerA3()); } } }
5,214
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/service/Type.java
/* * 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 org.apache.dubbo.service; public enum Type { High, Normal, Lower }
5,215
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/service/CustomArgument.java
/* * 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 org.apache.dubbo.service; import java.io.Serializable; @SuppressWarnings("serial") public class CustomArgument implements Serializable { Type type; String name; public CustomArgument() {} public CustomArgument(Type type, String name) { super(); this.type = type; this.name = name; } public Type getType() { return type; } public void setType(Type type) { this.type = type; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
5,216
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/service/MockInvocation.java
/* * 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 org.apache.dubbo.service; import org.apache.dubbo.rpc.AttachmentsAdapter; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.model.ServiceModel; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Consumer; import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY; import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; import static org.apache.dubbo.rpc.Constants.TOKEN_KEY; /** * MockInvocation.java */ public class MockInvocation implements Invocation { private String arg0; private Map<String, Object> attachments; public MockInvocation(String arg0) { this.arg0 = arg0; attachments = new HashMap<>(); attachments.put(PATH_KEY, "dubbo"); attachments.put(GROUP_KEY, "dubbo"); attachments.put(VERSION_KEY, "1.0.0"); attachments.put(DUBBO_VERSION_KEY, "1.0.0"); attachments.put(TOKEN_KEY, "sfag"); attachments.put(TIMEOUT_KEY, "1000"); } @Override public String getTargetServiceUniqueName() { return null; } @Override public String getProtocolServiceKey() { return null; } public String getMethodName() { return "echo"; } @Override public String getServiceName() { return "DemoService"; } public Class<?>[] getParameterTypes() { return new Class[] {String.class}; } public Object[] getArguments() { return new Object[] {arg0}; } public Map<String, String> getAttachments() { return new AttachmentsAdapter.ObjectToStringMap(attachments); } @Override public Map<String, Object> getObjectAttachments() { return attachments; } @Override public Map<String, Object> copyObjectAttachments() { return new HashMap<>(attachments); } @Override public void foreachAttachment(Consumer<Map.Entry<String, Object>> consumer) { attachments.entrySet().forEach(consumer); } @Override public void setAttachment(String key, String value) { setObjectAttachment(key, value); } @Override public void setAttachment(String key, Object value) { setObjectAttachment(key, value); } @Override public void setObjectAttachment(String key, Object value) { attachments.put(key, value); } @Override public void setAttachmentIfAbsent(String key, String value) { setObjectAttachmentIfAbsent(key, value); } @Override public void setAttachmentIfAbsent(String key, Object value) { setObjectAttachmentIfAbsent(key, value); } @Override public void setObjectAttachmentIfAbsent(String key, Object value) { attachments.put(key, value); } public Invoker<?> getInvoker() { return null; } @Override public Object put(Object key, Object value) { return null; } @Override public Object get(Object key) { return null; } @Override public void setServiceModel(ServiceModel serviceModel) {} @Override public ServiceModel getServiceModel() { return null; } @Override public Map<Object, Object> getAttributes() { return null; } public String getAttachment(String key) { return (String) getObjectAttachments().get(key); } @Override public Object getObjectAttachment(String key) { return attachments.get(key); } public String getAttachment(String key, String defaultValue) { return (String) getObjectAttachments().get(key); } @Override public Object getObjectAttachment(String key, Object defaultValue) { Object result = attachments.get(key); if (result == null) { return defaultValue; } return result; } @Override public void addInvokedInvoker(Invoker<?> invoker) {} @Override public List<Invoker<?>> getInvokedInvokers() { return null; } }
5,217
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/service/DemoServiceImpl.java
/* * 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 org.apache.dubbo.service; import org.apache.dubbo.rpc.RpcContext; import java.util.List; /** * DemoServiceImpl */ public class DemoServiceImpl implements DemoService { public DemoServiceImpl() { super(); } public String sayHello(String name) { return "hello " + name; } public long timestamp() { return System.currentTimeMillis(); } public String getThreadName() { return Thread.currentThread().getName(); } public int getSize(String[] strs) { if (strs == null) return -1; return strs.length; } public int getSize(Object[] os) { if (os == null) return -1; return os.length; } public Object invoke(String service, String method) throws Exception { System.out.println("RpcContext.getServerAttachment().getRemoteHost()=" + RpcContext.getServiceContext().getRemoteHost()); return service + ":" + method; } public Type enumlength(Type... types) { if (types.length == 0) return Type.Lower; return types[0]; } public Type enumlength(Type type) { return type; } public int stringLength(String str) { return str.length(); } public String get(CustomArgument arg1) { return arg1.toString(); } public byte getbyte(byte arg) { return arg; } @Override public String complexCompute(String input, ComplexObject co) { return input + "###" + co.toString(); } @Override public ComplexObject findComplexObject( String var1, int var2, long l, String[] var3, List<Integer> var4, ComplexObject.TestEnum testEnum) { return new ComplexObject(var1, var2, l, var3, var4, testEnum); } public Person gerPerson(Person person) { return person; } }
5,218
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/service/Person.java
/* * 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 org.apache.dubbo.service; import java.io.Serializable; /** * Person.java */ public class Person implements Serializable { private static final long serialVersionUID = 1L; 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; } }
5,219
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/service/DemoService.java
/* * 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 org.apache.dubbo.service; import java.util.List; public interface DemoService { String sayHello(String name); long timestamp(); String getThreadName(); int getSize(String[] strs); int getSize(Object[] os); Object invoke(String service, String method) throws Exception; int stringLength(String str); Type enumlength(Type... types); // Type enumlength(Type type); String get(CustomArgument arg1); byte getbyte(byte arg); String complexCompute(String input, ComplexObject co); ComplexObject findComplexObject( String var1, int var2, long l, String[] var3, List<Integer> var4, ComplexObject.TestEnum testEnum); }
5,220
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/RpcContextTest.java
/* * 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 org.apache.dubbo.rpc; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Future; import com.alibaba.dubbo.rpc.RpcContext; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; class RpcContextTest { @Test void testSetFuture() { CompletableFuture completableFuture = new CompletableFuture(); RpcContext.getContext().setFuture(completableFuture); CompletableFuture result = FutureContext.getContext().getCompatibleCompletableFuture(); assertEquals(result, completableFuture); } @Test void testSetFutureAlibaba() { CompletableFuture completableFuture = new CompletableFuture(); RpcContext.getContext().setFuture(completableFuture); Future future = RpcContext.getContext().getFuture(); System.out.println(future); } }
5,221
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/rpc
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/cluster/CompatibleRouter.java
/* * 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 org.apache.dubbo.rpc.cluster; import java.util.List; import com.alibaba.dubbo.common.URL; import com.alibaba.dubbo.rpc.Invocation; import com.alibaba.dubbo.rpc.Invoker; import com.alibaba.dubbo.rpc.RpcException; import com.alibaba.dubbo.rpc.cluster.Router; /** * */ public class CompatibleRouter implements Router { @Override public URL getUrl() { return null; } @Override public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { return null; } @Override public int compareTo(Router o) { return 0; } }
5,222
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/rpc
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/cluster/CompatibleRouter2.java
/* * 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 org.apache.dubbo.rpc.cluster; import java.util.List; import com.alibaba.dubbo.common.URL; import com.alibaba.dubbo.rpc.Invocation; import com.alibaba.dubbo.rpc.Invoker; import com.alibaba.dubbo.rpc.RpcException; import com.alibaba.dubbo.rpc.cluster.Router; /** * */ public class CompatibleRouter2 implements Router { @Override public URL getUrl() { return null; } @Override public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { return null; } @Override public int compareTo(Router o) { return 0; } }
5,223
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/rpc
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/cluster/NewRouter.java
/* * 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 org.apache.dubbo.rpc.cluster; import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcException; import java.util.List; /** * */ public class NewRouter implements Router { @Override public URL getUrl() { return null; } @Override public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { return null; } @Override public boolean isRuntime() { return false; } @Override public boolean isForce() { return false; } @Override public int getPriority() { return 0; } }
5,224
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/rpc
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/cluster/RouterTest.java
/* * 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 org.apache.dubbo.rpc.cluster; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; /** * */ class RouterTest { private static List<Router> routers = new ArrayList<>(); @BeforeAll public static void setUp() { CompatibleRouter compatibleRouter = new CompatibleRouter(); routers.add(compatibleRouter); CompatibleRouter2 compatibleRouter2 = new CompatibleRouter2(); routers.add(compatibleRouter2); NewRouter newRouter = new NewRouter(); routers.add(newRouter); } @Test void testCompareTo() { try { Collections.sort(routers); Assertions.assertTrue(true); } catch (Exception e) { Assertions.assertFalse(false); } } }
5,225
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/rpc
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/support/Type.java
/* * 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 org.apache.dubbo.rpc.support; public enum Type { High, Normal, Lower }
5,226
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/rpc
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/support/Person.java
/* * 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 org.apache.dubbo.rpc.support; import java.io.Serializable; /** * Person.java */ public class Person implements Serializable { private static final long serialVersionUID = 1L; private String name; private int age; public Person() {} public Person(String name, int age) { this.name = name; this.age = 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; } }
5,227
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/rpc
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/support/DemoService.java
/* * 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 org.apache.dubbo.rpc.support; import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; public interface DemoService { void sayHello(String name); String echo(String text); long timestamp(); String getThreadName(); int getSize(String[] strs); int getSize(Object[] os); Object invoke(String service, String method) throws Exception; int stringLength(String str); Type enumlength(Type... types); // Type enumlength(Type type); // String get(CustomArgument arg1); byte getbyte(byte arg); Person getPerson(Person person); String testReturnType(String str); List<String> testReturnType1(String str); CompletableFuture<String> testReturnType2(String str); CompletableFuture<List<String>> testReturnType3(String str); CompletableFuture testReturnType4(String str); CompletableFuture<Map<String, String>> testReturnType5(String str); void $invoke(String s1, String s2); }
5,228
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/rpc
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/filter/GenericImplFilterTest.java
/* * 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 org.apache.dubbo.rpc.filter; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.compact.Dubbo2GenericExceptionUtils; import org.apache.dubbo.rpc.AppResponse; import org.apache.dubbo.rpc.AsyncRpcResult; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcInvocation; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.support.DemoService; import org.apache.dubbo.rpc.support.Person; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import static org.mockito.Mockito.any; import static org.mockito.Mockito.when; class GenericImplFilterTest { private GenericImplFilter genericImplFilter = new GenericImplFilter(ApplicationModel.defaultModel().getDefaultModule()); @Test void testInvokeWithException() throws Exception { RpcInvocation invocation = new RpcInvocation( "getPerson", "org.apache.dubbo.rpc.support.DemoService", "org.apache.dubbo.rpc.support.DemoService:dubbo", new Class[] {Person.class}, new Object[] {new Person("dubbo", 10)}); URL url = URL.valueOf("test://test:11/org.apache.dubbo.rpc.support.DemoService?" + "accesslog=true&group=dubbo&version=1.1&generic=true"); Invoker invoker = Mockito.mock(Invoker.class); AppResponse mockRpcResult = new AppResponse(Dubbo2GenericExceptionUtils.newGenericException(new RuntimeException("failed"))); when(invoker.invoke(any(Invocation.class))) .thenReturn(AsyncRpcResult.newDefaultAsyncResult(mockRpcResult, invocation)); when(invoker.getUrl()).thenReturn(url); when(invoker.getInterface()).thenReturn(DemoService.class); Result asyncResult = genericImplFilter.invoke(invoker, invocation); Result result = asyncResult.get(); genericImplFilter.onResponse(result, invoker, invocation); Assertions.assertEquals(RuntimeException.class, result.getException().getClass()); } }
5,229
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/tools/SpringRestServiceTest.java
/* * 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 org.apache.dubbo.metadata.tools; import org.apache.dubbo.metadata.rest.RestService; import org.apache.dubbo.metadata.rest.SpringRestService; import org.apache.dubbo.metadata.rest.User; import java.io.IOException; import org.junit.jupiter.api.Test; /** * {@link SpringRestService} Test * * @since 2.7.6 */ class SpringRestServiceTest { @Test void test() throws IOException { Compiler compiler = new Compiler(); compiler.compile(User.class, RestService.class, SpringRestService.class); } }
5,230
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/tools/StandardRestServiceTest.java
/* * 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 org.apache.dubbo.metadata.tools; import org.apache.dubbo.metadata.rest.RestService; import org.apache.dubbo.metadata.rest.StandardRestService; import org.apache.dubbo.metadata.rest.User; import java.io.IOException; import org.junit.jupiter.api.Test; /** * The test case for {@link StandardRestService} * * @since 2.7.6 */ class StandardRestServiceTest { @Test void test() throws IOException { Compiler compiler = new Compiler(); compiler.compile(User.class, RestService.class, StandardRestService.class); } }
5,231
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/tools/TestProcessor.java
/* * 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 org.apache.dubbo.metadata.tools; import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.Processor; import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.SupportedAnnotationTypes; import javax.lang.model.SourceVersion; import javax.lang.model.element.TypeElement; import java.util.Set; import static javax.lang.model.SourceVersion.latestSupported; /** * {@link Processor} for test * * @since 2.7.6 */ @SupportedAnnotationTypes("*") public class TestProcessor extends AbstractProcessor { @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { return false; } public ProcessingEnvironment getProcessingEnvironment() { return super.processingEnv; } public SourceVersion getSupportedSourceVersion() { return latestSupported(); } }
5,232
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/tools/TestServiceImpl.java
/* * 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 org.apache.dubbo.metadata.tools; import org.apache.dubbo.config.annotation.Service; import java.io.Serializable; /** * {@link TestService} Implementation * * @since 2.7.6 */ @com.alibaba.dubbo.config.annotation.Service( interfaceName = "org.apache.dubbo.metadata.tools.TestService", interfaceClass = TestService.class, version = "3.0.0", group = "test") @Service( interfaceName = "org.apache.dubbo.metadata.tools.TestService", interfaceClass = TestService.class, version = "3.0.0", group = "test") public class TestServiceImpl extends GenericTestService implements TestService, AutoCloseable, Serializable { @Override public String echo(String message) { return "[ECHO] " + message; } @Override public void close() throws Exception {} }
5,233
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/tools/DefaultRestServiceTest.java
/* * 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 org.apache.dubbo.metadata.tools; import org.apache.dubbo.metadata.rest.DefaultRestService; import org.apache.dubbo.metadata.rest.RestService; import org.apache.dubbo.metadata.rest.SpringRestService; import org.apache.dubbo.metadata.rest.StandardRestService; import org.apache.dubbo.metadata.rest.User; import java.io.IOException; import org.junit.jupiter.api.Test; /** * The test case for {@link DefaultRestService} * * @since 2.7.6 */ class DefaultRestServiceTest { @Test void test() throws IOException { Compiler compiler = new Compiler(); compiler.compile( User.class, RestService.class, DefaultRestService.class, SpringRestService.class, StandardRestService.class); } }
5,234
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/tools/RestServiceTest.java
/* * 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 org.apache.dubbo.metadata.tools; import org.apache.dubbo.metadata.rest.RestService; import org.apache.dubbo.metadata.rest.SpringRestService; import org.apache.dubbo.metadata.rest.StandardRestService; import org.apache.dubbo.metadata.rest.User; import java.io.IOException; import org.junit.jupiter.api.Test; /** * {@link RestService} Test * * @since 2.7.6 */ class RestServiceTest { @Test void test() throws IOException { Compiler compiler = new Compiler(); compiler.compile(User.class, RestService.class, StandardRestService.class, SpringRestService.class); } }
5,235
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/tools/Compiler.java
/* * 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 org.apache.dubbo.metadata.tools; import javax.annotation.processing.Processor; import javax.tools.JavaCompiler; import javax.tools.JavaFileObject; import javax.tools.StandardJavaFileManager; import javax.tools.StandardLocation; import javax.tools.ToolProvider; import java.io.File; import java.io.IOException; import java.net.URL; import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; import static java.util.Arrays.asList; /** * The Java Compiler */ public class Compiler { private final File sourceDirectory; private final JavaCompiler javaCompiler; private final StandardJavaFileManager javaFileManager; private final Set<Processor> processors = new LinkedHashSet<>(); public Compiler() throws IOException { this(defaultTargetDirectory()); } public Compiler(File targetDirectory) throws IOException { this(defaultSourceDirectory(), targetDirectory); } public Compiler(File sourceDirectory, File targetDirectory) throws IOException { this.sourceDirectory = sourceDirectory; this.javaCompiler = ToolProvider.getSystemJavaCompiler(); this.javaFileManager = javaCompiler.getStandardFileManager(null, null, null); this.javaFileManager.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(targetDirectory)); this.javaFileManager.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(targetDirectory)); } private static File defaultSourceDirectory() { return new File(defaultRootDirectory(), "src/test/java"); } private static File defaultRootDirectory() { return detectClassPath(Compiler.class).getParentFile().getParentFile(); } private static File defaultTargetDirectory() { File dir = new File(defaultRootDirectory(), "target/generated-classes"); dir.mkdirs(); return dir; } private static File detectClassPath(Class<?> targetClass) { URL classFileURL = targetClass.getProtectionDomain().getCodeSource().getLocation(); if ("file".equals(classFileURL.getProtocol())) { return new File(classFileURL.getPath()); } else { throw new RuntimeException("No support"); } } public Compiler processors(Processor... processors) { this.processors.addAll(asList(processors)); return this; } private Iterable<? extends JavaFileObject> getJavaFileObjects(Class<?>... sourceClasses) { int size = sourceClasses == null ? 0 : sourceClasses.length; File[] javaSourceFiles = new File[size]; for (int i = 0; i < size; i++) { File javaSourceFile = javaSourceFile(sourceClasses[i].getName()); javaSourceFiles[i] = javaSourceFile; } return javaFileManager.getJavaFileObjects(javaSourceFiles); } private File javaSourceFile(String sourceClassName) { String javaSourceFilePath = sourceClassName.replace('.', '/').concat(".java"); return new File(sourceDirectory, javaSourceFilePath); } public boolean compile(Class<?>... sourceClasses) { JavaCompiler.CompilationTask task = javaCompiler.getTask( null, this.javaFileManager, null, asList("-parameters", "-Xlint:unchecked", "-nowarn", "-Xlint:deprecation"), // null, null, getJavaFileObjects(sourceClasses)); if (!processors.isEmpty()) { task.setProcessors(processors); } return task.call(); } public JavaCompiler getJavaCompiler() { return javaCompiler; } }
5,236
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/tools/DefaultTestService.java
/* * 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 org.apache.dubbo.metadata.tools; import org.apache.dubbo.config.annotation.Service; import org.apache.dubbo.metadata.annotation.processing.model.Model; import java.util.concurrent.TimeUnit; /** * {@link TestService} Implementation * * @since 2.7.6 */ @Service(interfaceName = "org.apache.dubbo.metadata.tools.TestService", version = "1.0.0", group = "default") public class DefaultTestService implements TestService { private String name; @Override public String echo(String message) { return "[ECHO] " + message; } @Override public Model model(Model model) { return model; } @Override public String testPrimitive(boolean z, int i) { return null; } @Override public Model testEnum(TimeUnit timeUnit) { return null; } @Override public String testArray(String[] strArray, int[] intArray, Model[] modelArray) { return null; } }
5,237
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/tools/CompilerTest.java
/* * 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 org.apache.dubbo.metadata.tools; import java.io.IOException; import org.junit.jupiter.api.Test; /** * The Compiler test case */ class CompilerTest { @Test void testCompile() throws IOException { Compiler compiler = new Compiler(); compiler.compile(TestServiceImpl.class, DefaultTestService.class, GenericTestService.class); } }
5,238
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/tools/Ancestor.java
/* * 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 org.apache.dubbo.metadata.tools; import java.io.Serializable; /** * Ancestor */ public class Ancestor implements Serializable { private boolean z; public boolean isZ() { return z; } public void setZ(boolean z) { this.z = z; } }
5,239
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/tools/Parent.java
/* * 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 org.apache.dubbo.metadata.tools; /** * Parent */ public class Parent extends Ancestor { private byte b; private short s; private int i; private long l; public byte getB() { return b; } public void setB(byte b) { this.b = b; } public short getS() { return s; } public void setS(short s) { this.s = s; } public int getI() { return i; } public void setI(int i) { this.i = i; } public long getL() { return l; } public void setL(long l) { this.l = l; } }
5,240
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/tools/TestService.java
/* * 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 org.apache.dubbo.metadata.tools; import org.apache.dubbo.metadata.annotation.processing.model.Model; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import java.util.concurrent.TimeUnit; /** * Test Service * * @since 2.7.6 */ @Path("/echo") public interface TestService { @GET <T> String echo(@PathParam("message") @DefaultValue("mercyblitz") String message); @POST Model model(@PathParam("model") Model model); // Test primitive @PUT String testPrimitive(boolean z, int i); // Test enumeration @PUT Model testEnum(TimeUnit timeUnit); // Test Array @GET String testArray(String[] strArray, int[] intArray, Model[] modelArray); }
5,241
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/tools/GenericTestService.java
/* * 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 org.apache.dubbo.metadata.tools; import java.util.EventListener; import com.alibaba.dubbo.config.annotation.Service; /** * {@link TestService} Implementation * * @since 2.7.6 */ @Service(version = "2.0.0", group = "generic") public class GenericTestService extends DefaultTestService implements TestService, EventListener { @Override public String echo(String message) { return "[ECHO] " + message; } }
5,242
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/AnnotationProcessingTestProcessor.java
/* * 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 org.apache.dubbo.metadata.annotation.processing; import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.SupportedAnnotationTypes; import javax.lang.model.SourceVersion; import javax.lang.model.element.TypeElement; import java.lang.reflect.Method; import java.util.Set; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.InvocationInterceptor; import org.junit.jupiter.api.extension.ReflectiveInvocationContext; import static javax.lang.model.SourceVersion.latestSupported; @SupportedAnnotationTypes("*") public class AnnotationProcessingTestProcessor extends AbstractProcessor { private final AbstractAnnotationProcessingTest abstractAnnotationProcessingTest; private final InvocationInterceptor.Invocation<Void> invocation; private final ReflectiveInvocationContext<Method> invocationContext; private final ExtensionContext extensionContext; public AnnotationProcessingTestProcessor( AbstractAnnotationProcessingTest abstractAnnotationProcessingTest, InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) { this.abstractAnnotationProcessingTest = abstractAnnotationProcessingTest; this.invocation = invocation; this.invocationContext = invocationContext; this.extensionContext = extensionContext; } @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (!roundEnv.processingOver()) { prepare(); abstractAnnotationProcessingTest.beforeEach(); try { invocation.proceed(); } catch (Throwable throwable) { throw new RuntimeException(throwable); } } return false; } private void prepare() { abstractAnnotationProcessingTest.processingEnv = super.processingEnv; abstractAnnotationProcessingTest.elements = super.processingEnv.getElementUtils(); abstractAnnotationProcessingTest.types = super.processingEnv.getTypeUtils(); } @Override public SourceVersion getSupportedSourceVersion() { return latestSupported(); } }
5,243
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/AbstractAnnotationProcessingTest.java
/* * 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 org.apache.dubbo.metadata.annotation.processing; import org.apache.dubbo.metadata.annotation.processing.util.TypeUtils; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.TypeElement; import javax.lang.model.util.Elements; import javax.lang.model.util.Types; import java.lang.annotation.Annotation; import java.util.Set; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; /** * Abstract {@link Annotation} Processing Test case * * @since 2.7.6 */ @ExtendWith(CompilerInvocationInterceptor.class) public abstract class AbstractAnnotationProcessingTest { static ThreadLocal<AbstractAnnotationProcessingTest> testInstanceHolder = new ThreadLocal<>(); protected ProcessingEnvironment processingEnv; protected Elements elements; protected Types types; @BeforeEach public final void init() { testInstanceHolder.set(this); } @AfterEach public final void destroy() { testInstanceHolder.remove(); } protected abstract void addCompiledClasses(Set<Class<?>> classesToBeCompiled); protected abstract void beforeEach(); protected TypeElement getType(Class<?> type) { return TypeUtils.getType(processingEnv, type); } }
5,244
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/CompilerInvocationInterceptor.java
/* * 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 org.apache.dubbo.metadata.annotation.processing; import org.apache.dubbo.metadata.tools.Compiler; import java.lang.reflect.Method; import java.util.LinkedHashSet; import java.util.Set; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.InvocationInterceptor; import org.junit.jupiter.api.extension.ReflectiveInvocationContext; import static org.apache.dubbo.metadata.annotation.processing.AbstractAnnotationProcessingTest.testInstanceHolder; public class CompilerInvocationInterceptor implements InvocationInterceptor { @Override public void interceptTestMethod( Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable { Set<Class<?>> classesToBeCompiled = new LinkedHashSet<>(); AbstractAnnotationProcessingTest abstractAnnotationProcessingTest = testInstanceHolder.get(); classesToBeCompiled.add(getClass()); abstractAnnotationProcessingTest.addCompiledClasses(classesToBeCompiled); Compiler compiler = new Compiler(); compiler.processors(new AnnotationProcessingTestProcessor( abstractAnnotationProcessingTest, invocation, invocationContext, extensionContext)); compiler.compile(classesToBeCompiled.toArray(new Class[0])); } }
5,245
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/util/AnnotationUtilsTest.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.util; import org.apache.dubbo.config.annotation.Service; import org.apache.dubbo.metadata.annotation.processing.AbstractAnnotationProcessingTest; import org.apache.dubbo.metadata.rest.SpringRestService; import org.apache.dubbo.metadata.tools.TestService; import org.apache.dubbo.metadata.tools.TestServiceImpl; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.type.TypeMirror; import javax.ws.rs.Path; import java.util.Iterator; import java.util.List; import java.util.Set; import org.junit.jupiter.api.Test; import org.springframework.web.bind.annotation.GetMapping; import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.findAnnotation; import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.findMetaAnnotation; import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.getAllAnnotations; import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.getAnnotation; import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.getAnnotations; import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.getAttribute; import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.getValue; import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.isAnnotationPresent; import static org.apache.dubbo.metadata.annotation.processing.util.MethodUtils.findMethod; import static org.apache.dubbo.metadata.annotation.processing.util.MethodUtils.getAllDeclaredMethods; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; /** * The {@link AnnotationUtils} Test * * @since 2.7.6 */ class AnnotationUtilsTest extends AbstractAnnotationProcessingTest { private TypeElement testType; @Override protected void addCompiledClasses(Set<Class<?>> classesToBeCompiled) {} @Override protected void beforeEach() { testType = getType(TestServiceImpl.class); } @Test void testGetAnnotation() { AnnotationMirror serviceAnnotation = getAnnotation(testType, Service.class); assertEquals("3.0.0", getAttribute(serviceAnnotation, "version")); assertEquals("test", getAttribute(serviceAnnotation, "group")); assertEquals("org.apache.dubbo.metadata.tools.TestService", getAttribute(serviceAnnotation, "interfaceName")); assertNull(getAnnotation(testType, (Class) null)); assertNull(getAnnotation(testType, (String) null)); assertNull(getAnnotation(testType.asType(), (Class) null)); assertNull(getAnnotation(testType.asType(), (String) null)); assertNull(getAnnotation((Element) null, (Class) null)); assertNull(getAnnotation((Element) null, (String) null)); assertNull(getAnnotation((TypeElement) null, (Class) null)); assertNull(getAnnotation((TypeElement) null, (String) null)); } @Test void testGetAnnotations() { List<AnnotationMirror> annotations = getAnnotations(testType); Iterator<AnnotationMirror> iterator = annotations.iterator(); assertEquals(2, annotations.size()); assertEquals( "com.alibaba.dubbo.config.annotation.Service", iterator.next().getAnnotationType().toString()); assertEquals( "org.apache.dubbo.config.annotation.Service", iterator.next().getAnnotationType().toString()); annotations = getAnnotations(testType, Service.class); iterator = annotations.iterator(); assertEquals(1, annotations.size()); assertEquals( "org.apache.dubbo.config.annotation.Service", iterator.next().getAnnotationType().toString()); annotations = getAnnotations(testType.asType(), Service.class); iterator = annotations.iterator(); assertEquals(1, annotations.size()); assertEquals( "org.apache.dubbo.config.annotation.Service", iterator.next().getAnnotationType().toString()); annotations = getAnnotations(testType.asType(), Service.class.getTypeName()); iterator = annotations.iterator(); assertEquals(1, annotations.size()); assertEquals( "org.apache.dubbo.config.annotation.Service", iterator.next().getAnnotationType().toString()); annotations = getAnnotations(testType, Override.class); assertEquals(0, annotations.size()); annotations = getAnnotations(testType, com.alibaba.dubbo.config.annotation.Service.class); assertEquals(1, annotations.size()); assertTrue(getAnnotations(null, (Class) null).isEmpty()); assertTrue(getAnnotations(null, (String) null).isEmpty()); assertTrue(getAnnotations(testType, (Class) null).isEmpty()); assertTrue(getAnnotations(testType, (String) null).isEmpty()); assertTrue(getAnnotations(null, Service.class).isEmpty()); assertTrue(getAnnotations(null, Service.class.getTypeName()).isEmpty()); } @Test void testGetAllAnnotations() { List<AnnotationMirror> annotations = getAllAnnotations(testType); assertEquals(5, annotations.size()); annotations = getAllAnnotations(testType.asType(), annotation -> true); assertEquals(5, annotations.size()); annotations = getAllAnnotations(processingEnv, TestServiceImpl.class); assertEquals(5, annotations.size()); annotations = getAllAnnotations(testType.asType(), Service.class); assertEquals(2, annotations.size()); annotations = getAllAnnotations(testType, Override.class); assertEquals(0, annotations.size()); annotations = getAllAnnotations(testType.asType(), com.alibaba.dubbo.config.annotation.Service.class); assertEquals(2, annotations.size()); assertTrue(getAllAnnotations((Element) null, (Class) null).isEmpty()); assertTrue(getAllAnnotations((TypeMirror) null, (String) null).isEmpty()); assertTrue(getAllAnnotations((ProcessingEnvironment) null, (Class) null).isEmpty()); assertTrue( getAllAnnotations((ProcessingEnvironment) null, (String) null).isEmpty()); assertTrue(getAllAnnotations((Element) null).isEmpty()); assertTrue(getAllAnnotations((TypeMirror) null).isEmpty()); assertTrue(getAllAnnotations(processingEnv, (Class) null).isEmpty()); assertTrue(getAllAnnotations(processingEnv, (String) null).isEmpty()); assertTrue(getAllAnnotations(testType, (Class) null).isEmpty()); assertTrue(getAllAnnotations(testType.asType(), (Class) null).isEmpty()); assertTrue(getAllAnnotations(testType, (String) null).isEmpty()); assertTrue(getAllAnnotations(testType.asType(), (String) null).isEmpty()); assertTrue(getAllAnnotations((Element) null, Service.class).isEmpty()); assertTrue(getAllAnnotations((TypeMirror) null, Service.class.getTypeName()) .isEmpty()); } @Test void testFindAnnotation() { assertEquals( "org.apache.dubbo.config.annotation.Service", findAnnotation(testType, Service.class).getAnnotationType().toString()); assertEquals( "com.alibaba.dubbo.config.annotation.Service", findAnnotation(testType, com.alibaba.dubbo.config.annotation.Service.class) .getAnnotationType() .toString()); assertEquals( "javax.ws.rs.Path", findAnnotation(testType, Path.class).getAnnotationType().toString()); assertEquals( "javax.ws.rs.Path", findAnnotation(testType.asType(), Path.class) .getAnnotationType() .toString()); assertEquals( "javax.ws.rs.Path", findAnnotation(testType.asType(), Path.class.getTypeName()) .getAnnotationType() .toString()); assertNull(findAnnotation(testType, Override.class)); assertNull(findAnnotation((Element) null, (Class) null)); assertNull(findAnnotation((Element) null, (String) null)); assertNull(findAnnotation((TypeMirror) null, (Class) null)); assertNull(findAnnotation((TypeMirror) null, (String) null)); assertNull(findAnnotation(testType, (Class) null)); assertNull(findAnnotation(testType, (String) null)); assertNull(findAnnotation(testType.asType(), (Class) null)); assertNull(findAnnotation(testType.asType(), (String) null)); } @Test void testFindMetaAnnotation() { getAllDeclaredMethods(getType(TestService.class)).forEach(method -> { assertEquals( "javax.ws.rs.HttpMethod", findMetaAnnotation(method, "javax.ws.rs.HttpMethod") .getAnnotationType() .toString()); }); } @Test void testGetAttribute() { assertEquals( "org.apache.dubbo.metadata.tools.TestService", getAttribute(findAnnotation(testType, Service.class), "interfaceName")); assertEquals( "org.apache.dubbo.metadata.tools.TestService", getAttribute(findAnnotation(testType, Service.class).getElementValues(), "interfaceName")); assertEquals("/echo", getAttribute(findAnnotation(testType, Path.class), "value")); assertNull(getAttribute(findAnnotation(testType, Path.class), null)); assertNull(getAttribute(findAnnotation(testType, (Class) null), null)); ExecutableElement method = findMethod(getType(SpringRestService.class), "param", String.class); AnnotationMirror annotation = findAnnotation(method, GetMapping.class); assertArrayEquals(new String[] {"/param"}, (String[]) getAttribute(annotation, "value")); assertNull(getAttribute(annotation, "path")); } @Test void testGetValue() { AnnotationMirror pathAnnotation = getAnnotation(getType(TestService.class), Path.class); assertEquals("/echo", getValue(pathAnnotation)); } @Test void testIsAnnotationPresent() { assertTrue(isAnnotationPresent(testType, "org.apache.dubbo.config.annotation.Service")); assertTrue(isAnnotationPresent(testType, "com.alibaba.dubbo.config.annotation.Service")); assertTrue(isAnnotationPresent(testType, "javax.ws.rs.Path")); } }
5,246
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/util/MemberUtilsTest.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.util; import org.apache.dubbo.metadata.annotation.processing.AbstractAnnotationProcessingTest; import org.apache.dubbo.metadata.annotation.processing.model.Model; import org.apache.dubbo.metadata.tools.TestServiceImpl; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import java.util.List; import java.util.Set; import org.junit.jupiter.api.Test; import static javax.lang.model.element.Modifier.PRIVATE; import static javax.lang.model.util.ElementFilter.fieldsIn; import static javax.lang.model.util.ElementFilter.methodsIn; import static org.apache.dubbo.metadata.annotation.processing.util.MemberUtils.getAllDeclaredMembers; import static org.apache.dubbo.metadata.annotation.processing.util.MemberUtils.getDeclaredMembers; import static org.apache.dubbo.metadata.annotation.processing.util.MemberUtils.hasModifiers; import static org.apache.dubbo.metadata.annotation.processing.util.MemberUtils.isPublicNonStatic; import static org.apache.dubbo.metadata.annotation.processing.util.MemberUtils.matchParameterTypes; import static org.apache.dubbo.metadata.annotation.processing.util.MethodUtils.findMethod; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; /** * {@link MemberUtils} Test * * @since 2.7.6 */ class MemberUtilsTest extends AbstractAnnotationProcessingTest { private TypeElement testType; @Override protected void addCompiledClasses(Set<Class<?>> classesToBeCompiled) {} @Override protected void beforeEach() { testType = getType(TestServiceImpl.class); } @Test void testIsPublicNonStatic() { assertFalse(isPublicNonStatic(null)); methodsIn(getDeclaredMembers(testType.asType())).forEach(method -> assertTrue(isPublicNonStatic(method))); } @Test void testHasModifiers() { assertFalse(hasModifiers(null)); List<? extends Element> members = getAllDeclaredMembers(testType.asType()); List<VariableElement> fields = fieldsIn(members); assertTrue(hasModifiers(fields.get(0), PRIVATE)); } @Test void testDeclaredMembers() { TypeElement type = getType(Model.class); List<? extends Element> members = getDeclaredMembers(type.asType()); List<VariableElement> fields = fieldsIn(members); assertEquals(19, members.size()); assertEquals(6, fields.size()); assertEquals("f", fields.get(0).getSimpleName().toString()); assertEquals("d", fields.get(1).getSimpleName().toString()); assertEquals("tu", fields.get(2).getSimpleName().toString()); assertEquals("str", fields.get(3).getSimpleName().toString()); assertEquals("bi", fields.get(4).getSimpleName().toString()); assertEquals("bd", fields.get(5).getSimpleName().toString()); members = getAllDeclaredMembers(type.asType()); fields = fieldsIn(members); assertEquals(11, fields.size()); assertEquals("f", fields.get(0).getSimpleName().toString()); assertEquals("d", fields.get(1).getSimpleName().toString()); assertEquals("tu", fields.get(2).getSimpleName().toString()); assertEquals("str", fields.get(3).getSimpleName().toString()); assertEquals("bi", fields.get(4).getSimpleName().toString()); assertEquals("bd", fields.get(5).getSimpleName().toString()); assertEquals("b", fields.get(6).getSimpleName().toString()); assertEquals("s", fields.get(7).getSimpleName().toString()); assertEquals("i", fields.get(8).getSimpleName().toString()); assertEquals("l", fields.get(9).getSimpleName().toString()); assertEquals("z", fields.get(10).getSimpleName().toString()); } @Test void testMatchParameterTypes() { ExecutableElement method = findMethod(testType, "echo", "java.lang.String"); assertTrue(matchParameterTypes(method.getParameters(), "java.lang.String")); assertFalse(matchParameterTypes(method.getParameters(), "java.lang.Object")); } }
5,247
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/util/MethodUtilsTest.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.util; import org.apache.dubbo.metadata.annotation.processing.AbstractAnnotationProcessingTest; import org.apache.dubbo.metadata.annotation.processing.model.Model; import org.apache.dubbo.metadata.tools.TestService; import org.apache.dubbo.metadata.tools.TestServiceImpl; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.type.TypeMirror; import java.util.List; import java.util.Set; import org.junit.jupiter.api.Test; import static org.apache.dubbo.metadata.annotation.processing.util.MethodUtils.findMethod; import static org.apache.dubbo.metadata.annotation.processing.util.MethodUtils.getAllDeclaredMethods; import static org.apache.dubbo.metadata.annotation.processing.util.MethodUtils.getDeclaredMethods; import static org.apache.dubbo.metadata.annotation.processing.util.MethodUtils.getMethodName; import static org.apache.dubbo.metadata.annotation.processing.util.MethodUtils.getMethodParameterTypes; import static org.apache.dubbo.metadata.annotation.processing.util.MethodUtils.getOverrideMethod; import static org.apache.dubbo.metadata.annotation.processing.util.MethodUtils.getPublicNonStaticMethods; import static org.apache.dubbo.metadata.annotation.processing.util.MethodUtils.getReturnType; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; /** * {@link MethodUtils} Test * * @since 2.7.6 */ class MethodUtilsTest extends AbstractAnnotationProcessingTest { private TypeElement testType; @Override protected void addCompiledClasses(Set<Class<?>> classesToBeCompiled) {} @Override protected void beforeEach() { testType = getType(TestServiceImpl.class); } @Test void testDeclaredMethods() { TypeElement type = getType(Model.class); List<ExecutableElement> methods = getDeclaredMethods(type); assertEquals(12, methods.size()); methods = getAllDeclaredMethods(type); // registerNatives() no provided in JDK 17 assertTrue(methods.size() >= 33); assertTrue(getAllDeclaredMethods((TypeElement) null).isEmpty()); assertTrue(getAllDeclaredMethods((TypeMirror) null).isEmpty()); } private List<? extends ExecutableElement> doGetAllDeclaredMethods() { return getAllDeclaredMethods(testType, Object.class); } @Test void testGetAllDeclaredMethods() { List<? extends ExecutableElement> methods = doGetAllDeclaredMethods(); assertEquals(14, methods.size()); } @Test void testGetPublicNonStaticMethods() { List<? extends ExecutableElement> methods = getPublicNonStaticMethods(testType, Object.class); assertEquals(14, methods.size()); methods = getPublicNonStaticMethods(testType.asType(), Object.class); assertEquals(14, methods.size()); } @Test void testIsMethod() { List<? extends ExecutableElement> methods = getPublicNonStaticMethods(testType, Object.class); assertEquals(14, methods.stream().map(MethodUtils::isMethod).count()); } @Test void testIsPublicNonStaticMethod() { List<? extends ExecutableElement> methods = getPublicNonStaticMethods(testType, Object.class); assertEquals( 14, methods.stream().map(MethodUtils::isPublicNonStaticMethod).count()); } @Test void testFindMethod() { TypeElement type = getType(Model.class); // Test methods from java.lang.Object // Object#toString() String methodName = "toString"; ExecutableElement method = findMethod(type.asType(), methodName); assertEquals(method.getSimpleName().toString(), methodName); // Object#hashCode() methodName = "hashCode"; method = findMethod(type.asType(), methodName); assertEquals(method.getSimpleName().toString(), methodName); // Object#getClass() methodName = "getClass"; method = findMethod(type.asType(), methodName); assertEquals(method.getSimpleName().toString(), methodName); // Object#finalize() methodName = "finalize"; method = findMethod(type.asType(), methodName); assertEquals(method.getSimpleName().toString(), methodName); // Object#clone() methodName = "clone"; method = findMethod(type.asType(), methodName); assertEquals(method.getSimpleName().toString(), methodName); // Object#notify() methodName = "notify"; method = findMethod(type.asType(), methodName); assertEquals(method.getSimpleName().toString(), methodName); // Object#notifyAll() methodName = "notifyAll"; method = findMethod(type.asType(), methodName); assertEquals(method.getSimpleName().toString(), methodName); // Object#wait(long) methodName = "wait"; method = findMethod(type.asType(), methodName, long.class); assertEquals(method.getSimpleName().toString(), methodName); // Object#wait(long,int) methodName = "wait"; method = findMethod(type.asType(), methodName, long.class, int.class); assertEquals(method.getSimpleName().toString(), methodName); // Object#equals(Object) methodName = "equals"; method = findMethod(type.asType(), methodName, Object.class); assertEquals(method.getSimpleName().toString(), methodName); } @Test void testGetOverrideMethod() { List<? extends ExecutableElement> methods = doGetAllDeclaredMethods(); ExecutableElement overrideMethod = getOverrideMethod(processingEnv, testType, methods.get(0)); assertNull(overrideMethod); ExecutableElement declaringMethod = findMethod(getType(TestService.class), "echo", "java.lang.String"); overrideMethod = getOverrideMethod(processingEnv, testType, declaringMethod); assertEquals(methods.get(0), overrideMethod); } @Test void testGetMethodName() { ExecutableElement method = findMethod(testType, "echo", "java.lang.String"); assertEquals("echo", getMethodName(method)); assertNull(getMethodName(null)); } @Test void testReturnType() { ExecutableElement method = findMethod(testType, "echo", "java.lang.String"); assertEquals("java.lang.String", getReturnType(method)); assertNull(getReturnType(null)); } @Test void testMatchParameterTypes() { ExecutableElement method = findMethod(testType, "echo", "java.lang.String"); assertArrayEquals(new String[] {"java.lang.String"}, getMethodParameterTypes(method)); assertTrue(getMethodParameterTypes(null).length == 0); } }
5,248
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/util/LoggerUtilsTest.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.util; import org.junit.jupiter.api.Test; import static org.apache.dubbo.metadata.annotation.processing.util.LoggerUtils.info; import static org.apache.dubbo.metadata.annotation.processing.util.LoggerUtils.warn; import static org.junit.jupiter.api.Assertions.assertNotNull; /** * {@link LoggerUtils} Test * * @since 2.7.6 */ class LoggerUtilsTest { @Test void testLogger() { assertNotNull(LoggerUtils.LOGGER); } @Test void testInfo() { info("Hello,World"); info("Hello,%s", "World"); info("%s,%s", "Hello", "World"); } @Test void testWarn() { warn("Hello,World"); warn("Hello,%s", "World"); warn("%s,%s", "Hello", "World"); } }
5,249
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/util/FieldUtilsTest.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.util; import org.apache.dubbo.metadata.annotation.processing.AbstractAnnotationProcessingTest; import org.apache.dubbo.metadata.annotation.processing.model.Color; import org.apache.dubbo.metadata.annotation.processing.model.Model; import org.apache.dubbo.metadata.tools.TestServiceImpl; import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.TypeMirror; import java.lang.reflect.Type; import java.math.BigDecimal; import java.math.BigInteger; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Test; import static javax.lang.model.element.Modifier.FINAL; import static javax.lang.model.element.Modifier.PRIVATE; import static javax.lang.model.element.Modifier.PUBLIC; import static javax.lang.model.element.Modifier.STATIC; import static org.apache.dubbo.metadata.annotation.processing.util.FieldUtils.findField; import static org.apache.dubbo.metadata.annotation.processing.util.FieldUtils.getAllDeclaredFields; import static org.apache.dubbo.metadata.annotation.processing.util.FieldUtils.getAllNonStaticFields; import static org.apache.dubbo.metadata.annotation.processing.util.FieldUtils.getDeclaredField; import static org.apache.dubbo.metadata.annotation.processing.util.FieldUtils.getDeclaredFields; import static org.apache.dubbo.metadata.annotation.processing.util.FieldUtils.getNonStaticFields; import static org.apache.dubbo.metadata.annotation.processing.util.FieldUtils.isEnumMemberField; import static org.apache.dubbo.metadata.annotation.processing.util.FieldUtils.isField; import static org.apache.dubbo.metadata.annotation.processing.util.FieldUtils.isNonStaticField; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; /** * {@link FieldUtils} Test * * @since 2.7.6 */ class FieldUtilsTest extends AbstractAnnotationProcessingTest { private TypeElement testType; @Override protected void addCompiledClasses(Set<Class<?>> classesToBeCompiled) {} @Override protected void beforeEach() { testType = getType(TestServiceImpl.class); } @Test void testGetDeclaredFields() { TypeElement type = getType(Model.class); List<VariableElement> fields = getDeclaredFields(type); assertModelFields(fields); fields = getDeclaredFields(type.asType()); assertModelFields(fields); assertTrue(getDeclaredFields((Element) null).isEmpty()); assertTrue(getDeclaredFields((TypeMirror) null).isEmpty()); fields = getDeclaredFields(type, f -> "f".equals(f.getSimpleName().toString())); assertEquals(1, fields.size()); assertEquals("f", fields.get(0).getSimpleName().toString()); } @Test void testGetAllDeclaredFields() { TypeElement type = getType(Model.class); List<VariableElement> fields = getAllDeclaredFields(type); assertModelAllFields(fields); assertTrue(getAllDeclaredFields((Element) null).isEmpty()); assertTrue(getAllDeclaredFields((TypeMirror) null).isEmpty()); fields = getAllDeclaredFields(type, f -> "f".equals(f.getSimpleName().toString())); assertEquals(1, fields.size()); assertEquals("f", fields.get(0).getSimpleName().toString()); } @Test void testGetDeclaredField() { TypeElement type = getType(Model.class); testGetDeclaredField(type, "f", float.class); testGetDeclaredField(type, "d", double.class); testGetDeclaredField(type, "tu", TimeUnit.class); testGetDeclaredField(type, "str", String.class); testGetDeclaredField(type, "bi", BigInteger.class); testGetDeclaredField(type, "bd", BigDecimal.class); assertNull(getDeclaredField(type, "b")); assertNull(getDeclaredField(type, "s")); assertNull(getDeclaredField(type, "i")); assertNull(getDeclaredField(type, "l")); assertNull(getDeclaredField(type, "z")); assertNull(getDeclaredField((Element) null, "z")); assertNull(getDeclaredField((TypeMirror) null, "z")); } @Test void testFindField() { TypeElement type = getType(Model.class); testFindField(type, "f", float.class); testFindField(type, "d", double.class); testFindField(type, "tu", TimeUnit.class); testFindField(type, "str", String.class); testFindField(type, "bi", BigInteger.class); testFindField(type, "bd", BigDecimal.class); testFindField(type, "b", byte.class); testFindField(type, "s", short.class); testFindField(type, "i", int.class); testFindField(type, "l", long.class); testFindField(type, "z", boolean.class); assertNull(findField((Element) null, "f")); assertNull(findField((Element) null, null)); assertNull(findField((TypeMirror) null, "f")); assertNull(findField((TypeMirror) null, null)); assertNull(findField(type, null)); assertNull(findField(type.asType(), null)); } @Test void testIsEnumField() { TypeElement type = getType(Color.class); VariableElement field = findField(type, "RED"); assertTrue(isEnumMemberField(field)); field = findField(type, "YELLOW"); assertTrue(isEnumMemberField(field)); field = findField(type, "BLUE"); assertTrue(isEnumMemberField(field)); type = getType(Model.class); field = findField(type, "f"); assertFalse(isEnumMemberField(field)); assertFalse(isEnumMemberField(null)); } @Test void testIsNonStaticField() { TypeElement type = getType(Model.class); assertTrue(isNonStaticField(findField(type, "f"))); type = getType(Color.class); assertFalse(isNonStaticField(findField(type, "BLUE"))); } @Test void testIsField() { TypeElement type = getType(Model.class); assertTrue(isField(findField(type, "f"))); assertTrue(isField(findField(type, "f"), PRIVATE)); type = getType(Color.class); assertTrue(isField(findField(type, "BLUE"), PUBLIC, STATIC, FINAL)); assertFalse(isField(null)); assertFalse(isField(null, PUBLIC, STATIC, FINAL)); } @Test void testGetNonStaticFields() { TypeElement type = getType(Model.class); List<VariableElement> fields = getNonStaticFields(type); assertModelFields(fields); fields = getNonStaticFields(type.asType()); assertModelFields(fields); assertTrue(getAllNonStaticFields((Element) null).isEmpty()); assertTrue(getAllNonStaticFields((TypeMirror) null).isEmpty()); } @Test void testGetAllNonStaticFields() { TypeElement type = getType(Model.class); List<VariableElement> fields = getAllNonStaticFields(type); assertModelAllFields(fields); fields = getAllNonStaticFields(type.asType()); assertModelAllFields(fields); assertTrue(getAllNonStaticFields((Element) null).isEmpty()); assertTrue(getAllNonStaticFields((TypeMirror) null).isEmpty()); } private void assertModelFields(List<VariableElement> fields) { assertEquals(6, fields.size()); assertEquals("d", fields.get(1).getSimpleName().toString()); assertEquals("tu", fields.get(2).getSimpleName().toString()); assertEquals("str", fields.get(3).getSimpleName().toString()); assertEquals("bi", fields.get(4).getSimpleName().toString()); assertEquals("bd", fields.get(5).getSimpleName().toString()); } private void assertModelAllFields(List<VariableElement> fields) { assertEquals(11, fields.size()); assertEquals("f", fields.get(0).getSimpleName().toString()); assertEquals("d", fields.get(1).getSimpleName().toString()); assertEquals("tu", fields.get(2).getSimpleName().toString()); assertEquals("str", fields.get(3).getSimpleName().toString()); assertEquals("bi", fields.get(4).getSimpleName().toString()); assertEquals("bd", fields.get(5).getSimpleName().toString()); assertEquals("b", fields.get(6).getSimpleName().toString()); assertEquals("s", fields.get(7).getSimpleName().toString()); assertEquals("i", fields.get(8).getSimpleName().toString()); assertEquals("l", fields.get(9).getSimpleName().toString()); assertEquals("z", fields.get(10).getSimpleName().toString()); } private void testGetDeclaredField(TypeElement type, String fieldName, Type fieldType) { VariableElement field = getDeclaredField(type, fieldName); assertField(field, fieldName, fieldType); } private void testFindField(TypeElement type, String fieldName, Type fieldType) { VariableElement field = findField(type, fieldName); assertField(field, fieldName, fieldType); } private void assertField(VariableElement field, String fieldName, Type fieldType) { assertEquals(fieldName, field.getSimpleName().toString()); assertEquals(fieldType.getTypeName(), field.asType().toString()); } }
5,250
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/util/TypeUtilsTest.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.util; import org.apache.dubbo.metadata.annotation.processing.AbstractAnnotationProcessingTest; import org.apache.dubbo.metadata.annotation.processing.model.ArrayTypeModel; import org.apache.dubbo.metadata.annotation.processing.model.Color; import org.apache.dubbo.metadata.annotation.processing.model.Model; import org.apache.dubbo.metadata.annotation.processing.model.PrimitiveTypeModel; import org.apache.dubbo.metadata.tools.DefaultTestService; import org.apache.dubbo.metadata.tools.GenericTestService; import org.apache.dubbo.metadata.tools.TestServiceImpl; import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; import java.io.File; import java.lang.reflect.Type; import java.math.BigDecimal; import java.math.BigInteger; import java.net.URISyntaxException; import java.net.URL; import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Set; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static java.util.Arrays.asList; import static org.apache.dubbo.metadata.annotation.processing.util.FieldUtils.findField; import static org.apache.dubbo.metadata.annotation.processing.util.FieldUtils.getDeclaredFields; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.getAllInterfaces; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.getAllSuperTypes; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.getHierarchicalTypes; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.getInterfaces; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.getResource; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.getResourceName; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.getSuperType; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.isAnnotationType; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.isArrayType; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.isClassType; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.isDeclaredType; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.isEnumType; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.isInterfaceType; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.isPrimitiveType; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.isSameType; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.isSimpleType; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.isTypeElement; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.listDeclaredTypes; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.listTypeElements; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.ofDeclaredType; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.ofDeclaredTypes; import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.ofTypeElement; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; /** * The {@link TypeUtils} Test * * @since 2.7.6 */ class TypeUtilsTest extends AbstractAnnotationProcessingTest { private TypeElement testType; @Override protected void addCompiledClasses(Set<Class<?>> classesToBeCompiled) { classesToBeCompiled.add(ArrayTypeModel.class); classesToBeCompiled.add(Color.class); } @Override protected void beforeEach() { testType = getType(TestServiceImpl.class); } @Test void testIsSimpleType() { assertTrue(isSimpleType(getType(Void.class))); assertTrue(isSimpleType(getType(Boolean.class))); assertTrue(isSimpleType(getType(Character.class))); assertTrue(isSimpleType(getType(Byte.class))); assertTrue(isSimpleType(getType(Short.class))); assertTrue(isSimpleType(getType(Integer.class))); assertTrue(isSimpleType(getType(Long.class))); assertTrue(isSimpleType(getType(Float.class))); assertTrue(isSimpleType(getType(Double.class))); assertTrue(isSimpleType(getType(String.class))); assertTrue(isSimpleType(getType(BigDecimal.class))); assertTrue(isSimpleType(getType(BigInteger.class))); assertTrue(isSimpleType(getType(Date.class))); assertTrue(isSimpleType(getType(Object.class))); assertFalse(isSimpleType(getType(getClass()))); assertFalse(isSimpleType((TypeElement) null)); assertFalse(isSimpleType((TypeMirror) null)); } @Test void testIsSameType() { assertTrue(isSameType(getType(Void.class).asType(), "java.lang.Void")); assertFalse(isSameType(getType(String.class).asType(), "java.lang.Void")); assertFalse(isSameType(getType(Void.class).asType(), (Type) null)); assertFalse(isSameType(null, (Type) null)); assertFalse(isSameType(getType(Void.class).asType(), (String) null)); assertFalse(isSameType(null, (String) null)); } @Test void testIsArrayType() { TypeElement type = getType(ArrayTypeModel.class); assertTrue(isArrayType(findField(type.asType(), "integers").asType())); assertTrue(isArrayType(findField(type.asType(), "strings").asType())); assertTrue(isArrayType(findField(type.asType(), "primitiveTypeModels").asType())); assertTrue(isArrayType(findField(type.asType(), "models").asType())); assertTrue(isArrayType(findField(type.asType(), "colors").asType())); assertFalse(isArrayType((Element) null)); assertFalse(isArrayType((TypeMirror) null)); } @Test void testIsEnumType() { TypeElement type = getType(Color.class); assertTrue(isEnumType(type.asType())); type = getType(ArrayTypeModel.class); assertFalse(isEnumType(type.asType())); assertFalse(isEnumType((Element) null)); assertFalse(isEnumType((TypeMirror) null)); } @Test void testIsClassType() { TypeElement type = getType(ArrayTypeModel.class); assertTrue(isClassType(type.asType())); type = getType(Model.class); assertTrue(isClassType(type.asType())); assertFalse(isClassType((Element) null)); assertFalse(isClassType((TypeMirror) null)); } @Test void testIsPrimitiveType() { TypeElement type = getType(PrimitiveTypeModel.class); getDeclaredFields(type.asType()).stream() .map(VariableElement::asType) .forEach(t -> assertTrue(isPrimitiveType(t))); assertFalse(isPrimitiveType(getType(ArrayTypeModel.class))); assertFalse(isPrimitiveType((Element) null)); assertFalse(isPrimitiveType((TypeMirror) null)); } @Test void testIsInterfaceType() { TypeElement type = getType(CharSequence.class); assertTrue(isInterfaceType(type)); assertTrue(isInterfaceType(type.asType())); type = getType(Model.class); assertFalse(isInterfaceType(type)); assertFalse(isInterfaceType(type.asType())); assertFalse(isInterfaceType((Element) null)); assertFalse(isInterfaceType((TypeMirror) null)); } @Test void testIsAnnotationType() { TypeElement type = getType(Override.class); assertTrue(isAnnotationType(type)); assertTrue(isAnnotationType(type.asType())); type = getType(Model.class); assertFalse(isAnnotationType(type)); assertFalse(isAnnotationType(type.asType())); assertFalse(isAnnotationType((Element) null)); assertFalse(isAnnotationType((TypeMirror) null)); } @Test void testGetHierarchicalTypes() { Set hierarchicalTypes = getHierarchicalTypes(testType.asType(), true, true, true); Iterator iterator = hierarchicalTypes.iterator(); assertEquals(8, hierarchicalTypes.size()); assertEquals( "org.apache.dubbo.metadata.tools.TestServiceImpl", iterator.next().toString()); assertEquals( "org.apache.dubbo.metadata.tools.GenericTestService", iterator.next().toString()); assertEquals( "org.apache.dubbo.metadata.tools.DefaultTestService", iterator.next().toString()); assertEquals("java.lang.Object", iterator.next().toString()); assertEquals( "org.apache.dubbo.metadata.tools.TestService", iterator.next().toString()); assertEquals("java.lang.AutoCloseable", iterator.next().toString()); assertEquals("java.io.Serializable", iterator.next().toString()); assertEquals("java.util.EventListener", iterator.next().toString()); hierarchicalTypes = getHierarchicalTypes(testType); iterator = hierarchicalTypes.iterator(); assertEquals(8, hierarchicalTypes.size()); assertEquals( "org.apache.dubbo.metadata.tools.TestServiceImpl", iterator.next().toString()); assertEquals( "org.apache.dubbo.metadata.tools.GenericTestService", iterator.next().toString()); assertEquals( "org.apache.dubbo.metadata.tools.DefaultTestService", iterator.next().toString()); assertEquals("java.lang.Object", iterator.next().toString()); assertEquals( "org.apache.dubbo.metadata.tools.TestService", iterator.next().toString()); assertEquals("java.lang.AutoCloseable", iterator.next().toString()); assertEquals("java.io.Serializable", iterator.next().toString()); assertEquals("java.util.EventListener", iterator.next().toString()); hierarchicalTypes = getHierarchicalTypes(testType.asType(), Object.class); iterator = hierarchicalTypes.iterator(); assertEquals(7, hierarchicalTypes.size()); assertEquals( "org.apache.dubbo.metadata.tools.TestServiceImpl", iterator.next().toString()); assertEquals( "org.apache.dubbo.metadata.tools.GenericTestService", iterator.next().toString()); assertEquals( "org.apache.dubbo.metadata.tools.DefaultTestService", iterator.next().toString()); assertEquals( "org.apache.dubbo.metadata.tools.TestService", iterator.next().toString()); assertEquals("java.lang.AutoCloseable", iterator.next().toString()); assertEquals("java.io.Serializable", iterator.next().toString()); assertEquals("java.util.EventListener", iterator.next().toString()); hierarchicalTypes = getHierarchicalTypes(testType.asType(), true, true, false); iterator = hierarchicalTypes.iterator(); assertEquals(4, hierarchicalTypes.size()); assertEquals( "org.apache.dubbo.metadata.tools.TestServiceImpl", iterator.next().toString()); assertEquals( "org.apache.dubbo.metadata.tools.GenericTestService", iterator.next().toString()); assertEquals( "org.apache.dubbo.metadata.tools.DefaultTestService", iterator.next().toString()); assertEquals("java.lang.Object", iterator.next().toString()); hierarchicalTypes = getHierarchicalTypes(testType.asType(), true, false, true); iterator = hierarchicalTypes.iterator(); assertEquals(5, hierarchicalTypes.size()); assertEquals( "org.apache.dubbo.metadata.tools.TestServiceImpl", iterator.next().toString()); assertEquals( "org.apache.dubbo.metadata.tools.TestService", iterator.next().toString()); assertEquals("java.lang.AutoCloseable", iterator.next().toString()); assertEquals("java.io.Serializable", iterator.next().toString()); assertEquals("java.util.EventListener", iterator.next().toString()); hierarchicalTypes = getHierarchicalTypes(testType.asType(), false, false, true); iterator = hierarchicalTypes.iterator(); assertEquals(4, hierarchicalTypes.size()); assertEquals( "org.apache.dubbo.metadata.tools.TestService", iterator.next().toString()); assertEquals("java.lang.AutoCloseable", iterator.next().toString()); assertEquals("java.io.Serializable", iterator.next().toString()); assertEquals("java.util.EventListener", iterator.next().toString()); hierarchicalTypes = getHierarchicalTypes(testType.asType(), true, false, false); iterator = hierarchicalTypes.iterator(); assertEquals(1, hierarchicalTypes.size()); assertEquals( "org.apache.dubbo.metadata.tools.TestServiceImpl", iterator.next().toString()); hierarchicalTypes = getHierarchicalTypes(testType.asType(), false, false, false); assertEquals(0, hierarchicalTypes.size()); assertTrue(getHierarchicalTypes((TypeElement) null).isEmpty()); assertTrue(getHierarchicalTypes((TypeMirror) null).isEmpty()); } @Test void testGetInterfaces() { TypeElement type = getType(Model.class); List<TypeMirror> interfaces = getInterfaces(type); assertTrue(interfaces.isEmpty()); interfaces = getInterfaces(testType.asType()); assertEquals(3, interfaces.size()); assertEquals( "org.apache.dubbo.metadata.tools.TestService", interfaces.get(0).toString()); assertEquals("java.lang.AutoCloseable", interfaces.get(1).toString()); assertEquals("java.io.Serializable", interfaces.get(2).toString()); assertTrue(getInterfaces((TypeElement) null).isEmpty()); assertTrue(getInterfaces((TypeMirror) null).isEmpty()); } @Test void testGetAllInterfaces() { Set<? extends TypeMirror> interfaces = getAllInterfaces(testType.asType()); assertEquals(4, interfaces.size()); Iterator<? extends TypeMirror> iterator = interfaces.iterator(); assertEquals( "org.apache.dubbo.metadata.tools.TestService", iterator.next().toString()); assertEquals("java.lang.AutoCloseable", iterator.next().toString()); assertEquals("java.io.Serializable", iterator.next().toString()); assertEquals("java.util.EventListener", iterator.next().toString()); Set<TypeElement> allInterfaces = getAllInterfaces(testType); assertEquals(4, interfaces.size()); Iterator<TypeElement> allIterator = allInterfaces.iterator(); assertEquals( "org.apache.dubbo.metadata.tools.TestService", allIterator.next().toString()); assertEquals("java.lang.AutoCloseable", allIterator.next().toString()); assertEquals("java.io.Serializable", allIterator.next().toString()); assertEquals("java.util.EventListener", allIterator.next().toString()); assertTrue(getAllInterfaces((TypeElement) null).isEmpty()); assertTrue(getAllInterfaces((TypeMirror) null).isEmpty()); } @Test void testGetType() { TypeElement element = TypeUtils.getType(processingEnv, String.class); assertEquals(element, TypeUtils.getType(processingEnv, element.asType())); assertEquals(element, TypeUtils.getType(processingEnv, "java.lang.String")); assertNull(TypeUtils.getType(processingEnv, (Type) null)); assertNull(TypeUtils.getType(processingEnv, (TypeMirror) null)); assertNull(TypeUtils.getType(processingEnv, (CharSequence) null)); assertNull(TypeUtils.getType(null, (CharSequence) null)); } @Test void testGetSuperType() { TypeElement gtsTypeElement = getSuperType(testType); assertEquals(gtsTypeElement, getType(GenericTestService.class)); TypeElement dtsTypeElement = getSuperType(gtsTypeElement); assertEquals(dtsTypeElement, getType(DefaultTestService.class)); TypeMirror gtsType = getSuperType(testType.asType()); assertEquals(gtsType, getType(GenericTestService.class).asType()); TypeMirror dtsType = getSuperType(gtsType); assertEquals(dtsType, getType(DefaultTestService.class).asType()); assertNull(getSuperType((TypeElement) null)); assertNull(getSuperType((TypeMirror) null)); } @Test void testGetAllSuperTypes() { Set<?> allSuperTypes = getAllSuperTypes(testType); Iterator<?> iterator = allSuperTypes.iterator(); assertEquals(3, allSuperTypes.size()); assertEquals(iterator.next(), getType(GenericTestService.class)); assertEquals(iterator.next(), getType(DefaultTestService.class)); assertEquals(iterator.next(), getType(Object.class)); allSuperTypes = getAllSuperTypes(testType); iterator = allSuperTypes.iterator(); assertEquals(3, allSuperTypes.size()); assertEquals(iterator.next(), getType(GenericTestService.class)); assertEquals(iterator.next(), getType(DefaultTestService.class)); assertEquals(iterator.next(), getType(Object.class)); assertTrue(getAllSuperTypes((TypeElement) null).isEmpty()); assertTrue(getAllSuperTypes((TypeMirror) null).isEmpty()); } @Test void testIsDeclaredType() { assertTrue(isDeclaredType(testType)); assertTrue(isDeclaredType(testType.asType())); assertFalse(isDeclaredType((Element) null)); assertFalse(isDeclaredType((TypeMirror) null)); assertFalse(isDeclaredType(types.getNullType())); assertFalse(isDeclaredType(types.getPrimitiveType(TypeKind.BYTE))); assertFalse(isDeclaredType(types.getArrayType(types.getPrimitiveType(TypeKind.BYTE)))); } @Test void testOfDeclaredType() { assertEquals(testType.asType(), ofDeclaredType(testType)); assertEquals(testType.asType(), ofDeclaredType(testType.asType())); assertEquals(ofDeclaredType(testType), ofDeclaredType(testType.asType())); assertNull(ofDeclaredType((Element) null)); assertNull(ofDeclaredType((TypeMirror) null)); } @Test void testIsTypeElement() { assertTrue(isTypeElement(testType)); assertTrue(isTypeElement(testType.asType())); assertFalse(isTypeElement((Element) null)); assertFalse(isTypeElement((TypeMirror) null)); } @Test void testOfTypeElement() { assertEquals(testType, ofTypeElement(testType)); assertEquals(testType, ofTypeElement(testType.asType())); assertNull(ofTypeElement((Element) null)); assertNull(ofTypeElement((TypeMirror) null)); } @Test void testOfDeclaredTypes() { Set<DeclaredType> declaredTypes = ofDeclaredTypes(asList(getType(String.class), getType(TestServiceImpl.class), getType(Color.class))); assertTrue(declaredTypes.contains(getType(String.class).asType())); assertTrue(declaredTypes.contains(getType(TestServiceImpl.class).asType())); assertTrue(declaredTypes.contains(getType(Color.class).asType())); assertTrue(ofDeclaredTypes(null).isEmpty()); } @Test void testListDeclaredTypes() { List<DeclaredType> types = listDeclaredTypes(asList(testType, testType, testType)); assertEquals(1, types.size()); assertEquals(ofDeclaredType(testType), types.get(0)); types = listDeclaredTypes(asList(new Element[] {null})); assertTrue(types.isEmpty()); } @Test void testListTypeElements() { List<TypeElement> typeElements = listTypeElements(asList(testType.asType(), ofDeclaredType(testType))); assertEquals(1, typeElements.size()); assertEquals(testType, typeElements.get(0)); typeElements = listTypeElements( asList(types.getPrimitiveType(TypeKind.BYTE), types.getNullType(), types.getNoType(TypeKind.NONE))); assertTrue(typeElements.isEmpty()); typeElements = listTypeElements(asList(new TypeMirror[] {null})); assertTrue(typeElements.isEmpty()); typeElements = listTypeElements(null); assertTrue(typeElements.isEmpty()); } @Test @Disabled public void testGetResource() throws URISyntaxException { URL resource = getResource(processingEnv, testType); assertNotNull(resource); assertTrue(new File(resource.toURI()).exists()); assertEquals(resource, getResource(processingEnv, testType.asType())); assertEquals(resource, getResource(processingEnv, "org.apache.dubbo.metadata.tools.TestServiceImpl")); assertThrows(RuntimeException.class, () -> getResource(processingEnv, "NotFound")); } @Test void testGetResourceName() { assertEquals("java/lang/String.class", getResourceName("java.lang.String")); assertNull(getResourceName(null)); } }
5,251
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/util/ServiceAnnotationUtilsTest.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.util; import org.apache.dubbo.metadata.annotation.processing.AbstractAnnotationProcessingTest; import org.apache.dubbo.metadata.tools.DefaultTestService; import org.apache.dubbo.metadata.tools.GenericTestService; import org.apache.dubbo.metadata.tools.TestService; import org.apache.dubbo.metadata.tools.TestServiceImpl; import javax.lang.model.element.TypeElement; import java.util.LinkedHashSet; import java.util.Set; import org.junit.jupiter.api.Test; import static java.util.Arrays.asList; import static org.apache.dubbo.metadata.annotation.processing.util.ServiceAnnotationUtils.DUBBO_SERVICE_ANNOTATION_TYPE; import static org.apache.dubbo.metadata.annotation.processing.util.ServiceAnnotationUtils.GROUP_ATTRIBUTE_NAME; import static org.apache.dubbo.metadata.annotation.processing.util.ServiceAnnotationUtils.INTERFACE_CLASS_ATTRIBUTE_NAME; import static org.apache.dubbo.metadata.annotation.processing.util.ServiceAnnotationUtils.INTERFACE_NAME_ATTRIBUTE_NAME; import static org.apache.dubbo.metadata.annotation.processing.util.ServiceAnnotationUtils.LEGACY_SERVICE_ANNOTATION_TYPE; import static org.apache.dubbo.metadata.annotation.processing.util.ServiceAnnotationUtils.SERVICE_ANNOTATION_TYPE; import static org.apache.dubbo.metadata.annotation.processing.util.ServiceAnnotationUtils.SUPPORTED_ANNOTATION_TYPES; import static org.apache.dubbo.metadata.annotation.processing.util.ServiceAnnotationUtils.VERSION_ATTRIBUTE_NAME; import static org.apache.dubbo.metadata.annotation.processing.util.ServiceAnnotationUtils.getAnnotation; import static org.apache.dubbo.metadata.annotation.processing.util.ServiceAnnotationUtils.getGroup; import static org.apache.dubbo.metadata.annotation.processing.util.ServiceAnnotationUtils.getVersion; import static org.apache.dubbo.metadata.annotation.processing.util.ServiceAnnotationUtils.isServiceAnnotationPresent; import static org.apache.dubbo.metadata.annotation.processing.util.ServiceAnnotationUtils.resolveServiceInterfaceName; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; /** * {@link ServiceAnnotationUtils} Test * * @since 2.7.6 */ class ServiceAnnotationUtilsTest extends AbstractAnnotationProcessingTest { @Override protected void addCompiledClasses(Set<Class<?>> classesToBeCompiled) {} @Override protected void beforeEach() {} @Test void testConstants() { assertEquals("org.apache.dubbo.config.annotation.DubboService", DUBBO_SERVICE_ANNOTATION_TYPE); assertEquals("org.apache.dubbo.config.annotation.Service", SERVICE_ANNOTATION_TYPE); assertEquals("com.alibaba.dubbo.config.annotation.Service", LEGACY_SERVICE_ANNOTATION_TYPE); assertEquals("interfaceClass", INTERFACE_CLASS_ATTRIBUTE_NAME); assertEquals("interfaceName", INTERFACE_NAME_ATTRIBUTE_NAME); assertEquals("group", GROUP_ATTRIBUTE_NAME); assertEquals("version", VERSION_ATTRIBUTE_NAME); assertEquals( new LinkedHashSet<>(asList( "org.apache.dubbo.config.annotation.DubboService", "org.apache.dubbo.config.annotation.Service", "com.alibaba.dubbo.config.annotation.Service")), SUPPORTED_ANNOTATION_TYPES); } @Test void testIsServiceAnnotationPresent() { assertTrue(isServiceAnnotationPresent(getType(TestServiceImpl.class))); assertTrue(isServiceAnnotationPresent(getType(GenericTestService.class))); assertTrue(isServiceAnnotationPresent(getType(DefaultTestService.class))); assertFalse(isServiceAnnotationPresent(getType(TestService.class))); } @Test void testGetAnnotation() { TypeElement type = getType(TestServiceImpl.class); assertEquals( "org.apache.dubbo.config.annotation.Service", getAnnotation(type).getAnnotationType().toString()); type = getType(GenericTestService.class); assertEquals( "com.alibaba.dubbo.config.annotation.Service", getAnnotation(type).getAnnotationType().toString()); type = getType(DefaultTestService.class); assertEquals( "org.apache.dubbo.config.annotation.Service", getAnnotation(type).getAnnotationType().toString()); assertThrows(IllegalArgumentException.class, () -> getAnnotation(getType(TestService.class))); } @Test void testResolveServiceInterfaceName() { TypeElement type = getType(TestServiceImpl.class); assertEquals( "org.apache.dubbo.metadata.tools.TestService", resolveServiceInterfaceName(type, getAnnotation(type))); type = getType(GenericTestService.class); assertEquals( "org.apache.dubbo.metadata.tools.TestService", resolveServiceInterfaceName(type, getAnnotation(type))); type = getType(DefaultTestService.class); assertEquals( "org.apache.dubbo.metadata.tools.TestService", resolveServiceInterfaceName(type, getAnnotation(type))); } @Test void testGetVersion() { TypeElement type = getType(TestServiceImpl.class); assertEquals("3.0.0", getVersion(getAnnotation(type))); type = getType(GenericTestService.class); assertEquals("2.0.0", getVersion(getAnnotation(type))); type = getType(DefaultTestService.class); assertEquals("1.0.0", getVersion(getAnnotation(type))); } @Test void testGetGroup() { TypeElement type = getType(TestServiceImpl.class); assertEquals("test", getGroup(getAnnotation(type))); type = getType(GenericTestService.class); assertEquals("generic", getGroup(getAnnotation(type))); type = getType(DefaultTestService.class); assertEquals("default", getGroup(getAnnotation(type))); } }
5,252
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/model/SimpleTypeModel.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.model; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Date; /** * Simple Type model * * @since 2.7.6 */ public class SimpleTypeModel { private Void v; private Boolean z; private Character c; private Byte b; private Short s; private Integer i; private Long l; private Float f; private Double d; private String str; private BigDecimal bd; private BigInteger bi; private Date dt; private int invalid; public Void getV() { return v; } public void setV(Void v) { this.v = v; } public Boolean getZ() { return z; } public void setZ(Boolean z) { this.z = z; } public Character getC() { return c; } public void setC(Character c) { this.c = c; } public Byte getB() { return b; } public void setB(Byte b) { this.b = b; } public Short getS() { return s; } public void setS(Short s) { this.s = s; } public Integer getI() { return i; } public void setI(Integer i) { this.i = i; } public Long getL() { return l; } public void setL(Long l) { this.l = l; } public Float getF() { return f; } public void setF(Float f) { this.f = f; } public Double getD() { return d; } public void setD(Double d) { this.d = d; } public String getStr() { return str; } public void setStr(String str) { this.str = str; } public BigDecimal getBd() { return bd; } public void setBd(BigDecimal bd) { this.bd = bd; } public BigInteger getBi() { return bi; } public void setBi(BigInteger bi) { this.bi = bi; } public Date getDt() { return dt; } public void setDt(Date dt) { this.dt = dt; } }
5,253
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/model/ArrayTypeModel.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.model; /** * Array Type Model * * @since 2.7.6 */ public class ArrayTypeModel { private int[] integers; // Primitive type array private String[] strings; // Simple type array private PrimitiveTypeModel[] primitiveTypeModels; // Complex type array private Model[] models; // Hierarchical Complex type array private Color[] colors; // Enum type array }
5,254
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/model/MapTypeModel.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.model; import java.util.HashMap; import java.util.Map; import java.util.NavigableMap; import java.util.SortedMap; import java.util.TreeMap; /** * {@link Map} Type model * * @since 2.7.6 */ public class MapTypeModel { private Map<String, String> strings; // The composite element is simple type private SortedMap<String, Color> colors; // The composite element is Enum type private NavigableMap<Color, PrimitiveTypeModel> primitiveTypeModels; // The composite element is POJO type private HashMap<String, Model> models; // The composite element is hierarchical POJO type private TreeMap<PrimitiveTypeModel, Model[]> modelArrays; // The composite element is hierarchical POJO type }
5,255
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/model/PrimitiveTypeModel.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.model; /** * Primitive Type model * * @since 2.7.6 */ public class PrimitiveTypeModel { private boolean z; private byte b; private char c; private short s; private int i; private long l; private float f; private double d; public boolean isZ() { return z; } public byte getB() { return b; } public char getC() { return c; } public short getS() { return s; } public int getI() { return i; } public long getL() { return l; } public float getF() { return f; } public double getD() { return d; } }
5,256
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/model/CollectionTypeModel.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.model; import java.util.Collection; import java.util.Deque; import java.util.List; import java.util.Queue; import java.util.Set; /** * {@link Collection} Type Model * * @since 2.7.6 */ public class CollectionTypeModel { private Collection<String> strings; // The composite element is simple type private List<Color> colors; // The composite element is Enum type private Queue<PrimitiveTypeModel> primitiveTypeModels; // The composite element is POJO type private Deque<Model> models; // The composite element is hierarchical POJO type private Set<Model[]> modelArrays; // The composite element is hierarchical POJO type }
5,257
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/model/Model.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.model; import org.apache.dubbo.metadata.tools.Parent; import java.math.BigDecimal; import java.math.BigInteger; import java.util.concurrent.TimeUnit; /** * Model Object */ public class Model extends Parent { private float f; private double d; private TimeUnit tu; private String str; private BigInteger bi; private BigDecimal bd; public float getF() { return f; } public void setF(float f) { this.f = f; } public double getD() { return d; } public void setD(double d) { this.d = d; } public TimeUnit getTu() { return tu; } public void setTu(TimeUnit tu) { this.tu = tu; } public String getStr() { return str; } public void setStr(String str) { this.str = str; } public BigInteger getBi() { return bi; } public void setBi(BigInteger bi) { this.bi = bi; } public BigDecimal getBd() { return bd; } public void setBd(BigDecimal bd) { this.bd = bd; } }
5,258
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/model/Color.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.model; /** * Color enumeration * * @since 2.7.6 */ public enum Color { RED(1), YELLOW(2), BLUE(3); private final int value; Color(int value) { this.value = value; } @Override public String toString() { return "Color{" + "value=" + value + "} " + super.toString(); } public int getValue() { return value; } }
5,259
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/builder/ArrayTypeDefinitionBuilderTest.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.builder; import org.apache.dubbo.metadata.annotation.processing.AbstractAnnotationProcessingTest; import org.apache.dubbo.metadata.annotation.processing.model.ArrayTypeModel; import org.apache.dubbo.metadata.definition.model.TypeDefinition; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.function.BiConsumer; import java.util.stream.Stream; import org.junit.jupiter.api.Test; import static org.apache.dubbo.metadata.annotation.processing.util.FieldUtils.findField; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; /** * {@link ArrayTypeDefinitionBuilder} Test * * @since 2.7.6 */ class ArrayTypeDefinitionBuilderTest extends AbstractAnnotationProcessingTest { private ArrayTypeDefinitionBuilder builder; private TypeElement testType; private VariableElement integersField; private VariableElement stringsField; private VariableElement primitiveTypeModelsField; private VariableElement modelsField; private VariableElement colorsField; @Override protected void addCompiledClasses(Set<Class<?>> classesToBeCompiled) { classesToBeCompiled.add(ArrayTypeModel.class); } @Override protected void beforeEach() { builder = new ArrayTypeDefinitionBuilder(); testType = getType(ArrayTypeModel.class); integersField = findField(testType, "integers"); stringsField = findField(testType, "strings"); primitiveTypeModelsField = findField(testType, "primitiveTypeModels"); modelsField = findField(testType, "models"); colorsField = findField(testType, "colors"); } @Test void testAccept() { assertTrue(builder.accept(processingEnv, integersField.asType())); assertTrue(builder.accept(processingEnv, stringsField.asType())); assertTrue(builder.accept(processingEnv, primitiveTypeModelsField.asType())); assertTrue(builder.accept(processingEnv, modelsField.asType())); assertTrue(builder.accept(processingEnv, colorsField.asType())); } @Test void testBuild() { buildAndAssertTypeDefinition(processingEnv, integersField, "int[]", "int", builder); buildAndAssertTypeDefinition(processingEnv, stringsField, "java.lang.String[]", "java.lang.String", builder); buildAndAssertTypeDefinition( processingEnv, primitiveTypeModelsField, "org.apache.dubbo.metadata.annotation.processing.model.PrimitiveTypeModel[]", "org.apache.dubbo.metadata.annotation.processing.model.PrimitiveTypeModel", builder); buildAndAssertTypeDefinition( processingEnv, modelsField, "org.apache.dubbo.metadata.annotation.processing.model.Model[]", "org.apache.dubbo.metadata.annotation.processing.model.Model", builder, (def, subDef) -> { TypeElement subType = elements.getTypeElement(subDef.getType()); assertEquals(ElementKind.CLASS, subType.getKind()); }); buildAndAssertTypeDefinition( processingEnv, colorsField, "org.apache.dubbo.metadata.annotation.processing.model.Color[]", "org.apache.dubbo.metadata.annotation.processing.model.Color", builder, (def, subDef) -> { TypeElement subType = elements.getTypeElement(subDef.getType()); assertEquals(ElementKind.ENUM, subType.getKind()); }); } static void buildAndAssertTypeDefinition( ProcessingEnvironment processingEnv, VariableElement field, String expectedType, String compositeType, TypeBuilder builder, BiConsumer<TypeDefinition, TypeDefinition>... assertions) { Map<String, TypeDefinition> typeCache = new HashMap<>(); TypeDefinition typeDefinition = TypeDefinitionBuilder.build(processingEnv, field, typeCache); String subTypeName = typeDefinition.getItems().get(0); TypeDefinition subTypeDefinition = typeCache.get(subTypeName); assertEquals(expectedType, typeDefinition.getType()); // assertEquals(field.getSimpleName().toString(), typeDefinition.get$ref()); assertEquals(compositeType, subTypeDefinition.getType()); // assertEquals(builder.getClass().getName(), typeDefinition.getTypeBuilderName()); Stream.of(assertions).forEach(assertion -> assertion.accept(typeDefinition, subTypeDefinition)); } }
5,260
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/builder/EnumTypeDefinitionBuilderTest.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.builder; import org.apache.dubbo.metadata.annotation.processing.AbstractAnnotationProcessingTest; import org.apache.dubbo.metadata.annotation.processing.model.Color; import org.apache.dubbo.metadata.definition.model.TypeDefinition; import javax.lang.model.element.TypeElement; import java.util.HashMap; import java.util.Map; import java.util.Set; import org.junit.jupiter.api.Test; import static java.util.Arrays.asList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; /** * {@link EnumTypeDefinitionBuilder} Test * * @since 2.7.6 */ class EnumTypeDefinitionBuilderTest extends AbstractAnnotationProcessingTest { private EnumTypeDefinitionBuilder builder; @Override protected void addCompiledClasses(Set<Class<?>> classesToBeCompiled) { classesToBeCompiled.add(Color.class); } @Override protected void beforeEach() { builder = new EnumTypeDefinitionBuilder(); } @Test void testAccept() { TypeElement typeElement = getType(Color.class); assertTrue(builder.accept(processingEnv, typeElement.asType())); } @Test void testBuild() { TypeElement typeElement = getType(Color.class); Map<String, TypeDefinition> typeCache = new HashMap<>(); TypeDefinition typeDefinition = TypeDefinitionBuilder.build(processingEnv, typeElement, typeCache); assertEquals(Color.class.getName(), typeDefinition.getType()); assertEquals(asList("RED", "YELLOW", "BLUE"), typeDefinition.getEnums()); // assertEquals(typeDefinition.getTypeBuilderName(), builder.getClass().getName()); } }
5,261
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/builder/SimpleTypeDefinitionBuilderTest.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.builder; import org.apache.dubbo.metadata.annotation.processing.AbstractAnnotationProcessingTest; import org.apache.dubbo.metadata.annotation.processing.model.SimpleTypeModel; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import java.util.Set; import org.junit.jupiter.api.Test; import static org.apache.dubbo.metadata.annotation.processing.builder.PrimitiveTypeDefinitionBuilderTest.buildAndAssertTypeDefinition; import static org.apache.dubbo.metadata.annotation.processing.util.FieldUtils.findField; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; /** * {@link SimpleTypeDefinitionBuilder} Test * * @since 2.7.6 */ class SimpleTypeDefinitionBuilderTest extends AbstractAnnotationProcessingTest { private SimpleTypeDefinitionBuilder builder; private VariableElement vField; private VariableElement zField; private VariableElement cField; private VariableElement bField; private VariableElement sField; private VariableElement iField; private VariableElement lField; private VariableElement fField; private VariableElement dField; private VariableElement strField; private VariableElement bdField; private VariableElement biField; private VariableElement dtField; private VariableElement invalidField; @Override protected void addCompiledClasses(Set<Class<?>> classesToBeCompiled) { classesToBeCompiled.add(SimpleTypeModel.class); } @Override protected void beforeEach() { builder = new SimpleTypeDefinitionBuilder(); TypeElement testType = getType(SimpleTypeModel.class); vField = findField(testType, "v"); zField = findField(testType, "z"); cField = findField(testType, "c"); bField = findField(testType, "b"); sField = findField(testType, "s"); iField = findField(testType, "i"); lField = findField(testType, "l"); fField = findField(testType, "f"); dField = findField(testType, "d"); strField = findField(testType, "str"); bdField = findField(testType, "bd"); biField = findField(testType, "bi"); dtField = findField(testType, "dt"); invalidField = findField(testType, "invalid"); assertEquals("java.lang.Void", vField.asType().toString()); assertEquals("java.lang.Boolean", zField.asType().toString()); assertEquals("java.lang.Character", cField.asType().toString()); assertEquals("java.lang.Byte", bField.asType().toString()); assertEquals("java.lang.Short", sField.asType().toString()); assertEquals("java.lang.Integer", iField.asType().toString()); assertEquals("java.lang.Long", lField.asType().toString()); assertEquals("java.lang.Float", fField.asType().toString()); assertEquals("java.lang.Double", dField.asType().toString()); assertEquals("java.lang.String", strField.asType().toString()); assertEquals("java.math.BigDecimal", bdField.asType().toString()); assertEquals("java.math.BigInteger", biField.asType().toString()); assertEquals("java.util.Date", dtField.asType().toString()); assertEquals("int", invalidField.asType().toString()); } @Test void testAccept() { assertTrue(builder.accept(processingEnv, vField.asType())); assertTrue(builder.accept(processingEnv, zField.asType())); assertTrue(builder.accept(processingEnv, cField.asType())); assertTrue(builder.accept(processingEnv, bField.asType())); assertTrue(builder.accept(processingEnv, sField.asType())); assertTrue(builder.accept(processingEnv, iField.asType())); assertTrue(builder.accept(processingEnv, lField.asType())); assertTrue(builder.accept(processingEnv, fField.asType())); assertTrue(builder.accept(processingEnv, dField.asType())); assertTrue(builder.accept(processingEnv, strField.asType())); assertTrue(builder.accept(processingEnv, bdField.asType())); assertTrue(builder.accept(processingEnv, biField.asType())); assertTrue(builder.accept(processingEnv, dtField.asType())); // false condition assertFalse(builder.accept(processingEnv, invalidField.asType())); } @Test void testBuild() { buildAndAssertTypeDefinition(processingEnv, vField, builder); buildAndAssertTypeDefinition(processingEnv, zField, builder); buildAndAssertTypeDefinition(processingEnv, cField, builder); buildAndAssertTypeDefinition(processingEnv, sField, builder); buildAndAssertTypeDefinition(processingEnv, iField, builder); buildAndAssertTypeDefinition(processingEnv, lField, builder); buildAndAssertTypeDefinition(processingEnv, fField, builder); buildAndAssertTypeDefinition(processingEnv, dField, builder); buildAndAssertTypeDefinition(processingEnv, strField, builder); buildAndAssertTypeDefinition(processingEnv, bdField, builder); buildAndAssertTypeDefinition(processingEnv, biField, builder); buildAndAssertTypeDefinition(processingEnv, dtField, builder); } }
5,262
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/builder/CollectionTypeDefinitionBuilderTest.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.builder; import org.apache.dubbo.metadata.annotation.processing.AbstractAnnotationProcessingTest; import org.apache.dubbo.metadata.annotation.processing.model.CollectionTypeModel; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import java.util.Set; import org.junit.jupiter.api.Test; import static org.apache.dubbo.metadata.annotation.processing.builder.ArrayTypeDefinitionBuilderTest.buildAndAssertTypeDefinition; import static org.apache.dubbo.metadata.annotation.processing.util.FieldUtils.findField; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; /** * {@link CollectionTypeDefinitionBuilder} Test * * @since 2.7.6 */ class CollectionTypeDefinitionBuilderTest extends AbstractAnnotationProcessingTest { private CollectionTypeDefinitionBuilder builder; private VariableElement stringsField; private VariableElement colorsField; private VariableElement primitiveTypeModelsField; private VariableElement modelsField; private VariableElement modelArraysField; @Override protected void addCompiledClasses(Set<Class<?>> classesToBeCompiled) { classesToBeCompiled.add(CollectionTypeModel.class); } @Override protected void beforeEach() { builder = new CollectionTypeDefinitionBuilder(); TypeElement testType = getType(CollectionTypeModel.class); stringsField = findField(testType, "strings"); colorsField = findField(testType, "colors"); primitiveTypeModelsField = findField(testType, "primitiveTypeModels"); modelsField = findField(testType, "models"); modelArraysField = findField(testType, "modelArrays"); assertEquals("strings", stringsField.getSimpleName().toString()); assertEquals("colors", colorsField.getSimpleName().toString()); assertEquals( "primitiveTypeModels", primitiveTypeModelsField.getSimpleName().toString()); assertEquals("models", modelsField.getSimpleName().toString()); assertEquals("modelArrays", modelArraysField.getSimpleName().toString()); } @Test void testAccept() { assertTrue(builder.accept(processingEnv, stringsField.asType())); assertTrue(builder.accept(processingEnv, colorsField.asType())); assertTrue(builder.accept(processingEnv, primitiveTypeModelsField.asType())); assertTrue(builder.accept(processingEnv, modelsField.asType())); assertTrue(builder.accept(processingEnv, modelArraysField.asType())); } @Test void testBuild() { buildAndAssertTypeDefinition( processingEnv, stringsField, "java.util.Collection<java.lang.String>", "java.lang.String", builder); buildAndAssertTypeDefinition( processingEnv, colorsField, "java.util.List<org.apache.dubbo.metadata.annotation.processing.model.Color>", "org.apache.dubbo.metadata.annotation.processing.model.Color", builder); buildAndAssertTypeDefinition( processingEnv, primitiveTypeModelsField, "java.util.Queue<org.apache.dubbo.metadata.annotation.processing.model.PrimitiveTypeModel>", "org.apache.dubbo.metadata.annotation.processing.model.PrimitiveTypeModel", builder); buildAndAssertTypeDefinition( processingEnv, modelsField, "java.util.Deque<org.apache.dubbo.metadata.annotation.processing.model.Model>", "org.apache.dubbo.metadata.annotation.processing.model.Model", builder); buildAndAssertTypeDefinition( processingEnv, modelArraysField, "java.util.Set<org.apache.dubbo.metadata.annotation.processing.model.Model[]>", "org.apache.dubbo.metadata.annotation.processing.model.Model[]", builder); } }
5,263
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/builder/ServiceDefinitionBuilderTest.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.builder; import org.apache.dubbo.metadata.annotation.processing.AbstractAnnotationProcessingTest; import org.apache.dubbo.metadata.definition.model.ServiceDefinition; import org.apache.dubbo.metadata.definition.model.TypeDefinition; import org.apache.dubbo.metadata.tools.TestServiceImpl; import java.util.Arrays; import java.util.List; import java.util.Set; import org.junit.jupiter.api.Test; import static org.apache.dubbo.metadata.annotation.processing.builder.ServiceDefinitionBuilder.build; import static org.junit.jupiter.api.Assertions.assertEquals; /** * {@link ServiceDefinitionBuilder} Test * * @since 2.7.6 */ class ServiceDefinitionBuilderTest extends AbstractAnnotationProcessingTest { @Override protected void addCompiledClasses(Set<Class<?>> classesToBeCompiled) { classesToBeCompiled.add(TestServiceImpl.class); } @Override protected void beforeEach() {} @Test void testBuild() { ServiceDefinition serviceDefinition = build(processingEnv, getType(TestServiceImpl.class)); assertEquals(TestServiceImpl.class.getTypeName(), serviceDefinition.getCanonicalName()); assertEquals("org/apache/dubbo/metadata/tools/TestServiceImpl.class", serviceDefinition.getCodeSource()); // types List<String> typeNames = Arrays.asList( "org.apache.dubbo.metadata.tools.TestServiceImpl", "org.apache.dubbo.metadata.tools.GenericTestService", "org.apache.dubbo.metadata.tools.DefaultTestService", "org.apache.dubbo.metadata.tools.TestService", "java.lang.AutoCloseable", "java.io.Serializable", "java.util.EventListener"); for (String typeName : typeNames) { String gotTypeName = getTypeName(typeName, serviceDefinition.getTypes()); assertEquals(typeName, gotTypeName); } // methods assertEquals(14, serviceDefinition.getMethods().size()); } private static String getTypeName(String type, List<TypeDefinition> types) { for (TypeDefinition typeDefinition : types) { if (type.equals(typeDefinition.getType())) { return typeDefinition.getType(); } } return type; } }
5,264
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/builder/MapTypeDefinitionBuilderTest.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.builder; import org.apache.dubbo.metadata.annotation.processing.AbstractAnnotationProcessingTest; import org.apache.dubbo.metadata.annotation.processing.model.MapTypeModel; import org.apache.dubbo.metadata.definition.model.TypeDefinition; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.function.BiConsumer; import java.util.stream.Stream; import org.junit.jupiter.api.Test; import static org.apache.dubbo.metadata.annotation.processing.util.FieldUtils.findField; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; /** * {@link MapTypeDefinitionBuilder} Test * * @since 2.7.6 */ class MapTypeDefinitionBuilderTest extends AbstractAnnotationProcessingTest { private MapTypeDefinitionBuilder builder; private VariableElement stringsField; private VariableElement colorsField; private VariableElement primitiveTypeModelsField; private VariableElement modelsField; private VariableElement modelArraysField; @Override protected void addCompiledClasses(Set<Class<?>> classesToBeCompiled) { classesToBeCompiled.add(MapTypeModel.class); } @Override protected void beforeEach() { builder = new MapTypeDefinitionBuilder(); TypeElement testType = getType(MapTypeModel.class); stringsField = findField(testType, "strings"); colorsField = findField(testType, "colors"); primitiveTypeModelsField = findField(testType, "primitiveTypeModels"); modelsField = findField(testType, "models"); modelArraysField = findField(testType, "modelArrays"); assertEquals("strings", stringsField.getSimpleName().toString()); assertEquals("colors", colorsField.getSimpleName().toString()); assertEquals( "primitiveTypeModels", primitiveTypeModelsField.getSimpleName().toString()); assertEquals("models", modelsField.getSimpleName().toString()); assertEquals("modelArrays", modelArraysField.getSimpleName().toString()); } @Test void testAccept() { assertTrue(builder.accept(processingEnv, stringsField.asType())); assertTrue(builder.accept(processingEnv, colorsField.asType())); assertTrue(builder.accept(processingEnv, primitiveTypeModelsField.asType())); assertTrue(builder.accept(processingEnv, modelsField.asType())); assertTrue(builder.accept(processingEnv, modelArraysField.asType())); } @Test void testBuild() { buildAndAssertTypeDefinition( processingEnv, stringsField, "java.util.Map<java.lang.String,java.lang.String>", "java.lang.String", "java.lang.String", builder); buildAndAssertTypeDefinition( processingEnv, colorsField, "java.util.SortedMap<java.lang.String,org.apache.dubbo.metadata.annotation.processing.model.Color>", "java.lang.String", "org.apache.dubbo.metadata.annotation.processing.model.Color", builder); buildAndAssertTypeDefinition( processingEnv, primitiveTypeModelsField, "java.util.NavigableMap<org.apache.dubbo.metadata.annotation.processing.model.Color,org.apache.dubbo.metadata.annotation.processing.model.PrimitiveTypeModel>", "org.apache.dubbo.metadata.annotation.processing.model.Color", "org.apache.dubbo.metadata.annotation.processing.model.PrimitiveTypeModel", builder); buildAndAssertTypeDefinition( processingEnv, modelsField, "java.util.HashMap<java.lang.String,org.apache.dubbo.metadata.annotation.processing.model.Model>", "java.lang.String", "org.apache.dubbo.metadata.annotation.processing.model.Model", builder); buildAndAssertTypeDefinition( processingEnv, modelArraysField, "java.util.TreeMap<org.apache.dubbo.metadata.annotation.processing.model.PrimitiveTypeModel,org.apache.dubbo.metadata.annotation.processing.model.Model[]>", "org.apache.dubbo.metadata.annotation.processing.model.PrimitiveTypeModel", "org.apache.dubbo.metadata.annotation.processing.model.Model[]", builder); } static void buildAndAssertTypeDefinition( ProcessingEnvironment processingEnv, VariableElement field, String expectedType, String keyType, String valueType, TypeBuilder builder, BiConsumer<TypeDefinition, TypeDefinition>... assertions) { Map<String, TypeDefinition> typeCache = new HashMap<>(); TypeDefinition typeDefinition = TypeDefinitionBuilder.build(processingEnv, field, typeCache); String keyTypeName = typeDefinition.getItems().get(0); TypeDefinition keyTypeDefinition = typeCache.get(keyTypeName); String valueTypeName = typeDefinition.getItems().get(1); TypeDefinition valueTypeDefinition = typeCache.get(valueTypeName); assertEquals(expectedType, typeDefinition.getType()); // assertEquals(field.getSimpleName().toString(), typeDefinition.get$ref()); assertEquals(keyType, keyTypeDefinition.getType()); assertEquals(valueType, valueTypeDefinition.getType()); // assertEquals(builder.getClass().getName(), typeDefinition.getTypeBuilderName()); Stream.of(assertions).forEach(assertion -> assertion.accept(typeDefinition, keyTypeDefinition)); } }
5,265
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/builder/GeneralTypeDefinitionBuilderTest.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.builder; import org.apache.dubbo.metadata.annotation.processing.AbstractAnnotationProcessingTest; import org.apache.dubbo.metadata.annotation.processing.model.ArrayTypeModel; import org.apache.dubbo.metadata.annotation.processing.model.CollectionTypeModel; import org.apache.dubbo.metadata.annotation.processing.model.Color; import org.apache.dubbo.metadata.annotation.processing.model.Model; import org.apache.dubbo.metadata.annotation.processing.model.PrimitiveTypeModel; import org.apache.dubbo.metadata.annotation.processing.model.SimpleTypeModel; import java.util.Set; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; /** * {@link GeneralTypeDefinitionBuilder} Test * * @since 2.7.6 */ class GeneralTypeDefinitionBuilderTest extends AbstractAnnotationProcessingTest { private GeneralTypeDefinitionBuilder builder; @Override protected void addCompiledClasses(Set<Class<?>> classesToBeCompiled) { classesToBeCompiled.add(Model.class); } @Override protected void beforeEach() { builder = new GeneralTypeDefinitionBuilder(); } @Test void testAccept() { assertTrue(builder.accept(processingEnv, getType(Model.class).asType())); assertTrue( builder.accept(processingEnv, getType(PrimitiveTypeModel.class).asType())); assertTrue(builder.accept(processingEnv, getType(SimpleTypeModel.class).asType())); assertTrue(builder.accept(processingEnv, getType(ArrayTypeModel.class).asType())); assertTrue( builder.accept(processingEnv, getType(CollectionTypeModel.class).asType())); assertFalse(builder.accept(processingEnv, getType(Color.class).asType())); } @Test void testBuild() {} }
5,266
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/builder/PrimitiveTypeDefinitionBuilderTest.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.builder; import org.apache.dubbo.metadata.annotation.processing.AbstractAnnotationProcessingTest; import org.apache.dubbo.metadata.annotation.processing.model.PrimitiveTypeModel; import org.apache.dubbo.metadata.definition.model.TypeDefinition; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import java.util.HashMap; import java.util.Map; import java.util.Set; import org.junit.jupiter.api.Test; import static org.apache.dubbo.metadata.annotation.processing.util.FieldUtils.findField; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; /** * {@link PrimitiveTypeDefinitionBuilder} Test * * @since 2.7.6 */ class PrimitiveTypeDefinitionBuilderTest extends AbstractAnnotationProcessingTest { private PrimitiveTypeDefinitionBuilder builder; private VariableElement zField; private VariableElement bField; private VariableElement cField; private VariableElement sField; private VariableElement iField; private VariableElement lField; private VariableElement fField; private VariableElement dField; @Override protected void addCompiledClasses(Set<Class<?>> classesToBeCompiled) { classesToBeCompiled.add(PrimitiveTypeModel.class); } @Override protected void beforeEach() { builder = new PrimitiveTypeDefinitionBuilder(); TypeElement testType = getType(PrimitiveTypeModel.class); zField = findField(testType, "z"); bField = findField(testType, "b"); cField = findField(testType, "c"); sField = findField(testType, "s"); iField = findField(testType, "i"); lField = findField(testType, "l"); fField = findField(testType, "f"); dField = findField(testType, "d"); assertEquals("boolean", zField.asType().toString()); assertEquals("byte", bField.asType().toString()); assertEquals("char", cField.asType().toString()); assertEquals("short", sField.asType().toString()); assertEquals("int", iField.asType().toString()); assertEquals("long", lField.asType().toString()); assertEquals("float", fField.asType().toString()); assertEquals("double", dField.asType().toString()); } @Test void testAccept() { assertTrue(builder.accept(processingEnv, zField.asType())); assertTrue(builder.accept(processingEnv, bField.asType())); assertTrue(builder.accept(processingEnv, cField.asType())); assertTrue(builder.accept(processingEnv, sField.asType())); assertTrue(builder.accept(processingEnv, iField.asType())); assertTrue(builder.accept(processingEnv, lField.asType())); assertTrue(builder.accept(processingEnv, fField.asType())); assertTrue(builder.accept(processingEnv, dField.asType())); } @Test void testBuild() { buildAndAssertTypeDefinition(processingEnv, zField, builder); buildAndAssertTypeDefinition(processingEnv, bField, builder); buildAndAssertTypeDefinition(processingEnv, cField, builder); buildAndAssertTypeDefinition(processingEnv, sField, builder); buildAndAssertTypeDefinition(processingEnv, iField, builder); buildAndAssertTypeDefinition(processingEnv, lField, builder); buildAndAssertTypeDefinition(processingEnv, zField, builder); buildAndAssertTypeDefinition(processingEnv, fField, builder); buildAndAssertTypeDefinition(processingEnv, dField, builder); } static void buildAndAssertTypeDefinition( ProcessingEnvironment processingEnv, VariableElement field, TypeBuilder builder) { Map<String, TypeDefinition> typeCache = new HashMap<>(); TypeDefinition typeDefinition = TypeDefinitionBuilder.build(processingEnv, field, typeCache); assertBasicTypeDefinition(typeDefinition, field.asType().toString(), builder); // assertEquals(field.getSimpleName().toString(), typeDefinition.get$ref()); } static void assertBasicTypeDefinition(TypeDefinition typeDefinition, String type, TypeBuilder builder) { assertEquals(type, typeDefinition.getType()); // assertEquals(builder.getClass().getName(), typeDefinition.getTypeBuilderName()); assertTrue(typeDefinition.getProperties().isEmpty()); assertTrue(typeDefinition.getItems().isEmpty()); assertTrue(typeDefinition.getEnums().isEmpty()); } }
5,267
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/rest/AnnotatedMethodParameterProcessorTest.java
/* * 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 org.apache.dubbo.metadata.annotation.processing.rest; import org.apache.dubbo.metadata.annotation.processing.AbstractAnnotationProcessingTest; import org.apache.dubbo.metadata.rest.RestMethodMetadata; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; /** * The abstract class for {@link AnnotatedMethodParameterProcessor}'s test cases * * @since 2.7.6 */ public abstract class AnnotatedMethodParameterProcessorTest extends AbstractAnnotationProcessingTest { protected AnnotatedMethodParameterProcessor processor; protected RestMethodMetadata restMethodMetadata; protected abstract AnnotatedMethodParameterProcessor createTestInstance(); @BeforeEach public final void prepare() { this.processor = createTestInstance(); this.restMethodMetadata = createRestMethodMetadata(); } protected RestMethodMetadata createRestMethodMetadata() { return new RestMethodMetadata(); } protected abstract String getExpectedAnnotationType(); @Test void testGetAnnotationType() { String expectedAnnotationType = getExpectedAnnotationType(); assertNull(processor.getAnnotationType()); assertEquals(expectedAnnotationType, processor.getAnnotationType()); } }
5,268
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/rest/DefaultRestService.java
/* * 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 org.apache.dubbo.metadata.rest; import org.apache.dubbo.config.annotation.DubboService; import java.util.Map; /** * The default implementation of {@link RestService} * * @since 2.7.6 */ @DubboService(version = "1.0.0", group = "default") public class DefaultRestService implements RestService { @Override public String param(String param) { return null; } @Override public String params(int a, String b) { return null; } @Override public String headers(String header, String header2, Integer param) { return null; } @Override public String pathVariables(String path1, String path2, String param) { return null; } @Override public String form(String form) { return null; } @Override public User requestBodyMap(Map<String, Object> data, String param) { return null; } @Override public Map<String, Object> requestBodyUser(User user) { return null; } public User user(User user) { return user; } }
5,269
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/rest/User.java
/* * 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 org.apache.dubbo.metadata.rest; import java.io.Serializable; /** * User Entity * * @since 2.7.6 */ public class User implements Serializable { private Long id; private String name; private Integer age; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } @Override public String toString() { return "User{" + "id=" + id + ", name='" + name + '\'' + ", age=" + age + '}'; } }
5,270
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/rest/StandardRestService.java
/* * 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 org.apache.dubbo.metadata.rest; import org.apache.dubbo.config.annotation.DubboService; import javax.ws.rs.Consumes; import javax.ws.rs.FormParam; import javax.ws.rs.GET; import javax.ws.rs.HeaderParam; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import java.util.HashMap; import java.util.Map; /** * JAX-RS {@link RestService} */ @DubboService( version = "3.0.0", protocol = {"dubbo", "rest"}, group = "standard") @Path("/") public class StandardRestService implements RestService { @Override @Path("param") @GET public String param(@QueryParam("param") String param) { return param; } @Override @Path("params") @POST public String params(@QueryParam("a") int a, @QueryParam("b") String b) { return a + b; } @Override @Path("headers") @GET public String headers( @HeaderParam("h") String header, @HeaderParam("h2") String header2, @QueryParam("v") Integer param) { String result = header + " , " + header2 + " , " + param; return result; } @Override @Path("path-variables/{p1}/{p2}") @GET public String pathVariables( @PathParam("p1") String path1, @PathParam("p2") String path2, @QueryParam("v") String param) { String result = path1 + " , " + path2 + " , " + param; return result; } // @CookieParam does not support : https://github.com/OpenFeign/feign/issues/913 // @CookieValue also does not support @Override @Path("form") @POST public String form(@FormParam("f") String form) { return String.valueOf(form); } @Override @Path("request/body/map") @POST @Produces("application/json;charset=UTF-8") public User requestBodyMap(Map<String, Object> data, @QueryParam("param") String param) { User user = new User(); user.setId(((Integer) data.get("id")).longValue()); user.setName((String) data.get("name")); user.setAge((Integer) data.get("age")); return user; } @Path("request/body/user") @POST @Override @Consumes("application/json;charset=UTF-8") public Map<String, Object> requestBodyUser(User user) { Map<String, Object> map = new HashMap<>(); map.put("id", user.getId()); map.put("name", user.getName()); map.put("age", user.getAge()); return map; } }
5,271
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/rest/SpringRestService.java
/* * 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 org.apache.dubbo.metadata.rest; import org.apache.dubbo.config.annotation.DubboService; import java.util.HashMap; import java.util.Map; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** * Spring MVC {@link RestService} * * @since 2.7.6 */ @DubboService(version = "2.0.0", group = "spring") @RestController public class SpringRestService implements RestService { @Override @GetMapping(value = "/param") public String param(@RequestParam(defaultValue = "value-param") String param) { return null; } @Override @PostMapping("/params") public String params( @RequestParam(defaultValue = "value-a") int a, @RequestParam(defaultValue = "value-b") String b) { return null; } @Override @GetMapping("/headers") public String headers( @RequestHeader(name = "h", defaultValue = "value-h") String header, @RequestHeader(name = "h2", defaultValue = "value-h2") String header2, @RequestParam(value = "v", defaultValue = "1") Integer param) { return null; } @Override @GetMapping("/path-variables/{p1}/{p2}") public String pathVariables( @PathVariable("p1") String path1, @PathVariable("p2") String path2, @RequestParam("v") String param) { return null; } @Override @PostMapping("/form") public String form(@RequestParam("f") String form) { return String.valueOf(form); } @Override @PostMapping(value = "/request/body/map", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public User requestBodyMap(@RequestBody Map<String, Object> data, @RequestParam("param") String param) { User user = new User(); user.setId(((Integer) data.get("id")).longValue()); user.setName((String) data.get("name")); user.setAge((Integer) data.get("age")); return user; } @PostMapping(value = "/request/body/user", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) @Override public Map<String, Object> requestBodyUser(@RequestBody User user) { Map<String, Object> map = new HashMap<>(); map.put("id", user.getId()); map.put("name", user.getName()); map.put("age", user.getAge()); return map; } }
5,272
0
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata
Create_ds/dubbo/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/rest/RestService.java
/* * 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 org.apache.dubbo.metadata.rest; import java.util.Map; /** * An interface for REST service * * @since 2.7.6 */ public interface RestService { String param(String param); String params(int a, String b); String headers(String header, String header2, Integer param); String pathVariables(String path1, String path2, String param); String form(String form); User requestBodyMap(Map<String, Object> data, String param); Map<String, Object> requestBodyUser(User user); }
5,273
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/Transporter.java
/* * 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.dubbo.remoting; import org.apache.dubbo.common.extension.Adaptive; import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.remoting.RemotingServer; import com.alibaba.dubbo.common.DelegateURL; import com.alibaba.dubbo.common.URL; @Deprecated public interface Transporter extends org.apache.dubbo.remoting.Transporter { @Adaptive({Constants.SERVER_KEY, Constants.TRANSPORTER_KEY}) Server bind(URL url, ChannelHandler handler) throws RemotingException; @Override default RemotingServer bind(org.apache.dubbo.common.URL url, org.apache.dubbo.remoting.ChannelHandler handler) throws org.apache.dubbo.remoting.RemotingException { return bind(new DelegateURL(url), new ChannelHandler() { @Override public void connected(Channel channel) throws RemotingException { try { handler.connected(channel); } catch (org.apache.dubbo.remoting.RemotingException e) { throw new RemotingException(e); } } @Override public void disconnected(Channel channel) throws RemotingException { try { handler.disconnected(channel); } catch (org.apache.dubbo.remoting.RemotingException e) { throw new RemotingException(e); } } @Override public void sent(Channel channel, Object message) throws RemotingException { try { handler.sent(channel, message); } catch (org.apache.dubbo.remoting.RemotingException e) { throw new RemotingException(e); } } @Override public void received(Channel channel, Object message) throws RemotingException { try { handler.received(channel, message); } catch (org.apache.dubbo.remoting.RemotingException e) { throw new RemotingException(e); } } @Override public void caught(Channel channel, Throwable exception) throws RemotingException { try { handler.caught(channel, exception); } catch (org.apache.dubbo.remoting.RemotingException e) { throw new RemotingException(e); } } }); } }
5,274
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/Codec2.java
/* * 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.dubbo.remoting; @Deprecated public interface Codec2 extends org.apache.dubbo.remoting.Codec2 {}
5,275
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/Channel.java
/* * 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.dubbo.remoting; @Deprecated public interface Channel extends org.apache.dubbo.remoting.Channel { @Override com.alibaba.dubbo.common.URL getUrl(); @Override com.alibaba.dubbo.remoting.ChannelHandler getChannelHandler(); }
5,276
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/RemotingException.java
/* * 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.dubbo.remoting; import org.apache.dubbo.remoting.Channel; import java.net.InetSocketAddress; @Deprecated public class RemotingException extends org.apache.dubbo.remoting.RemotingException { public RemotingException(Channel channel, String msg) { super(channel, msg); } public RemotingException(InetSocketAddress localAddress, InetSocketAddress remoteAddress, String message) { super(localAddress, remoteAddress, message); } public RemotingException(Channel channel, Throwable cause) { super(channel, cause); } public RemotingException(InetSocketAddress localAddress, InetSocketAddress remoteAddress, Throwable cause) { super(localAddress, remoteAddress, cause); } public RemotingException(Channel channel, String message, Throwable cause) { super(channel, message, cause); } public RemotingException( InetSocketAddress localAddress, InetSocketAddress remoteAddress, String message, Throwable cause) { super(localAddress, remoteAddress, message, cause); } public RemotingException(Exception e) { super(null, e.getMessage()); } }
5,277
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/Dispatcher.java
/* * 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.dubbo.remoting; import org.apache.dubbo.common.URL; import org.apache.dubbo.remoting.ChannelHandler; @Deprecated public interface Dispatcher extends org.apache.dubbo.remoting.Dispatcher { com.alibaba.dubbo.remoting.ChannelHandler dispatch( com.alibaba.dubbo.remoting.ChannelHandler handler, com.alibaba.dubbo.common.URL url); @Override default ChannelHandler dispatch(ChannelHandler handler, URL url) { return null; } }
5,278
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/Server.java
/* * 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.dubbo.remoting; import org.apache.dubbo.remoting.RemotingServer; @Deprecated public interface Server extends RemotingServer {}
5,279
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/ChannelHandler.java
/* * 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.dubbo.remoting; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.RemotingException; @Deprecated public interface ChannelHandler extends org.apache.dubbo.remoting.ChannelHandler { void connected(com.alibaba.dubbo.remoting.Channel channel) throws com.alibaba.dubbo.remoting.RemotingException; void disconnected(com.alibaba.dubbo.remoting.Channel channel) throws com.alibaba.dubbo.remoting.RemotingException; void sent(com.alibaba.dubbo.remoting.Channel channel, Object message) throws com.alibaba.dubbo.remoting.RemotingException; void received(com.alibaba.dubbo.remoting.Channel channel, Object message) throws com.alibaba.dubbo.remoting.RemotingException; void caught(com.alibaba.dubbo.remoting.Channel channel, Throwable exception) throws com.alibaba.dubbo.remoting.RemotingException; @Override default void connected(Channel channel) throws RemotingException {} @Override default void disconnected(Channel channel) throws RemotingException {} @Override default void sent(Channel channel, Object message) throws RemotingException {} @Override default void received(Channel channel, Object message) throws RemotingException {} @Override default void caught(Channel channel, Throwable exception) throws RemotingException {} }
5,280
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/Codec.java
/* * 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.dubbo.remoting; @Deprecated public interface Codec extends org.apache.dubbo.remoting.Codec {}
5,281
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/exchange/ResponseCallback.java
/* * 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.dubbo.remoting.exchange; /** * 2019-06-20 */ @Deprecated public interface ResponseCallback { /** * done. * * @param response */ void done(Object response); /** * caught exception. * * @param exception */ void caught(Throwable exception); }
5,282
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/exchange/ResponseFuture.java
/* * 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.dubbo.remoting.exchange; import com.alibaba.dubbo.remoting.RemotingException; /** * 2019-06-20 */ @Deprecated public interface ResponseFuture { /** * get result. * * @return result. */ Object get() throws RemotingException; /** * get result with the specified timeout. * * @param timeoutInMillis timeout. * @return result. */ Object get(int timeoutInMillis) throws RemotingException; /** * set callback. * * @param callback */ void setCallback(ResponseCallback callback); /** * check is done. * * @return done or not. */ boolean isDone(); }
5,283
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/exchange/Exchanger.java
/* * 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.dubbo.remoting.exchange; @Deprecated public interface Exchanger extends org.apache.dubbo.remoting.exchange.Exchanger {}
5,284
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/zookeeper/ZookeeperTransporter.java
/* * 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.dubbo.remoting.zookeeper; @Deprecated public interface ZookeeperTransporter extends org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter {}
5,285
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/http/HttpBinder.java
/* * 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.dubbo.remoting.http; @Deprecated public interface HttpBinder extends org.apache.dubbo.remoting.http.HttpBinder {}
5,286
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/telnet/TelnetHandler.java
/* * 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.dubbo.remoting.telnet; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.RemotingException; @Deprecated public interface TelnetHandler extends org.apache.dubbo.remoting.telnet.TelnetHandler { String telnet(com.alibaba.dubbo.remoting.Channel channel, String message) throws com.alibaba.dubbo.remoting.RemotingException; @Override default String telnet(Channel channel, String message) throws RemotingException { return null; } }
5,287
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/monitor/MonitorFactory.java
/* * 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.dubbo.monitor; import org.apache.dubbo.common.URL; import org.apache.dubbo.monitor.Monitor; @Deprecated public interface MonitorFactory extends org.apache.dubbo.monitor.MonitorFactory { com.alibaba.dubbo.monitor.Monitor getMonitor(com.alibaba.dubbo.common.URL url); @Override default Monitor getMonitor(URL url) { return this.getMonitor(new com.alibaba.dubbo.common.DelegateURL(url)); } }
5,288
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/monitor/Monitor.java
/* * 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.dubbo.monitor; import org.apache.dubbo.common.URL; import java.util.List; import java.util.stream.Collectors; @Deprecated public interface Monitor extends org.apache.dubbo.monitor.Monitor { @Override com.alibaba.dubbo.common.URL getUrl(); void collect(com.alibaba.dubbo.common.URL statistics); List<com.alibaba.dubbo.common.URL> lookup(com.alibaba.dubbo.common.URL query); @Override default void collect(URL statistics) { this.collect(new com.alibaba.dubbo.common.DelegateURL(statistics)); } @Override default List<URL> lookup(URL query) { return this.lookup(new com.alibaba.dubbo.common.DelegateURL(query)).stream() .map(url -> url.getOriginalURL()) .collect(Collectors.toList()); } }
5,289
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/cache/Cache.java
/* * 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.dubbo.cache; @Deprecated public interface Cache extends org.apache.dubbo.cache.Cache {}
5,290
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/cache/CacheFactory.java
/* * 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.dubbo.cache; import com.alibaba.dubbo.common.DelegateURL; import com.alibaba.dubbo.common.URL; import com.alibaba.dubbo.rpc.Invocation; @Deprecated public interface CacheFactory extends org.apache.dubbo.cache.CacheFactory { Cache getCache(URL url, Invocation invocation); default org.apache.dubbo.cache.Cache getCache( org.apache.dubbo.common.URL url, org.apache.dubbo.rpc.Invocation invocation) { return this.getCache(new DelegateURL(url), new Invocation.CompatibleInvocation(invocation)); } }
5,291
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/cache
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/cache/support/AbstractCacheFactory.java
/* * 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.dubbo.cache.support; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import com.alibaba.dubbo.cache.Cache; import com.alibaba.dubbo.cache.CacheFactory; import com.alibaba.dubbo.common.DelegateURL; import com.alibaba.dubbo.common.URL; import com.alibaba.dubbo.rpc.Invocation; import static org.apache.dubbo.common.constants.CommonConstants.METHOD_KEY; @Deprecated public abstract class AbstractCacheFactory implements CacheFactory { private final ConcurrentMap<String, Cache> caches = new ConcurrentHashMap<String, Cache>(); @Override public Cache getCache(URL url, Invocation invocation) { url = url.addParameter(METHOD_KEY, invocation.getMethodName()); String key = url.toFullString(); Cache cache = caches.get(key); if (cache == null) { caches.put(key, createCache(url)); cache = caches.get(key); } return cache; } protected abstract Cache createCache(URL url); @Override public org.apache.dubbo.cache.Cache getCache( org.apache.dubbo.common.URL url, org.apache.dubbo.rpc.Invocation invocation) { return getCache(new DelegateURL(url), new Invocation.CompatibleInvocation(invocation)); } }
5,292
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/config/ApplicationConfig.java
/* * 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.dubbo.config; @Deprecated public class ApplicationConfig extends org.apache.dubbo.config.ApplicationConfig { public ApplicationConfig() { super(); } public ApplicationConfig(String name) { super(name); } public void setRegistry(com.alibaba.dubbo.config.RegistryConfig registry) { super.setRegistry(registry); } public void setMonitor(com.alibaba.dubbo.config.MonitorConfig monitor) { super.setMonitor(monitor); } @Override public void setMonitor(String monitor) { setMonitor(new com.alibaba.dubbo.config.MonitorConfig(monitor)); } }
5,293
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/config/ServiceConfig.java
/* * 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.dubbo.config; import org.apache.dubbo.config.annotation.Service; import java.util.ArrayList; import java.util.List; @Deprecated public class ServiceConfig<T> extends org.apache.dubbo.config.ServiceConfig<T> { public ServiceConfig() {} public ServiceConfig(Service service) { super(service); } public void setProvider(com.alibaba.dubbo.config.ProviderConfig provider) { super.setProvider(provider); } public void setApplication(com.alibaba.dubbo.config.ApplicationConfig application) { super.setApplication(application); } public void setModule(com.alibaba.dubbo.config.ModuleConfig module) { super.setModule(module); } public void setRegistry(com.alibaba.dubbo.config.RegistryConfig registry) { super.setRegistry(registry); } public void addMethod(com.alibaba.dubbo.config.MethodConfig methodConfig) { super.addMethod(methodConfig); } public com.alibaba.dubbo.config.MonitorConfig getMonitor() { org.apache.dubbo.config.MonitorConfig monitorConfig = super.getMonitor(); if (monitorConfig == null) { return null; } if (monitorConfig instanceof com.alibaba.dubbo.config.MonitorConfig) { return (com.alibaba.dubbo.config.MonitorConfig) monitorConfig; } throw new IllegalArgumentException("Monitor has not been set with type com.alibaba.dubbo.config.MonitorConfig. " + "Found " + monitorConfig.getClass().getName() + " instead."); } public void setMonitor(com.alibaba.dubbo.config.MonitorConfig monitor) { super.setMonitor(monitor); } public void setProtocol(com.alibaba.dubbo.config.ProtocolConfig protocol) { super.setProtocol(protocol); } public void setMock(Boolean mock) { if (mock == null) { setMock((String) null); } else { setMock(String.valueOf(mock)); } } public void setProviders(List<ProviderConfig> providers) { setProtocols(convertProviderToProtocol(providers)); } private static List<ProtocolConfig> convertProviderToProtocol(List<ProviderConfig> providers) { if (providers == null || providers.isEmpty()) { return null; } List<ProtocolConfig> protocols = new ArrayList<ProtocolConfig>(providers.size()); for (ProviderConfig provider : providers) { protocols.add(convertProviderToProtocol(provider)); } return protocols; } private static ProtocolConfig convertProviderToProtocol(ProviderConfig provider) { ProtocolConfig protocol = new ProtocolConfig(); protocol.setName(provider.getProtocol().getName()); protocol.setServer(provider.getServer()); protocol.setClient(provider.getClient()); protocol.setCodec(provider.getCodec()); protocol.setHost(provider.getHost()); protocol.setPort(provider.getPort()); protocol.setPath(provider.getPath()); protocol.setPayload(provider.getPayload()); protocol.setThreads(provider.getThreads()); protocol.setParameters(provider.getParameters()); return protocol; } private static ProviderConfig convertProtocolToProvider(ProtocolConfig protocol) { ProviderConfig provider = new ProviderConfig(); provider.setProtocol(protocol); provider.setServer(protocol.getServer()); provider.setClient(protocol.getClient()); provider.setCodec(protocol.getCodec()); provider.setHost(protocol.getHost()); provider.setPort(protocol.getPort()); provider.setPath(protocol.getPath()); provider.setPayload(protocol.getPayload()); provider.setThreads(protocol.getThreads()); provider.setParameters(protocol.getParameters()); return provider; } }
5,294
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/config/RegistryConfig.java
/* * 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.dubbo.config; @Deprecated public class RegistryConfig extends org.apache.dubbo.config.RegistryConfig { public RegistryConfig() {} public RegistryConfig(String address) { super(address); } public RegistryConfig(String address, String protocol) { super(address, protocol); } }
5,295
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/config/ModuleConfig.java
/* * 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.dubbo.config; @Deprecated public class ModuleConfig extends org.apache.dubbo.config.ModuleConfig { public ModuleConfig() {} public ModuleConfig(String name) { super(name); } public void setRegistry(com.alibaba.dubbo.config.RegistryConfig registry) { super.setRegistry(registry); } public void setMonitor(com.alibaba.dubbo.config.MonitorConfig monitor) { super.setMonitor(monitor); } @Override public void setMonitor(String monitor) { setMonitor(new com.alibaba.dubbo.config.MonitorConfig(monitor)); } }
5,296
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/config/ProviderConfig.java
/* * 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.dubbo.config; @Deprecated public class ProviderConfig extends org.apache.dubbo.config.ProviderConfig { public void setApplication(com.alibaba.dubbo.config.ApplicationConfig application) { super.setApplication(application); } public void setModule(com.alibaba.dubbo.config.ModuleConfig module) { super.setModule(module); } public void setRegistry(com.alibaba.dubbo.config.RegistryConfig registry) { super.setRegistry(registry); } public void addMethod(com.alibaba.dubbo.config.MethodConfig methodConfig) { super.addMethod(methodConfig); } public void setMonitor(com.alibaba.dubbo.config.MonitorConfig monitor) { super.setMonitor(monitor); } public void setProtocol(com.alibaba.dubbo.config.ProtocolConfig protocol) { super.setProtocol(protocol); } @Override public void setProtocol(String protocol) { setProtocol(new com.alibaba.dubbo.config.ProtocolConfig(protocol)); } public void setMock(Boolean mock) { if (mock == null) { setMock((String) null); } else { setMock(String.valueOf(mock)); } } }
5,297
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/config/MonitorConfig.java
/* * 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.dubbo.config; @Deprecated public class MonitorConfig extends org.apache.dubbo.config.MonitorConfig { public MonitorConfig() {} public MonitorConfig(String address) { super(address); } }
5,298
0
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo
Create_ds/dubbo/dubbo-compatible/src/main/java/com/alibaba/dubbo/config/ReferenceConfig.java
/* * 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.dubbo.config; import org.apache.dubbo.config.annotation.Reference; @Deprecated public class ReferenceConfig<T> extends org.apache.dubbo.config.ReferenceConfig<T> { public ReferenceConfig() {} public ReferenceConfig(Reference reference) { super(reference); } public void setConsumer(com.alibaba.dubbo.config.ConsumerConfig consumer) { super.setConsumer(consumer); } public void setApplication(com.alibaba.dubbo.config.ApplicationConfig application) { super.setApplication(application); } public void setModule(com.alibaba.dubbo.config.ModuleConfig module) { super.setModule(module); } public void setRegistry(com.alibaba.dubbo.config.RegistryConfig registry) { super.setRegistry(registry); } public void addMethod(com.alibaba.dubbo.config.MethodConfig methodConfig) { super.addMethod(methodConfig); } public void setMonitor(com.alibaba.dubbo.config.MonitorConfig monitor) { super.setMonitor(monitor); } public void setMock(Boolean mock) { if (mock == null) { setMock((String) null); } else { setMock(String.valueOf(mock)); } } public void setInterfaceClass(Class<?> interfaceClass) { setInterface(interfaceClass); } }
5,299