zoukankan      html  css  js  c++  java
  • Jersey(1.19.1)

    The Jersey client API was originally developed to aid the testing of the Jersey server-side, primarily to make it easier to write functional tests in conjunction with the JUnit framework for execution and reporting. It is used extensively and there are currently over 1000 tests.

    Embedded servers, Grizzly and a special in-memory server, are utilized to deploy the test-based services. Many of the Jersey samples contain tests that utilize the client API to server both for testing and examples of how to use the API. The samples utilize Grizzly or embedded Glassfish to deploy the services.

    The following code snippets are presented from the single unit test HelloWorldWebAppTest of the helloworld-webapp sample. The setUp method, called before a test is executed, creates an instance of the Glassfish server, deploys the application, and a WebResource instance that references the base resource:

    @Override
    protected void setUp() throws Exception {
        super.setUp();
    
        // Start Glassfish
        glassfish = new GlassFish(BASE_URI.getPort());
    
        // Deploy Glassfish referencing the web.xml
        ScatteredWar war = new ScatteredWar(
            BASE_URI.getRawPath(), 
            new File("src/main/webapp"),
            new File("src/main/webapp/WEB-INF/web.xml"),
            Collections.singleton(new File("target/classes").toURI().toURL()));
        glassfish.deploy(war);
    
        Client c = Client.create();
        r = c.resource(BASE_URI);
    }

    The tearDown method, called after a test is executed, stops the Glassfish server.

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
        glassfish.stop();
    }

    The testHelloWorld method tests that the response to a GET request to the Web resource returns “Hello World”:

    public void testHelloWorld() throws Exception {
        String responseMsg = r.path("helloworld").get(String.class);
        assertEquals("Hello World", responseMsg);
    }

    Note the use of the path method on the WebResource to build from the base WebResource.

  • 相关阅读:
    NOIP 2017 游记?
    bzoj4596 [Shoi2016]黑暗前的幻想乡
    bzoj2467 [中山市选2010]生成树
    bzoj3534 [Sdoi2014]重建
    bzoj1016 [JSOI2008]最小生成树计数
    bzoj4044 [Cerc2014] Virus synthesis
    bzoj4530 [Bjoi2014]大融合
    bzoj2594 [Wc2006]水管局长数据加强版
    bzoj 2342 [Shoi2011]双倍回文
    bzoj [HNOI2008]Cards
  • 原文地址:https://www.cnblogs.com/huey/p/5401850.html
Copyright © 2011-2022 走看看