Search in sources :

Example 41 with ExtensionModel

use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.

the class ExtensionsTestInfrastructureDiscoverer method generateDslResources.

public List<GeneratedResource> generateDslResources(File generatedResourcesDirectory, ExtensionModel forExtensionModel) {
    DslResolvingContext context;
    if (extensionManager.getExtensions().stream().anyMatch(e -> !e.getImportedTypes().isEmpty())) {
        HashSet<ExtensionModel> models = new HashSet<>(extensionManager.getExtensions());
        models.add(MuleExtensionModelProvider.getExtensionModel());
        context = DslResolvingContext.getDefault(models);
    } else {
        context = new NullDslResolvingContext();
    }
    ExtensionsTestDslResourcesGenerator dslResourceGenerator = new ExtensionsTestDslResourcesGenerator(getDslResourceFactories(), generatedResourcesDirectory, context);
    extensionManager.getExtensions().stream().filter(runtimeExtensionModel -> forExtensionModel != null ? runtimeExtensionModel.equals(forExtensionModel) : true).forEach(dslResourceGenerator::generateFor);
    return dslResourceGenerator.dumpAll();
}
Also used : Manifest(java.util.jar.Manifest) MuleManifest.getProductVersion(org.mule.runtime.core.api.config.MuleManifest.getProductVersion) GeneratedResource(org.mule.runtime.extension.api.resources.GeneratedResource) HashMap(java.util.HashMap) Thread.currentThread(java.lang.Thread.currentThread) MuleManifest(org.mule.runtime.core.api.config.MuleManifest) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) GeneratedResourceFactory(org.mule.runtime.extension.api.resources.spi.GeneratedResourceFactory) HashSet(java.util.HashSet) Collections.singleton(java.util.Collections.singleton) ByteArrayInputStream(java.io.ByteArrayInputStream) TYPE_PROPERTY_NAME(org.mule.runtime.module.extension.api.loader.java.DefaultJavaExtensionModelLoader.TYPE_PROPERTY_NAME) Map(java.util.Map) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) ServiceRegistry(org.mule.runtime.core.api.registry.ServiceRegistry) ExtensionModelLoader(org.mule.runtime.extension.api.loader.ExtensionModelLoader) NullDslResolvingContext(org.mule.runtime.internal.dsl.NullDslResolvingContext) FileOutputStream(java.io.FileOutputStream) Set(java.util.Set) IOException(java.io.IOException) ImmutableList.copyOf(com.google.common.collect.ImmutableList.copyOf) String.format(java.lang.String.format) File(java.io.File) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) List(java.util.List) ExtensionManager(org.mule.runtime.core.api.extension.ExtensionManager) VERSION(org.mule.runtime.module.extension.api.loader.java.DefaultJavaExtensionModelLoader.VERSION) ExtensionSchemaGenerator(org.mule.runtime.extension.api.dsl.syntax.resources.spi.ExtensionSchemaGenerator) FileUtils(org.mule.runtime.core.api.util.FileUtils) DslResourceFactory(org.mule.runtime.extension.api.dsl.syntax.resources.spi.DslResourceFactory) ResourcesGenerator(org.mule.runtime.extension.api.resources.ResourcesGenerator) MuleExtensionModelProvider(org.mule.runtime.core.api.extension.MuleExtensionModelProvider) DslResolvingContext.getDefault(org.mule.runtime.api.dsl.DslResolvingContext.getDefault) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) NullDslResolvingContext(org.mule.runtime.internal.dsl.NullDslResolvingContext) NullDslResolvingContext(org.mule.runtime.internal.dsl.NullDslResolvingContext) HashSet(java.util.HashSet)

Example 42 with ExtensionModel

use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.

the class ExtensionsTestInfrastructureDiscoverer method generateSchemaTestResource.

