Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Refactor the URL building method for Arquillian tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Munoz committed May 8, 2013
1 parent 9a121ff commit a72a154
Showing 1 changed file with 25 additions and 15 deletions.
Expand Up @@ -86,6 +86,21 @@ else if (serverVersion.contains(RestConstant.SNAPSHOT_VERSION) && !serverTimesta
}
}

/**
* Returns the Base url to be used for rest Requests.
*/
protected URL getBaseUrl()
{
try
{
return new URL(fixBase(crf.getBase()).toString() + RESOURCE_PREFIX);
}
catch (MalformedURLException e)
{
throw new RuntimeException(e);
}
}

public <T> T createProxy(Class<T> clazz, URI baseUri)
{
log.debug("{} proxy uri: {}", clazz.getSimpleName(), baseUri);
Expand All @@ -106,12 +121,7 @@ public <T> T createProxy(Class<T> clazz)
{
try
{
URL url = new URL(crf.getBase().toURL(), RESOURCE_PREFIX );
return createProxy(clazz, url.toURI());
}
catch(MalformedURLException e)
{
throw new RuntimeException(e);
return createProxy(clazz, new URI(getBaseUrl().toString()));
}
catch (URISyntaxException e)
{
Expand Down Expand Up @@ -150,7 +160,7 @@ public URI getGlossaryResourceURI()
{
try
{
URL url = new URL(crf.getBase().toURL(), RESOURCE_PREFIX + "/glossary");
URL url = new URL(getBaseUrl(), "glossary");
return url.toURI();
}
catch (MalformedURLException e)
Expand All @@ -172,7 +182,7 @@ public URI getAccountURI(String username)
{
try
{
URL url = new URL(crf.getBase().toURL(), RESOURCE_PREFIX + "/accounts/u/" + username);
URL url = new URL(getBaseUrl(), "accounts/u/" + username);
return url.toURI();
}
catch (MalformedURLException e)
Expand All @@ -195,7 +205,7 @@ public URI getProjectURI(String proj)
{
try
{
URL url = new URL(crf.getBase().toURL(), RESOURCE_PREFIX + "/projects/p/" + proj);
URL url = new URL(getBaseUrl(), "projects/p/" + proj);
return url.toURI();
}
catch (MalformedURLException e)
Expand All @@ -217,7 +227,7 @@ public URI getProjectIterationURI(String proj, String iter)
{
try
{
URL url = new URL(crf.getBase().toURL(), RESOURCE_PREFIX + "/projects/p/" + proj + "/iterations/i/" + iter);
URL url = new URL(getBaseUrl(), "projects/p/" + proj + "/iterations/i/" + iter);
return url.toURI();
}
catch (MalformedURLException e)
Expand Down Expand Up @@ -254,10 +264,10 @@ public IFileResource getFileResource()

private URI getFileURI()
{
String spec = RESOURCE_PREFIX + "/file/";
String spec = "file/";
try
{
return new URL(crf.getBase().toURL(), spec).toURI();
return new URL(getBaseUrl(), spec).toURI();
}
catch (MalformedURLException e)
{
Expand Down Expand Up @@ -291,10 +301,10 @@ public AsynchronousProcessResource getAsynchronousProcessResource()
@Override
public URI getResourceURI(String projectSlug, String versionSlug)
{
String spec = RESOURCE_PREFIX + "/projects/p/" + projectSlug + "/iterations/i/" + versionSlug + "/r";
String spec = "projects/p/" + projectSlug + "/iterations/i/" + versionSlug + "/r";
try
{
return new URL(crf.getBase().toURL(), spec).toURI();
return new URL(getBaseUrl(), spec).toURI();
}
catch (MalformedURLException e)
{
Expand Down Expand Up @@ -323,7 +333,7 @@ protected IVersionResource createIVersionResource()
URL url;
try
{
url = new URL(crf.getBase().toURL(), RESOURCE_PREFIX + "/version");
url = new URL(getBaseUrl(), "version");
return createProxy(IVersionResource.class, url.toURI());
}
catch (MalformedURLException e)
Expand Down

0 comments on commit a72a154

Please sign in to comment.