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

File AttachVfsResourceReferenceSerializerTest.java

 

Code metrics

0
10
1
1
78
43
1
0.1
10
1
1

Classes

Class Line # Actions
AttachVfsResourceReferenceSerializerTest 46 10 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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.vfs.internal.attach;
21   
22    import java.net.URI;
23    import java.util.Arrays;
24   
25    import org.junit.Rule;
26    import org.junit.Test;
27    import org.xwiki.component.util.DefaultParameterizedType;
28    import org.xwiki.model.reference.AttachmentReference;
29    import org.xwiki.model.reference.AttachmentReferenceResolver;
30    import org.xwiki.model.reference.DocumentReference;
31    import org.xwiki.model.reference.EntityReferenceSerializer;
32    import org.xwiki.test.mockito.MockitoComponentMockingRule;
33    import org.xwiki.url.ExtendedURL;
34    import org.xwiki.url.URLNormalizer;
35    import org.xwiki.vfs.VfsResourceReference;
36   
37    import static org.junit.Assert.*;
38    import static org.mockito.Mockito.*;
39   
40    /**
41    * Unit tests for {@link AttachVfsResourceReferenceSerializer}.
42    *
43    * @version $Id: 08c760db12c06fc014040b37ddaf0494a4bb8896 $
44    * @since 7.4M2
45    */
 
46    public class AttachVfsResourceReferenceSerializerTest
47    {
48    @Rule
49    public MockitoComponentMockingRule<AttachVfsResourceReferenceSerializer> mocker =
50    new MockitoComponentMockingRule<>(AttachVfsResourceReferenceSerializer.class);
51   
 
52  1 toggle @Test
53    public void serialize() throws Exception
54    {
55  1 VfsResourceReference reference = new VfsResourceReference(
56    URI.create("attach:attachment"), "path1/path2/test.txt");
57   
58  1 ExtendedURL extendedURL = new ExtendedURL(Arrays.asList(
59    "vfs", "attach:wiki:space.page@attachment", "path1", "path2", "test.txt"));
60   
61  1 URLNormalizer<ExtendedURL> normalizer = this.mocker.getInstance(
62    new DefaultParameterizedType(null, URLNormalizer.class, ExtendedURL.class), "contextpath");
63  1 when(normalizer.normalize(extendedURL)).thenReturn(extendedURL);
64   
65  1 AttachmentReferenceResolver<String> attachmentResolver = this.mocker.getInstance(
66    AttachmentReferenceResolver.TYPE_STRING, "current");
67  1 AttachmentReference attachmentReference = new AttachmentReference("attachment",
68    new DocumentReference("wiki", Arrays.asList("space"), "page"));
69  1 when(attachmentResolver.resolve("attachment")).thenReturn(attachmentReference);
70   
71  1 EntityReferenceSerializer<String> entitySerializer = this.mocker.getInstance(
72    EntityReferenceSerializer.TYPE_STRING);
73  1 when(entitySerializer.serialize(attachmentReference)).thenReturn("wiki:space.page@attachment");
74   
75  1 assertEquals("/vfs/attach%3Awiki%3Aspace.page%40attachment/path1/path2/test.txt",
76    this.mocker.getComponentUnderTest().serialize(reference).toString());
77    }
78    }