Package org.jboss.resteasy.client

Examples of org.jboss.resteasy.client.ClientRequest



   @Test
   public void testMapper() throws Exception
   {
      ClientRequest request = new ClientRequest(generateBaseUrl() + "/test");
      ClientResponse response = request.get();
      Assert.assertEquals(Response.Status.PRECONDITION_FAILED.getStatusCode(), response.getStatus());
   }
View Full Code Here


   }

   @Test
   public void testMapper() throws Exception
   {
      ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/interception"));
      ClientResponse res = request.get();
      Assert.assertEquals(412, res.getStatus());

   }
View Full Code Here

   }

   @Test
   public void testProvider() throws Exception
   {
      ClientRequest request = new ClientRequest(generateURL("/map"));
      ClientResponse<String> response = request.get(String.class);
      Assert.assertEquals(200, response.getStatus());
      System.out.println(response.getEntity());

      request = new ClientRequest(generateURL("/map"));
      request.body("application/json", response.getEntity());
      response = request.post();
      Assert.assertEquals(200, response.getStatus());

      request = new ClientRequest(generateURL("/map"));
      request.body("application/json", "{\"monica\":{\"foo\":{\"@name\":\"monica\"}},\"bill\":{\"foo\":{\"@name\":\"bill\"}}}");
      response = request.post();
      Assert.assertEquals(200, response.getStatus());
   }
View Full Code Here

   }

   @Test
   public void testEmptyMap() throws Exception
   {
      ClientRequest request = new ClientRequest(generateURL("/map/empty"));
      request.body("application/json", "{}");
      ClientResponse<String> response = request.post(String.class);
      Assert.assertEquals(200, response.getStatus());
      Assert.assertEquals("{}", response.getEntity());

   }
View Full Code Here

   {
      Verifier verifier = new Verifier();
      Verification verification = verifier.addNew();
      verification.setRepository(repository);

      ClientRequest request = new ClientRequest("http://localhost:9095/signed");
      ClientResponse<String> response = request.get(String.class);
      response.getAttributes().put(Verifier.class.getName(), verifier);

      System.out.println("Client: ");
      System.out.println(response.getHeaders().getFirst(DKIMSignature.DKIM_SIGNATURE));
      Assert.assertEquals(200, response.getStatus());
View Full Code Here

   }

   @Test
   public void testPost() throws Exception
   {
      ClientRequest request = new ClientRequest("http://localhost:9095/signed");
      DKIMSignature contentSignature = new DKIMSignature();
      contentSignature.setSelector("bill");
      contentSignature.setDomain("client.com");
      request.getAttributes().put(KeyRepository.class.getName(), repository);

      request.header(DKIMSignature.DKIM_SIGNATURE, contentSignature);
      request.body("text/plain", "hello world");
      ClientResponse response = request.post();
      Assert.assertEquals(204, response.getStatus());


   }
View Full Code Here

   @Test
   public void testPopulateDB() throws Exception
   {
      String url = "http://localhost:9095/shop";
      ClientRequest request = new ClientRequest("http://localhost:8080/ex11_1-war/shop");
      ClientResponse response = request.head();
      Map<String, Link> shoppingLinks = processLinkHeaders(response);

      System.out.println("** Populate Products");
      request = new ClientRequest(shoppingLinks.get("products").getHref());

      Product product = new Product();
      product.setName("iPhone");
      product.setCost(199.99);
      request.body("application/xml", product);
      response = request.post();
      Assert.assertEquals(201, response.getStatus());

      product = new Product();
      product.setName("MacBook Pro");
      product.setCost(3299.99);
      request.body("application/xml", product);
      response = request.post();
      Assert.assertEquals(201, response.getStatus());

      product = new Product();
      product.setName("iPod");
      product.setCost(49.99);
      request.body("application/xml", product);
      response = request.post();
      Assert.assertEquals(201, response.getStatus());

   }
