1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.internal.parser

File DefaultContentParserTest.java

 
testMissingParserException: Failed to find a parser for syntax [XWiki 2.1]
 

Code metrics

0
12
4
1
104
65
4
0.33
3
4
1

Classes

Class Line # Actions
DefaultContentParserTest 57 12 0% 4 5
0.687568.8%
 

Contributing tests

This file is covered by 3 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;
21   
22    import static org.hamcrest.CoreMatchers.any;
23    import static org.hamcrest.CoreMatchers.equalTo;
24    import static org.hamcrest.CoreMatchers.nullValue;
25    import static org.junit.Assert.assertThat;
26    import static org.mockito.hamcrest.MockitoHamcrest.argThat;
27    import static org.mockito.Mockito.when;
28   
29    import java.io.Reader;
30    import java.util.Collections;
31   
32    import org.junit.Before;
33    import org.junit.Rule;
34    import org.junit.Test;
35    import org.junit.rules.ExpectedException;
36    import org.xwiki.component.internal.ContextComponentManagerProvider;
37    import org.xwiki.component.manager.ComponentLookupException;
38    import org.xwiki.model.reference.DocumentReference;
39    import org.xwiki.model.reference.EntityReferenceSerializer;
40    import org.xwiki.rendering.block.Block;
41    import org.xwiki.rendering.block.XDOM;
42    import org.xwiki.rendering.listener.MetaData;
43    import org.xwiki.rendering.parser.ContentParser;
44    import org.xwiki.rendering.parser.MissingParserException;
45    import org.xwiki.rendering.parser.Parser;
46    import org.xwiki.rendering.syntax.Syntax;
47    import org.xwiki.test.annotation.ComponentList;
48    import org.xwiki.test.mockito.MockitoComponentMockingRule;
49   
50    /**
51    * Unit tests for {@link org.xwiki.rendering.internal.parser.DefaultContentParser}.
52    *
53    * @version $Id: 2482819a1cf68376d56346cc457ff51d66749401 $
54    * @since 6.0M2
55    */
56    @ComponentList(ContextComponentManagerProvider.class)
 
57    public class DefaultContentParserTest
58    {
59    @Rule
60    public final MockitoComponentMockingRule<ContentParser> mocker =
61    new MockitoComponentMockingRule<ContentParser>(DefaultContentParser.class);
62   
63   
64    @Rule
65    public ExpectedException thrown = ExpectedException.none();
66   
67    private static final DocumentReference DOCUMENT_REFERENCE = new DocumentReference("wiki", "space", "page");
68    private static final String SOURCE = "wiki:space.page";
69   
 
70  3 toggle @Before
71    public void configure() throws Exception
72    {
73  3 Parser parser = mocker.registerMockComponent(Parser.class, Syntax.PLAIN_1_0.toIdString());
74  3 when(parser.parse(argThat(any(Reader.class)))).thenReturn(new XDOM(Collections.<Block>emptyList()));
75   
76  3 EntityReferenceSerializer<String> serializer = mocker.getInstance(EntityReferenceSerializer.TYPE_STRING);
77  3 when(serializer.serialize(DOCUMENT_REFERENCE)).thenReturn(SOURCE);
78    }
79   
 
80  1 toggle @Test
81    public void testNoMetadataSource() throws Exception
82    {
83  1 XDOM xdom = mocker.getComponentUnderTest().parse("", Syntax.PLAIN_1_0);
84   
85  1 assertThat(xdom.getMetaData().getMetaData(MetaData.SOURCE), nullValue());
86    }
87   
 
88  1 toggle @Test
89    public void testAddingMetadataSource() throws Exception
90    {
91  1 XDOM xdom = mocker.getComponentUnderTest().parse("", Syntax.PLAIN_1_0, DOCUMENT_REFERENCE);
92   
93  1 assertThat((String) xdom.getMetaData().getMetaData(MetaData.SOURCE), equalTo(SOURCE));
94    }
95   
 
96  0 toggle @Test
97    public void testMissingParserException() throws Exception
98    {
99  0 thrown.expect(MissingParserException.class);
100  0 thrown.expectMessage("Failed to find a parser for syntax [XWiki 2.1]");
101  0 thrown.expectCause(any(ComponentLookupException.class));
102  0 Test failure here mocker.getComponentUnderTest().parse("", Syntax.XWIKI_2_1, DOCUMENT_REFERENCE);
103    }
104    }