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();
}
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));
}
}
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));
}
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));
}
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);
}
Aggregations