× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Ok. So today I made some changes to my iSeries software and went through my
usual motions of testing it thoroughly.  When I was done I realized I spent
about 2 hours cutting and pasting various xml documents into my GUI Web
Service Unit Tester (http://mowyourlawn.com/blog/?p=17).  It was then I
realized I needed to "enhance" my method of doing humdrum testing so I
ventured into the JUnit world.  I have read about JUnit but have never
implemented it's practices because I have had other programmatical means to
test various processes, but they are much more manual than what I believe
JUnit has to offer.
 
I have put together what I understand to be JUnits approach to testing if a
web service has executed successfully.  I have done both tests for valid
completion and also tests for exceptions (say errors).  The basic concept is
that I execute an HTTP POST against a web service on the iSeries using a
local document as the POST content.  The response I receive from the POST is
then compared to another local document to see if the expected results were
received.
 
Here is my main class that I execute in Eclipse by doing a Run As -> JUnit
Test
import junit.framework.Test;
import junit.framework.TestSuite;
 
public class AllTests {
    public static void main(String[] args) {
    }
    public static Test suite() {
        TestSuite suite = new TestSuite("Web service testing");
        //$JUnit-BEGIN$
        suite.addTestSuite(Webservices.class);
        //$JUnit-END$
        return suite;
    }
}
 
-----Here is the Webservices.java file-----
import java.io.IOException;
import java.net.ConnectException;
import java.net.MalformedURLException;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import util.FileControl;
import util.HttpUtil;
 
public class Webservices extends TestCase {
    String svrUrl = "http://172.29.134.41:8181/myrxs/";;
    public Webservices(String arg0) {
        super(arg0);
    }
    @Before
    protected void setUp() throws Exception {
        super.setUp();
    }
    @After
    protected void tearDown() throws Exception {
        super.tearDown();
    }
    @Test
    public void test_rxs5_t1() {
        System.out.println("Running...rxs5_t1");
        try {
            String fullUrl = svrUrl + "rxs5";
            String postContent =
FileControl.readFileToString("xml/reqdocs/rxs5_t1.xml");
            String contentType = "text/xml";
            String soapAction = "";
 
            String actual = HttpUtil.post(fullUrl, postContent, contentType,
soapAction);
            String expected =
FileControl.readFileToString("xml/rspdocs/rxs5_t1.xml");
 
            assertEquals("Response document not as expected.", expected,
actual);
 
        } catch (ConnectException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    @Test
    public void test_rxs5_t2() {
        System.out.println("Running...rxs5_t2");
        try {
            String fullUrl = svrUrl + "rxs5";
            String postContent =
FileControl.readFileToString("xml/reqdocs/rxs5_t2.xml");
            String contentType = "text/xml";
            String soapAction = "";
 
            String actual = HttpUtil.post(fullUrl, postContent, contentType,
soapAction);
            String expected =
FileControl.readFileToString("xml/rspdocs/rxs5_t2.xml");
 
            assertEquals("Response document not as expected.",
actual.startsWith(expected));
 
        } catch (ConnectException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Am I going in the right direction?  
Aaron Bartell
http://mowyourlawn.com

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.