Search in sources :

Example 31 with HttpRequest

use of co.cask.common.http.HttpRequest in project cdap by caskdata.

the class RESTClientTest method testPutUnauthorizedWithAccessToken.

@Test(expected = UnauthenticatedException.class)
public void testPutUnauthorizedWithAccessToken() throws Exception {
    URL url = getBaseURI().resolve("/api/testPutAuth").toURL();
    HttpRequest request = HttpRequest.put(url).build();
    restClient.execute(request, new AccessToken("Unknown", 82000L, "Bearer"));
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) AccessToken(co.cask.cdap.security.authentication.client.AccessToken) URL(java.net.URL) Test(org.junit.Test)

Example 32 with HttpRequest

use of co.cask.common.http.HttpRequest in project cdap by caskdata.

the class RESTClientTest method testPostUnauthorizedWithAccessToken.

@Test(expected = UnauthenticatedException.class)
public void testPostUnauthorizedWithAccessToken() throws Exception {
    URL url = getBaseURI().resolve("/api/testPostAuth").toURL();
    HttpRequest request = HttpRequest.post(url).build();
    restClient.execute(request, new AccessToken("Unknown", 82000L, "Bearer"));
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) AccessToken(co.cask.cdap.security.authentication.client.AccessToken) URL(java.net.URL) Test(org.junit.Test)

Example 33 with HttpRequest

use of co.cask.common.http.HttpRequest in project cdap by caskdata.

the class RESTClientTest method testPostForbidden.

@Test(expected = UnauthorizedException.class)
public void testPostForbidden() throws Exception {
    URL url = getBaseURI().resolve("/api/testPostForbidden").toURL();
    HttpRequest request = HttpRequest.post(url).build();
    restClient.execute(request, new AccessToken("Unknown", 82000L, "Bearer"));
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) AccessToken(co.cask.cdap.security.authentication.client.AccessToken) URL(java.net.URL) Test(org.junit.Test)

Example 34 with HttpRequest

use of co.cask.common.http.HttpRequest in project cdap by caskdata.

the class RESTClientTest method testGetSuccessWithAccessToken.

@Test
public void testGetSuccessWithAccessToken() throws Exception {
    URL url = getBaseURI().resolve("/api/testGetAuth").toURL();
    HttpRequest request = HttpRequest.get(url).build();
    HttpResponse response = restClient.execute(request, new AccessToken(ACCESS_TOKEN, 82000L, "Bearer"));
    verifyResponse(response, only(200), any(), only("Access token received: " + ACCESS_TOKEN));
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) AccessToken(co.cask.cdap.security.authentication.client.AccessToken) HttpResponse(co.cask.common.http.HttpResponse) URL(java.net.URL) Test(org.junit.Test)

Example 35 with HttpRequest

use of co.cask.common.http.HttpRequest in project cdap by caskdata.

the class DatasetServiceTestBase method deployModuleBundled.

// creates a bundled jar with moduleClass and list of bundleEmbeddedJar files, moduleName and moduleClassName are
// used to make request for deploying module.
protected int deployModuleBundled(String moduleName, String moduleClassName, Class moduleClass, Location... bundleEmbeddedJars) throws IOException {
    Location moduleJar = createModuleJar(moduleClass, bundleEmbeddedJars);
    HttpRequest request = HttpRequest.put(getUrl("/data/modules/" + moduleName)).addHeader("X-Class-Name", moduleClassName).withBody(Locations.newInputSupplier(moduleJar)).build();
    return HttpRequests.execute(request).getResponseCode();
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) Location(org.apache.twill.filesystem.Location)

Aggregations

HttpRequest (co.cask.common.http.HttpRequest)97 URL (java.net.URL)75 HttpResponse (co.cask.common.http.HttpResponse)71 Test (org.junit.Test)22 AccessToken (co.cask.cdap.security.authentication.client.AccessToken)13 BadRequestException (co.cask.cdap.common.BadRequestException)10 NotFoundException (co.cask.cdap.common.NotFoundException)9 ApplicationManager (co.cask.cdap.test.ApplicationManager)9 ServiceManager (co.cask.cdap.test.ServiceManager)9 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)6 IOException (java.io.IOException)6 TopicNotFoundException (co.cask.cdap.api.messaging.TopicNotFoundException)5 StreamNotFoundException (co.cask.cdap.common.StreamNotFoundException)5 TypeToken (com.google.common.reflect.TypeToken)5 TypeToken (com.google.gson.reflect.TypeToken)5 ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)4 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)4 Instances (co.cask.cdap.proto.Instances)4 SparkManager (co.cask.cdap.test.SparkManager)4 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)3