Package com.volantis.testtools.servletunit

Examples of com.volantis.testtools.servletunit.ServletRunner$JasperJSPServletDescriptor


    /**
     * This tests the creation and initialisation of the servlet.
     */
    public void testInstantiation() throws Exception {
        ServletRunner runner = new ServletRunner(createWebXML(
                createConfigFile(null, null, 10, false, null)));

        ServletUnitClient client = runner.newClient();

        WebRequest request = createPostRequest(VALID_TEST_XML, READER_TEST_URL);
        request.setHeaderField("User-Agent", "Mozilla/5.0 Firefox...");
        request.setHeaderField("Accept", "text/html");

        // Try with a invalid location specified in the config file
        try {
            client.getResponse(request);
            fail("Runtime exception because of invalid location expected");
        } catch (RuntimeException e) {
            // This is expected...
        }

        // Now try where the init() etc. should succeed
        runner = new ServletRunner(createDefaultWebXML());
        client = runner.newClient();

        request = createPostRequest(VALID_TEST_XML, READER_TEST_URL);
        request.setHeaderField("User-Agent", "Mozilla/5.0 Firefox...");
        request.setHeaderField("Accept", "text/html");
        client.getResponse(request);
View Full Code Here


     *
     * @throws Exception
     */
    public void testStore() throws Exception {

        ServletRunner runner = new ServletRunner(createDefaultWebXML());
        ServletUnitClient client = runner.newClient();

        WebRequest request = createPostRequest(VALID_TEST_XML, READER_TEST_URL);

        WebResponse response = client.getResponse(request);
        String id = response.getHeaderField(
View Full Code Here

     *
     * @throws Exception
     */
    public void testValidatingStore() throws Exception {
        // create validating message store
        ServletRunner runner = new ServletRunner(createWebXML(
                createConfigFile(MessageStoreTestHelper.MESSAGE_STORE_LOCATION,
                                 null,
                                 10,
                                 true,
                                 null)));

        // tets with valid XML
        ServletUnitClient client = runner.newClient();
        WebRequest request = createPostRequest(VALID_TEST_XML, READER_TEST_URL);
        WebResponse response = client.getResponse(request);
        String id = response.getHeaderField(
                MessageStoreServlet.MESSAGE_RESPONSE_HEADER_NAME);

        // Check the ID has been returned OK
        assertNotNull("ID should exist in the headers", id);
        // Look for the file
        File storedFile =
                new File(MessageStoreTestHelper.MESSAGE_STORE_LOCATION,
                         id + ".xml");
        assertTrue("Stored file should exist", storedFile.exists());


        // And using invalid XML
        request = createPostRequest(INVALID_TEST_XML, READER_TEST_URL);
        client = runner.newClient();
        try {
            response = client.getResponse(request);
            fail("This is invalid XML and should cause an exception");
        } catch (HttpException he) {
            // Test success
View Full Code Here

     *
     * @throws Exception
     */

    public void testNonExistentID() throws Exception {
        ServletRunner runner = new ServletRunner(createDefaultWebXML());
        ServletUnitClient client = runner.newClient();

        WebRequest request = createPostRequest(VALID_TEST_XML, READER_TEST_URL);
        WebResponse response = client.getResponse(request);
        String id = response.getHeaderField(
                MessageStoreServlet.MESSAGE_RESPONSE_HEADER_NAME);

        // Check the ID has been returned OK
        assertNotNull("ID should exist in the headers", id);

        // Use a fake servlet class to avoid the need to initialise and run
        // an entire MCS session.
        request = new GetMethodWebRequest(PARTIAL_TEST_URL);
        request.setHeaderField("User-Agent", "Mozilla/5.0 Firefox...");
        request.setParameter(MessageStoreServlet.MESSAGE_RETRIEVE_PARAM_NAME,
                             id);

        client = runner.newClient();
        response = client.getResponse(request);
        assertEquals("The response code should indicate success",
                     MessageStoreMessageEnumeration.SUCCESS.getValue(),
                     response.getResponseCode());

        // create invalid ID
        String invalidID = "123h23h29t";

        // get the invalid ID
        request = new GetMethodWebRequest(FULL_TEST_URL);
        request.setHeaderField("User-Agent", "Mozilla/5.0 Firefox...");
        request.setParameter(MessageStoreServlet.MESSAGE_RETRIEVE_PARAM_NAME,
                             invalidID);

        client = runner.newClient();

        try {
            client.getResponse(request);
            fail("Getting an invalid ID is not allowed and should throw a 404");
        } catch (HttpException he) {
View Full Code Here

     *
     * @throws Exception
     */

    public void testGetStore() throws Exception {
        ServletRunner runner = new ServletRunner(createDefaultWebXML());
        ServletUnitClient client = runner.newClient();

        WebRequest getRequest = new GetMethodWebRequest(FULL_TEST_URL);
        getRequest.setParameter(MessageStoreServlet.MESSAGE_STORE_PARAM_NAME,
                             VALID_TEST_XML);

View Full Code Here

     *
     * @throws Exception
     */

    public void testMixedRequest() throws Exception {
        ServletRunner runner = new ServletRunner(createDefaultWebXML());
        ServletUnitClient client = runner.newClient();

        WebRequest request = createPostRequest(VALID_TEST_XML, READER_TEST_URL);
        WebResponse response = client.getResponse(request);
        String id = response.getHeaderField(
                MessageStoreServlet.MESSAGE_RESPONSE_HEADER_NAME);
View Full Code Here

    public void testEmptyMessageBody() throws Exception {
        // emtpy message
        final String emptyMsg = "";

        // create MSS
        ServletRunner runner = new ServletRunner(createDefaultWebXML());
        ServletUnitClient client = runner.newClient();

        WebRequest request = createPostRequest(emptyMsg, READER_TEST_URL);
        request.setHeaderField("User-Agent", "Mozilla/5.0 Firefox...");

        try {
View Full Code Here

    /**
     * This tests the retrieval operation using a GET request
     */

    public void testRetrieve() throws Exception {
        ServletRunner runner = new ServletRunner(createDefaultWebXML());
        ServletUnitClient client = runner.newClient();

        WebRequest request = createPostRequest(VALID_TEST_XML, READER_TEST_URL);
        WebResponse response = client.getResponse(request);
        String id = response.getHeaderField(
                MessageStoreServlet.MESSAGE_RESPONSE_HEADER_NAME);

        // Check the ID has been returned OK
        assertNotNull("ID should exist in the headers", id);

        // Use a fake servlet class to avoid the need to initialise and run
        // an entire MCS session.
        request = new GetMethodWebRequest(PARTIAL_TEST_URL);
        request.setHeaderField("User-Agent", "Mozilla/5.0 Firefox...");
        request.setParameter(MessageStoreServlet.MESSAGE_RETRIEVE_PARAM_NAME,
                             id);

        client = runner.newClient();
        response = client.getResponse(request);
        assertEquals("The response code should indicate success",
                     MessageStoreMessageEnumeration.SUCCESS.getValue(),
                     response.getResponseCode());
        String message = response.getText();
View Full Code Here

TOP

Related Classes of com.volantis.testtools.servletunit.ServletRunner$JasperJSPServletDescriptor

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.