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