1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.macro.script.classloader

File DefaultAttachmentClassLoaderFactoryTest.java

 

Code metrics

0
13
3
1
79
41
3
0.23
4.33
3
1

Classes

Class Line # Actions
DefaultAttachmentClassLoaderFactoryTest 39 13 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Unit tests for {@link DefaultAttachmentClassLoaderFactory}.
35    *
36    * @version $Id: 6907eaf5079ee86aee8658ec82381b04adc8b2d1 $
37    * @since 2.0.1
38    */
 
39    public class DefaultAttachmentClassLoaderFactoryTest extends AbstractComponentTestCase
40    {
41    private AttachmentClassLoaderFactory factory;
42   
43    private AttachmentReferenceResolver<String> arf;
44   
45    private DocumentAccessBridge dab;
46   
 
47  2 toggle @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   
 
58  1 toggle @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   
 
70  1 toggle @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    }