Package org.jboss.resteasy.api.validation

Examples of org.jboss.resteasy.api.validation.ResteasyViolationException


//      request.accept(MediaType.APPLICATION_XML);
//      ClientResponse<?> response = request.get(ViolationReport.class);
//      ViolationReport report = response.getEntity(ViolationReport.class);
      ClientResponse<?> response = request.get();
      String report = response.getEntity(String.class);
      ResteasyViolationException e = new ResteasyViolationException(String.class.cast(report));
      log.info("status: " + response.getStatus());
      log.info("entity: " + report);
      assertEquals(400, response.getStatus());
//      countViolations(report, 1, 0, 0, 0, 1, 0);
      countViolations(e, 1, 0, 0, 0, 1, 0);
      ResteasyConstraintViolation cv = e.getParameterViolations().iterator().next();
      Assert.assertTrue(cv.getMessage().equals("must be greater than or equal to 13"));
   }
View Full Code Here


//      request.accept(MediaType.APPLICATION_XML);
//      ClientResponse<?> response = request.get(ViolationReport.class);
//      ViolationReport report = response.getEntity(ViolationReport.class);
      ClientResponse<?> response = request.get();
      String report = response.getEntity(String.class);
      ResteasyViolationException e = new ResteasyViolationException(String.class.cast(report));
      log.info("status: " + response.getStatus());
      log.info("entity: " + report);
      assertEquals(500, response.getStatus());
//      countViolations(report, 1, 0, 0, 0, 0, 1);
//      ResteasyConstraintViolation cv = report.getReturnValueViolations().iterator().next();
      countViolations(e, 1, 0, 0, 0, 0, 1);
      ResteasyConstraintViolation cv = e.getReturnValueViolations().iterator().next();
      Assert.assertTrue(cv.getMessage().equals("must be greater than or equal to 17"));
   }
View Full Code Here

         ClientRequest request = new ClientRequest(generateURL("/none"));
         request.body(MediaType.TEXT_PLAIN_TYPE, "abc");
         ClientResponse<?> response = request.post(String.class);
         Assert.assertEquals(400, response.getStatus());
         String entity = response.getEntity(String.class);
         ResteasyViolationException e = new ResteasyViolationException(String.class.cast(entity));
         System.out.println(e);
         countViolations(e, 2, 0, 2, 0, 0, 0);
      }

      {
         // No method validation. Two property violations.
         ClientRequest request = new ClientRequest(generateURL("/getterOnNonGetter"));
         request.body(MediaType.TEXT_PLAIN_TYPE, "abc");
         ClientResponse<?> response = request.post(Serializable.class);
         Assert.assertEquals(400, response.getStatus());
         String entity = response.getEntity(String.class);
         ResteasyViolationException e = new ResteasyViolationException(String.class.cast(entity));
         System.out.println(e);
         countViolations(e, 2, 0, 2, 0, 0, 0);
      }

      {
         // No method validation. Two property violations
         ClientRequest request = new ClientRequest(generateURL("/nonGetterOnGetter"));
         ClientResponse<?> response = request.post(Serializable.class);
         Assert.assertEquals(400, response.getStatus());
         String entity = response.getEntity(String.class);
         ResteasyViolationException e = new ResteasyViolationException(String.class.cast(entity));
         System.out.println(e);
         countViolations(e, 2, 0, 2, 0, 0, 0);
      }

      {
         // Failure.
         ClientRequest request = new ClientRequest(generateURL("/implicitOnNonGetter"));
         request.body(MediaType.TEXT_PLAIN_TYPE, "abc");
         ClientResponse<?> response = request.post(Serializable.class);
         Assert.assertEquals(400, response.getStatus());
         String entity = response.getEntity(String.class);
         ResteasyViolationException e = new ResteasyViolationException(String.class.cast(entity));
         System.out.println(e);
         countViolations(e, 3, 0, 2, 0, 1, 0);
      }

      {
         // Failure.
         ClientRequest request = new ClientRequest(generateURL("/implicitOnGetter"));
         ClientResponse<?> response = request.post(Serializable.class);
         Assert.assertEquals(400, response.getStatus());
         String entity = response.getEntity(String.class);
         ResteasyViolationException e = new ResteasyViolationException(String.class.cast(entity));
         countViolations(e, 2, 0, 2, 0, 0, 0);
      }

      {
         // Failure.
         ClientRequest request = new ClientRequest(generateURL("/allOnNonGetter"));
         request.body(MediaType.TEXT_PLAIN_TYPE, "abc");
         ClientResponse<?> response = request.post(Serializable.class);
         Assert.assertEquals(400, response.getStatus());
         String entity = response.getEntity(String.class);
         ResteasyViolationException e = new ResteasyViolationException(String.class.cast(entity));
         countViolations(e, 3, 0, 2, 0, 1, 0);
      }

      {
         // Failure.
         ClientRequest request = new ClientRequest(generateURL("/allOnGetter"));
         ClientResponse<?> response = request.post(Serializable.class);
         Assert.assertEquals(400, response.getStatus());
         String entity = response.getEntity(String.class);
         ResteasyViolationException e = new ResteasyViolationException(String.class.cast(entity));
         countViolations(e, 2, 0, 2, 0, 0, 0);
      }

      {
         // Failure.
         ClientRequest request = new ClientRequest(generateURL("/override"));
         request.body(MediaType.TEXT_PLAIN_TYPE, "abc");
         ClientResponse<?> response = request.post(Serializable.class);
         Assert.assertEquals(400, response.getStatus());
         String entity = response.getEntity(String.class);
         ResteasyViolationException e = new ResteasyViolationException(String.class.cast(entity));
         countViolations(e, 3, 0, 2, 0, 1, 0);
      }

      after();
   }
