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

File MockWikiModel.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

12
19
6
1
107
56
12
0.63
3.17
6
2

Classes

Class Line # Actions
MockWikiModel 38 19 0% 12 2
0.945945994.6%
 

Contributing tests

This file is covered by 54 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.test;
21   
22    import java.util.Map;
23   
24    import org.xwiki.component.descriptor.ComponentDescriptor;
25    import org.xwiki.component.descriptor.DefaultComponentDescriptor;
26    import org.xwiki.rendering.listener.reference.AttachmentResourceReference;
27    import org.xwiki.rendering.listener.reference.DocumentResourceReference;
28    import org.xwiki.rendering.listener.reference.ResourceReference;
29    import org.xwiki.rendering.listener.reference.ResourceType;
30    import org.xwiki.rendering.wiki.WikiModel;
31   
32    /**
33    * Mock WikiModel implementation for integration tests.
34    *
35    * @version $Id: 52506d2da8732799e78643cefec8472c322635d1 $
36    * @since 2.0M1
37    */
 
38    public class MockWikiModel implements WikiModel
39    {
40    /**
41    * Question Mark symbol.
42    */
43    private static final String QM = "?";
44   
45    /**
46    * Create and return a descriptor for this component.
47    *
48    * @return the descriptor of the component.
49    */
 
50  323 toggle public static ComponentDescriptor<WikiModel> getComponentDescriptor()
51    {
52  323 DefaultComponentDescriptor<WikiModel> componentDescriptor = new DefaultComponentDescriptor<WikiModel>();
53   
54  323 componentDescriptor.setRoleType(WikiModel.class);
55  323 componentDescriptor.setImplementation(MockWikiModel.class);
56   
57  323 return componentDescriptor;
58    }
59   
60    /**
61    * {@inheritDoc}
62    *
63    * @since 2.5RC1
64    */
 
65  11 toggle @Override
66    public String getLinkURL(ResourceReference linkReference)
67    {
68  11 String queryString = linkReference.getParameter(AttachmentResourceReference.QUERY_STRING);
69  11 return "attachmenturl" + (queryString != null ? QM + queryString : "");
70    }
71   
 
72  22 toggle @Override
73    public String getImageURL(ResourceReference imageReference, Map<String, String> parameters)
74    {
75  22 String queryString = imageReference.getParameter(AttachmentResourceReference.QUERY_STRING);
76  22 return "imageurl" + (queryString != null ? QM + queryString : "");
77    }
78   
 
79  23 toggle @Override
80    public String getDocumentEditURL(ResourceReference documentReference)
81    {
82  23 return "editurl";
83    }
84   
 
85  22 toggle @Override
86    public String getDocumentViewURL(ResourceReference documentReference)
87    {
88  22 String queryString = documentReference.getParameter(DocumentResourceReference.QUERY_STRING);
89  22 String anchor = documentReference.getParameter(DocumentResourceReference.ANCHOR);
90  22 return "viewurl" + (queryString != null ? QM + queryString : "") + (anchor != null ? "#" + anchor : "");
91    }
92   
 
93  45 toggle @Override
94    public boolean isDocumentAvailable(ResourceReference documentReference)
95    {
96  45 ResourceType resourceType = documentReference.getType();
97  45 String resourceValue = documentReference.getReference();
98   
99  45 if (ResourceType.DOCUMENT.equals(resourceType)) {
100  43 return "Space.ExistingPage".equals(resourceValue);
101  2 } else if (ResourceType.SPACE.equals(resourceType)) {
102  2 return "ExistingSpace".equals(resourceValue);
103    }
104   
105  0 return false;
106    }
107    }