| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package com.xpn.xwiki.web; |
| 21 |
|
|
| 22 |
|
import java.util.Arrays; |
| 23 |
|
|
| 24 |
|
import javax.servlet.ServletOutputStream; |
| 25 |
|
|
| 26 |
|
import org.junit.Rule; |
| 27 |
|
import org.junit.Test; |
| 28 |
|
import org.mockito.ArgumentCaptor; |
| 29 |
|
import org.xwiki.filter.input.InputFilterStream; |
| 30 |
|
import org.xwiki.filter.input.InputFilterStreamFactory; |
| 31 |
|
import org.xwiki.filter.instance.input.DocumentInstanceInputProperties; |
| 32 |
|
import org.xwiki.filter.output.BeanOutputFilterStream; |
| 33 |
|
import org.xwiki.filter.output.BeanOutputFilterStreamFactory; |
| 34 |
|
import org.xwiki.filter.output.OutputFilterStreamFactory; |
| 35 |
|
import org.xwiki.filter.type.FilterStreamType; |
| 36 |
|
import org.xwiki.filter.xar.output.XAROutputProperties; |
| 37 |
|
import org.xwiki.model.reference.DocumentReference; |
| 38 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
| 39 |
|
|
| 40 |
|
import static org.mockito.Mockito.*; |
| 41 |
|
import static org.junit.Assert.*; |
| 42 |
|
|
| 43 |
|
import com.xpn.xwiki.XWikiContext; |
| 44 |
|
import com.xpn.xwiki.test.MockitoOldcoreRule; |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
@link |
| 48 |
|
|
| 49 |
|
@version |
| 50 |
|
@since |
| 51 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (33) |
Complexity: 1 |
Complexity Density: 0.03 |
|
| 52 |
|
public class ExportActionTest |
| 53 |
|
{ |
| 54 |
|
@Rule |
| 55 |
|
public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(); |
| 56 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
| 57 |
1 |
@Test... |
| 58 |
|
public void exportFullSpaceUsingWildcardsAsXAR() throws Exception |
| 59 |
|
{ |
| 60 |
1 |
ExportAction action = new ExportAction(); |
| 61 |
|
|
| 62 |
1 |
XWikiContext context = oldcore.getXWikiContext(); |
| 63 |
|
|
| 64 |
|
|
| 65 |
1 |
XWikiRequest request = mock(XWikiRequest.class); |
| 66 |
1 |
when(request.get("format")).thenReturn("xar"); |
| 67 |
1 |
context.setRequest(request); |
| 68 |
|
|
| 69 |
|
|
| 70 |
1 |
when(request.get("name")).thenReturn("myexport"); |
| 71 |
|
|
| 72 |
1 |
when(request.getParameterValues("pages")).thenReturn(new String[] {"Space.%"}); |
| 73 |
|
|
| 74 |
|
|
| 75 |
1 |
when(oldcore.getMockRightService().hasWikiAdminRights(context)).thenReturn(true); |
| 76 |
|
|
| 77 |
|
|
| 78 |
1 |
when(oldcore.getMockStore().searchDocumentsNames("where doc.fullName like ?", Arrays.asList("Space.%"), |
| 79 |
|
context)).thenReturn(Arrays.asList("Space.Page1", "Space.Page2")); |
| 80 |
1 |
when(oldcore.getMockRightService().hasAccessLevel("view", "XWiki.XWikiGuest", "xwiki:Space.Page1", context)) |
| 81 |
|
.thenReturn(true); |
| 82 |
1 |
when(oldcore.getMockRightService().hasAccessLevel("view", "XWiki.XWikiGuest", "xwiki:Space.Page2", context)) |
| 83 |
|
.thenReturn(true); |
| 84 |
1 |
DocumentReferenceResolver<String> resolver = |
| 85 |
|
oldcore.getMocker().registerMockComponent(DocumentReferenceResolver.TYPE_STRING, "current"); |
| 86 |
1 |
when(resolver.resolve("xwiki:Space.Page1")).thenReturn(new DocumentReference("xwiki", "Space", "Page1")); |
| 87 |
1 |
when(resolver.resolve("xwiki:Space.Page2")).thenReturn(new DocumentReference("xwiki", "Space", "Page2")); |
| 88 |
|
|
| 89 |
|
|
| 90 |
1 |
InputFilterStreamFactory inputFilterStreamFactory = oldcore.getMocker().registerMockComponent( |
| 91 |
|
InputFilterStreamFactory.class, FilterStreamType.XWIKI_INSTANCE.serialize()); |
| 92 |
1 |
when(inputFilterStreamFactory.createInputFilterStream(anyMap())).thenReturn(mock(InputFilterStream.class)); |
| 93 |
1 |
BeanOutputFilterStreamFactory beanOutputFilterStreamFactory = mock(BeanOutputFilterStreamFactory.class); |
| 94 |
1 |
oldcore.getMocker().registerComponent(OutputFilterStreamFactory.class, |
| 95 |
|
FilterStreamType.XWIKI_XAR_CURRENT.serialize(), beanOutputFilterStreamFactory); |
| 96 |
1 |
when(beanOutputFilterStreamFactory.createOutputFilterStream(any(XAROutputProperties.class))).thenReturn( |
| 97 |
|
mock(BeanOutputFilterStream.class)); |
| 98 |
|
|
| 99 |
|
|
| 100 |
1 |
XWikiResponse response = mock(XWikiResponse.class); |
| 101 |
1 |
ServletOutputStream outputStream = mock(ServletOutputStream.class); |
| 102 |
1 |
when(response.getOutputStream()).thenReturn(outputStream); |
| 103 |
1 |
context.setResponse(response); |
| 104 |
|
|
| 105 |
1 |
String result = action.render(oldcore.getXWikiContext()); |
| 106 |
|
|
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
1 |
assertNull(result); |
| 111 |
|
|
| 112 |
|
|
| 113 |
1 |
ArgumentCaptor<DocumentInstanceInputProperties> properties = |
| 114 |
|
ArgumentCaptor.forClass(DocumentInstanceInputProperties.class); |
| 115 |
1 |
verify(inputFilterStreamFactory).createInputFilterStream(properties.capture()); |
| 116 |
1 |
assertEquals(false, properties.getValue().isVerbose()); |
| 117 |
1 |
assertEquals(false, properties.getValue().isWithJRCSRevisions()); |
| 118 |
1 |
assertEquals(false, properties.getValue().isWithRevisions()); |
| 119 |
1 |
assertEquals(true, properties.getValue().getEntities().matches( |
| 120 |
|
new DocumentReference("xwiki", "Space", "Page1"))); |
| 121 |
1 |
assertEquals(true, properties.getValue().getEntities().matches( |
| 122 |
|
new DocumentReference("xwiki", "Space", "Page2"))); |
| 123 |
|
} |
| 124 |
|
} |