Search in sources :

Example 6 with MetadataKey

use of org.mule.runtime.api.metadata.MetadataKey in project mule by mulesoft.

the class MetadataOperationTestCase method shouldInheritExtensionResolvers.

@Test
@Ignore("MULE-14190: Revamp MetadataScope annotation")
public void shouldInheritExtensionResolvers() throws Exception {
    location = Location.builder().globalName(SHOULD_INHERIT_EXTENSION_RESOLVERS).addProcessorsPart().addIndexPart(0).build();
    final MetadataResult<MetadataKeysContainer> metadataKeysResult = metadataService.getMetadataKeys(location);
    assertSuccessResult(metadataKeysResult);
    final Set<MetadataKey> metadataKeys = getKeysFromContainer(metadataKeysResult.get());
    assertThat(metadataKeys.size(), is(1));
    assertThat(metadataKeys, hasItems(metadataKeyWithId("APPLE")));
    final ComponentMetadataDescriptor<OperationModel> metadataDescriptor = getSuccessComponentDynamicMetadataWithKey(newKey("APPLE").build());
    final OperationModel typedModel = metadataDescriptor.getModel();
    assertExpectedOutput(typedModel, typeLoader.load(Apple.class), void.class);
}
Also used : MetadataKeysContainer(org.mule.runtime.api.metadata.MetadataKeysContainer) Apple(org.mule.tck.testmodels.fruit.Apple) MetadataKey(org.mule.runtime.api.metadata.MetadataKey) NullMetadataKey(org.mule.runtime.extension.api.metadata.NullMetadataKey) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with MetadataKey

use of org.mule.runtime.api.metadata.MetadataKey in project mule by mulesoft.

the class QueryMetadataTestCase method getNativeQueryOutputMetadata.

@Test
public void getNativeQueryOutputMetadata() throws Exception {
    location = builder().globalName(NATIVE_QUERY_FLOW).addProcessorsPart().addIndexPart(0).build();
    MetadataKey nativeKey = newKey(NATIVE_QUERY).build();
    MetadataResult<ComponentMetadataDescriptor<OperationModel>> entityMetadata = getComponentDynamicMetadata(nativeKey);
    assertThat(entityMetadata.isSuccess(), is(true));
    MetadataType generatedType = entityMetadata.get().getModel().getOutput().getType();
    assertCircleType((ObjectType) generatedType);
}
Also used : ExtensionsTestUtils.toMetadataType(org.mule.test.module.extension.internal.util.ExtensionsTestUtils.toMetadataType) MetadataType(org.mule.metadata.api.model.MetadataType) MetadataKey(org.mule.runtime.api.metadata.MetadataKey) ComponentMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.ComponentMetadataDescriptor) Test(org.junit.Test)

Example 8 with MetadataKey

use of org.mule.runtime.api.metadata.MetadataKey in project mule by mulesoft.

the class QueryMetadataTestCase method getDsqlQueryAutomaticGeneratedOutputMetadata.

@Test
public void getDsqlQueryAutomaticGeneratedOutputMetadata() throws Exception {
    location = QUERY_LOCATION;
    MetadataKey dsqlKey = newKey(DSQL_QUERY).build();
    MetadataResult<ComponentMetadataDescriptor<OperationModel>> entityMetadata = getComponentDynamicMetadata(dsqlKey);
    assertThat(entityMetadata.isSuccess(), is(true));
    MetadataType generatedType = entityMetadata.get().getModel().getOutput().getType();
    assertThat(generatedType, is(instanceOf(ArrayType.class)));
    assertCircleType((ObjectType) ((ArrayType) generatedType).getType());
}
Also used : ArrayType(org.mule.metadata.api.model.ArrayType) ExtensionsTestUtils.toMetadataType(org.mule.test.module.extension.internal.util.ExtensionsTestUtils.toMetadataType) MetadataType(org.mule.metadata.api.model.MetadataType) MetadataKey(org.mule.runtime.api.metadata.MetadataKey) ComponentMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.ComponentMetadataDescriptor) Test(org.junit.Test)

Example 9 with MetadataKey

