| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.test.rest; |
| 21 |
|
|
| 22 |
|
import java.io.StringReader; |
| 23 |
|
import java.util.Arrays; |
| 24 |
|
|
| 25 |
|
import org.apache.commons.httpclient.HttpStatus; |
| 26 |
|
import org.apache.commons.httpclient.methods.GetMethod; |
| 27 |
|
import org.junit.Assert; |
| 28 |
|
import org.junit.Test; |
| 29 |
|
import org.restlet.engine.io.ReaderInputStream; |
| 30 |
|
import org.xwiki.model.reference.AttachmentReference; |
| 31 |
|
import org.xwiki.model.reference.DocumentReference; |
| 32 |
|
import org.xwiki.rest.Relations; |
| 33 |
|
import org.xwiki.rest.model.jaxb.Attachment; |
| 34 |
|
import org.xwiki.rest.model.jaxb.Attachments; |
| 35 |
|
import org.xwiki.rest.model.jaxb.Link; |
| 36 |
|
import org.xwiki.rest.model.jaxb.SearchResult; |
| 37 |
|
import org.xwiki.rest.model.jaxb.SearchResults; |
| 38 |
|
import org.xwiki.rest.model.jaxb.Space; |
| 39 |
|
import org.xwiki.rest.model.jaxb.Spaces; |
| 40 |
|
import org.xwiki.rest.model.jaxb.Wiki; |
| 41 |
|
import org.xwiki.rest.model.jaxb.Wikis; |
| 42 |
|
import org.xwiki.rest.resources.spaces.SpaceAttachmentsResource; |
| 43 |
|
import org.xwiki.rest.resources.spaces.SpaceSearchResource; |
| 44 |
|
import org.xwiki.rest.resources.wikis.WikisResource; |
| 45 |
|
import org.xwiki.test.rest.framework.AbstractHttpTest; |
| 46 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (51) |
Complexity: 4 |
Complexity Density: 0.09 |
|
| 47 |
|
public class SpacesResourceTest extends AbstractHttpTest |
| 48 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 2 |
Complexity Density: 0.09 |
1PASS
|
|
| 49 |
1 |
@Override... |
| 50 |
|
@Test |
| 51 |
|
public void testRepresentation() throws Exception |
| 52 |
|
{ |
| 53 |
|
|
| 54 |
1 |
createPageIfDoesntExist(Arrays.asList("SpaceA", "SpaceB", "SpaceC"), "MyPage", "some content"); |
| 55 |
|
|
| 56 |
1 |
GetMethod getMethod = executeGet(getFullUri(WikisResource.class)); |
| 57 |
1 |
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); |
| 58 |
|
|
| 59 |
1 |
Wikis wikis = (Wikis) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); |
| 60 |
1 |
Assert.assertTrue(wikis.getWikis().size() > 0); |
| 61 |
|
|
| 62 |
1 |
Wiki wiki = wikis.getWikis().get(0); |
| 63 |
1 |
Link link = getFirstLinkByRelation(wiki, Relations.SPACES); |
| 64 |
1 |
Assert.assertNotNull(link); |
| 65 |
|
|
| 66 |
1 |
getMethod = executeGet(link.getHref()); |
| 67 |
1 |
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); |
| 68 |
|
|
| 69 |
1 |
Spaces spaces = (Spaces) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); |
| 70 |
|
|
| 71 |
1 |
Assert.assertTrue(spaces.getSpaces().size() > 0); |
| 72 |
|
|
| 73 |
1 |
boolean nestedSpaceFound = false; |
| 74 |
|
|
| 75 |
1 |
for (Space space : spaces.getSpaces()) { |
| 76 |
9 |
link = getFirstLinkByRelation(space, Relations.SEARCH); |
| 77 |
9 |
Assert.assertNotNull(link); |
| 78 |
|
|
| 79 |
9 |
checkLinks(space); |
| 80 |
|
|
| 81 |
9 |
if ("xwiki:SpaceA.SpaceB.SpaceC".equals(space.getId())) { |
| 82 |
1 |
Assert.assertEquals("SpaceC", space.getName()); |
| 83 |
1 |
nestedSpaceFound = true; |
| 84 |
|
} |
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
| 90 |
9 |
Assert.assertFalse(space.getName().equals("Scheduler")); |
| 91 |
|
} |
| 92 |
|
|
| 93 |
1 |
Assert.assertTrue(nestedSpaceFound); |
| 94 |
|
} |
| 95 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
| 96 |
1 |
@Test... |
| 97 |
|
public void testSearch() throws Exception |
| 98 |
|
{ |
| 99 |
1 |
DocumentReference reference = new DocumentReference(getWiki(), getTestClassName(), getTestMethodName()); |
| 100 |
1 |
this.testUtils.rest().delete(reference); |
| 101 |
1 |
this.testUtils.rest().savePage(reference, "content " + getTestMethodName(), "title " + getTestMethodName()); |
| 102 |
|
|
| 103 |
1 |
GetMethod getMethod = executeGet(String.format("%s?q=somethingthatcannotpossiblyexist", |
| 104 |
|
buildURI(SpaceSearchResource.class, getWiki(), Arrays.asList(getTestClassName())))); |
| 105 |
1 |
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); |
| 106 |
|
|
| 107 |
1 |
SearchResults searchResults = (SearchResults) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); |
| 108 |
|
|
| 109 |
1 |
Assert.assertEquals(0, searchResults.getSearchResults().size()); |
| 110 |
|
|
| 111 |
1 |
getMethod = executeGet(String.format("%s?q=%s", |
| 112 |
|
buildURI(SpaceSearchResource.class, getWiki(), Arrays.asList(getTestClassName())), getTestMethodName())); |
| 113 |
1 |
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); |
| 114 |
|
|
| 115 |
1 |
searchResults = (SearchResults) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); |
| 116 |
|
|
| 117 |
1 |
int resultSize = searchResults.getSearchResults().size(); |
| 118 |
1 |
Assert.assertTrue("Found " + resultSize + " result", resultSize == 1); |
| 119 |
|
|
| 120 |
1 |
for (SearchResult searchResult : searchResults.getSearchResults()) { |
| 121 |
1 |
checkLinks(searchResult); |
| 122 |
|
} |
| 123 |
|
} |
| 124 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
| 125 |
1 |
@Test... |
| 126 |
|
public void testAttachments() throws Exception |
| 127 |
|
{ |
| 128 |
1 |
DocumentReference reference = new DocumentReference(getWiki(), getTestClassName(), getTestMethodName()); |
| 129 |
1 |
this.testUtils.rest().delete(reference); |
| 130 |
1 |
this.testUtils.rest().savePage(reference); |
| 131 |
1 |
this.testUtils.rest().attachFile(new AttachmentReference("attachment.txt", reference), |
| 132 |
|
new ReaderInputStream(new StringReader("content")), true); |
| 133 |
|
|
| 134 |
|
|
| 135 |
1 |
GetMethod getMethod = executeGet(String.format("%s", |
| 136 |
|
buildURI(SpaceAttachmentsResource.class, getWiki(), Arrays.asList(getTestClassName())))); |
| 137 |
1 |
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); |
| 138 |
|
|
| 139 |
1 |
Attachments attachments = (Attachments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); |
| 140 |
|
|
| 141 |
1 |
Assert.assertEquals(getAttachmentsInfo(attachments), 1, attachments.getAttachments().size()); |
| 142 |
|
|
| 143 |
1 |
for (Attachment attachment : attachments.getAttachments()) { |
| 144 |
1 |
checkLinks(attachment); |
| 145 |
|
} |
| 146 |
|
|
| 147 |
|
} |
| 148 |
|
} |