Examples of ClientResponse


Examples of org.jboss.resteasy.client.ClientResponse

   {
      // test that media type is chosen from resource method and accepts
      {
         ClientRequest request = new ClientRequest(generateURL("/mapper/accepts-produces"));
         request.accept("application/json");
         ClientResponse response = request.get();
         Assert.assertEquals(412, response.getStatus());
         Assert.assertEquals("application/json", response.getHeaders().getFirst("Content-Type"));
         String error = (String) response.getEntity(String.class);
         Assert.assertNotNull(error);
         System.out.println(error);
      }

      {
         ClientRequest request = new ClientRequest(generateURL("/mapper/accepts-produces"));
         request.accept("application/xml");
         ClientResponse response = request.get();
         Assert.assertEquals(412, response.getStatus());
         Assert.assertEquals("application/xml", response.getHeaders().getFirst("Content-Type"));
         String error = (String) response.getEntity(String.class);
         Assert.assertNotNull(error);
         System.out.println(error);
      }
   }
View Full Code Here

Examples of org.jboss.resteasy.client.ClientResponse

      Assert.assertTrue(header.getLinksByRelationship().containsKey("previous"));
      Assert.assertEquals(header.getLinksByTitle().get("previous chapter").getHref(), "http://example.com/TheBook/chapter2");

      ClientRequest request = new ClientRequest(generateURL("/linkheader/str"));
      request.addLink("previous chapter", "previous", "http://example.com/TheBook/chapter2", null);
      ClientResponse response = request.post();
      header = response.getLinkHeader();
      Assert.assertNotNull(header);
      Assert.assertTrue(header.getLinksByTitle().containsKey("previous chapter"));
      Assert.assertTrue(header.getLinksByRelationship().containsKey("previous"));
      Assert.assertEquals(header.getLinksByTitle().get("previous chapter").getHref(), "http://example.com/TheBook/chapter2");
   }
View Full Code Here

Examples of org.jboss.resteasy.client.ClientResponse

   {
      // test that media type is chosen from accepts
      {
         ClientRequest request = new ClientRequest(generateURL("/mapper/accepts"));
         request.accept("application/json");
         ClientResponse response = request.get();
         Assert.assertEquals(412, response.getStatus());
         Assert.assertEquals("application/json", response.getHeaders().getFirst("Content-Type"));
         String error = (String) response.getEntity(String.class);
         Assert.assertNotNull(error);
         System.out.println(error);
      }

      {
         ClientRequest request = new ClientRequest(generateURL("/mapper/accepts"));
         request.accept("application/xml");
         ClientResponse response = request.get();
         Assert.assertEquals(412, response.getStatus());
         Assert.assertEquals("application/xml", response.getHeaders().getFirst("Content-Type"));
         String error = (String) response.getEntity(String.class);
         Assert.assertNotNull(error);
         System.out.println(error);
      }
   }
View Full Code Here

Examples of org.jboss.resteasy.client.ClientResponse

      Assert.assertTrue(header.getLinksByRelationship().containsKey("start"));
      Assert.assertTrue(header.getLinksByRelationship().containsKey("http://example.net/relation/other"));
      ClientRequest request = new ClientRequest(generateURL("/linkheader"));
      request.header("link", "<http://example.org/>; rel=index;" +
              "             rel=\"start http://example.net/relation/other\"");
      ClientResponse response = request.post();
      header = response.getLinkHeader();
      Assert.assertNotNull(header);
      Assert.assertTrue(header.getLinksByRelationship().containsKey("index"));
      Assert.assertTrue(header.getLinksByRelationship().containsKey("start"));
      Assert.assertTrue(header.getLinksByRelationship().containsKey("http://example.net/relation/other"));
   }
View Full Code Here

Examples of org.jboss.resteasy.client.ClientResponse

   {
      // test that media type is chosen from accepts
      {
         ClientRequest request = new ClientRequest(generateURL("/mapper/accepts-entity"));
         request.accept("application/json");
         ClientResponse response = request.get();
         Assert.assertEquals(200, response.getStatus());
         Assert.assertEquals("application/json", response.getHeaders().getFirst("Content-Type"));
         String error = (String) response.getEntity(String.class);
         Assert.assertNotNull(error);
         System.out.println(error);
      }

      {
         ClientRequest request = new ClientRequest(generateURL("/mapper/accepts-entity"));
         request.accept("application/xml");
         ClientResponse response = request.get();
         Assert.assertEquals(200, response.getStatus());
         Assert.assertEquals("application/xml", response.getHeaders().getFirst("Content-Type"));
         String error = (String) response.getEntity(String.class);
         Assert.assertNotNull(error);
         System.out.println(error);
      }
   }
View Full Code Here

