| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.test.ui; |
| 21 |
|
|
| 22 |
|
import java.io.ByteArrayInputStream; |
| 23 |
|
import java.io.ByteArrayOutputStream; |
| 24 |
|
import java.io.File; |
| 25 |
|
import java.io.FileInputStream; |
| 26 |
|
import java.io.InputStream; |
| 27 |
|
import java.net.URI; |
| 28 |
|
import java.net.URLEncoder; |
| 29 |
|
import java.util.ArrayList; |
| 30 |
|
import java.util.Arrays; |
| 31 |
|
import java.util.Collections; |
| 32 |
|
import java.util.HashMap; |
| 33 |
|
import java.util.HashSet; |
| 34 |
|
import java.util.IdentityHashMap; |
| 35 |
|
import java.util.List; |
| 36 |
|
import java.util.Locale; |
| 37 |
|
import java.util.Map; |
| 38 |
|
import java.util.Set; |
| 39 |
|
import java.util.regex.Matcher; |
| 40 |
|
import java.util.regex.Pattern; |
| 41 |
|
|
| 42 |
|
import javax.ws.rs.core.MediaType; |
| 43 |
|
import javax.ws.rs.core.Response.Status; |
| 44 |
|
import javax.ws.rs.core.UriBuilder; |
| 45 |
|
import javax.xml.bind.JAXBContext; |
| 46 |
|
import javax.xml.bind.JAXBException; |
| 47 |
|
import javax.xml.bind.Marshaller; |
| 48 |
|
import javax.xml.bind.Unmarshaller; |
| 49 |
|
|
| 50 |
|
import org.apache.commons.httpclient.HttpClient; |
| 51 |
|
import org.apache.commons.httpclient.HttpMethod; |
| 52 |
|
import org.apache.commons.httpclient.UsernamePasswordCredentials; |
| 53 |
|
import org.apache.commons.httpclient.auth.AuthScope; |
| 54 |
|
import org.apache.commons.httpclient.methods.DeleteMethod; |
| 55 |
|
import org.apache.commons.httpclient.methods.EntityEnclosingMethod; |
| 56 |
|
import org.apache.commons.httpclient.methods.GetMethod; |
| 57 |
|
import org.apache.commons.httpclient.methods.InputStreamRequestEntity; |
| 58 |
|
import org.apache.commons.httpclient.methods.PostMethod; |
| 59 |
|
import org.apache.commons.httpclient.methods.PutMethod; |
| 60 |
|
import org.apache.commons.httpclient.methods.RequestEntity; |
| 61 |
|
import org.apache.commons.io.IOUtils; |
| 62 |
|
import org.apache.commons.lang.ArrayUtils; |
| 63 |
|
import org.apache.commons.lang.StringUtils; |
| 64 |
|
import org.junit.Assert; |
| 65 |
|
import org.openqa.selenium.By; |
| 66 |
|
import org.openqa.selenium.Cookie; |
| 67 |
|
import org.openqa.selenium.NoSuchElementException; |
| 68 |
|
import org.openqa.selenium.WebDriver; |
| 69 |
|
import org.openqa.selenium.WebElement; |
| 70 |
|
import org.openqa.selenium.support.ui.ExpectedCondition; |
| 71 |
|
import org.xwiki.component.manager.ComponentManager; |
| 72 |
|
import org.xwiki.model.EntityType; |
| 73 |
|
import org.xwiki.model.reference.AttachmentReference; |
| 74 |
|
import org.xwiki.model.reference.DocumentReference; |
| 75 |
|
import org.xwiki.model.reference.EntityReference; |
| 76 |
|
import org.xwiki.model.reference.EntityReferenceResolver; |
| 77 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
| 78 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
| 79 |
|
import org.xwiki.rest.model.jaxb.Page; |
| 80 |
|
import org.xwiki.rest.model.jaxb.Property; |
| 81 |
|
import org.xwiki.rest.model.jaxb.Xwiki; |
| 82 |
|
import org.xwiki.rest.resources.attachments.AttachmentResource; |
| 83 |
|
import org.xwiki.rest.resources.classes.ClassPropertyResource; |
| 84 |
|
import org.xwiki.rest.resources.objects.ObjectPropertyResource; |
| 85 |
|
import org.xwiki.rest.resources.objects.ObjectResource; |
| 86 |
|
import org.xwiki.rest.resources.objects.ObjectsResource; |
| 87 |
|
import org.xwiki.rest.resources.pages.PageResource; |
| 88 |
|
import org.xwiki.rest.resources.pages.PageTranslationResource; |
| 89 |
|
import org.xwiki.test.integration.XWikiExecutor; |
| 90 |
|
import org.xwiki.test.ui.po.ViewPage; |
| 91 |
|
import org.xwiki.test.ui.po.editor.ClassEditPage; |
| 92 |
|
import org.xwiki.test.ui.po.editor.ObjectEditPage; |
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
@version |
| 98 |
|
@since |
| 99 |
|
|
| |
|
| 85.5% |
Uncovered Elements: 87 (601) |
Complexity: 209 |
Complexity Density: 0.59 |
|
| 100 |
|
public class TestUtils |
| 101 |
|
{ |
| 102 |
|
|
| 103 |
|
@since |
| 104 |
|
|
| 105 |
|
public static final UsernamePasswordCredentials ADMIN_CREDENTIALS = |
| 106 |
|
new UsernamePasswordCredentials("Admin", "admin"); |
| 107 |
|
|
| 108 |
|
|
| 109 |
|
@since |
| 110 |
|
|
| 111 |
|
public static final UsernamePasswordCredentials SUPER_ADMIN_CREDENTIALS = |
| 112 |
|
new UsernamePasswordCredentials("superadmin", "pass"); |
| 113 |
|
|
| 114 |
|
|
| 115 |
|
@since |
| 116 |
|
@deprecated@link |
| 117 |
|
|
| 118 |
|
@Deprecated |
| 119 |
|
public static final String BASE_URL = XWikiExecutor.URL + ":" + XWikiExecutor.DEFAULT_PORT + "/xwiki/"; |
| 120 |
|
|
| 121 |
|
|
| 122 |
|
@since |
| 123 |
|
@deprecated@link |
| 124 |
|
|
| 125 |
|
@Deprecated |
| 126 |
|
public static final String BASE_BIN_URL = BASE_URL + "bin/"; |
| 127 |
|
|
| 128 |
|
|
| 129 |
|
@since |
| 130 |
|
@deprecated@link |
| 131 |
|
|
| 132 |
|
@Deprecated |
| 133 |
|
public static final String BASE_REST_URL = BASE_URL + "rest/"; |
| 134 |
|
|
| 135 |
|
|
| 136 |
|
@since |
| 137 |
|
|
| 138 |
|
public static final int[] STATUS_OK_NOT_FOUND = |
| 139 |
|
new int[] { Status.OK.getStatusCode(), Status.NOT_FOUND.getStatusCode() }; |
| 140 |
|
|
| 141 |
|
|
| 142 |
|
@since |
| 143 |
|
|
| 144 |
|
public static final int[] STATUS_OK = new int[] { Status.OK.getStatusCode() }; |
| 145 |
|
|
| 146 |
|
|
| 147 |
|
@since |
| 148 |
|
|
| 149 |
|
public static final int[] STATUS_NO_CONTENT = new int[] { Status.NO_CONTENT.getStatusCode() }; |
| 150 |
|
|
| 151 |
|
|
| 152 |
|
@since |
| 153 |
|
|
| 154 |
|
public static final int[] STATUS_NO_CONTENT_NOT_FOUND = |
| 155 |
|
new int[] { Status.NO_CONTENT.getStatusCode(), Status.NOT_FOUND.getStatusCode() }; |
| 156 |
|
|
| 157 |
|
|
| 158 |
|
@since |
| 159 |
|
|
| 160 |
|
public static final int[] STATUS_CREATED_ACCEPTED = |
| 161 |
|
new int[] { Status.CREATED.getStatusCode(), Status.ACCEPTED.getStatusCode() }; |
| 162 |
|
|
| 163 |
|
|
| 164 |
|
@since |
| 165 |
|
|
| 166 |
|
public static final int[] STATUS_CREATED = new int[] { Status.CREATED.getStatusCode() }; |
| 167 |
|
|
| 168 |
|
private static PersistentTestContext context; |
| 169 |
|
|
| 170 |
|
private static ComponentManager componentManager; |
| 171 |
|
|
| 172 |
|
private static EntityReferenceResolver<String> relativeReferenceResolver; |
| 173 |
|
|
| 174 |
|
private static EntityReferenceSerializer<String> referenceSerializer; |
| 175 |
|
|
| 176 |
|
private static EntityReferenceResolver<String> referenceResolver; |
| 177 |
|
|
| 178 |
|
|
| 179 |
|
|
| 180 |
|
|
| 181 |
|
private static Marshaller marshaller; |
| 182 |
|
|
| 183 |
|
|
| 184 |
|
|
| 185 |
|
|
| 186 |
|
private static Unmarshaller unmarshaller; |
| 187 |
|
|
| 188 |
|
|
| 189 |
|
private String secretToken = null; |
| 190 |
|
|
| 191 |
|
private HttpClient httpClient; |
| 192 |
|
|
| 193 |
|
|
| 194 |
|
@since |
| 195 |
|
|
| 196 |
|
private List<XWikiExecutor> executors; |
| 197 |
|
|
| 198 |
|
|
| 199 |
|
@since |
| 200 |
|
|
| 201 |
|
private int currentExecutorIndex; |
| 202 |
|
|
| 203 |
|
|
| 204 |
|
@since |
| 205 |
|
|
| 206 |
|
private String currentWiki = "xwiki"; |
| 207 |
|
|
| 208 |
|
private RestTestUtils rest; |
| 209 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 210 |
117 |
public TestUtils()... |
| 211 |
|
{ |
| 212 |
117 |
this.httpClient = new HttpClient(); |
| 213 |
117 |
this.httpClient.getState().setCredentials(AuthScope.ANY, SUPER_ADMIN_CREDENTIALS); |
| 214 |
117 |
this.httpClient.getParams().setAuthenticationPreemptive(true); |
| 215 |
|
|
| 216 |
117 |
this.rest = new RestTestUtils(this); |
| 217 |
|
} |
| 218 |
|
|
| 219 |
|
|
| 220 |
|
@since |
| 221 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
| 222 |
20290 |
public XWikiExecutor getCurrentExecutor()... |
| 223 |
|
{ |
| 224 |
20290 |
return this.executors != null && this.executors.size() > this.currentExecutorIndex |
| 225 |
|
? this.executors.get(this.currentExecutorIndex) : null; |
| 226 |
|
} |
| 227 |
|
|
| 228 |
|
|
| 229 |
|
@since |
| 230 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 231 |
586 |
public void switchExecutor(int index)... |
| 232 |
|
{ |
| 233 |
586 |
this.currentExecutorIndex = index; |
| 234 |
|
} |
| 235 |
|
|
| 236 |
|
|
| 237 |
|
@since |
| 238 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 239 |
32 |
public void setExecutors(List<XWikiExecutor> executors)... |
| 240 |
|
{ |
| 241 |
32 |
this.executors = executors; |
| 242 |
|
} |
| 243 |
|
|
| 244 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 245 |
32 |
public static void setContext(PersistentTestContext context)... |
| 246 |
|
{ |
| 247 |
32 |
TestUtils.context = context; |
| 248 |
|
} |
| 249 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 250 |
33 |
public static void initializeComponent(ComponentManager componentManager) throws Exception... |
| 251 |
|
{ |
| 252 |
33 |
TestUtils.componentManager = componentManager; |
| 253 |
33 |
TestUtils.relativeReferenceResolver = |
| 254 |
|
TestUtils.componentManager.getInstance(EntityReferenceResolver.TYPE_STRING, "relative"); |
| 255 |
33 |
TestUtils.referenceResolver = TestUtils.componentManager.getInstance(EntityReferenceResolver.TYPE_STRING); |
| 256 |
33 |
TestUtils.referenceSerializer = TestUtils.componentManager.getInstance(EntityReferenceSerializer.TYPE_STRING); |
| 257 |
|
} |
| 258 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 259 |
4947 |
public XWikiWebDriver getDriver()... |
| 260 |
|
{ |
| 261 |
4947 |
return context.getDriver(); |
| 262 |
|
} |
| 263 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 264 |
32 |
public Session getSession()... |
| 265 |
|
{ |
| 266 |
32 |
return this.new Session(getDriver().manage().getCookies(), getSecretToken()); |
| 267 |
|
} |
| 268 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 269 |
107 |
public void setSession(Session session)... |
| 270 |
|
{ |
| 271 |
107 |
WebDriver.Options options = getDriver().manage(); |
| 272 |
107 |
options.deleteAllCookies(); |
| 273 |
107 |
if (session != null) { |
| 274 |
38 |
for (Cookie cookie : session.getCookies()) { |
| 275 |
153 |
options.addCookie(cookie); |
| 276 |
|
} |
| 277 |
|
} |
| 278 |
107 |
if (session != null && !StringUtils.isEmpty(session.getSecretToken())) { |
| 279 |
38 |
this.secretToken = session.getSecretToken(); |
| 280 |
|
} else { |
| 281 |
69 |
recacheSecretToken(); |
| 282 |
|
} |
| 283 |
|
} |
| 284 |
|
|
| 285 |
|
|
| 286 |
|
@since |
| 287 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 288 |
89 |
public void setDefaultCredentials(String username, String password)... |
| 289 |
|
{ |
| 290 |
89 |
setDefaultCredentials(new UsernamePasswordCredentials(username, password)); |
| 291 |
|
} |
| 292 |
|
|
| 293 |
|
|
| 294 |
|
@since |
| 295 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 296 |
160 |
public UsernamePasswordCredentials setDefaultCredentials(UsernamePasswordCredentials defaultCredentials)... |
| 297 |
|
{ |
| 298 |
160 |
UsernamePasswordCredentials currentCredentials = getDefaultCredentials(); |
| 299 |
|
|
| 300 |
160 |
this.httpClient.getState().setCredentials(AuthScope.ANY, defaultCredentials); |
| 301 |
|
|
| 302 |
160 |
return currentCredentials; |
| 303 |
|
} |
| 304 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 305 |
164 |
public UsernamePasswordCredentials getDefaultCredentials()... |
| 306 |
|
{ |
| 307 |
164 |
return (UsernamePasswordCredentials) this.httpClient.getState().getCredentials(AuthScope.ANY); |
| 308 |
|
} |
| 309 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 310 |
6 |
public void loginAsSuperAdmin()... |
| 311 |
|
{ |
| 312 |
6 |
login(SUPER_ADMIN_CREDENTIALS.getUserName(), SUPER_ADMIN_CREDENTIALS.getPassword()); |
| 313 |
|
} |
| 314 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 315 |
4 |
public void loginAsSuperAdminAndGotoPage(String pageURL)... |
| 316 |
|
{ |
| 317 |
4 |
loginAndGotoPage(SUPER_ADMIN_CREDENTIALS.getUserName(), SUPER_ADMIN_CREDENTIALS.getPassword(), pageURL); |
| 318 |
|
} |
| 319 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 320 |
3 |
public void loginAsAdmin()... |
| 321 |
|
{ |
| 322 |
3 |
login(ADMIN_CREDENTIALS.getUserName(), ADMIN_CREDENTIALS.getPassword()); |
| 323 |
|
} |
| 324 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 325 |
0 |
public void loginAsAdminAndGotoPage(String pageURL)... |
| 326 |
|
{ |
| 327 |
0 |
loginAndGotoPage(ADMIN_CREDENTIALS.getUserName(), ADMIN_CREDENTIALS.getPassword(), pageURL); |
| 328 |
|
} |
| 329 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 330 |
178 |
public void login(String username, String password)... |
| 331 |
|
{ |
| 332 |
178 |
loginAndGotoPage(username, password, null); |
| 333 |
|
} |
| 334 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 335 |
184 |
public void loginAndGotoPage(String username, String password, String pageURL)... |
| 336 |
|
{ |
| 337 |
184 |
if (!username.equals(getLoggedInUserName())) { |
| 338 |
|
|
| 339 |
|
|
| 340 |
|
|
| 341 |
53 |
getDriver().get(getURLToLoginAndGotoPage(username, password, getURL("XWiki", "Register", "register"))); |
| 342 |
53 |
recacheSecretTokenWhenOnRegisterPage(); |
| 343 |
53 |
if (pageURL != null) { |
| 344 |
|
|
| 345 |
6 |
getDriver().get(pageURL); |
| 346 |
|
} else { |
| 347 |
47 |
getDriver().get(getURLToNonExistentPage()); |
| 348 |
|
} |
| 349 |
|
|
| 350 |
53 |
setDefaultCredentials(username, password); |
| 351 |
|
} |
| 352 |
|
} |
| 353 |
|
|
| 354 |
|
|
| 355 |
|
|
| 356 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 357 |
0 |
public String getURLToLogout()... |
| 358 |
|
{ |
| 359 |
0 |
return getURL("XWiki", "XWikiLogin", "logout"); |
| 360 |
|
} |
| 361 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 362 |
7 |
public String getURLToLoginAsAdmin()... |
| 363 |
|
{ |
| 364 |
7 |
return getURLToLoginAs(ADMIN_CREDENTIALS.getUserName(), ADMIN_CREDENTIALS.getPassword()); |
| 365 |
|
} |
| 366 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 367 |
0 |
public String getURLToLoginAsSuperAdmin()... |
| 368 |
|
{ |
| 369 |
0 |
return getURLToLoginAs(SUPER_ADMIN_CREDENTIALS.getUserName(), SUPER_ADMIN_CREDENTIALS.getPassword()); |
| 370 |
|
} |
| 371 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 372 |
12 |
public String getURLToLoginAs(final String username, final String password)... |
| 373 |
|
{ |
| 374 |
12 |
return getURLToLoginAndGotoPage(username, password, null); |
| 375 |
|
} |
| 376 |
|
|
| 377 |
|
|
| 378 |
|
@param |
| 379 |
|
@return |
| 380 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 381 |
36 |
public String getURLToLoginAsAdminAndGotoPage(final String pageURL)... |
| 382 |
|
{ |
| 383 |
36 |
return getURLToLoginAndGotoPage(ADMIN_CREDENTIALS.getUserName(), ADMIN_CREDENTIALS.getPassword(), pageURL); |
| 384 |
|
} |
| 385 |
|
|
| 386 |
|
|
| 387 |
|
@param |
| 388 |
|
@return |
| 389 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 390 |
0 |
public String getURLToLoginAsSuperAdminAndGotoPage(final String pageURL)... |
| 391 |
|
{ |
| 392 |
0 |
return getURLToLoginAndGotoPage(SUPER_ADMIN_CREDENTIALS.getUserName(), SUPER_ADMIN_CREDENTIALS.getPassword(), |
| 393 |
|
pageURL); |
| 394 |
|
} |
| 395 |
|
|
| 396 |
|
|
| 397 |
|
@param |
| 398 |
|
@param |
| 399 |
|
@param |
| 400 |
|
@return |
| 401 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 402 |
134 |
public String getURLToLoginAndGotoPage(final String username, final String password, final String pageURL)... |
| 403 |
|
{ |
| 404 |
134 |
Map<String, String> parameters = new HashMap<String, String>() |
| 405 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 406 |
134 |
{... |
| 407 |
134 |
put("j_username", username); |
| 408 |
134 |
put("j_password", password); |
| 409 |
134 |
if (pageURL != null && pageURL.length() > 0) { |
| 410 |
122 |
put("xredirect", pageURL); |
| 411 |
|
} |
| 412 |
|
} |
| 413 |
|
}; |
| 414 |
134 |
return getURL("XWiki", "XWikiLogin", "loginsubmit", parameters); |
| 415 |
|
} |
| 416 |
|
|
| 417 |
|
|
| 418 |
|
@return |
| 419 |
|
|
| 420 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 421 |
115 |
public String getURLToNonExistentPage()... |
| 422 |
|
{ |
| 423 |
115 |
return getURL("NonExistentSpace", "NonExistentPage", "view", "xpage=plain"); |
| 424 |
|
} |
| 425 |
|
|
| 426 |
|
|
| 427 |
|
|
| 428 |
|
|
| 429 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 430 |
4 |
public void assertOnPage(final String pageURL)... |
| 431 |
|
{ |
| 432 |
4 |
final String pageURI = pageURL.replaceAll("\\?.*", ""); |
| 433 |
4 |
getDriver().waitUntilCondition(new ExpectedCondition<Boolean>() |
| 434 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 435 |
4 |
@Override... |
| 436 |
|
public Boolean apply(WebDriver driver) |
| 437 |
|
{ |
| 438 |
4 |
return getDriver().getCurrentUrl().contains(pageURI); |
| 439 |
|
} |
| 440 |
|
}); |
| 441 |
|
} |
| 442 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 443 |
185 |
public String getLoggedInUserName()... |
| 444 |
|
{ |
| 445 |
185 |
By userAvatarInDrawer = By.id("tmUser"); |
| 446 |
185 |
if (!getDriver().hasElementWithoutWaiting(userAvatarInDrawer)) { |
| 447 |
|
|
| 448 |
39 |
return null; |
| 449 |
|
} |
| 450 |
|
|
| 451 |
146 |
WebElement element = getDriver().findElementWithoutWaiting(userAvatarInDrawer); |
| 452 |
146 |
String href = element.getAttribute("href"); |
| 453 |
146 |
String loggedInUserName = href.substring(href.lastIndexOf("/") + 1); |
| 454 |
|
|
| 455 |
|
|
| 456 |
146 |
return loggedInUserName; |
| 457 |
|
} |
| 458 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 459 |
33 |
public void createUserAndLogin(final String username, final String password, Object... properties)... |
| 460 |
|
{ |
| 461 |
33 |
createUserAndLoginWithRedirect(username, password, getURLToNonExistentPage(), properties); |
| 462 |
|
} |
| 463 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 464 |
33 |
public void createUserAndLoginWithRedirect(final String username, final String password, String url,... |
| 465 |
|
Object... properties) |
| 466 |
|
{ |
| 467 |
33 |
createUser(username, password, getURLToLoginAndGotoPage(username, password, url), properties); |
| 468 |
|
|
| 469 |
33 |
setDefaultCredentials(username, password); |
| 470 |
|
} |
| 471 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 2 |
Complexity Density: 0.17 |
|
| 472 |
39 |
public void createUser(final String username, final String password, String redirectURL, Object... properties)... |
| 473 |
|
{ |
| 474 |
39 |
Map<String, String> parameters = new HashMap<String, String>(); |
| 475 |
39 |
parameters.put("register", "1"); |
| 476 |
39 |
parameters.put("xwikiname", username); |
| 477 |
39 |
parameters.put("register_password", password); |
| 478 |
39 |
parameters.put("register2_password", password); |
| 479 |
39 |
parameters.put("register_email", ""); |
| 480 |
39 |
parameters.put("xredirect", redirectURL); |
| 481 |
39 |
parameters.put("form_token", getSecretToken()); |
| 482 |
39 |
getDriver().get(getURL("XWiki", "Register", "register", parameters)); |
| 483 |
39 |
recacheSecretToken(); |
| 484 |
39 |
if (properties.length > 0) { |
| 485 |
9 |
updateObject("XWiki", username, "XWiki.XWikiUsers", 0, properties); |
| 486 |
|
} |
| 487 |
|
} |
| 488 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 489 |
132 |
public ViewPage gotoPage(String space, String page)... |
| 490 |
|
{ |
| 491 |
132 |
gotoPage(space, page, "view"); |
| 492 |
132 |
return new ViewPage(); |
| 493 |
|
} |
| 494 |
|
|
| 495 |
|
|
| 496 |
|
@since |
| 497 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 498 |
18 |
public ViewPage gotoPage(EntityReference reference)... |
| 499 |
|
{ |
| 500 |
18 |
gotoPage(reference, "view"); |
| 501 |
18 |
return new ViewPage(); |
| 502 |
|
} |
| 503 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 504 |
769 |
public void gotoPage(String space, String page, String action)... |
| 505 |
|
{ |
| 506 |
769 |
gotoPage(space, page, action, ""); |
| 507 |
|
} |
| 508 |
|
|
| 509 |
|
|
| 510 |
|
@since |
| 511 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 512 |
23 |
public void gotoPage(EntityReference reference, String action)... |
| 513 |
|
{ |
| 514 |
23 |
gotoPage(reference, action, ""); |
| 515 |
|
} |
| 516 |
|
|
| 517 |
|
|
| 518 |
|
@since |
| 519 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 520 |
32 |
public void gotoPage(String space, String page, String action, Object... queryParameters)... |
| 521 |
|
{ |
| 522 |
32 |
gotoPage(space, page, action, toQueryString(queryParameters)); |
| 523 |
|
} |
| 524 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 525 |
16 |
public void gotoPage(String space, String page, String action, Map<String, ?> queryParameters)... |
| 526 |
|
{ |
| 527 |
16 |
gotoPage(Collections.singletonList(space), page, action, queryParameters); |
| 528 |
|
} |
| 529 |
|
|
| 530 |
|
|
| 531 |
|
@since |
| 532 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 533 |
124 |
public void gotoPage(List<String> spaces, String page, String action, Map<String, ?> queryParameters)... |
| 534 |
|
{ |
| 535 |
124 |
gotoPage(spaces, page, action, toQueryString(queryParameters)); |
| 536 |
|
} |
| 537 |
|
|
| 538 |
|
|
| 539 |
|
@since |
| 540 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 541 |
85 |
public void gotoPage(EntityReference reference, String action, Map<String, ?> queryParameters)... |
| 542 |
|
{ |
| 543 |
85 |
gotoPage(reference, action, toQueryString(queryParameters)); |
| 544 |
|
} |
| 545 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 546 |
927 |
public void gotoPage(String space, String page, String action, String queryString)... |
| 547 |
|
{ |
| 548 |
927 |
gotoPage(Collections.singletonList(space), page, action, queryString); |
| 549 |
|
} |
| 550 |
|
|
| 551 |
|
|
| 552 |
|
@since |
| 553 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 554 |
1055 |
public void gotoPage(List<String> spaces, String page, String action, String queryString)... |
| 555 |
|
{ |
| 556 |
1055 |
gotoPage(getURL(spaces, page, action, queryString)); |
| 557 |
|
} |
| 558 |
|
|
| 559 |
|
|
| 560 |
|
@since |
| 561 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 562 |
110 |
public void gotoPage(EntityReference reference, String action, String queryString)... |
| 563 |
|
{ |
| 564 |
110 |
gotoPage(getURL(reference, action, queryString)); |
| 565 |
|
|
| 566 |
|
|
| 567 |
110 |
EntityReference wikiReference = reference.extractReference(EntityType.WIKI); |
| 568 |
110 |
if (wikiReference != null) { |
| 569 |
32 |
this.currentWiki = wikiReference.getName(); |
| 570 |
|
} |
| 571 |
|
} |
| 572 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 573 |
1225 |
public void gotoPage(String url)... |
| 574 |
|
{ |
| 575 |
|
|
| 576 |
1225 |
if (!getDriver().getCurrentUrl().equals(url)) { |
| 577 |
1217 |
getDriver().get(url); |
| 578 |
|
} |
| 579 |
|
} |
| 580 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 581 |
34 |
public String getURLToDeletePage(String space, String page)... |
| 582 |
|
{ |
| 583 |
34 |
return getURL(space, page, "delete", "confirm=1"); |
| 584 |
|
} |
| 585 |
|
|
| 586 |
|
|
| 587 |
|
@since |
| 588 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 589 |
3 |
public String getURLToDeletePage(EntityReference reference)... |
| 590 |
|
{ |
| 591 |
3 |
return getURL(reference, "delete", "confirm=1"); |
| 592 |
|
} |
| 593 |
|
|
| 594 |
|
|
| 595 |
|
@param |
| 596 |
|
@return |
| 597 |
|
@since |
| 598 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 599 |
29 |
public String getURLToDeleteSpace(String space)... |
| 600 |
|
{ |
| 601 |
29 |
return getURL(space, "WebHome", "deletespace", "confirm=1&async=false&affectChidlren=on"); |
| 602 |
|
} |
| 603 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 604 |
62 |
public ViewPage createPage(String space, String page, String content, String title)... |
| 605 |
|
{ |
| 606 |
62 |
return createPage(Collections.singletonList(space), page, content, title); |
| 607 |
|
} |
| 608 |
|
|
| 609 |
|
|
| 610 |
|
@since |
| 611 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 612 |
9 |
public ViewPage createPage(EntityReference reference, String content, String title)... |
| 613 |
|
{ |
| 614 |
9 |
return createPage(reference, content, title, null); |
| 615 |
|
} |
| 616 |
|
|
| 617 |
|
|
| 618 |
|
@since |
| 619 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 620 |
68 |
public ViewPage createPage(List<String> spaces, String page, String content, String title)... |
| 621 |
|
{ |
| 622 |
68 |
return createPage(spaces, page, content, title, null); |
| 623 |
|
} |
| 624 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 625 |
9 |
public ViewPage createPage(String space, String page, String content, String title, String syntaxId)... |
| 626 |
|
{ |
| 627 |
9 |
return createPage(Collections.singletonList(space), page, content, title, syntaxId); |
| 628 |
|
} |
| 629 |
|
|
| 630 |
|
|
| 631 |
|
@since |
| 632 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 633 |
9 |
public ViewPage createPage(EntityReference reference, String content, String title, String syntaxId)... |
| 634 |
|
{ |
| 635 |
9 |
return createPage(reference, content, title, syntaxId, null); |
| 636 |
|
} |
| 637 |
|
|
| 638 |
|
|
| 639 |
|
@since |
| 640 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 641 |
77 |
public ViewPage createPage(List<String> spaces, String page, String content, String title, String syntaxId)... |
| 642 |
|
{ |
| 643 |
77 |
return createPage(spaces, page, content, title, syntaxId, null); |
| 644 |
|
} |
| 645 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 646 |
2 |
public ViewPage createPage(String space, String page, String content, String title, String syntaxId,... |
| 647 |
|
String parentFullPageName) |
| 648 |
|
{ |
| 649 |
2 |
return createPage(Collections.singletonList(space), page, content, title, syntaxId, parentFullPageName); |
| 650 |
|
} |
| 651 |
|
|
| 652 |
|
|
| 653 |
|
@since |
| 654 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 5 |
Complexity Density: 0.45 |
|
| 655 |
80 |
public ViewPage createPage(List<String> spaces, String page, String content, String title, String syntaxId,... |
| 656 |
|
String parentFullPageName) |
| 657 |
|
{ |
| 658 |
80 |
Map<String, String> queryMap = new HashMap<String, String>(); |
| 659 |
80 |
if (content != null) { |
| 660 |
58 |
queryMap.put("content", content); |
| 661 |
|
} |
| 662 |
80 |
if (title != null) { |
| 663 |
56 |
queryMap.put("title", title); |
| 664 |
|
} |
| 665 |
80 |
if (syntaxId != null) { |
| 666 |
10 |
queryMap.put("syntaxId", syntaxId); |
| 667 |
|
} |
| 668 |
80 |
if (parentFullPageName != null) { |
| 669 |
2 |
queryMap.put("parent", parentFullPageName); |
| 670 |
|
} |
| 671 |
80 |
gotoPage(spaces, page, "save", queryMap); |
| 672 |
80 |
return new ViewPage(); |
| 673 |
|
} |
| 674 |
|
|
| 675 |
|
|
| 676 |
|
@since |
| 677 |
|
|
| |
|
| 68.4% |
Uncovered Elements: 6 (19) |
Complexity: 5 |
Complexity Density: 0.45 |
|
| 678 |
9 |
public ViewPage createPage(EntityReference reference, String content, String title, String syntaxId,... |
| 679 |
|
String parentFullPageName) |
| 680 |
|
{ |
| 681 |
9 |
Map<String, String> queryMap = new HashMap<>(); |
| 682 |
9 |
if (content != null) { |
| 683 |
9 |
queryMap.put("content", content); |
| 684 |
|
} |
| 685 |
9 |
if (title != null) { |
| 686 |
9 |
queryMap.put("title", title); |
| 687 |
|
} |
| 688 |
9 |
if (syntaxId != null) { |
| 689 |
0 |
queryMap.put("syntaxId", syntaxId); |
| 690 |
|
} |
| 691 |
9 |
if (parentFullPageName != null) { |
| 692 |
0 |
queryMap.put("parent", parentFullPageName); |
| 693 |
|
} |
| 694 |
9 |
gotoPage(reference, "save", queryMap); |
| 695 |
9 |
return new ViewPage(); |
| 696 |
|
} |
| 697 |
|
|
| 698 |
|
|
| 699 |
|
@since |
| 700 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 701 |
0 |
public ViewPage createPageWithAttachment(String space, String page, String content, String title, String syntaxId,... |
| 702 |
|
String parentFullPageName, String attachmentName, InputStream attachmentData) throws Exception |
| 703 |
|
{ |
| 704 |
0 |
return createPageWithAttachment(space, page, content, title, syntaxId, parentFullPageName, attachmentName, |
| 705 |
|
attachmentData, null); |
| 706 |
|
} |
| 707 |
|
|
| 708 |
|
|
| 709 |
|
@since |
| 710 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 711 |
0 |
public ViewPage createPageWithAttachment(String space, String page, String content, String title, String syntaxId,... |
| 712 |
|
String parentFullPageName, String attachmentName, InputStream attachmentData, |
| 713 |
|
UsernamePasswordCredentials credentials) throws Exception |
| 714 |
|
{ |
| 715 |
0 |
return createPageWithAttachment(Collections.singletonList(space), page, content, title, syntaxId, |
| 716 |
|
parentFullPageName, attachmentName, attachmentData, credentials); |
| 717 |
|
} |
| 718 |
|
|
| 719 |
|
|
| 720 |
|
@since |
| 721 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 722 |
1 |
public ViewPage createPageWithAttachment(List<String> spaces, String page, String content, String title,... |
| 723 |
|
String syntaxId, String parentFullPageName, String attachmentName, InputStream attachmentData, |
| 724 |
|
UsernamePasswordCredentials credentials) throws Exception |
| 725 |
|
{ |
| 726 |
1 |
ViewPage vp = createPage(spaces, page, content, title, syntaxId, parentFullPageName); |
| 727 |
1 |
attachFile(spaces, page, attachmentName, attachmentData, false, credentials); |
| 728 |
1 |
return vp; |
| 729 |
|
} |
| 730 |
|
|
| 731 |
|
|
| 732 |
|
@since |
| 733 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 734 |
0 |
public ViewPage createPageWithAttachment(String space, String page, String content, String title,... |
| 735 |
|
String attachmentName, InputStream attachmentData) throws Exception |
| 736 |
|
{ |
| 737 |
0 |
return createPageWithAttachment(space, page, content, title, null, null, attachmentName, attachmentData); |
| 738 |
|
} |
| 739 |
|
|
| 740 |
|
|
| 741 |
|
@since |
| 742 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 743 |
2 |
public ViewPage createPageWithAttachment(String space, String page, String content, String title,... |
| 744 |
|
String attachmentName, InputStream attachmentData, UsernamePasswordCredentials credentials) throws Exception |
| 745 |
|
{ |
| 746 |
2 |
ViewPage vp = createPage(space, page, content, title); |
| 747 |
2 |
attachFile(space, page, attachmentName, attachmentData, false, credentials); |
| 748 |
2 |
return vp; |
| 749 |
|
} |
| 750 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 751 |
34 |
public void deletePage(String space, String page)... |
| 752 |
|
{ |
| 753 |
34 |
getDriver().get(getURLToDeletePage(space, page)); |
| 754 |
|
} |
| 755 |
|
|
| 756 |
|
|
| 757 |
|
@since |
| 758 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 759 |
3 |
public void deletePage(EntityReference reference)... |
| 760 |
|
{ |
| 761 |
3 |
getDriver().get(getURLToDeletePage(reference)); |
| 762 |
|
} |
| 763 |
|
|
| 764 |
|
|
| 765 |
|
@since |
| 766 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 767 |
8 |
public EntityReference resolveDocumentReference(String referenceAsString)... |
| 768 |
|
{ |
| 769 |
8 |
return referenceResolver.resolve(referenceAsString, EntityType.DOCUMENT); |
| 770 |
|
} |
| 771 |
|
|
| 772 |
|
|
| 773 |
|
@since |
| 774 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 775 |
6 |
public EntityReference resolveSpaceReference(String referenceAsString)... |
| 776 |
|
{ |
| 777 |
6 |
return referenceResolver.resolve(referenceAsString, EntityType.SPACE); |
| 778 |
|
} |
| 779 |
|
|
| 780 |
|
|
| 781 |
|
@since |
| 782 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 783 |
21 |
public String serializeReference(EntityReference reference)... |
| 784 |
|
{ |
| 785 |
21 |
return referenceSerializer.serialize(reference); |
| 786 |
|
} |
| 787 |
|
|
| 788 |
|
|
| 789 |
|
|
| 790 |
|
|
| 791 |
|
@param |
| 792 |
|
@since |
| 793 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 794 |
29 |
public void deleteSpace(String space)... |
| 795 |
|
{ |
| 796 |
29 |
getDriver().get(getURLToDeleteSpace(space)); |
| 797 |
|
} |
| 798 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 799 |
111 |
public boolean pageExists(String space, String page) throws Exception... |
| 800 |
|
{ |
| 801 |
111 |
return rest().exists(new LocalDocumentReference(space, page)); |
| 802 |
|
} |
| 803 |
|
|
| 804 |
|
|
| 805 |
|
@since |
| 806 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 807 |
4 |
public boolean pageExists(List<String> spaces, String page) throws Exception... |
| 808 |
|
{ |
| 809 |
4 |
return rest().exists(new LocalDocumentReference(spaces, page)); |
| 810 |
|
} |
| 811 |
|
|
| 812 |
|
|
| 813 |
|
|
| 814 |
|
|
| 815 |
|
@param |
| 816 |
|
@param |
| 817 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 818 |
36 |
public String getURL(String space, String page)... |
| 819 |
|
{ |
| 820 |
36 |
return getURL(space, page, "view"); |
| 821 |
|
} |
| 822 |
|
|
| 823 |
|
|
| 824 |
|
|
| 825 |
|
|
| 826 |
|
@param |
| 827 |
|
@param |
| 828 |
|
@param |
| 829 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 830 |
91 |
public String getURL(String space, String page, String action)... |
| 831 |
|
{ |
| 832 |
91 |
return getURL(space, page, action, ""); |
| 833 |
|
} |
| 834 |
|
|
| 835 |
|
|
| 836 |
|
|
| 837 |
|
|
| 838 |
|
@param |
| 839 |
|
@param |
| 840 |
|
@param |
| 841 |
|
@param |
| 842 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 843 |
480 |
public String getURL(String space, String page, String action, String queryString)... |
| 844 |
|
{ |
| 845 |
480 |
return getURL(action, new String[] { space, page }, queryString); |
| 846 |
|
} |
| 847 |
|
|
| 848 |
|
|
| 849 |
|
@since |
| 850 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 851 |
3 |
public String getURL(List<String> spaces, String page)... |
| 852 |
|
{ |
| 853 |
3 |
return getURL(spaces, page, "view", ""); |
| 854 |
|
} |
| 855 |
|
|
| 856 |
|
|
| 857 |
|
@since |
| 858 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 859 |
1058 |
public String getURL(List<String> spaces, String page, String action, String queryString)... |
| 860 |
|
{ |
| 861 |
1058 |
List<String> path = new ArrayList<>(spaces); |
| 862 |
1058 |
path.add(page); |
| 863 |
1058 |
return getURL(action, path.toArray(new String[] {}), queryString); |
| 864 |
|
} |
| 865 |
|
|
| 866 |
|
|
| 867 |
|
@since |
| 868 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 869 |
113 |
public String getURL(EntityReference reference, String action, String queryString)... |
| 870 |
|
{ |
| 871 |
113 |
return getURL(action, extractListFromReference(reference).toArray(new String[] {}), queryString); |
| 872 |
|
} |
| 873 |
|
|
| 874 |
|
|
| 875 |
|
@since |
| 876 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 877 |
15 |
public String getURLFragment(EntityReference reference)... |
| 878 |
|
{ |
| 879 |
15 |
return StringUtils.join(extractListFromReference(reference), "/"); |
| 880 |
|
} |
| 881 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 882 |
128 |
private List<String> extractListFromReference(EntityReference reference)... |
| 883 |
|
{ |
| 884 |
128 |
List<String> path = new ArrayList<>(); |
| 885 |
|
|
| 886 |
128 |
EntityReference spaceReference = reference.extractReference(EntityType.SPACE); |
| 887 |
128 |
EntityReference wikiReference = reference.extractReference(EntityType.WIKI); |
| 888 |
128 |
for (EntityReference singleReference : spaceReference.removeParent(wikiReference).getReversedReferenceChain()) { |
| 889 |
230 |
path.add(singleReference.getName()); |
| 890 |
|
} |
| 891 |
128 |
if (reference.getType() == EntityType.DOCUMENT) { |
| 892 |
107 |
path.add(reference.getName()); |
| 893 |
|
} |
| 894 |
128 |
return path; |
| 895 |
|
} |
| 896 |
|
|
| 897 |
|
|
| 898 |
|
@since |
| 899 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 900 |
1007 |
public String getCurrentWiki()... |
| 901 |
|
{ |
| 902 |
1007 |
return this.currentWiki; |
| 903 |
|
} |
| 904 |
|
|
| 905 |
|
|
| 906 |
|
@since |
| 907 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 908 |
13838 |
public String getBaseURL()... |
| 909 |
|
{ |
| 910 |
13838 |
return XWikiExecutor.URL + ":" |
| 911 |
13838 |
+ (getCurrentExecutor() != null ? getCurrentExecutor().getPort() : XWikiExecutor.DEFAULT_PORT) + "/xwiki/"; |
| 912 |
|
} |
| 913 |
|
|
| 914 |
|
|
| 915 |
|
@since |
| 916 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 917 |
1658 |
public String getBaseBinURL()... |
| 918 |
|
{ |
| 919 |
1658 |
return getBaseURL() + "bin/"; |
| 920 |
|
} |
| 921 |
|
|
| 922 |
|
|
| 923 |
|
@since |
| 924 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 6 |
Complexity Density: 0.38 |
|
| 925 |
1658 |
public String getURL(String action, String[] path, String queryString)... |
| 926 |
|
{ |
| 927 |
1658 |
StringBuilder builder = new StringBuilder(getBaseBinURL()); |
| 928 |
|
|
| 929 |
1658 |
if (!StringUtils.isEmpty(action)) { |
| 930 |
1656 |
builder.append(action).append('/'); |
| 931 |
|
} |
| 932 |
1658 |
List<String> escapedPath = new ArrayList<>(); |
| 933 |
1658 |
for (String element : path) { |
| 934 |
3398 |
escapedPath.add(escapeURL(element)); |
| 935 |
|
} |
| 936 |
1658 |
builder.append(StringUtils.join(escapedPath, '/')); |
| 937 |
|
|
| 938 |
1658 |
boolean needToAddSecretToken = !Arrays.asList("view", "register", "download").contains(action); |
| 939 |
1658 |
if (needToAddSecretToken || !StringUtils.isEmpty(queryString)) { |
| 940 |
828 |
builder.append('?'); |
| 941 |
|
} |
| 942 |
1658 |
if (needToAddSecretToken) { |
| 943 |
631 |
addQueryStringEntry(builder, "form_token", getSecretToken()); |
| 944 |
631 |
builder.append('&'); |
| 945 |
|
} |
| 946 |
1658 |
if (!StringUtils.isEmpty(queryString)) { |
| 947 |
747 |
builder.append(queryString); |
| 948 |
|
} |
| 949 |
|
|
| 950 |
1658 |
return builder.toString(); |
| 951 |
|
} |
| 952 |
|
|
| 953 |
|
|
| 954 |
|
|
| 955 |
|
|
| 956 |
|
|
| 957 |
|
@param |
| 958 |
|
@param |
| 959 |
|
@param |
| 960 |
|
@param |
| 961 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 962 |
173 |
public String getURL(String space, String page, String action, Map<String, ?> queryParameters)... |
| 963 |
|
{ |
| 964 |
173 |
return getURL(space, page, action, toQueryString(queryParameters)); |
| 965 |
|
} |
| 966 |
|
|
| 967 |
|
|
| 968 |
|
@param |
| 969 |
|
@param |
| 970 |
|
@param |
| 971 |
|
@param |
| 972 |
|
@param |
| 973 |
|
@return |
| 974 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 975 |
1 |
public String getAttachmentURL(String space, String page, String attachment, String action, String queryString)... |
| 976 |
|
{ |
| 977 |
1 |
return getURL(action, new String[] { space, page, attachment }, queryString); |
| 978 |
|
} |
| 979 |
|
|
| 980 |
|
|
| 981 |
|
@param |
| 982 |
|
@param |
| 983 |
|
@param |
| 984 |
|
@param |
| 985 |
|
@return |
| 986 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 987 |
1 |
public String getAttachmentURL(String space, String page, String attachment, String action)... |
| 988 |
|
{ |
| 989 |
1 |
return getAttachmentURL(space, page, attachment, action, ""); |
| 990 |
|
} |
| 991 |
|
|
| 992 |
|
|
| 993 |
|
@param |
| 994 |
|
@param |
| 995 |
|
@param |
| 996 |
|
@return |
| 997 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 998 |
1 |
public String getAttachmentURL(String space, String page, String attachment)... |
| 999 |
|
{ |
| 1000 |
1 |
return getAttachmentURL(space, page, attachment, "download"); |
| 1001 |
|
} |
| 1002 |
|
|
| 1003 |
|
|
| 1004 |
|
|
| 1005 |
|
@link |
| 1006 |
|
|
| 1007 |
|
@see |
| 1008 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 1009 |
561 |
public void recacheSecretToken()... |
| 1010 |
|
{ |
| 1011 |
|
|
| 1012 |
|
|
| 1013 |
|
|
| 1014 |
|
|
| 1015 |
561 |
String previousURL = getDriver().getCurrentUrl(); |
| 1016 |
|
|
| 1017 |
561 |
gotoPage(getCurrentWiki(), "Register", "register"); |
| 1018 |
561 |
recacheSecretTokenWhenOnRegisterPage(); |
| 1019 |
|
|
| 1020 |
561 |
getDriver().get(previousURL); |
| 1021 |
|
} |
| 1022 |
|
|
| |
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 1023 |
614 |
private void recacheSecretTokenWhenOnRegisterPage()... |
| 1024 |
|
{ |
| 1025 |
614 |
try { |
| 1026 |
614 |
WebElement tokenInput = getDriver().findElement(By.xpath("//input[@name='form_token']")); |
| 1027 |
614 |
this.secretToken = tokenInput.getAttribute("value"); |
| 1028 |
|
} catch (NoSuchElementException exception) { |
| 1029 |
|
|
| 1030 |
0 |
System.out.println("Warning: Failed to cache anti-CSRF secret token, some tests might fail!"); |
| 1031 |
0 |
exception.printStackTrace(); |
| 1032 |
|
} |
| 1033 |
|
} |
| 1034 |
|
|
| 1035 |
|
|
| 1036 |
|
@link |
| 1037 |
|
|
| 1038 |
|
@return |
| 1039 |
|
@see |
| 1040 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 1041 |
1148 |
public String getSecretToken()... |
| 1042 |
|
{ |
| 1043 |
1148 |
if (this.secretToken == null) { |
| 1044 |
2 |
System.out.println("Warning: No cached anti-CSRF token found. " |
| 1045 |
|
+ "Make sure to call recacheSecretToken() before getSecretToken(), otherwise this test might fail."); |
| 1046 |
2 |
return ""; |
| 1047 |
|
} |
| 1048 |
1146 |
return this.secretToken; |
| 1049 |
|
} |
| 1050 |
|
|
| 1051 |
|
|
| 1052 |
|
|
| 1053 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
| 1054 |
|
public class Session |
| 1055 |
|
{ |
| 1056 |
|
private final Set<Cookie> cookies; |
| 1057 |
|
|
| 1058 |
|
private final String secretToken; |
| 1059 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 1060 |
32 |
private Session(final Set<Cookie> cookies, final String secretToken)... |
| 1061 |
|
{ |
| 1062 |
32 |
this.cookies = Collections.unmodifiableSet(new HashSet<Cookie>() |
| 1063 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1064 |
32 |
{... |
| 1065 |
32 |
addAll(cookies); |
| 1066 |
|
} |
| 1067 |
|
}); |
| 1068 |
32 |
this.secretToken = secretToken; |
| 1069 |
|
} |
| 1070 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1071 |
38 |
private Set<Cookie> getCookies()... |
| 1072 |
|
{ |
| 1073 |
38 |
return this.cookies; |
| 1074 |
|
} |
| 1075 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1076 |
76 |
private String getSecretToken()... |
| 1077 |
|
{ |
| 1078 |
76 |
return this.secretToken; |
| 1079 |
|
} |
| 1080 |
|
} |
| 1081 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1082 |
0 |
public boolean isInWYSIWYGEditMode()... |
| 1083 |
|
{ |
| 1084 |
0 |
return getDriver().findElements(By.xpath("//div[@id='editcolumn' and contains(@class, 'editor-wysiwyg')]")) |
| 1085 |
|
.size() > 0; |
| 1086 |
|
} |
| 1087 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1088 |
1 |
public boolean isInWikiEditMode()... |
| 1089 |
|
{ |
| 1090 |
1 |
return getDriver().findElements(By.xpath("//div[@id='editcolumn' and contains(@class, 'editor-wiki')]")) |
| 1091 |
|
.size() > 0; |
| 1092 |
|
} |
| 1093 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1094 |
2 |
public boolean isInViewMode()... |
| 1095 |
|
{ |
| 1096 |
2 |
return !getDriver().hasElementWithoutWaiting(By.id("editMeta")); |
| 1097 |
|
} |
| 1098 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1099 |
1 |
public boolean isInSourceViewMode()... |
| 1100 |
|
{ |
| 1101 |
1 |
return getDriver().findElements(By.xpath("//textarea[@class = 'wiki-code']")).size() > 0; |
| 1102 |
|
} |
| 1103 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 1104 |
1 |
public boolean isInInlineEditMode()... |
| 1105 |
|
{ |
| 1106 |
1 |
String currentURL = getDriver().getCurrentUrl(); |
| 1107 |
|
|
| 1108 |
1 |
return currentURL.contains("editor=inline") || currentURL.contains("/inline/"); |
| 1109 |
|
} |
| 1110 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1111 |
1 |
public boolean isInRightsEditMode()... |
| 1112 |
|
{ |
| 1113 |
1 |
return getDriver().getCurrentUrl().contains("editor=rights"); |
| 1114 |
|
} |
| 1115 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1116 |
1 |
public boolean isInObjectEditMode()... |
| 1117 |
|
{ |
| 1118 |
1 |
return getDriver().getCurrentUrl().contains("editor=object"); |
| 1119 |
|
} |
| 1120 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1121 |
1 |
public boolean isInClassEditMode()... |
| 1122 |
|
{ |
| 1123 |
1 |
return getDriver().getCurrentUrl().contains("editor=class"); |
| 1124 |
|
} |
| 1125 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1126 |
1 |
public boolean isInDeleteMode()... |
| 1127 |
|
{ |
| 1128 |
1 |
return getDriver().getCurrentUrl().contains("/delete/"); |
| 1129 |
|
} |
| 1130 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1131 |
1 |
public boolean isInRenameMode()... |
| 1132 |
|
{ |
| 1133 |
1 |
return getDriver().getCurrentUrl().contains("xpage=rename"); |
| 1134 |
|
} |
| 1135 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1136 |
2 |
public boolean isInCreateMode()... |
| 1137 |
|
{ |
| 1138 |
2 |
return getDriver().getCurrentUrl().contains("/create/"); |
| 1139 |
|
} |
| 1140 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1141 |
1 |
public boolean isInAdminMode()... |
| 1142 |
|
{ |
| 1143 |
1 |
return getDriver().getCurrentUrl().contains("/admin/"); |
| 1144 |
|
} |
| 1145 |
|
|
| 1146 |
|
|
| 1147 |
|
|
| 1148 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1149 |
68 |
public void forceGuestUser()... |
| 1150 |
|
{ |
| 1151 |
68 |
setSession(null); |
| 1152 |
|
} |
| 1153 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1154 |
6 |
public void addObject(String space, String page, String className, Object... properties)... |
| 1155 |
|
{ |
| 1156 |
6 |
gotoPage(space, page, "objectadd", toQueryParameters(className, null, properties)); |
| 1157 |
|
} |
| 1158 |
|
|
| 1159 |
|
|
| 1160 |
|
@since |
| 1161 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1162 |
2 |
public void addObject(EntityReference reference, String className, Object... properties)... |
| 1163 |
|
{ |
| 1164 |
2 |
gotoPage(reference, "objectadd", toQueryParameters(className, null, properties)); |
| 1165 |
|
} |
| 1166 |
|
|
| 1167 |
|
|
| 1168 |
|
@since |
| 1169 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1170 |
6 |
public void addObject(EntityReference reference, String className, Map<String, ?> properties)... |
| 1171 |
|
{ |
| 1172 |
6 |
gotoPage(reference, "objectadd", toQueryParameters(className, null, properties)); |
| 1173 |
|
} |
| 1174 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1175 |
0 |
public void addObject(String space, String page, String className, Map<String, ?> properties)... |
| 1176 |
|
{ |
| 1177 |
0 |
gotoPage(space, page, "objectadd", toQueryParameters(className, null, properties)); |
| 1178 |
|
} |
| 1179 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1180 |
0 |
public void deleteObject(String space, String page, String className, int objectNumber) throws Exception... |
| 1181 |
|
{ |
| 1182 |
0 |
TestUtils.assertStatusCodes( |
| 1183 |
|
rest().executeDelete(ObjectResource.class, getCurrentWiki(), space, page, className, objectNumber), true, |
| 1184 |
|
STATUS_NO_CONTENT_NOT_FOUND); |
| 1185 |
|
} |
| 1186 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1187 |
0 |
public void updateObject(String space, String page, String className, int objectNumber, Map<String, ?> properties)... |
| 1188 |
|
{ |
| 1189 |
0 |
gotoPage(space, page, "save", toQueryParameters(className, objectNumber, properties)); |
| 1190 |
|
} |
| 1191 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1192 |
27 |
public void updateObject(String space, String page, String className, int objectNumber, Object... properties)... |
| 1193 |
|
{ |
| 1194 |
27 |
updateObject(Collections.singletonList(space), page, className, objectNumber, properties); |
| 1195 |
|
} |
| 1196 |
|
|
| 1197 |
|
|
| 1198 |
|
@since |
| 1199 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 1200 |
28 |
public void updateObject(List<String> spaces, String page, String className, int objectNumber, Object... properties)... |
| 1201 |
|
{ |
| 1202 |
|
|
| 1203 |
28 |
Map<String, Object> queryParameters = |
| 1204 |
|
(Map<String, Object>) toQueryParameters(className, objectNumber, properties); |
| 1205 |
|
|
| 1206 |
|
|
| 1207 |
28 |
queryParameters.put("objectPolicy", "updateOrCreate"); |
| 1208 |
|
|
| 1209 |
28 |
gotoPage(spaces, page, "save", queryParameters); |
| 1210 |
|
} |
| 1211 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1212 |
14 |
public void addClassProperty(String space, String page, String propertyName, String propertyType)... |
| 1213 |
|
{ |
| 1214 |
14 |
gotoPage(space, page, "propadd", "propname", propertyName, "proptype", propertyType); |
| 1215 |
|
} |
| 1216 |
|
|
| 1217 |
|
|
| 1218 |
|
@since |
| 1219 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1220 |
32 |
public String toQueryString(Object... queryParameters)... |
| 1221 |
|
{ |
| 1222 |
32 |
return toQueryString(toQueryParameters(queryParameters)); |
| 1223 |
|
} |
| 1224 |
|
|
| 1225 |
|
|
| 1226 |
|
@since |
| 1227 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 1228 |
414 |
public String toQueryString(Map<String, ?> queryParameters)... |
| 1229 |
|
{ |
| 1230 |
414 |
StringBuilder builder = new StringBuilder(); |
| 1231 |
|
|
| 1232 |
414 |
for (Map.Entry<String, ?> entry : queryParameters.entrySet()) { |
| 1233 |
1308 |
addQueryStringEntry(builder, entry.getKey(), entry.getValue()); |
| 1234 |
1308 |
builder.append('&'); |
| 1235 |
|
} |
| 1236 |
|
|
| 1237 |
414 |
return builder.toString(); |
| 1238 |
|
} |
| 1239 |
|
|
| 1240 |
|
|
| 1241 |
|
@since |
| 1242 |
|
|
| |
|
| 63.6% |
Uncovered Elements: 4 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 1243 |
1308 |
public void addQueryStringEntry(StringBuilder builder, String key, Object value)... |
| 1244 |
|
{ |
| 1245 |
1308 |
if (value != null) { |
| 1246 |
1274 |
if (value instanceof Iterable) { |
| 1247 |
0 |
for (Object element : (Iterable<?>) value) { |
| 1248 |
0 |
addQueryStringEntry(builder, key, element.toString()); |
| 1249 |
0 |
builder.append('&'); |
| 1250 |
|
} |
| 1251 |
|
} else { |
| 1252 |
1274 |
addQueryStringEntry(builder, key, value.toString()); |
| 1253 |
|
} |
| 1254 |
|
} else { |
| 1255 |
34 |
addQueryStringEntry(builder, key, (String) null); |
| 1256 |
|
} |
| 1257 |
|
} |
| 1258 |
|
|
| 1259 |
|
|
| 1260 |
|
@since |
| 1261 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 1262 |
1939 |
public void addQueryStringEntry(StringBuilder builder, String key, String value)... |
| 1263 |
|
{ |
| 1264 |
1939 |
builder.append(escapeURL(key)); |
| 1265 |
1939 |
if (value != null) { |
| 1266 |
1905 |
builder.append('='); |
| 1267 |
1905 |
builder.append(escapeURL(value)); |
| 1268 |
|
} |
| 1269 |
|
} |
| 1270 |
|
|
| 1271 |
|
|
| 1272 |
|
@since |
| 1273 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1274 |
32 |
public Map<String, ?> toQueryParameters(Object... properties)... |
| 1275 |
|
{ |
| 1276 |
32 |
return toQueryParameters(null, null, properties); |
| 1277 |
|
} |
| 1278 |
|
|
| |
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 1279 |
68 |
public Map<String, ?> toQueryParameters(String className, Integer objectNumber, Object... properties)... |
| 1280 |
|
{ |
| 1281 |
68 |
Map<String, Object> queryParameters = new HashMap<String, Object>(); |
| 1282 |
|
|
| 1283 |
68 |
queryParameters.put("classname", className); |
| 1284 |
|
|
| 1285 |
184 |
for (int i = 0; i < properties.length; i += 2) { |
| 1286 |
116 |
int nextIndex = i + 1; |
| 1287 |
116 |
queryParameters.put(toQueryParameterKey(className, objectNumber, (String) properties[i]), |
| 1288 |
116 |
nextIndex < properties.length ? properties[nextIndex] : null); |
| 1289 |
|
} |
| 1290 |
|
|
| 1291 |
68 |
return queryParameters; |
| 1292 |
|
} |
| 1293 |
|
|
| |
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 1294 |
6 |
public Map<String, ?> toQueryParameters(String className, Integer objectNumber, Map<String, ?> properties)... |
| 1295 |
|
{ |
| 1296 |
6 |
Map<String, Object> queryParameters = new HashMap<String, Object>(); |
| 1297 |
|
|
| 1298 |
6 |
if (className != null) { |
| 1299 |
6 |
queryParameters.put("classname", className); |
| 1300 |
|
} |
| 1301 |
|
|
| 1302 |
6 |
for (Map.Entry<String, ?> entry : properties.entrySet()) { |
| 1303 |
11 |
queryParameters.put(toQueryParameterKey(className, objectNumber, entry.getKey()), entry.getValue()); |
| 1304 |
|
} |
| 1305 |
|
|
| 1306 |
6 |
return queryParameters; |
| 1307 |
|
} |
| 1308 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 1309 |
127 |
public String toQueryParameterKey(String className, Integer objectNumber, String key)... |
| 1310 |
|
{ |
| 1311 |
127 |
if (className == null) { |
| 1312 |
50 |
return key; |
| 1313 |
|
} else { |
| 1314 |
77 |
StringBuilder keyBuilder = new StringBuilder(className); |
| 1315 |
|
|
| 1316 |
77 |
keyBuilder.append('_'); |
| 1317 |
|
|
| 1318 |
77 |
if (objectNumber != null) { |
| 1319 |
43 |
keyBuilder.append(objectNumber); |
| 1320 |
43 |
keyBuilder.append('_'); |
| 1321 |
|
} |
| 1322 |
|
|
| 1323 |
77 |
keyBuilder.append(key); |
| 1324 |
|
|
| 1325 |
77 |
return keyBuilder.toString(); |
| 1326 |
|
} |
| 1327 |
|
} |
| 1328 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 1329 |
0 |
public ObjectEditPage editObjects(String space, String page)... |
| 1330 |
|
{ |
| 1331 |
0 |
gotoPage(space, page, "edit", "editor=object"); |
| 1332 |
0 |
return new ObjectEditPage(); |
| 1333 |
|
} |
| 1334 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 1335 |
2 |
public ClassEditPage editClass(String space, String page)... |
| 1336 |
|
{ |
| 1337 |
2 |
gotoPage(space, page, "edit", "editor=class"); |
| 1338 |
2 |
return new ClassEditPage(); |
| 1339 |
|
} |
| 1340 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 1341 |
0 |
public String getVersion() throws Exception... |
| 1342 |
|
{ |
| 1343 |
0 |
Xwiki xwiki = rest().getResource("", null); |
| 1344 |
|
|
| 1345 |
0 |
return xwiki.getVersion(); |
| 1346 |
|
} |
| 1347 |
|
|
| |
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 1348 |
0 |
public String getMavenVersion() throws Exception... |
| 1349 |
|
{ |
| 1350 |
0 |
String version = getVersion(); |
| 1351 |
|
|
| 1352 |
0 |
int index = version.indexOf('-'); |
| 1353 |
0 |
if (index > 0) { |
| 1354 |
0 |
version = version.substring(0, index) + "-SNAPSHOT"; |
| 1355 |
|
} |
| 1356 |
|
|
| 1357 |
0 |
return version; |
| 1358 |
|
} |
| 1359 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 1360 |
0 |
public void attachFile(String space, String page, String name, File file, boolean failIfExists) throws Exception... |
| 1361 |
|
{ |
| 1362 |
0 |
InputStream is = new FileInputStream(file); |
| 1363 |
0 |
try { |
| 1364 |
0 |
attachFile(space, page, name, is, failIfExists); |
| 1365 |
|
} finally { |
| 1366 |
0 |
is.close(); |
| 1367 |
|
} |
| 1368 |
|
} |
| 1369 |
|
|
| 1370 |
|
|
| 1371 |
|
@since |
| 1372 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1373 |
3 |
public void attachFile(String space, String page, String name, InputStream is, boolean failIfExists,... |
| 1374 |
|
UsernamePasswordCredentials credentials) throws Exception |
| 1375 |
|
{ |
| 1376 |
3 |
attachFile(Collections.singletonList(space), page, name, is, failIfExists, credentials); |
| 1377 |
|
} |
| 1378 |
|
|
| 1379 |
|
|
| 1380 |
|
@since |
| 1381 |
|
|
| |
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 1382 |
4 |
public void attachFile(List<String> spaces, String page, String name, InputStream is, boolean failIfExists,... |
| 1383 |
|
UsernamePasswordCredentials credentials) throws Exception |
| 1384 |
|
{ |
| 1385 |
4 |
UsernamePasswordCredentials currentCredentials = getDefaultCredentials(); |
| 1386 |
|
|
| 1387 |
4 |
try { |
| 1388 |
4 |
if (credentials != null) { |
| 1389 |
4 |
setDefaultCredentials(credentials); |
| 1390 |
|
} |
| 1391 |
4 |
attachFile(spaces, page, name, is, failIfExists); |
| 1392 |
|
} finally { |
| 1393 |
4 |
setDefaultCredentials(currentCredentials); |
| 1394 |
|
} |
| 1395 |
|
} |
| 1396 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1397 |
3 |
public void attachFile(String space, String page, String name, InputStream is, boolean failIfExists)... |
| 1398 |
|
throws Exception |
| 1399 |
|
{ |
| 1400 |
3 |
attachFile(Collections.singletonList(space), page, name, is, failIfExists); |
| 1401 |
|
} |
| 1402 |
|
|
| 1403 |
|
|
| 1404 |
|
@since |
| 1405 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 1406 |
7 |
public void attachFile(List<String> spaces, String page, String name, InputStream is, boolean failIfExists)... |
| 1407 |
|
throws Exception |
| 1408 |
|
{ |
| 1409 |
7 |
AttachmentReference reference = |
| 1410 |
|
new AttachmentReference(name, new DocumentReference(getCurrentWiki(), spaces, page)); |
| 1411 |
|
|
| 1412 |
7 |
attachFile(reference, is, failIfExists); |
| 1413 |
|
} |
| 1414 |
|
|
| 1415 |
|
|
| 1416 |
|
@since |
| 1417 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 1418 |
19 |
public void attachFile(EntityReference pageReference, String name, InputStream is, boolean failIfExists)... |
| 1419 |
|
throws Exception |
| 1420 |
|
{ |
| 1421 |
19 |
EntityReference reference = new EntityReference(name, EntityType.ATTACHMENT, pageReference); |
| 1422 |
|
|
| 1423 |
19 |
attachFile(reference, is, failIfExists); |
| 1424 |
|
} |
| 1425 |
|
|
| 1426 |
|
|
| 1427 |
|
@since |
| 1428 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1429 |
26 |
public void attachFile(EntityReference reference, Object is, boolean failIfExists) throws Exception... |
| 1430 |
|
{ |
| 1431 |
26 |
rest().attachFile(reference, is, failIfExists); |
| 1432 |
|
} |
| 1433 |
|
|
| 1434 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 1435 |
0 |
public void importXar(File file) throws Exception... |
| 1436 |
|
{ |
| 1437 |
|
|
| 1438 |
0 |
attachFile("XWiki", "Import", file.getName(), file, false); |
| 1439 |
|
|
| 1440 |
|
|
| 1441 |
0 |
executeGet( |
| 1442 |
|
getBaseBinURL() + "import/XWiki/Import?historyStrategy=add&importAsBackup=true&ajax&action=import&name=" |
| 1443 |
|
+ escapeURL(file.getName()), |
| 1444 |
|
Status.OK.getStatusCode()); |
| 1445 |
|
} |
| 1446 |
|
|
| 1447 |
|
|
| 1448 |
|
|
| 1449 |
|
|
| 1450 |
|
@param |
| 1451 |
|
@param |
| 1452 |
|
@since |
| 1453 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1454 |
2 |
public void deleteLatestVersion(String space, String page)... |
| 1455 |
|
{ |
| 1456 |
2 |
deleteVersion(space, page, "latest"); |
| 1457 |
|
} |
| 1458 |
|
|
| 1459 |
|
|
| 1460 |
|
|
| 1461 |
|
|
| 1462 |
|
@param |
| 1463 |
|
@param |
| 1464 |
|
@param |
| 1465 |
|
@since |
| 1466 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1467 |
2 |
public void deleteVersion(String space, String page, String version)... |
| 1468 |
|
{ |
| 1469 |
2 |
deleteVersions(space, page, version, version); |
| 1470 |
|
} |
| 1471 |
|
|
| 1472 |
|
|
| 1473 |
|
|
| 1474 |
|
|
| 1475 |
|
@param |
| 1476 |
|
@param |
| 1477 |
|
@param |
| 1478 |
|
@param |
| 1479 |
|
@since |
| 1480 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1481 |
2 |
public void deleteVersions(String space, String page, String v1, String v2)... |
| 1482 |
|
{ |
| 1483 |
2 |
gotoPage(space, page, "deleteversions", "rev1", v1, "rev2", v2, "confirm", "1"); |
| 1484 |
|
} |
| 1485 |
|
|
| 1486 |
|
|
| 1487 |
|
|
| 1488 |
|
|
| 1489 |
|
@param |
| 1490 |
|
@param |
| 1491 |
|
@since |
| 1492 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1493 |
0 |
public void rollbackToPreviousVersion(String space, String page)... |
| 1494 |
|
{ |
| 1495 |
0 |
rollBackTo(space, page, "previous"); |
| 1496 |
|
} |
| 1497 |
|
|
| 1498 |
|
|
| 1499 |
|
|
| 1500 |
|
|
| 1501 |
|
@param |
| 1502 |
|
@param |
| 1503 |
|
@param |
| 1504 |
|
@since |
| 1505 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1506 |
0 |
public void rollBackTo(String space, String page, String version)... |
| 1507 |
|
{ |
| 1508 |
0 |
gotoPage(space, page, "rollback", "rev", version, "confirm", "1"); |
| 1509 |
|
} |
| 1510 |
|
|
| 1511 |
|
|
| 1512 |
|
|
| 1513 |
|
|
| 1514 |
|
@param |
| 1515 |
|
@since |
| 1516 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1517 |
12 |
public void setHierarchyMode(String mode)... |
| 1518 |
|
{ |
| 1519 |
12 |
setPropertyInXWikiPreferences("core.hierarchyMode", "String", mode); |
| 1520 |
|
} |
| 1521 |
|
|
| 1522 |
|
|
| 1523 |
|
|
| 1524 |
|
|
| 1525 |
|
@param |
| 1526 |
|
@param |
| 1527 |
|
@param |
| 1528 |
|
@since |
| 1529 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 1530 |
12 |
public void setPropertyInXWikiPreferences(String propertyName, String propertyType, Object value)... |
| 1531 |
|
{ |
| 1532 |
12 |
addClassProperty("XWiki", "XWikiPreferences", propertyName, propertyType); |
| 1533 |
12 |
gotoPage("XWiki", "XWikiPreferences", "edit", "editor", "object"); |
| 1534 |
12 |
ObjectEditPage objectEditPage = new ObjectEditPage(); |
| 1535 |
12 |
if (objectEditPage.hasObject("XWiki.XWikiPreferences")) { |
| 1536 |
10 |
updateObject("XWiki", "XWikiPreferences", "XWiki.XWikiPreferences", 0, propertyName, value); |
| 1537 |
|
} else { |
| 1538 |
2 |
addObject("XWiki", "XWikiPreferences", "XWiki.XWikiPreferences", propertyName, value); |
| 1539 |
|
} |
| 1540 |
|
} |
| 1541 |
|
|
| 1542 |
|
|
| 1543 |
|
@since |
| 1544 |
|
|
| |
|
| 50% |
Uncovered Elements: 2 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 1545 |
11615 |
public static void assertStatuses(int actualCode, int... expectedCodes)... |
| 1546 |
|
{ |
| 1547 |
11615 |
if (!ArrayUtils.contains(expectedCodes, actualCode)) { |
| 1548 |
0 |
Assert.fail( |
| 1549 |
|
"Unexpected code [" + actualCode + "], was expecting one of [" + Arrays.toString(expectedCodes) + "]"); |
| 1550 |
|
} |
| 1551 |
|
} |
| 1552 |
|
|
| 1553 |
|
|
| 1554 |
|
@since |
| 1555 |
|
|
| |
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 1556 |
11615 |
public static <M extends HttpMethod> M assertStatusCodes(M method, boolean release, int... expectedCodes)... |
| 1557 |
|
{ |
| 1558 |
11615 |
if (expectedCodes.length > 0) { |
| 1559 |
11615 |
assertStatuses(method.getStatusCode(), expectedCodes); |
| 1560 |
|
} |
| 1561 |
|
|
| 1562 |
11615 |
if (release) { |
| 1563 |
549 |
method.releaseConnection(); |
| 1564 |
|
} |
| 1565 |
|
|
| 1566 |
11615 |
return method; |
| 1567 |
|
} |
| 1568 |
|
|
| 1569 |
|
|
| 1570 |
|
|
| 1571 |
|
|
| 1572 |
|
|
| 1573 |
|
|
| 1574 |
|
|
| 1575 |
|
|
| 1576 |
|
|
| 1577 |
|
@param |
| 1578 |
|
|
| |
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 1579 |
9070 |
public String escapeURL(String url)... |
| 1580 |
|
{ |
| 1581 |
9070 |
String encodedURL; |
| 1582 |
9070 |
try { |
| 1583 |
9070 |
encodedURL = URLEncoder.encode(url, "UTF-8"); |
| 1584 |
|
} catch (Exception e) { |
| 1585 |
|
|
| 1586 |
0 |
throw new RuntimeException("Missing charset [UTF-8]", e); |
| 1587 |
|
} |
| 1588 |
|
|
| 1589 |
|
|
| 1590 |
|
|
| 1591 |
9070 |
encodedURL = encodedURL.replaceAll("\\+", "%20"); |
| 1592 |
|
|
| 1593 |
9070 |
return encodedURL; |
| 1594 |
|
} |
| 1595 |
|
|
| 1596 |
|
|
| 1597 |
|
|
| 1598 |
|
|
| 1599 |
|
|
| 1600 |
|
|
| 1601 |
|
|
| 1602 |
|
|
| 1603 |
|
|
| 1604 |
|
|
| 1605 |
|
@param |
| 1606 |
|
@return |
| 1607 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1608 |
1 |
public String escapeXPath(String value)... |
| 1609 |
|
{ |
| 1610 |
1 |
return "concat('" + value.replace("'", "', \"'\", '") + "', '')"; |
| 1611 |
|
} |
| 1612 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1613 |
0 |
public InputStream getInputStream(String path, Map<String, ?> queryParams) throws Exception... |
| 1614 |
|
{ |
| 1615 |
0 |
return getInputStream(getBaseURL(), path, queryParams); |
| 1616 |
|
} |
| 1617 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 3 |
Complexity Density: 1 |
|
| 1618 |
11029 |
public String getString(String path, Map<String, ?> queryParams) throws Exception... |
| 1619 |
|
{ |
| 1620 |
11029 |
try (InputStream inputStream = getInputStream(getBaseURL(), path, queryParams)) { |
| 1621 |
11029 |
return IOUtils.toString(inputStream); |
| 1622 |
|
} |
| 1623 |
|
} |
| 1624 |
|
|
| |
|
| 90.5% |
Uncovered Elements: 2 (21) |
Complexity: 6 |
Complexity Density: 0.55 |
|
| 1625 |
11061 |
public InputStream getInputStream(String prefix, String path, Map<String, ?> queryParams, Object... elements)... |
| 1626 |
|
throws Exception |
| 1627 |
|
{ |
| 1628 |
11061 |
String cleanPrefix = prefix.endsWith("/") ? prefix.substring(0, prefix.length() - 1) : prefix; |
| 1629 |
11061 |
if (path.startsWith(cleanPrefix)) { |
| 1630 |
0 |
cleanPrefix = ""; |
| 1631 |
|
} |
| 1632 |
|
|
| 1633 |
11061 |
UriBuilder builder = UriBuilder.fromUri(cleanPrefix).path(path.startsWith("/") ? path.substring(1) : path); |
| 1634 |
|
|
| 1635 |
11061 |
if (queryParams != null) { |
| 1636 |
11049 |
for (Map.Entry<String, ?> entry : queryParams.entrySet()) { |
| 1637 |
11048 |
if (entry.getValue() instanceof Object[]) { |
| 1638 |
19 |
builder.queryParam(entry.getKey(), (Object[]) entry.getValue()); |
| 1639 |
|
} else { |
| 1640 |
11029 |
builder.queryParam(entry.getKey(), entry.getValue()); |
| 1641 |
|
} |
| 1642 |
|
} |
| 1643 |
|
} |
| 1644 |
|
|
| 1645 |
11061 |
String url = builder.build(elements).toString(); |
| 1646 |
|
|
| 1647 |
11061 |
return executeGet(url, Status.OK.getStatusCode()).getResponseBodyAsStream(); |
| 1648 |
|
} |
| 1649 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 1650 |
11217 |
protected GetMethod executeGet(String uri) throws Exception... |
| 1651 |
|
{ |
| 1652 |
11217 |
GetMethod getMethod = new GetMethod(uri); |
| 1653 |
|
|
| 1654 |
11217 |
this.httpClient.executeMethod(getMethod); |
| 1655 |
|
|
| 1656 |
11217 |
return getMethod; |
| 1657 |
|
} |
| 1658 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1659 |
11061 |
protected GetMethod executeGet(String uri, int... expectedCodes) throws Exception... |
| 1660 |
|
{ |
| 1661 |
11061 |
return executeGet(uri, false, expectedCodes); |
| 1662 |
|
} |
| 1663 |
|
|
| 1664 |
|
|
| 1665 |
|
@since |
| 1666 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1667 |
11061 |
protected GetMethod executeGet(String uri, boolean release, int... expectedCodes) throws Exception... |
| 1668 |
|
{ |
| 1669 |
11061 |
return assertStatusCodes(executeGet(uri), release, expectedCodes); |
| 1670 |
|
} |
| 1671 |
|
|
| 1672 |
|
|
| 1673 |
|
@since |
| 1674 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 1675 |
0 |
protected PostMethod executePost(String uri, InputStream content, String mediaType) throws Exception... |
| 1676 |
|
{ |
| 1677 |
0 |
PostMethod postMethod = new PostMethod(uri); |
| 1678 |
0 |
RequestEntity entity = new InputStreamRequestEntity(content, mediaType); |
| 1679 |
0 |
postMethod.setRequestEntity(entity); |
| 1680 |
|
|
| 1681 |
0 |
this.httpClient.executeMethod(postMethod); |
| 1682 |
|
|
| 1683 |
0 |
return postMethod; |
| 1684 |
|
} |
| 1685 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1686 |
0 |
protected PostMethod executePost(String uri, InputStream content, String mediaType, int... expectedCodes)... |
| 1687 |
|
throws Exception |
| 1688 |
|
{ |
| 1689 |
0 |
return executePost(uri, content, mediaType, true, expectedCodes); |
| 1690 |
|
} |
| 1691 |
|
|
| 1692 |
|
|
| 1693 |
|
@since |
| 1694 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1695 |
0 |
protected PostMethod executePost(String uri, InputStream content, String mediaType, boolean release,... |
| 1696 |
|
int... expectedCodes) throws Exception |
| 1697 |
|
{ |
| 1698 |
0 |
return assertStatusCodes(executePost(uri, content, mediaType), false, expectedCodes); |
| 1699 |
|
} |
| 1700 |
|
|
| 1701 |
|
|
| 1702 |
|
@since |
| 1703 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 1704 |
345 |
protected DeleteMethod executeDelete(String uri) throws Exception... |
| 1705 |
|
{ |
| 1706 |
345 |
DeleteMethod postMethod = new DeleteMethod(uri); |
| 1707 |
|
|
| 1708 |
345 |
this.httpClient.executeMethod(postMethod); |
| 1709 |
|
|
| 1710 |
345 |
return postMethod; |
| 1711 |
|
} |
| 1712 |
|
|
| 1713 |
|
|
| 1714 |
|
@since |
| 1715 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1716 |
0 |
protected void executeDelete(String uri, int... expectedCodes) throws Exception... |
| 1717 |
|
{ |
| 1718 |
0 |
assertStatusCodes(executeDelete(uri), true, expectedCodes); |
| 1719 |
|
} |
| 1720 |
|
|
| 1721 |
|
|
| 1722 |
|
@since |
| 1723 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 1724 |
204 |
protected PutMethod executePut(String uri, InputStream content, String mediaType) throws Exception... |
| 1725 |
|
{ |
| 1726 |
204 |
PutMethod putMethod = new PutMethod(uri); |
| 1727 |
204 |
RequestEntity entity = new InputStreamRequestEntity(content, mediaType); |
| 1728 |
204 |
putMethod.setRequestEntity(entity); |
| 1729 |
|
|
| 1730 |
204 |
this.httpClient.executeMethod(putMethod); |
| 1731 |
|
|
| 1732 |
204 |
return putMethod; |
| 1733 |
|
} |
| 1734 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1735 |
0 |
protected void executePut(String uri, InputStream content, String mediaType, int... expectedCodes) throws Exception... |
| 1736 |
|
{ |
| 1737 |
0 |
executePut(uri, content, mediaType, true, expectedCodes); |
| 1738 |
|
} |
| 1739 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1740 |
0 |
protected PutMethod executePut(String uri, InputStream content, String mediaType, boolean release,... |
| 1741 |
|
int... expectedCodes) throws Exception |
| 1742 |
|
{ |
| 1743 |
0 |
return assertStatusCodes(executePut(uri, content, mediaType), release, expectedCodes); |
| 1744 |
|
} |
| 1745 |
|
|
| 1746 |
|
|
| 1747 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1748 |
1519 |
public RestTestUtils rest()... |
| 1749 |
|
{ |
| 1750 |
1519 |
return this.rest; |
| 1751 |
|
} |
| 1752 |
|
|
| 1753 |
|
|
| 1754 |
|
@since |
| 1755 |
|
|
| 1756 |
|
|
| |
|
| 77.8% |
Uncovered Elements: 76 (342) |
Complexity: 100 |
Complexity Density: 0.46 |
|
| 1757 |
|
public static class RestTestUtils |
| 1758 |
|
{ |
| 1759 |
|
public static final Boolean ELEMENTS_ENCODED = new Boolean(true); |
| 1760 |
|
|
| 1761 |
|
public static final Map<EntityType, ResourceAPI> RESOURCES_MAP = new IdentityHashMap<>(); |
| 1762 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 1763 |
|
public static class ResourceAPI |
| 1764 |
|
{ |
| 1765 |
|
public Class<?> api; |
| 1766 |
|
|
| 1767 |
|
public Class<?> localeAPI; |
| 1768 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 1769 |
132 |
public ResourceAPI(Class<?> api, Class<?> localeAPI)... |
| 1770 |
|
{ |
| 1771 |
132 |
this.api = api; |
| 1772 |
132 |
this.localeAPI = localeAPI; |
| 1773 |
|
} |
| 1774 |
|
} |
| 1775 |
|
|
| 1776 |
|
|
| 1777 |
|
|
| 1778 |
|
|
| 1779 |
|
private static final Pattern OBJECT_NAME_PATTERN = Pattern.compile("(\\\\*)\\[(\\d*)\\]$"); |
| 1780 |
|
|
| |
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 2 |
Complexity Density: 0.22 |
|
| 1781 |
33 |
static {... |
| 1782 |
33 |
try { |
| 1783 |
|
|
| 1784 |
33 |
JAXBContext jaxbContext = JAXBContext |
| 1785 |
|
.newInstance("org.xwiki.rest.model.jaxb:org.xwiki.extension.repository.xwiki.model.jaxb"); |
| 1786 |
33 |
marshaller = jaxbContext.createMarshaller(); |
| 1787 |
33 |
unmarshaller = jaxbContext.createUnmarshaller(); |
| 1788 |
|
} catch (JAXBException e) { |
| 1789 |
0 |
throw new RuntimeException(e); |
| 1790 |
|
} |
| 1791 |
|
|
| 1792 |
33 |
RESOURCES_MAP.put(EntityType.DOCUMENT, new ResourceAPI(PageResource.class, PageTranslationResource.class)); |
| 1793 |
33 |
RESOURCES_MAP.put(EntityType.OBJECT, new ResourceAPI(ObjectResource.class, null)); |
| 1794 |
33 |
RESOURCES_MAP.put(EntityType.OBJECT_PROPERTY, new ResourceAPI(ObjectPropertyResource.class, null)); |
| 1795 |
33 |
RESOURCES_MAP.put(EntityType.CLASS_PROPERTY, new ResourceAPI(ClassPropertyResource.class, null)); |
| 1796 |
|
} |
| 1797 |
|
|
| 1798 |
|
|
| 1799 |
|
@since |
| 1800 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 1801 |
108 |
public static org.xwiki.rest.model.jaxb.Object object(String className)... |
| 1802 |
|
{ |
| 1803 |
108 |
org.xwiki.rest.model.jaxb.Object obj = new org.xwiki.rest.model.jaxb.Object(); |
| 1804 |
|
|
| 1805 |
108 |
obj.setClassName(className); |
| 1806 |
|
|
| 1807 |
108 |
return obj; |
| 1808 |
|
} |
| 1809 |
|
|
| 1810 |
|
|
| 1811 |
|
@since |
| 1812 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
| 1813 |
401 |
public static String toPropertyString(Object value)... |
| 1814 |
|
{ |
| 1815 |
401 |
String stringValue; |
| 1816 |
|
|
| 1817 |
401 |
if (value instanceof Iterable) { |
| 1818 |
60 |
StringBuilder builder = new StringBuilder(); |
| 1819 |
60 |
for (Object item : (Iterable) value) { |
| 1820 |
4 |
if (builder.length() > 0) { |
| 1821 |
1 |
builder.append('|'); |
| 1822 |
|
} |
| 1823 |
|
|
| 1824 |
4 |
builder.append(item); |
| 1825 |
|
} |
| 1826 |
|
|
| 1827 |
60 |
stringValue = builder.toString(); |
| 1828 |
341 |
} else if (value != null) { |
| 1829 |
314 |
stringValue = value.toString(); |
| 1830 |
|
} else { |
| 1831 |
27 |
stringValue = null; |
| 1832 |
|
} |
| 1833 |
|
|
| 1834 |
401 |
return stringValue; |
| 1835 |
|
} |
| 1836 |
|
|
| 1837 |
|
|
| 1838 |
|
@since |
| 1839 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 1840 |
401 |
public static Property property(String name, Object value)... |
| 1841 |
|
{ |
| 1842 |
401 |
Property property = new Property(); |
| 1843 |
|
|
| 1844 |
401 |
property.setName(name); |
| 1845 |
401 |
property.setValue(toPropertyString(value)); |
| 1846 |
|
|
| 1847 |
401 |
return property; |
| 1848 |
|
} |
| 1849 |
|
|
| 1850 |
|
private TestUtils testUtils; |
| 1851 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1852 |
117 |
public RestTestUtils(TestUtils testUtils)... |
| 1853 |
|
{ |
| 1854 |
117 |
this.testUtils = testUtils; |
| 1855 |
|
} |
| 1856 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1857 |
1151 |
public String getBaseURL()... |
| 1858 |
|
{ |
| 1859 |
1151 |
return this.testUtils.getBaseURL() + "rest"; |
| 1860 |
|
} |
| 1861 |
|
|
| |
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 1862 |
175 |
private String toSpaceElement(Iterable<?> spaces)... |
| 1863 |
|
{ |
| 1864 |
175 |
StringBuilder builder = new StringBuilder(); |
| 1865 |
|
|
| 1866 |
175 |
for (Object space : spaces) { |
| 1867 |
191 |
if (builder.length() > 0) { |
| 1868 |
16 |
builder.append("/spaces/"); |
| 1869 |
|
} |
| 1870 |
|
|
| 1871 |
191 |
if (space instanceof EntityReference) { |
| 1872 |
191 |
builder.append(((EntityReference) space).getName()); |
| 1873 |
|
} else { |
| 1874 |
0 |
builder.append(space.toString()); |
| 1875 |
|
} |
| 1876 |
|
} |
| 1877 |
|
|
| 1878 |
175 |
return builder.toString(); |
| 1879 |
|
} |
| 1880 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1881 |
175 |
private String toSpaceElement(String spaceReference)... |
| 1882 |
|
{ |
| 1883 |
175 |
return toSpaceElement( |
| 1884 |
|
relativeReferenceResolver.resolve(spaceReference, EntityType.SPACE).getReversedReferenceChain()); |
| 1885 |
|
} |
| 1886 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 1887 |
175 |
protected Object[] toElements(Page page)... |
| 1888 |
|
{ |
| 1889 |
175 |
List<Object> elements = new ArrayList<>(); |
| 1890 |
|
|
| 1891 |
|
|
| 1892 |
175 |
if (page.getWiki() != null) { |
| 1893 |
171 |
elements.add(page.getWiki()); |
| 1894 |
|
} else { |
| 1895 |
4 |
elements.add(this.testUtils.getCurrentWiki()); |
| 1896 |
|
} |
| 1897 |
|
|
| 1898 |
|
|
| 1899 |
175 |
elements.add(toSpaceElement(page.getSpace())); |
| 1900 |
|
|
| 1901 |
|
|
| 1902 |
175 |
elements.add(page.getName()); |
| 1903 |
|
|
| 1904 |
175 |
return elements.toArray(); |
| 1905 |
|
} |
| 1906 |
|
|
| |
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
| 1907 |
0 |
public Object[] toElements(org.xwiki.rest.model.jaxb.Object obj, boolean onlyDocument)... |
| 1908 |
|
{ |
| 1909 |
0 |
List<Object> elements = new ArrayList<>(); |
| 1910 |
|
|
| 1911 |
|
|
| 1912 |
0 |
if (obj.getWiki() != null) { |
| 1913 |
0 |
elements.add(obj.getWiki()); |
| 1914 |
|
} else { |
| 1915 |
0 |
elements.add(this.testUtils.getCurrentWiki()); |
| 1916 |
|
} |
| 1917 |
|
|
| 1918 |
|
|
| 1919 |
0 |
elements.add(toSpaceElement(obj.getSpace())); |
| 1920 |
|
|
| 1921 |
|
|
| 1922 |
0 |
elements.add(obj.getPageName()); |
| 1923 |
|
|
| 1924 |
0 |
if (!onlyDocument) { |
| 1925 |
|
|
| 1926 |
0 |
elements.add(obj.getClassName()); |
| 1927 |
|
|
| 1928 |
|
|
| 1929 |
0 |
elements.add(obj.getNumber()); |
| 1930 |
|
} |
| 1931 |
|
|
| 1932 |
0 |
return elements.toArray(); |
| 1933 |
|
} |
| 1934 |
|
|
| |
|
| 62.5% |
Uncovered Elements: 18 (48) |
Complexity: 8 |
Complexity Density: 0.24 |
|
| 1935 |
530 |
public Object[] toElements(EntityReference reference)... |
| 1936 |
|
{ |
| 1937 |
530 |
List<EntityReference> references = reference.getReversedReferenceChain(); |
| 1938 |
|
|
| 1939 |
530 |
List<Object> elements = new ArrayList<>(references.size() + 2); |
| 1940 |
|
|
| 1941 |
|
|
| 1942 |
530 |
elements.add(ELEMENTS_ENCODED); |
| 1943 |
|
|
| 1944 |
|
|
| 1945 |
530 |
if (reference.extractReference(EntityType.WIKI) == null) { |
| 1946 |
406 |
elements.add(this.testUtils.escapeURL(this.testUtils.getCurrentWiki())); |
| 1947 |
|
} |
| 1948 |
|
|
| 1949 |
|
|
| 1950 |
530 |
for (EntityReference ref : references) { |
| 1951 |
1399 |
if (ref.getType() == EntityType.SPACE) { |
| 1952 |
|
|
| 1953 |
|
|
| 1954 |
|
|
| 1955 |
716 |
Object value = elements.get(elements.size() - 1); |
| 1956 |
|
|
| 1957 |
716 |
StringBuilder builder; |
| 1958 |
716 |
if (value instanceof StringBuilder) { |
| 1959 |
186 |
builder = (StringBuilder) value; |
| 1960 |
186 |
builder.append("/spaces/"); |
| 1961 |
|
} else { |
| 1962 |
530 |
builder = new StringBuilder(); |
| 1963 |
530 |
elements.add(builder); |
| 1964 |
|
} |
| 1965 |
|
|
| 1966 |
716 |
builder.append(this.testUtils.escapeURL(ref.getName())); |
| 1967 |
683 |
} else if (ref.getType() == EntityType.OBJECT) { |
| 1968 |
|
|
| 1969 |
|
|
| 1970 |
0 |
String classReferenceStr; |
| 1971 |
0 |
String objectNumberStr; |
| 1972 |
|
|
| 1973 |
0 |
Matcher matcher = OBJECT_NAME_PATTERN.matcher(ref.getName()); |
| 1974 |
0 |
if (matcher.find()) { |
| 1975 |
0 |
if (matcher.group(1).length() % 2 == 0) { |
| 1976 |
0 |
classReferenceStr = ref.getName().substring(0, matcher.end(1)); |
| 1977 |
0 |
objectNumberStr = matcher.group(2); |
| 1978 |
|
} else { |
| 1979 |
0 |
classReferenceStr = ref.getName(); |
| 1980 |
0 |
objectNumberStr = null; |
| 1981 |
|
} |
| 1982 |
|
} else { |
| 1983 |
0 |
classReferenceStr = ref.getName(); |
| 1984 |
0 |
objectNumberStr = null; |
| 1985 |
|
} |
| 1986 |
|
|
| 1987 |
0 |
elements.add(classReferenceStr); |
| 1988 |
0 |
elements.add(objectNumberStr); |
| 1989 |
|
} else { |
| 1990 |
683 |
elements.add(this.testUtils.escapeURL(ref.getName())); |
| 1991 |
|
} |
| 1992 |
|
} |
| 1993 |
|
|
| 1994 |
|
|
| 1995 |
530 |
Locale locale = getLocale(reference); |
| 1996 |
530 |
if (locale != null) { |
| 1997 |
6 |
elements.add(locale); |
| 1998 |
|
} |
| 1999 |
|
|
| 2000 |
530 |
return elements.toArray(); |
| 2001 |
|
} |
| 2002 |
|
|
| 2003 |
|
|
| 2004 |
|
|
| 2005 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2006 |
123 |
public void save(Page page, int... expectedCodes) throws Exception... |
| 2007 |
|
{ |
| 2008 |
123 |
save(page, true, expectedCodes); |
| 2009 |
|
} |
| 2010 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 2011 |
175 |
public EntityEnclosingMethod save(Page page, boolean release, int... expectedCodes) throws Exception... |
| 2012 |
|
{ |
| 2013 |
175 |
if (expectedCodes.length == 0) { |
| 2014 |
|
|
| 2015 |
160 |
expectedCodes = STATUS_CREATED_ACCEPTED; |
| 2016 |
|
} |
| 2017 |
|
|
| 2018 |
175 |
return TestUtils.assertStatusCodes(executePut(PageResource.class, page, toElements(page)), release, |
| 2019 |
|
expectedCodes); |
| 2020 |
|
} |
| 2021 |
|
|
| 2022 |
|
|
| 2023 |
|
@since |
| 2024 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
| 2025 |
171 |
public Page page(EntityReference reference)... |
| 2026 |
|
{ |
| 2027 |
171 |
Page page = new Page(); |
| 2028 |
|
|
| 2029 |
|
|
| 2030 |
171 |
EntityReference wikiReference = reference.extractReference(EntityType.WIKI); |
| 2031 |
171 |
if (wikiReference == null) { |
| 2032 |
28 |
page.setWiki(this.testUtils.getCurrentWiki()); |
| 2033 |
|
} else { |
| 2034 |
143 |
page.setWiki(wikiReference.getName()); |
| 2035 |
|
} |
| 2036 |
|
|
| 2037 |
|
|
| 2038 |
171 |
EntityReference spaceReference = reference.extractReference(EntityType.SPACE).removeParent(wikiReference); |
| 2039 |
171 |
page.setSpace(referenceSerializer.serialize(spaceReference)); |
| 2040 |
|
|
| 2041 |
|
|
| 2042 |
171 |
EntityReference documentReference = reference.extractReference(EntityType.DOCUMENT); |
| 2043 |
171 |
page.setName(documentReference.getName()); |
| 2044 |
|
|
| 2045 |
171 |
return page; |
| 2046 |
|
} |
| 2047 |
|
|
| 2048 |
|
|
| 2049 |
|
@since |
| 2050 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2051 |
36 |
public void savePage(EntityReference reference) throws Exception... |
| 2052 |
|
{ |
| 2053 |
36 |
savePage(reference, null, null, null, null); |
| 2054 |
|
} |
| 2055 |
|
|
| 2056 |
|
|
| 2057 |
|
@since |
| 2058 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2059 |
16 |
public void savePage(EntityReference reference, String content, String title) throws Exception... |
| 2060 |
|
{ |
| 2061 |
16 |
savePage(reference, content, null, title, null); |
| 2062 |
|
} |
| 2063 |
|
|
| 2064 |
|
|
| 2065 |
|
@since |
| 2066 |
|
|
| |
|
| 77.8% |
Uncovered Elements: 4 (18) |
Complexity: 5 |
Complexity Density: 0.5 |
|
| 2067 |
52 |
public void savePage(EntityReference reference, String content, String syntaxId, String title,... |
| 2068 |
|
String parentFullPageName) throws Exception |
| 2069 |
|
{ |
| 2070 |
52 |
Page page = page(reference); |
| 2071 |
|
|
| 2072 |
52 |
if (content != null) { |
| 2073 |
16 |
page.setContent(content); |
| 2074 |
|
} |
| 2075 |
52 |
if (title != null) { |
| 2076 |
12 |
page.setTitle(title); |
| 2077 |
|
} |
| 2078 |
52 |
if (syntaxId != null) { |
| 2079 |
0 |
page.setSyntax(syntaxId); |
| 2080 |
|
} |
| 2081 |
52 |
if (parentFullPageName != null) { |
| 2082 |
0 |
page.setParent(parentFullPageName); |
| 2083 |
|
} |
| 2084 |
|
|
| 2085 |
52 |
save(page, true); |
| 2086 |
|
} |
| 2087 |
|
|
| 2088 |
|
|
| 2089 |
|
|
| 2090 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2091 |
0 |
public void add(org.xwiki.rest.model.jaxb.Object obj) throws Exception... |
| 2092 |
|
{ |
| 2093 |
0 |
add(obj, true); |
| 2094 |
|
} |
| 2095 |
|
|
| 2096 |
|
|
| 2097 |
|
|
| 2098 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2099 |
0 |
public EntityEnclosingMethod add(org.xwiki.rest.model.jaxb.Object obj, boolean release) throws Exception... |
| 2100 |
|
{ |
| 2101 |
0 |
return TestUtils.assertStatusCodes(executePost(ObjectsResource.class, obj, toElements(obj, true)), release, |
| 2102 |
|
STATUS_CREATED); |
| 2103 |
|
} |
| 2104 |
|
|
| 2105 |
|
|
| 2106 |
|
|
| 2107 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2108 |
0 |
public void update(org.xwiki.rest.model.jaxb.Object obj) throws Exception... |
| 2109 |
|
{ |
| 2110 |
0 |
update(obj, true); |
| 2111 |
|
} |
| 2112 |
|
|
| 2113 |
|
|
| 2114 |
|
|
| 2115 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2116 |
0 |
public EntityEnclosingMethod update(org.xwiki.rest.model.jaxb.Object obj, boolean release) throws Exception... |
| 2117 |
|
{ |
| 2118 |
0 |
return TestUtils.assertStatusCodes(executePut(ObjectResource.class, obj, toElements(obj, false)), release, |
| 2119 |
|
STATUS_CREATED_ACCEPTED); |
| 2120 |
|
} |
| 2121 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 2122 |
345 |
public void delete(EntityReference reference) throws Exception... |
| 2123 |
|
{ |
| 2124 |
345 |
Class<?> resource = getResourceAPI(reference); |
| 2125 |
|
|
| 2126 |
345 |
TestUtils.assertStatusCodes(executeDelete(resource, toElements(reference)), true, |
| 2127 |
|
STATUS_NO_CONTENT_NOT_FOUND); |
| 2128 |
|
} |
| 2129 |
|
|
| 2130 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 2131 |
1030 |
private Locale getLocale(EntityReference reference)... |
| 2132 |
|
{ |
| 2133 |
1030 |
if (reference instanceof DocumentReference) { |
| 2134 |
213 |
return ((DocumentReference) reference).getLocale(); |
| 2135 |
817 |
} else if (reference instanceof LocalDocumentReference) { |
| 2136 |
774 |
return ((LocalDocumentReference) reference).getLocale(); |
| 2137 |
|
} |
| 2138 |
|
|
| 2139 |
43 |
return null; |
| 2140 |
|
} |
| 2141 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2142 |
149 |
public void deletePage(String space, String page) throws Exception... |
| 2143 |
|
{ |
| 2144 |
149 |
delete(new LocalDocumentReference(space, page)); |
| 2145 |
|
} |
| 2146 |
|
|
| 2147 |
|
|
| 2148 |
|
@since |
| 2149 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2150 |
0 |
public void deletePage(String space, String page, Locale locale) throws Exception... |
| 2151 |
|
{ |
| 2152 |
0 |
delete(new LocalDocumentReference(space, page, locale)); |
| 2153 |
|
} |
| 2154 |
|
|
| 2155 |
|
|
| 2156 |
|
@since |
| 2157 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 2158 |
29 |
public void attachFile(EntityReference reference, Object is, boolean failIfExists) throws Exception... |
| 2159 |
|
{ |
| 2160 |
|
|
| 2161 |
29 |
if (!exists(reference.getParent())) { |
| 2162 |
2 |
savePage(reference.getParent()); |
| 2163 |
|
} |
| 2164 |
|
|
| 2165 |
29 |
if (failIfExists) { |
| 2166 |
23 |
assertStatusCodes(executePut(AttachmentResource.class, is, toElements(reference)), true, |
| 2167 |
|
STATUS_CREATED); |
| 2168 |
|
} else { |
| 2169 |
6 |
assertStatusCodes(executePut(AttachmentResource.class, is, toElements(reference)), true, |
| 2170 |
|
STATUS_CREATED_ACCEPTED); |
| 2171 |
|
} |
| 2172 |
|
} |
| 2173 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 2174 |
151 |
public boolean exists(EntityReference reference) throws Exception... |
| 2175 |
|
{ |
| 2176 |
151 |
GetMethod getMethod = executeGet(reference); |
| 2177 |
|
|
| 2178 |
151 |
getMethod.releaseConnection(); |
| 2179 |
|
|
| 2180 |
151 |
return getMethod.getStatusCode() == Status.OK.getStatusCode(); |
| 2181 |
|
} |
| 2182 |
|
|
| 2183 |
|
|
| 2184 |
|
|
| 2185 |
|
|
| 2186 |
|
@since |
| 2187 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2188 |
4 |
public <T> T get(EntityReference reference) throws Exception... |
| 2189 |
|
{ |
| 2190 |
4 |
return get(reference, true); |
| 2191 |
|
} |
| 2192 |
|
|
| 2193 |
|
|
| 2194 |
|
|
| 2195 |
|
|
| 2196 |
|
@since |
| 2197 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 2198 |
4 |
public <T> T get(EntityReference reference, boolean failIfNotFound) throws Exception... |
| 2199 |
|
{ |
| 2200 |
4 |
Class<?> resource = getResourceAPI(reference); |
| 2201 |
|
|
| 2202 |
4 |
return get(resource, reference, failIfNotFound); |
| 2203 |
|
} |
| 2204 |
|
|
| 2205 |
|
|
| 2206 |
|
@since |
| 2207 |
|
|
| |
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 2208 |
500 |
public Class<?> getResourceAPI(EntityReference reference) throws Exception... |
| 2209 |
|
{ |
| 2210 |
500 |
ResourceAPI resource = RESOURCES_MAP.get(reference.getType()); |
| 2211 |
|
|
| 2212 |
500 |
if (resource == null) { |
| 2213 |
0 |
throw new Exception("Unsuported type [" + reference.getType() + "]"); |
| 2214 |
|
} |
| 2215 |
|
|
| 2216 |
500 |
return getLocale(reference) != null ? resource.localeAPI : resource.api; |
| 2217 |
|
} |
| 2218 |
|
|
| 2219 |
|
|
| 2220 |
|
|
| 2221 |
|
|
| 2222 |
|
@since |
| 2223 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2224 |
1 |
public <T> T get(Object resourceURI, EntityReference reference) throws Exception... |
| 2225 |
|
{ |
| 2226 |
1 |
return get(resourceURI, reference, true); |
| 2227 |
|
} |
| 2228 |
|
|
| 2229 |
|
|
| 2230 |
|
|
| 2231 |
|
|
| 2232 |
|
@since |
| 2233 |
|
|
| |
|
| 68.8% |
Uncovered Elements: 5 (16) |
Complexity: 6 |
Complexity Density: 0.6 |
|
| 2234 |
5 |
public <T> T get(Object resourceURI, EntityReference reference, boolean failIfNotFound) throws Exception... |
| 2235 |
|
{ |
| 2236 |
5 |
GetMethod getMethod = assertStatusCodes(executeGet(resourceURI, reference), false, |
| 2237 |
5 |
failIfNotFound ? STATUS_OK : STATUS_OK_NOT_FOUND); |
| 2238 |
|
|
| 2239 |
5 |
if (getMethod.getStatusCode() == Status.NOT_FOUND.getStatusCode()) { |
| 2240 |
0 |
return null; |
| 2241 |
|
} |
| 2242 |
|
|
| 2243 |
5 |
if (reference.getType() == EntityType.ATTACHMENT) { |
| 2244 |
0 |
return (T) getMethod.getResponseBodyAsStream(); |
| 2245 |
|
} else { |
| 2246 |
5 |
try { |
| 2247 |
5 |
try (InputStream stream = getMethod.getResponseBodyAsStream()) { |
| 2248 |
5 |
return toResource(stream); |
| 2249 |
|
} |
| 2250 |
|
} finally { |
| 2251 |
5 |
getMethod.releaseConnection(); |
| 2252 |
|
} |
| 2253 |
|
} |
| 2254 |
|
} |
| 2255 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2256 |
32 |
public InputStream getInputStream(String resourceUri, Map<String, ?> queryParams, Object... elements)... |
| 2257 |
|
throws Exception |
| 2258 |
|
{ |
| 2259 |
32 |
return this.testUtils.getInputStream(getBaseURL(), resourceUri, queryParams, elements); |
| 2260 |
|
} |
| 2261 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2262 |
0 |
public InputStream postRESTInputStream(Object resourceUri, Object restObject, Object... elements)... |
| 2263 |
|
throws Exception |
| 2264 |
|
{ |
| 2265 |
0 |
return postInputStream(resourceUri, restObject, Collections.<String, Object[]>emptyMap(), elements); |
| 2266 |
|
} |
| 2267 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2268 |
0 |
public InputStream postInputStream(Object resourceUri, Object restObject, Map<String, Object[]> queryParams,... |
| 2269 |
|
Object... elements) throws Exception |
| 2270 |
|
{ |
| 2271 |
0 |
return executePost(resourceUri, restObject, queryParams, elements).getResponseBodyAsStream(); |
| 2272 |
|
} |
| 2273 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2274 |
5 |
public <T> T toResource(InputStream is) throws JAXBException... |
| 2275 |
|
{ |
| 2276 |
5 |
return (T) unmarshaller.unmarshal(is); |
| 2277 |
|
} |
| 2278 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 2279 |
204 |
protected InputStream toResourceInputStream(Object restObject) throws JAXBException... |
| 2280 |
|
{ |
| 2281 |
204 |
InputStream resourceStream; |
| 2282 |
204 |
if (restObject instanceof InputStream) { |
| 2283 |
28 |
resourceStream = (InputStream) restObject; |
| 2284 |
176 |
} else if (restObject instanceof byte[]) { |
| 2285 |
1 |
resourceStream = new ByteArrayInputStream((byte[]) restObject); |
| 2286 |
|
} else { |
| 2287 |
175 |
ByteArrayOutputStream stream = new ByteArrayOutputStream(); |
| 2288 |
175 |
marshaller.marshal(restObject, stream); |
| 2289 |
175 |
resourceStream = new ByteArrayInputStream(stream.toByteArray()); |
| 2290 |
|
} |
| 2291 |
|
|
| 2292 |
204 |
return resourceStream; |
| 2293 |
|
} |
| 2294 |
|
|
| 2295 |
|
|
| 2296 |
|
@since |
| 2297 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 2298 |
151 |
public GetMethod executeGet(EntityReference reference) throws Exception... |
| 2299 |
|
{ |
| 2300 |
151 |
Class<?> resource = getResourceAPI(reference); |
| 2301 |
|
|
| 2302 |
151 |
return executeGet(resource, reference); |
| 2303 |
|
} |
| 2304 |
|
|
| 2305 |
|
|
| 2306 |
|
@since |
| 2307 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2308 |
156 |
public GetMethod executeGet(Object resourceURI, EntityReference reference) throws Exception... |
| 2309 |
|
{ |
| 2310 |
156 |
return executeGet(resourceURI, toElements(reference)); |
| 2311 |
|
} |
| 2312 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2313 |
156 |
public GetMethod executeGet(Object resourceUri, Object... elements) throws Exception... |
| 2314 |
|
{ |
| 2315 |
156 |
return executeGet(resourceUri, Collections.<String, Object[]>emptyMap(), elements); |
| 2316 |
|
} |
| 2317 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 2318 |
156 |
public GetMethod executeGet(Object resourceUri, Map<String, Object[]> queryParams, Object... elements)... |
| 2319 |
|
throws Exception |
| 2320 |
|
{ |
| 2321 |
|
|
| 2322 |
156 |
String uri = createUri(resourceUri, queryParams, elements).toString(); |
| 2323 |
|
|
| 2324 |
156 |
return this.testUtils.executeGet(uri); |
| 2325 |
|
} |
| 2326 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2327 |
0 |
public PostMethod executePost(Object resourceUri, Object restObject, Object... elements) throws Exception... |
| 2328 |
|
{ |
| 2329 |
0 |
return executePost(resourceUri, restObject, Collections.<String, Object[]>emptyMap(), elements); |
| 2330 |
|
} |
| 2331 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 2332 |
0 |
public PostMethod executePost(Object resourceUri, Object restObject, Map<String, Object[]> queryParams,... |
| 2333 |
|
Object... elements) throws Exception |
| 2334 |
|
{ |
| 2335 |
|
|
| 2336 |
0 |
String uri = createUri(resourceUri, queryParams, elements).toString(); |
| 2337 |
|
|
| 2338 |
0 |
try (InputStream resourceStream = toResourceInputStream(restObject)) { |
| 2339 |
0 |
return this.testUtils.executePost(uri, resourceStream, MediaType.APPLICATION_XML); |
| 2340 |
|
} |
| 2341 |
|
} |
| 2342 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2343 |
204 |
public PutMethod executePut(Object resourceUri, Object restObject, Object... elements) throws Exception... |
| 2344 |
|
{ |
| 2345 |
204 |
return executePut(resourceUri, restObject, Collections.<String, Object[]>emptyMap(), elements); |
| 2346 |
|
} |
| 2347 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 2348 |
204 |
public PutMethod executePut(Object resourceUri, Object restObject, Map<String, Object[]> queryParams,... |
| 2349 |
|
Object... elements) throws Exception |
| 2350 |
|
{ |
| 2351 |
|
|
| 2352 |
204 |
String uri = createUri(resourceUri, queryParams, elements).toString(); |
| 2353 |
|
|
| 2354 |
204 |
try (InputStream resourceStream = toResourceInputStream(restObject)) { |
| 2355 |
204 |
return this.testUtils.executePut(uri, resourceStream, MediaType.APPLICATION_XML); |
| 2356 |
|
} |
| 2357 |
|
} |
| 2358 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2359 |
345 |
public DeleteMethod executeDelete(Object resourceUri, Object... elements) throws Exception... |
| 2360 |
|
{ |
| 2361 |
345 |
return executeDelete(resourceUri, Collections.<String, Object[]>emptyMap(), elements); |
| 2362 |
|
} |
| 2363 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 2364 |
345 |
public DeleteMethod executeDelete(Object resourceUri, Map<String, Object[]> queryParams, Object... elements)... |
| 2365 |
|
throws Exception |
| 2366 |
|
{ |
| 2367 |
|
|
| 2368 |
345 |
String uri = createUri(resourceUri, queryParams, elements).toString(); |
| 2369 |
|
|
| 2370 |
345 |
return this.testUtils.executeDelete(uri); |
| 2371 |
|
} |
| 2372 |
|
|
| |
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 2373 |
937 |
public URI createUri(Object resourceUri, Map<String, Object[]> queryParams, Object... elements)... |
| 2374 |
|
{ |
| 2375 |
937 |
if (resourceUri instanceof URI) { |
| 2376 |
0 |
return (URI) resourceUri; |
| 2377 |
|
} |
| 2378 |
|
|
| 2379 |
|
|
| 2380 |
937 |
UriBuilder builder = getUriBuilder(resourceUri, queryParams); |
| 2381 |
|
|
| 2382 |
|
|
| 2383 |
937 |
URI uri; |
| 2384 |
937 |
if (elements.length > 0 && elements[0] == ELEMENTS_ENCODED) { |
| 2385 |
530 |
uri = builder.buildFromEncoded(Arrays.copyOfRange(elements, 1, elements.length)); |
| 2386 |
|
} else { |
| 2387 |
407 |
uri = builder.build(elements); |
| 2388 |
|
} |
| 2389 |
|
|
| 2390 |
937 |
return uri; |
| 2391 |
|
} |
| 2392 |
|
|
| |
|
| 60% |
Uncovered Elements: 6 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
| 2393 |
937 |
public UriBuilder getUriBuilder(Object resourceUri, Map<String, Object[]> queryParams)... |
| 2394 |
|
{ |
| 2395 |
|
|
| 2396 |
937 |
UriBuilder builder; |
| 2397 |
937 |
if (resourceUri instanceof Class) { |
| 2398 |
937 |
builder = getUriBuilder((Class) resourceUri); |
| 2399 |
|
} else { |
| 2400 |
0 |
String stringResourceUri = (String) resourceUri; |
| 2401 |
0 |
builder = UriBuilder.fromUri(getBaseURL().substring(0, getBaseURL().length() - 1)) |
| 2402 |
0 |
.path(!stringResourceUri.isEmpty() && stringResourceUri.charAt(0) == '/' |
| 2403 |
|
? stringResourceUri.substring(1) : stringResourceUri); |
| 2404 |
|
} |
| 2405 |
|
|
| 2406 |
|
|
| 2407 |
937 |
if (queryParams != null) { |
| 2408 |
705 |
for (Map.Entry<String, Object[]> entry : queryParams.entrySet()) { |
| 2409 |
0 |
builder.queryParam(entry.getKey(), entry.getValue()); |
| 2410 |
|
} |
| 2411 |
|
} |
| 2412 |
|
|
| 2413 |
937 |
return builder; |
| 2414 |
|
} |
| 2415 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 2416 |
937 |
protected UriBuilder getUriBuilder(Class<?> resource)... |
| 2417 |
|
{ |
| 2418 |
937 |
return UriBuilder.fromUri(getBaseURL()).path(resource); |
| 2419 |
|
} |
| 2420 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 2421 |
6 |
public byte[] getBuffer(String resourceUri, Map<String, Object[]> queryParams, Object... elements)... |
| 2422 |
|
throws Exception |
| 2423 |
|
{ |
| 2424 |
6 |
InputStream is = getInputStream(resourceUri, queryParams, elements); |
| 2425 |
|
|
| 2426 |
6 |
byte[] buffer; |
| 2427 |
6 |
try { |
| 2428 |
6 |
buffer = IOUtils.toByteArray(is); |
| 2429 |
|
} finally { |
| 2430 |
6 |
is.close(); |
| 2431 |
|
} |
| 2432 |
|
|
| 2433 |
6 |
return buffer; |
| 2434 |
|
} |
| 2435 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 2436 |
26 |
public <T> T getResource(String resourceUri, Map<String, Object[]> queryParams, Object... elements)... |
| 2437 |
|
throws Exception |
| 2438 |
|
{ |
| 2439 |
26 |
T resource; |
| 2440 |
26 |
try (InputStream is = getInputStream(resourceUri, queryParams, elements)) { |
| 2441 |
26 |
resource = (T) unmarshaller.unmarshal(is); |
| 2442 |
|
} |
| 2443 |
|
|
| 2444 |
26 |
return resource; |
| 2445 |
|
} |
| 2446 |
|
} |
| 2447 |
|
} |