Search in sources :

Example 1 with MARSHAL

use of org.omg.CORBA.MARSHAL in project ACS by ACS-Community.

the class CorbaNullFinderTest method testJacorbNullBehavior.

/**
	 * Tests jacorb's reaction to null data inside structs.
	 * If this test fails after a jacorb update, the logic of the Null Finder must be revisited.
	 */
public void testJacorbNullBehavior() throws Exception {
    // Below we'll need an ORB... 
    AcsLogger logger = ClientLogManager.getAcsLogManager().getLoggerForApplication("testOrbLogger", false);
    AcsCorba acsCorba = new AcsCorba(logger);
    acsCorba.initCorbaForClient(false);
    // Jacorb uses ReplyOutputStream, but its base class ServiceContextTransportingOutputStream is easier to construct
    // and should be similar enough for this test.
    OutputStream out = new ServiceContextTransportingOutputStream(acsCorba.getORB());
    Struct2 myStruct2 = ComponentWithBadNullsImpl.createGoodStruct2();
    // the good data should marshal without exception
    Struct2Helper.write(out, myStruct2);
    // null string
    try {
        myStruct2.mystruct1.mystring = null;
        Struct2Helper.write(out, myStruct2);
        fail("null strings in structs should marshal with exception.");
    } catch (MARSHAL ex) {
        // expected
        assertEquals("org.omg.CORBA.MARSHAL: Cannot marshall null string.", ex.toString());
    }
    // null enum
    myStruct2 = ComponentWithBadNullsImpl.createGoodStruct2();
    try {
        myStruct2.mystruct1.myenum1 = null;
        Struct2Helper.write(out, myStruct2);
        fail("null strings in structs should marshal with NPE.");
    } catch (NullPointerException ex) {
    // expected... this is a really mean case, because we get NPE instead of MARSHAL. Maybe a jacorb bug?
    }
    // null struct
    myStruct2 = ComponentWithBadNullsImpl.createGoodStruct2();
    try {
        myStruct2.mystruct1 = null;
        Struct2Helper.write(out, myStruct2);
        fail("null structs inside structs should marshal with NPE.");
    } catch (NullPointerException ex) {
    // expected... this is a really mean case, because we get NPE instead of MARSHAL. Maybe a jacorb bug?
    }
    // top-level struct itself is null
    try {
        Struct2Helper.write(out, null);
        fail("top-level null structs should marshal with NPE.");
    } catch (NullPointerException ex) {
    // expected... 
    }
    // null sequence of structs
    myStruct2 = ComponentWithBadNullsImpl.createGoodStruct2();
    try {
        myStruct2.seqOfStruct1 = null;
        Struct2Helper.write(out, myStruct2);
        fail("null sequence of structs inside structs should marshal with NPE.");
    } catch (NullPointerException ex) {
    // expected... this is a really mean case, because we get NPE instead of MARSHAL. Maybe a jacorb bug?
    }
    // sequence with null struct
    myStruct2 = ComponentWithBadNullsImpl.createGoodStruct2();
    try {
        // with null inside
        myStruct2.seqOfStruct1 = new Struct1[1];
        Struct2Helper.write(out, myStruct2);
        fail("sequence of structs with nulls should marshal with NPE.");
    } catch (NullPointerException ex) {
    // expected... this is a really mean case, because we get NPE instead of MARSHAL. Maybe a jacorb bug?
    }
}
Also used : ServiceContextTransportingOutputStream(org.jacorb.orb.giop.ServiceContextTransportingOutputStream) ServiceContextTransportingOutputStream(org.jacorb.orb.giop.ServiceContextTransportingOutputStream) OutputStream(org.omg.CORBA.portable.OutputStream) Struct2(alma.jconttest.ComponentWithBadNullsPackage.Struct2) MARSHAL(org.omg.CORBA.MARSHAL) AcsLogger(alma.acs.logging.AcsLogger)

Aggregations

AcsLogger (alma.acs.logging.AcsLogger)1 Struct2 (alma.jconttest.ComponentWithBadNullsPackage.Struct2)1 ServiceContextTransportingOutputStream (org.jacorb.orb.giop.ServiceContextTransportingOutputStream)1 MARSHAL (org.omg.CORBA.MARSHAL)1 OutputStream (org.omg.CORBA.portable.OutputStream)1