Search in sources :

Example 1 with MulePolicyModelBuilder

use of org.mule.runtime.api.deployment.meta.MulePolicyModel.MulePolicyModelBuilder in project mule by mulesoft.

the class AbstractDeploymentTestCase method createPolicyIncludingDependantPluginFileBuilder.

private PolicyFileBuilder createPolicyIncludingDependantPluginFileBuilder() {
    MulePolicyModelBuilder mulePolicyModelBuilder = new MulePolicyModelBuilder().setMinMuleVersion(MIN_MULE_VERSION).setName(BAZ_POLICY_NAME).setRequiredProduct(Product.MULE).withBundleDescriptorLoader(createBundleDescriptorLoader(BAZ_POLICY_NAME, MULE_POLICY_CLASSIFIER, PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID)).withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
    ArtifactPluginFileBuilder dependantPlugin;
    try {
        dependantPlugin = new ArtifactPluginFileBuilder("dependantPlugin").configuredWith(EXPORTED_CLASS_PACKAGES_PROPERTY, "org.foo.echo").containingClass(new SingleClassCompiler().compile(getResourceFile("/org/foo/echo/Plugin3Echo.java")), "org/foo/echo/Plugin3Echo.class").dependingOn(helloExtensionV1Plugin);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
    return new PolicyFileBuilder(BAZ_POLICY_NAME).describedBy(mulePolicyModelBuilder.build()).dependingOn(dependantPlugin);
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) ArtifactPluginFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder) PolicyFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.PolicyFileBuilder) MulePolicyModelBuilder(org.mule.runtime.api.deployment.meta.MulePolicyModel.MulePolicyModelBuilder) URISyntaxException(java.net.URISyntaxException) SingleClassCompiler(org.mule.tck.util.CompilerUtils.SingleClassCompiler)

Example 2 with MulePolicyModelBuilder

use of org.mule.runtime.api.deployment.meta.MulePolicyModel.MulePolicyModelBuilder in project mule by mulesoft.

the class PolicyTemplateDescriptorFactoryTestCase method readsRuntimeLibs.

@Test
public void readsRuntimeLibs() throws Exception {
    MulePolicyModelBuilder mulePolicyModelBuilder = new MulePolicyModelBuilder().setName(POLICY_NAME).setMinMuleVersion("4.0.0").setRequiredProduct(MULE).withBundleDescriptorLoader(createPolicyBundleDescriptorLoader(PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID));
    mulePolicyModelBuilder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptor(FILE_SYSTEM_POLICY_MODEL_LOADER_ID, emptyMap()));
    PolicyFileBuilder policyFileBuilder = new PolicyFileBuilder(POLICY_NAME).usingLibrary(echoTestJarFile.getAbsolutePath()).describedBy(mulePolicyModelBuilder.build());
    File tempFolder = createTempFolder();
    unzip(policyFileBuilder.getArtifactFile(), tempFolder);
    PolicyTemplateDescriptorFactory descriptorFactory = new PolicyTemplateDescriptorFactory(artifactPluginDescriptorLoader, descriptorLoaderRepository, ArtifactDescriptorValidatorBuilder.builder());
    PolicyTemplateDescriptor desc = descriptorFactory.create(tempFolder, empty());
    assertThat(desc.getClassLoaderModel().getUrls().length, equalTo(2));
    assertThat(toFile(desc.getClassLoaderModel().getUrls()[0]).getPath(), equalTo(tempFolder.toString()));
    assertThat(toFile(desc.getClassLoaderModel().getUrls()[1]).getPath(), equalTo(new File(tempFolder, LIB_DIR + separator + JAR_FILE_NAME).toString()));
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) PolicyFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.PolicyFileBuilder) MulePolicyModelBuilder(org.mule.runtime.api.deployment.meta.MulePolicyModel.MulePolicyModelBuilder) PolicyTemplateDescriptor(org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor) File.createTempFile(java.io.File.createTempFile) FileUtils.toFile(org.apache.commons.io.FileUtils.toFile) File(java.io.File) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with MulePolicyModelBuilder

use of org.mule.runtime.api.deployment.meta.MulePolicyModel.MulePolicyModelBuilder in project mule by mulesoft.

the class PolicyTemplateDescriptorFactoryTestCase method readsPlugin.

