Search in sources :

Example 1 with BookWithValidation

use of org.apache.cxf.systest.jaxrs.validation.BookWithValidation in project cxf by apache.

the class JAXRSClientServerValidationSpringTest method testHelloSoapValidationFailsIfNameIsNull.

@Test
public void testHelloSoapValidationFailsIfNameIsNull() throws Exception {
    final QName serviceName = new QName("http://bookworld.com", "BookWorld");
    final QName portName = new QName("http://bookworld.com", "BookWorldPort");
    final String address = "http://localhost:" + PORT + "/bwsoap";
    Service service = Service.create(serviceName);
    service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address);
    BookWorld bwService = service.getPort(BookWorld.class);
    BookWithValidation bw = bwService.echoBook(new BookWithValidation("WS", "123"));
    assertEquals("123", bw.getId());
    try {
        bwService.echoBook(new BookWithValidation(null, "123"));
        fail("Validation failure expected");
    } catch (SOAPFaultException ex) {
    // complete
    }
}
Also used : QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) BookWithValidation(org.apache.cxf.systest.jaxrs.validation.BookWithValidation) AbstractJAXRSValidationTest(org.apache.cxf.systest.jaxrs.validation.AbstractJAXRSValidationTest) Test(org.junit.Test)

Example 2 with BookWithValidation

use of org.apache.cxf.systest.jaxrs.validation.BookWithValidation in project cxf by apache.

the class JAXRSClientServerValidationSpringTest method testHelloRestValidationFailsIfNameIsNullClient.

@Test
public void testHelloRestValidationFailsIfNameIsNullClient() throws Exception {
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    bean.setAddress("http://localhost:" + PORT + "/bwrest");
    bean.setServiceClass(BookWorld.class);
    bean.setFeatures(Arrays.asList(new JAXRSClientBeanValidationFeature()));
    BookWorld service = bean.create(BookWorld.class);
    BookWithValidation bw = service.echoBook(new BookWithValidation("RS", "123"));
    assertEquals("123", bw.getId());
    try {
        service.echoBook(new BookWithValidation(null, "123"));
        fail("Validation failure expected");
    } catch (ConstraintViolationException ex) {
    // complete
    }
}
Also used : JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) ConstraintViolationException(javax.validation.ConstraintViolationException) JAXRSClientBeanValidationFeature(org.apache.cxf.jaxrs.client.validation.JAXRSClientBeanValidationFeature) BookWithValidation(org.apache.cxf.systest.jaxrs.validation.BookWithValidation) AbstractJAXRSValidationTest(org.apache.cxf.systest.jaxrs.validation.AbstractJAXRSValidationTest) Test(org.junit.Test)

Example 3 with BookWithValidation

use of org.apache.cxf.systest.jaxrs.validation.BookWithValidation in project cxf by apache.

the class JAXRSServerSpringDiscoveryTest method testThatClientDiscoversServiceProperly.

@Test
public void testThatClientDiscoversServiceProperly() throws Exception {
    BookStore bs = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class, "org/apache/cxf/systest/jaxrs/discovery/jaxrs-http-client.xml");
    assertEquals("http://localhost:" + PORT, WebClient.client(bs).getBaseURI().toString());
    BookWithValidation book = bs.getBook("123");
    assertEquals(book.getId(), "123");
}
Also used : BookWithValidation(org.apache.cxf.systest.jaxrs.validation.BookWithValidation) AbstractJAXRSValidationTest(org.apache.cxf.systest.jaxrs.validation.AbstractJAXRSValidationTest) Test(org.junit.Test)

Example 4 with BookWithValidation

use of org.apache.cxf.systest.jaxrs.validation.BookWithValidation in project cxf by apache.

the class BookStoreWithValidation method addBook.

@POST
@Path("/books")
public Response addBook(@Context final UriInfo uriInfo, @NotNull @FormParam("id") String id, @FormParam("name") String name) {
    final BookWithValidation book = new BookWithValidation(name, id);
    provider.validateBean(book);
    return Response.created(uriInfo.getRequestUriBuilder().path(id).build()).build();
}
Also used : BookWithValidation(org.apache.cxf.systest.jaxrs.validation.BookWithValidation) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 5 with BookWithValidation

use of org.apache.cxf.systest.jaxrs.validation.BookWithValidation in project cxf by apache.

the class JAXRSClientServerValidationSpringTest method testHelloRestValidationFailsIfNameIsNull.

@Test
public void testHelloRestValidationFailsIfNameIsNull() throws Exception {
    String address = "http://localhost:" + PORT + "/bwrest";
    BookWorld service = JAXRSClientFactory.create(address, BookWorld.class);
    BookWithValidation bw = service.echoBook(new BookWithValidation("RS", "123"));
    assertEquals("123", bw.getId());
    try {
        service.echoBook(new BookWithValidation(null, "123"));
        fail("Validation failure expected");
    } catch (BadRequestException ex) {
    // complete
    }
}
Also used : BadRequestException(javax.ws.rs.BadRequestException) BookWithValidation(org.apache.cxf.systest.jaxrs.validation.BookWithValidation) AbstractJAXRSValidationTest(org.apache.cxf.systest.jaxrs.validation.AbstractJAXRSValidationTest) Test(org.junit.Test)

Aggregations

BookWithValidation (org.apache.cxf.systest.jaxrs.validation.BookWithValidation)5 AbstractJAXRSValidationTest (org.apache.cxf.systest.jaxrs.validation.AbstractJAXRSValidationTest)4 Test (org.junit.Test)4 ConstraintViolationException (javax.validation.ConstraintViolationException)1 BadRequestException (javax.ws.rs.BadRequestException)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 QName (javax.xml.namespace.QName)1 Service (javax.xml.ws.Service)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)1 JAXRSClientBeanValidationFeature (org.apache.cxf.jaxrs.client.validation.JAXRSClientBeanValidationFeature)1