Java Code Examples for org.restlet.Response#getEntityAsText()

The following examples show how to use org.restlet.Response#getEntityAsText() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: uReplicator   File: TestAdminManagement.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPostRebalance() {
  Request request = ManagerRequestURLBuilder.baseUrl(REQUEST_URL).postInstanceRebalance();
  Response response = HTTP_CLIENT.handle(request);
  String responseString = response.getEntityAsText();
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
  Assert.assertEquals(responseString, "{\"opt\":\"force_rebalance\",\"status\":200}");
}
 
Example 2
Source Project: uReplicator   File: TestAdminManagement.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPostControllerRebalance() {
  Request request = ManagerRequestURLBuilder.baseUrl(REQUEST_URL).postSetControllerRebalance(true);
  Response response = HTTP_CLIENT.handle(request);
  String responseString = response.getEntityAsText();
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
  Assert.assertEquals(responseString, "{\"execution\":{},\"managerAutoscaling\":true,\"status\":{}}");
  request = ManagerRequestURLBuilder.baseUrl(REQUEST_URL).postSetControllerRebalance("sjc1a", "sjc1-agg1", true);
  response = HTTP_CLIENT.handle(request);
  responseString = response.getEntityAsText();
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
  Assert.assertEquals(responseString, "{\"execution\":{},\"managerAutoscaling\":true,\"status\":{}}");
}
 
Example 3
Source Project: uReplicator   File: TestAdminManagement.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetControllerRebalance() {
  Request request = ManagerRequestURLBuilder.baseUrl(REQUEST_URL).getControllerRebalanceStatus();
  Response response = HTTP_CLIENT.handle(request);
  String responseString = response.getEntityAsText();
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
  Assert.assertEquals(responseString, "{}");
}
 
Example 4
Source Project: uReplicator   File: TestHealthCheck.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testHealthCheck() {
  Request request = ManagerRequestURLBuilder.baseUrl(REQUEST_URL).getHealthCheck();
  Response response = HTTP_CLIENT.handle(request);
  String responseString = response.getEntityAsText();
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
  Assert.assertEquals(responseString, "OK\n");
}
 
Example 5
@Override
public Object readResponse( Response response, Class<?> resultType )
{
    if( response.getEntity().getMediaType().equals( MediaType.APPLICATION_JSON ) )
    {
        if( ValueComposite.class.isAssignableFrom( resultType ) )
        {
            String jsonValue = response.getEntityAsText();
            ValueCompositeType valueType = module.valueDescriptor( resultType.getName() ).valueType();
            return jsonDeserializer.deserialize( module, valueType, jsonValue );
        }
        else if( resultType.equals( Form.class ) )
        {
            try( JsonReader reader = jsonFactories.readerFactory()
                                                  .createReader( response.getEntity().getReader() ) )
            {
                JsonObject jsonObject = reader.readObject();
                Form form = new Form();
                jsonObject.forEach(
                    ( key, value ) ->
                    {
                        String valueString = value.getValueType() == JsonValue.ValueType.STRING
                                             ? ( (JsonString) value ).getString()
                                             : value.toString();
                        form.set( key, valueString );
                    } );
                return form;
            }
            catch( IOException | JsonException e )
            {
                throw new ResourceException( e );
            }
        }
    }
    return null;
}