use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class SoapExtensionWithCustomTransportsDeclarationTestCase method assertSoapExtensionModel.
@Test
public void assertSoapExtensionModel() {
Map<String, Object> params = new HashMap<>();
params.put(TYPE_PROPERTY_NAME, RickAndMortyExtension.class.getName());
params.put(VERSION, getProductVersion());
ExtensionModel model = loader.loadExtensionModel(RickAndMortyExtension.class.getClassLoader(), getDefault(emptySet()), params);
assertThat(model.getConfigurationModels(), hasSize(1));
ConfigurationModel configuration = model.getConfigurationModels().get(0);
assertThat(configuration.getName(), is(DEFAULT_CONFIG_NAME));
assertThat(configuration.getDescription(), is(DEFAULT_CONFIG_DESCRIPTION));
assertThat(configuration.getOperationModels(), hasSize(1));
assertSubtypes(model);
List<ConnectionProviderModel> providers = configuration.getConnectionProviders();
assertThat(providers, hasSize(1));
assertConnectionProvider(providers.get(0), "rick-and-morty-connection", "", true, new ParameterProber("wsdlUrl", StringType.class), new ParameterProber("port", StringType.class), new ParameterProber("service", StringType.class), new ParameterProber("transport", ObjectType.class));
}
use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class AbstractComponentDefinitionParser method doParse.
@Override
protected Builder doParse(Builder definitionBuilder) throws ConfigurationException {
Builder finalBuilder = definitionBuilder.withIdentifier(operationDsl.getElementName()).withTypeDefinition(fromType(getMessageProcessorType())).withObjectFactoryType(getMessageProcessorFactoryType()).withConstructorParameterDefinition(fromFixedValue(extensionModel).build()).withConstructorParameterDefinition(fromFixedValue(componentModel).build()).withConstructorParameterDefinition(fromReferenceObject(MuleContext.class).build()).withConstructorParameterDefinition(fromReferenceObject(Registry.class).build()).withConstructorParameterDefinition(fromReferenceObject(PolicyManager.class).build()).withSetterParameterDefinition(TARGET_PARAMETER_NAME, fromSimpleParameter(TARGET_PARAMETER_NAME).build()).withSetterParameterDefinition(TARGET_VALUE_PARAMETER_NAME, fromSimpleParameter(TARGET_VALUE_PARAMETER_NAME).build()).withSetterParameterDefinition(CONFIG_PROVIDER_ATTRIBUTE_NAME, fromSimpleReferenceParameter(CONFIG_ATTRIBUTE_NAME).build()).withSetterParameterDefinition(CURSOR_PROVIDER_FACTORY_FIELD_NAME, fromChildConfiguration(CursorProviderFactory.class).build()).withSetterParameterDefinition("retryPolicyTemplate", fromChildConfiguration(RetryPolicyTemplate.class).build());
Optional<? extends NestableElementModel> nestedChain = componentModel.getNestedComponents().stream().filter(c -> c instanceof NestedChainModel).findFirst();
if (nestedChain.isPresent()) {
// TODO MULE-13483: improve parsers to support things like [source, chainOfProcessors, errorHandler]
// or [chainOfProcessors, errorHandler]
finalBuilder = finalBuilder.withSetterParameterDefinition("nestedProcessors", fromChildCollectionConfiguration(Processor.class).build());
parseParameters(componentModel.getAllParameterModels());
} else {
List<ParameterGroupModel> inlineGroups = getInlineGroups(componentModel);
parseParameters(getFlatParameters(inlineGroups, componentModel.getAllParameterModels()));
for (ParameterGroupModel group : inlineGroups) {
parseInlineParameterGroup(group);
}
// TODO MULE-13483
parseNestedComponents(componentModel.getNestedComponents());
}
return finalBuilder;
}
use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class AbstractXmlResourceFactory method generateResource.
@Override
public Optional<GeneratedResource> generateResource(ExtensionModel extensionModel) {
Set<ImportedTypeModel> importedTypes = extensionModel.getImportedTypes();
DslResolvingContext dslContext = importedTypes.isEmpty() ? new NullDslResolvingContext() : new ClasspathBasedDslContext(extensionModel.getModelProperty(ImplementingTypeModelProperty.class).map(mp -> mp.getType().getClassLoader()).orElse(Thread.currentThread().getContextClassLoader()));
return generateResource(extensionModel, dslContext);
}
use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class DefaultExtensionSchemaGeneratorTestCase method data.
@Parameterized.Parameters(name = "{1}")
public static Collection<Object[]> data() {
final ClassLoader classLoader = DefaultExtensionSchemaGeneratorTestCase.class.getClassLoader();
final ServiceRegistry serviceRegistry = mock(ServiceRegistry.class);
when(serviceRegistry.lookupProviders(DeclarationEnricher.class, classLoader)).thenReturn(asList(new JavaXmlDeclarationEnricher()));
final List<SchemaGeneratorTestUnit> extensions;
extensions = asList(newTestUnit(javaLoader, MapConnector.class, "map.xsd"), newTestUnit(javaLoader, ListConnector.class, "list.xsd"), newTestUnit(javaLoader, TestConnector.class, "basic.xsd"), newTestUnit(javaLoader, StringListConnector.class, "string-list.xsd"), newTestUnit(javaLoader, GlobalPojoConnector.class, "global-pojo.xsd"), newTestUnit(javaLoader, GlobalInnerPojoConnector.class, "global-inner-pojo.xsd"), newTestUnit(javaLoader, VeganExtension.class, "vegan.xsd"), newTestUnit(javaLoader, PetStoreConnector.class, "petstore.xsd"), newTestUnit(javaLoader, MetadataExtension.class, "metadata.xsd"), newTestUnit(javaLoader, HeisenbergExtension.class, "heisenberg.xsd"), newTestUnit(javaLoader, SubstitutionGroupExtension.class, "substitutiongroup.xsd"), newTestUnit(javaLoader, TransactionalExtension.class, "tx-ext.xsd"), newTestUnit(javaLoader, SubTypesMappingConnector.class, "subtypes.xsd"), newTestUnit(javaLoader, MarvelExtension.class, "marvel.xsd"), newTestUnit(soapLoader, FootballSoapExtension.class, "soap.xsd"), newTestUnit(soapLoader, RickAndMortyExtension.class, "ram.xsd"), newTestUnit(javaLoader, TypedValueExtension.class, "typed-value.xsd"), newTestUnit(javaLoader, TestOAuthExtension.class, "test-oauth.xsd"), newTestUnit(javaLoader, WeaveFunctionExtension.class, "test-fn.xsd"), newTestUnit(javaLoader, ValuesExtension.class, "values.xsd"), newTestUnit(javaLoader, ReconnectionExtension.class, "reconnection-extension.xsd"));
BiFunction<Class<?>, ExtensionModelLoader, ExtensionModel> createExtensionModel = (extension, loader) -> {
ExtensionModel model = loadExtension(extension, loader);
if (extensionModels.put(model.getName(), model) != null) {
throw new IllegalArgumentException(format("Extension names must be unique. Name [%s] for extension [%s] was already used", model.getName(), extension.getName()));
}
return model;
};
return extensions.stream().map(e -> new Object[] { createExtensionModel.apply(e.getExtensionClass(), e.getLoader()), e.getFileName() }).collect(toList());
}
use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class ExtensionResourcesGeneratorAnnotationProcessorTestCase method generateDocumentedSchema.
@Test
public void generateDocumentedSchema() throws Exception {
ArgumentCaptor<ByteSource> byteSourceCaptor = ArgumentCaptor.forClass(ByteSource.class);
ByteSource byteSource = mock(ByteSource.class);
when(byteSource.contentEquals(byteSourceCaptor.capture())).thenReturn(true);
DefaultJavaExtensionModelLoader loader = new DefaultJavaExtensionModelLoader();
ExtensionModel model = loader.loadExtensionModel(TestExtensionWithDocumentationAndMultipleConfig.class.getClassLoader(), DslResolvingContext.getDefault(emptySet()), ImmutableMap.<String, Object>builder().put(TYPE_PROPERTY_NAME, TestExtensionWithDocumentationAndMultipleConfig.class.getName()).put(VERSION, "4.0.0").build());
String generatedSchema = new DefaultExtensionSchemaGenerator().generate(model, DslResolvingContext.getDefault(emptySet()));
assertThat(generatedSchema, is(notNullValue()));
assertXpath(generatedSchema, "//xs:attribute[@name='configParameter']/xs:annotation/xs:documentation", "Config parameter");
assertXpath(generatedSchema, "//xs:attribute[@name='configParameterWithComplexJavadoc']/xs:annotation/xs:documentation", "Config Parameter with an Optional value");
assertXpath(generatedSchema, "//xs:attribute[@name='value1']/xs:annotation/xs:documentation", GROUP_PARAMETER_1);
assertXpath(generatedSchema, "//xs:attribute[@name='value2']/xs:annotation/xs:documentation", GROUP_PARAMETER_2);
assertXpath(generatedSchema, "//xs:element[@name='operation']/xs:annotation/xs:documentation", "Test Operation");
assertXpath(generatedSchema, "//xs:complexType[@name='OperationType']/xs:complexContent/xs:extension/xs:attribute[@name='value']/xs:annotation/xs:documentation", "test value");
assertXpath(generatedSchema, "//xs:complexType[@name='OperationType']/xs:complexContent/xs:extension/xs:attribute[@name='value1']/xs:annotation/xs:documentation", GROUP_PARAMETER_1);
assertXpath(generatedSchema, "//xs:complexType[@name='OperationType']/xs:complexContent/xs:extension/xs:attribute[@name='value2']/xs:annotation/xs:documentation", GROUP_PARAMETER_2);
assertXpath(generatedSchema, "//xs:element[@name='ignore-operation-should-be-ignored']/xs:annotation/xs:documentation", "");
assertXpath(generatedSchema, "//xs:element[@name='private-operation-should-be-ignored']/xs:annotation/xs:documentation", "");
assertXpath(generatedSchema, "//xs:element[@name='operation-with-blank-parameter-description']/xs:annotation/xs:documentation", "Test Operation with blank parameter description");
assertXpath(generatedSchema, "//xs:complexType[@name='OperationWithBlankParameterDescriptionType']/xs:complexContent/xs:extension/xs:attribute[@name='value']/xs:annotation/xs:documentation", "");
assertXpath(generatedSchema, "//xs:element[@name='operation-with-javadoc-link-references']/xs:annotation/xs:documentation", "Operation that returns a String value");
assertXpath(generatedSchema, "//xs:complexType[@name='OperationWithJavadocLinkReferencesType']/xs:complexContent/xs:extension/xs:attribute[@name='value']/xs:annotation/xs:documentation", "this is the String to be returned");
}
Aggregations