use of org.mule.runtime.api.metadata.MetadataKey in project mule by mulesoft.

the class MetadataExtensionFunctionalTestCase method getSuccessComponentDynamicMetadata.

private ComponentMetadataDescriptor<T> getSuccessComponentDynamicMetadata(MetadataKey key, BiConsumer<MetadataResult<ComponentMetadataDescriptor<T>>, MetadataKey> assertKeys) {
    MetadataResult<ComponentMetadataDescriptor<T>> componentMetadata = getComponentDynamicMetadata(key);
    String msg = componentMetadata.getFailures().stream().map(f -> "Failure: " + f.getMessage()).collect(joining(", "));
    assertThat(msg, componentMetadata.isSuccess(), is(true));
    assertKeys.accept(componentMetadata, key);
    return componentMetadata.get();
}
Also used : Arrays(java.util.Arrays) DSL_RESOLUTION(org.mule.test.module.extension.metadata.MetadataExtensionFunctionalTestCase.ResolutionType.DSL_RESOLUTION) PERSON(org.mule.test.metadata.extension.MetadataConnection.PERSON) Assert.assertThat(org.junit.Assert.assertThat) MetadataKey(org.mule.runtime.api.metadata.MetadataKey) ExtensionsTestUtils(org.mule.test.module.extension.internal.util.ExtensionsTestUtils) Is.is(org.hamcrest.core.Is.is) ComponentMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.ComponentMetadataDescriptor) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) MetadataService(org.mule.runtime.api.metadata.MetadataService) Parameterized(org.junit.runners.Parameterized) NullMetadataKey(org.mule.runtime.extension.api.metadata.NullMetadataKey) ConnectableComponentModel(org.mule.runtime.api.meta.model.ConnectableComponentModel) Collection(java.util.Collection) Set(java.util.Set) SAN_FRANCISCO(org.mule.test.metadata.extension.resolver.TestMultiLevelKeyResolver.SAN_FRANCISCO) Message.of(org.mule.runtime.api.message.Message.of) Collectors.joining(java.util.stream.Collectors.joining) USA(org.mule.test.metadata.extension.resolver.TestMultiLevelKeyResolver.USA) METADATA_SERVICE_KEY(org.mule.runtime.api.metadata.MetadataService.METADATA_SERVICE_KEY) MetadataComponent(org.mule.runtime.api.metadata.resolving.MetadataComponent) TestMetadataResolverUtils.getMetadata(org.mule.test.metadata.extension.resolver.TestMetadataResolverUtils.getMetadata) Type(java.lang.reflect.Type) EXPLICIT_RESOLUTION(org.mule.test.module.extension.metadata.MetadataExtensionFunctionalTestCase.ResolutionType.EXPLICIT_RESOLUTION) OutputModel(org.mule.runtime.api.meta.model.OutputModel) MetadataType(org.mule.metadata.api.model.MetadataType) Matchers.containsString(org.hamcrest.Matchers.containsString) MetadataResult(org.mule.runtime.api.metadata.resolving.MetadataResult) AbstractExtensionFunctionalTestCase(org.mule.test.module.extension.AbstractExtensionFunctionalTestCase) AMERICA(org.mule.test.metadata.extension.resolver.TestMultiLevelKeyResolver.AMERICA) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) ExtensionsTypeLoaderFactory(org.mule.runtime.extension.api.declaration.type.ExtensionsTypeLoaderFactory) JAVA(org.mule.metadata.api.model.MetadataFormat.JAVA) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) MultilevelMetadataKeyBuilder(org.mule.runtime.module.extension.api.metadata.MultilevelMetadataKeyBuilder) Location(org.mule.runtime.api.component.location.Location) BaseTypeBuilder(org.mule.metadata.api.builder.BaseTypeBuilder) Inject(javax.inject.Inject) RunnerDelegateTo(org.mule.test.runner.RunnerDelegateTo) BiConsumer(java.util.function.BiConsumer) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MetadataKeyBuilder.newKey(org.mule.runtime.api.metadata.MetadataKeyBuilder.newKey) Named(javax.inject.Named) Before(org.junit.Before) Typed(org.mule.runtime.api.meta.Typed) FailureCode(org.mule.runtime.api.metadata.resolving.FailureCode) Matchers.empty(org.hamcrest.Matchers.empty) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) CAR(org.mule.test.metadata.extension.MetadataConnection.CAR) MetadataKeysContainer(org.mule.runtime.api.metadata.MetadataKeysContainer) MetadataFailure(org.mule.runtime.api.metadata.resolving.MetadataFailure) Matchers.containsString(org.hamcrest.Matchers.containsString) ComponentMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.ComponentMetadataDescriptor)

