Jaxrs endpoint

Run
How to run the sample
The source code for this sample can be found in the javaee7-samples GitHub repository. The first thing we need to do is to get the source by downloading the repository and then go into the samples folder:
git clone git://github.com/javaee-samples/javaee7-samples.git
cd javaee7-samples/jaxrs/jaxrs-endpoint/
Now we are ready to start testing. You can run all the tests in this sample by executing:
mvn test
Or you can run individual tests by executing one of the following:
mvn test -Dtest=MyResourceTest

  • Specifications in use:
    • JAXRS

    MyResourceTest

    Missing a description for the story. Add some javadoc to the TestClass. Show me how!

    Arquillian specific method for creating a file which can be deployed while executing the test.

    @Deployment(testable = false)
    public static WebArchive createDeployment() {
        WebArchive war = ShrinkWrap.create(WebArchive.class).
                addClass(MyApplication.class).
                addClass(Database.class).
                addClass(MyResource.class);
        System.out.println(war.toString(true));
    
        return war;
    }

    Test of POST method, of class MyResource.

    @Test
    public void test1Post() {
        target.request().post(Entity.text("apple"));
        String r = target.request().get(String.class);
        assertEquals("[apple]", r);
    }

    Test of PUT method, of class MyResource.

    @Test
    public void test2Put() {
        target.request().put(Entity.text("banana"));
        String r = target.request().get(String.class);
        assertEquals("[apple, banana]", r);
    }

    Test of GET method, of class MyResource.

    @Test
    public void test3GetAll() {
        String r = target.request().get(String.class);
        assertEquals("[apple, banana]", r);
    }

    Test of GET method, of class MyResource.

    @Test
    public void test4GetOne() {
        String r = target.path("apple").request().get(String.class);
        assertEquals("apple", r);
    }

    Test of GET method, of class MyResource.

    @Test
    public void test5Delete() {
        target.path("banana").request().delete();
        String r = target.request().get(String.class);
        assertEquals("[apple]", r);
    
        target.path("apple").request().delete();
        r = target.request().get(String.class);
        assertEquals("[]", r);
    }

    Share the Knowledge

    Find this sample useful? Share on

    There's a lot more about JavaEE to cover. If you're ready to learn more, check out the other available samples.

    Help Improve

    Find a bug in the sample? Something missing? You can fix it by editing the source, making the correction and sending a pull request. Or report the problem to the issue tracker

    Recent Changelog

    • Oct 05, 2014: #252 fixed arquillian configuration for the jobs by John D. Ament
    • Jul 15, 2014: Removed default header by Roberto Cortez
    • Jul 15, 2014: Removed header license. the licensing is now referenced in the license file in the root of the project by Roberto Cortez
    • Mar 20, 2014: Update arquillian.xml cr1 references to final by Aslak Knutsen
    • Dec 24, 2013: Updated to wildfly 8.0.0.cr1 by Roberto Cortez
    • Dec 03, 2013: Change to use client.target(uri) to be compatible with jax-rs 1.0 by Aslak Knutsen
    • Nov 12, 2013: Convert jax-rs samples to arquillian: jax-rs endpoint by Aslak Knutsen
    • Nov 12, 2013: Add wildfly managed/remote and glassfish embedded arquillian profiles by Aslak Knutsen
    • Nov 08, 2013: Removing redundant test by Arun Gupta
    • Nov 07, 2013: Resteasy dependency moved to parent pom in a specific profile by Arun Gupta
    How to help improve this sample
    The source code for this sample can be found in the javaee7-samples GitHub repository. The first thing you need to do is to get the source by downloading the repository and then go into the samples folder:
    git clone git://github.com/javaee-samples/javaee7-samples.git
    cd javaee7-samples/jaxrs/jaxrs-endpoint/

    Do the changes as you see fit and send a pull request!

    Good Luck!