@Test
public void readsPlugin() throws Exception {
    MulePolicyModelBuilder policyModelBuilder = new MulePolicyModelBuilder().setName(POLICY_NAME).setMinMuleVersion("4.0.0").setRequiredProduct(MULE).withBundleDescriptorLoader(createPolicyBundleDescriptorLoader(PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID)).withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
    ArtifactPluginFileBuilder plugin1 = new ArtifactPluginFileBuilder("plugin1");
    ArtifactPluginFileBuilder plugin2 = new ArtifactPluginFileBuilder("plugin2");
    PolicyFileBuilder policyFileBuilder = new PolicyFileBuilder(POLICY_NAME).describedBy(policyModelBuilder.build()).dependingOn(plugin1).dependingOn(plugin2);
    File tempFolder = createTempFolder();
    unzip(policyFileBuilder.getArtifactFile(), tempFolder);
    final ArtifactPluginDescriptorFactory pluginDescriptorFactory = mock(ArtifactPluginDescriptorFactory.class);
    final PolicyTemplateDescriptorFactory policyTemplateDescriptorFactory = new PolicyTemplateDescriptorFactory(new ArtifactPluginDescriptorLoader(pluginDescriptorFactory), descriptorLoaderRepository, ArtifactDescriptorValidatorBuilder.builder());
    final ArtifactPluginDescriptor expectedPluginDescriptor1 = new ArtifactPluginDescriptor("plugin1");
    final ArtifactPluginDescriptor expectedPluginDescriptor2 = new ArtifactPluginDescriptor("plugin2");
    when(pluginDescriptorFactory.create(any(), any())).thenReturn(expectedPluginDescriptor1).thenReturn(expectedPluginDescriptor2);
    PolicyTemplateDescriptor descriptor = policyTemplateDescriptorFactory.create(tempFolder, empty());
    Set<ArtifactPluginDescriptor> plugins = descriptor.getPlugins();
    assertThat(plugins.size(), equalTo(2));
    assertThat(plugins, hasItem(equalTo(expectedPluginDescriptor1)));
    assertThat(plugins, hasItem(equalTo(expectedPluginDescriptor2)));
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) ArtifactPluginFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) PolicyFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.PolicyFileBuilder) ArtifactPluginDescriptorLoader(org.mule.runtime.module.deployment.impl.internal.plugin.ArtifactPluginDescriptorLoader) MulePolicyModelBuilder(org.mule.runtime.api.deployment.meta.MulePolicyModel.MulePolicyModelBuilder) ArtifactPluginDescriptorFactory(org.mule.runtime.module.deployment.impl.internal.plugin.ArtifactPluginDescriptorFactory) PolicyTemplateDescriptor(org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor) File.createTempFile(java.io.File.createTempFile) FileUtils.toFile(org.apache.commons.io.FileUtils.toFile) File(java.io.File) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 4 with MulePolicyModelBuilder

use of org.mule.runtime.api.deployment.meta.MulePolicyModel.MulePolicyModelBuilder in project mule by mulesoft.

the class AbstractDeploymentTestCase method createPolicyIncludingHelloPluginV2FileBuilder.

private PolicyFileBuilder createPolicyIncludingHelloPluginV2FileBuilder() {
    MulePolicyModelBuilder mulePolicyModelBuilder = new MulePolicyModelBuilder().setMinMuleVersion(MIN_MULE_VERSION).setName(BAZ_POLICY_NAME).setRequiredProduct(MULE).withBundleDescriptorLoader(createBundleDescriptorLoader(BAZ_POLICY_NAME, MULE_POLICY_CLASSIFIER, PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID));
    mulePolicyModelBuilder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
    return new PolicyFileBuilder(BAZ_POLICY_NAME).describedBy(mulePolicyModelBuilder.build()).dependingOn(helloExtensionV2Plugin);
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) PolicyFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.PolicyFileBuilder) MulePolicyModelBuilder(org.mule.runtime.api.deployment.meta.MulePolicyModel.MulePolicyModelBuilder)

Example 5 with MulePolicyModelBuilder

use of org.mule.runtime.api.deployment.meta.MulePolicyModel.MulePolicyModelBuilder in project mule by mulesoft.

the class PolicyTemplateDescriptorFactoryTestCase method detectsInvalidBundleDescriptorLoaderId.

@Test
public void detectsInvalidBundleDescriptorLoaderId() throws Exception {
    MulePolicyModelBuilder mulePolicyModelBuilder = new MulePolicyModelBuilder().setName(POLICY_NAME).setMinMuleVersion("4.0.0").setRequiredProduct(MULE).withBundleDescriptorLoader(createPolicyBundleDescriptorLoader(INVALID_LOADER_ID)).withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptor(FILE_SYSTEM_POLICY_MODEL_LOADER_ID, emptyMap()));
    PolicyFileBuilder policyFileBuilder = new PolicyFileBuilder(POLICY_NAME).describedBy(mulePolicyModelBuilder.build());
    File tempFolder = createTempFolder();
    unzip(policyFileBuilder.getArtifactFile(), tempFolder);
    PolicyTemplateDescriptorFactory descriptorFactory = new PolicyTemplateDescriptorFactory(artifactPluginDescriptorLoader, descriptorLoaderRepository, ArtifactDescriptorValidatorBuilder.builder());
    expectedException.expect(ArtifactDescriptorCreateException.class);
    expectedException.expectMessage(invalidBundleDescriptorLoaderIdError(tempFolder, mulePolicyModelBuilder.getBundleDescriptorLoader()));
    descriptorFactory.create(tempFolder, empty());
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) PolicyFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.PolicyFileBuilder) MulePolicyModelBuilder(org.mule.runtime.api.deployment.meta.MulePolicyModel.MulePolicyModelBuilder) File.createTempFile(java.io.File.createTempFile) FileUtils.toFile(org.apache.commons.io.FileUtils.toFile) File(java.io.File) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

MuleArtifactLoaderDescriptor (org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor)7 MulePolicyModelBuilder (org.mule.runtime.api.deployment.meta.MulePolicyModel.MulePolicyModelBuilder)7 PolicyFileBuilder (org.mule.runtime.module.deployment.impl.internal.builder.PolicyFileBuilder)7 File (java.io.File)5 File.createTempFile (java.io.File.createTempFile)5 FileUtils.toFile (org.apache.commons.io.FileUtils.toFile)5 Test (org.junit.Test)5 SmallTest (org.mule.tck.size.SmallTest)5 PolicyTemplateDescriptor (org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor)3 ArtifactPluginFileBuilder (org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder)2 URISyntaxException (java.net.URISyntaxException)1 ArtifactPluginDescriptor (org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor)1 ArtifactPluginDescriptorFactory (org.mule.runtime.module.deployment.impl.internal.plugin.ArtifactPluginDescriptorFactory)1 ArtifactPluginDescriptorLoader (org.mule.runtime.module.deployment.impl.internal.plugin.ArtifactPluginDescriptorLoader)1 SingleClassCompiler (org.mule.tck.util.CompilerUtils.SingleClassCompiler)1