| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.rendering.macro.script.classloader; |
| 21 |
|
|
| 22 |
|
import java.net.URL; |
| 23 |
|
|
| 24 |
|
import org.junit.Assert; |
| 25 |
|
|
| 26 |
|
import org.xwiki.bridge.DocumentAccessBridge; |
| 27 |
|
import org.xwiki.classloader.ExtendedURLClassLoader; |
| 28 |
|
import org.xwiki.classloader.URIClassLoader; |
| 29 |
|
import org.xwiki.model.reference.AttachmentReferenceResolver; |
| 30 |
|
import org.xwiki.rendering.internal.macro.script.AttachmentClassLoaderFactory; |
| 31 |
|
import org.xwiki.test.jmock.AbstractComponentTestCase; |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
@link |
| 35 |
|
|
| 36 |
|
@version |
| 37 |
|
@since |
| 38 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 3 |
Complexity Density: 0.23 |
|
| 39 |
|
public class DefaultAttachmentClassLoaderFactoryTest extends AbstractComponentTestCase |
| 40 |
|
{ |
| 41 |
|
private AttachmentClassLoaderFactory factory; |
| 42 |
|
|
| 43 |
|
private AttachmentReferenceResolver<String> arf; |
| 44 |
|
|
| 45 |
|
private DocumentAccessBridge dab; |
| 46 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 47 |
2 |
@Override... |
| 48 |
|
protected void registerComponents() throws Exception |
| 49 |
|
{ |
| 50 |
2 |
super.registerComponents(); |
| 51 |
|
|
| 52 |
2 |
this.arf = registerMockComponent(AttachmentReferenceResolver.TYPE_STRING, "current"); |
| 53 |
2 |
this.dab = registerMockComponent(DocumentAccessBridge.class); |
| 54 |
|
|
| 55 |
2 |
this.factory = getComponentManager().getInstance(AttachmentClassLoaderFactory.class); |
| 56 |
|
} |
| 57 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 58 |
1 |
@org.junit.Test... |
| 59 |
|
public void testCreateAttachmentClassLoader() throws Exception |
| 60 |
|
{ |
| 61 |
1 |
URIClassLoader cl = (URIClassLoader) factory.createAttachmentClassLoader( |
| 62 |
|
"attach:page@filename1, http://some/url, attach:filename2", null); |
| 63 |
|
|
| 64 |
1 |
Assert.assertEquals(3, cl.getURLs().length); |
| 65 |
1 |
Assert.assertEquals("attachmentjar://page%40filename1", cl.getURLs()[0].toString()); |
| 66 |
1 |
Assert.assertEquals("http://some/url", cl.getURLs()[1].toString()); |
| 67 |
1 |
Assert.assertEquals("attachmentjar://filename2", cl.getURLs()[2].toString()); |
| 68 |
|
} |
| 69 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 70 |
1 |
@org.junit.Test... |
| 71 |
|
public void testExtendClassLoaderLoader() throws Exception |
| 72 |
|
{ |
| 73 |
1 |
ExtendedURLClassLoader cl = new ExtendedURLClassLoader(new URL[0]); |
| 74 |
1 |
factory.extendAttachmentClassLoader("attach:page@filename, http://some/url", cl); |
| 75 |
|
|
| 76 |
1 |
Assert.assertEquals("attachmentjar://page%40filename", cl.getURLs()[0].toString()); |
| 77 |
1 |
Assert.assertEquals("http://some/url", cl.getURLs()[1].toString()); |
| 78 |
|
} |
| 79 |
|
} |