public void generateSchemaTestResource(ExtensionModel model, File generatedResourcesDirectory) {
    String xsdFileName = model.getXmlDslModel().getXsdFileName();
    try {
        ExtensionSchemaGenerator schemaGenerator = getSchemaGenerator();
        Set<ExtensionModel> models = new HashSet<>(extensionManager.getExtensions());
        models.add(MuleExtensionModelProvider.getExtensionModel());
        String schema = schemaGenerator.generate(model, DslResolvingContext.getDefault(models));
        File xsd = FileUtils.newFile(generatedResourcesDirectory, xsdFileName);
        FileUtils.copyStreamToFile(new ByteArrayInputStream(schema.getBytes()), xsd);
    } catch (IOException e) {
        throw new RuntimeException(format("Error generating test xsd resource [%s]: " + e.getMessage(), xsdFileName, e));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ExtensionSchemaGenerator(org.mule.runtime.extension.api.dsl.syntax.resources.spi.ExtensionSchemaGenerator) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) IOException(java.io.IOException) File(java.io.File) HashSet(java.util.HashSet)

Example 43 with ExtensionModel

use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.

the class CompositeArtifactExtensionManagerTestCase method returnsChildConfigurationProviderFromProviderName.

@Test
public void returnsChildConfigurationProviderFromProviderName() throws Exception {
    ExtensionModel childExtension = mock(ExtensionModel.class);
    Set<ExtensionModel> childExtensions = singleton(childExtension);
    when(childExtensionManager.getExtensions()).thenReturn(childExtensions);
    when(parentExtensionManager.getExtensions()).thenReturn(emptySet());
    CompositeArtifactExtensionManager extensionManager = new CompositeArtifactExtensionManager(parentExtensionManager, childExtensionManager);
    ConfigurationProvider childConfigurationProvider = mock(ConfigurationProvider.class);
    when(childExtensionManager.getConfigurationProvider(PROVIDER_NAME)).thenReturn(of(childConfigurationProvider));
    when(parentExtensionManager.getConfigurationProvider(PROVIDER_NAME)).thenReturn(empty());
    Optional<ConfigurationProvider> configurationProvider = extensionManager.getConfigurationProvider(PROVIDER_NAME);
    assertThat(configurationProvider.get(), is(childConfigurationProvider));
}
Also used : ConfigurationProvider(org.mule.runtime.extension.api.runtime.config.ConfigurationProvider) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 44 with ExtensionModel

use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.

the class CompositeArtifactExtensionManagerTestCase method providesComposedExtensions.

@Test
public void providesComposedExtensions() throws Exception {
    ExtensionModel parentExtension = mock(ExtensionModel.class);
    Set<ExtensionModel> parentExtensions = singleton(parentExtension);
    when(parentExtensionManager.getExtensions()).thenReturn(parentExtensions);
    ExtensionModel childExtension = mock(ExtensionModel.class);
    Set<ExtensionModel> childExtensions = singleton(childExtension);
    when(childExtensionManager.getExtensions()).thenReturn(childExtensions);
    CompositeArtifactExtensionManager extensionManager = new CompositeArtifactExtensionManager(parentExtensionManager, childExtensionManager);
    Set<ExtensionModel> extensions = extensionManager.getExtensions();
    assertThat(extensions.size(), equalTo(2));
    assertThat(extensions, hasItem(parentExtension));
    assertThat(extensions, hasItem(childExtension));
}
Also used : ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 45 with ExtensionModel

use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.

the class CompositeArtifactExtensionManagerTestCase method failsToObtainMissingConfigurationFromModel.

@Test
public void failsToObtainMissingConfigurationFromModel() throws Exception {
    ExtensionModel childExtension = mock(ExtensionModel.class);
    Set<ExtensionModel> childExtensions = singleton(childExtension);
    when(childExtensionManager.getExtensions()).thenReturn(childExtensions);
    when(parentExtensionManager.getExtensions()).thenReturn(emptySet());
    CompositeArtifactExtensionManager extensionManager = new CompositeArtifactExtensionManager(parentExtensionManager, childExtensionManager);
    CoreEvent event = mock(CoreEvent.class);
    ConfigurationProvider childConfigurationProvider = mock(ConfigurationProvider.class);
    ConfigurationInstance configurationInstance = mock(ConfigurationInstance.class);
    when(childConfigurationProvider.get(event)).thenReturn(configurationInstance);
    when(childExtensionManager.getConfiguration(childExtension, operationModel, event)).thenReturn(empty());
    when(childExtensionManager.getConfigurationProvider(childExtension, operationModel)).thenReturn(empty());
    when(parentExtensionManager.getConfigurationProvider(childExtension, operationModel)).thenReturn(empty());
    expectedException.expect(IllegalArgumentException.class);
    extensionManager.getConfiguration(childExtension, operationModel, event);
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ConfigurationProvider(org.mule.runtime.extension.api.runtime.config.ConfigurationProvider) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)94 Test (org.junit.Test)50 SmallTest (org.mule.tck.size.SmallTest)34 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)31 Optional (java.util.Optional)26 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)24 List (java.util.List)22 Set (java.util.Set)19 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)19 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)19 ConnectionProviderModel (org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)16 HashMap (java.util.HashMap)15 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)15 String.format (java.lang.String.format)13 Collectors.toList (java.util.stream.Collectors.toList)13 HashSet (java.util.HashSet)12 Map (java.util.Map)12 Reference (org.mule.runtime.api.util.Reference)12 Optional.empty (java.util.Optional.empty)11 ObjectType (org.mule.metadata.api.model.ObjectType)11