use of org.omg.CORBA.TypeCode in project cxf by apache.
the class CorbaConduitTest method testBuildReturn.
@Test
public void testBuildReturn() throws Exception {
Message msg = new MessageImpl();
CorbaMessage message = new CorbaMessage(msg);
QName objName = new QName("returnName");
QName objIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "short", CorbaConstants.NP_WSDL_CORBA);
TypeCode objTypeCode = orb.get_primitive_tc(TCKind.tk_short);
CorbaPrimitiveHandler obj1 = new CorbaPrimitiveHandler(objName, objIdlType, objTypeCode, null);
CorbaStreamable arg = message.createStreamableObject(obj1, objName);
CorbaConduit conduit = setupCorbaConduit(false);
NamedValue ret = conduit.getReturn(message);
assertNotNull("Return should not be null", ret != null);
assertEquals("name should be equal", ret.name(), "return");
message.setStreamableReturn(arg);
NamedValue ret2 = conduit.getReturn(message);
assertNotNull("Return2 should not be null", ret2 != null);
assertEquals("name should be equal", ret2.name(), "returnName");
}
use of org.omg.CORBA.TypeCode in project cxf by apache.
the class CorbaConduitTest method testBuildArguments.
@Test
public void testBuildArguments() throws Exception {
Message msg = new MessageImpl();
CorbaMessage message = new CorbaMessage(msg);
CorbaStreamable[] arguments = new CorbaStreamable[1];
QName objName = new QName("object");
QName objIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "short", CorbaConstants.NP_WSDL_CORBA);
TypeCode objTypeCode = orb.get_primitive_tc(TCKind.tk_short);
CorbaPrimitiveHandler obj1 = new CorbaPrimitiveHandler(objName, objIdlType, objTypeCode, null);
CorbaStreamable arg = message.createStreamableObject(obj1, objName);
arguments[0] = arg;
arguments[0].setMode(org.omg.CORBA.ARG_OUT.value);
CorbaConduit conduit = setupCorbaConduit(false);
NVList list = conduit.getArguments(message);
assertNotNull("list should not be null", list != null);
message.setStreamableArguments(arguments);
NVList listArgs = conduit.getArguments(message);
assertNotNull("listArgs should not be null", listArgs != null);
assertNotNull("listArgs Item should not be null", listArgs.item(0) != null);
assertEquals("Name should be equal", listArgs.item(0).name(), "object");
assertEquals("flags should be 2", listArgs.item(0).flags(), 2);
assertNotNull("Any Value should not be null", listArgs.item(0).value() != null);
}
use of org.omg.CORBA.TypeCode in project cxf by apache.
the class CorbaObjectReaderTest method testReadObjectReference.
@Test
public void testReadObjectReference() throws IOException {
OutputStream oStream = orb.create_output_stream();
URL refUrl = getClass().getResource("/references/account.ref");
String oRef = IOUtils.toString(refUrl.openStream()).trim();
org.omg.CORBA.Object objRef = orb.string_to_object(oRef);
assertNotNull(objRef);
oStream.write_Object(objRef);
// we need an ORBinstance to handle reading objects so use the input stream
InputStream iStream = oStream.create_input_stream();
CorbaObjectReader reader = new CorbaObjectReader(iStream);
// create a test object
org.apache.cxf.binding.corba.wsdl.Object objectType = new org.apache.cxf.binding.corba.wsdl.Object();
objectType.setRepositoryID("IDL:Account:1.0");
objectType.setBinding(new QName("AccountCORBABinding"));
QName objectName = new QName("TestObject");
QName objectIdlType = new QName("corbaatm:TestObject");
TypeCode objectTC = orb.create_interface_tc("IDL:Account:1.0", "TestObject");
CorbaObjectReferenceHandler obj = new CorbaObjectReferenceHandler(objectName, objectIdlType, objectTC, objectType);
reader.readObjectReference(obj);
assertTrue(obj.getReference()._is_equivalent(objRef));
}
use of org.omg.CORBA.TypeCode in project cxf by apache.
the class CorbaObjectReaderTest method testReadArray.
// need to add tests for arrays, sequences, struct, exceptions
@Test
public void testReadArray() {
int[] data = { 1, 1, 2, 3, 5, 8, 13, 21 };
OutputStream oStream = orb.create_output_stream();
oStream.write_long_array(data, 0, data.length);
InputStream iStream = oStream.create_input_stream();
CorbaObjectReader reader = new CorbaObjectReader(iStream);
// create an array of longs
QName longIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "long", CorbaConstants.NP_WSDL_CORBA);
QName arrayIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "array", CorbaConstants.NP_WSDL_CORBA);
Array arrayType = new Array();
arrayType.setBound(data.length);
arrayType.setElemtype(longIdlType);
// name and respoitory ID of the array are not needed for this test
// build the object holder for an array.
TypeCode arrayTC = orb.create_array_tc(data.length, orb.get_primitive_tc(TCKind.tk_long));
CorbaArrayHandler obj = new CorbaArrayHandler(new QName("Array"), arrayIdlType, arrayTC, arrayType);
for (int i = 0; i < data.length; ++i) {
CorbaObjectHandler nestedObj = new CorbaPrimitiveHandler(new QName("item"), longIdlType, orb.get_primitive_tc(TCKind.tk_long), null);
obj.addElement(nestedObj);
}
reader.readArray(obj);
int length = obj.getElements().size();
for (int i = 0; i < length; ++i) {
assertTrue(new Long(((CorbaPrimitiveHandler) obj.getElement(i)).getDataFromValue()).intValue() == data[i]);
}
}
use of org.omg.CORBA.TypeCode in project cxf by apache.
the class CorbaObjectReaderTest method testReadException.
@Test
public void testReadException() {
OutputStream oStream = orb.create_output_stream();
// create the following exception
// exception TestExcept {
// short code;
// string message;
// }
short code = 12345;
String message = "54321";
oStream.write_string("IDL:org.apache.cxf.TestException/1.0");
oStream.write_short(code);
oStream.write_string(message);
InputStream iStream = oStream.create_input_stream();
CorbaObjectReader reader = new CorbaObjectReader(iStream);
QName exceptIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "exception", CorbaConstants.NP_WSDL_CORBA);
QName shortIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "short", CorbaConstants.NP_WSDL_CORBA);
QName stringIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "string", CorbaConstants.NP_WSDL_CORBA);
Exception exceptType = new Exception();
exceptType.setName("TestException");
MemberType m1 = new MemberType();
m1.setIdltype(shortIdlType);
m1.setName("code");
MemberType m2 = new MemberType();
m2.setIdltype(stringIdlType);
m2.setName("message");
exceptType.getMember().add(m1);
exceptType.getMember().add(m2);
// build the object holder
StructMember[] exceptMembers = new StructMember[2];
exceptMembers[0] = new StructMember("code", orb.get_primitive_tc(TCKind.tk_short), null);
exceptMembers[1] = new StructMember("message", orb.get_primitive_tc(TCKind.tk_string), null);
TypeCode exceptTC = orb.create_exception_tc("IDL:org.apache.cxf.TestException/1.0", "TestException", exceptMembers);
CorbaExceptionHandler obj = new CorbaExceptionHandler(new QName("TestException"), exceptIdlType, exceptTC, exceptType);
obj.addMember(new CorbaPrimitiveHandler(new QName("code"), shortIdlType, exceptMembers[0].type, null));
obj.addMember(new CorbaPrimitiveHandler(new QName("message"), stringIdlType, exceptMembers[1].type, null));
reader.readException(obj);
List<CorbaObjectHandler> nestedObjs = obj.getMembers();
assertTrue(new Short(((CorbaPrimitiveHandler) nestedObjs.get(0)).getDataFromValue()).shortValue() == code);
assertTrue(((CorbaPrimitiveHandler) nestedObjs.get(1)).getDataFromValue().equals(message));
}
Aggregations