Search in sources :

Example 81 with Request

use of org.restlet.Request in project camel by apache.

the class RestletRouteBuilderTest method testNotFound.

@Test
public void testNotFound() throws IOException {
    Client client = new Client(Protocol.HTTP);
    Response response = client.handle(new Request(Method.POST, "http://localhost:" + portNum + "/unknown"));
    // expect error status as no Restlet consumer to handle POST method
    assertEquals(Status.CLIENT_ERROR_NOT_FOUND, response.getStatus());
    assertNotNull(response.getEntity().getText());
}
Also used : Response(org.restlet.Response) Request(org.restlet.Request) Client(org.restlet.Client) Test(org.junit.Test)

Example 82 with Request

use of org.restlet.Request in project camel by apache.

the class RestletRouteBuilderTest method testConsumer.

@Test
public void testConsumer() throws IOException {
    Client client = new Client(Protocol.HTTP);
    Response response = client.handle(new Request(Method.GET, "http://localhost:" + portNum + "/orders/99991/6"));
    assertEquals("received GET request with id=99991 and x=6", response.getEntity().getText());
}
Also used : Response(org.restlet.Response) Request(org.restlet.Request) Client(org.restlet.Client) Test(org.junit.Test)

Example 83 with Request

use of org.restlet.Request in project camel by apache.

the class RestletRouteBuilderTest method testConsumerWithSpaces.

@Test
public void testConsumerWithSpaces() throws IOException {
    Client client = new Client(Protocol.HTTP);
    Response response = client.handle(new Request(Method.GET, "http://localhost:" + portNum + "/orders with spaces in path/99991/6"));
    assertEquals("received GET request with id=99991 and x=6", response.getEntity().getText());
}
Also used : Response(org.restlet.Response) Request(org.restlet.Request) Client(org.restlet.Client) Test(org.junit.Test)

Example 84 with Request

use of org.restlet.Request in project lucene-solr by apache.

the class TestRestManager method testResolveResourceIdDecodeUrlEntities.

@Test
public void testResolveResourceIdDecodeUrlEntities() throws Exception {
    Request testRequest = new Request();
    Reference rootRef = new Reference("http://solr.apache.org/");
    testRequest.setRootRef(rootRef);
    Reference resourceRef = new Reference("http://solr.apache.org/schema/analysis/synonyms/de/%C3%84ndern");
    testRequest.setResourceRef(resourceRef);
    String resourceId = RestManager.ManagedEndpoint.resolveResourceId(testRequest);
    assertEquals(resourceId, "/schema/analysis/synonyms/de/Ă„ndern");
}
Also used : Reference(org.restlet.data.Reference) Request(org.restlet.Request) Test(org.junit.Test)

Example 85 with Request

use of org.restlet.Request in project helix by apache.

the class AdminTestHelper method get.

public static ZNRecord get(Client client, String url) throws IOException {
    Reference resourceRef = new Reference(url);
    Request request = new Request(Method.GET, resourceRef);
    Response response = client.handle(request);
    Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
    Representation result = response.getEntity();
    StringWriter sw = new StringWriter();
    result.write(sw);
    String responseStr = sw.toString();
    Assert.assertTrue(responseStr.toLowerCase().indexOf("error") == -1);
    Assert.assertTrue(responseStr.toLowerCase().indexOf("exception") == -1);
    ObjectMapper mapper = new ObjectMapper();
    ZNRecord record = mapper.readValue(new StringReader(responseStr), ZNRecord.class);
    return record;
}
Also used : Response(org.restlet.Response) StringWriter(java.io.StringWriter) Reference(org.restlet.data.Reference) Request(org.restlet.Request) StringReader(java.io.StringReader) Representation(org.restlet.representation.Representation) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) ZNRecord(org.apache.helix.ZNRecord)

Aggregations

Request (org.restlet.Request)100 Response (org.restlet.Response)64 Test (org.testng.annotations.Test)38 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)37 Reference (org.restlet.data.Reference)26 Representation (org.restlet.representation.Representation)24 ChallengeResponse (org.restlet.data.ChallengeResponse)18 StringWriter (java.io.StringWriter)15 Status (org.restlet.data.Status)15 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 HashMap (java.util.HashMap)12 ZNRecord (org.apache.helix.ZNRecord)11 AccessToken (org.forgerock.oauth2.core.AccessToken)11 AccessTokenVerifier (org.forgerock.oauth2.core.AccessTokenVerifier)11 StringReader (java.io.StringReader)10 TypeReference (org.codehaus.jackson.type.TypeReference)10 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)9 Form (org.restlet.data.Form)9 OAuth2ProviderSettings (org.forgerock.oauth2.core.OAuth2ProviderSettings)8 BeforeMethod (org.testng.annotations.BeforeMethod)8