View Full Code Here

      Assert.assertTrue(header instanceof String);
      Assert.assertTrue(Boolean.valueOf(String.class.cast(header)));
      String answer = response.readEntity(String.class);
      System.out.println("entity: " + answer);
      assertEquals(400, response.getStatus());
      ResteasyViolationException e = new ResteasyViolationException(String.class.cast(answer));
      countViolations(e, 1, 1, 1, 1, 0);
      ResteasyConstraintViolation violation = e.getFieldViolations().iterator().next();
      System.out.println("violation: " + violation);
      System.out.println("field path: " + violation.getPath());
      Assert.assertEquals(fieldPath, violation.getPath());
      violation = e.getPropertyViolations().iterator().next();
      System.out.println("property path: " + violation.getPath());
      Assert.assertEquals(propertyPath, violation.getPath());
      violation = e.getClassViolations().iterator().next();
      System.out.println("class path: " + violation.getPath());
      Assert.assertEquals(classPath, violation.getPath());;
      violation = e.getParameterViolations().iterator().next();
      System.out.println("parameter path: " + violation.getPath());
      Assert.assertEquals(parameterPath, violation.getPath());
   }
View Full Code Here

      Assert.assertTrue(header instanceof String);
      Assert.assertTrue(Boolean.valueOf(String.class.cast(header)));
      String answer = response.readEntity(String.class);
      System.out.println("entity: " + answer);
      assertEquals(400, response.getStatus());
      ResteasyViolationException e = new ResteasyViolationException(String.class.cast(answer));
      countViolations(e, 0, 0, 0, 0, 1);
      ResteasyConstraintViolation violation = e.getReturnValueViolations().iterator().next();
      System.out.println("return value path: " + violation.getPath());
      Assert.assertEquals(returnValuePath, violation.getPath());
   }
