Search in sources :

Example 11 with MethodDefinition

use of org.apache.dubbo.metadata.definition.model.MethodDefinition in project incubator-dubbo-ops by apache.

the class ConsulMetaDataCollectorTest method testGetProviderMetaData.

@Test
public void testGetProviderMetaData() {
    MetadataIdentifier identifier = buildIdentifier(true);
    Map<String, String> params = new HashMap<>();
    params.put("key1", "value1");
    params.put("key2", "true");
    FullServiceDefinition definition = ServiceDefinitionBuilder.buildFullDefinition(ServiceA.class, params);
    String metadata = gson.toJson(definition);
    consulMetaDataCollector.getClient().setKVValue(identifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), metadata);
    String providerMetaData = consulMetaDataCollector.getProviderMetaData(identifier);
    Assert.assertEquals(metadata, providerMetaData);
    FullServiceDefinition retDef = gson.fromJson(providerMetaData, FullServiceDefinition.class);
    Assert.assertEquals(ServiceA.class.getCanonicalName(), retDef.getCanonicalName());
    Assert.assertEquals(ClassUtils.getCodeSource(ServiceA.class), retDef.getCodeSource());
    Assert.assertEquals(params, retDef.getParameters());
    // method def assertions
    Assert.assertNotNull(retDef.getMethods());
    Assert.assertEquals(3, retDef.getMethods().size());
    List<String> methodNames = retDef.getMethods().stream().map(MethodDefinition::getName).sorted().collect(Collectors.toList());
    Assert.assertEquals("method1", methodNames.get(0));
    Assert.assertEquals("method2", methodNames.get(1));
    Assert.assertEquals("method3", methodNames.get(2));
}
Also used : MetadataIdentifier(org.apache.dubbo.metadata.report.identifier.MetadataIdentifier) HashMap(java.util.HashMap) FullServiceDefinition(org.apache.dubbo.metadata.definition.model.FullServiceDefinition) MethodDefinition(org.apache.dubbo.metadata.definition.model.MethodDefinition) Test(org.junit.Test)

Aggregations

MethodDefinition (org.apache.dubbo.metadata.definition.model.MethodDefinition)11 TypeDefinition (org.apache.dubbo.metadata.definition.model.TypeDefinition)5 FullServiceDefinition (org.apache.dubbo.metadata.definition.model.FullServiceDefinition)4 Type (java.lang.reflect.Type)3 Method (java.lang.reflect.Method)2 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 MetadataIdentifier (org.apache.dubbo.metadata.report.identifier.MetadataIdentifier)2 Test (org.junit.jupiter.api.Test)2 Gson (com.google.gson.Gson)1 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 MethodMetadata (org.apache.dubbo.admin.model.domain.MethodMetadata)1 URL (org.apache.dubbo.common.URL)1 ServiceDefinition (org.apache.dubbo.metadata.definition.model.ServiceDefinition)1 ComplexObject (org.apache.dubbo.metadata.definition.service.ComplexObject)1 RequestMetadata (org.apache.dubbo.metadata.rest.RequestMetadata)1 RestMethodMetadata (org.apache.dubbo.metadata.rest.RestMethodMetadata)1