use of alma.jconttest.ComponentWithBadNullsPackage.Struct2 in project ACS by ACS-Community.
the class ComponentWithBadNullsImpl method createGoodStruct2.
/**
* Creates a valid instance of the IDL-defined {@link Struct2}.
*/
public static Struct2 createGoodStruct2() {
Struct1 goodStruct1 = createGoodStruct1();
Struct1[] goodStruct1Array = new Struct1[1];
goodStruct1Array[0] = goodStruct1;
Struct2 goodStruct2 = new Struct2(goodStruct1, goodStruct1Array);
return goodStruct2;
}
use of alma.jconttest.ComponentWithBadNullsPackage.Struct2 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?
}
}
use of alma.jconttest.ComponentWithBadNullsPackage.Struct2 in project ACS by ACS-Community.
the class CorbaNullFinderTest method testNullFinder.
/**
* Tests the errors found and reported by CorbaNullFinder
*/
public void testNullFinder() {
List<String> expected = new ArrayList<String>();
Struct2 myStruct2 = ComponentWithBadNullsImpl.createGoodStruct2();
// all fine
CorbaNullFinder finder = new CorbaNullFinder(myStruct2);
assertFalse(finder.hasErrors());
assertNullFinderErrors(expected, finder.getErrors());
// struct missing
myStruct2.mystruct1 = null;
finder = new CorbaNullFinder(myStruct2);
assertTrue(finder.hasErrors());
expected.add("Null struct in field Struct2/mystruct1");
assertNullFinderErrors(expected, finder.getErrors());
// string and enum in struct missing
myStruct2 = ComponentWithBadNullsImpl.createGoodStruct2();
myStruct2.mystruct1.mystring = null;
myStruct2.mystruct1.myenum1 = null;
finder = new CorbaNullFinder(myStruct2);
assertTrue(finder.hasErrors());
expected.clear();
expected.add("Null string in field Struct2/mystruct1/mystring");
expected.add("Null enum in field Struct2/mystruct1/myenum1");
// mystruct1 is also part of the sequence
expected.add("Null string in field Struct2/seqOfStruct1[0]/mystring");
expected.add("Null enum in field Struct2/seqOfStruct1[0]/myenum1");
assertNullFinderErrors(expected, finder.getErrors());
// null sequence of structs
myStruct2 = ComponentWithBadNullsImpl.createGoodStruct2();
myStruct2.seqOfStruct1 = null;
finder = new CorbaNullFinder(myStruct2);
assertTrue(finder.hasErrors());
expected.clear();
expected.add("Null array in field Struct2/seqOfStruct1");
assertNullFinderErrors(expected, finder.getErrors());
// sequence with null struct
myStruct2 = ComponentWithBadNullsImpl.createGoodStruct2();
myStruct2.seqOfStruct1[0] = null;
finder = new CorbaNullFinder(myStruct2);
assertTrue(finder.hasErrors());
expected.clear();
expected.add("Null object in field Struct2/seqOfStruct1[0]");
assertNullFinderErrors(expected, finder.getErrors());
// Arrays outside of structs, with good values or with null values (see COMP-6091)
finder = new CorbaNullFinder(new String[] { "goodString" });
assertFalse(finder.hasErrors());
finder = new CorbaNullFinder(new String[] { "goodStringAtFirst", null, "anotherGoodString" });
assertTrue(finder.hasErrors());
expected.clear();
expected.add("Null object in field String[1]");
assertNullFinderErrors(expected, finder.getErrors());
// CorbaNullFinder will see them as Integer objects.
finder = new CorbaNullFinder(new int[] { 1, 2 });
assertFalse(finder.hasErrors());
// main object null
finder = new CorbaNullFinder(null);
assertTrue(finder.hasErrors());
expected.clear();
expected.add("Top-level object is null; cannot distinguish between a legal null object reference and an illegal null data item.");
assertNullFinderErrors(expected, finder.getErrors());
}
Aggregations