1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.internal.filter

File AbstractInstanceFilterStreamTest.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

2
21
4
1
121
75
7
0.33
5.25
4
1.75

Classes

Class Line # Actions
AbstractInstanceFilterStreamTest 55 21 0% 7 7
0.740740774.1%
 

Contributing tests

This file is covered by 10 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.filter;
21   
22    import java.io.IOException;
23    import java.net.URL;
24    import java.text.ParseException;
25    import java.text.SimpleDateFormat;
26    import java.util.Date;
27    import java.util.Locale;
28   
29    import org.junit.Before;
30    import org.junit.Rule;
31    import org.xwiki.filter.FilterException;
32    import org.xwiki.filter.filterxml.input.FilterXMLInputProperties;
33    import org.xwiki.filter.input.BeanInputFilterStreamFactory;
34    import org.xwiki.filter.input.DefaultURLInputSource;
35    import org.xwiki.filter.input.InputFilterStream;
36    import org.xwiki.filter.input.InputFilterStreamFactory;
37    import org.xwiki.filter.instance.output.InstanceOutputProperties;
38    import org.xwiki.filter.output.BeanOutputFilterStreamFactory;
39    import org.xwiki.filter.output.OutputFilterStream;
40    import org.xwiki.filter.output.OutputFilterStreamFactory;
41    import org.xwiki.filter.type.FilterStreamType;
42    import org.xwiki.test.annotation.AllComponents;
43   
44    import com.xpn.xwiki.test.MockitoOldcoreRule;
45   
46    import static com.xpn.xwiki.test.mockito.OldcoreMatchers.anyXWikiContext;
47    import static org.mockito.Mockito.doReturn;
48   
49    /**
50    * Base class to validate an instance sub {@link OutputInstanceFilterStream}.
51    *
52    * @version $Id: 99d964f1af29def073c916939dcefc3987eae86c $
53    */
54    @AllComponents
 
55    public class AbstractInstanceFilterStreamTest
56    {
57    private static final SimpleDateFormat DATE_PARSER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z", Locale.ENGLISH);
58   
59    @Rule
60    public MockitoOldcoreRule oldcore = new MockitoOldcoreRule();
61   
62    protected BeanInputFilterStreamFactory<FilterXMLInputProperties> xmlInputFilterStreamFactory;
63   
64    protected BeanOutputFilterStreamFactory<InstanceOutputProperties> outputFilterStreamFactory;
65   
 
66  10 toggle @Before
67    public void before() throws Exception
68    {
69  10 this.xmlInputFilterStreamFactory = this.oldcore.getMocker().getInstance(InputFilterStreamFactory.class,
70    FilterStreamType.FILTER_XML.serialize());
71  10 this.outputFilterStreamFactory = this.oldcore.getMocker().getInstance(OutputFilterStreamFactory.class,
72    FilterStreamType.XWIKI_INSTANCE.serialize());
73   
74  10 this.oldcore.getXWikiContext().setWikiId("wiki");
75   
76    // XWiki
77   
78  10 doReturn(true).when(this.oldcore.getSpyXWiki()).hasAttachmentRecycleBin(anyXWikiContext());
79    }
80   
 
81  0 toggle protected void importFromXML(String resource) throws FilterException
82    {
83  0 importFromXML(resource, null);
84    }
85   
 
86  10 toggle protected void importFromXML(String resource, InstanceOutputProperties instanceProperties) throws FilterException
87    {
88  10 if (instanceProperties == null) {
89  0 instanceProperties = new InstanceOutputProperties();
90  0 instanceProperties.setVerbose(false);
91    }
92   
93  10 OutputFilterStream outputFilterStream =
94    this.outputFilterStreamFactory.createOutputFilterStream(instanceProperties);
95   
96  10 URL url = getClass().getResource("/filter/" + resource + ".xml");
97   
98  10 FilterXMLInputProperties properties = new FilterXMLInputProperties();
99  10 properties.setSource(new DefaultURLInputSource(url));
100   
101  10 InputFilterStream inputFilterStream = this.xmlInputFilterStreamFactory.createInputFilterStream(properties);
102   
103  10 inputFilterStream.read(outputFilterStream.getFilter());
104   
105  10 try {
106  10 inputFilterStream.close();
107    } catch (IOException e) {
108  0 throw new FilterException("Failed to close input wiki stream", e);
109    }
110  10 try {
111  10 outputFilterStream.close();
112    } catch (IOException e) {
113  0 throw new FilterException("Failed to close output wiki stream", e);
114    }
115    }
116   
 
117  17 toggle protected Date toDate(String date) throws ParseException
118    {
119  17 return DATE_PARSER.parse(date);
120    }
121    }