Search in sources :

Example 16 with FullServiceDefinition

use of org.apache.dubbo.metadata.definition.model.FullServiceDefinition 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

FullServiceDefinition (org.apache.dubbo.metadata.definition.model.FullServiceDefinition)16 MetadataIdentifier (org.apache.dubbo.metadata.report.identifier.MetadataIdentifier)11 Gson (com.google.gson.Gson)5 SubscriberMetadataIdentifier (org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier)5 Test (org.junit.jupiter.api.Test)5 URL (org.apache.dubbo.common.URL)4 MethodDefinition (org.apache.dubbo.metadata.definition.model.MethodDefinition)4 ServiceMetadataIdentifier (org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Consumer (org.apache.dubbo.admin.model.domain.Consumer)2 Provider (org.apache.dubbo.admin.model.domain.Provider)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JsonParseException (com.google.gson.JsonParseException)1 GetResponse (io.etcd.jetcd.kv.GetResponse)1 VersionValidationException (org.apache.dubbo.admin.common.exception.VersionValidationException)1 MethodMetadata (org.apache.dubbo.admin.model.domain.MethodMetadata)1 ServiceDetailDTO (org.apache.dubbo.admin.model.dto.ServiceDetailDTO)1 TypeDefinition (org.apache.dubbo.metadata.definition.model.TypeDefinition)1 MetadataReport (org.apache.dubbo.metadata.report.MetadataReport)1