Package org.jboss.resteasy.client.jaxrs

Examples of org.jboss.resteasy.client.jaxrs.ResteasyClient


   }

   @Test
   public void testMe() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();
      ResteasyWebTarget target = client.target(generateURL("/lang"));
      Invocation.Builder request = target.request().header("Accept-Language", "en-US;q=0,en;q=0.8,de-AT,de;q=0.9");
      Assert.assertEquals(request.get().getStatus(), 200);
      client.close();

   }
View Full Code Here


   }

   @Test
   public void testMe() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();
      MyTest proxy = client.target(TestPortProvider.generateURL("")).proxy(MyTest.class);
      try
      {
         proxy.postIt("hello");
         Assert.fail();
      }
      catch (NotAuthorizedException e)
      {
         Assert.assertEquals(401, e.getResponse().getStatus());
      }
      client.close();
   }
View Full Code Here

    * @throws Exception
    */
   @Test
   public void testMultiValueParam() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();
      ResteasyWebTarget target = client.target(generateURL("/myform/server"));
      Response response = target.request().get();
      int status = response.getStatus();
      Assert.assertEquals(200, status);
      boolean sv1 = false;
      boolean sv2 = false;
      MultivaluedMap<String, String> form = response.readEntity(new javax.ws.rs.core.GenericType<MultivaluedMap<String, String>>(){});
      Assert.assertEquals(2, form.get("servername").size());
      for (String str : form.get("servername"))
      {
         if (str.equals("srv1")) sv1 = true;
         else if (str.equals("srv2")) sv2 = true;
      }
      Assert.assertTrue(sv1);
      Assert.assertTrue(sv2);
      client.close();
   }
View Full Code Here

    * @throws Exception
    */
   @Test
   public void testProxy691() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();
      ResteasyWebTarget target = client.target(generateBaseUrl());
      MyFormProxy proxy = target.proxy(MyFormProxy.class);
      proxy.post(null);
      client.close();
   }
View Full Code Here


   @Test
   public void testEcho()
   {
      ResteasyClient client = new ResteasyClientBuilder().build();

      ResourceInterface proxy = client.target(generateBaseUrl()).proxy(ResourceInterface.class);
      Assert.assertEquals("content", proxy.echo(null));
      client.close();
   }
View Full Code Here

   }

   @Test
   public void testProxy() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();
      ResteasyWebTarget target = client.target(generateBaseUrl());
      FormClientProxy proxy = target.proxy(FormClientProxy.class);
      ClientForm form = new ClientForm();
      form.setBooleanValue(true);
      form.setName("This is My Name");
      form.setDoubleValue(123.45);
      form.setLongValue(566780L);
      form.setIntegerValue(3);
      form.setShortValue((short) 12345);
      form.setHeaderParam(42);
      form.setQueryParam(42);
      form.setId(42);
      MultivaluedMap<String, String> rtn = proxy.post(form);
      Assert.assertEquals(rtn.getFirst(BOOLEAN_VALUE_FIELD), "true");
      Assert.assertEquals(rtn.getFirst(NAME_FIELD), "This is My Name");
      Assert.assertEquals(rtn.getFirst(DOUBLE_VALUE_FIELD), "123.45");
      Assert.assertEquals(rtn.getFirst(LONG_VALUE_FIELD), "566780");
      Assert.assertEquals(rtn.getFirst(INTEGER_VALUE_FIELD), "3");
      Assert.assertEquals(rtn.getFirst(SHORT_VALUE_FIELD), "12345");
      String str = proxy.postString(form);
      System.out.println("STR: " + str);
      String[] params = str.split("&");
      Map<String, String> map = new HashMap<String, String>();
      for (int i = 0; i < params.length; i++)
      {
         int index = params[i].indexOf('=');
         String key = params[i].substring(0, index).trim();
         String value = params[i].substring(index + 1).trim().replace('+', ' ');
         map.put(key, value);
      }
      Assert.assertEquals(map.get(BOOLEAN_VALUE_FIELD), "true");
      Assert.assertEquals(map.get(NAME_FIELD), "This is My Name");
      Assert.assertEquals(map.get(DOUBLE_VALUE_FIELD), "123.45");
      Assert.assertEquals(map.get(LONG_VALUE_FIELD), "566780");
      Assert.assertEquals(map.get(INTEGER_VALUE_FIELD), "3");
      Assert.assertEquals(map.get(SHORT_VALUE_FIELD), "12345");
      client.close();
   }
