| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.rendering.internal.parser.xwiki20; |
| 21 |
|
|
| 22 |
|
import javax.inject.Provider; |
| 23 |
|
|
| 24 |
|
import org.junit.Before; |
| 25 |
|
import org.junit.Rule; |
| 26 |
|
import org.junit.Test; |
| 27 |
|
import org.xwiki.component.manager.ComponentManager; |
| 28 |
|
import org.xwiki.component.util.DefaultParameterizedType; |
| 29 |
|
import org.xwiki.rendering.internal.parser.reference.type.AttachmentResourceReferenceTypeParser; |
| 30 |
|
import org.xwiki.rendering.internal.parser.reference.type.URLResourceReferenceTypeParser; |
| 31 |
|
import org.xwiki.rendering.listener.reference.ResourceReference; |
| 32 |
|
import org.xwiki.rendering.listener.reference.ResourceType; |
| 33 |
|
import org.xwiki.rendering.parser.ResourceReferenceParser; |
| 34 |
|
import org.xwiki.rendering.wiki.WikiModel; |
| 35 |
|
import org.xwiki.test.annotation.BeforeComponent; |
| 36 |
|
import org.xwiki.test.annotation.ComponentList; |
| 37 |
|
import org.xwiki.test.mockito.MockitoComponentManagerRule; |
| 38 |
|
|
| 39 |
|
import static org.junit.Assert.assertEquals; |
| 40 |
|
import static org.junit.Assert.assertFalse; |
| 41 |
|
import static org.mockito.Mockito.when; |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
@link |
| 45 |
|
|
| 46 |
|
@version |
| 47 |
|
@since |
| 48 |
|
|
| 49 |
|
|
| 50 |
|
@ComponentList({ |
| 51 |
|
XWiki20ImageReferenceParser.class, |
| 52 |
|
URLResourceReferenceTypeParser.class, |
| 53 |
|
AttachmentResourceReferenceTypeParser.class |
| 54 |
|
}) |
| 55 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 4 |
Complexity Density: 0.21 |
|
| 56 |
|
public class XWiki20ImageReferenceParserTest |
| 57 |
|
{ |
| 58 |
|
@Rule |
| 59 |
|
public MockitoComponentManagerRule componentManager = new MockitoComponentManagerRule(); |
| 60 |
|
|
| 61 |
|
private ResourceReferenceParser parser; |
| 62 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 63 |
2 |
@BeforeComponent... |
| 64 |
|
public void setUpComponents() throws Exception |
| 65 |
|
{ |
| 66 |
|
|
| 67 |
2 |
this.componentManager.registerMockComponent(WikiModel.class); |
| 68 |
|
|
| 69 |
2 |
Provider<ComponentManager> contextComponentManagerProvider = this.componentManager.registerMockComponent( |
| 70 |
|
new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context"); |
| 71 |
2 |
when(contextComponentManagerProvider.get()).thenReturn(this.componentManager); |
| 72 |
|
} |
| 73 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 74 |
2 |
@Before... |
| 75 |
|
public void setUp() throws Exception |
| 76 |
|
{ |
| 77 |
2 |
this.parser = this.componentManager.getInstance(ResourceReferenceParser.class, "xwiki/2.0/image"); |
| 78 |
|
} |
| 79 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
| 80 |
1 |
@Test... |
| 81 |
|
public void testParseImagesCommon() throws Exception |
| 82 |
|
{ |
| 83 |
|
|
| 84 |
1 |
ResourceReference reference = this.parser.parse("wiki:space.page@filename"); |
| 85 |
1 |
assertEquals(ResourceType.ATTACHMENT, reference.getType()); |
| 86 |
1 |
assertEquals("wiki:space.page@filename", reference.getReference()); |
| 87 |
1 |
assertEquals("Typed = [false] Type = [attach] Reference = [wiki:space.page@filename]", |
| 88 |
|
reference.toString()); |
| 89 |
1 |
assertFalse(reference.isTyped()); |
| 90 |
|
|
| 91 |
|
|
| 92 |
1 |
reference = this.parser.parse("http://server/path/to/image"); |
| 93 |
1 |
assertEquals(ResourceType.URL, reference.getType()); |
| 94 |
1 |
assertEquals("http://server/path/to/image", reference.getReference()); |
| 95 |
1 |
assertEquals("Typed = [false] Type = [url] Reference = [http://server/path/to/image]", |
| 96 |
|
reference.toString()); |
| 97 |
1 |
assertFalse(reference.isTyped()); |
| 98 |
|
|
| 99 |
|
} |
| 100 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 101 |
1 |
@Test... |
| 102 |
|
public void testParseImages() throws Exception |
| 103 |
|
{ |
| 104 |
|
|
| 105 |
1 |
ResourceReference reference = this.parser.parse("attach:wiki:space.page@filename"); |
| 106 |
1 |
assertEquals(ResourceType.ATTACHMENT, reference.getType()); |
| 107 |
1 |
assertEquals("attach:wiki:space.page@filename", reference.getReference()); |
| 108 |
1 |
assertFalse(reference.isTyped()); |
| 109 |
1 |
assertEquals("Typed = [false] Type = [attach] Reference = [attach:wiki:space.page@filename]", |
| 110 |
|
reference.toString()); |
| 111 |
|
} |
| 112 |
|
} |