Examples of org.jboss.resteasy.client.ClientResponse

   public void testCreateCancelPurge() throws Exception
   {
      //RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
      String url = "http://localhost:9095/shop";
      ClientRequest request = new ClientRequest(url);
      ClientResponse response = request.head();
      Map<String, Link> shoppingLinks = processLinkHeaders(response);

      Link customers = shoppingLinks.get("customers");
      System.out.println("** Create a customer through this URL: " + customers.getHref());

      Customer customer = new Customer();
      customer.setFirstName("Bill");
      customer.setLastName("Burke");
      customer.setStreet("10 Somewhere Street");
      customer.setCity("Westford");
      customer.setState("MA");
      customer.setZip("01711");
      customer.setCountry("USA");

      request = new ClientRequest(customers.getHref());
      request.body("application/xml", customer);
      response = request.post();
      Assert.assertEquals(201, response.getStatus());

      Link orders = shoppingLinks.get("orders");

      Order order = new Order();
      order.setTotal("$199.99");
      order.setCustomer(customer);
      order.setDate(new Date().toString());
      LineItem item = new LineItem();
      item.setCost("$199.99");
      item.setProduct("iPhone");
      order.setLineItems(new ArrayList<LineItem>());
      order.getLineItems().add(item);

      System.out.println();
      System.out.println("** Create an order through this URL: " + orders.getHref());
      request = new ClientRequest(orders.getHref());
      request.body("application/xml", order);
      response = request.post();
      Assert.assertEquals(201, response.getStatus());
      String createdOrderUrl = (String) response.getHeaders().getFirst("Location");

      System.out.println();
      System.out.println("** New list of orders");
      request = new ClientRequest(orders.getHref());
      response = request.get();
      System.out.println(response.getEntity(String.class));
      Map<String, Link> ordersLinks = processLinkHeaders(response);

      request = new ClientRequest(createdOrderUrl);
      response = request.head();
      Map<String, Link> orderLinks = processLinkHeaders(response);

      Link cancel = orderLinks.get("cancel");
      if (cancel != null)
      {
         System.out.println("** Canceling the order at URL: " + cancel.getHref());
         request = new ClientRequest(cancel.getHref());
         response = request.post();
         Assert.assertEquals(204, response.getStatus());
      }

      System.out.println();
      System.out.println("** New list of orders after cancel: ");
      request = new ClientRequest(orders.getHref());
      response = request.get();
      System.out.println(response.getEntity(String.class));

      System.out.println();
      Link purge = ordersLinks.get("purge");
      System.out.println("** Purge cancelled orders at URL: " + purge.getHref());
      request = new ClientRequest(purge.getHref());
      response = request.post();
      Assert.assertEquals(204, response.getStatus());

      System.out.println();
      System.out.println("** New list of orders after purge: ");
      request = new ClientRequest(orders.getHref());
      response = request.get();
      System.out.println(response.getEntity(String.class));
   }
View Full Code Here

Examples of org.jboss.resteasy.client.ClientResponse

      ClientResponse<Integer> paramPathResult = requestFactory.createRequest(generateURL("/uriParam/{param}")).accept("text/plain")
              .pathParameter("param", 1234).get(Integer.class);
      Assert.assertEquals(1234, paramPathResult.getEntity().intValue());

      Assert.assertEquals(Response.Status.NO_CONTENT, client.putBasicReturnCode("hello world"));
      ClientResponse putResponse = createClientRequest("/basic").body("text/plain", "hello world").put();

      Assert.assertEquals(Response.Status.NO_CONTENT, putResponse.getResponseStatus());

      Assert.assertEquals("headervalue", ((BaseClientResponse) client.getHeaderClientResponse()).getHeaders().getFirst("header"));
      Assert.assertEquals("headervalue", requestFactory.createRequest(generateURL("/header")).get().getHeaders().getFirst("header"));
      Assert.assertEquals("headervalue", client.getHeaderResponse().getMetadata().getFirst("header"));
View Full Code Here

Examples of org.jboss.resteasy.client.ClientResponse

   @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

Examples of org.jboss.resteasy.client.ClientResponse

   @Test
   public void testBadList() throws Exception
   {
      ClientRequest request = new ClientRequest(generateURL("/array"));
      request.body("application/json", "asdfasdfasdf");
      ClientResponse response = request.post();
      Assert.assertEquals(400, response.getStatus());
      response.releaseConnection();

   }
View Full Code Here

Examples of org.jboss.resteasy.client.ClientResponse

      contentSignature.setDomain("samplezone.org");
      contentSignature.setSelector("test");
      contentSignature.setPrivateKey(keys.getPrivate());
      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
TOP
Copyright © 2018 www.massapi.com. 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.