View Full Code Here

   @Test
   public void testFormResource() throws Exception
   {     
      InputStream in = null;
      ResteasyClient client = new ResteasyClientBuilder().build();
      try
      {
         ResteasyWebTarget target = client.target(TEST_URI);
         Invocation.Builder request = target.request();
         request.header("custom-header", "42");
         Form form = new Form().param(BOOLEAN_VALUE_FIELD, "true")
                               .param(NAME_FIELD, "This is My Name")
                               .param(DOUBLE_VALUE_FIELD, "123.45")
                               .param(LONG_VALUE_FIELD, "566780")
                               .param(INTEGER_VALUE_FIELD, "3")
                               .param(SHORT_VALUE_FIELD, "12345");
         Response response = request.post(Entity.form(form));
         Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
         String contentType = response.getHeaderString("content-type");
         Assert.assertEquals("application/x-www-form-urlencoded", contentType);
         InputStream responseStream = response.readEntity(InputStream.class);
         in = new BufferedInputStream(responseStream);
         String formData = readString(in);
         String[] keys = formData.split("&");
         Map<String, String> values = new HashMap<String, String>();
         for (String pair : keys)
         {
            int index = pair.indexOf('=');
            if (index < 0)
            {
               values.put(URLDecoder.decode(pair, "UTF-8"), null);
            }
            else if (index > 0)
            {
               values.put(URLDecoder.decode(pair.substring(0, index), "UTF-8"), URLDecoder.decode(pair
                     .substring(index + 1), "UTF-8"));
            }
         }
         Assert.assertEquals(values.get(BOOLEAN_VALUE_FIELD), "true");
         Assert.assertEquals(values.get(NAME_FIELD), "This is My Name");
         Assert.assertEquals(values.get(DOUBLE_VALUE_FIELD), "123.45");
         Assert.assertEquals(values.get(LONG_VALUE_FIELD), "566780");
         Assert.assertEquals(values.get(INTEGER_VALUE_FIELD), "3");
      }
      finally
      {
         if (in != null)
         {
            in.close();
         }
         client.close();
      }
   }
View Full Code Here

   }

   @Test
   public void lastModifiedTest() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();
      ResteasyWebTarget target = client.target(generateURL("/last"));
      Invocation.Builder request = target.request();
      Response response = request.get();
      System.out.println("status: " + response.getStatus());
      System.out.println("lastModified string: " + response.getHeaderString("last-modified"));
      Date last = response.getLastModified();
      System.out.println("lastModified Date:   " + DateUtil.formatDate(last));
      System.out.println("expected:            " + DateUtil.formatDate(RIGHT_AFTER_BIG_BANG));
      Assert.assertEquals(response.getStatus(), 200);
      Assert.assertEquals(DateUtil.formatDate(RIGHT_AFTER_BIG_BANG), DateUtil.formatDate(last));
      client.close();
   }
View Full Code Here


   @Test
   public void testStreamStillOpen() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();

      final MyResource proxy = client.target( "http://localhost:8081").proxy(MyResource.class);
      boolean failed = true;
      try
      {
         String str = proxy.error();
         failed = false;
      }
      catch (NotFoundException e)
      {
         Assert.assertEquals(e.getResponse().getStatus(), 404);
         Assert.assertEquals(e.getResponse().readEntity(String.class), "there was an error");
         e.getResponse().close();
      }

      Assert.assertTrue(failed);
      client.close();
   }
View Full Code Here

   }

   @Test
   public void testEcho()  throws Exception
   {
      ResteasyClient client1 = new ResteasyClientBuilder().socketTimeout(2, TimeUnit.SECONDS).build();
      ClientHttpEngine engine = client1.httpEngine();
      Assert.assertNotNull(engine);

      ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
      ResteasyWebTarget target = client.target(TestPortProvider.generateURL("/timeout"));
      try
      {
         Response response = target.queryParam("sleep", "5").request().get();
         Assert.fail();
      }
      catch (ProcessingException e)
      {
         Assert.assertEquals(e.getCause().getClass(), SocketTimeoutException.class);
      }

      TimeoutResource proxy = client.target(TestPortProvider.generateURL("")).proxy(TimeoutResource.class);
      try
      {
         proxy.get(5);
         Assert.fail();
      }
View Full Code Here

TOP

Related Classes of org.jboss.resteasy.client.jaxrs.ResteasyClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.