View Full Code Here

   @Test
   public void testCreateOrder() throws Exception
   {
      String url = "http://localhost:9095/shop";
      ClientRequest request = new ClientRequest("http://localhost:8080/ex11_1-war/shop");
      ClientResponse response = request.head();
      Map<String, Link> shoppingLinks = processLinkHeaders(response);

      System.out.println("** Buy an iPhone for Bill Burke");
      System.out.println();
      System.out.println("** First see if Bill Burke exists as a customer");
      request = new ClientRequest(shoppingLinks.get("customers").getHref() + "?firstName=Bill&lastName=Burke");
      Customers customers = request.getTarget(Customers.class);
      Customer customer = null;
      if (customers.getCustomers().size() > 0)
      {
         System.out.println("- Found a Bill Burke in the database, using that");
         customer = customers.getCustomers().iterator().next();
      }
      else
      {
         System.out.println("- Cound not find a Bill Burke in the database, creating one.");
         customer = new Customer();
         customer.setFirstName("Bill");
         customer.setLastName("Burke");
         customer.setStreet("222 Dartmouth Street");
         customer.setCity("Boston");
         customer.setState("MA");
         customer.setZip("02115");
         customer.setCountry("USA");
         request = new ClientRequest(shoppingLinks.get("customers").getHref());
         request.body("application/xml", customer);
         response = request.post();
         Assert.assertEquals(201, response.getStatus());
         String uri = (String) response.getHeaders().getFirst("Location");

         request = new ClientRequest(uri);
         customer = request.getTarget(Customer.class);
      }

      System.out.println();
      System.out.println("Search for iPhone in the Product database");
      request = new ClientRequest(shoppingLinks.get("products").getHref() + "?name=iPhone");
      Products products = request.getTarget(Products.class);
      Product product = null;
      if (products.getProducts().size() > 0)
      {
         System.out.println("- Found iPhone in the database.");
         product = products.getProducts().iterator().next();
      }
      else
      {
         throw new RuntimeException("Failed to find an iPhone in the database!");
      }

      System.out.println();
      System.out.println("** Create Order for iPhone");
      LineItem item = new LineItem();
      item.setProduct(product);
      item.setQuantity(1);
      Order order = new Order();
      order.setTotal(product.getCost());
      order.setCustomer(customer);
      order.setDate(new Date().toString());
      order.getLineItems().add(item);
      request = new ClientRequest(shoppingLinks.get("orders").getHref());
      request.body("application/xml", order);
      response = request.post();
      Assert.assertEquals(201, response.getStatus());

      System.out.println();
      System.out.println("** Show all orders.");
      request = new ClientRequest(shoppingLinks.get("orders").getHref());
      String xml = request.getTarget(String.class);
      System.out.println(xml);


   }
View Full Code Here

   @Test
   public void testCarResource() throws Exception
   {

      System.out.println("**** Via @MatrixParam ***");
      ClientRequest get = new ClientRequest(TestPortProvider.generateURL("/cars/mercedes/matrixparam/e55;color=black/2006"));
      ClientResponse<String> response = get.get(String.class);
      Assert.assertEquals(200, response.getStatus());
      Assert.assertEquals("A black 2006 mercedes e55", response.getEntity());

      System.out.println("**** Via PathSegment ***");
      get = new ClientRequest(TestPortProvider.generateURL("/cars/mercedes/pathsegment/e55;color=black/2006"));
      response = get.get(String.class);
      Assert.assertEquals(200, response.getStatus());
      Assert.assertEquals("A black 2006 mercedes e55", response.getEntity());

      System.out.println("**** Via PathSegments ***");
      get = new ClientRequest(TestPortProvider.generateURL("/cars/mercedes/pathsegments/e55/amg/year/2006"));
      response = get.get(String.class);
      Assert.assertEquals(200, response.getStatus());
      Assert.assertEquals("A 2006 mercedes e55 amg", response.getEntity());

      System.out.println("**** Via PathSegment ***");
      get = new ClientRequest(TestPortProvider.generateURL("/cars/mercedes/uriinfo/e55;color=black/2006"));
      response = get.get(String.class);
      Assert.assertEquals(200, response.getStatus());
      Assert.assertEquals("A black 2006 mercedes e55", response.getEntity());
   }
View Full Code Here

    * @param path the request path
    * @return the ClientRequest object
    */
   public static ClientRequest createClientRequest(String path)
   {
      return new ClientRequest(generateURL(path));
   }
View Full Code Here

TOP

Related Classes of org.jboss.resteasy.client.ClientRequest

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.