Search in sources :

Example 1 with PolicyTemplateClassLoaderBuilder

use of org.mule.runtime.deployment.model.internal.policy.PolicyTemplateClassLoaderBuilder in project mule by mulesoft.

the class DefaultPolicyTemplateFactoryTestCase method managesArtifactContextCreationFailure.

@Test
public void managesArtifactContextCreationFailure() throws Exception {
    RegionClassLoader regionClassLoader = createRegionClassLoader();
    PolicyTemplateClassLoaderBuilder policyTemplateClassLoaderBuilder = createPolicyTemplateClassLoaderBuilder(regionClassLoader);
    final String errorMessage = "Error";
    final IOException exceptionCause = new IOException(errorMessage);
    when(policyTemplateClassLoaderBuilder.build()).thenThrow(exceptionCause);
    when(classLoaderBuilderFactory.createArtifactClassLoaderBuilder()).thenReturn(policyTemplateClassLoaderBuilder);
    this.expectedException.expect(PolicyTemplateCreationException.class);
    this.expectedException.expectMessage(createPolicyTemplateCreationErrorMessage(POLICY_NAME));
    this.expectedException.expectCause(equalTo(exceptionCause));
    policyTemplateFactory.createArtifact(createApplication(regionClassLoader), descriptor);
    // Checks that the region was not updated
    assertThat(regionClassLoader.getArtifactPluginClassLoaders().size(), equalTo(0));
}
Also used : PolicyTemplateClassLoaderBuilder(org.mule.runtime.deployment.model.internal.policy.PolicyTemplateClassLoaderBuilder) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader) IOException(java.io.IOException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with PolicyTemplateClassLoaderBuilder

use of org.mule.runtime.deployment.model.internal.policy.PolicyTemplateClassLoaderBuilder in project mule by mulesoft.

the class DefaultPolicyTemplateFactoryTestCase method createsPolicyTemplate.

@Test
public void createsPolicyTemplate() throws Exception {
    RegionClassLoader regionClassLoader = createRegionClassLoader();
    PolicyTemplateClassLoaderBuilder policyTemplateClassLoaderBuilder = createPolicyTemplateClassLoaderBuilder(regionClassLoader);
    MuleDeployableArtifactClassLoader policyClassLoader = mock(MuleDeployableArtifactClassLoader.class);
    when(policyClassLoader.getArtifactId()).thenReturn(POLICY_ID);
    when(policyTemplateClassLoaderBuilder.build()).thenReturn(policyClassLoader);
    when(classLoaderBuilderFactory.createArtifactClassLoaderBuilder()).thenReturn(policyTemplateClassLoaderBuilder);
    PolicyTemplate policyTemplate = policyTemplateFactory.createArtifact(createApplication(regionClassLoader), descriptor);
    assertThat(policyTemplate.getArtifactClassLoader(), is(policyClassLoader));
    assertThat(policyTemplate.getDescriptor(), is(descriptor));
    assertThat(policyTemplate.getArtifactId(), is(POLICY_ID));
    assertThat(regionClassLoader.getArtifactPluginClassLoaders().size(), equalTo(1));
}
Also used : MuleDeployableArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader) PolicyTemplateClassLoaderBuilder(org.mule.runtime.deployment.model.internal.policy.PolicyTemplateClassLoaderBuilder) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader) PolicyTemplate(org.mule.runtime.deployment.model.api.policy.PolicyTemplate) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with PolicyTemplateClassLoaderBuilder

use of org.mule.runtime.deployment.model.internal.policy.PolicyTemplateClassLoaderBuilder in project mule by mulesoft.

the class DefaultPolicyTemplateFactoryTestCase method createPolicyTemplateClassLoaderBuilder.

private PolicyTemplateClassLoaderBuilder createPolicyTemplateClassLoaderBuilder(RegionClassLoader regionClassLoader) {
    PolicyTemplateClassLoaderBuilder policyTemplateClassLoaderBuilder = mock(PolicyTemplateClassLoaderBuilder.class);
    when(policyTemplateClassLoaderBuilder.setParentClassLoader(regionClassLoader)).thenReturn(policyTemplateClassLoaderBuilder);
    when(policyTemplateClassLoaderBuilder.setArtifactDescriptor(descriptor)).thenReturn(policyTemplateClassLoaderBuilder);
    when(policyTemplateClassLoaderBuilder.addArtifactPluginDescriptors(anyVararg())).thenReturn(policyTemplateClassLoaderBuilder);
    return policyTemplateClassLoaderBuilder;
}
Also used : PolicyTemplateClassLoaderBuilder(org.mule.runtime.deployment.model.internal.policy.PolicyTemplateClassLoaderBuilder)

Aggregations

PolicyTemplateClassLoaderBuilder (org.mule.runtime.deployment.model.internal.policy.PolicyTemplateClassLoaderBuilder)3 Test (org.junit.Test)2 RegionClassLoader (org.mule.runtime.module.artifact.api.classloader.RegionClassLoader)2 SmallTest (org.mule.tck.size.SmallTest)2 IOException (java.io.IOException)1 PolicyTemplate (org.mule.runtime.deployment.model.api.policy.PolicyTemplate)1 MuleDeployableArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader)1