Package org.apache.wink.itest.contextresolver

Examples of org.apache.wink.itest.contextresolver.User


    }

    public void testUserContextProvider() throws Exception {
        HttpClient httpClient = new HttpClient();

        User user = new User();
        user.setUserName("joedoe@example.com");
        JAXBElement<User> element =
            new JAXBElement<User>(new QName("http://jaxb.context.tests", "user"), User.class, user);
        JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
        StringWriter sw = new StringWriter();
        Marshaller m = context.createMarshaller();
        m.marshal(element, sw);
        PostMethod postMethod = new PostMethod(getBaseURI());
        try {
            postMethod.setRequestEntity(new ByteArrayRequestEntity(sw.toString().getBytes(),
                                                                   "text/xml"));
            httpClient.executeMethod(postMethod);
            assertEquals(204, postMethod.getStatusCode());
        } finally {
            postMethod.releaseConnection();
        }

        GetMethod getMethod = new GetMethod(getBaseURI() + "/joedoe@example.com");
        try {
            httpClient.executeMethod(getMethod);
            assertEquals(200, getMethod.getStatusCode());
            Unmarshaller u = context.createUnmarshaller();
            element =
                u.unmarshal(new StreamSource(getMethod.getResponseBodyAsStream()), User.class);
            assertNotNull(element);
            user = element.getValue();
            assertNotNull(user);
            assertEquals("joedoe@example.com", user.getUserName());
        } finally {
            getMethod.releaseConnection();
        }
    }
View Full Code Here


@XmlRegistry
public class ObjectFactory {

    @XmlElement(name = "user", namespace = "http://jaxb.context.tests")
    public User createUser() {
        return new User();
    }
View Full Code Here

    }

    public void testUserContextProvider() throws Exception {
        HttpClient httpClient = new HttpClient();

        User user = new User();
        user.setUserName("joedoe@example.com");
        JAXBElement<User> element =
            new JAXBElement<User>(new QName("http://jaxb.context.tests", "user"), User.class, user);
        JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
        StringWriter sw = new StringWriter();
        Marshaller m = context.createMarshaller();
        m.marshal(element, sw);
        PostMethod postMethod = new PostMethod(USER_URI);
        try {
            postMethod.setRequestEntity(new ByteArrayRequestEntity(sw.toString().getBytes(),
                                                                   "text/xml"));
            httpClient.executeMethod(postMethod);
            assertEquals(204, postMethod.getStatusCode());
        } finally {
            postMethod.releaseConnection();
        }

        GetMethod getMethod = new GetMethod(USER_URI + "/joedoe@example.com");
        try {
            httpClient.executeMethod(getMethod);
            assertEquals(200, getMethod.getStatusCode());
            Unmarshaller u = context.createUnmarshaller();
            element =
                u.unmarshal(new StreamSource(getMethod.getResponseBodyAsStream()), User.class);
            assertNotNull(element);
            user = element.getValue();
            assertNotNull(user);
            assertEquals("joedoe@example.com", user.getUserName());
        } finally {
            getMethod.releaseConnection();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.wink.itest.contextresolver.User

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.