1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.internal.model.reference

File CurrentMixedReferenceEntityReferenceResolverTest.java

 

Code metrics

0
15
3
1
83
45
3
0.2
5
3
1

Classes

Class Line # Actions
CurrentMixedReferenceEntityReferenceResolverTest 38 15 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 com.xpn.xwiki.internal.model.reference;
21   
22    import org.junit.Assert;
23    import org.junit.Test;
24    import org.xwiki.model.EntityType;
25    import org.xwiki.model.reference.DocumentReference;
26    import org.xwiki.model.reference.EntityReference;
27    import org.xwiki.model.reference.EntityReferenceResolver;
28    import org.xwiki.model.reference.ObjectReference;
29   
30    import com.xpn.xwiki.doc.XWikiDocument;
31    import com.xpn.xwiki.test.AbstractBridgedComponentTestCase;
32   
33    /**
34    * Unit tests for {@link CurrentMixedReferenceEntityReferenceResolver}.
35    *
36    * @version $Id: 4c6657d1b78783a92cf4b8e1b763aa1368949e02 $
37    */
 
38    public class CurrentMixedReferenceEntityReferenceResolverTest extends AbstractBridgedComponentTestCase
39    {
40    private static final String CURRENT_WIKI = "currentwiki";
41   
42    private static final String CURRENT_SPACE = "currentspace";
43   
44    private static final String CURRENT_PAGE = "currentpage";
45   
46    private EntityReferenceResolver<EntityReference> resolver;
47   
 
48  2 toggle @Override
49    public void setUp() throws Exception
50    {
51  2 super.setUp();
52   
53  2 this.resolver = getComponentManager().getInstance(EntityReferenceResolver.TYPE_REFERENCE, "currentmixed");
54    }
55   
 
56  1 toggle @Test
57    public void testResolveAttachmentReferenceWhenMissingParentsAndContextDocument()
58    {
59  1 getContext().setWikiId(CURRENT_WIKI);
60  1 getContext().setDoc(new XWikiDocument(new DocumentReference(CURRENT_WIKI, CURRENT_SPACE, CURRENT_PAGE)));
61   
62  1 EntityReference reference =
63    resolver.resolve(new EntityReference("filename", EntityType.ATTACHMENT), EntityType.ATTACHMENT);
64   
65  1 Assert.assertEquals("WebHome", reference.getParent().getName());
66  1 Assert.assertEquals(EntityType.DOCUMENT, reference.getParent().getType());
67  1 Assert.assertEquals(CURRENT_SPACE, reference.getParent().getParent().getName());
68  1 Assert.assertEquals(EntityType.SPACE, reference.getParent().getParent().getType());
69  1 Assert.assertEquals(CURRENT_WIKI, reference.getParent().getParent().getParent().getName());
70  1 Assert.assertEquals(EntityType.WIKI, reference.getParent().getParent().getParent().getType());
71    }
72   
 
73  1 toggle @Test
74    public void testResolveDocumentFromObjectReference()
75    {
76  1 DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
77  1 ObjectReference objectReference = new ObjectReference("object", documentReference);
78   
79  1 EntityReference reference = this.resolver.resolve(objectReference, EntityType.DOCUMENT);
80   
81  1 Assert.assertEquals(documentReference, reference);
82    }
83    }