1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.internal.parser.reference

File DefaultImageReferenceParserTest.java

 

Code metrics

0
27
3
1
93
54
3
0.11
9
3
1

Classes

Class Line # Actions
DefaultImageReferenceParserTest 36 27 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.internal.parser.reference;
21   
22    import org.junit.Assert;
23    import org.junit.Test;
24    import org.xwiki.rendering.listener.reference.ResourceReference;
25    import org.xwiki.rendering.listener.reference.ResourceType;
26    import org.xwiki.rendering.parser.ResourceReferenceParser;
27    import org.xwiki.rendering.wiki.WikiModel;
28    import org.xwiki.test.jmock.AbstractComponentTestCase;
29   
30    /**
31    * Unit tests for {@link DefaultImageReferenceParser}.
32    *
33    * @version $Id: 5717de984081bad1e8b5843fc4a4d6e3db470ae5 $
34    * @since 2.6M1
35    */
 
36    public class DefaultImageReferenceParserTest extends AbstractComponentTestCase
37    {
38    private ResourceReferenceParser parser;
39   
 
40  2 toggle @Override
41    protected void registerComponents() throws Exception
42    {
43    // Create a Mock WikiModel implementation so that the link parser works in wiki mode
44  2 registerMockComponent(WikiModel.class);
45   
46  2 this.parser = getComponentManager().getInstance(ResourceReferenceParser.class, "image");
47    }
48   
 
49  1 toggle @Test
50    public void testParseImagesCommon() throws Exception
51    {
52    // Verify that non-typed image referencing an attachment works.
53  1 ResourceReference reference = this.parser.parse("wiki:space.page@filename");
54  1 Assert.assertEquals(ResourceType.ATTACHMENT, reference.getType());
55  1 Assert.assertEquals("wiki:space.page@filename", reference.getReference());
56  1 Assert.assertEquals("Typed = [false] Type = [attach] Reference = [wiki:space.page@filename]",
57    reference.toString());
58  1 Assert.assertFalse(reference.isTyped());
59   
60    // Verify that non-typed image referencing a URL works.
61  1 reference = this.parser.parse("scheme://server/path/to/image");
62  1 Assert.assertEquals(ResourceType.URL, reference.getType());
63  1 Assert.assertEquals("scheme://server/path/to/image", reference.getReference());
64  1 Assert.assertEquals("Typed = [false] Type = [url] Reference = [scheme://server/path/to/image]",
65    reference.toString());
66  1 Assert.assertFalse(reference.isTyped());
67    }
68   
 
69  1 toggle @Test
70    public void testParseImages() throws Exception
71    {
72  1 ResourceReference reference = this.parser.parse("attach:wiki:space.page@filename");
73  1 Assert.assertEquals(ResourceType.ATTACHMENT, reference.getType());
74  1 Assert.assertEquals("wiki:space.page@filename", reference.getReference());
75  1 Assert.assertTrue(reference.isTyped());
76  1 Assert.assertEquals("Typed = [true] Type = [attach] Reference = [wiki:space.page@filename]",
77    reference.toString());
78   
79    // Verify path: support
80  1 reference = this.parser.parse("path:/some/image");
81  1 Assert.assertEquals(ResourceType.PATH, reference.getType());
82  1 Assert.assertEquals("/some/image", reference.getReference());
83  1 Assert.assertTrue(reference.isTyped());
84  1 Assert.assertEquals("Typed = [true] Type = [path] Reference = [/some/image]", reference.toString());
85   
86    // Verify icon: support
87  1 reference = this.parser.parse("icon:name");
88  1 Assert.assertEquals(ResourceType.ICON, reference.getType());
89  1 Assert.assertEquals("name", reference.getReference());
90  1 Assert.assertTrue(reference.isTyped());
91  1 Assert.assertEquals("Typed = [true] Type = [icon] Reference = [name]", reference.toString());
92    }
93    }