Example 10 with MetadataKey

use of org.mule.runtime.api.metadata.MetadataKey in project mule by mulesoft.

the class MetadataKeysDelegate method getMetadataKeys.

MetadataResult<MetadataKeysContainer> getMetadataKeys(MetadataContext context, Object partialKey, ReflectionCache reflectionCache) {
    final TypeKeysResolver keyResolver = resolverFactory.getKeyResolver();
    final String componentResolverName = keyResolver.getCategoryName();
    final MetadataKeysContainerBuilder keysContainer = MetadataKeysContainerBuilder.getInstance();
    if (keyParts.isEmpty()) {
        return success(keysContainer.add(componentResolverName, ImmutableSet.of(new NullMetadataKey())).build());
    }
    try {
        final Map<Integer, ParameterModel> partsByOrder = getPartOrderMapping(keyParts);
        Set<MetadataKey> metadataKeys;
        if (keyResolver instanceof PartialTypeKeysResolver && hasInitialLevel(partialKey, partsByOrder, reflectionCache)) {
            metadataKeys = singleton(((PartialTypeKeysResolver) keyResolver).resolveChilds(context, partialKey));
        } else {
            metadataKeys = keyResolver.getKeys(context);
        }
        final Set<MetadataKey> enrichedMetadataKeys = metadataKeys.stream().map(metadataKey -> cloneAndEnrichMetadataKey(metadataKey, partsByOrder)).map(MetadataKeyBuilder::build).collect(toSet());
        keysContainer.add(componentResolverName, enrichedMetadataKeys);
        return success(keysContainer.build());
    } catch (Exception e) {
        return failure(newFailure(e).onKeys());
    }
}
Also used : ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) NullMetadataKey(org.mule.runtime.extension.api.metadata.NullMetadataKey) MetadataKeysContainerBuilder(org.mule.runtime.api.metadata.MetadataKeysContainerBuilder) PartialTypeKeysResolver(org.mule.runtime.api.metadata.resolving.PartialTypeKeysResolver) TypeKeysResolver(org.mule.runtime.api.metadata.resolving.TypeKeysResolver) MetadataKey(org.mule.runtime.api.metadata.MetadataKey) NullMetadataKey(org.mule.runtime.extension.api.metadata.NullMetadataKey) PartialTypeKeysResolver(org.mule.runtime.api.metadata.resolving.PartialTypeKeysResolver)

Aggregations

MetadataKey (org.mule.runtime.api.metadata.MetadataKey)19 Test (org.junit.Test)13 ComponentMetadataDescriptor (org.mule.runtime.api.metadata.descriptor.ComponentMetadataDescriptor)9 NullMetadataKey (org.mule.runtime.extension.api.metadata.NullMetadataKey)7 MetadataType (org.mule.metadata.api.model.MetadataType)5 MetadataKeysContainer (org.mule.runtime.api.metadata.MetadataKeysContainer)4 MetadataResolvingException (org.mule.runtime.api.metadata.MetadataResolvingException)3 ExtensionsTestUtils.toMetadataType (org.mule.test.module.extension.internal.util.ExtensionsTestUtils.toMetadataType)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Set (java.util.Set)2 ArrayType (org.mule.metadata.api.model.ArrayType)2 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)2 TypeKeysResolver (org.mule.runtime.api.metadata.resolving.TypeKeysResolver)2 Type (java.lang.reflect.Type)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 BiConsumer (java.util.function.BiConsumer)1 Collectors.joining (java.util.stream.Collectors.joining)1 Inject (javax.inject.Inject)1