FileDocCategorySizeDatePackage
TestHeaderAttrs.javaAPI DocApache Axis 1.47124Sat Apr 22 18:57:28 BST 2006test.soap

TestHeaderAttrs

public class TestHeaderAttrs extends TestCase
A fairly comprehensive test of MustUnderstand/Actor combinations.
author
Glen Daniels (gdaniels@apache.org)

Fields Summary
static final String
PROP_DOUBLEIT
static final String
GOOD_HEADER_NS
static final String
GOOD_HEADER_NAME
static final String
BAD_HEADER_NS
static final String
BAD_HEADER_NAME
static final String
ACTOR
static org.apache.axis.message.SOAPHeaderElement
goodHeader
static org.apache.axis.message.SOAPHeaderElement
badHeader
private org.apache.axis.configuration.SimpleProvider
provider
private org.apache.axis.server.AxisServer
engine
private org.apache.axis.transport.local.LocalTransport
localTransport
static final String
localURL
protected org.apache.axis.soap.SOAPConstants
soapVersion
Constructors Summary
public TestHeaderAttrs(String name)


       
        super(name);
    
Methods Summary
public booleanrunTest(org.apache.axis.message.SOAPHeaderElement header, boolean doubled)
Call the service with a random string. Returns true if the result is the length of the string (doubled if the doubled arg is true).

        Call call = new Call(new Service());
        call.setSOAPVersion(soapVersion);
        call.setTransport(localTransport);
        
        call.addHeader(header);
        
        String str = "a";
        int maxChars = new Random().nextInt(50);
        for (int i = 0; i < maxChars; i++) {
            str += "a";
        }

        Integer i = (Integer)call.invoke("countChars", new Object [] { str });
        
        int desiredResult = str.length();
        if (doubled) desiredResult = desiredResult * 2;
        
        return (i.intValue() == desiredResult);
    
public voidsetUp()
Prep work. Make a server, tie a LocalTransport to it, and deploy our little test service therein.

        engine.init();
        localTransport.setUrl(localURL);
        
        SOAPService service = new SOAPService(new TestHandler(),
                                              new RPCProvider(),
                                              null);
        
        service.setOption("className", TestService.class.getName());
        service.setOption("allowedMethods", "*");
        
        provider.deployService("testService", service);

        SimpleTargetedChain serverTransport =
                new SimpleTargetedChain(null, null, new LocalResponder());
        provider.deployTransport("local", serverTransport);
    
public voidtestGoodHeader()
Test a recognized header (make sure it has the desired result)

        goodHeader.setActor(soapVersion.getNextRoleURI());
        assertTrue("Good header with next actor returned bad result!",
                   runTest(goodHeader, true));
    
public voidtestGoodHeaderWithActors()
Test a recognized header with a particular actor attribute

        // 1. Good header to unrecognized actor -> should be ignored, and
        //    we should get a non-doubled result
        goodHeader.setActor(ACTOR);
        assertTrue("Good header with unrecognized actor returned bad result!",
                   runTest(goodHeader, false));
        
        // Now tell the engine to recognize the ACTOR value
        engine.addActorURI(ACTOR);
        
        // 2. Good header should now be processed and return doubled result
        assertTrue("Good header with recognized actor returned bad result!",
                   runTest(goodHeader, true));
        
        engine.removeActorURI(ACTOR);
    
public voidtestMUBadHeader()
Test an unrecognized header with MustUnderstand="true"

        // 1. MU header to unrecognized actor -> should work fine
        badHeader.setActor(ACTOR);
        badHeader.setMustUnderstand(true);
        
        assertTrue("Bad result from test", runTest(badHeader, false));
        
        // 2. MU header to NEXT -> should fail
        badHeader.setActor(soapVersion.getNextRoleURI());
        badHeader.setMustUnderstand(true);
        
        // Test (should produce MU failure)
        try {
            runTest(badHeader, false);
        } catch (Exception e) {
            assertTrue("Non AxisFault Exception : " + e, 
                       e instanceof AxisFault);
            AxisFault fault = (AxisFault)e;
            assertEquals("Bad fault code!", soapVersion.getMustunderstandFaultQName(),
                         fault.getFaultCode());
            return;
        }
        
        fail("Should have gotten mustUnderstand fault!");
    
public voidtestNonMUBadHeader()
Test an unrecognized header with MustUnderstand="false"

        badHeader.setActor(soapVersion.getNextRoleURI());
        badHeader.setMustUnderstand(false);

        assertTrue("Non-MU bad header to next actor returned bad result!",
                   runTest(badHeader, false));

        badHeader.setActor(ACTOR);
        
        assertTrue("Non-MU bad header to unrecognized actor returned bad result!", 
                   runTest(badHeader, false));