View Full Code Here

      Assert.assertEquals(400, response.getStatus());
      String header = response.getResponseHeaders().getFirst(Validation.VALIDATION_HEADER);
      Assert.assertNotNull(header);
      Assert.assertTrue(Boolean.valueOf(header));
      String entity = response.getEntity(String.class);
      ResteasyViolationException e = new ResteasyViolationException(entity);
      countViolations(e, 4, 1, 1, 1, 1, 0);
      ResteasyConstraintViolation violation = e.getFieldViolations().iterator().next();
      System.out.println("field path: " + violation.getPath());
      Assert.assertEquals(fieldPath, violation.getPath());
      violation = e.getPropertyViolations().iterator().next();
      System.out.println("property path: " + violation.getPath());
      Assert.assertEquals(propertyPath, violation.getPath());
      violation = e.getClassViolations().iterator().next();
      System.out.println("class path: " + violation.getPath());
      Assert.assertEquals(classPath, violation.getPath());
      violation = e.getParameterViolations().iterator().next();
      System.out.println("parameter path: " + violation.getPath());
      Assert.assertEquals(parameterPath, violation.getPath());
   }
View Full Code Here

      Assert.assertEquals(500, response.getStatus());
      String header = response.getResponseHeaders().getFirst(Validation.VALIDATION_HEADER);
      Assert.assertNotNull(header);
      Assert.assertTrue(Boolean.valueOf(header));
      String entity = response.getEntity(String.class);
      ResteasyViolationException e = new ResteasyViolationException(entity);
      ResteasyConstraintViolation violation = e.getReturnValueViolations().iterator().next();
      System.out.println("return value path: " + violation.getPath());
      Assert.assertEquals(returnValuePath, violation.getPath());
   }
View Full Code Here

      ClientResponse<?> response = request.get();
      log.info("status: " + response.getStatus());
      Object entity = response.getEntity(String.class);
      System.out.println("entity: " + entity);
      Assert.assertEquals(400, response.getStatus());
      ResteasyViolationException e = new ResteasyViolationException(String.class.cast(entity));
      log.info("result: " + e.toString());
      countViolations(e, 4, 0, 2, 1, 1, 0);
      Iterator<ResteasyConstraintViolation> it = e.getPropertyViolations().iterator();
      ResteasyConstraintViolation cv1 = it.next();
      ResteasyConstraintViolation cv2 = it.next();
      boolean b1 = cv1.getPath().indexOf("numberOne") > -1 && cv2.getPath().indexOf("numberTwo") > -1;
      boolean b2 = cv2.getPath().indexOf("numberOne") > -1 && cv1.getPath().indexOf("numberTwo") > -1;
      Assert.assertTrue(b1 || b2);
      cv1 = e.getClassViolations().iterator().next();
      Assert.assertTrue(cv1.getMessage().indexOf("SumConstraint") > -1);
      cv1 = e.getParameterViolations().iterator().next();
      log.info("path: " + cv1.getPath());
      Assert.assertTrue(cv1.getPath().indexOf("InputErrorResource") > -1);
   }
View Full Code Here

      ClientRequest request = new ClientRequest("http://localhost:8080/resteasy-cdi-ejb-test/rest/return/test");
      ClientResponse<?> response = request.get();
      log.info("status: " + response.getStatus());
      Object entity = response.getEntity(String.class);
      System.out.println("entity: " + entity);
      ResteasyViolationException e = new ResteasyViolationException(String.class.cast(entity));
      log.info("result: " + e.toString());
      Assert.assertEquals(500, response.getStatus());
      countViolations(e, 1, 0, 0, 0, 0, 1);
      ResteasyConstraintViolation cv = e.getReturnValueViolations().iterator().next();
      Assert.assertTrue(cv.getMessage().indexOf("") > -1);
   }
View Full Code Here

      String header = response.getResponseHeaders().getFirst(Validation.VALIDATION_HEADER);
      Assert.assertNotNull(header);
      Assert.assertTrue(Boolean.valueOf(header));
      String entity = response.getEntity(String.class);
      System.out.println("entity: " + entity);
      ResteasyViolationException e = new ResteasyViolationException(entity);
      System.out.println(e.toString());
      countViolations(e, 1, 0, 0, 0, 0, 1);
   }
View Full Code Here

TOP

Related Classes of org.jboss.resteasy.api.validation.ResteasyViolationException

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.