com.atlassian.jira.webtests.ztests.bundledplugins2.rest.client
Class RestApiClient<T extends RestApiClient<T>>

java.lang.Object
  extended by com.atlassian.jira.webtests.ztests.bundledplugins2.rest.client.RestApiClient<T>
Direct Known Subclasses:
AttachmentClient, BackdoorControl, BeanClient, CommentClient, ComponentClient, DashboardClient, FieldClient, FilterClient, GroupPickerClient, IssueClient, IssueLinkTypeClient, IssueSecurityTypeClient, IssueTypeClient, LinkIssueClient, PriorityClient, ProjectClient, ProjectRoleClient, ResolutionClient, SearchClient, StatusClient, TransitionsClient, UserClient, VersionClient, VotesClient, WatchersClient, WorklogClient

public abstract class RestApiClient<T extends RestApiClient<T>>
extends Object

Abstract base class for REST API clients.

Since:
v4.3

Nested Class Summary
static interface RestApiClient.Method
          Method interface to use with getResponse.
 
Field Summary
static String REST_VERSION
          The REST plugin version to test.
 
Constructor Summary
protected RestApiClient(JIRAEnvironmentData environmentData)
          Constructs a new RestApiClient for a JIRA instance.
protected RestApiClient(JIRAEnvironmentData environmentData, String version)
          Constructs a new RestApiClient for a JIRA instance.
 
Method Summary
 T anonymous()
          Ensures that this client does not authenticate when making a request.
protected  com.sun.jersey.api.client.WebResource createResource()
          Creates the resource that corresponds to the root of the REST API.
protected  Response errorResponse(com.sun.jersey.api.client.ClientResponse clientResponse)
           
protected  com.sun.jersey.api.client.WebResource expanded(com.sun.jersey.api.client.WebResource resource, EnumSet<?> expands)
          Adds the expand query param to the given WebResource.
 T loginAs(String username)
          Makes this client authenticate as the given user.
 T loginAs(String username, String password)
          Makes this client authenticate as the given username and password.
protected static String percentEncode(String queryParam)
          Percent-encode the % when stuffing it into a query param.
protected  com.sun.jersey.api.client.WebResource resourceRoot(String url)
          Creates a WebResource for the given URL.
protected static
<E extends Enum<E>>
EnumSet<E>
setOf(Class<E> cls, E... expand)
          Constructs an EnumSet from a var-args param.
protected  Response toResponse(RestApiClient.Method method)
           
protected
<T> Response<T>
toResponse(RestApiClient.Method method, Class<T> clazz)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REST_VERSION

public static final String REST_VERSION
The REST plugin version to test.

See Also:
Constant Field Values
Constructor Detail

RestApiClient

protected RestApiClient(JIRAEnvironmentData environmentData)
Constructs a new RestApiClient for a JIRA instance.

Parameters:
environmentData - The JIRA environment data

RestApiClient

protected RestApiClient(JIRAEnvironmentData environmentData,
                        String version)
Constructs a new RestApiClient for a JIRA instance.

Parameters:
environmentData - The JIRA environment data
version - a String containing the version to test against
Method Detail

anonymous

public T anonymous()
Ensures that this client does not authenticate when making a request.

Returns:
this

loginAs

public T loginAs(String username)
Makes this client authenticate as the given user. If this method is not called, this client will authenticate as ""admin"".

Parameters:
username - a String containing the username
Returns:
this

loginAs

public T loginAs(String username,
                 String password)
Makes this client authenticate as the given username and password. If this method is not called, this client will authenticate as ""admin"".

Parameters:
username - a String containing the username
password - a String containing the passoword
Returns:
this

createResource

protected com.sun.jersey.api.client.WebResource createResource()
Creates the resource that corresponds to the root of the REST API.

Returns:
a WebResource for the REST API root

resourceRoot

protected com.sun.jersey.api.client.WebResource resourceRoot(String url)
Creates a WebResource for the given URL. The relevant authentication parameters are added to the resource, if applicable.

Parameters:
url - a String containing a URL
Returns:
a WebResource, with optional authentication parameters

toResponse

protected Response toResponse(RestApiClient.Method method)

toResponse

protected <T> Response<T> toResponse(RestApiClient.Method method,
                                     Class<T> clazz)

errorResponse

protected Response errorResponse(com.sun.jersey.api.client.ClientResponse clientResponse)

expanded

protected com.sun.jersey.api.client.WebResource expanded(com.sun.jersey.api.client.WebResource resource,
                                                         EnumSet<?> expands)
Adds the expand query param to the given WebResource. The name of the attributes to expand must exactly match the name of the enum instances that are passed in.

Parameters:
resource - a WebResource
expands - an EnumSet containing the attributes to expand
Returns:
the input WebResource, with added expand parameters

setOf

protected static <E extends Enum<E>> EnumSet<E> setOf(Class<E> cls,
                                                      E... expand)
Constructs an EnumSet from a var-args param.

Type Parameters:
E - the Enum class
Parameters:
cls - the Enum class object
expand - the enum instances to expand
Returns:
an EnumSet

percentEncode

protected static String percentEncode(String queryParam)
Percent-encode the % when stuffing it into a query param. Otherwise it may not get escaped properly, as per this EAC blog.

Parameters:
queryParam - the query param value
Returns:
a String with % replaced by %25


Copyright © 2002-2012 Atlassian. All Rights Reserved.