Search in sources :

Example 1 with TestClassLoader

use of org.mule.tck.classlaoder.TestClassLoader in project mule by mulesoft.

the class FilteringArtifactClassLoaderTestCase method loadsExportedClass.

@Test
public void loadsExportedClass() throws ClassNotFoundException {
    TestClassLoader classLoader = new TestClassLoader(null);
    Class expectedClass = this.getClass();
    classLoader.addClass(CLASS_NAME, expectedClass);
    when(filter.exportsClass(CLASS_NAME)).thenReturn(true);
    when(artifactClassLoader.getClassLoader()).thenReturn(classLoader);
    filteringArtifactClassLoader = doCreateClassLoader(emptyList());
    Class<?> aClass = filteringArtifactClassLoader.loadClass(CLASS_NAME);
    assertThat(aClass, equalTo(expectedClass));
}
Also used : TestClassLoader(org.mule.tck.classlaoder.TestClassLoader) Test(org.junit.Test)

Example 2 with TestClassLoader

use of org.mule.tck.classlaoder.TestClassLoader in project mule by mulesoft.

the class FilteringArtifactClassLoaderTestCase method filtersResources.

@Test
public void filtersResources() throws Exception {
    TestClassLoader classLoader = new TestClassLoader(null);
    URL blockedResource = new URL("file:///app.txt");
    classLoader.addResource(RESOURCE_NAME, blockedResource);
    when(filter.exportsResource(RESOURCE_NAME)).thenReturn(false);
    when(artifactClassLoader.getClassLoader()).thenReturn(classLoader);
    filteringArtifactClassLoader = doCreateClassLoader(emptyList());
    Enumeration<URL> resources = filteringArtifactClassLoader.getResources(RESOURCE_NAME);
    assertThat(resources, equalTo(Collections.EMPTY_LIST));
}
Also used : TestClassLoader(org.mule.tck.classlaoder.TestClassLoader) URL(java.net.URL) Test(org.junit.Test)

Example 3 with TestClassLoader

use of org.mule.tck.classlaoder.TestClassLoader in project mule by mulesoft.

the class FilteringContainerClassLoaderTestCase method loadsExportedResource.

@Test
@Override
public void loadsExportedResource() throws ClassNotFoundException, MalformedURLException {
    TestClassLoader classLoader = new TestClassLoader(null);
    URL expectedResource = new URL("file:///app.txt");
    classLoader.addResource(FilteringArtifactClassLoaderTestCase.RESOURCE_NAME, expectedResource);
    when(filter.exportsResource(FilteringArtifactClassLoaderTestCase.RESOURCE_NAME)).thenReturn(true);
    when(artifactClassLoader.getClassLoader()).thenReturn(classLoader);
    filteringArtifactClassLoader = doCreateClassLoader(emptyList());
    URL resource = filteringArtifactClassLoader.getResource(FilteringArtifactClassLoaderTestCase.RESOURCE_NAME);
    assertThat(resource, equalTo(expectedResource));
}
Also used : TestClassLoader(org.mule.tck.classlaoder.TestClassLoader) URL(java.net.URL) Test(org.junit.Test)

Example 4 with TestClassLoader

use of org.mule.tck.classlaoder.TestClassLoader in project mule by mulesoft.

the class FilteringContainerClassLoaderTestCase method getsExportedResources.

@Test
@Override
public void getsExportedResources() throws Exception {
    TestClassLoader classLoader = new TestClassLoader(null);
    URL resource = new URL("file:/app.txt");
    classLoader.addResource(FilteringArtifactClassLoaderTestCase.RESOURCE_NAME, resource);
    when(filter.exportsResource(FilteringArtifactClassLoaderTestCase.RESOURCE_NAME)).thenReturn(true);
    when(artifactClassLoader.getClassLoader()).thenReturn(classLoader);
    filteringArtifactClassLoader = doCreateClassLoader(emptyList());
    Enumeration<URL> resources = filteringArtifactClassLoader.getResources(FilteringArtifactClassLoaderTestCase.RESOURCE_NAME);
    assertThat(resources, EnumerationMatcher.equalTo(Collections.singletonList(resource)));
}
Also used : TestClassLoader(org.mule.tck.classlaoder.TestClassLoader) URL(java.net.URL) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 TestClassLoader (org.mule.tck.classlaoder.TestClassLoader)4 URL (java.net.URL)3